akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}

using namespace std;
typedef long long int llint;

int main (void) {
	int k, s; cin >> k >> s;
	int result = 0;
	int total;
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			total = s - i - j;
			if (0 <= total && total <= k) {
				result++;
			}
		}
	}
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <list>

using namespace std;



int main() {
    set<string> se;
    int n;scanf("%d",&n);
    for(int i=0;i<n;i++){
        string str;
        cin>>str;
        se.insert(str);
    }
    if(se.size()==3){
        printf("Three");
    }else if(se.size()==4){
        printf("Four");
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

LL even = 0;
LL odd = 0;

LL n,m;
vector<vector<LL>> graph;
vector<LL> state;
vector<bool> point;

bool dfs(LL ind,LL pre,bool frag){
    bool ret = true;
    state[ind] = 1;
    point[ind] = frag;
    if(frag){
        odd++;
    }else{
        even++;
    }
    for(int i = 0; i < graph[ind].size(); i++){
        if(graph[ind][i] == pre){
            continue;
        }
        if(state[graph[ind][i]] == 1){
            if(point[graph[ind][i]] == !frag){
                continue;
            }
            return false;
        }else if(state[graph[ind][i]] == 0){
            ret &= dfs(graph[ind][i],ind,!frag);
        }
    }
    return ret;
}

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

    cin >> n >> m;
    
    graph = vector<vector<LL>>(n+1);
    state = vector<LL>(n+1,0);
    point = vector<bool>(n+1);

    for(int i = 0; i < m; i++){
        LL a,b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    if(dfs(1,-1,true)){
        cout << even*odd - m << endl;
    }else{
        cout << ((n-1)*n)/2 - m << endl;
    }

    return 0;
}

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

const int INF = 1e9 + 5;

int main(){
    int a,b,c,d;

    scanf("%d%d%d%d", &a, &b, &c, &d);

    while(true){
        c = c -b;
        if(c <= 0){
            printf("Yes");
            break;
        }
        a = a - d;
        if(a <= 0){
            printf("No");
            break;
        }

    }


    return 0;
}

Measured memory_bytes: 3720
#include<stdio.h>
int main(){
  int d[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int n;
  scanf("%d",&n);
  printf("%d\n",d[n-1]);
  return 0;
}      


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char[]ss = S.toCharArray();
        
        Arrays.sort(ss);
        if(ss[0]==ss[1] && ss[2]==ss[3] && ss[0]!=ss[3]){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
	}
}

Measured memory_bytes: 22740
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define all(v) v.begin(),v.end()
#define itr(r,v) for(auto r=v.begin();r!=v.end();r++)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffo(i,a,b) for(ll i=a;i<=b;i++)
#define rfr(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl "\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vll,greater<ll>>
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define ctime auto sttart = high_resolution_clock::now()
#define etime auto sttop = high_resolution_clock::now()
#define go_t ll testcases; cin>>testcases; for(ll caseno= 1 ;caseno <= testcases; caseno++)
#define ptime auto z1z = duration_cast<microseconds>(sttop-sttart); cout<<"\nTime taken : "<<z1z.count()<<" microseconds\n"
#define dbg1(x)             cout <<#x<<": "<<x<<'\n';
#define dbg2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<'\n';
#define dbg3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<'\n';
#define dbg4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<'\n';
#define dbg5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<'\n';

using namespace std;
using namespace std::chrono;

const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
const ll maxN = 3e3 + 5;
const ll MAX_SIZE = 2e6 + 6;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const double PI = 3.14159265359;

ll powerM(ll x, ll y, ll M = MOD) { // default argument
	ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;
}

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

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	FIO
	ll n; cin >> n;
	double ph[n];
	FOR(i, n) cin >> ph[i];
	double dp[n + 1][n + 1] = {};
	// dp[i][j] means that till position i, we have j number of heads and i - j number of tails
	dp[0][0] = 1.00;
	for (ll i = 1; i <= n; i++) {
		dp[i][0] = dp[i - 1][0] * (1.00 - ph[i - 1]);
		for (ll j = 1; j <= i; j++) {
			dp[i][j] = (dp[i - 1][j - 1] * 1.0 * ph[i - 1]) + (dp[i - 1][j] * (1.00 - ph[i - 1]));
		}
	}
	double ans = 0.0;
	for (ll i = (n + 1) / 2; i <= n; i++) {
		ans += dp[n][i];
	}
	cout << fixed << setprecision(10) << ans;
	return 0;
}


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

int main(){
    string a,b; cin>>a>>b;

    string c=a+b;

    double x=stoi(c);

    int root=sqrt(x);

    if(pow(root,2)==x)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
long long a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
int main()
{
	cin>>a>>b>>h;
	cout<<(a+b)*h/2<<endl;
	return 0;
}//

Measured memory_bytes: 256
#include<set>  
#include<map>  
#include<stack>  
#include<cmath>  
#include<cstdio>  
#include<queue>  
#include<vector>  
#include<climits>  
#include<cstring> 
#include<iostream> 
#include<algorithm> 
using namespace std; 
#define LL long long
#define MAXN 100000
const long long H=1000000000000000ll,INF=1000000000000000ll;
LL read(){ 
    LL f=1,x=0; 
    char c=getchar(); 
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();} 
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();} 
    return f*x;
}
struct edge{
	int v;LL w;
	edge(){}
	edge(int V,LL W){v=V,w=W;}
};
int n,m,s,t;
LL disy[MAXN+5],disd[MAXN+5];
bool vis[MAXN+5];
queue<int>Q;
vector<edge> G[2][MAXN+5];
void SPFA(int C,int S){
	memset(vis,0,sizeof(vis));
	if(!C) memset(disy,0x3f3f3f,sizeof(disy)),disy[S]=0;
	else memset(disd,0x3f3f3f,sizeof(disd)),disd[S]=0;
	vis[S]=1,Q.push(S);
	while(!Q.empty()){
		int u=Q.front();
		Q.pop(),vis[u]=0;
		int siz=G[C][u].size();
		for(int i=0;i<siz;i++){
			int v=G[C][u][i].v;
			LL w=G[C][u][i].w;
			if(!C&&disy[v]>disy[u]+w){
				disy[v]=disy[u]+w;
				if(!vis[v])
					vis[v]=1,Q.push(v);
			}
			else if(C&&disd[v]>disd[u]+w){
				disd[v]=disd[u]+w;
				if(!vis[v])
					vis[v]=1,Q.push(v);
			}
		}
	}
	return ;
}
LL ans[MAXN+5];
int main(){
	n=read(),m=read(),s=read(),t=read();
	for(int i=1;i<=m;i++){
		int u=read(),v=read(),w1=read(),w2=read();
		G[0][u].push_back(edge(v,w1));
		G[0][v].push_back(edge(u,w1));
		G[1][u].push_back(edge(v,w2));
		G[1][v].push_back(edge(u,w2));
	}
	SPFA(0,s);
	SPFA(1,t);
	ans[n+1]=INF;
	for(int i=n;i>=1;i--)
		ans[i]=min(ans[i+1],disy[i]+disd[i]);
	for(int i=1;i<=n;i++)
		printf("%lld\n",H-ans[i]);
    return 0;
}

