akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int D;
int c[26];
int s[365][26];
int selected[365];
int scores[26];

int calculateScore(int t){
    int retVal = 0;
    int last = -1;
    for(int i=0;i<D;i++){
        if(selected[i] == t){
            last = i;
            retVal += s[i][t];
        }else{
            retVal -= c[t] * (i-last);
        }
    }
    return retVal;
}


int main() {
    clock_t start = clock();
    cin >> D;
    for(int i=0;i<26;i++){
        cin >> c[i];
    }
    for(int i=0;i<D;i++)for(int j=0;j<26;j++){
        cin >> s[i][j];
    }

    int last[26];
    memset(last,-1,sizeof(last));
    for(int i=0;i<D;i++){
        int maxNum =-(1e7);
        int maxArg = 0;
        for(int j=0;j<26;j++){
            if(s[i][j] -c[j]*(i-last[j]) > maxNum){
                maxNum = s[i][j] -c[j]*(i-last[j]);
                maxArg = j;
            }
        }
        cerr <<"i=" <<i <<"maxArg=" << maxArg << "\n";
        selected[i] = maxArg;
        last[maxArg] = i;
    }
    for(int i=0;i<26;i++){
        scores[i] = calculateScore(i);
    }
    int itr = 1;
    while(clock()-start<(CLOCKS_PER_SEC*2- 1000000)){
        // cerr <<"itr =" << itr <<"\n";
        itr++;
        int t = rand()%D;
        int oldq = selected[t];
        int maxdiff=0;
        int maxArg = oldq;
        for(int q=0;q<26;q++){
            if(q==oldq){
                continue;
            }
            int oldscore = scores[oldq] + scores[q];
            selected[t] = q;
            int newScore = calculateScore(oldq) + calculateScore(q);
            if(maxdiff < newScore-oldscore){
                maxdiff = newScore-oldscore;
                maxArg = q;
            }
            selected[t] = oldq;
        }
        // cerr<<"maxArg = " << maxArg <<"maxDiff=" << maxdiff << "\n";
        selected[t] = maxArg;
        scores[oldq] = calculateScore(oldq);
        scores[maxArg] = calculateScore(maxArg);
        // cerr <<"oldScore=" << oldscore <<"newScore=" << newScore << "\n";
       
    }
    for(int i=0;i<D;i++){
        cout << selected[i]+1 <<"\n";
    }
    return 0;
}

Measured memory_bytes: 3660
import java.util.*;
import java.math.BigInteger;
 class Main{

     public static void main(String []args){
      Scanner scan = new Scanner(System.in);
      int a = scan.nextInt() ;
      int b =scan.nextInt();
      int c =scan.nextInt();
      int d = scan.nextInt();
      
      int x1 = Math.max(a,c);
      int x2 = Math.min(b,d);
      System.out.println((x2-x1)>0 ? (x2-x1) : 0) ;
    }
}

