akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        Dice dice = new Dice(str);
        str = br.readLine();
        for(int i=0;i<str.length();i++){
            char c = str.charAt(i);
            switch(c){
                case 'S':
                    dice.moveS();
                    break;
                case 'W':
                    dice.moveW();
                    break;
                case 'E':
                    dice.moveE();
                    break;
                case 'N':
                    dice.moveN();
                    break;
                default:
                    break;
            }
        }
        System.out.println(dice.getStr(0));
    }
}
 
class Dice{
    private String str[];//0=???,1=???,2=???,3=???,4=??????,5=???
    private String tmp;
     
    Dice(String str) {
        this.str = new String[6];
        this.str = str.split(" ");
    }
     
    public String getStr(int n){
        return this.str[n];
    }
     
    void moveW(){
        tmp = this.str[0];
        this.str[0] = this.str[2];
        this.str[2] = this.str[5];
        this.str[5] = this.str[3];
        this.str[3] = tmp;
    }
     
    void moveE(){
        tmp = this.str[0];
        this.str[0] = this.str[3];
        this.str[3] = this.str[5];
        this.str[5] = this.str[2];
        this.str[2] = tmp;
    }
     
    void moveS(){
        tmp = this.str[0];
        this.str[0] = this.str[4];
        this.str[4] = this.str[5];
        this.str[5] = this.str[1];
        this.str[1] = tmp;
    }
     
    void moveN(){
        tmp = this.str[0];
        this.str[0] = this.str[1];
        this.str[1] = this.str[5];
        this.str[5] = this.str[4];
        this.str[4] = tmp;
    }
}