Measured memory_bytes: 19200
n = int(input())
*A, = map(int, input().split())
q = int(input())
*M, = map(int, input().split())

MAX = max(M)
dp = [[0]*(MAX+1) for _ in range(n+1)]
chk = [[0]*(MAX+1) for _ in range(n+1)]


def solve(i, m):
    if not 0 <= m <= MAX:
        return False
    if 1 <= n and chk[i][m]:
        return dp[i][m]

    elif m == 0:
        dp[i][m] = True
    elif i >= n:
        dp[i][m] = False
    elif solve(i+1, m):
        dp[i][m] = True
    elif solve(i+1, m - A[i]):
        dp[i][m] = True
    else:
        dp[i][m] = False

    chk[i][m] = 1
    return dp[i][m]


for m in M:
    print('yes' if solve(0, m) else 'no')



Measured memory_bytes: 6292
import java.io.InputStream;
import java.util.Scanner;

class Main {
	
	public static void main(String[] args){
		
		Scanner In = new Scanner(System.in);
		
		int x = In.nextInt();
	
		int y = In.nextInt();

		int sum = x * y;

		int sum2 = x * 2 + y * 2;
		
		System.out.print(sum);
		System.out.print(" ");
		System.out.println(sum2);
		
}
}

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

typedef long long ll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

const char nl = '\n';

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
    int n, k; cin >> n >> k;
    int a[n];
    F0R(i, n) {
        cin >> a[i];
    }
    cout << ceil((double)(n - 1) / (k - 1)) << nl;
}

