akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8

t_net = [int(input()) for _ in range(5)]
t_next = [(t+9)//10*10 for t in t_net]
diff = [y-x for x,y in zip(t_net, t_next)]

t_tuple = list(zip(t_net, t_next, diff))
t_tuple.sort(key=lambda x:x[2])
print(sum([x[1] for x in t_tuple[:-1]])+t_tuple[-1][0])

Measured memory_bytes: 3060
"""
10^5以下の素数を列挙しておく。
それをもとに、10^5以下の各整数以下の2017に似た数の個数のメモを作成する。
"""
#10^5以下の素数を列挙
prime = [1] * (100001)
prime[0] = 0
prime[1] = 0
for i in range(2,100001):
    if prime[i]:
        for j in range(i*i,100001,i):
            prime[j] = 0

memo = [0]*(100001)
for i in range(3,100001):
    memo[i] = memo[i-1]
    if prime[i] and prime[(i+1)//2]:
        memo[i] += 1

Q = int(input())
for _ in range(Q):
    l,r = map(int,input().split())
    print(memo[r]-memo[l-1])

Measured memory_bytes: 51928
from string import ascii_lowercase
s = input()
for x in ascii_lowercase:
    cnt = 0
    l = 0
    for r, y in enumerate(s):
        if y == x:
            cnt += 1
        else:
            cnt -= 1
        if r - l > 0 and cnt > 0:
            print(l + 1, r + 1)
            exit()
        if y == x:
            l = r
            cnt = 1

print(-1, -1)

Measured memory_bytes: 3836
while True:
    m,f,r = map(int, input().split())
    if m == f == r == -1:
        break
    elif m == -1 or f == -1 or m+f < 30:
        print("F")
    elif 80 <= m+f:
        print("A")
    elif 65 <= m+f < 80:
        print("B")
    elif 50 <= m+f < 65:
        print("C")
    elif 30 <= m+f < 50:
        if 50 <= r:
            print("C")
        else:
            print("D")

Measured memory_bytes: 7664
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    int cnt[100010] = {};
    ll ans = 1, zero = 0;
    for(int i=0; i<N; i++) {
        if(A[i] == 0) {
            ans *= max(0LL, 3 - zero);
            ans %= MOD;
            zero++;
        }
        else {
            ans *= cnt[ A[i] - 1 ];
            ans %= MOD;
            cnt[ A[i] - 1 ] = max(0, cnt[ A[i] - 1 ] - 1);
        }
        cnt[ A[i] ]++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
	int K, X;
	cin >> K >> X;
	int an = X - K  + 1;
	for(int i = 0; i < 2 * K - 1; i++){
		cout << an << " ";
		an++;
	}
	cout << endl;
}

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

using namespace std;

#define pb push_back
#define NL endl
#define pi 2.0*acos(0.0)
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

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

ll n, arr[100005], dp[100005];

ll calculateJump(ll pos) {
    if(pos >= n) return 0;
    if (dp[pos] != -1) return dp[pos];
    ll val2, val1 = abs(arr[pos] - arr[pos + 1]);
    if (pos + 2 <= n) val2 = abs(arr[pos] - arr[pos + 2]);
    else val2 = 1e18;
    dp[pos] = min(val1 + calculateJump(pos + 1), val2 + calculateJump(pos + 2));
    return dp[pos];
}

int main() {
    cin >> n;
    for (ll i = 1; i <= n; i++) {
        cin >> arr[i];
    }
    fill(dp, dp + n + 1, -1);
    cout << calculateJump(1) << endl;
}


Measured memory_bytes: 7512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; cin >> N >> M;
    vector<int> X(N);
    rep(i,N) cin >> X[i];

    vector<int> A(100001);
    rep(i,N) A[X[i]]++;
    vector<ll> B(M),C(M);
    rep(i,100001) {
        B[i%M] += A[i];
        C[i%M] += A[i]/2;
    }

    ll ans = 0;
    for (int i = 1; i <= M/2; i++) {
        if (M%2==0 && i == M/2) {
            ans += B[M/2]/2LL;
        } else {
            if (B[i] >= B[M-i]) {
                ans += B[M-i];
                B[i] -= B[M-i];
                ans += min(B[i]/2LL,C[i]);
            } else {
                ans += B[i];
                B[M-i] -= B[i];
                ans += min(B[M-i]/2LL,C[M-i]);
            }
        }
    }
    ans += B[0]/2LL;

    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <stdio.h>
  
int main(void){
    int l,x,y,min,max;
    long long sum;
    sum = 0;
    scanf("%d", &x);
    for (l = 0;l<x;l++){
        scanf("%d", &y);
        if(l == 0){
            min = y;
            max = y;
        }
        if (min > y){
            min = y;
        }
        if (max < y){
            max = y;
        }
        sum += y;
    }
    printf("%d %d %lld\n",min,max,sum);
    return(0);
}

Measured memory_bytes: 2708
#include <vector>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc, char* argv[])
{
	//ABC162 B
	int n, i;
	unsigned long long ans = 0;
	// N (整数10の6乗まで)

	// X(赤食) Y(緑食) A(赤) B(緑) C(無)
	// p1 p2...赤
	// q1 q2...緑
	// r1 r2...無
	//cin >> x >> y >> a >> b >> c;

	cin >> n;

	for (i = 1; i <= n; i++) {
		if ((i % 3 == 0) || (i % 5 == 0)) {
			continue;
		}
		ans += i;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 3620
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	S := Read()
	ans := 0
	wCount := 0
	for i := 0; i < len(S); i++ {
		if S[i] == 'W' {
			ans += i - wCount
			wCount++
		}
	}
	fmt.Println(ans)
}

var sc = bufio.NewScanner(os.Stdin)

func init()        { sc.Buffer(make([]byte, 256), 1e9); sc.Split(bufio.ScanWords) }
func Read() string { sc.Scan(); return sc.Text() }


Measured memory_bytes: 1280
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define debug cout << "here!"
#define pii pair<int , int>
#define pdd pair<double , double>
#define F first
#define S second
const int maxn = 1e5 * 5 + 10 , inf = 1e9 , pi = 3.14159265;
string s;
void solve(){
    
}
void in(){
    cin >> s;
    if (s[s.size() - 1] == 's'){
        s += "es";
    }
    else{
        s += "s";
    }
    cout << s;
}
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    in();
    return 0;
}


Measured memory_bytes: 3616
def mtx2vec(mtx):
    tmp = ''
    for s in mtx:
        tmp += s
    return tmp
N, M = map(int, input().split())
A = []
B = []
for _ in range(N):
    A.append(input())
for _ in range(M):
    B.append(input())

b = ''
for s in B:
    b += s
ans = 'No'
for i in range(N-M+1):
    for j in range(N-M+1):
        tmp = ''
        for k in range(M):
            tmp += A[i+k][j:j+M]
        if tmp == b:
            ans =  'Yes'
            break
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int ac = 0;
    	int wa = 0;
    	int tle = 0;
    	int re = 0;
    	for(int i = 0; i < n; i++) {
    		String temp = sc.next();
    		switch(temp) {
    			case("AC"):
    				ac++;
    				break;
    			case("WA"):
    				wa++;
    				break;
    			case("TLE"):
    				tle++;
    				break;
    			case("RE"):
    				re++;
    				break;
    		}
    	}
    	System.out.println("AC x " + ac);
    	System.out.println("WA x " + wa);
    	System.out.println("TLE x " + tle);
    	System.out.println("RE x " + re);

    }
}