Measured memory_bytes: 22868
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Main main = new Main();
		main.solveA();
	}

	private void solveA() {
		Scanner sc = new Scanner(System.in);
		int five = 0;
		int seven = 0;
		for (int i = 0; i < 3; i++) {
			switch (sc.nextInt()) {
			case 5:
				five++;
				break;
			case 7:
				seven++;
				break;
			default:
			}
		}
		if (five == 2 && seven == 1) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 8788
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s,ans="No";
  cin>>s;
  if(s[0]==s[1]){
    if(s[2]==s[3]&&s[0]!=s[2]){
      ans="Yes";
    }
  }
  
  if(s[0]==s[2]){
    if(s[1]==s[3]&&s[0]!=s[1]){
      ans="Yes";
    }
  }
  
  if(s[0]==s[3]){
    if(s[1]==s[2]&&s[0]!=s[1]){
      ans="Yes";
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  int n,k; cin >>n >>k;
  // kが奇数の場合も偶数の場合も、a,b,c全てがkの倍数である組は答えに入る
  ll tmp = n / k; // 1以上n以下の整数のうちkの倍数である者の数
  ll res = tmp * tmp * tmp;
  if (k % 2 == 0){
    // k が偶数の場合はa,b,c全てがkで割ったあまりがk/2である組も条件を満たす
    ll buf = (n + k/2) / k;
    res += buf * buf * buf;
  }
  cout <<res <<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int x = scan.nextInt();

		if (x < a) {
			System.out.println("NO");
		} else if (a + b < x) {
			System.out.println("NO");
		} else {
			System.out.println("YES");
		}

	}

}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
                    
                    
int main(){
    int A, B, C;
    cin >> A >> B >> C;

    string ans = "Yes";

    if(A == B & A == C & B == C|| A != B & A != C & B != C){
        ans = "No";
    }	

    cout << ans << endl;       
}

Measured memory_bytes: 256
def main():
    s = int(input())
    mod = 10**9+7
    dp = [0]*(s+1)
    dp[0] = 1
    ans = 0
    for i in range(s//3+1):
        dp2 = [0]*(s+1)
        temp = 0
        for j in range(s-2):
            temp = (temp+dp[j]) % mod
            dp2[j+3] = temp
        ans = (ans+dp2[s]) % mod
        dp = dp2
    print(ans)


main()


Measured memory_bytes: 67944
#include <ios>
#include <iostream>
#define INF 1000000000000000000LL

inline long long int minimum(long long int a, long long int b)
{
    return (a < b ? a : b);
}

inline long long int m4(long long int a, long long int b, long long int c, long long int d)
{
    return minimum(minimum(a, b), minimum(c, d));
}

inline long long int cost(long long int a, long long int b)
{
    return a*b;
}

int main()
{
    long long int q, h, s, d, n;
    std::cin >> q >> h >> s >> d;
    std::cin >> n;
    if (n & 1)
    {
        std::cout << m4(cost(4*n, q), cost(2*n, h), cost(n, s), cost(n/2, d) + m4(cost(4, q), cost(2, h), cost(1, s), INF));
    }
    else
    {
        std::cout << m4(cost(4*n, q), cost(2*n, h), cost(n, s), cost(n/2, d));
    }
}


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

int main(int argc, const char * argv[]) {
    
    string nyuuryoku;
    int a,b,c,d;
    string p="+";
    string m="-";
    
    cin >> nyuuryoku;
    
    a=nyuuryoku[0]-'0';
    b=nyuuryoku[1]-'0';
    c=nyuuryoku[2]-'0';
    d=nyuuryoku[3]-'0';
    
    
    if(a+b+c+d==7){
        cout << a << p << b << p << c << p << d << "=7" << endl;
    }
    else if(a+b+c-d==7){
        cout << a << p << b << p << c << m << d << "=7" << endl;
    }
    else if(a+b-c+d==7){
        cout << a << p << b << m << c << p << d << "=7" << endl;
    }
    else if(a+b-c-d==7){
        cout << a << p << b << m << c << m << d << "=7" << endl;
    }
    else if(a-b+c+d==7){
        cout << a << m << b << p << c << p << d << "=7" << endl;
    }
    else if(a-b+c-d==7){
        cout << a << m << b << p << c << m << d << "=7" << endl;
    }
    else if(a-b-c+d==7){
        cout << a << m << b << m << c << p << d << "=7" << endl;
    }
    else if(a-b-c-d==7){
        cout << a << m << b << m << c << m << d << "=7" << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 256
n = int(input())
numbers = input().split()
min_n = int(numbers[0])
max_n = int(numbers[0])
sum_n = int(numbers[0])
for i in range(1,n):
    sum_n = sum_n + int(numbers[i])
    if min_n > int(numbers[i]):
        min_n = int(numbers[i])
    if max_n < int(numbers[i]):
        max_n = int(numbers[i])
print("{0} {1} {2}".format(min_n, max_n, sum_n))


Measured memory_bytes: 6328
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <queue>
#include <stdarg.h>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <numeric>
#include <set>

#define ll long long

using namespace std;

void
solve() {
  ll n, m, x;
  cin>>n>>m>>x;

  vector<ll> c(n);
  vector<vector<ll>> a(n, vector<ll>(m, 0));
  for (int i=0; i<n; i++) {
    cin>>c[i];
    for (int j=0; j<m; j++)
      cin>>a[i][j];
  }

  ll best = INT_MAX;
  for (int i=0; i<(1<<n); i++) {
    bool valid = true;
    for (int j=0; j<m; j++) {
      ll now = 0;
      for (int k=0; k<n; k++) 
        if ((1<<k) & i)
          now += a[k][j];
      if (now < x) {
        valid = false;
        break;
      }
    }

    if (valid) {
      ll sum = 0;
      for (int k=0; k<n; k++)
        if ((1<<k) & i)
          sum += c[k];

      best = min(best, sum);
    }
  }

  if (best == INT_MAX)
    cout<<-1<<endl;
  else
    cout<<best<<endl;
}

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

  int t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



Measured memory_bytes: 3660
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let p: Vec<usize> = sc.vec(n);
    let mut ans = 0;
    for i in 1..(n - 1) {
        let mut v = vec![p[i - 1], p[i], p[i + 1]];
        v.sort();
        if v[1] == p[i] {
            ans += 1;
        }
    }
    println!("{}", ans);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
"""
x, y = LS()
if x > y:
    print(">")
elif x == y:
    print("=")
else:
    print("<")
"""

#B
"""
x, y, z = LI()
print((x-z)//(y+z))
"""

#C
n, m = LI()
print((m*1900+(n-m)*100)*2**m)

Measured memory_bytes: 38384
import sys
import re


def shift(lis):
    a = lis.pop()
    lis.insert(0, a)
    return lis


class Caesar:
    def __init__(self, n):
        a = list("abcdefghijklmnopqrstuvwxyz")
        b = list("abcdefghijklmnopqrstuvwxyz")
        for i in range(n):
            b = shift(b)
#        self.table = map((lambda x, y: (x, y)), a, b)
        self.table = zip(a, b)

    def lookup(self, c):
        for p in self.table:
            if c == p[0]:
                c = p[1]
                break
        return c

    def decrypt(self, str):
        result = map(self.lookup, str)
        return "".join(result)



#input_file = open(sys.argv[1], "r")
r = re.compile("the|this|that")

#for line in input_file:
for line in sys.stdin:
    line = line.rstrip("\r\n")
    for n in range(1,27):
        caesar = Caesar(n)
        result = caesar.decrypt(line)
        m = r.findall(result)
        if not len(m) == 0:
#            print m
            break
    print result

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

int main() {
  int N;
  cin >> N;
  set<string> O;
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    O.insert(S);
  }
  cout << O.size() << endl;
}

Measured memory_bytes: 19256
// you**can**do**anything :~  
#include <bits/stdc++.h>
#define ll long long
#define read(i) scanf("%lli" , &i)
const int maxn=5e5+10;
using namespace std;
vector< pair< ll , ll > >abj[545445];
int main()
{
ll n , l=100 ,count=0;
cin>>n;
while(n>l){
	l+=(((double)1/100)*l);
//cout<<l<<endl;
count++;
}
cout<<count;

}


Measured memory_bytes: 16416
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a, b, c ;
    cin >> a >> b >> c;
    //*/
    
    /*
    vector<int> vec(4);
    cin >> a.at(0) >> a.at(1) >> a.at(2) ;
    
    sort(vec.begin(), vec.end());
    */
    
    /*
    if( ( vec.at(0) == vec.at(1) && vec.at(1) == vec.at(2) ) || ( vec.at(3) == vec.at(2) && vec.at(1) == vec.at(2) ) ){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    */
    
    cout << min(a * b, c) << endl;

    return 0; 
}


Measured memory_bytes: 3596
def geti; gets.to_i end
def getis; gets.split.map &:to_i end
def getin n;  n.times.map{geti}  end
def getisn n; n.times.map{getis} end
YES = "YES"; NO = "NO"; Yes = "Yes"; No = "No";

n = geti
puts n % n.to_s.chars.map(&:to_i).reduce(:+) == 0 ? Yes : No

__END__

n,a,b = getis
p [n*a,b].min

a,b,c = getis
p [a,b,c].any?(&:even?) ? 0 : [a*b,b*c,c*a].min

a,b=getis
puts a > 0 ? 'Positive' : b >= 0 ? 'Zero' : (b - a) % 2 == 1 ? 'Positive' : 'Negative'


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;

# define mp make_pair
# define pb push_back
# define PI acos(-1)
# define ff first 
# define ss second 
# define endl '\n'
# define vt vector
# define all(c) (c).begin(), (c).end()
# define rep(i,a,b) for(int i = a ; i < b ; ++i)

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

template<class T> bool umin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool umax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const int MOD = 1e9+9 ;
const ll inf = 1e18 ;  
const ll mod = 1e9+7 ;  

ll nCr(ll n,ll r){ll t=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){t*=(n-i);t/=(i+1);}return t;}
ll power(ll a, ll n) { ll r=1;while(n){if(n&1)r=(r*a)%MOD;n>>=1;a=(a*a)%MOD;}return r%MOD;}



vt<pii> dir =  {{-1,0} , {1, 0} , {0,-1} , {0,1}} ; 

// ==========Start Here==============

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ; 
 		
 	int n ; 
 	cin >> n ; 
 	map<int,int> present ;
 	bool ok = 1 ; 
 	vt<int> a(n) ; 
 	rep(i,0,n) {
 		cin >> a[i] ; 
 		if(present[a[i]]) 
 			ok = 0 ; 
 		present[a[i]]++; 
 	}
 	if(ok) {
 		cout << "YES" ; 
 	} else {
 		cout << "NO" ; 
 	}


	return 0 ; 
}

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