Measured memory_bytes: 4168
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>>h(200001);

    for(int i=0; i<m; i++){
        int a, b;
        cin >> a >> b;
        h[b].push_back(a);
        if(b==n){
            for(int i=0; i<h[a].size(); i++){
                if(h[a][i]==1){
                    puts("POSSIBLE");
                    return 0;
                }
            }
        }
    }

    for(int i=0; i<h[n].size(); i++){
        int t = h[n][i];
        for(int j=0; j<h[t].size(); j++){
            if(h[t][j]==1){
                puts("POSSIBLE");
                return 0;
            }
        }
    }

    puts("IMPOSSIBLE");
    
    return 0;
}

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

int gcd(int x,int y){
  if (y==0){
    return x;
  }
  return gcd(y,x%y);
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0;i<N;i++){
    cin >> A[i];
  }
  vector<int> gcd1(N);
  vector<int> gcd2(N);
  gcd1[0]=A[0];
  gcd2[N-1]=A[N-1];
  for (int i=1;i<N;i++){
    gcd1[i]=gcd(gcd1[i-1],A[i]);
  }
  for (int i=N-2;i>=0;i--){
    gcd2[i]=gcd(gcd2[i+1],A[i]);
  }
  int ans=max(gcd2[1],gcd1[N-2]);
  for (int i=1;i<N-1;i++){
    ans=max(ans,gcd(gcd1[i-1],gcd2[i+1]));
  }
  cout << ans << endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n; cin >> n;
    ll ans = 0;
    rep3(a, 1, n-1){
        ans += n/a;
        if(n % a == 0) ans--;
    }
    cout << ans << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3624
module Main where

import Data.Maybe (fromJust)
import Control.Monad

import Data.List
import qualified Data.ByteString.Char8 as BS

import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM


bytestr2Int = fst . fromJust . BS.readInt
getInt = bytestr2Int <$> BS.getLine
getIntL_V n = replicateM n $ getInt
getIntL_H = map bytestr2Int. BS.words <$> BS.getLine
getIntM n = replicateM n $ getIntL_H


main :: IO ()
main = do
    [n,k,q] <- getIntL_H
    qs <- getIntL_V q
    mapM_ putStrLn =<< checkLive <$> (reducePoint qs $ makeInitilPoints n k q)


checkLive :: VU.Vector Int -> [String]
checkLive vec = map sayYes . VU.toList $ VU.map ((<)0) vec

sayYes True = "Yes"
sayYes _ = "No"


makeInitilPoints :: Int -> Int -> Int -> VU.Vector Int
makeInitilPoints n k q = VU.replicate n (k-q)

reducePoint :: [Int] -> VU.Vector Int -> IO (VU.Vector Int)
reducePoint qs vec = do
    mvec <- VU.thaw vec
    forM_ qs $ \i -> do
        VUM.modify mvec (+1) (i-1)
    VU.freeze mvec



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

int fact(int n)
{
    return(n==1||n==0)?1:fact(n-1)*n;
}