Measured memory_bytes: 58740
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cstring>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>
#include<cstdio>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
//#define INF ((LLONG_MAX) / (2))
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;
#define INF 1e9+7




int main(){

    ll n;
    cin >> n;
    vector<ll> arr(n);
    REP(i,n){
        cin >> arr[i];
    }
    ll count = 0;

    for(ll i = 0;i < n;){

        ll j = i+1;
        ll tmp = arr[i];
        if(tmp < arr[j]){
            /*単調増加の部分*/
            //cout << i << " a" << endl;
            while(tmp <= arr[j] && j < n){
                tmp = arr[j];
                j++;
            }
            if(j != n){
                /*途中で単調増加しなくなった場合*/
                count++;
                i = j;
            }else{
                i = n;
                break;
            }
        }else if(tmp > arr[j]){
            //cout << i << " b" << endl;
            /*単調減少の部分*/
            while(tmp >= arr[j] && j < n){
                tmp = arr[j];
                j++;
            }
            if(j != n){
                /*途中で単調減少しなくなった場合*/
                count++;
                i = j;
            }else{
                i = n;
                break;
            }
        }else{
            //一致している場合は次の要素を調べる
            //cout << i << " c" << endl;
            i++;
        }
    }
    cout << count+1 << endl;

    return 0;
}

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



#define rep(i,n) for(int i = 0 ; i< (n);i++)

using namespace std;



typedef long long ll;

typedef pair<int,int> P;




int main(){


int n ; 
cin>>n;
	vector<int> B(n-1);
	rep(i,n-1){
	  cin>>B[i];
	 
	  }
	  //cout<<"B0"<<B[0]<<endl;
	vector<int> A(n);
		for(int i = 0 ; i < n ; i++){
		if(i==0){
			A[i]=B[0];
		  }
		if(i==n-1){
			A[i]=B[i-1];
		  }
		  else if(i!=0&&i!=(n-1)){
			  if((B[i-1]>=B[i]&&B[i]>=B[i+1])||(B[i-1]>=B[i]&&B[i]<=B[i+1])){
				  A[i]=B[i];
			}
			else if((B[i-1]<=B[i]&&B[i]<=B[i+1])||(B[i-1]<=B[i]&&B[i]>=B[i+1])){
			  A[i]=B[i-1];
			  }
		}
	//	  cout<<"A"<<i<<":"<<A[i]<<endl;
		}
		int ans=0;
		rep(i,n){
		  ans+=A[i];
		  }
		cout<<ans<<endl;
	
}