int a,b,c,d;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>a>>b>>c>>d;
	if(abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d))
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int m = scanner.nextInt();
			String[] s = new String[n];
			int[] win = new int[n];
			for (int i = 0; i < n; i++) {
				s[i] = scanner.next();
				win[i] = scanner.nextInt();
			}
			String[] num = new String[m];
			int ans = 0;
			for (int i = 0; i < m; i++)
				num[i] = scanner.next();
			for (int i = 0; i < m; i++)
				loop: for (int j = 0; j < n; j++) {
					for (int k = 0; k < 8; k++) {
						if (s[j].charAt(k) == '*')
							continue;
						if (s[j].charAt(k) != num[i].charAt(k))
							continue loop;
					}
					ans += win[j];
					break;
				}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 32448
S = input()
y, m, d = int(S[:4]), int(S[5:7]), int(S[8:])
H, T = 'Heisei', 'TBD'
if y < 2019:
    print(H)
elif y > 2019:
    print(T)
else:  # y == 2019
    if m < 4:
        print(H)
    elif m > 4:
        print(T)
    else:
        print(H)

Measured memory_bytes: 3060
// package app;

import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        // final String N = sc.next();

        final int n = sc.nextInt();
        final int m = sc.nextInt();
        // final int N = sc.nextInt();
        // final int D = sc.nextInt();
        // System.out.println();


        System.out.println((n - 1) * (m - 1));

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define ll long long
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const ll INF = 1061109567;
const double EPS = 1e-10;
int main(){
    char X;
    cin>>X;
    if(X<=95){
        cout<<'A'<<endl;
    }else{
        cout<<'a'<<endl;
    }
    return 0;
}


