akhauriyash/Code-Regression huggingface dataset:
import math
a,b,C = map(int,input().split())
S = (a * b * math.sin(math.radians(C))) / 2
L = a + b + math.sqrt(a**2 + b**2 - 2*a*b*math.cos(math.radians(C)))
h = b * math.sin(math.radians(C))
print(S)
print(L)
print(h)


Measured memory_bytes: 5704
#include <bits/stdc++.h>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;

// 木上の探索
vector<int> depth;
vector<int> subtree_size;
int oya[214514];
void dfs(const Graph &G, int v, int p, int d) {
    depth[v] = d;
    for (auto nv : G[v]) {
    	oya[v]=p;
        if (nv == p) continue; // nv が親 p だったらダメ
        dfs(G, nv, v, d+1);
    }
}
int ans[214514];
pair<pair<int,int>,int> pp[214514];
int main() {
    // 頂点数 (木なので辺数は N-1 で確定)
    int N; cin >> N;
    int q; cin>>q;
    // グラフ入力受取
    Graph G(N);
    for (int i = 0; i < N-1; ++i) {
        int a, b;
        cin >> a >> b;
        a-=1;
        b-=1;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    // 探索
    int root = 0; // 仮に頂点 0 を根とする
    depth.assign(N, 0);
    dfs(G, root, -1, 0);
    
    for(int i=0;i<N;i++){
    	pp[i].first.first=depth[i];
    	pp[i].first.second=i;
    	pp[i].second=oya[i];
    }	
    for(int i=0;i<q;i++){
    	int p,x;
    	cin>>p>>x;
    	p-=1;
    	ans[p]+=x;
    }	
    sort(pp,pp+N);
    for(int i=1;i<N;i++)ans[pp[i].first.second]+=ans[pp[i].second];
    for(int i=0;i<N;i++)cout<<ans[i]<<" ";
}


Measured memory_bytes: 33920
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int C = sc.nextInt();
    int[][] A = new int[N][M];
    int[] B = new int[M];
    int[] count = new int[N];
    int tmp =C,ans =0;
    for (int i=0; i<M; i++) {
      B[i] = sc.nextInt();
    }
    for (int i=0; i<N; i++) {
      for (int j=0; j<M; j++) {
        A[i][j] = sc.nextInt();
      }
    }
    for (int i=0; i<N; i++) {
      for (int j=0; j<M; j++) {
        tmp += A[i][j] * B[j];
      }
      if (tmp > 0) count[i]++;
      tmp = C;
    }
    for (int i=0; i<N; i++) {
      if (count[i] == 1) ans++;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22100
import java.util.*;

public class Main {
    private final static int M = 1000000007;

    private static int solve(int N, boolean[][] a) {
        int states = 1 << N;

        int[] count = new int[states];
        count[0] = 1;

        for (int state = 1; state < states; state++) {
            int i = Integer.bitCount(state) - 1;

            for (int j = 0, p = 1; j < N; j++, p <<= 1) {
                if (!a[i][j]) continue;

                int prevState = state & ~p;
                if (prevState == state) continue;

                count[state] = (count[state] + count[prevState]) % M;
            }
        }

        return count[states-1];
    }

    public static int run(Scanner scanner) {
        int N = scanner.nextInt();
        boolean[][] a = new boolean[N][N];
        for (int i=0; i < N; i++)
            for (int j=0; j < N; j++)
                a[i][j] = scanner.nextInt() == 1;

        return solve(N, a);
    }

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            System.out.println(run(scanner));
        }
        //Tests.run();
    }
}

Measured memory_bytes: 30292
#!/usr/bin/env pypy
from __future__ import division, print_function

import os
import sys
from __builtin__ import xrange as range
from cStringIO import StringIO
from future_builtins import ascii, filter, hex, map, oct, zip
from io import IOBase

import __pypy__


def main():
    R, C = read_int_array()
    grid = [read() for _ in range(R)]
    vdp, ldp, ddp, rdp = [[0]*C for _ in range(R)], [[0]*C for _ in range(R)], [[0]*C for _ in range(R)], [[0]*C for _ in range(R)]
    for r in range(R):
        for c in range(C):
            if grid[r][c] != b'#'[0]:
                vdp[r][c] = (vdp[r-1][c] if r else 0) + 1
                ldp[r][c] = (ldp[r][c-1] if c else 0) + 1
    for r in range(R-1, -1, -1):
        for c in range(C-1, -1, -1):
            if grid[r][c] != b'#'[0]:
                ddp[r][c] = (ddp[r+1][c] if r + 1 < R else 0) + 1
                rdp[r][c] = (rdp[r][c+1] if c + 1 < C else 0) + 1

    print(max(vdp[r][c] + ldp[r][c] + ddp[r][c] + rdp[r][c] - 3 for r in range(R) for c in range(C) if grid[r][c] != b'#'[0]))



# region fastio

BUFSIZE = 8192