Measured memory_bytes: 256
#include<stdio.h>

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

  for(int i=0; i<100; i++){
    for(int j=0; j<100; j++){
      if(n == i*4 + j*7){
	printf("Yes\n");
	  return 0;
      }
    }
  }

  printf("No\n");
  return 0;
}


Measured memory_bytes: 128
n,m,l = [eval(x) for x in input().split()]
mat_1 = [[eval(x) for x in input().split()] for _ in range(n)]
mat_2 = [[eval(x) for x in input().split()] for _ in range(m)]
res_mat = [[sum([mat_1[i][j]*mat_2[j][k] for j in range(m)]) for k in range(l)] for i in range(n)]
[print(*res_mat[i]) for i in range(n)]

Measured memory_bytes: 8772
#include <iostream>
#include<stdio.h>
#define MAX 5000001
#define INFTY (1<<30)

using namespace std;
int n = 0, arr[MAX];

void swapNode(int index1, int index2) {
    int temp = arr[index1];
    arr[index1] = arr[index2];
    arr[index2] = temp;
}

void maxHeapify(int i) {
    //if(i > n) return;
    int left = 2*i;
    int right = 2*i+1;
    int largest = i;
    if(left <= n && right <= n) {
       int larger = arr[left] > arr[right] ? left : right;
       largest = arr[largest] > arr[larger] ? largest : larger;
    }else if(left <= n) {
        largest = arr[largest] > arr[left] ? largest : left;
    }else if(right <= n) {
        largest = arr[largest] > arr[right] ? largest : right;
    }
    if(largest != i) {
        swapNode(i, largest);
        maxHeapify(largest);
    }
}

void insertKey(int i, int key) {
    if(key < arr[i]) return;
    arr[i] = key;
    while(i > 1 && arr[i/2] < arr[i]) {
        swapNode(i, i/2);
        i = i/2;
    }
}

int insert(int key) {
    n++;
    arr[n] = -INFTY;
    insertKey(n, key);
}

int extract() {
    if(n < 1) return -INFTY;
    int res = arr[1];
    arr[1] = arr[n--];
    maxHeapify(1);
    return res;
}

int main()
{
    char com[10];
    int key;
    while(1) {
        scanf("%s", com);
        if(com[0] == 'e' && com[1] == 'n') break;
        else if(com[0] == 'i') {
            scanf("%d", &key);
            insert(key);

        }else {
            printf("%d\n", extract());
        }
    }
    return 0;
}

Measured memory_bytes: 7084
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T;
  cin >> S >> T;
  string A;
  for(int i = 0; i < S.size(); i++){
    A+=S[i];
    if(i >= T.size()){
      break;
    }
    A+=T[i];
  }
  cout << A << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  string s; cin >> s;
  int n = s.length();
  vector<vector<int> > dp(17, vector<int>(n));
  REP(j, n) dp[0][j] = (s[j] == 'L' ? j - 1 : j + 1);
  FOR(i, 1, 17) REP(j, n) dp[i][j] = dp[i - 1][dp[i - 1][j]];
  vector<int> ans(n, 0);
  REP(i, n) {
    int pos = i;
    REP(j, 17) if (100000 >> j & 1) {
      pos = dp[j][pos];
    }
    ++ans[pos];
  }
  REP(i, n) cout << ans[i] << (i == n - 1 ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 7624
#include<stdio.h>
int main(void)
{
  long tate,yoko,ura;
  scanf("%ld%ld",&tate,&yoko);
  if(tate>=2 && yoko>=2) ura=(tate-2)*(yoko-2);
  if(tate==1 && yoko==1) ura=1;
  if(tate==1 && yoko!=1) ura=yoko-2;
  if(tate!=1 && yoko==1) ura=tate-2;
  printf("%ld",ura);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;

int main()
{
    int k, x;
    cin >> k >> x;

    for(int i = x-k+1; i <= x+k-1; i++){
        if(i >= -1000000 && i <= 1000000){
            cout << i << " ";
        }
    }
    cout << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int num, i, a, b;
    a = b = 0;
    for (i = 0; i < 3; ++i)
    {
        scanf("%d", &num);
        if (num == 5)
            a++;
        else if (num == 7)
            b++;
    }
    if (a == 2 && b == 1)
        printf("YES\n");
    else
        printf("NO\n");
}

Measured memory_bytes: 128
// sandeep_007	

#include <bits/stdc++.h>
 
using namespace std;
 
#define PI acos(-1)
#define mod 1000000007
#define ll long long
#define nitro std::ios_base::sync_with_stdio (false); cin.tie(NULL)
#define pb push_back
#define mp make_pair
#define vi vector < int >
#define INV 333333336

bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b){
    return (a.second < b.second);
}

inline ll mx(ll a,ll b){
	if(a > b) return a;
	else return b;	
}

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

ll power(ll x,ll y,ll p){
    ll res = 1;   
    x = x % p;    
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
 
        y = y>>1; 
        x = (x*x) % p; 
    }
    return res;
}