Measured memory_bytes: 3632
a,b,c=map(int,input().split())
k=int(input())

for i in range(k):
    if a>=c:
        c=c*2
    elif a<=c and b>=c:
        c=c*2
    elif a<=c and b<=a:
        b=b*2
    elif c>=b and b>=a:
        c=c*2

if c>b and a<b:
    print('Yes')
else:
    print('No')

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

using namespace std;

int main(){
	int n;
	cin >> n;
	int a[200000];
	
	int i;
	for (i = 0; i < n; i++){
		cin >> a[i];
	}
	int maxn = -2000000000;
	int minn = a[0];
	for (i = 1; i < n; i++){
		maxn = max(maxn, a[i] - minn);
                minn = min(minn, a[i]);
		

	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 3836
import numpy as np
w, h, n = map(int, input().split())
mat = [list(map(int, input().split())) for _ in range(n)]

arr = np.array([[1 for _ in range(w)] for _ in range(h)])

for x, y, a in mat:
    if a == 1:
        arr[:,:x] = 0
    elif a == 2:
        arr[:, x:] = 0
    elif a == 3:
        arr[-y:,:] = 0
    
    elif a == 4:
        arr[:-y,:] = 0

print(arr.sum())


Measured memory_bytes: 12544
fun main(args: Array<String>) {
    var (a, b, k) = readLine()!!.split(" ").map { it.toInt() }

    for (i in (1..k)) {
        if (i % 2 == 1) {
            b += a / 2
            a /= 2
        } else {
            a += b / 2
            b /= 2
        }
    }
    println("$a $b")
}

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

int main(){
    string s;
    cin>>s;
    int num;
    int min=999;
    for(int i=0;i<s.size()-2;i++){
        num = (int)(s[i]-'0')*100 + (int)(s[i+1]-'0')*10 + (int)(s[i+2]-'0');
        // cout<<num<<endl;
        min=std::min(min,abs(753-num));
    }
    cout<<min<<endl;   
}



Measured memory_bytes: 3596
# input the number for array of a[]
n = int(input())
a = list(map(int, input().split()))

# input the number for array of b[]
m = int(input())
b = list(map(int, input().split()))

# do the linear search
count = 0
for i in range(m):
    for j in range(n):
        if(b[i] == a[j]):
            count += 1
            break

print(count)



Measured memory_bytes: 6316
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long w = sc.nextLong();
        long[] wi = new long[n];
        int[] vi = new int[n];
        for(int i = 0;i < n;i++) {
            wi[i] = sc.nextLong();
            vi[i] = sc.nextInt();
        }
        
        int dpy = n + 1;
        int dpx = (int)Math.pow(10, 5) + 1;
        long[][] dp = new long[dpy][dpx];
        for(int i = 0;i < dpy;i++) {
            for(int j = 0;j < dpx;j++) dp[i][j] = 9999999999999999l;
        }
        dp[0][0] = 0;
        
        for(int y = 1;y < dpy;y++) {
            for(int x = 0;x < dpx;x++) {
                int tmpX = x - vi[y - 1];
                long candidate1 = (tmpX < 0 ? 9999999999999999l : (dp[y - 1][tmpX] + wi[y - 1]));
                long candidate2 = dp[y - 1][x];
                dp[y][x] = Long.min(candidate1, candidate2);
                if(dp[y][x] > w) dp[y][x] = 9999999999999999l;
            }
        }
        
        long ans = 0;
        for(int x = dpx - 1;x >= 0;x--) {
            if(dp[n][x] <= w) {
                ans = x;
                break;
            }
        }
    
        System.out.println(ans);
    }
}


Measured memory_bytes: 129620
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define RN cout << "\r\n"
#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 fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;

// combination
const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

void next(vector<ll> &path, vector<vector<bool>> &graph, ll &ans, ll &N) {
    if (path.size() == N) {
        ans++;
        return;
    }
    REP(i, N) {
        if (graph[path[path.size() - 1]][i] && find(path.begin(), path.end(), i) == path.end()) {
            path.push_back(i);
            next(path, graph, ans, N);
            path.erase(path.begin() + path.size() - 1);
        }
    }
}