class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()


class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

read = input
read_int = lambda: int(input())
read_array = lambda sep=None, maxsplit=-1: input().split(sep, maxsplit)
read_int_array = lambda: [int(a) for a in read_array()]

if __name__ == "__main__":
    main()


Measured memory_bytes: 168080
#include<stdio.h>

int main(){
		int n,i,ans=1,f=0,c=0;
		long long a[100002],b[100000];
		scanf("%d",&n);
		for(i=0;i<n;i++)scanf("%lld",&a[i]);
		b[0]=a[0];f++;
		for(i=1;i<n;i++){
					if(c==0){
							b[f++]=a[i];
							if(f>=2&&b[f-1]>b[f-2])c=1;
							if(f>=2&&b[f-1]<b[f-2])c=-1;
					}
					else if(c==1){
							if(b[f-1]<=a[i])b[f++]=a[i];
							else {
									ans++;
									b[0]=a[i];
									f=1;
									c=0;
						//			printf("%d\n",i);
							}
					}
					else if(c==-1){
							if(b[f-1]>=a[i])b[f++]=a[i];
							else {
									ans++;
									b[0]=a[i];
									f=1;
									c=0;
						//			printf("%d\n",i);
							}
					}
		}
		printf("%d\n",ans);
		return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <queue>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <sstream>
#include <cassert>
#include <functional>
#include <cfloat>
#include <climits>
#include <cstring>
#include <stack>
#include <time.h>
#include <complex>
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define ford(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define fore(i,a,n) for(int i=(int)(a);i<(int)(n);i++)
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define last(a) (int(a.size())-1)
#define all(a) a.begin(),a.end()
int n;
char wcz[1007];
int czy[1007];
long long wyn;
void check(){
	czy[n]=1;
	long long aktu=0;
	for (int i=1;i<=n;i++)
	{
		aktu*=10;
		aktu+=wcz[i]-'0';
		if(czy[i])
		{
			wyn+=aktu;
			aktu=0;
		}
	}
}
void rek(int v)
{
	if(v==n)
	{
		check();
		return;
	}
	czy[v]=0;
	rek(v+1);
	czy[v]=1;
	rek(v+1);
}
int main()
{
	cin>>wcz+1;
	while (wcz[n+1])
		n++;
	rek(1);
	cout<<wyn<<endl; 
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
#include <memory.h>
using namespace std;
vector<int> ox; //障害物のx座標
vector<int> oy; //障害物のy座標
int o[500][500];

class State{
public:
  int x, y, cost;

  State(){}
  State(int _x,int _y,int _cost){
    x = _x;
    y = _y;
    cost = _cost;
  }
};

int Breadth_First_Search(int t, int n, int sx, int sy) {
  static const int dx[] = {-1,-1,0,1,1,0};
  static const int dy[] = {-1,0,1,1,0,-1};
  bool closed[500][500];
  int count = 0;

  queue<State> open;
  memset(closed,0,sizeof(closed));
  open.push(State(sx,sy,0));


  for(int i = 0; i < n; i++){
    closed[ox[i]][oy[i]] = true;
  }


  while(!open.empty()){
    State st = open.front();
    open.pop();

    //cout << closed[st.x][st.y] << endl;
    if(closed[st.x][st.y] || st.cost > t) {
      //cout << 'a'  << ' ' << count << endl;
      continue;
    }
    closed[st.x][st.y] = true;

    count++;

    for(int i = 0; i < 6; i++) {
      int nx = st.x + dx[i];
      int ny = st.y + dy[i];
      //cout << nx << ' ' << ny << endl;
      open.push(State(nx, ny, st.cost + 1));
    }
  }

  return count;
}

int main() {
  int t; //ターン数
  int n; //障害物の数
  int sx, sy; //スタートマス

  while(1){
    memset(o,0,sizeof(o));
    cin >> t >> n;
    if(t == 0 && n == 0)
      break;

    for(int i = 0; i < n; i++) {
      int X, Y;
      cin >> X >> Y;
      X += 200;
      Y += 200;
      //o[Y][X] = true;
      ox.push_back(X);
      oy.push_back(Y);
    }

    cin >> sx >> sy;
    sx += 200;
    sy += 200;

    cout << Breadth_First_Search(t, n, sx, sy) << endl;
    ox.clear();
    oy.clear();
  }
  return 0;
}



Measured memory_bytes: 4368
#include <iostream>
#include <string>
using namespace std;
int main(){
    int k, n;
    cin >> k >> n;
    int a[n];
    int i;
    int dst_max = 0;
    for(i=0;i<n;i++){
        cin >> a[i];
        if(i>=1){
            if(a[i]-a[i-1] > dst_max) dst_max = a[i]-a[i-1];
        }
    }
    if(a[0] + k - a[n-1] > dst_max) dst_max = a[0] + k - a[n-1];
    int res = k - dst_max;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
package main

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

//=====I/O=====

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInt64() int64 {
	sc.Scan()
	a,_ := strconv.ParseInt(sc.Text(),10,64)
	return a
}

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

//•*¨*•.¸¸♪func•*¨*•.¸¸♪

//•*¨*•.¸¸♪main•*¨*•.¸¸♪

func main() {
	sc.Split(bufio.ScanWords)
	// sc.Buffer(make([]byte, 10000), 100000000)

	n := scanInt()
	m := scanInt()

	if n == m {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        n: u64
    }

    let mut ret = 0;
    for i in 1..n+1 {
        if i%2==1 && divisors(i).len() == 8 {
            ret += 1;
        }
    }
    println!("{}", ret);
}

#[doc = " n>=1"]
#[allow(dead_code)]
fn divisors(n: u64) -> Vec<u64> {
    let mut ret = vec![];
    for i in (1..).take_while(|i| i * i <= n) {
        if n % i == 0 {
            ret.push(i);
            if i != n / i {
                ret.push(n / i);
            }
        }
    }
    ret
}

Measured memory_bytes: 4352
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

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

const int maxn = 1e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

char s[maxn], t[maxn];
ll prefix_s[maxn], prefix_t[maxn];

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    scanf("%s", s + 1);
    scanf("%s", t + 1);
    int n = strlen(s + 1);
    int m = strlen(t + 1);
    for (int i = 1; i <= n; i++) {
        if (s[i] == 'B') prefix_s[i] = prefix_s[i - 1] + 1LL;
        else prefix_s[i] = prefix_s[i - 1] + 2LL;
    }
    for (int i = 1; i <= m; i++) {
        if (t[i] == 'B') prefix_t[i] = prefix_t[i - 1] + 1LL;
        else prefix_t[i] = prefix_t[i - 1] + 2LL;
    }
    int q;
    scanf("%d", &q);
    while (q--) {
        int a, b, c, d;
        scanf("%d%d%d%d", &a, &b, &c, &d);
        ll A = prefix_s[b] - prefix_s[a - 1];
        ll B = prefix_t[d] - prefix_t[c - 1];
        if ((A - B) % 3LL == 0) puts("YES");
        else puts("NO");
    }

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 2304
#include <iostream>
using namespace std;
int main(void){
   int a,b,c;
   cin>>a>>b>>c;
   if(a==1&&b==1&&c==0){
       cout<<"Open"<<endl;
   }
   else if(a==0&&b==0&&c==1){
   
       cout<<"Open"<<endl;
   }
   else{
       cout<<"Close"<<endl;
   }
}



Measured memory_bytes: 3088
import java.io.*;
import java.util.ArrayList;
 
public class Main{
 
    public static void main(String[] args) throws IOException {
 
        int n = 0;
        int m = 0;
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        String[] line = br.readLine().split(" ");
        n = Integer.parseInt(line[0]);
        m = Integer.parseInt(line[1]);
 
        int num_a[][];
        num_a = new int[n][m];
 
        for (int i = 0; i < n; i++) {
 
            String[] line1 = br.readLine().split(" ");
 
            for (int x = 0; x < m; x++) {
                num_a[i][x] = Integer.parseInt(line1[x]);
            }
 
        }
         
        int num_b[];
        int num_c[];
        num_b = new int[m];
        num_c = new int[n];
         
        for(int i = 0; i < m; i++) {
            num_b[i] = Integer.parseInt(br.readLine());
        }
         
         
        for(int i = 0; i < n; i++) {
             
            for(int x = 0; x < m; x++) {
                num_c[i] += num_a[i][x] * num_b[x];
            }
            
        }
         
        for(int i = 0; i < n; i++) {
            System.out.println(num_c[i]);
        }
    }
 
}

Measured memory_bytes: 27516
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する
int w,h;
bool valid(int y,int x){
    return y >= 0 && x >= 0 && y < h && x < w;
}
int dfs(int y,int x,vector<vector<int> > &v){
    if(v[y][x] != 0){
        return 0;
    }
    v[y][x] = 3;
    int ret = 1;
    if(valid(y+1,x)){
        ret += dfs(y+1,x,v);
    }
    if(valid(y-1,x)){
        ret += dfs(y-1,x,v);
    }
    if(valid(y,x+1)){
        ret += dfs(y,x+1,v);
    }
    if(valid(y,x-1)){
        ret += dfs(y,x-1,v);
    }
    return ret;
}
void solve(int W,int H){
    vector<vector<int> > v(H,vector<int>(W));
    w = W;
    h = H;
    int sy,sx;
    rep(i,0,H){
        rep(j,0,W){
            char tmp;
            cin >> tmp;
            if(tmp == '@'){
                sy = i;
                sx = j;
                v[i][j] = 0;
            }else if(tmp == '.'){
                v[i][j] = 0;
            }else if(tmp == '#'){
                v[i][j] = 1;
            }
        }
    }
    cout << dfs(sy,sx,v) << endl;

}

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

    while(true){
        int W,H;
        cin >> W >> H;
        if(W == 0) break;
        solve(W,H);


    }


    return 0;
}



Measured memory_bytes: 3112
#include <iostream>

unsigned short calculate_area (unsigned short radius)
{
	return (unsigned short)(3) * radius * radius;
}

int main (void)
{
	// variables for main process
	register unsigned short r;

	// STEP.01
	// read out the given data
	std::cin >> r;

	// STEP.02
	// output the answer of this task
	std::cout << calculate_area (r) << std::endl;

	// STEP.END
	return EXIT_SUCCESS;
}

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

int main(){
  int n,a;
  cin >> n;
  vector<int> b(n),c;
  for(int i=0;i<n;i++){
    cin >> b.at(i);
  }
  reverse(b.begin(),b.end());
  c.push_back(b.at(0));
  for(int i=1;i<n;i++){
    auto iter = upper_bound(c.begin(),c.end(),b.at(i)+0.5);
    if(iter == c.end()){
      //cout << b.at(i) << " saigoni" << endl;
      c.insert(iter,b.at(i));
    }
    else if(iter != c.end()){
      //cout << b.at(i) << "kesimasu" << endl;
      c.erase(iter);
      c.insert(iter,b.at(i));
    }
  }
  cout << c.size() << endl;
}

Measured memory_bytes: 1276
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
#include <stack>
#include <functional>
#include <queue>
using namespace std;
#define int long long

const int INF = 1e12;

signed main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    }

    int h, n;
    cin >> h >> n;
    vector<int> a, b;
    for (int i = 0; i != n; ++i) {
        int aa, bb;
        cin >> aa >> bb;
        a.push_back(aa);
        b.push_back(bb);
    }
    vector<int> dp(h + 1, INF);
    dp[0] = 0;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j != n; ++j)
            if (i + a[j] <= h)
                dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j]);
            else
                dp[h] = min(dp[h], dp[i] + b[j]);
    }
    cout << dp[h];
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int a[10];
	int mx[3];
	for(int i=0;i<10;i++)cin>>a[i];
	mx[0]=mx[1]=mx[2]=0;
	for(int i=0;i<10;i++){
		if(mx[0]<a[i]){
			mx[2]=mx[1];
			mx[1]=mx[0];
			mx[0]=a[i];
		}else if(mx[1]<a[i]){
			mx[2]=mx[1];
			mx[1]=a[i];
		}else if(mx[2]<a[i]){
			mx[2]=a[i];
		}
	}
	cout<<mx[0]+mx[1]+mx[2]<<" ";
	for(int i=0;i<10;i++)cin>>a[i];
	mx[0]=mx[1]=mx[2]=0;
	for(int i=0;i<10;i++){
		if(mx[0]<a[i]){
			mx[2]=mx[1];
			mx[1]=mx[0];
			mx[0]=a[i];
		}else if(mx[1]<a[i]){
			mx[2]=mx[1];
			mx[1]=a[i];
		}else if(mx[2]<a[i]){
			mx[2]=a[i];
		}
	}
	cout<<mx[0]+mx[1]+mx[2]<<endl;
	return 0;
}