int main(){
	nitro;

	#ifdef DBG
		freopen("in","r",stdin);
	#endif
	
	int n,k;
	cin >> n >> k;
	ll A[n+1];
	
	for(int i=0;i<n;i++) cin >> A[i];
	
	map < int ,int> m;
	vector < int > v;
	for(int i=0;i<n;i++){
		if(m.find(A[i]) == m.end()){
			 m[A[i]] = 1;
			 v.pb(A[i]);
		}
		else m[A[i]]+=1;		
	}
	vector < pair<int,int> > p;	
	
	if(k >= v.size())
		cout << 0 << "\n";
	else{
		for(int i=0;i<v.size();i++)
			p.pb(mp(m[v[i]],v[i]));
		
		sort(p.begin(),p.end());
		int ans = 0;
		for(int i=0;i<v.size()-k;i++){
			ans += p[i].first;
		}			
		cout << ans << "\n";
	} 
	return 0;	
}

Measured memory_bytes: 14196
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e5+5;
char s[N],c[N];
int sum[N],cnt,len,ans,mid;

int main()
{
	scanf("%s",s+1);
	len=strlen(s+1);
	for(int i=1;i<=len;++i)
	{
		if(s[i]!='x')	c[++cnt]=s[i];
		else	sum[cnt]++;
	}
	if(cnt==0)
	{
		puts("0");
		return 0;
	}
	if(cnt&1)
	{
		mid=(cnt>>1)+1;
		for(int i=mid-1;i>=1;--i)
		{
			int j=cnt+1-i;
			if(c[i]!=c[j])
			{
				puts("-1");
				return 0;
			}
		}
		for(int i=mid-1;i>=0;--i)
		{
			int j=cnt-i;
			ans+=max(sum[i],sum[j]);
			ans-=min(sum[i],sum[j]);
		}
		printf("%d",ans);
	}
	else
	{
		mid=cnt>>1;
		for(int i=mid;i>=1;--i)
		{
			int j=cnt+1-i;
			if(c[i]!=c[j])	
			{
				puts("-1");
				return 0;
			}
		}
		for(int i=mid;i>=0;--i)
		{
			int j=cnt-i;
			ans+=max(sum[i],sum[j]);
			ans-=min(sum[i],sum[j]);
		}
		printf("%d",ans);
	}
	return 0;
}

Measured memory_bytes: 640
;/*
 * Created by KeigoOgawa
 */


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <cmath>

#define INF (int)1e8
#define EPS 1e-10
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define RFOR(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)
#define debug(x) cerr << #x << ": " << x << endl
#define all(a) (a).begin(), (a).end()

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int, int> PII;

// vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len - 1) s << "\t";
    }
    return s;
}

// 2 dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
    int len = vv.size();
    for (int i = 0; i < len; ++i) {
        s << vv[i] << endl;
    }
    return s;
}

int n;
vector<int> a;


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

    cin >> n;

    REP(i, n) {
        int t;
        cin >> t;
        a.push_back(t);
    }

    sort(all(a));
    if (a.size() == 2) {
        cout << a[1] << " " << a[0] << endl;
        return 0;
    }



    int b = a[a.size() - 1];
    auto itl = lower_bound(all(a), b / 2);


    if (*itl == b) {
        cout << b << " " << a[a.size() - 2];
    } else if (abs(*itl - b / 2.0) < abs(*(itl - 1) - b / 2.0)) {
        cout << b << " " << *itl;
    } else {
        cout << b << " " << *(itl - 1);
    }
    cout << endl;


    return 0;
}


Measured memory_bytes: 892
n=int(input())
s=input().split()

count=[]
for i in s:
  if i not in count:
    count.append(i)
if (len(count)==1):print('One'),
if (len(count)==2):print('Two'),
if (len(count)==3):print('Three'),
if (len(count)==4):print('Four')

Measured memory_bytes: 38256
#include <iostream>
#include <cmath>

using namespace std;