int main() {
    ll N, M, ans;
    vector<vector<bool>> graph;
    vector<ll> path;
    path.push_back(0);
    cin >> N >> M;
    ans = 0;
    graph = vector<vector<bool>>(N, vector<bool>(N, false));
    REP(n, M) {
        ll a, b;
        cin >> a >> b;
        graph[a - 1][b - 1] = true;
        graph[b - 1][a - 1] = true;
    }
    next(path, graph, ans, N);
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
//Zory-2018
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
using namespace std;

namespace mine
{
	typedef long long ll;
	const int INF=0x3f3f3f3f;

	const int MAX_N=1100;
	int n,x[MAX_N],y[MAX_N];
	vector<int> d;
	vector<char> ans[MAX_N];
	void gao(int k)
	{
		d.push_back(k);
		for(int i=1;i<=n;i++)
			if(abs(x[i])>abs(y[i]))
			{
				if(x[i]<0) x[i]+=k,ans[i].push_back('L');
				else x[i]-=k,ans[i].push_back('R');//debug 倒着走！
			}
			else
			{
				if(y[i]<0) y[i]+=k,ans[i].push_back('D');
				else y[i]-=k,ans[i].push_back('U');
			}
	}
	void main()
	{
		scanf("%d",&n);
		for(int i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]);
		for(int i=30;i>=0;i--) gao(1<<i);
		for(int i=1;i<=8;i++) gao(1);
		if(x[1]!=0 or y[1]!=0) gao(1);//曼哈顿距离为奇数

		for(int i=1;i<=n;i++) if(x[i]!=0 or y[i]!=0) {puts("-1");return;}

		printf("%d\n",d.size());
		for(int i=0;i<(int)d.size();i++) printf("%d ",d[i]);
		puts("");
		for(int i=1;i<=n;i++)
		{
			for(int j=0;j<(int)ans[i].size();j++) printf("%c",ans[i][j]);
			puts("");
		}
	}
}
int main()
{
	mine::main();
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  long long n;
  cin >> n;
  long long i;
  long long sum = 0;
  for(i=1;i<=n;i++){
    if(i%3==0 || i%5==0){
      continue;
    }
    else{
      sum += i;
    }
  }
  cout << sum <<"\n";
  return 0;
}



Measured memory_bytes: 3640
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var w = int.Parse(line[0]);
        var h = int.Parse(line[1]);
        var n = int.Parse(line[2]);
        var maxX = new int[h];
        var maxY = new int[w];
        for (int i = 0; i < n; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var x = int.Parse(line[0]);
            var y = int.Parse(line[1]);
            if (x > maxX[y]) maxX[y] = x;
            if (y > maxY[x]) maxY[x] = y;
        }
        if (w > h)
        {
            var t = getMax2(maxX);
            var ans = getAns(t);
            Console.WriteLine(ans);
        }
        else if (w < h)
        {
            var t = getMax2(maxY);
            var ans = getAns(t);
            Console.WriteLine(ans);
        }
        else
        {
            var t = getMax2(maxX);
            var ans = getAns(t);
            var t2= getMax2(maxY);
            var ans2 = getAns(t2);
            Console.WriteLine(Min(ans,ans2));
        }
    }
    static int getAns(int[] a)
    {
        var p = 0;
        var ans = int.MaxValue;
        foreach (var x in a)
            ans = Min(ans, x + p++);
        return ans;
    }
    static int[] getMax2(int[] a)
    {
        var aL = a.Length;
        var b = new int[aL];
        for (int i = aL - 1; i >= 1; i--)
            b[i - 1] = Max(b[i], a[i]);
        return b;
    }
}




Measured memory_bytes: 23132
#include<bits/stdc++.h>
using namespace std;
int n,i,t;
int main(){
	string s;
	cin>>n>>s;
	int j=n-1;
	while(i<j){
		if(s[i]=='W' && s[j]=='R'){
			swap(s[i],s[j]);
			t++; i++;
		}
		if(s[i]=='R') i++;
		if(s[j]=='W') j--;
	}
	cout<<t;
}

Measured memory_bytes: 3720
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 100005;
const int MM = 1000000007;

char D[MX];

int main()
{
	scanf("%s", D+1);
	int N = strlen(D+1);
	for(int i = N/2; i >= 1; i--){
		if( D[i+1] != D[i] || D[N-i] != D[N-i+1] ){
			return !printf("%d\n", N-i);
		}
	}
	printf("%d\n", N);
}


Measured memory_bytes: 384
#include <iostream>
#include <queue>
#include <stack>
using namespace std;
stack<int> stal, star;
queue<int> que;
bool dfs();

int main() {
    int n;

    while (cin >> n) {
        int num;
        while (n--) {
            while (!que.empty()) que.pop();
            for (int i = 0; i < 10; i++) {
                cin >> num;
                que.push(num);
            }
            while (!stal.empty()) stal.pop();
            while (!star.empty()) star.pop();
            cout << (dfs() ? "YES" : "NO") << endl;
        }
    }

    return 0;
}