main()
{
    int N,M,p=0;
    cin>>N>>M;
    if(N>1)
        p+=(N*(N-1)/2);
    if(M>1)
        p+=(M*(M-1)/2);
    cout<<p<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
ns = list(map(int, input().split()))
dp = [[0] * n for i in range(n+1)]
for i in range(n+1, -1, -1):
    for j in range(i, n):
        if n % 2 == (i + j+1) % 2:
            dp[i][j] = max(dp[i + 1][j] + ns[i], dp[i][j - 1] + ns[j])
        else:
            dp[i][j] = min(dp[i + 1][j] - ns[i], dp[i][j - 1] - ns[j])
print(dp[0][-1])

Measured memory_bytes: 112604
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using BigInt = long long;
using BigFloat = long double;
#define ALL(a)  (a).begin(),(a).end()
 
int main(){
    BigFloat W,H,x,y;
    cin >> W >> H >> x >> y;
    if (W / 2 == x && H / 2 == y){
        cout << W * H / 2 << " " << 1 << endl;
    } else {
        cout << W * H / 2 << " " << 0 << endl;
    }
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {

	// input
	params := inputLineAsNumArray(5)
	pA := float64(params[0])
	pB := float64(params[1])
	pAB := float64(params[2])
	rA := params[3]
	rB := params[4]

	var a, b, ab int
	//created
	cA := 0
	cB := 0

	sum := 0.0
	if pAB < (pA+pB)/2 {
		min := min(rA, rB)
		sum += float64(min) * 2 * pAB
		cA += min
		cB += min

		ab += min * 2
	}

	if 2*pAB < pA {
		toCreate := (rA - cA)
		sum += float64(toCreate) * 2 * pAB
		cA += toCreate
		cB += toCreate

		ab += toCreate * 2
	}

	if 2*pAB < pB {
		toCreate := (rB - cB)
		sum += float64(toCreate) * 2 * pAB
		cA += toCreate
		cB += toCreate

		ab += toCreate * 2
	}

	if (rA - cA) > 0 {
		toCreate := (rA - cA)
		sum += float64(toCreate) * pA

		a += toCreate
	}

	if (rB - cB) > 0 {

		toCreate := (rB - cB)
		sum += float64(toCreate) * pB

		b += toCreate
	}

	fmt.Println(int(math.Ceil(sum)))
}

func min(x, y int) int {
	if x <= y {
		return x
	} else {
		return y
	}
}

func max(x, y int) int {
	if x >= y {
		return x
	} else {
		return y
	}
}

func inputLineAsNumArray(length int) []int {

	line := strings.Split(readLine(), " ")
	var nums []int
	for i := 0; i < length; i++ {
		num, _ := strconv.Atoi(line[i])
		nums = append(nums, num)
	}
	return nums
}

func readLine() string {

	sc.Scan()
	return sc.Text()
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    vector<P> lis;

    int N; cin >> N;

    for (int i = 0;i < N;i++){
        int x,y; cin >> x >> y;
        lis.push_back(P(x,y));
    }

    map<P,int> mp;
    int ans = 0;

    for (int i = 0;i < N;i++){
        for (int j = 0;j < N;j++){
            if(i == j) continue;
            mp[P(lis[i].first-lis[j].first,lis[i].second-lis[j].second)]++;
            ans = max(ans,mp[P(lis[i].first-lis[j].first,lis[i].second-lis[j].second)]);
        }
    }

    cout << N-ans << endl;

    return 0;

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1001001001;

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n) {
		if (n & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	string s;
	while (true) {
		cin >> s;
		if (s == "0") break;
		int sum = 0;
		for (int i = 0; i < s.size(); i++) {
			sum += s[i] - '0';
		}
		cout << sum << endl;
	}
}


Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <climits>
#include <cmath>
#include <unordered_map>

using namespace std;

typedef long long ll;

int main(void) {
  int N;
  cin >> N;
  cout << (180 * (N - 2)) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int r,c,k;
ll dp[3010][3010][4];
ll items[3010][3010];

void solve(){
  cin >> r >> c >> k;
  rep(i,k){
    int x,y,v;
    cin >> x >> y >> v;
    items[x][y]=v;
  }
  rep(i,r+1){
    rep(j,c+1){
      rep(p,4){
        if(i+1<=r)dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][p]);
        if(i+1<=r)dp[i+1][j][1]=max(dp[i+1][j][1],dp[i][j][p]+items[i+1][j]);
        if(j+1<=c)dp[i][j+1][p]=max(dp[i][j+1][p],dp[i][j][p]);
        if(j+1<=c) if(p<3)dp[i][j+1][p+1]=max(dp[i][j+1][p+1],dp[i][j][p]+items[i][j+1]);
      }
    }
  }
  // rep(i,r+1){
  //   rep(j,c+1){
  //     rep(p,4){
  //       cout << i << " " << j << " " << p << " " << dp[i][j][p] << endl;
  //     }
  //   }
  // }
  ll ans=0;
  rep(p,4){
    ans=max(ans,dp[r][c][p]);
  }
  cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 356364
#include<stdio.h>
#include<algorithm>
int p2[30];
int next[100010][30]={0};
int x[100010];
void init(void){
	p2[0]=1;
	for (int i=1;i<=20;i++) p2[i]=p2[i-1]*2;
}
int main(void){
	init();
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d",x+i);
	}
	int l;
	scanf("%d",&l);
	int p=1;
	for (int i=1;i<n;i++){
		for (;p<=n&&x[i]+l>=x[p];p++);
		next[i][0]=p-1;
	}
	for (int j=1;j<=20;j++){
		for (int i=1;i<=n;i++)next[i][j]=next[next[i][j-1]][j-1];
	}
	int q;
	scanf("%d",&q);
	while (q--){
		int a, b;
		scanf("%d%d",&a,&b);
		if (a>b) std::swap(a,b);
		int ans=0;
		while (a<b){
			int j;
			for (j=1;next[a][j]>0&&next[a][j]<=b;j++);
			a=next[a][j-1];
			ans+=p2[j-1];
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 12928
#define TST 0
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)
#define printM(a, n, m) F(i, 0, n){ FE(j, 0, m) cout << a[i][j] << (i==m?'\n':' ');}

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

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;
}

#define printMatrix(mat,n,m){ \
    F(i, 0, n){               \
        F(j, 0, m){           \
            cout << mat[i][j] << space;\
        }\
        cout << endl;\
    }\
}

int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    vl stack;
    string input;
    while(cin >> input){
        if(input == "+" || input == "-" || input == "*"){
            long last1 = stack[stack.size()-1];
            long last2 = stack[stack.size()-2];
            stack.pop_back();
            stack.pop_back();
            long res;
            if(input == "+"){
                res = last1 + last2;
            }else if(input == "-"){
                res = last2 - last1;
            }else if(input == "*"){
                res = last1 * last2;
            }
            stack.pb(res);
            continue;
        }
        char * end;
        long inp = strtol(&input[0], &end, 10);
        stack.pb(inp);
    }
    long ans = stack[stack.size()-1];
    
#if TST==1
#endif
    cout << ans << endl;
}



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

char stop[] ="0123456789543210123456789";

void solve(int start,int goal) {
  int ans = 10000;int pos = 0;
  for(int i=0;i<25;i++) {
    if(stop[i] != start + '0') continue;
    //stop[i] == goal
    for(int j=i+1;j<25;j++) {
      if(stop[j] == goal + '0') {
        ans = min(ans,j-i);pos = i;
        continue;
      }
    }
  }
  for(int i = pos;i<=pos + ans;i++) {
    cout << ( i==pos ? "":" ") << stop[i];
  }
  cout << endl;
}

int main() {
  int n,f,t;
  cin >> n;
  for(int i=0;i<n;i++) {
    cin >> f >> t;
    solve(f,t);
  }
}

Measured memory_bytes: 0
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
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; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  vi v(31);
  v[0] = v[1] = 1;
  v[2]        = 2;
  loop(i, 3, 31) v[i] = v[i - 1] + v[i - 2] + v[i - 3];
  int n;
  while (cin >> n, n) cout << (v[n] + 3659) / 3650 << endl;
}