int main(){

    int64_t N;
    cin >> N;

    int64_t ans = 1e12;
    for(int64_t i = 1; i <= sqrt(N); i++) {
        int64_t j = (N / i);
        if(i * j == N) ans = min(ans, i + j - 2);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
let rec toSlim isDown tList fList =
    match fList with
    | [] -> tList |> List.rev
    | [ a ] -> toSlim isDown (a :: tList) []
    | a :: b :: from ->
        if a = b
           || (a > b && isDown)
           || (a < b && (not isDown)) then
            toSlim isDown tList (b :: from)
        else
            toSlim (not isDown) (a :: tList) (b :: from)

let rec solve money list =
    match list with
    | [] -> money
    | [ _ ] -> money
    | a :: b :: list ->
        let num = money / a
        let rest = money % a
        let gain = b * num
        solve (gain + rest) list

stdin.ReadLine()

stdin.ReadLine().Split(" ")
|> Array.map int64
|> Array.toList
|> toSlim true []
|> solve (int64 1000)
|> printfn "%d"

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

const int maxn = 4005;

char s[maxn];
int p[maxn], p1[maxn], p2[maxn];

int main(int argc, char const *argv[])
{
  int n;
  scanf("%d", &n);
  scanf("%s", s);

  for(int i = 0; i < n; ++i){
    if(s[i] == 'R'){
      p[i] = 1;
    }else if(s[i] == 'G'){
      p1[i] = 1;
    }else {
      p2[i] = 1;
    }
  }
  for(int i = 1; i < n; ++i){
    p[i] += p[i - 1]; p1[i] += p1[i - 1]; p2[i] += p2[i - 1];
  }
  long long ans = 0;
  for(int i = 0; i < n; ++i){
    for(int j = i + 1; j < n; ++j){
      int dis = j - i;
      if(s[i] == 'R' && s[j] == 'G'){
        ans += p2[n - 1] - p2[j];
        if(j + dis < n){
          if(s[j + dis] == 'B')ans--;
        }
      }
      if(s[i] == 'R' && s[j] == 'B'){
        ans += p1[n - 1] - p1[j];
        if(j + dis < n){
          if(s[j + dis] == 'G')ans--;
        }
      }
      if(s[i] == 'B' && s[j] == 'R'){
        ans += p1[n - 1] - p1[j];
        if(j + dis < n){
          if(s[j + dis] == 'G')ans--;
        }
      }
      if(s[i] == 'G' && s[j] == 'R'){
        ans += p2[n - 1] - p2[j];
        if(j + dis < n){
          if(s[j + dis] == 'B')ans--;
        }
      }
      if(s[i] == 'G' && s[j] == 'B'){
        ans += p[n - 1] - p[j];
        if(j + dis < n){
          if(s[j + dis] == 'R'){
            ans--;
          }
        }
      }
      if(s[i] == 'B' && s[j] == 'G'){
        ans += p[n - 1] - p[j];
        if(j + dis < n){
          if(s[j + dis] == 'R')ans--;
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}

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


using namespace std;

int main(){
    string S;
    cin >> S;

    if(S[0] != 'A'){
        cout << "WA" << endl;
        return 0;
    }
    bool flag = false;
    for(int i = 1; i < S.size(); i++){
        if(S[i] <= 'Z'){
            if(S[i] != 'C'){
                cout << "WA" << endl;
                return 0;
            }else{
                if(flag == true || i == 1 || i == S.size()-1){
                    cout << "WA" << endl;
                    return 0;
                }
                flag = true;
            }
        }
    }
    if(flag == true){
        cout << "AC" << endl;
    }else{
        cout << "WA" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
// abc162_a
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  int n,cnt=0;
  cin>>n;
  while(n>0){
    if (n%10==7) cnt++;
    n/=10;
  }

  if (cnt)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <cstring>
#include <algorithm>
#include <set>
#include <climits>
#include <numeric>

//usings
using namespace std;

//type def
typedef long long int64;
typedef pair<int, int> ii;

//consts
const int mod = 1e9 + 7;

//methods
template<typename T>
bool chmax(T& source, const T& compare_to) {
    if(source < compare_to) {
        source = compare_to;
        return true;
    }
    return false;
}

int modpow(int64 base, int n) {
    int64 ret = 1;
    while(n) {
        if(n & 1) ret = ret * base % mod;
        base = base * base % mod;
        n >>= 1;
    }
    return ret;
}

class Solution {
private:
public:
    int64 KthStepNumber(int k) {
        if(k < 10) return k;
        queue<int64> q;
        for(int i = 1; i < 10; ++i) q.push(i);
        for(int i = 9; i < k; ) {
            auto& f = q.front();
            int64 a = f * 10, b = f % 10, next_num = 0;
            if(b) {
                next_num = a + b - 1;
                if(++i == k) return next_num;
                q.push(next_num);
            }
            next_num = a + b;
            if(++i == k) return next_num;
            q.push(next_num);
            if(b != 9) {
                next_num = a + b + 1;
                if(++i == k) return next_num;
                q.push(next_num);
            }
            q.pop();
        }
        return -1;
    }
};

int main() {
    int k;
    cin >> k;
    Solution sol;
    auto ret = sol.KthStepNumber(k);
    cout << ret << endl;
}

Measured memory_bytes: 768
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    L = lmi()
    print(sum(L) - n)    


if __name__ == "__main__":
    main()


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

int main() {
  string S;
  cin >> S;
  int ans=0;
  
  for(int i=0; i<4; i++) {
    if(S.at(i) == '+') ans++;
    else ans--;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 3620
i = list(map(int, input().split()))
n = i[0]
s = 0

if(n==100000):
    s = 90909
elif(n>=10000):
    s = n - 9999 + 900 + 9
elif(n>=1000):
    s = 900 + 9
elif(n>=100):
    s = n - 99 + 9
elif(n>=10):
    s = 9
else:
    s = n

print(s)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
const int N = ((int)1e5) + 5;
const int M = ((int)1e3) + 5;
const int mod = 2019;
 
long long int l,r;
 
int main ()
{
	fast;
	cin >> l >> r;
 
	if (r - l >= 2019)
		return cout << 0,0;
	long long int a = INT_MAX;
	for (int i = l; i <= r - 1; i++)
	{
		for (int j = i + 1; j <= r; j++)
		{
			a = min(a,((long long int)i * j) % mod);
		}
	}
	cout << a;
}

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

const long long LEN = 1e9;

int main() {
  #ifdef LOCAL
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
  #endif
  ios::sync_with_stdio(false);
  long long s;
  cin >> s;
  if (s % LEN == 0) {
    cout << 0 << ' ' << 0 << ' ' << 0 << ' ' << (int)(LEN) << ' ' << s / LEN << ' ' << 0;
    return 0;
  } 
  long long y = s / LEN * LEN + LEN - s;
  cout << 0 << ' ' << (int)(LEN) << ' ' << 1 << ' ' << 0 << ' ' << (s / LEN + 1) << ' ' << LEN - y;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt()-1;
        int m = in.nextInt();
        int[] s = new int[m];
        String[] c = new String[m];
        for(int i=0; i<m; i++) {
            s[i] = in.nextInt();
            c[i] = in.next();
        }
        int start = (int)Math.round(Math.pow(10, n));
        int end = start*10;
        if(start==1) {
            start = 0;
        }

        for(int i=start; i<end; i++) {
            String str = Integer.toString(i);
            boolean isOK = true;
            for(int j=0; j<m; j++) {
                if(!str.substring(s[j]-1, s[j]).equals(c[j])) {
                    isOK = false;
                    break;
                }
            }
            if(isOK) {
                System.out.println(i);
                return;
            }
        }
        System.out.println(-1);
    }
}


Measured memory_bytes: 21972
import java.util.Scanner;

//AtCoder Beginner Contest 155
//A	Poor
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = Integer.parseInt(sc.next());
		int B = Integer.parseInt(sc.next());
		int C = Integer.parseInt(sc.next());
		sc.close();

		String ans = "No";
		if (A == B) {
			if (A != C) {
				ans = "Yes";
			}
		} else if (A == C) {
			if (A != B) {
				ans = "Yes";
			}
		} else if (B == C) {
			if (A != B) {
				ans = "Yes";
			}
		}
		System.out.println(ans);
	}
}


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

int main() {
  string s,ans="Yes"; cin>>s;
  for(int i; i<s.size(); i++){
    if ((i+1)%2==1 && s[i]=='L') ans="No";
    else if ((i+1)%2==0 && s[i]=='R') ans="No";
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

std::string S;
int cnt[2];

int main()
{
  std::cin >> S;

  rep( i, S.size() )
    ++cnt[S[i]-'0'];

  printf( "%d\n", 2*std::min( cnt[0], cnt[1] ) );

  return 0;
}

Measured memory_bytes: 512
my $s = <STDIN>;
my ($N,$M) = split(/\s+/,$s);
my $count=0;
my $flag = 0;
if($N==4){ $flag =1;}
for(my $i=1;$i<=$M;$i++){
    printf "%d %d\n",$i,$N-$i-$flag;
    if( $N%2==0 && $i==int(($N-1)/4)){$flag =1;}
}


Measured memory_bytes: 4812
#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 1000003
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c));
#define max3(a,b,c) max(a,max(b,c));
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define sumall(v) accumulate(all(v),(ll)0)
#define suma accumulate
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define br "\n"
#define sp " "
#define zero (ll)0
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<bool>vbool ;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<" " ;}cout<<"\n" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
ll n,m,k,x,y;
bool ok = false;
int main()
{
    FastIO ;
    PRECISION(10) ;
    ll a,b,c,d,i,j,t;//,x,y,z;//,x1,y1,z1,e,f;
    ll p,q,r,u,w ;
    char ch,chr ;
    string str,st,str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    //Stay Motivated!!
    //Never use i for two or more nested loops!!
    //Range Query + Constructive + DSU  +  Graph Theory + Math + DP + Bitmasks + Geometry + Brute Force + Implementation + Binary Search
    cin>>n;
    for(i=-1003 ; i<=1003 ; i++)
    {
        for(j=-1003 ; j<=1003 ; j++)
        {
            a = sqr(i)*sqr(i)*i - sqr(j)*sqr(j)*j;
            if(a==n)
            {
                cout<<i<<" "<<j;
                exit(0);
            }
        }
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char s1[10];
    cin>>s1;
    if(s1[0]==s1[1] && s1[1]==s1[2] || s1[1]==s1[2] && s1[2]==s1[3])
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}




Measured memory_bytes: 256
## main

rtr = atr = otr = 0

loop do
  a, b, c = gets.strip.split(' ').map{|s| s.to_i}

  if a >= b + c || b >= c + a || c >= a + b
    total = rtr + atr + otr
    puts [total, rtr, atr, otr].join(' ')
    break
  end

  a2 = a * a
  b2 = b * b
  c2 = c * c

  if a2 == b2 + c2 || b2 == c2 + a2 || c2 == a2 + b2
    rtr += 1
  elsif a2 > b2 + c2 || b2 > c2 + a2 || c2 > a2 + b2
    otr += 1
  else
    atr += 1
  end
end

Measured memory_bytes: 6108
#include<iostream>
#include<algorithm>
using namespace std;
int p[1001],n,a,b,c,d;
pair<int,int>q[1001];
int main(){
	cin>>n;
	for(int i=0;i<n*(n-1)/2;i++){
		cin>>a>>b>>c>>d;
		if(c>d){p[a]+=3;}
		if(c==d){p[a]+=1;p[b]+=1;}
		if(c<d){p[b]+=3;}
	}
	for(int i=1;i<=n;i++){q[i]=make_pair(-p[i],i);}
	sort(q+1,q+n+1);int J=1;
	for(int i=1;i<=n;i++){
		if(i>=2 && q[i].first!=q[i-1].first)J=i;
		p[q[i].second]=J;
	}
	for(int i=1;i<=n;i++)cout<<p[i]<<endl;
	return 0;
}

Measured memory_bytes: 3088
import numpy as np

#k ,n = list(map(int,(input().split())))
#a = list(map(int,(input().split())))
#a = np.array(a)
#sp = np.diff(a)
#print((sum(sp)))

x = int(input())
n500 = x//500
n5 = (x - n500*500 )//5
ans = n500 * 1000 + n5 * 5
print(ans)

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

using namespace std;

int main() {
	long long x;
	cin >> x;

	long long ans = 0;

	ans += (x - x % 500) * 2;

	x %= 500;

	ans += x - x % 5;

	cout << ans << '\n';

	return 0;
}

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

using namespace std;

#define fastio cin.tie(NULL);cout.tie(NULL);ios_base::sync_with_stdio(0);
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define MAXN 200005
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define pb push_back
#define endl '\n'

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vii;
typedef vector <vi> matriz;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// auto timer_start = chrono::steady_clock::now().time_since_epoch().count();

int a, b, c, n, m, k;
string s, t, u;

int p(string ss, int asd){
    vi pi(sz(ss));
    pi[0] = 0;
    int j = 0, tam = sz(ss);
    for(int i = 1; i < tam; i++){
        j = pi[i - 1];
        while(j > 0 && ss[i] != ss[j]) j = pi[j - 1];
        if(ss[i] == ss[j]) j++;
        pi[i] = j;
        if(pi[i] == asd) return 1;
        // cout << ss[i] << " " << pi[i] << endl;
    }
    return 0;
}

int32_t main(){
    fastio
    cin >> n >> s;
    int res = 0;
    string left = "";
    left += s[0];
    for(int i = 1; i < sz(s); i++){
        string ss = "";
        int l = 1, r = i;
        int mid;
        while(l <= r){
            mid = (l + r) / 2;
            string aux = s.substr(i, mid) + "#" + left;
            if(mid > i or p(aux, mid) == 0) r = mid - 1;
            else {
                res = max(res, mid);
                l = mid + 1;
            }
        }
        // for(int j = i; j < sz(s); j++){
        //     ss += s[j];
        //     if(sz(ss) > sz(left)) break;
        //     // cout << mapa[ss] << endl;
        //     string aux = ss + "#" + left;
        //     // cout << ss << " " << p(aux) << " " << left << endl;
        //     if(p(aux, sz(ss)) != 0) res = max(res, sz(ss));
        // }
        left += s[i];
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 384
s=input()
l=len(s)
kq=1
for i in range(l):
  if(i%2==0):
    if(s[i]=='L'):
      kq=0
      break
  else:
    if(s[i]=='R'):
      kq=0
      break
if(kq==0):
  print('No')
else:
  print('Yes')

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

int main()
{
    int n;
    cin >> n;

    string s, t;
    cin >> s >> t;

    rep (i, n)
    {
        cout << s[i];
        cout << t[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; 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(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
char notes[110][10];
ll treasure[3030][3030];
ll dp[3030][3030][4];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll r, c, n;
	cin >> r >> c >> n;
	rep(i, r) {
		rep(j, c) {
			treasure[i][j] = 0;
		}
	}
	rep(i, n) {
		ll x, y, v;
		cin >> x >> y >> v;
		x--;
		y--;
		treasure[x][y] = v;
	}
	rep(i, r) {
		rep(j, c) {
			for (ll k = 2;k >= 0;--k) {
				dp[i][j][k + 1] = max(dp[i][j][k + 1], dp[i][j][k] + treasure[i][j]);
			}
			rep(k, 4) {
				dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
				dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
			}
		}
	}
	ll ans = 0;
	rep(k, 4) {
		ans = max(ans, dp[r - 1][c - 1][k]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 358812
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
	double r = sc.nextDouble();
	
	double area = Math.PI * (double)r * (double)r; 
        double cir = Math.PI * 2 * (double)r ;
	
	System.out.printf("%6f",area);
	System.out.printf(" ");
	System.out.printf("%6f\n",cir);	
  }
	


}

Measured memory_bytes: 28120
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;
import java.util.jar.JarOutputStream;

public class Main {

    public static void recurse(ArrayList<ArrayList<Integer>> adj, int[] dp,int[] visited, int v){

        visited[v]=1;

        for(int i=0;i<adj.get(v).size();i++){
            if(visited[adj.get(v).get(i)]!=1){
                recurse(adj,dp,visited,adj.get(v).get(i));
            }
            dp[v]=Math.max(dp[v],dp[adj.get(v).get(i)]+1);

        }
    }

    public static void main(String[] args) throws IOException {

        Reader.init(System.in);
        int n = Reader.nextInt();
        double[] prob=new double[n];
        for(int i=0;i<n;i++){
            prob[i]=Reader.nextDouble();
        }
        double[][] dp=new double[n+1][n+1];
        dp[0][0]=1;

        for(int i=1;i<=n;i++){
            for(int j=0;j<=i;j++){
                if(j==0){
                    dp[i][j] = dp[i-1][j]*(1-prob[i-1]);
                }
                else{
                    dp[i][j] = dp[i-1][j]*(1-prob[i-1])+dp[i-1][j-1]*prob[i-1];
                }
            }
        }
        double ans=0;
        for (int i = (n + 1) / 2; i <= n; i += 1){
            ans += dp[n][i];
        }
        System.out.println(ans);
    }

}






class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    /** call this method to initialize reader for InputStream */
    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input) );
        tokenizer = new StringTokenizer("");
    }

    /** get next word */
    static String nextLine() throws IOException {
        while ( ! tokenizer.hasMoreTokens() ) {
            //TODO add check for eof if necessary
            tokenizer = new StringTokenizer(
                    reader.readLine() );
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt( nextLine() );
    }
    static long nextLong() throws IOException {
        return Long.parseLong(nextLine());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble( nextLine() );
    }

    static float nextFloat() throws IOException {
        return Float.parseFloat( nextLine() );
    }
    static int[] nextIntArray(int length) throws IOException {
        int[] arr = new int[length];
        //System.out.println(length);
        for (int i=0; i<length; i++) {
            arr[i] = Integer.parseInt( nextLine() );
            //System.out.println(arr[i]);
        }
        //System.out.println(arr);
        return arr;
    }
    static long[] nextLongArray(int length) throws IOException {
        long[] arr = new long[length];
        for (int i=0; i<length; i++) {
            arr[i] = Long.parseLong( nextLine() );
        }
        return arr;
    }

}



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

int main()
{
    int h, w;
    while (1)
    {
        cin >> h >> w;
        if (h == 0 && w == 0)
            break;
        rep(i, h)
        {
            rep(j, w)
            {
                if ((j + (i % 2)) % 2 == 0)
                {
                    cout << "#";
                }
                else
                {
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
// 2012/12/10 Tazoe

#include <iostream>
using namespace std;

int main()
{
while(true){
	int T;
	cin >> T;

if(T==0)
break;

	int P[10];
	for(int i=0; i<9; i++){
		cin >> P[i];
	}

	P[9] = T;
	for(int i=0; i<9; i++){
		P[9] -= P[i];
	}

	cout << P[9] << endl;
}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e10;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double



////////////////////////////////////////////////////////////////////


////////////////////////////////////////////////////////////////////i

int a[10], ans1, ans2;
signed main(){
  rep(i,7)cin>>a[i];
  ans1 = ans2 = a[1];
  ans1 += (a[0]/2)*2;
  ans1 += (a[3]/2)*2;
  ans1 += (a[4]/2)*2;

  if(a[0] && a[3] && a[4]){
    ans2 += 3;a[0]--;a[3]--;a[4]--;
  }
  ans2 += (a[0]/2)*2;
  ans2 += (a[3]/2)*2;
  ans2 += (a[4]/2)*2;
  cout << max(ans1, ans2) << endl;
}





Measured memory_bytes: 256