Measured memory_bytes: 24368
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	Int L, R;
	cin >> L >> R;

	Int res = 1e18;
	for (int i = 0; i < 2019; ++i) {
		Int l = L + i;
		if (l >= R) { break; }
		for (int j = 1; j <= 2019; ++j) {
			Int r = l + j;
			if (r > R) { break; }
			res = min(res, l * r % 2019);
		}
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,k,q,a[100000];
	int i,b[100000]={0};
	scanf("%d %d %d",&n,&k,&q);
	for(i=0;i<q;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++){
		b[i]=k-q;
	}
	for(i=0;i<q;i++){
		b[a[i]-1]+=1;
	}
	//for(i=0;i<n;i++) printf("%d\n",b[i]);
	for(i=0;i<n;i++){
		if(b[i]>0){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2404
#include <iostream>

int main() {
    int r;
    std::cin >> r;
    if (r < 1200) std::cout << "ABC" << std::endl;
    else if (r < 2800) std::cout << "ARC" << std::endl;
    else std::cout << "AGC" << std::endl;

    return 0;
}

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))
#define PI (long double)3.1415926535

int main(){
    FAST
    int n, m; cin >> n >> m;
    int sum = 0;
    for(int i = 0; i < m; i++){
        int a; cin >> a;
        sum += a;
    }
    if(sum > n){
        cout << -1;
        return 0;
    }
    cout << n - sum;
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main(){
	char c;
	int count[26]={0},a,i;
	while(cin>>c){
		a=c-'a';
		if(a<0){
			a+=32;
		}
		count[a]++;
	}
	for(i=0;i<26;i++){
		cout<<(char)(i+'a')<<" : "<<count[i]<<endl;
	}
	return 0;
}
		

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

int main(){
  int n;
  std::cin>>n;
  long long l[90]={2,1};
  for(int i=2; i<=n; ++i)l[i]=l[i-1]+l[i-2];
  std::cout<<l[n]<<std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int ans[2010];
int main(){
	int N,X,Y,i,j,a,b,d;
	scanf("%d%d%d",&N,&X,&Y);
	for(i=1;i<=N;i++)
		for(j=i+1;j<=N;j++){
			a=j-i;
			b=(X>i?X-i:i-X)+(Y>j?Y-j:j-Y)+1;
			d=min(a,b);
			ans[d]++;
		}
	for(i=1;i<N;i++)printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
const ll MINF = LLONG_MIN;
const int INT_INF = INT_MAX;

int main()
{
    string s;
    cin >> s;
    bool res = true;
    for (int i = 0; i < s.length(); i++)
    {
        if (i % 2 == 0)
        {
            if (!(s[i] == 'R' || s[i] == 'U' || s[i] == 'D'))
                res = false;
        }
        else
        {
            if (!(s[i] == 'L' || s[i] == 'U' || s[i] == 'D'))
                res = false;
        }
    }
    cout << (res ? "Yes" : "No") << endl;
}

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

using namespace std;

typedef long long ll;
typedef double dd;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef tuple<int,int,int> iii;
typedef vector<ii> vii;

#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define DOW(i,b,a) for (int i = (b); i >= (a); i--)
#define pb(a) push_back(a)
#define ALL(a) (a).begin(),(a).end()
#define fi first
#define se second

template<typename T>
void print_array(T* arr, int num) {
   FOR(i, 0, num) cout << arr[i] << ' ';
   cout << endl;
}

template<typename T> 
void print_vector(vector<T> vec) {
   FOR(i,0,vec.size()) cout << vec[i] << ' ';
   cout << endl;
}

int n,x;
map<int,int, greater<int>> m;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
	//freopen("test.txt", "r", stdin);
	cin >> n;
	FOR(i,0,n) {
		cin >> x;
		m[x]++;
	}
	int pre = -1;
	for(ii a: m) {
		if ( a.se >= 2) {
			if (pre != -1) {
				cout << (ll)  a.fi * pre;
				return 0;
			} else if ( a.se >= 4) {
				cout << (ll)  a.fi * a.fi;
				return 0;
			} else {
				pre = a.fi;
			}
		}
	}
	cout << 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

struct BIT{
	int size;
	vector<llint> bit;
	BIT(){size = 0;}
	BIT(int s){
		size = s;
		bit.resize(size+1);
		init();
	}
	void init(){
		for(int i = 1; i <= size; i++) bit[i] = 0;
	}
	llint query(int i){
		llint ret = 0;
		while(i > 0){
			ret += bit[i];
			i -= i&(-i);
		}
		return ret;
	}
	void add(int i, llint x){
		while(i <= size){
			bit[i] += x;
			i += i&(-i);
		}
	}
};

llint n, m;
llint l[300005], r[300005];
llint dif[300005];
llint ans[300005];
vector<llint> vec[300005];
BIT bit(300005);

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		cin >> l[i] >> r[i];
		llint len = r[i]-l[i]+1;
		vec[len].push_back(i);
		dif[len]++;
	}
	for(int i = m; i >= 1; i--) ans[i] = ans[i+1] + dif[i];
	
	for(int i = 1; i <= m; i++){
		for(int j = i; j <= m; j+=i) ans[i] += bit.query(j);
		for(int j = 0; j < vec[i].size(); j++){
			llint id = vec[i][j];
			bit.add(l[id], 1);
			bit.add(r[id]+1, -1);
		}
	}
	
	for(int i = 1; i <= m; i++) cout << ans[i] << endl;
	
	return 0;
}

Measured memory_bytes: 24064
#include <bits/stdc++.h>
#define int long long
using namespace std;

pair<long double,long double> pa[10];
long double sum=0;

void printArr(int a[],int n) 
{
    long double smallSum=0;
    for(int i=1;i<n;i++)
    {
        long double xdif=pa[a[i]].first-pa[a[i-1]].first;
        long double ydif=pa[a[i]].second-pa[a[i-1]].second;
        smallSum+=sqrt(xdif*xdif+ydif*ydif);
    }
    sum+=smallSum;
} 

void heapPermutation(int a[], int size, int n) 
{ 
    if (size == 1) 
    { 
        printArr(a, n); 
        return; 
    } 
  
    for (int i=0; i<size; i++) 
    { 
        heapPermutation(a,size-1,n); 
  
        // if size is odd, swap first and last 
        // element 
        if (size%2==1) 
            swap(a[0], a[size-1]); 
  
        // If size is even, swap ith and last 
        // element 
        else
            swap(a[i], a[size-1]); 
    } 
} 
   
int32_t main() {
    int n,i,j,temp1,temp2;
    cin>>n;
    
    int b[n];
    for(i=0;i<n;i++)b[i]=i;

    for(i=0;i<n;i++)
    {
        cin>>temp1>>temp2;
        pa[i]={temp1,temp2};
    }
    heapPermutation(b,n,n);
    long double val=sum;
    for(i=1;i<=n;i++)
    val/=i;
    cout.precision(numeric_limits<long double>::digits10);
    cout<<val<<"\n";
    return 0;
}


Measured memory_bytes: 256
S = input()
N = len(S)+1
A = [0]*N

for i in range(1, N):
    if S[i-1] == '<':
        A[i] = max(A[i-1] + 1, A[i])

for i in range(N-1, 0, -1):
    if S[i-1] == '>':
        A[i-1] = max(A[i] + 1, A[i-1])

print(sum(A))

Measured memory_bytes: 29000
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String O = sc.next();
        String E = sc.next();
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<O.length();i++){
            sb.append(O.charAt(i));
            if(i<E.length()) sb.append(E.charAt(i));
        }
        System.out.println(sb.toString());
    }
}
 


Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
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;}
const int inf = 1001001001;

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    rep(i,n) cin >> d[i];
    int ans = 0;
    rep(i,n-1) rep2(j,i+1,n) {
        ans += d[i]*d[j];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,a[110];
signed main(){
    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n){
        if(a[i]%2==0){
            if(a[i]%3&&a[i]%5){
                puts("DENIED");
                return 0;
            }
        }
    }
    puts("APPROVED");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s, t;
int n, m, dp[3030][3030];
int solve(int i, int j){
    if(dp[i][j] != -1)
        return dp[i][j];

    if(i == 0 || j == 0)
        return dp[i][j] = 0;

    if(s[i - 1] == t[j - 1])
        return dp[i][j] = 1 + solve(i - 1, j - 1);

    return dp[i][j] = max(solve(i - 1, j), solve(i, j - 1));
}
int main(){
    memset(dp, -1, sizeof dp);
    cin>>s>>t;
    n = s.length(), m = t.length();
    solve(n, m);
    string res = "";
    while(n > 0 && m > 0){
        if(s[n - 1] == t[m - 1])
            res = s[n - 1] + res, n--, m--;
        else if(dp[n - 1][m] > dp[n][m - 1])
            n--;
        else m--;
    }
    cout<<res<<endl;
}


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

int main() {
  int N;
  cin >> N;
  for (int i=1 ; i<=9 ; i++){
    for (int j=1 ; j<=9 ; j++){
    if (i*j==N){
    cout << "Yes" << endl;
    return 0;
    }
    }
  }
  cout << "No" << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i= 0; i< n; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  cout << a.at(n-1) -a.at(0) <<endl;
}

Measured memory_bytes: 256
use std::io::Read;
use std::collections::HashMap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let march: Vec<char> = "MARCH".chars().collect();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut counts: HashMap<char, usize> = HashMap::new();
    for _ in 0..n {
        let first_char = iterator.next().unwrap().chars().next().unwrap();
        if march.contains(&first_char) {
            *counts.entry(first_char).or_insert(0) += 1;
        }
    }

    let zero = 0;
    let mut ans = 0;
    for i in 0..3 {
        for j in (i + 1)..4 {
            for k in (j + 1)..5 {
                let ci = counts.get(&march[i]).unwrap_or(&zero);
                let cj = counts.get(&march[j]).unwrap_or(&zero);
                let ck = counts.get(&march[k]).unwrap_or(&zero);
                ans += *ci * *cj * *ck;
            }
        }
    }
    return ans.to_string();
}