Measured memory_bytes: 2956
N=gets.to_i
a=gets.chomp.split.map(&:to_i)
b=gets.chomp.split.map(&:to_i)
s = 0
t = 0 
N.times do |i|
  s += a[i] - b[i] if a[i] > b[i]
  t += (b[i] - a[i]) / 2 if a[i] < b[i]
end
puts t >= s ? 'Yes' : 'No'



Measured memory_bytes: 3068
D = int(input())
clist = list(map(int, input().split()))
slist = [list(map(int, input().split())) for _ in range(D)]
tlist = [int(input()) for _ in range(D)]
zlist = []
dlist = [0] * 26
ans = 0
'''
print(sum(clist))
print('--------------')
print(slist[0][0])
print(slist[1][16])
print(clist[16])

print('--------------')
'''
for i in range(D):
  #print(slist[i],tlist[i]-1)
  zlist.append(clist[tlist[i]-1] * ((i+1) - dlist[tlist[i]-1]))
  dlist[tlist[i]-1] = i+1
  ans += slist[i][tlist[i]-1] - ((i+1) * sum(clist)) + sum(zlist)
  print(ans)

Measured memory_bytes: 9408
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue> 
#include <tuple>
 
using namespace std;

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

    int A, B;

    cin >> A >> B;
 
    if(B == 1) {
        cout << 0 << endl;
    } else if(A >= B) {
        cout << 1 << endl;
    } else {
        int x = ((B - 1) + (A - 2)) / (A - 1);
        cout << x << endl;
    }
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if(a + b > c + d) cout << "Left" << endl;
  else if(a + b == c + d) cout << "Balanced" << endl;
  else cout << "Right" << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int N;
  int A[100];
  int run_length = 0;
  int max_run_length = 0;
  
  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0 && run_length) {
      if (run_length > max_run_length) {
        max_run_length = run_length;
      }
      run_length = 0;
    } else if (A[i] == 1) {
      run_length++;
    }
  }
  if (run_length > max_run_length) {
    max_run_length = run_length;
  }
  
  cout << max_run_length + 1  << endl;
}



Measured memory_bytes: 3080
n,W = map(int,input().split())
dp = [[10**12] * (10**5+1) for i in range(n+1)]
dp[0][0] = 0
ma = 0
for i in range(1,n+1):
  w,v = map(int,input().split())
  ma += v
  for j in range(v):
    dp[i][j] = dp[i-1][j]
  for j in range(v,ma+1):
    dp[i][j] = min(dp[i-1][j-v]+w,dp[i-1][j])