bool dfs() {
    bool flag = true, enter = false;
    if (stal.empty() || stal.top() < que.front()) {
        stal.push(que.front());
        que.pop();
        flag = dfs();
        enter = true;
    }
    if (!flag && !enter) { que.push(stal.top()); stal.pop(); }
    if ((star.empty() || star.top() < que.front()) && (!flag || !enter)) {
        star.push(que.front());
        que.pop();
        dfs();
    }
    if (que.empty()) return true;
    else return false;
}

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

using namespace std;
int main()
{
    string s;
    cin >> s;
    int i = 0;
    vector <int> len;
    len.push_back(5);
    int x = s.size();
    while(i < x){
        if(len.back() == 5){
            if(s.substr(i, 5) == "erase" || s.substr(i, 5) == "dream"){
                i += 5;
                len.push_back(5);
            }
            else{
                len.back()++;
            }
        }
        else if(len.back() == 6){
            if(s.substr(i, 6) == "eraser"){
                i += 6;
                len.push_back(5);
            }
            else{
                len.back()++;
            }
        }
        else if(len.back() == 7){
            if(s.substr(i, 7) == "dreamer"){
                i += 7;
                len.push_back(5);
            }
            else{
                len.back()++;
            }
        }
        else{
            len.pop_back();
            if(len.size() == 0){
                cout << "NO";
                return 0;
            }
            i -= len.back();
            len.back()++;
        }
    }
    cout << "YES";
    return 0;
}


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

#define all(a) a.begin(), a.end()
#define allr(a) a.rbegin(), a.rend()
#define rev(v) reverse(v.begin(), v.end());
#define io() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); srand(time(NULL));
#define check cout<<"?\n";
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

signed main(){
    io(); 
    int n; cin >> n;
    cout << n*n*n << '\n';
    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <string.h>

int main(void) {
	char s[11], t[11];
	
	scanf("%s", s);
	scanf("%s", t);
	
	if (strlen(s) == strlen(t) - 1) {
		t[strlen(t)-1] = 0;
		if (strcmp(s,t) == 0) {
			printf("Yes\n");
		} else {
			printf("No\n");
		}
	} else {
		printf("No\n");
	}
	
	return 0;
}

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define reps(i,s,e) for(int i=s; i<(int)e; i++)
#define coutd(i) cout << std::fixed << std::setprecision(i)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Set = std::set<T>;
template<class T, class U>
using Map = std::map<T, U>;

template<class T>
using Graph = vector<vector<T>>;

const int INT_BIG = 1<<28;

int main() {
    int a, b;
    cin >> a >> b;
    cout << a*b << endl;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
		int N;
	cin >> N;
	vector<double> ans;
	fx(N) {
		double a;
		cin >> a;
		pb(ans,a)
	}
	sorts(ans)
		double sum = 0;
	fx(N-1) {
		double b= (ans.at(x) + ans.at(x + 1)) / 2;
		sum += b;
			ans.at(x + 1) = b;
	}
	//ce(ans.at(N-1))
		cout << fixed << setprecision(10) << ans.at(N - 1) << endl;
    return 0;
}



Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Data.List
import Control.Monad

solve xs = loop t o
    where
        t = filter (\v -> v `rem` 10 == 0) xs
        o = filter (\v -> v `rem` 10 /= 0) xs
        loop t o
            | null o = 0
            | (sum o `rem` 10) == 0 = loop t (delete (minimum o) o)
            | otherwise = sum o + sum t

main = do
    n <- readLn :: IO Int
    xs <- replicateM n (fst . fromJust . B.readInt <$> B.getLine)
    print $ solve xs

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<<"### "<<x<<endl;
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
inline int read(){
    int x=0;char c=getchar();
    while(c<'0'||c>'9')c=getchar();
    while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
    return x;
}
const int N=1e5+10;
int a[N],b[N],n,c[N];
void add(int x,int d){
	for(;x<N;x|=x+1)c[x]=max(c[x],d);
}
int sum(int x){
	int res=0;
	for(;x>=0;x=(x&(x+1))-1)res=max(c[x],res);
	return res;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(b+1,b+n+1);
	int num=unique(b+1,b+n+1)-b-1;
	
	for(int i=1;i<=n;i++)a[i]=lower_bound(b+1,b+num+1,a[i])-b,a[i]=n-a[i]+1;
	
	int ans=0,ma=0,lst=0;
	for(int i=1;i<=n;i++){
		int all=sum(a[i]);
	//	cout<<i<<" "<<all<<endl;
		ans=max(ans,all+1);
		add(a[i],all+1);
	}
	cout<<ans;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 30)
#define MOD 1000000007
//int dy[4] = {-1,0,0,1};
//int dx[4] = {0,1,-1,0};



int main(){

  int n,c;
  cin >> n >> c;
  vector<int> v(200200,0);
  vector<vector<int>> cc(c,vector<int>(200200,0));
  REP(i,n){
    int l,r,ccc;cin >> l >> r >> ccc;
    ccc--;
    if(cc[ccc][l*2] != -1)cc[ccc][l*2-1]++;
    else cc[ccc][l*2] = 0;
    if(cc[ccc][r*2-1] != 1)cc[ccc][r*2]--;
    else cc[ccc][r*2-1] = 0;
  }
  REP(i,200200)REP(j,c)v[i] += cc[j][i];
  for(int i = 1;i <= 200000;i++)v[i] += v[i-1];
  cout << *max_element(ALL(v)) << endl;











  return 0;
}

Measured memory_bytes: 25344
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0 ; i < n ; i++)
        cin >> a[i];
    
    bool flg = true;
    for (int i = 0; i < n; i++)
    {
        if(a[i]%2 == 0){
            if (!(a[i] % 3 == 0 || a[i] % 5 == 0))
                flg = false;
        }
    }
    
    if(flg == true)
        cout << "APPROVED" << endl;
    else
        cout << "DENIED" << endl;
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n,0);
    for(int i=0;i<n;i++) cin >> a[i];
    int j=1;
    b[0] = 1;
    int ans = 0;
    while(ans<=n){
        if(j == 2){
            break;
        }
        j = a[j-1];
        if(b[j-1] == 1){
            ans = -1;
            break;
        }
        b[j-1] = 1;
        ans++;
    }   
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(void){
	int n,m,t;
	
	while(cin >> n >> m){
		if((n|m) == 0) break;
		
		int board[n+1];
		int dice[m];
		int pos = 1;
		int times = 0;
		
		for(int i=1;i<=n;i++){
			cin >> board[i];
		}
		for(int i=0;i<m;i++){
			cin >> dice[i];
		}
		
		for(int i=0;i<m;i++){
			t = dice[i];
			times++;
			if(pos+t >= n){
				cout << times << endl;
				break;
			}else{
				pos += t;
				pos += board[pos];
				if(pos >= n){
					cout << times << endl;
					break;
				}
				if(pos <= 0) pos = 1;
			}
		}
	}
}