Measured memory_bytes: 4352
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())

flag = [[0] * 3 for _ in range(N)]
score = 0

for i in range(K):
    t = T[i]
    if t == 'r':
        flag[i][0] = 1
        score += P
    elif t == 's':
        flag[i][1] = 1
        score += R
    elif t == 'p':
        flag[i][2] = 1
        score += S


for i in range(K,N):
    t = T[i]
    if t == 'r':
        if flag[i-K][0] != 1:
            flag[i][0] = 1
            score += P
    if t == 's':
        if flag[i-K][1] != 1:
            flag[i][1] = 1
            score += R
    if t == 'p':
        if flag[i-K][2] != 1:
            flag[i][2] = 1
            score += S

print(score)

Measured memory_bytes: 14032
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  map<char,int>a;
  a['a']=0;
  a['c']=0;
  a['b']=0;
  char b;
  cin>>b;
  a[b]++;
  cin>>b;
  a[b]++;
  cin>>b;
  a[b]++;
  if(a['a']==1&&a['b']==1)cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		String[] ymd = in.next().split("/");
		if (ymd[0].compareTo("2019") < 0
				|| ymd[0].compareTo("2019") == 0 && ymd[1].compareTo("04") < 0
				|| ymd[0].compareTo("2019") == 0 && ymd[1].compareTo("04") == 0 && ymd[2].compareTo("30") <= 0) {
			System.out.println("Heisei");
		} else {
			System.out.println("TBD");
		}
	}
}


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

typedef long long ll;
using namespace std;