Measured memory_bytes: 0
a = [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]
b = int(input())
print(a[b - 1])

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <math.h>

#define roop(i,n,k) for(i=k;i<n;i++)

using namespace std;

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	int n;
	cin >> n;
	double ans = 0.0;
	if (n % 2 == 0) {
		ans = (1 / (double)n) * ((double)n / 2);
	} else {
		ans = ((1 / (double)n) * ceil((double)n / 2));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
ll t, a, b, c, i, j, k, x, y, n, m;
ll arr[100005];
string s;
char str[105][105];
int main() {
	cin >> s;
	ll sum = 0;
	for (i = 0; i < s.length(); i++) {
		sum += s[i]-'0';
	}
	if (sum % 9 == 0)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}
/*
4 6 8
4 6 8 6 8 6 8
24+18+4
46
4 6 8 2 9 9 9 9
36+20
56
*/

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int mod = 1e9+7;

ll dp[105][4][4][4];

int main(){
    int n;
    cin >> n;
    rep(j, 4) rep(k, 4) rep(l, 4) {
        if (j == 0 && k == 1 && l == 2) continue;   // ACG
        if (j == 0 && k == 2 && l == 1) continue;   // AGC
        if (j == 2 && k == 0 && l == 1) continue;   // GAC
        dp[3][j][k][l] = 1;
    }

    for(int i = 3; i < n; i++){
        int ni = i + 1;
        rep(j, 4) rep(k, 4) rep(l, 4){
            rep(c, 4){
                if (k == 0 && l == 2 && c == 1) continue;   // ~AG + C
                if (k == 0 && l == 1 && c == 2) continue;   // ~AC + G
                if (k == 2 && l == 0 && c == 1) continue;   // ~GA + C
                if (j == 0 && l == 2 && c == 1) continue;   // A~G + C
                if (j == 0 && k == 2 && c == 1) continue;   // AG~ + C
                dp[ni][k][l][c] += dp[i][j][k][l];
                dp[ni][k][l][c] %= mod;
            }
        }
    }
    ll ans = 0;
    rep(j, 4) rep(k, 4) rep(l, 4) {
        ans += dp[n][j][k][l];
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3672
#include<stdio.h>

int main()
{
    int a,b;
    while((scanf("%d %d",&a,&b)!=EOF))
    {
        int sum=a+b;
        int cnt=0;
        while(sum)
        {
            cnt++;
            sum=sum/10;
        }
        printf("%d\n",cnt);
    }
    return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <queue>
#define MAX 1000000
using namespace std;

int main(void){
	int i,j,k,n,ans;
	bool a[MAX];

	for(i=0;i<MAX;i++) a[i] = true;
	for(i=2;i<MAX;i++){
		if(a[i]){
			for(j=i+i;j<MAX;j+=i) a[j] = false;
		}
	}

	while(1){
		cin >> n;
		ans = 0;
		if(n == 0) break;
		for(i=2;i<=n/2;i++){
			if(a[i] && a[n-i]) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(){
    int n, a, b, c, d;
    cin >> n;
    a = n/1000;
    b = n/100%10;
    c = n/10%10;
    d = n%10;
    if(a+b+c+d == 7){
        cout << a << '+' << b << '+' << c << '+' << d << "=7";
    }else if(a+b+c-d == 7){
        cout << a << '+' << b << '+' << c << '-' << d << "=7";
    }else if(a+b-c+d == 7){
        cout << a << '+' << b << '-' << c << '+' << d << "=7";
    }else if(a+b-c-d == 7){
        cout << a << '+' << b << '-' << c << '-' << d << "=7";
    }else if(a-b+c+d == 7){
        cout << a << '-' << b << '+' << c << '+' << d << "=7";
    }else if(a-b+c-d == 7){
        cout << a << '-' << b << '+' << c << '-' << d << "=7";
    }else if(a-b-c+d == 7){
        cout << a << '-' << b << '-' << c << '+' << d << "=7";
    }else{
        cout << a << '-' << b << '-' << c << '-' << d << "=7";
    }
    return 0;
}

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

#define pb  push_back
#define mp  make_pair
#define ll  long long
#define itr iterator

typedef pair<int,int> pii;

const int MAX=1e5;

ll N,X,arr[MAX];

signed main()
{
	ios_base::sync_with_stdio(false);

	cin>>N>>X;
	for(int A=1;A<=N;A++)
		cin>>arr[A];
	sort(arr+1,arr+N+1);
	for(int A=2;A<=N;A++)
		arr[A]+=arr[A-1];
	if(arr[N]==X)
		return cout<<N,0;
	for(int A=N-1;A>=0;A--)
		if(arr[A]<=X)
			return cout<<A,0;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int gcm(int m, int n) {
    if (m < n) {
        int w = m;
        m = n;
        n = w;
    }

    while (n != 0) {
        int w = m % n;
        m = n;
        n = w;
    }

    return m;
}

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

    int a_min;
    cin >> a_min;

    for (int i = 1; i < n; i++) {
        int a;
        cin >> a;
        a_min = gcm(a_min, a);
    }

    cout << a_min << endl;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
 
module Main
  ( main
  )
where
 
import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import           Control.Monad.ST
 
parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine
 
main = do
  x <- readInt
  putStrLn $ if x < 1200 then "ABC" else "ARC"


Measured memory_bytes: 380
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
 
using namespace std;
int main()
{
  int N;
  int M;
  int Ain;
  long sum;
 
  Ain = 0;
  sum = 0;
  
  cin >> N >> M;
  vector<int> AM(M);
 
  // Mまではそのまま挿入
  for(int i=0; i < M; i++){
    cin >> AM[i]; 
    sum += AM[i];
  }
 
  for(int i=0; i < N-M; i++){
    cin >> Ain;
    sum += Ain;
    sort(AM.begin(), AM.end());
    reverse(AM.begin(), AM.end());
    if(AM[M-1] < Ain){
      AM[M-1] = Ain;
    }
  }
  
  if((AM[M-1]*4*M) < sum){
   	cout << "No\n"; 
  }
  else{
   	cout << "Yes\n";  
  }
  
      return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;


class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        if (Regex.IsMatch(ReadLine(), @"^A?KIHA?BA?RA?$"))
        {
            WriteLine("YES");
        }
        else
        {
            WriteLine("NO");
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 16204
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n;
  cin >> n;
  vector <ll> c(n-1), s(n-1), f(n-1);
  rep(i, n-1) {
    cin >> c.at(i) >> s.at(i) >> f.at(i);
  }
  rep(i, n) {
    ll res = 0;
    for (ll j = i; j < n-1; j++) {
      if (res <= s.at(j)) res = s.at(j) + c.at(j);
      else {
        ll tmp = res - s.at(j);
        if (tmp%f.at(j)) res = s.at(j) + (tmp/f.at(j)+1)*f.at(j) + c.at(j);
        else res = s.at(j) + tmp + c.at(j);
      }
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	static int[][] t;
	static int[] r1;
	static long ans;
	static boolean[] used;
	static int R;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		R = sc.nextInt();
		used=new boolean[R];
		ans=Integer.MAX_VALUE;
		t = new int[n+1][n+1];
		r1 = new int[R];
		for(int i= 0; i<R; i++){
			r1[i]= sc.nextInt();
		}
		for(int i = 1; i<=n; i++){
			for(int j = 1; j<=n; j++){
				if(i!=j){
					t[i][j]=Integer.MAX_VALUE/10;
				}
			}
		}
		for(int i = 0; i<m; i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			t[a][b]=c;
			t[b][a]=c;
		}
		for(int i = 1; i<=n; i++){
			for(int j = 1; j<=n; j++){
				for(int k = 1; k<=n; k++){
						t[j][k]=Math.min(t[j][k],t[j][i]+t[i][k]);
				}
			}
		}
		dfs(0,-1,0);
			System.out.println(ans);
			
	}
	static void dfs(int count, int last, int sum){
		if(count==R){
			ans=Math.min(ans,sum);
			return;
		}
		for(int i = 0; i<R; i++){
			if(!used[i]){
				used[i]=true;
				if(last==-1){
					dfs(count+1,i,0);
				}else{
					dfs(count+1,i,sum+t[r1[last]][r1[i]]);
				}
				used[i]=false;
			}
		}
	}
}

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

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

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

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

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

A,B,C = II()

if A%2==0 or B%2==0 or C%2==0:
  print(0)
else:
  print(min(A*B, A*C, B*C))

Measured memory_bytes: 38512
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut input = buf.split_whitespace();
    let (r, d, x2000) = (
        input.next().unwrap().parse().unwrap(),
        input.next().unwrap().parse().unwrap(),
        input.next().unwrap().parse().unwrap(),
    );

    for i in doa(r, d, x2000) {
        println!("{}", i);
    }
}

fn doa(r: u64, d: u64, x2000: u64) -> Vec<u64> {
    let mut v = Vec::with_capacity(10);
    let mut xi = x2000;
    for _ in 0..10 {
        xi = r * xi - d;
        v.push(xi)
    }
    v
}


Measured memory_bytes: 4352
w,a,b = map(int,input().split())
s = {int(i) for i in range(a,a+w+1)} & {int(i) for i in range(b,b+w+1)}
if s:
    print(0)
else:
    if a+w < b:
        print(b-a-w)
    elif b+w < a:
        print(a-b-w)

Measured memory_bytes: 24296
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

const int Maxn = 200;

int N;
vector<int> G[Maxn + 5];

int dis[Maxn + 5], fa[Maxn + 5];
int BFS(int s) {
	queue<int> q;
	for(int i = 1; i <= N; i++)
		dis[i] = 0, fa[i] = 0;
	fa[s] = -1;
	dis[s] = 2, q.push(s);
	int ret = 0;
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for(int i = 0; i < (int)G[u].size(); i++) {
			int v = G[u][i];
			if(v == fa[u] || dis[v] == dis[u] - 1) continue;
			if(dis[v] && dis[v] != dis[u] + 1) return -1;
			if(dis[v] && dis[v] == dis[u] + 1) continue;
			dis[v] = dis[u] + 1, fa[v] = u;
			q.push(v);
			ret = max(ret, dis[v]);
		}
	}
	return ret;
}

int main() {
#ifdef LOACL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) {
		char inp[Maxn + 5];
		scanf("%s", inp + 1);
		for(int j = 1; j <= N; j++)
			if(inp[j] == '1') G[i].push_back(j);
	}
	int ans = -1;
	for(int i = 1; i <= N; i++)
		ans = max(ans, BFS(i));
	printf("%d\n", ans == -1 ? -1 : ans - 1);
	return 0;
}


Measured memory_bytes: 384
import scala.io.StdIn.readInt

object Main extends App {
  val n = readInt
  var minv = readInt
  var maxv = Int.MinValue
  var i=1

  while(i<n) {
    val r = readInt
    val m = r-minv

    if(m > maxv) maxv = m
    if(m < 0) minv = r
    i += 1
  }
  println(maxv)
}

Measured memory_bytes: 63440
#include <bits/stdc++.h>
 
using namespace std;
 
#define cel(n, k) ((n-1)/k+1)
#define sets(a) memset(a, -1, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))
 
 
#define fr(i, n) for(int i=0; i<n;i++)
#define fr1(i, n) for(int i=1; i<=n;i++) 
 
#define readf(f) freopen(f, "r", stdin)
#define writef(f) freopen(f, "w", stdout)
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define nl "\n"
 
void file(){
	readf("in.txt");
    writef("out.txt");
}
 
template< class T > T sq(T x) { return x * x; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
 
typedef long long ll;
typedef pair<int,int> pii;
 
int main()
{
	//file();
 
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 	
 	int N, W;	

	cin>>N>>W;

	int w[W+2], v[N+2];

	ll dp[N+2][W+2];

	fr1(i,N)
		cin>>w[i]>>v[i];

	fr(i,N+1)
		dp[i][0] = 0;
	
	fr(i,W+1)
		dp[0][i] = 0;

	fr1(i,N){
		fr1(j,W){
			
			if(w[i] <= j){
				dp[i][j] = max(dp[i-1][j], v[i] + dp[i-1][j-w[i]]);
			}
			else
				dp[i][j] = dp[i-1][j];
		}
	}

	
	cout<<dp[N][W]<<nl;

	


    return 0;
 
}

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

using namespace std;

#define endl '\n'

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
const int maxn = 100000 + 10;

deque<int> build(int64 v){
	if (v == 1) return {};

	if (v & 1){
		auto answer = build(v - 1);
		int val = answer.size() + 1;
		answer.push_front( val );
		return answer;
	}
	else{
		auto answer = build(v / 2);
		int val = answer.size() + 1;
		answer.push_back( val );
		return answer;
	}

}

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

#ifdef MARX
	freopen("data.in", "r", stdin);
	// freopen("data.out", "w", stdout);
#endif

	int64 n;
	cin >> n;

	auto perm = build(n + 1);

	cout << 2 * perm.size() << endl;

	for (auto u : perm) cout << u << " ";

	for (int i = 1; i <= (int)perm.size(); ++i)
		cout << i << " ";

	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef long double ld;
using namespace std;

int gcd(int a, int b) {
  return b == 0 ? a : gcd(b, a % b);
}

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

  int n;
  cin >> n;
  vector<int> v(n), l(n), r(n);
  for (int &x : v) cin >> x;
  for (int i = 0; i < n; i++) {
    l[i] = v[i];
    if (i > 0) l[i] = gcd(v[i], l[i - 1]);
  }
  for (int i = n - 1; i >= 0; i--) {
    r[i] = v[i];
    if (i < n - 1) r[i] = gcd(v[i], r[i + 1]);
  }
  int mx = 0;
  for (int i = 0; i < n; i++) {
    int g = 0;
    if (i > 0) g = gcd(g, l[i - 1]);
    if (i < n - 1) g = gcd(g, r[i + 1]);
    mx = max(mx, g);
  }
  cout << mx << endl;

  return 0;
}

Measured memory_bytes: 1408
import java.util.*;
import java.lang.Math;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] dp = new int[n][3];
		int[][] abc=new int[n][3];
		for(int i=0;i<n;i++)for(int j=0;j<3;j++)abc[i][j]=sc.nextInt();
		for(int j=0;j<3;j++)dp[0][j]=abc[0][j];
		for(int i=1;i<n;i++){
			for(int j=0;j<3;j++){
				int _max=0;
				for(int k=0;k<3;k++){
					if(j!=k)if(_max<(dp[i-1][k]+abc[i][j]))_max=(dp[i-1][k]+abc[i][j]);
				}
				dp[i][j]=_max;
			}
		}
		int max=0;
		for(int j=0;j<3;j++)if(dp[dp.length-1][j]>max)max=dp[dp.length-1][j];
		System.out.print(max);
	}
}

Measured memory_bytes: 67112
# 下，右，上，左
dy = [1, 0, -1, 0]
dx = [0, 1, 0, -1]

H, W = map(int, input().split())

field = []

for i in range(H):
    field.append(list(input()))

for y in range(H):
    for x in range(W):
        
        if field[y][x] == "#":

            cnt = 0

            for k in range(4):

                ny = y + dy[k]
                nx = x + dx[k]

                if ny < 0 or H <= ny or nx < 0 or W <= nx:
                    continue

                if field[ny][nx] == "#":
                    cnt += 1

            if cnt == 0:
                print("No")
                exit()

print("Yes")

Measured memory_bytes: 3064
a=int(input())
b=[int(input()) for i in range(a)]
sr=list(reversed(sorted(b)))
if sr[1]==sr[0]:
  for i in range(a):
    print(sr[0])
else:
  for i in b:
    if i==sr[0]:
      print(sr[1])
    else:
      print(sr[0])

Measured memory_bytes: 14264
#include<bits/stdc++.h>
using namespace std;
long long int dp[100005];

long long int frogJump(int a[], int n, int i){
	if(i==n-1){
		return 0;
	}
	if(i>=n){
		return INT_MAX;
	}
	if(dp[i] != -1){
		return dp[i];
	}
	long long int oneJump = abs(a[i]-a[i+1]) + frogJump(a, n, i+1);
	long long int twoJump = INT_MAX;
	if(i+2 < n){
		twoJump = abs(a[i]-a[i+2]) + frogJump(a, n, i+2);
	} 
	return dp[i] = min(oneJump, twoJump);
}

int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	memset(dp, -1, sizeof dp);
	cout<<frogJump(a, n, 0)<<endl;
}

Measured memory_bytes: 9216
w,h,n = map(int,input().split())
xya = []
for i in range(n):
    array = list(map(int, input().strip().split()))
    xya.append(array)

xl1 =[0]
xl2 =[w]
yl3 =[0]
yl4 =[h]
for i in range(n):
    if xya[i][2]==1:
        xl1.append(xya[i][0])
    elif xya[i][2]==2:
        xl2.append(xya[i][0])
    elif xya[i][2]==3:
        yl3.append(xya[i][1])
    elif xya[i][2]==4:
        yl4.append(xya[i][1])
s1=min(xl2)-max(xl1)
s2=min(yl4)-max(yl3)

if s1>0 and s2>0:
    s = s1*s2
    print(s)
else:
    print(0)

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

using namespace std;
#ifdef ONLINE_JUDGE
#define cerr if(false)cerr
#endif
//#define int long long
#define ld1 long double
#define watch(x) cerr << (#x) << " is " << (x) << endl
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL),cout<<setprecision(14);
#define cint int t;cin>>t;while(t--)
#define vint vector<int>
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define pb push_back
#define N 50011
#define mm0(X) memset((X), 0, sizeof((X)))
#define mm1(X) memset((X), -1, sizeof((X)))
#define MAXN (int)1e6 + 11
#define INF (int)1e9
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define endl '\n'

const int mod=1000000007;
int powmod(int a,int b) {int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

void solve(){
    string s;
    cin>>s;
    if(s=="ABC") cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;
}

int32_t main() {
    faster;

#ifndef ONLINE_JUDGE
    READ("inp.txt");
    WRITE("out.txt");
    double beg=clock();
#endif

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

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

#ifndef ONLINE_JUDGE
    double end=clock();
    cerr<<"*** Total time = "<<(end-beg)/CLOCKS_PER_SEC;
#endif
}


Measured memory_bytes: 3644
#include<stdio.h>
#include<string.h>
int main()
{
	int j, i, k, flag = 0, tt = 0;
	char S[60], T[60], temp[60];
	gets(S);
	gets(T);

	for (i = strlen(S) - strlen(T); i >= 0; i--)
	{
		strcpy(temp, S);
		strcpy(temp + i, T);
		temp[i + strlen(T)] = S[i + strlen(T)];
		for (j = 0; j < strlen(S); j++)
		{
			if (S[j] != '?')
			{
				if (S[j] != temp[j])
				{
					break;
				}
			}
			if (j == strlen(S) - 1)
			{
				flag = 1;
				for (i = 0; i < strlen(temp); i++)
					if (temp[i] == '?') printf("a");
					else printf("%c", temp[i]);
				goto end;
			}
		}
	}

end:
	if (flag == 0)
		printf("UNRESTORABLE");


}

Measured memory_bytes: 128
import sys
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for i in range(m)]
a = ls[0][0]
b = ls[0][1]
for j in range(1,m):
    a = max(a,ls[j][0])
    b = min(b,ls[j][1])
    if b-a<0:
        print(0)
        sys.exit()
print(b-a+1)

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

int main(void){

  string s, t;
  cin >> s >> t;
  
  int ans = 0;
  for(int i=0; i<3; i++){
    if(s.at(i) == t.at(i)) ans++;
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#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.at(i);
  
  vector<int> l(n), r(n); // l.at(i)は左から(i + 1)個の数のgcd，rは右から
  l.at(0) = a.at(0);
  r.at(n - 1) = a.at(n - 1);
  for(int i = 1; i < n; i++){
    l.at(i) = gcd(l.at(i - 1), a.at(i));
  }
  for(int i = n - 2; i >= 0; i--){
    r.at(i) = gcd(r.at(i + 1), a.at(i));
  }
  
  int ans = max(l.at(n - 2), r.at(1));
  for(int i = 1; i < n - 1; i++){
    ans = max(ans, gcd(l.at(i - 1), r.at(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++)

int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  int alice=0,bob=0;
  sort(a.begin(),a.end(),greater<int>());
  rep(i,n){
    if(i%2==0)alice+=a[i];
    else bob+=a[i];
  }
  cout<<alice-bob<<endl;
  return 0;
  
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main() {
	long long n, a, b;
	long long ans = 0;
	cin >> n >> a >> b;
	if ((n > 1 && a <= b) || (n == 1 && a == b)) {
		ans = (b - a) * (n - 2) + 1;
	}
	cout << ans;
}

Measured memory_bytes: 256