Measured memory_bytes: 0
N,M=map(int,input().split())
A=list(map(int,input().split()))
w=[0,2,5,5,4,5,6,3,7,6]
dp=[-1]*(N+1)
dp[0]=0
for i in range(N+1):
  for a in A:
    if i+w[a]<N+1:
      dp[i+w[a]]=max(dp[i+w[a]],dp[i]*10+a)
      
print(dp[-1])

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

signed main()
{
	cin >> n;
	if (n == 'a' || n == 'e' || n == 'i' || n == 'o' || n == 'u')
		cout << "vowel\n";
	else
		cout << "consonant\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
const int MAX = 11;
const int INF = 1<<28;
 
int n,r[MAX][MAX],v[MAX],mini,mn,maxnum,minnum;
bool visit[MAX];
 
int dijkstra(int s){
    for(int i = 0 ; i < MAX ; i++){
        v[i] = INF;
        visit[i] = false;
    }
     
    v[s] = 0;
    while(true){
        mini = INF;
        for(int i = 0 ; i <= maxnum ; i++){
            if(v[i] < mini && !visit[i]){
                mini = v[i];
                mn = i;
            }
        }
         
        if(mini == INF) break;
        visit[mn] = true;
         
        for(int i = 0; i <= maxnum ; i++){
            int t = r[mn][i]+v[mn];
            v[i] = min(v[i],t);
        }
    }
     
    int sum = 0;
    for(int i = 0 ; i <= maxnum ; i++){
        sum += v[i];
    }
     
    return sum;
}
 
 
int main(){
    int a,b,c;
 
    while(cin >> n,n){
         
        for(int i = 0 ; i < MAX ; i++)
            for(int j = 0 ; j < MAX ; j++)
                r[i][j] = INF;
         
        maxnum = 0;
        for(int i = 0 ; i < n ; i++){
            cin >> a >> b >> c;
            r[a][b] = r[b][a] = c;
	     maxnum = max(maxnum,max(a,b));
        }
 
        int mx = INF, e;
        for(int i = 0 ; i <= maxnum ; i++){
            int val = mx;
            mx = min(mx,dijkstra(i));
            if(val > mx) e = i;
        }
        cout << e << " " << mx << endl;
    }
     
    return 0;
}

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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return 1;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int a, b;
  cin >> a >> b;
  int ma = -MAX_I;
  ma = max(a+b, ma);
  ma = max(a*b, ma);
  ma = max(a-b, ma);

  cout << ma << endl;
}