int main() {
  string s;
  cin>>s;
  
  if(s[2]==s[3] && s[4]==s[5]) {
  	cout <<"Yes";
  } else {
  	cout << "No";
  }
	return 0;
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));
mt19937_64 rnd64(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 100 * 1000 + 13;
const int AL = 26;

int n;
string s;

bool read () {
	if (scanf("%d", &n) != 1)
		return false;
	static char buf[N];
	scanf("%s", buf);
	s = buf;
	return true;
}

int cnt[AL];

void solve() {	
	memset(cnt, 0, sizeof(cnt));
	forn(i, n) ++cnt[s[i] - 'a'];
	
	int res = 1;
	forn(i, AL)
		res = (res * li(cnt[i] + 1)) % MOD;
	printf("%d\n", (res + MOD - 1) % MOD);
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
	
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef _DEBUG
	while(read()) {	
#else
	if(read()) {
#endif
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

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

int main() {
  
  int a=0, b=0, ans=0;
  
  cin >> a >> b;
  
  if((a==1 && b==2) || (a==2 && b==1)) {
    
    cout << "3" << endl;
    
  } else if((a==1 && b==3) || (a==3 && b==1)) {
    
    cout << "2" << endl;
    
  } else if((a==2 && b==3) || (a==3 && b==2)) {
    
    cout << "1" << endl;
    
  }
  
  return 0;
  
}

Measured memory_bytes: 256
S = input()
S2 = set(S)

if len(S2) == 2:
    if S[0] == S[1] and S[2] == S[3] or S[0] == S[2] and S[1] == S[3] or S[0] == S[3] and S[1] == S[2]:
        print("Yes")
        exit()

print("No")


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

using ll=long long;
struct Person{
    ll h,p;
};
bool operator<(Person lhs,Person rhs){
    return lhs.h+lhs.p<rhs.h+rhs.p;
}
const ll INF=1e16;

int main(){
    int n;
    cin>>n;
    vector<Person> hp(n);
    for(int i=0;i<n;i++) cin>>hp[i].h>>hp[i].p;
    sort(hp.begin(),hp.end());
    vector<vector<ll>> dp(n+1,vector<ll>(n+1,INF));
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=i;j++){
            if(dp[i][j]<=hp[i].h) dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+hp[i].p);
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
        }
    }
    int res=-1;
    for(int i=0;i<=n;i++){
        if(dp[n][i]<INF) res=i;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 195968
#include<bits/stdc++.h>
#define maxn 200050
#define eps 1e-6

using namespace std;
typedef long long ll;

ll a[maxn],f[maxn],n,m,k,cnt1,cnt2;
bool ck;
vector <int> h[maxn];

void dfs(int x,int y)
{
    f[x]=true;a[x]=y;
    if (y==1) cnt1++; else cnt2++;
    int sz=h[x].size();
    for (int i=0;i<sz;i++)
    {
        int tmp=h[x][i];
        if (f[tmp]){
            if (a[tmp]==a[x]) ck=false;
        }
        else dfs(tmp,-y);
    }
}

int main()
{
    scanf("%d%d",&n,&m);cnt1=cnt2=0;ck=true;
    for (int i=1;i<=n;i++) h[i].clear();
    for (int i=1;i<=m;i++)
    {
        int u,v;scanf("%d%d",&u,&v);
        h[u].push_back(v);
        h[v].push_back(u);
    }
    memset(f,false,sizeof(f));
    memset(a,0,sizeof(a));
    dfs(1,1);
    if (ck) printf("%lld\n",cnt1*cnt2-m);
    else printf("%lld\n",n*(n-1)/2-m);
    return 0;
}


Measured memory_bytes: 12032
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def X(): return list(input())
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

a = int(input())
aa = a**2
aaa = a**3
print(a+aa+aaa)


Measured memory_bytes: 10048
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    A,B,C = input_number_list()
    print(C,A,B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

int main(){

	int n;
	int score[100];
	int m = 101;
	int sum = 0;

	cin >> n;
	rep(i, 0, n) {
		cin >> score[i];
		sum += score[i];
	}

	rep(i, 0, n) {
		rep(j, 0, n) {
			if (score[i] < score[j])swap(score[i], score[j]);
		}
	}

	rep(i, 0, n) {
		if (score[i] % 10 != 0) {
			m = score[i];
			break;
		}
		if (i == n - 1) {
			m = score[0];
		}
	}

	if (sum % 10 != 0) {
		cout << sum << endl;
	}
	else if (m % 10 != 0) {
		cout << sum - m << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def dfs(curr, pare, pare_c, k, color_dic):
    curr_c = pare_c
    for chi in g[curr]:
        if chi == pare: continue
        curr_c = curr_c%k + 1
        color_dic[(curr,chi)] = curr_c
        dfs(chi, curr, curr_c, k, color_dic)


n = int(input())
g = [ [] for _ in range(n+1)]
gl = []
for i in range(n-1):
    a, b = map(int, input().split()) 
    g[a].append(b)
    g[b].append(a)
    gl.append((a,b))


k = 0
for node in g:
    k = max(len(node),k)


color_dic = {}
dfs(1, -1, 0, k, color_dic)

print(k)
for edge in gl:
    print(color_dic[edge])

Measured memory_bytes: 76900
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;

int n;
LL a[305][305];
LL tmp[305][305];

bool check() {
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			tmp[i][j] = INF;
	for(int k = 1; k <= n; k++) 
		for(int i = 1; i <= n; i++) 
			for(int j = 1; j <= n; j++) 
				tmp[i][j] = min(tmp[i][j], a[i][k] + a[k][j]);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			if(i == j) continue;
			if(a[i][j] != tmp[i][j]) return 0;
		}
	}
	return 1;
}

int main()
{
	while(scanf("%d", &n) != EOF)
	{
		for(int i = 1; i <= n; i++)
			for(int j = 1; j <= n; j++) 
				scanf("%lld", &a[i][j]);
		if(!check()) printf("-1\n");
		else {
			LL ans = 0;
			for(int i = 1; i <= n; i++) {
				for(int j = i + 1; j <= n; j++) {
					bool f = 1;
					for(int k = 1; k <= n; k++) {
						if(k == i || k == j) continue;
						if(a[i][j] == a[i][k] + a[k][j]) f = 0;
					}
					if(f == 1) ans += a[i][j];
				}
			}
			printf("%lld\n", ans);
		}
	}
	return 0;
}

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

int main()
{
   int n;
   cin >> n;
   int a[n];
   int count=0;
   
   for(int i=1;i<=n;i++)
   {
       cin >> a[i];
       if(i%2!=0 && a[i]%2!=0)
       {
           count++;
       }
   }
   cout << count ;

    return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF ll(1e9)
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll x, y;

void solve() {
    ll ans = INF * INF;
    if (y >= x) {
        ans = min(ans, abs(y - x));
    }
    if (-y >= -x) {
        ans = min(ans, abs(-y - (-x)) + 2);
    }
    if (y >= -x) {
        ans = min(ans, abs(y - (-x)) + 1);
    }
    if (-y >= x) {
        ans = min(ans, abs(-y - x) + 1);
    }
    cout << ans << endl;
}

int main() {
    cin >> x >> y;
    solve();
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, t, h int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var ts, hs string
		fmt.Scan(&ts, &hs)
		if ts > hs {
			t += 3
		} else if ts < hs {
			h += 3
		} else {
			t++
			h++
		}
	}
	fmt.Println(t, h)
}



Measured memory_bytes: 1180
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 20;
ll p10[N] = {1} , cof[N];
int D,n;

ll dfs(int c,ll D,ll way) {
    ll Mx=0;
    rep(i,c,n) Mx+=cof[i]*9;
    if(D>Mx||D<-Mx) return 0;
    if(c==n) return way;
    ll res=0;
    for(int x=c==0?0:-9;x<=9;++x)
        res+=dfs(c+1,D-x*cof[c],way*(c==0?9-x:10-abs(x)));
    return res;
}

ll solve(int len){
    rep(i,1,len) p10[i]=p10[i-1]*10;
    n = 0;
    for(int i=len-1,j=0;i>j;--i,++j)
        cof[n++]=p10[i]-p10[j];
    return dfs(0,D,1);
}

int main(){
    cin >> D;
    ll ans = 0;
    rep(len,2,19){
        ll tmp = solve(len);
        if(len & 1) tmp *= 10;
        ans += tmp;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())

from itertools import product

l = []
for i in range(3, 10):
    for prod in product(*[['3', '5', '7'] for _ in range(i)]):
        p = ''.join(list(prod))
        if p.count('3') and p.count('5') and p.count('7'):
            l.append(p)

ans = 0
for ll in l:
    if int(ll) <= n:
        ans += 1
print(ans)


Measured memory_bytes: 46320
function main()
  
  N, D = map(x -> parse(Int, x), split(readline()))
  
  D = D^2
  
  cnt = 0
  
  for i in 1:N
    X, Y = map(x -> parse(Int, x), split(readline()))
    if X^2 + Y^2 <= D
      cnt += 1
    end
  end
  
  println(cnt)
  
end

main()

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    ll A[N]; rep(i, N) cin >> A[i];
    ll sum[N+1] = {};
    rep(i, N) sum[i+1] = (sum[i] + A[i]) % mod;
    ll ans = 0;
    rep(i, N) ans = (ans + ((sum[N]-sum[i+1]) % mod)*A[i] % mod) % mod;
    if(ans < 0) ans += mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6780
// AtCode.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>

using namespace std;

typedef vector<vector<char>> Graph;
typedef vector<vector<int>> Dist;
typedef pair<int, int> P;
Graph graph;
Dist dist;

void bfs(int start_x, int start_y) {
	
	queue<P> que;  // キューを用意して、初期探索点をセット
	que.push(P(start_x, start_y));
	dist[start_x][start_y] = 0; // 初期点の距離を0

	while (!que.empty()) { // BFSループ

		// キューの先頭のセルを取得
		P v = que.front(); que.pop();
		int x = v.first;
		int y = v.second;

		// 取得したセルに対する処理

		// そのセルからつながるセルに処理を移行
		int H = graph.size();
		int W = graph[0].size();
		if (x + 1 < H) {
			if (dist[x + 1][y] == -1 && !(graph[x + 1][y] == '#') ) { // 処理以降条件
				dist[x + 1][y] = dist[x][y] + 1;
				que.push(P(x + 1, y));
			}
		}
		if (x - 1 >= 0) {
			if (dist[x - 1][y] == -1 && !(graph[x - 1][y] == '#') ) {
				dist[x - 1][y] = dist[x][y] + 1;
				que.push(P(x - 1, y));
			}
		}
		if (y + 1 < W) {
			if (dist[x][y + 1] == -1 && !(graph[x][y + 1] == '#') ) {
				dist[x][y + 1] = dist[x][y] + 1;
				que.push(P(x, y + 1));
			}
		}
		if (y - 1 >= 0) {
			if (dist[x][y - 1] == -1 && !(graph[x][y - 1] == '#') ) {
				dist[x][y - 1] = dist[x][y] + 1;
				que.push(P(x, y - 1));
			}
		}
	}

}

int main() {

	int H, W;
	cin >> H >> W;

	graph.resize(H);
	dist.resize(H);

	int black_count = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			char tmp;
			cin >> tmp;
			graph[i].push_back(tmp);
			dist[i].push_back(-1);
			if (tmp == '#') black_count++;
		}
	}

	bfs(0, 0);
	int min_dist = dist[H - 1][W - 1];
	
	if (min_dist == -1) cout << "-1" << endl;
	else cout << H*W-black_count-(min_dist+1) << endl;

	return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include <string.h>
using namespace std;
int main(){
	int N,M,a,ans=0,now=0,temp=0,d=0;
	cin>>N>>M;
	vector<int> dist,way;
	dist.push_back(0);
	for(int i=0;i<N-1;i++){
		cin>>a;
		d=(d+a)%100000;
		dist.push_back(d);
	}
	for(int i=0;i<M;i++){
		cin>>a;
		temp=now+a;
		ans=(ans+dist[max(temp,now)]-dist[min(temp,now)])%100000;
		now=temp;
	}	
	cout<<ans<<endl;
}

Measured memory_bytes: 1672
#include <bits/stdc++.h>
using std::cerr;
using std::endl;
using std::cout;
using std::cin;

const int N = 233;

std::vector<char> buc;
int len;
std::set<std::pair<int, std::string>> set;

inline int query(std::string str) {
  cout << "? " << str << endl;
  int x; cin >> x; return x;
}

inline std::string merge(std::string A, std::string B) {
  int i = 0, j = 0, sA = A.size(), sB = B.size();
  std::string str = "";
  while (i < sA && j < sB) {
    std::string tmp = str + A[i];
    for (int k = j; k < sB; ++k)
      tmp += B[k];
    int x = query(tmp);
    if (x + tmp.size() == len)
      str += A[i++];
    else
      str += B[j++];
  }
  while (i < sA) str += A[i++];
  while (j < sB) str += B[j++];
  return str;
}

int main() {
  for (int i = 0; i < 10; ++i)
    buc.emplace_back(i + '0');
  for (int i = 0; i < 26; ++i)
    buc.emplace_back(i + 'a');
  for (int i = 0; i < 26; ++i)
    buc.emplace_back(i + 'A');
  /*
  for (char c : "abc")
    buc.emplace_back(c);
  buc.pop_back();
  */

  for (char c : buc) {
    std::string str(128, c);
    int x = 128 - query(str);
    if (x == 0) continue;
    if (!len)
      len = query(std::string(1, c)) + 1;
    std::string now(x, c);
    set.insert({ x, now });
  }

  while (set.size() > 1) {
    std::string A = set.begin()->second;
    set.erase(set.begin());
    std::string B = set.begin()->second;
    set.erase(set.begin());
    std::string str = merge(A, B);
    set.insert({ (int)str.size(), str });
  }

  cout << "! " << set.begin()->second << endl;

  return 0;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;cin>>n;
    int w[n];rep(i,n)cin>>w[i];
    int ans=10000000;
    rep(i,n-1){
        int above=0;
        int below=0;
        rep(j,n){
            if(j>i)above+=w[j];
            else below+=w[j];
        }
        chmin(ans,abs(above-below));
    }
    cout<<ans<<endl;
}

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

int main(){
    long long n, k;
    cin >> n >> k;
    const int MOD = 1000000007;
    long long add;
    long long sum = 0;

    for(long long i=k;i<=n+1;i++){
        long long minsum = i * (i - 1) / 2;
        long long maxsum = i * ((2 * n) - i + 1) / 2;
        add = maxsum - minsum + 1;
        sum = (sum + add) % MOD;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll L, R, mi = 2000000000;
  cin >> L >> R;
  if((L / 2019 + 1) * 2019 <= R) cout << 0 << endl;
  else {
    for(ll i = L; i <= R - 1; i++) {
      for(ll j = i + 1; j <= R; j++) {
        if(((i % 2019) * (j % 2019) % 2019) < mi) mi = ((i % 2019) * (j % 2019) % 2019);
      }
    }
    cout << mi << endl;
  }
}

Measured memory_bytes: 3608
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) throws Exception {
        InputStreamReader r = new InputStreamReader(System.in);
        String S = nextString(r);
        int len = S.length();
        int ans = 0;
        for (int i = 0; i < len/2; i++) {
            if (S.charAt(i) != S.charAt(len-i-1)) {
                ans++;
            }
        }
        System.out.println(ans);
    }

    public static String nextString(InputStreamReader r) throws Exception {
        String str = "";
        while (true) {
            int c = r.read();
            if (c == 32 || c == 10 || c == -1) {
                break;
            }
            str += (char)c;
        }
        return str;
    }
}


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

long long n,ans;

void dfs(long long x,long long a,long long b,long long c){
  if(x>n) return; 
  if(a&&b&&c) ans++;
  dfs(x*10+3,1,b,c);
  dfs(x*10+5,a,1,c);
  dfs(x*10+7,a,b,1);
}

int main(){
  cin >> n;
  dfs(0,0,0,0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int b[101];
int p[101];
int c[101];
int main()
{
    cin>>n;
    for(int i = 1;i <= n;i++) {cin>>b[i];c[i] = b[i] - 1;}
    for(int i = 1;i <= n;i++) {
        int pos = -1;
        for(int j = n;j >= 1;j--) {
            if(c[j] == 0) {
                p[j] = i;pos = j;break;
            }
        }
        if(pos == -1) {
            puts("-1");return 0;
        }
        for(int j = pos+1;j <= n;j++) {
            c[j]--;
        }
        c[pos] = -1;
    }
    for(int i = 1;i <= n;i++) c[p[i]] = b[i];
    for(int i = 1;i <= n;i++) printf("%d ",c[i]);
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7

H, W = map(int, input().split())
INF = 10**10
N = 10
cost = [[INF]*N for _ in range(N)]

for i in range(N):
    C = list(map(int, input().split()))
    for j in range(N):
        cost[i][j] = C[j]

for i in range(N):
    for j in range(N):
        for k in range(N):
            cost[j][k] = min(cost[j][i]+cost[i][k], cost[j][k]) 

ans = 0
for h in range(H):
    A = list(map(int, input().split()))
    for a in A:
        if a!=-1:
            ans += cost[a][1]

print (ans)



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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  s[5] = ' ';
  s[13] = ' ';
  cout << s << endl;

  return 0;
}


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

using pint = pair<long long int, long long int>;

int n, m;

vector<int> a;
vector<pint> cards;

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

    a.resize(n);

    for (int i = 0; i < n; ++i) cin >> a.at(i);

    sort(a.begin(), a.begin()+n);

    cards.resize(m+n);

    for (int i = 0; i < m; ++i) cin >> cards.at(i).second >> cards.at(i).first;

    for (int i = m; i < m+n; ++i) cards.at(i) = pint(a.at(i-m), 1);

    sort(cards.begin(), cards.end());
    reverse(cards.begin(), cards.end());

    int rn = n;
    long long int ans = 0;

    for (int i = 0; i < m+n; ++i)
    {
        if (rn <= cards.at(i).second)
        {
            ans += cards.at(i).first * rn;
            rn = 0;
            break;
        }

        ans += cards.at(i).first * cards.at(i).second;
        rn -= cards.at(i).second;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3712
#include<cstdio>
#include<vector>
#include<tuple>
#include<queue>

using namespace std;

vector<pair<int, int>> map[100001];

long long ds[100001], dt[100001];
long long cs[100001], ct[100001];

const int MOD = 1000000007;

void dijk(int n, int s, long long *d, long long *c) {
	priority_queue<pair<long long, int>> H;
	for (int i = 1; i <= n; i++) d[i] = -1;
	c[s] = 1; d[s] = 0;
	H.emplace(0, s);
	long long w; int x, xx;
	while (!H.empty()) {
		tie(w, x) = H.top(); H.pop();
		if ((w*=-1) != d[x]) continue;
		for (auto &e : map[x]) {
			tie(xx, w) = e;
			if (d[xx] == -1 || d[xx] > d[x] + w) {
				d[xx] = d[x] + w;
				c[xx] = c[x];
				H.emplace(-d[xx], xx);
			}
			else if(d[xx] == d[x] + w) (c[xx] += c[x]) %= MOD;
		}
	}
	return;
}

int main() {
	int n, m, s, t, a, b, d;
	scanf("%d%d%d%d", &n, &m, &s, &t);
	for (int i = 1; i <= m; i++) {
		scanf("%d%d%d", &a, &b, &d);
		map[a].emplace_back(b, d);
		map[b].emplace_back(a, d);
	}
	dijk(n, s, ds, cs);
	dijk(n, t, dt, ct);
	vector<long long> c;
	long long D = ds[t], ans = 0, S = 0;
	for (int i = 1; i <= n; i++) {
		if (ds[i] == dt[i]) c.push_back(cs[i] * ct[i] % MOD);
		if (ds[i] * 2 >= D) continue;
		for (auto e : map[i]) {
			if (ds[i] + e.second + dt[e.first] != D) continue;
			if (dt[e.first] * 2 < D) c.push_back(cs[i] * ct[e.first] % MOD);
		}
	}
	for (auto x : c) (S += x) %= MOD;
	for (auto x : c) {
		ans = (ans + x*(S-x+MOD)) % MOD;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 15060
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<cctype>
#define lowbit(x) (x & (-x))
#define rep(i,x,y) for(register int i = x  ;i <= y; ++ i)
typedef long long ll;
using namespace std;
template<typename T>inline void read(T&x)
{
	x = 0;char c;int sign = 1;
	do { c = getchar(); if(c == '-') sign = -1; }while(!isdigit(c));
	do { x = x * 10 + c - '0'; c = getchar(); }while(isdigit(c));
	x *= sign;
}
inline void init(string name )
{
	string in = name + ".in",out = name + ".out";
	freopen(in.c_str(),"r",stdin);
	freopen(out.c_str(),"w",stdout);
}

const int N = 101;
int a[N][N],f[N][N],n;

int main()
{
	read(n);
	rep(i,1,2)
		rep(j,1,n) 
			read(a[i][j]);
	
	rep(i,1,2)
		rep(j,1,n)
			f[i][j] = max(f[i - 1][j] , f[i][j - 1]) + a[i][j];
			
	cout << f[2][n] << endl;
	
	return 0;
}

Measured memory_bytes: 256
//verma_ankit484

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
const int mod = (int) 1e9+7;

using namespace std;
//using namespace __gnu_pbds;

//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


int32_t main() {
  IOS
  #ifdef AV
  freopen("input.txt", "r", stdin);
  #endif
  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
  return 0;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

int n,dp[100005][5],a[100005][5],k; 
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++){
		scanf("%d %d %d",&a[i][1],&a[i][2],&a[i][3]);
	}
	dp[1][1]=a[1][1]; dp[1][2]=a[1][2]; dp[1][3]=a[1][3];
	for (int i=2;i<=n;i++){
		dp[i][1]=max(dp[i-1][2]+a[i][1],dp[i-1][3]+a[i][1]);
		dp[i][2]=max(dp[i-1][1]+a[i][2],dp[i-1][3]+a[i][2]);
		dp[i][3]=max(dp[i-1][1]+a[i][3],dp[i-1][2]+a[i][3]);
	}
	printf("%d\n",max(max(dp[n][1],dp[n][2]),dp[n][3]));
	return 0;
} 

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

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int k = scan.nextInt();

		int[] h = new int[n];

		int i;
		for(i = 0; i < n; i++) {
			h[i] = scan.nextInt();
		}

		Arrays.sort(h);

		if(k >= n) {
			System.out.println(0);
			return;
		}else {
			long sum = 0;
			for(i = 0; i < n - k; i++) {
				sum += h[i];
			}
			System.out.println(sum);
			return;
		}

	}
}

Measured memory_bytes: 85912
H, W, K = map(int, input().split())
C = []
for h in range(0, H):
    c = str(input())
    C.append(c)
ans = 0
for h in range(0, 2**H):
    for w in range(0, 2**W):
        cnt = 0
        for i in range(0, H):
            for j in range(0, W):
                if ((h >> i) & 1) and ((w >> j) & 1) and (C[i][j] == '#'):
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)


Measured memory_bytes: 9144
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int H,W;
    cin>>H>>W;
    vector<vector<string>>S(H,vector<string>(W));
    for(int i=0;i<H;i++){
        for(char j=0;j<W;j++){
            cin>>S.at(i).at(j);
            if(S.at(i).at(j)=="snuke"){cout<<(char)(j+'A')<<i+1<<endl;return 0;}
        }
    }
    return 0;
}

Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def MS(): return map(str, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
# N = I()
# A = [LI() for _ in range(N)]

import bisect


a = LI()
for i in range(5):
    if a[i] == 0:
        ans = i+ 1
print(ans)



Measured memory_bytes: 27212
#include <iostream>
#include <string>
#include <algorithm>

std::string str;

bool dat[(int)1e5];

int main() {

    std::cin>>str;

    for(int i=0;i<str.size();++i){
        if(str[i]=='1')
            dat[i]=true;
    }

    bool flag=true;

    if(!dat[0])
        flag=false;

    int ans=str.size();

    for(int i=1;i<(str.size()+1)/2;++i){
        if(dat[i]!=flag){
            ans=str.size()-i;
            flag=!flag;
        }
    }

    int res=str.size();

    for(int i=(str.size()+1)/2;i<str.size();++i){
        if(flag!=dat[i]){
            res=i;
            break;
        }
    }

    std::cout<<std::min(ans,res)<<std::endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}


int main(){
  long long N,M;
  cin >> N >> M;
  long long ans = 0;
  if(N == 1 && M >= 3) ans = M-2;
  else if(M == 1 && N >= 3) ans = N-2;
  else  ans = N * M - 2*N - 2*M + 4;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
def I():
	return int(sys.stdin.readline().rstrip())


def SL():
	return S().split()


def IL():
	return list(map(int, sys.stdin.readline().rstrip().split()))


N = I()
h_i = IL()
dp = [0 for _ in range(N)]
for i in range(N):
	if i == 0:
		pass
	elif i == 1:
		dp[i] = abs(h_i[i] - h_i[i-1])
	else:
		point_1 = abs(h_i[i] - h_i[i-1]) + dp[i-1]
		point_2 = abs(h_i[i] - h_i[i-2]) + dp[i-2]
		if point_1 <= point_2:
			dp[i] = point_1
		else:
			dp[i] = point_2

print(dp[-1])

Measured memory_bytes: 13924
n = int(input())
x = [int(i) for i in input().split()]
p = 10000000
for i in range(100):
    pi = 0
    for j in range(n):
        pi += (x[j] - (i + 1))**2
    if pi < p:
        p = pi
    # else:
    #     break
        # p[i] += (x[j]-(i+1))**2
print(p)

Measured memory_bytes: 2940
#include <iostream>

int main(void)
{
    long long A, B, K;

    std::cin >> A >> B >> K;

    if (K < A) {
        std::cout << A - K << ' ' << B;
    } else if (K < A + B) {
        std::cout << 0 << ' ' << B - (K - A);
    } else {
        std::cout << "0 0";
    }

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <vector>
using namespace std;
const double eps = 1e-10;
#define EQ(a, b) (abs((a) - (b)) < eps)
using P = complex<double>;      // position
struct L : vector<P> {
    L(const P &a = P(), const P &b = P()) {
        emplace_back(a); emplace_back(b);
    }
};
double dot(const P &a, const P &b) { return real(conj(a) * b); }
double cross(const P &a, const P &b) { return imag(conj(a) * b); }

enum CCW_RESULT { CCW = +1, CW = -1, BEHIND = +2, FRONT = -2, ON = 0 };
int ccw(P a, P b, P c) {
    b -= a; c -= a;
    if (cross(b, c) > eps) return CCW;      // counter clockwise
    if (cross(b, c) < -eps) return CW;      // clockwise
    if (dot(b, c) < 0) return BEHIND;       // c--a--b on line
    if (norm(b) < norm(c)) return FRONT;    // a--b--c on line | a=b
    return ON;                              // on segment | a=c | b=c
}

#include <iostream>
#include <iomanip>
enum {
    COUNTER_CLOCKWISE = 1, CLOCKWISE = -1,
    ONLINE_BACK = 2, ONLINE_FRONT = -2, ON_SEGMENT = 0
};
int main() {
    cout << fixed << setprecision(10);
    int a, b, c, d; cin >> a >> b >> c >> d;
    P p1(a, b), p2(c, d);
    int q; cin >> q;
    while (q--) {
        int x, y; cin >> x >> y;
        int res = ccw(p1, p2, P(x, y));
        if (res == COUNTER_CLOCKWISE) cout << "COUNTER_CLOCKWISE" << endl;
        if (res == CLOCKWISE) cout << "CLOCKWISE" << endl;
        if (res == ONLINE_BACK) cout << "ONLINE_BACK" << endl;
        if (res == ONLINE_FRONT) cout << "ONLINE_FRONT" << endl;
        if (res == ON_SEGMENT) cout << "ON_SEGMENT" << endl;
    }
    return 0;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int64 a, b, k;
  cin >> a >> b >> k;
  int64 d1 = min(a, k);
  a -= d1;
  k -= d1;
  int64 d2 = min(b, k);
  b -= d2;
  k -= d2;
  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
signed main () {
	int n;
  	cin >> n;
  	n %= 10;
  	if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
      	cout << "hon\n";
  	else if (n == 0 || n == 1 || n == 6 || n == 8)
      	cout << "pon\n";
 	else
      	cout << "bon\n";
}

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

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

inline void Main() {
  // code
  string s;
  cin>>s;
  rep(i,3) {
    if(s[i] == s[i+1]) {
      cout<<"Bad"<<endl;
      return;
    }
  }
  cout<<"Good"<<endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256