m = 0
for i in range(ma+1):
  if dp[-1][i] <= W:
    m = i
print(m)

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

using namespace std;

int main() {
  int A, B;
  scanf("%d %d", &A, &B);
  int ans = 0;
  ans += max(A, B);
  if (ans == A) { --A; }
  else { --B; }
  ans += max(A, B);
  printf("%d", ans);
  fflush(stdout);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

    int N;
    cin >> N;

    printf("%s\n",to_string(N).find('7') != string::npos ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b, ans=0;
  cin >> a >> b;
  vector<int> digits(5,0);
  for(int i=a;i<=b;i++){
    int tag = i;
    for(int j=0;j<5;j++){
      digits[4 - j] = tag % 10;
      tag /= 10;
    }
    if(digits[0] == digits[4] && digits[1] == digits[3]){
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main()
{
	int n = 0, a[100] = {0};

	cin >> n;

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

	for (int i = 0; i < n; i++) {
		cout << a[n - i - 1];
		if (i < n - 1)
			cout << " ";
		else
			cout << endl;
	}
    return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define MAX 100000

int parent(int i) { return i / 2; }
int left(int i) { return i * 2; }
int right(int i) { return i * 2 + 1; }

int main(void)
{
    int H, i, A[MAX+1];

    cin >> H;
    for ( i = 1; i <= H; ++i ) cin >> A[i];

    for ( i = 1; i <= H; ++i ) {
        cout << "node " << i << ": key = " << A[i] << ", ";
        if ( parent(i) >= 1 ) cout << "parent key = " << A[parent(i)] << ", ";
        if ( left(i) <= H ) cout << "left key = " << A[left(i)] << ", ";
        if ( right(i) <= H ) cout << "right key = " << A[right(i)] << ", ";
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  
  ll x,a ,b;
  cin >> x >> a >> b;
  if(-a+b<=0)cout << "delicious" << endl;
  else if(-a+b<=x)cout << "safe" << endl;
  else  cout << "dangerous" << endl;
  return 0;     
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
int SIZE(string s){return (int)s.size();}
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int n,m,q; cin >> n >> m >> q;
    vi num(n);
    vi fin(n);
    rep(i,n){
        num[i] = 1;
        fin[i] = m;
    }
    ll ans = 0;
    vc<vi> qu(q,vi(4));
    rep(i,q){
        cin >> qu[i][0] >> qu[i][1] >> qu[i][2] >> qu[i][3];
        qu[i][0]--;
        qu[i][1]--;
    }
    while(1){
        ll sum = 0;
        rep(i,q){
            if(num[qu[i][1]] - num[qu[i][0]] == qu[i][2]){
                sum += qu[i][3];
            }
        }
        chmax(ans,sum);
        if(num == fin) break;
        num[n-1]++;
        int from = n;
        gnr(i,0,n){
            if(num[i] > m){
                num[i-1]++;
                from--;
            } else {
                rng(j,from,n) num[j] = num[j-1];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
//
// Created on 2020/06/27.
//


#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    int a;
    cin>>a;
    int ans = a + (a*a) + (a*a*a);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include<stdio.h>
int main()
{
    int n,i,j,d,x,s=0,sum;
    scanf("%d",&n);
    int a[n];
    scanf("%d %d",&d,&x);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        for(j=1;j<=d;j++)
        {
            sum=j*a[i]+1;
            if(sum>d)
                break;
            else
                s++;
        }
        sum=0;
    }
    printf("%d\n",s+x+n);
}


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

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int[] c = new int[3];
		for(int i=0; i<n; i++){
			int temp = sc.nextInt();
			if(temp <= a)
				c[0]++;
			else if (temp <= b)
				c[1]++;
			else c[2]++;
		}
		int ans = Math.min(c[0], Math.min(c[1], c[2]));
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
// https://atcoder.jp/contests/abc165/tasks/abc165_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int K, A, B;
    cin >> K >> A >> B;
    int ans = 0;
    FOR(i, A, B + 1) {
        if (i % K == 0) {
            ans++;
        }
    }
    if (ans > 0) {
        cout << "OK\n";
    } else {
        cout << "NG\n";
    }

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    int n, ma, mb;
    cin >> n >> ma >> mb;
    vvi dp(4001, vi(4001, INF));
    vector< pair<int, i_i > > item(n);
    rep(i, n) {
        pair<int, i_i > tmp;
        cin >> tmp.first >> tmp.second.first >> tmp.second.second;
        item[i] = tmp;
    }
    dp[0][0] = 0;
    rep(i, n) {
        for (int j = 4000; j >= 0; j--) {
            for (int k = 4000; k >= 0; k--) {
                if (dp[j][k] != INF || (j == 0 && k == 0)) {
                    dp[j+item[i].first][k+item[i].second.first] =
                        min(dp[j+item[i].first][k+item[i].second.first],
                        dp[j][k] + item[i].second.second);
                }
            }
        }
    }
    int i = 1;
    int ret = INF;
    while (i * ma < 4001 && i * mb < 4001) {
        ret = min(ret, dp[i*ma][i*mb]);
        i++;
    }
    cout << ((ret == INF) ? -1 : ret) << endl;

    return 0;
}



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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for (int i = a; i < (int)b; ++i)
#define rrep(i, n) for (int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld = long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    char c;
    cin >> c;
    if (c >= 'a' && c <= 'z') cout << 'a' << endl;
    else cout << 'A' << endl;
    
    return 0;
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

struct BIT{
    vector<ll> bit; //1-indexed
    int n;
    BIT(int n) : n(n), bit(vector<ll>(n+1, 0)) {}
    ll sum(int i){
        ll s = 0;
        while(i > 0){
            s += bit[i];
            i -= i & -i;
        }
        return s;
    }
    void add(int i, int x){
        while(i <= n){
            bit[i] += (ll)x;
            i += i & -i;
        }
    }
    //xより大きい値(区間和)が現れる最初のインデックス. (l,u]の範囲
    int lower_bound(ll x) {
        ll ret = 0;
        ll k = 1;
        while(2 * k <= n) k <<= 1;
        for(; k > 0; k >>= 1) {
            if(ret + k < n && bit[ret + k] < x) {
                x -= bit[ret + k];
                ret += k;
            }
        }
        return ret + 1;
    }
    //x以上の値(区間和)が現れる最初のインデックス. [l,u)の範囲
    int upper_bound(ll x) {
        ll ret = 0;
        ll k = 1;
        while(2 * k <= n) k <<= 1;
        for(; k > 0; k >>= 1) {
            if(ret + k < n && bit[ret + k] <= x) {
                x -= bit[ret + k];
                ret += k;
            }
        }
        return ret + 1;
    }
    ll between(int i, int j){
        if(i > j) return 0;
        return sum(j) - sum(i-1);
    }
};

int main(void)
{
    int n,q;
    cin >> n >> q;
    
    BIT bit(n);

    REP(i, q){
        int c,x,y;
        cin >> c >> x >> y;
        if(c==0){
            bit.add(x, y);
        }else{
            pr(bit.between(x,y));
        }
    }  
}


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

int main(){
    int k;
    cin >> k;
    long long ans = 0;
    for (int i = 1; i <= k; i++){
        for (int j = 1; j <= k; j++){
            for (int l = 1; l <= k; l++)
                ans+=(__gcd(i,__gcd(j,l)));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3580
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int n, a, b, p[2009], dp[2009][2009][2], INF = 1000000007;

int dfs(int r1, int r2, int c) {
	if (dp[r1][r2][c] != INF)return dp[r1][r2][c];
	if (r1 == n || r2 == n) {
		int W = p[r1];
		if (r2 >= 1)W -= p[r2]; else W -= b;
		return abs(W);
	}
	if (c == 0) {
		dp[r1][r2][c] = max(dfs(max(r1, r2) + 1, r2, 0), dfs(max(r1, r2) + 1, r2, 1));
	}
	if (c == 1) {
		dp[r1][r2][c] = min(dfs(r1, max(r1, r2) + 1, 0), dfs(r1, max(r1, r2) + 1, 1));
	}
	return dp[r1][r2][c];
}

int main() {
	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++)cin >> p[i];
	for (int i = 0; i < 2009; i++) { for (int j = 0; j < 2009; j++) { dp[i][j][0] = INF; dp[i][j][1] = INF; } }
	cout << dfs(0, 0, 0) << endl;
	return 0;
}

Measured memory_bytes: 32000
import itertools

if __name__ == '__main__':
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    e = int(input())
    k = int(input())

    position = [a, b, c, d, e]
    test_cases = list(itertools.combinations(position, 2))

    is_all_communication_possible = True

    for e in test_cases:
        position1 = e[0]
        position2 = e[1]

        if position2 - position1 > k:
            is_all_communication_possible = False

    if is_all_communication_possible:
        print("Yay!")
    else:
        print(":(")


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

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,weight;cin>>n>>weight;
    vector<ll> w(n),v(n);rep(i,n){cin>>w[i]>>v[i];}
    vector<vector<ll> > dp(n,vector<ll>(100005,0));
    dp.at(0).at(w.at(0))=v.at(0);
    repr(i,1,n){
        rep(j,weight+1){
            dp.at(i).at(j)=dp.at(i-1).at(j);
        }
        for(ll j=w[i];j<=weight;j++){
            dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
        }
    }
    ll res=0;
    rep(i,weight+1){
        res = max(res, dp.at(n-1).at(i));
    }
    cout << res << endl;
    return 0;
}


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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

int dp[maxn][4];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d%d", &dp[i][1], &dp[i][2], &dp[i][3]);
        dp[i][1] += max(dp[i - 1][2], dp[i - 1][3]);
        dp[i][2] += max(dp[i - 1][1], dp[i - 1][3]);
        dp[i][3] += max(dp[i - 1][1], dp[i - 1][2]);
    }

    int res = 0;
    for (int i = 1; i <= 3; i++) res = max(res, dp[n][i]);

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


Measured memory_bytes: 1792
N = int(input())
d = list()
for n in range(N):
    d.append(int(input()))
d = sorted(d, reverse=True)
ans = 1
for i, n in enumerate(d):
    if i == len(d) - 1:
        break
    if n > d[i + 1]:
        ans += 1
print(ans)


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

using namespace std;

void doc() {
    freopen("OB.inp", "r", stdin);
    freopen("OB.out", "w", stdout);
}

int n, W;
int c[100 + 1], v[100 + 1];
long long f[100 + 1][100005 + 1];

void Trace(int i, int j){
    if (i <= 0 || j <= 0) return;
    if (f[i][j] == f[i - 1][j]) {
        Trace(i - 1, j);
        return;
    }
    Trace(i - 1, j - c[i]);
    cout << i << '\n';
}

void solve(){

    cin >> n >> W;

    for(int i = 1; i <= n; i++)
        cin >> c[i] >> v[i];
    memset(f, 0, sizeof(f));
   // f[0][0] = 0;
    for(int i = 1; i <= n; i++)
        for(int j = 0; j <= W; j++){
            f[i][j] = f[i - 1][j];
            if (j - c[i] >= 0)
                f[i][j] = max(f[i - 1][j - c[i]] + v[i], f[i][j]);
        }
    cout << f[n][W];
    //Trace(n, W);
}

int main()
{
//    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
  //  doc();
    solve();
}



Measured memory_bytes: 79232
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n = int(input())
    ans = [0]*(n+1)
    lim = int(n**(0.5)) +1
    for i in range(1, lim):
        for j in range(1,lim):
            for k in range(1,lim): 
                tmp = i**2 + j**2 + k**2 +i*j + j*k+ k*i
                if tmp <= n:
                    ans[tmp] += 1
    for a in ans[1:]:
        print(a)   


if __name__ == '__main__':
    main()

Measured memory_bytes: 9420
#include<stdio.h>
 
int main()
{
  int n,i,j,v,vv,m;
  int map[101][101];
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      map[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&m);
    for(j=0;j<m;j++){
      scanf("%d",&vv);
      map[v-1][vv-1]=1;
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<n-1;j++){
      printf("%d ",map[i][j]);
    }
    printf("%d\n",map[i][j]);
  }
  return 0;
}


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

int main(){
  int N;
  cin>>N;
  int j=1;
  for(int i=0;i<N;i++){
    int A;
    cin>>A;
    if(A%2==0)
      j*=2;
  }
  cout<<(int)pow(3,N)-j<<endl;
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))

A = 0
D = 0
for i in a:
  if i % 2 == 0:
    if i % 3 == 0 or i % 5 == 0:
      A += 1
    else:
      D += 1
if D == 0:
  print('APPROVED')
else:
  print('DENIED')

Measured memory_bytes: 3060
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  n = int(input())
  *A, = map(int,input().split()) # こうすることで、当データとidxが取得できる！！！つよ！！
  from collections import deque
  B = deque([]) # リストとして活用できる
  for i,a in enumerate(A):
    if i % 2 == 0:
      B.append(a)
    else:
      B.appendleft(a)
  if n % 2 == 1:
    B.reverse() # 逆順に
  print(*B)
if __name__ == '__main__':
  main()

Measured memory_bytes: 26020