/*





















*/


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
    static int[] swim;
    static int[] bugs;
    static int[] hw;
    static int[][] dp;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //BufferedReader br = new BufferedReader(new FileWriter("vacation.in");
        //StringTokenizer st = new StringTokenizer(br.readLine());
        //PrintWriter pw = new PrintWriter("vacation.out");

        int n = sc.nextInt();
        swim = new int[n+1];
        bugs = new int[n+1];
        hw = new int[n+1];
        dp = new int[n+1][3];
        for(int x = 0; x<n+1; x++){
            Arrays.fill(dp[x], Integer.MIN_VALUE);
        }
        for(int x = 1; x<n+1; x++){
            swim[x] = sc.nextInt();
            bugs[x] = sc.nextInt();
            hw[x] = sc.nextInt();
        }

        System.out.println(Math.max(Math.max(hap(n, 0), hap(n, 1)), hap(n, 2)));

    }

    public static int hap(int n, int act){
        if(dp[n][act] != Integer.MIN_VALUE)
            return dp[n][act];
        if(n == 0)
            return dp[n][act] = 0;
        if(act == 0){
            return dp[n][act] = Math.max(hap(n-1, 1) + bugs[n], hap(n-1,2) + hw[n]);
        }
        else if(act == 1){
            return dp[n][act] = Math.max(hap(n-1, 0) + swim[n], hap(n-1,2) + hw[n]);
        }
        else
            return dp[n][act] = Math.max(hap(n-1, 0) + swim[n], hap(n-1,1) + bugs[n]);
    }
}


Measured memory_bytes: 111404
#include<stdio.h>
#include<string.h>

int main(void){
	
	int n,m,a[100][100],b[100]={0},c[100]={0},i,j,ans,cnt=0;
	
	scanf("%d %d",&n,&m);
	
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<m;i++){
		scanf("%d",&b[i]);
	}
	for(i=0;i<n;i++){
		ans=0;
		for(j=0;j<m;j++){
			ans+=a[i][j]*b[j];
		}
		c[i]=ans;
		cnt++;
	}

	for(i=0;i<cnt;i++){
		printf("%d\n",c[i]);
	}
	
	return 0;
}

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

int main(){
    double r; cin >> r;
    printf("%.20lf\n", 2*M_PI*r);

    return 0;
}

Measured memory_bytes: 3780
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

signed main(void)
{
    ll n;
    ll d;
    cin >> n >> d;
    ll r = 0;
    ll tmp = 0;
    ll rt = 0;
    vvll a(n, vll(d));
    rep(i, n) {
        rep(j, d) {
            cin >> a[i][j];
        }
    }
    
    rep(i, n) {
        for (int j=i+1; j<n; j++) {
            rep(k, d) {
                tmp += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
            }
            rt = (ll)sqrt(tmp);
            if (rt*rt == tmp) r++;
            tmp = 0;
        }
    }
    
    mes(r);
    
    
    
    
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define INF 1e18

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector < pair<int, int> > vii;
typedef long double ld;
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

map <ll, ll> x;
ll a[222222];

int main()
{
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL);
	ll n;
	cin >> n;
	ll cur = 0;
	x[0]++;
	ll ans = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		cur+=a[i];
		ans+=x[cur];
		x[cur]++;
	}
	cout << ans;
	
	return 0;
}


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

int main() {
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    if (A + B < C + D){
        cout << "Right" << endl;
    }
    else if (A + B > C + D) {
        cout << "Left" << endl;
    }
    else {
        cout << "Balanced" << endl;
    }
}


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

int main() {
	int A[4][4];
    string ans="No";
  
  	for(int i=0;i<3;i++){
     	for(int j=0;j<3;j++){
         	cin>>A[i][j]; 
        }
    }
  
  	int N;
  	cin>>N;
  	int b[N];
  	
  	for(int i=0;i<N;i++){
     	cin>>b[i]; 
    }
  	
  	for(int i=0;i<3;i++){
     	for(int j=0;j<3;j++){
         	for(int k=0;k<N;k++){
             	if(b[k]==A[i][j]){
                 	A[i][j]=-1; 
                }
            }
        }
    }
  	
  	for(int i=0;i<3;i++){
     	for(int j=0;j<3;j++){
         	if(A[0][0]==-1 && A[0][1]==-1 && A[0][2]==-1){
             	ans="Yes"; 
            }
          	if(A[1][0]==-1&&A[1][1]==-1&&A[1][2]==-1){
             	ans="Yes"; 	             	  
            }
          	if(A[2][0]==-1&&A[2][1]==-1&&A[2][2]==-1){
             	ans="Yes";  
            }
          	if(A[0][0]==-1&&A[1][0]==-1&&A[2][0]==-1){
             	ans="Yes";  
            }
          	if(A[0][1]==-1&&A[1][1]==-1&&A[2][1]==-1){
             	ans="Yes";  
            }
          	if(A[0][2]==-1&&A[1][2]==-1&&A[2][2]==-1){
             	ans="Yes";  
            }
          	if(A[0][0]==-1&&A[1][1]==-1&&A[2][2]==-1){
             	ans="Yes";  
            }
          	if(A[0][2]==-1&&A[1][1]==-1&&A[2][0]==-1){
             	ans="Yes";  
            }
        }
    }
  	
  	cout<<ans<<endl;
}

Measured memory_bytes: 256