akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

class Main{
	@SuppressWarnings("resource")
	public static void main(String[] args) {
		//??\????????£?¨?
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] hako = new int[n];
		long sum = 0;
		int max = -1000000;
		int min = 1000000;

		for(int i = 0; i < n; i++){
			hako[i] = scan.nextInt();
			sum = sum + hako[i];
		}
		
		//??\?????????

		for (int i=0; i<hako.length; i++) {
			if (max < hako[i]) {
				max = hako[i];
			}
			if (min > hako[i]) {
				min = hako[i];
			}
		}
		 
		//??????
		System.out.println(min + " " + max + " " + sum);
	}
}

Measured memory_bytes: 42464
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in '1'*n]
b = [list(map(int, input().split())) for _ in '1'*m]
for i in a:
	d=[]
	for j in b:
		d.append(abs(i[0]-j[0])+abs(i[1]-j[1]))
	print(d.index(min(d))+1)

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

bool read(int &x)
{ return scanf("%d", &x)  != EOF; }
void write(int x)
{ printf("%d", x); }

const int N = 1500 + 10;
const int M = 3000 + 10;

int n, m;
struct EDG { int u, v, wei; int getNode(int x) { return x ^ u ^ v; } } edg[M];
vector<int > adj[N];

bool mark[N];
bool finalMark[N];
int minDist[N][N];
queue<pair<int, int > > Q;

const int inf = 1e9 + 7;

struct data {
    int u, du, source;
    bool operator < (const data &A) const
    { return du > A.du; }
};
priority_queue<data > PQ;

void build_mintable(){
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++) minDist[i][j] = inf;
        minDist[i][i] = 0;
        PQ.push({i, 0, i});
    }
    while (!PQ.empty()){
        data tmp = PQ.top(); PQ.pop();
        int u = tmp.u, du = tmp.du, su = tmp.source;
        if (du != minDist[su][u]) continue;
        for (int id : adj[u]){
            int v = edg[id].getNode(u);
            if (minDist[su][v] > du + edg[id].wei) {
                minDist[su][v] = du + edg[id].wei;
                PQ.push({v, minDist[su][v], su});
            }
        }
    }
}

main(){
    // freopen("7.inp", "r", stdin);
    // freopen("7.out", "w", stdout);
    read(n); read(m);
    for (int i = 1; i <= m; i++){
        int a, b, c;
        read(a); read(b), read(c);
        edg[i] = {a, b, c};
        adj[a].push_back(i);
        adj[b].push_back(i);
    }

    build_mintable();
		static vector<int > finAns;
    int maxD = 0;
	for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) maxD = max(maxD, minDist[i][j]);
    for (int i = 1; i <= n; i++){
        memset(mark, 0, sizeof mark);
        while (Q.size()) Q.pop();
        for (int j = i + 1; j <= n; j++)
            if (minDist[i][j] == maxD)
                Q.push({j, j}), mark[j] = 1;
        while (!Q.empty()){
            int u = Q.front().first;
            int su = Q.front().second;
            Q.pop();
            for (int id : adj[u]){
                int v = edg[id].getNode(u);
                if (minDist[v][i] + edg[id].wei + minDist[u][su] == minDist[su][i] && !mark[v]){
                    mark[v] = 1;
                    Q.push({v, su});
                }
            }
        }

        for (int j = 1; j <= n; j++)
            finalMark[j] |= mark[j];
    }
    for (int i = 1; i <= n; i++)
        if (!finalMark[i]) finAns.push_back(i);
	write(finAns.size()); printf("\n");
	for (int u : finAns)
		write(u), printf("\n");
}



Measured memory_bytes: 61120
from statistics import mean

frame_num = int(input())
frame_value = list(map(int, input().split()))
avg = mean(frame_value)
min_frame = max(frame_value)
thumbanil = 0
for frame, value in enumerate(frame_value):
    diff = abs(avg - value)
    # print(diff, value, frame)
    if diff < min_frame:
        min_frame = diff
        thumbanil = frame

print(thumbanil)



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

ll N;
vector<ll> A(200001, 0);
pair<ll, ll> L[200001];
pair<ll, ll> R[200001];

void MakePair(ll tail, ll t_sum, ll h_sum, pair<ll, ll> *P){
    for(ll head = 1; head < N - 2; ++head){
        h_sum += A[head];
        while(tail < head - 1 && abs(h_sum - t_sum) > abs((h_sum - A[tail + 1]) - (t_sum + A[tail + 1]))){
            ++tail;
            t_sum += A[tail], h_sum -= A[tail];
        }
        P[head] = make_pair(t_sum, h_sum);
    }
    return ;
}

int main(void){
    
    cin >> N;
    for(ll i = 0; i < N; ++i) cin >> A[i];
    
    MakePair(0, A[0], 0, L);
    reverse(A.begin(), A.begin() + N);
    MakePair(0, A[0], 0, R);
    
    ll j = N - 3, ans = LLONG_MAX;
    for(ll i = 1; i < N - 2; ++i){
        ll mx = max(max(L[i].first, L[i].second), max(R[j].first, R[j].second));
        ll mn = min(min(L[i].first, L[i].second), min(R[j].first, R[j].second));
        --j;
        ans = min(ans, mx - mn);
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 8064
// mod custom_lib;
use std::cmp;

use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: u32) -> Vec<T> {
  read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: u32, mut a: Vec<T>) -> Vec<T> {
  match n {
    0 => a,
    _ => {
      a.push(read::<T>());
      read_n_logic(n - 1, a)
    }
  }
}

fn main() {
  let n = read::<u32>();
  let w = read_n::<i32>(n);

  let mut sum: i32 = w.iter().sum();

  let mut possible_ans = 0;
  let mut answer = 100000000;
  for item in w {
    possible_ans += item;
    sum -= item;
    answer = cmp::min(answer, (sum - possible_ans).abs());
  }
  println!("{}", answer);
}

Measured memory_bytes: 4352
/*
 ============================================================================
 Name        : AtCoder_A.c
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>

int main(void) {
	char text[3];
	int a=0,b=0,c=0;
	int i;

	scanf("%s",text);

	for(i=0; i<3; i++){
		if(text[i]== 'a'){
			a=1;
		}
		if(text[i]== 'b'){
					b=1;
		}
		if(text[i]== 'c'){
					c=1;
		}
	}

	if( (a+b+c) ==3){
		printf("Yes");
	}else{
		printf("No");
	}
	return EXIT_SUCCESS;
}


Measured memory_bytes: 128
d,n = map(int, input().split())

if d == 0:
  if n == 100: print(101)
  else: print(n)
elif d == 1:
  if n == 100: print(n*100+100)
  else: print(n*100)
else:
  if n == 100: print(n*(100**2)+10000)
  else: print(n*(100**2))

Measured memory_bytes: 9088
def dfs(i, m, l):
    if i == m:
        return [l]
    ans = dfs(i+1, m, l+[i])
    ans += dfs(i+1, m, l)
    return ans


def main():
    H, W, K = map(int, input().split())
    M = [input() for _ in range(H)]
    r_cnt = [0]*H
    c_cnt = [0]*W
    for i, row in enumerate(M):
        for j, c in enumerate(row):
            if row[j] == "#":
                r_cnt[i] += 1
                c_cnt[j] += 1
    ans = 0
    bc = 0
    r_combi = dfs(0, H, [])
    c_combi = dfs(0, W, [])
    for rc in r_combi:
        for cc in c_combi:
            for r in rc:
                bc += r_cnt[r]
            for r in rc:
                for c in cc:
                    if M[r][c] == "#":
                        bc -= 1
            if bc == K:
                ans += 1
            bc = 0
    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

int main(void)
{
	int n,x; cin>>n>>x;
	int a[n]; for(int i = 0; i < n; i++) cin>>a[i];
	int left = 0, right = 1;
	long long ans = 0;
	for(int i = 0; i < n; i++){
		if(a[i] > x){
			ans+=(a[i]-x);
			a[i] = x;
		}
	}
	while(left < n && right < n){
		if(a[left]+a[right] > x){
			ans += (a[right]+a[left])-x;
			a[right] = x - a[left];
		}
		left++;
		right++;
	}
	
	cout<<ans<<endl;

	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef long long ll;

using namespace std;

int main(int argc, const char * argv[]) {
  ll A, B;
  cin >> A >> B;
  if(A<10 && B < 10) cout << A*B;
  else cout << -1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n+1;i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int n,k;
  cin >> n >> k;
  int ans = 1;
  n -= k;
  if(n <= 0){
    cout << ans << endl;
    return 0;
  }
  while(n > 0){
    n -= k-1;
    ans ++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/*
          .  .
          |\_|\
          | a_a\
          | | "]
      ____| '-\___
     /.----.___.-'\
    //        _    \
   //   .-. (~v~) /|
  |'|  /\:  .--  / \
 // |-/  \_/____/\/~|
|/  \ |  []_|_|_] \ |
| \  | \ |___   _\ ]_}
| |  '-' /   '.'  |
| |     /    /|:  |
| |     |   / |:  /\
| |     /  /  |  /  \
| |    |  /  /  |    \
\ |    |/\/  |/|/\    \
 \|\ |\|  |  | / /\/\__\
  \ \| | /   | |__
       / |   |____)
       |_/
*/

#include<bits/stdc++.h>

#define iamabatman ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define precision cout.precision(10); cout << fixed;
#define endl '\n'

#define ll long long int
#define ull unsigned long long int
#define ld long double
const int INF = 1<<29;
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pii pair<int,int>
#define vi vector<int>
#define vs vector<string>
#define vvi vector<vector<int>>
#define mii map<int,int>
#define msi map<string,int>
#define mis map<int,string>

#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define debug(x) cerr<<#x<<'='<<(x)<<endl;
using namespace std;


void solve()
{
  ll ans=0;
  int n,rc=0,gc=0,bc=0;
  cin>>n;
  string s;
  cin>>s;
  int r[n],g[n],b[n];
  int l=n-1;
  for(int i=n-1;i>=0;i--)
  {
    if(s[i]=='R')
      rc++;
    else if(s[i]=='G')
      gc++;
    else
      bc++;
    r[i]=rc;
    g[i]=gc;
    b[i]=bc;
  }
  for(int i=0;i<n;i++);
    //cout<<g[i]<<" ";
  cout<<endl;
  for(int i=0;i<n-2;i++)
  {
    char k,l;
    int c=i+1,d=i+2,m=0;
    if(s[i]=='R')
      k='G',l='B';
    else if(s[i]=='G')
      k='R',l='B';
    else
      k='G',l='R';
    while(d<n)
    {

      if((s[c]==k && s[d]==l) || (s[c]==l && s[d]==k))
          m++;
      c++;
      d=c+(c-i);
    }

    if(s[i]=='R')
     ans+=(b[i])*(g[i]);
    else if(s[i]=='G')
      ans+=(r[i])*(b[i]);
    else
      ans+=(g[i])*(r[i]);
      ans-=m;
  }
  cout<<ans;
}


int main()
{

  iamabatman
  precision

  int t=1;
  //cin>>t;
  for(int ha=1;ha<=t;ha++)
  {
    //cout<<"Case #"<<ha<<": ";
    solve();
  }
  return 0;
}
/*
if(s[i]=='R')
     ans+=(b[i]-m)*(g[i]-m);
    else if(s[i]=='G')
      ans+=(r[i]-m)*(b[i]-m);
    else
      ans+=(g[i]-m)*(b[i]-m);*/


Measured memory_bytes: 3696
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 10000
using namespace std;
typedef long long ll;

int main(){
  string s; cin >> s;
  string fs = s.substr(0, s.length()/2-1);
  s.pop_back();
  s.pop_back();
  while(s.length() != 0){
    if(fs + fs == s){
      cout << fs.length()*2 << endl;
      break;
    }
    rep(i, 0, 2)  s.pop_back();
    fs.pop_back();
  }
  return 0;
}


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

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int H, N;
    cin >> H >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    int sum = 0;
    for (int i = 0; i < N; i++) sum += A[i];
    cout << (sum >= H ? "Yes" : "No") << endl;
    return 0;
}






Measured memory_bytes: 1024
_ = gets.to_i
A = gets.split.map(&:to_i)

def check(array)
  array.each do |ai|
    if ai.even?
      if ai % 3 != 0 && ai % 5 != 0
        puts "DENIED"
        return
      end
    end
  end

  puts "APPROVED"
end

check(A)

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#include <cassert>
#include <map>
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
#define ll long long
constexpr ll MOD = 1e9 + 7;
ll gcd(ll a, ll b) {return b % a ? gcd(b % a, a) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
using namespace std;
using P = pair<ll, ll>;
using VI = vector<ll>;

int cnt(string s, string t) {
//    cout << s << " " << t << endl;
    int sc[26] = {};
    int tc[26] = {};
    for (char c: s) {
        sc[c - 'a']++;
    }
    for (char c: t) {
        tc[c - 'a']++;
    }
    int ans = 0;
    REP(i,26) {
        ans += !!(sc[i] * tc[i]);
    }
    return ans;
}

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int a = 0;
    for (int i = 1; i < n; i++) {
        a = max(a, cnt(s.substr(0,i), s.substr(i)));
    }
    cout << a << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int A, B, Q;
ll s[100000], t[100000];

ll calc(ll x, int si, int ti){
	ll s1, s2 = s[si + 1];
	if(si != -1)
		s1 = s[si];
	else
		s1 = s2;
	ll t1, t2 = t[ti + 1];
	if(ti != -1)
		t1 = t[ti];
	else
		t1 = t2;
	/*
	d2(s1, s2);
	d2(t1, t2);
	YN;
	*/
	ll rec = LINF;
	rec = min(abs(x - s1) + min(abs(s1 - t1), abs(s1 - t2)), abs(s2 - x) + min(abs(s2 - t1), abs(s2 - t2)));
	ll r = min(abs(x - t1) + min(abs(s2 - t1), abs(s1 - t1)), abs(t2 - x) + min(abs(t2 - s1), abs(t2 - s2)));
	return min(rec, r);
}
void solve(){
	rep(i, Q){
		ll x;
		cin >> x;
		int si = lower_bound(s, s + A, x) - s;
		int ti = lower_bound(t, t + B, x) - t;
		/*
		d2(x, si);
		d(ti);
		YN;
		*/
		cout << calc(x, si - 1, ti - 1) << endl;
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> A >> B >> Q;
	rep(i, A) {
		cin >> s[i];
	}
	rep(i, B)
		cin >> t[i];
		solve();
	return 0;
}


Measured memory_bytes: 2944
n = int(input())
s = list(map(int,input().split()))

t = sum(x < 0 for x in s)
p = 0
p1 = abs(s[0])
q = abs(s[0])

if t % 2 == 0:
    for i in range(n):
        p += abs(s[i])
    print(p)
else:
    for i in range(n-1):
        p1 += abs(s[i+1])
        q = min(q,abs(s[i+1]))
    print(p1-q*2)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d,n;
    cin>>n>>a>>b>>c>>d;
    string s;
    cin>>s;
    for(int i=a+1;i<c-1;i++){
        if(s[i]=='#'&&s[i-1]=='#'){
            cout << "No"<<endl;
            return 0;
        }
    }
    for(int i=b+1;i<d-1;i++){
        if(s[i]=='#'&&s[i-1]=='#'){
            cout << "No"<<endl;
            return 0;
        }
    }
    if(d<c){
        for(int i=b-1;i<d;i++){
            if(s[i]=='.'&&s[i-1]=='.'&&s[i+1]=='.'){
                cout << "Yes"<<endl;
                return 0;
            }
        }
        cout <<"No"<<endl;
    }else{
        cout << "Yes"<<endl;
    }
    return 0;
}



Measured memory_bytes: 592
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <assert.h>
#include <numeric>

using namespace std;

int solve() {
    int N;
    cin >> N;

    vector<int> As(N);
    for (int i = 0; i < N; i++) {
        int X;
        cin >> X;
        As[i]=X;
    }
    sort(As.begin(), As.end());
    int n = As[As.size()-1];
    int m = (n+1)/2;
    int r = 0;
    for (int i = 0; i < N; i++) {
        if (abs(m-r) > abs(m-As[i])) {
            r = As[i];
        }
        if (As[i] > m) break;
    }
    
    cout << n << " " << r << endl;
    return 0;
}

int main() {
    solve();
#ifdef DEBUG
    while (1) {
        solve();
    }
#endif
}


Measured memory_bytes: 640
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    vector<int> viHeight(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &viHeight[i]);
    }
    int nCount = 0;
    while(true){
      int nSegmentCount = 0;
      bool bSegment = false;
      for(int i = 0; i < n; i++){
          if(viHeight[i] == 0){
              bSegment = false;
          } else {
              if(!bSegment){
                  nSegmentCount++;
                  bSegment = true;
              }
              viHeight[i] -= 1;
          }
          
      }
      nCount += nSegmentCount;
      bool bAllZero = true;
      for (int i = 0; i < n; i++){
          if(viHeight[i] > 0){
              bAllZero = false;
              break;
          }
      }
      if(bAllZero){
          break;
      }
    }
    
    printf("%d", nCount);

    return 0;
}


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

int main()
{
	ll A,B,K;
	cin >> A >> B >> K;
	vector<ll> N;
	ll cnt(0);
	for(ll i(100);i>=1;--i){
		if(A%i == 0 && B%i == 0){
			cnt++;
		}
		if(cnt == K){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 2e9
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a1,a2,a3;
    cin>>a1>>a2>>a3;
    a1=a1+a2+a3;
    cout<<(a1>=22 ? "bust" : "win")<<'\n';
    
    return(0);
}

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

char F[102][102];

void DFS(int H,int W,char a)
{
	if(F[H][W]!=a)
		return;

	F[H][W]='.';

	DFS(H-1,W,a); //???
	DFS(H,W+1,a); //???
	DFS(H+1,W,a); //???
	DFS(H,W-1,a); //???
}	

int main(){
	int N,M;
	while(1){
	cin>>N>>M;
	
	if(N==0&&M==0)
            return 0;
            
	for(int h=1;h<=N;h++)
		for(int w=1;w<=M;w++)
			cin>>F[h][w];
			
	int cnt=0;
	for(int h=1;h<=N;h++)
		for(int w=1;w<=M;w++)
			if(F[h][w]=='@'){
				cnt++;
				DFS(h,w,'@');
			}else if(F[h][w]=='#'){
				cnt++;
				DFS(h,w,'#');
			}else if(F[h][w]=='*'){
				cnt++;
				DFS(h,w,'*');
			}
                
	cout<<cnt<<endl;
	}
	return 0;
}							

Measured memory_bytes: 3300
#include<stdio.h>
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if((a+b)>(c+d))
	{
		printf("Left\n");
	}
		else if((a+b)<(c+d))
	{
		printf("Right\n");
	}
	else
	{
		printf("Balanced\n");
	}
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

//スタックに入るデータの上限
#define MAX_STACK_NUM 10

//スタック構造体
typedef struct STACK{
    //スタックされているデータの数
    int num;
    //スタックされているデータ
    int data[MAX_STACK_NUM];
} STACK_T;

void initStack(STACK_T*);
void printStack(STACK_T*);
void push(STACK_T*, int);
int pop(STACK_T*);

//スタックを初期化する関数
void initStack(STACK_T *stack){
    int i = 0;
    //データの数を初期化
    stack -> num = 0;
    //データの中身を初期化
    for (i = 0; i < MAX_STACK_NUM; i++){
        stack -> data[i] = 0;
    }
}

//pushする関数
void push(STACK_T *stack, int input){
    //スタックが満杯なら何もせずに関数終了
    if (stack -> num >= MAX_STACK_NUM){
        return;
    }

    //データをスタックの最後に追加
    stack -> data[stack -> num] = input;
    //データの数もカウントアップ
    stack -> num++;
}

//popする関数
int pop(STACK_T *stack){
    int i = 0;
    int ret = 0;

    //スタックが空ならなにもせずに関数終了
    if (stack -> num == 0){
        return (-1);
    }

    //一番最後にpushした数（配列の最後尾）を取得
    ret = stack -> data[stack -> num - 1];
    //popしたのでスタックのデータを１減らす
    stack -> num--;

    return ret;
}

int main(void)
{
    int input;
    int output;
    STACK_T stack;

    //スタックを初期化
    initStack(&stack);

    while (fscanf(stdin,"%d", &input) != EOF){
        //scanf("%d", &input);

        if (input == 0){
            output = pop(&stack);
            if (output != -1){
                printf("%d\n", output);
            }
        }else {
            push(&stack, input);
        }
    }

    return (0);
}



Measured memory_bytes: 2048
#
import sys
import math
import numpy as np
import itertools

def gcd(m,n):
    p=max(m,n)
    q=min(m,n)
    if p % q == 0:
        return q
    else:
        return gcd(q,p%q)



# いくつか入力
a,b,c,d = (int(i) for i in input().split())  

x = b // c - (a-1) // c
y = b // d - (a-1) // d
e = c * d // gcd(c,d)
z = b // e - (a-1) // e

print(b-a+1-x-y+z)



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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

ll s;

ll modpow(ll a, ll b, ll m){
  ll r = 1;
  while(b){
    if(b&1)r=r*a%MOD;
    a=a*a%MOD;
    b>>=1;
  }
  return r;
}

ll num(ll x){
  ll ret = 9ll;
  return ret * modpow(10, x-1, MOD) % MOD;
  // REP(i,x-1){
  //   ret *= 10ll;
  //   ret %= MOD;
  // }
  // return ret;
}

ll extgcd(ll a,ll b,ll &x,ll &y){
  ll g=a;
  x=1;
  y=0;
  if(b!=0){
    g = extgcd(b,a%b,y,x);
    y -= (a/b)*x;
  }
  return g;
}

#define dfl(a,b) ((a)>=0 ? (a)/(b) : ((a)-(b)+1)/(b))
#define dce(a,b) ((a)<0 ? (a)/(b) : ((a)+(b)-1)/(b))

ll calc(ll s, ll x, ll y){
  // make s from x-digit number and y-digit number
  // use x and y at least once
  ll ux, uy;
  ll g = extgcd(x,y,ux,uy);
  if(s%g != 0)return 0;
  ll nx = x > 8 ? 100000000ll : num(x);
  ll ny = y > 8 ? 100000000ll : num(y);
  x /= g;
  y /= g;
  s /= g;
  ux *= s;
  uy *= s;
  ll n = min(dfl(uy-1,x), dfl(nx-ux,y));
  ll m = max(dce(1-ux,y), dce(uy-ny,x));
  // printf("%lld %lld %lld -> %lld %lld\n", s*g,x*g,y*g, n,m);
  return max(0ll, n-m+1);
}


int main(){
  cin>>s;
  ll ans = 0;
  // use triple
  FOR(x,1,9){
    ll bet = 0;
    FOR(y,x+1,10){
      bet += num(y) * y;
      if(bet>s)break;
      ans += calc(s-bet,x,y+1);
      ans %= MOD;
    }
    ans += calc(s,x,x+1);
    ans %= MOD;
  }
  // use double
  FOR(x,9,s){
    ll z = 1 - 2ll*(x+1ll) + s;
    ll n = dfl(z,x);
    ll m = dce(z,x+1);
    ans += max(0ll, n-m+1);
  }
  // use single
  for(int x=1;x*x<=s;x++){
    if(s%x==0){
      ll y = x;
      ll n = num(y);
      ll need = s/y;
      if(y > 8 || need <= n){
        ans += n-need+1+MOD;
        ans %= MOD;
      }
      if(x!=s/x){
        ll y = s/x;
        ll n = num(y);
        ll need = s/y;
        if(y > 8 || need <= n){
          ans += n-need+1+MOD;
          ans %= MOD;
        }
      }
    }
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 200;
int n, a[N], dp[2][N][N];

void add(int &a, int b) {a+=b;if (a>=P) a-=P;}

int main() {
	scanf("%d", &n);
	int m = 2*n-1;
	REP(i,1,m) scanf("%d", a+i);
	sort(a+1,a+1+m);
	int cur = 0;
	dp[0][0][0] = 1;
	PER(i,1,n-1) {
		cur ^= 1;
		memset(dp[cur],0,sizeof dp[0]);
		int l = a[i]!=a[i+1], r = a[2*n-i-1]!=a[2*n-i];
		REP(j,0,m) REP(k,0,m) {
			int &ret = dp[!cur][j][k];
			if (!ret) continue;
			//b[i]=b[i+1]
			add(dp[cur][j+l][k+r],ret);
			//b[i]<b[i+1]
			REP(t,0,j+l-1) add(dp[cur][t][k+r+1],ret);
			//b[i]>b[i+1]
			REP(t,0,k+r-1) add(dp[cur][j+l+1][t],ret);
		}
	}
	int ans = 0;
	REP(i,0,m) REP(j,0,m) add(ans,dp[cur][i][j]);
	printf("%d\n", ans);
}








Measured memory_bytes: 512
#include <iostream>

 

using namespace std;

 

int main()
{
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    
    if (x-r >= 0 && y-r >= 0  && x+r <= w && y+r <= h)
       cout << "Yes" << endl;
    else
       cout << "No" << endl;
    
}


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

using namespace std;

void solve();

int main() {

    solve();
    return 0;
}

void solve() {

    int n, m;
    cin >> n >> m;

    vector<vector<int> > matrix;
    vector<int> column;
    vector<int> product;

    // reading matrix
    for (int i = 0; i < n; i++) {
        vector<int> temp;
        for (int j = 0; j < m; j++) {
            int valor;
            cin >> valor;
            temp.push_back(valor);
        }
        matrix.push_back(temp);
    }

    // reading column vectors
    for (int i = 0; i < m; i++) {
        int valor;
        cin >> valor;
        column.push_back(valor);
    }

    //making product
    for (int i = 0; i < n; i++) {
        int suma = 0;
        for (int j = 0; j < m; j++) {
            suma += matrix[i][j] * column[j];
        }
        product.push_back(suma);
    }

    // showing product
    for (int i = 0; i < n; i++) {
        cout << product[i] << endl;
    }   
}


Measured memory_bytes: 3192
n = int(input())
d = list(map(int,input().split()))
m = int(input())
t = list(map(int,input().split()))

d.sort()
t.sort()
j = 0
#print(d)
#print(t)
for i in range(n):
    if d[i] == t[j]:
        if j < m-1:
            j += 1
        else:
            j += 1
            break

if j == m:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 127572
N = int(input())
a = list(map(int, input().split()))
a.insert(0,0)
b = [0] * (N + 1)
ans = []
count = 0
for i in reversed(range(1,N + 1)):
  if a[i] == 1:
    sumi = 0
    j = 2
    while True:
      if (i * j) > N:
        break
      sumi += b[i * j]
      j += 1
    if sumi % 2 == 0:
      b[i] = 1
      count += 1
      ans.append(int(i))
  else:
    sumi = 0
    j = 2
    while True:
      if (i * j) > N:
        break
      sumi += b[i * j]
      j += 1
    if sumi % 2 == 1:
      b[i] = 1
      count += 1
      ans.append(int(i))
#ans.sort()
print(count)
print(' '.join(map(str, ans)))

Measured memory_bytes: 20500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
int main(){
    ll d; cin >> d;
    vector<ll> ansl(365,0);
    vector<ll> c(26,0);
    vector<ll> las(26,0);
    vec2(s,d,26,0);
    REP(i,26) cin >> c[i];
    REP(i,d)REP(j,26) cin >> s[i][j];
    ll con = 0;
    REP(i,d){
        ll maxind = 0; ll maxc = s[i][0]+c[0]*(i+1-las[0]);
        FOR(j,1,25)if(maxc<s[i][j]+c[j]*(i+1-las[j])){
            maxind = j;
            maxc = s[i][j]+c[j]*(i+1-las[j]);
            ansl[i]=j;
            las[j]=i+1;
        }
        cout << maxind+1 << endl;
    }
    //REP(i,d) cout << ansl[i]+1 << endl;
}

Measured memory_bytes: 3728
H,W,K = map(int,input().split())

S = [input() for _ in range(H)]

ans = 10**10
for i in range(2**(H-1)):   # iはbit
    rel = [0 for h in range(H)]
    a,b = 0,0
    for h in range(H-1):
        if i>>h&1:
            b += 1
        rel[h+1] = b

    a += b

    cnt = [0 for j in range(b+1)]
    for w in range(W):
        for h in range(H):
            if S[h][w] == '1':
                cnt[rel[h]] += 1
        
        OK = True
        for j in range(b+1):
            if cnt[j] > K:
                OK = False
                break
        
        if OK:
            continue

        a += 1
        cnt = [0 for j in range(b+1)]
        for h in range(H):
            if S[h][w] == '1':
                cnt[rel[h]] += 1

        OK2 = True
        for j in range(b+1):
            if cnt[j] > K:
                OK2 = False
                break
        
        if OK2:
            continue
        a = 10**10
        break
    ans = min(ans,a)
print(ans)


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

#define FOR(i, s, e)   for(int i = (s); i < (e); i++)
#define FOR64(i, s, e) for(ll  i = (s); i < (e); i++)
#define ALL(x)         (x).begin(), (x).end()
#define SORT(b, e)     sort((b), (e))
#define REV(b, e)      reverse((b), (e))
#define VSORT(v)       sort((v).begin(), (v).end())
#define VREV(v)        reverse((v).begin(), (v).end())
#define pb(a)          push_back(a)
#define INF            999999999

typedef long long ll;

int main()
{
	int N;
	cin >> N;
	vector<int> xx, yy, hh;
	int use = 0;
	FOR(i, 0, N){
		int x, y, h;
		cin >> x >> y >> h;
		xx.pb(x);
		yy.pb(y);
		hh.pb(h);

		if(h > 0) use = i;
	}

	FOR(cy, 0, 101){
		FOR(cx, 0, 101){
			bool match = true;
			int H = hh[use] + abs(xx[use] - cx) + abs(yy[use] - cy);
			FOR(k, 0, hh.size()){
				int h = max(H - abs(xx[k] - cx) - abs(yy[k] - cy), 0);
				if(h != hh[k]){
					match = false;
					break;
				}
			}

			if(match){
				printf("%d %d %d\n", cx, cy, H);
				exit(0);
			}
		}
	}

	return 0;
}



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

int main(void)
{
    int n, l, i, j, k, m;
    char s[101][101], tmp[101];
    scanf("%d %d", &n, &l);
    for (i = 0; i < n; i++)
    {
        scanf("%s", s[i]);
    }

    for (k = n - 1; k > 0; k--)
    {
        for (j = 0; j < k; j++)
        {
            for (i = 0; i < l; i++)
            {
                if (s[j][i] < s[j + 1][i]) {
                    break;
                }
                else if (s[j][i] > s[j + 1][i]) {
                    for (m = 0; m < l; m++)
                    {
                        tmp[m] = s[j + 1][m];
                        s[j + 1][m] = s[j][m];
                        s[j][m] = tmp[m];
                    }
                    break;
                }
            }
        }
    }

    for (i = 0; i < n; i++)
    {
        printf("%s", s[i]);
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1LL<<30;

ll n[9]={2,5,5,4,5,6,3,7,6};

string maxStr(string a, string b){
    string res=a;
    ll x=a.size(),y=b.size();
    if(x>y){
        res=a;
    }else if(x<y){
        res=b;
    }else{
        sort(a.begin(),a.end(),greater<char>());
        sort(b.begin(),b.end(),greater<char>());
        for(ll i=0;i<max(x,y);++i){
            if(a[i]>b[i]){res=a;break;}
            if(a[i]<b[i]){res=b;break;}
        }
    }
    if(a[0]=='x')res=b;if(b[0]=='x')res=a;
    return res;
}

string F(string x,string a){
    x+=a;
    //sort(x.begin(),x.end(),greater<char>());
    string res=x;
    return res;
}

int main(){
    ll N,M;cin >> N >> M;
    map<string,ll> mp;
    vector<string> v;

    for(ll i=0;i<M;++i){
        string a;cin >> a;
        v.push_back(a);
        mp[a]=n[a[0]-'1'];
    }

    //  dp配列初期化
    string dp[20010];
    for(ll i=0;i<=N;++i){
        dp[i]='x';
    }
    for(auto s: v)dp[mp[s]]=s;

    for(ll i=1;i<=N;++i){
        for(auto s: v){
            if(i-mp[s]<0)continue;
            if(dp[i-mp[s]]!="x"){
                dp[i]=maxStr(F(dp[i-mp[s]],s),dp[i]);
            }
        }
    }
    sort(dp[N].begin(),dp[N].end(),greater<char>());
    cout << dp[N] << endl;
}

Measured memory_bytes: 45440
N = int(input())

A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

last = -1
ans = 0
for i in range(N):
    ans += B[A[i]-1]
    if i==0:
        continue
    if A[i-1]+1 == A[i]:
        ans += C[A[i-1]-1]

print(ans)



Measured memory_bytes: 38256
import java.util.*;
import java.math.*;
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 0; i < n; i++) {
			BigInteger x = sc.nextBigInteger().add(sc.nextBigInteger());
			if(x.toString().length() > 80) System.out.println("overflow");
			else System.out.println(x);
		}
	}
}

Measured memory_bytes: 26124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> v(8), L(8);
int Min = 1000000000, N, A, B, C;

void calc(vector<int> &vec, int N){
	int a = 0, b = 0, c = 0, cnt_a = 0, cnt_b = 0, cnt_c = 0;
	for(int i=0; i<N; i++){
		if(v[i] == 0) a += L[i], cnt_a++;
		if(v[i] == 1) b += L[i], cnt_b++;
		if(v[i] == 2) c += L[i], cnt_c++;
	}
	if(cnt_a != 0 && cnt_b != 0 && cnt_c != 0){
		int ans = 10*(cnt_a + cnt_b + cnt_c - 3) + abs(a-A) + abs(b-B) + abs(c-C);
		if(Min > ans) Min = ans;
	}
	return;
}

void dfs(int depth){
	if(depth == N){ calc(v, N); return; }
	for(int i=0; i<4; i++){
		v[depth] = i;
		dfs(depth+1);
	}
}

int main(){
	cin >> N >> A >> B >> C;
	for(int i=0; i<N; i++) cin >> L[i];
	dfs(0);
	cout << Min << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <fstream>
#include <unordered_map>
#include <vector>
#include <numeric>
#include <algorithm>

int main() {
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	int m = 0;
	
	std::vector<int> c(8, 0);
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
		if (a[i] < 400) c[0]++;
		else if (a[i]< 800) c[1]++;	
		else if (a[i]< 1200) c[2]++;
		else if (a[i]< 1600) c[3]++;
		else if (a[i]< 2000) c[4]++;
		else if (a[i]<2400) c[5]++;
		else if (a[i]<2800) c[6]++;
		else if (a[i]<3200) c[7]++;
		else if(a[i]>=3200) m++;
	}
	int j = std::count(c.begin(), c.end(), 0);
	int k = 8 - j;
	if (k == 0)
		std::cout << 1;
	else
		std::cout << k;

	std::cout << " " << k + m << std::endl;


}

Measured memory_bytes: 256
#include<iostream>
#include<bitset>
using namespace std;
#define MAX 15

int main(){
    int i, n;
    cin >> n;
    int a[n], x[n][n], y[n][n];
    for(i=0; i<n; i++){
        cin >> a[i];
        for(int j=0; j<a[i]; j++){
            cin >> x[i][j] >> y[i][j];
        }
    }

    int cnt, max_cnt=0;
    for (int tmp=0; tmp<(1<<n); tmp++){
        bitset<MAX> hyp(tmp);
        cnt = 0;        
        bool flg=true;
        // cout << hyp << endl;
        for(i=0; i<n; i++){
            if(hyp.test(i)){
                cnt++;
                for(int j=0; j<a[i]; j++){
                    if(hyp.test(x[i][j]-1) != y[i][j]) {
                        flg = false;
                    }
                }
            }
        }
        if(flg == true) max_cnt = max(max_cnt, cnt);
        // cout << flg << " " << cnt << endl;
    }
    cout << max_cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int a,b;
int main(){
	scanf("%d %d",&a,&b);
	if(a==0||b==0){
		printf("Zero");
		return 0;
	}
	if(a>0&&b>0){
		printf("Positive");
		return 0;
	}
	if((a>0&&b<0)||(b>0&&a<0)){
		printf("Zero");
		return 0;
	}
	if(a<0&&b<0){
		if(b>a){
			if((b-a+1)%2==0){
				printf("Positive");
			}else{
				printf("Negative");
			}
		}else{
			if((a-b+1)%2==0){
				printf("Positive");
			}else{
				printf("Negative");
			}
		}
	}
	return 0;
}

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

int main () {
    int N, M;
    cin >> N >> M;
    vector<P> p(M);
    rep(i, M) cin >> p[i].first >> p[i].second;
    vector<int> A(N, -1);
    rep(i, M) {
        if (A[p[i].first-1] != -1 && A[p[i].first-1] != p[i].second) {
            cout << -1 << endl;
            return 0;
        }
        A[p[i].first-1] = p[i].second;
    }
    if ((N == 2 && A[0] == 0) || (N == 3 && A[0] == 0)) {
        cout << -1 << endl;
        return 0;
    }
    if (A[0] == -1 && N == 1) A[0] = 0;
    if (A[0] == -1 && (N == 2 || N == 3)) A[0] = 1;
    rep(i, N) {
        if (A[i] == -1) A[i] = 0;
        cout << A[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
int main(){
    ll h,w;cin >> h >>w;
    vector<vector<char>> g(h,vector<char>(w));
    rep(i,h)rep(j,w)cin >> g[i][j];
    vvl dp(h,vl(w,inf));
    if(g[0][0]=='.')dp[0][0]=0;
    else dp[0][0]=1;
    rep(i,h){
        rep(j,w){
            if(i+1<h){
                if(g[i][j]=='.'&&g[i+1][j]=='#')chmin(dp[i+1][j],dp[i][j]+1);
                else chmin(dp[i+1][j],dp[i][j]);
            }
            if(j+1<w){
                if(g[i][j]=='.'&&g[i][j+1]=='#')chmin(dp[i][j+1],dp[i][j]+1);
                else chmin(dp[i][j+1],dp[i][j]);
            }
        }
    }
    cout << dp[h-1][w-1] <<endl;
}

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

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int P, Q, R;
double getx(double t){
  return (double)(P - Q) * cos(t) + (double)R * cos(t * (P - Q) / Q);
}
double dx(double t){
  return (double)(P - Q) * (-sin(t)) + (double)R * (P - Q) / Q * (-sin(t * (P - Q) / Q));
}
double gety(double t){
  return (double)(P - Q) * sin(t) - (double)R * sin(t * (P - Q) / Q);
}
double dy(double t){
  return (double)(P - Q) * (cos(t)) - (double)R * (P - Q) / Q * (cos(t * (P - Q) / Q));
}
double dist(double x1, double y1, double x2, double y2){
  return sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
}

int main(){
  while(cin>>P>>Q>>R && P){
    int time = -1;
    for(int k = 1; ; k++){
      if(R == 0){
        time = 1;
        break;
      }
      if(k * (P - Q) % Q == 0){
        time = k;
        break;
      }
    }
    const int ITER = 10000;
    const double delta = 2.0 * time * M_PI / ITER;
    double ans = 0;
    REP(iter, ITER){
      double t = delta * iter;
      ans += sqrt(dx(t) * dx(t) + dy(t) * dy(t)) * delta;
    }
    printf("%.2f\n", ans + EPS);
  }
  return 0;
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int h, w;
    cin >> h >> w;
    auto a = make_vec<int>(h, w);
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) {
        int x;
        cin >> x;
        a[i][j] = abs(a[i][j] - x);
    }
    auto dp = make_vec<bitset<20000>>(h, w);
    dp[0][0].set(a[0][0] + 10000);
    dp[0][0].set(-a[0][0] + 10000);
    rep(i, h) rep(j, w) {
        if (i+1 < h) dp[i+1][j] |= ((dp[i][j] >> a[i+1][j]) | (dp[i][j] << a[i+1][j]));
        if (j+1 < w) dp[i][j+1] |= ((dp[i][j] >> a[i][j+1]) | (dp[i][j] << a[i][j+1]));
    }
    for (int i = 0; ; ++i) {
        if (dp[h-1][w-1].test(i+10000) || dp[h-1][w-1].test(-i+10000)) {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 19076
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
using namespace std;

int main(){
  int k,x; cin>>k>>x;
  for(int i=x-k+1;i<x+k;i++){
    cout<<i<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
ll array[1005]={0};
int main(){
  int n;
  cin>>n;
  ll ksum=0,gsum=0;
  vector<int> ks,gs,ans;
  for(int i=1;i<=n;i++){
    ll a;
    cin>>a;
    array[i]=a;
    if(a>0){
      if(i%2==1){
        ks.push_back(i);
        ksum+=a;
      }
      else{
        gs.push_back(i);
        gsum+=a;
      }
    }
  }
  if(ksum==0&&gsum==0){
    ll m2=-1e15;
    int midx=0;
    for(int i=1;i<=n;i++){
      if(m2<array[i]){
        m2=array[i];
        midx=i;
      }
    }
    cout<<m2<<endl<<n-1<<endl;
    for(int i=n;i>midx;i--) cout<<i<<endl;
    for(int i=1;i<midx;i++) cout<<1<<endl;
    return 0;
  }
  if(ksum>gsum){
    int sz=ks.size();
    for(int i=0;i<n-ks[sz-1];i++) ans.push_back(n-i);
    for(int i=1;i<ks[0];i++) ans.push_back(1);
    for(int i=0;i<sz-1;i++){
      for(int j=(ks[i+1]-ks[i])/2+1;j>1;j--) ans.push_back(j);
    }
  }
  else{
    int sz=gs.size();
    for(int i=0;i<n-gs[sz-1];i++) ans.push_back(n-i);
    for(int i=1;i<gs[0];i++) ans.push_back(1);
    for(int i=0;i<sz-1;i++){
      for(int j=(gs[i+1]-gs[i])/2+1;j>1;j--) ans.push_back(j);
    }
  }
  cout<<max(ksum,gsum)<<endl<<ans.size()<<endl;
  for(int i=0;i<ans.size();i++) cout<<ans[i]<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
int main(){
    ll n, k;
    cin >> n >> k;
    ll s = 0;
    for(ll i=k;i<=n+1;i++){
        ll mi = (i - 1)*(i) / 2;
        ll ma = (2*n - i + 1)*(i) / 2;
        s += ma - mi + 1;
    }
    s %= mod;
    cout << s << endl;

    return 0;
}  

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

int n, t, s;
int markets[3001][2], dp[3001][3001];

int main(){
    scanf("%d%d%d", &n, &t, &s);
    for(int i = 1; i <= n; i++){
        scanf("%d%d", &markets[i][0], &markets[i][1]);
    }

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= t; j++){
            dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            if(j >= markets[i][1]){
                if(j <= s || j > s && j - markets[i][1] >= s){
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - markets[i][1]] + markets[i][0]);
                }
            }
        }
    }

    printf("%d\n", dp[n][t]);

    return 0;
}

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

#define int long long

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

    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()

dp = [[0 for i in range(5005)] for j in range(5005)]

for i in range(N)[::-1]:
    for j in range(N)[::-1]:
        if S[i] != S[j]:
            dp[i][j] = 0
        else:
            dp[i][j] = dp[i+1][j+1]+1

ans = 0
for i in range(N):
    for j in range(N):
        if i >= j:
            continue
        now = min(dp[i][j], j-i)
        ans = max(ans, now)

print(ans)

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

using namespace std;

#define INF (1ll << 62)
#define pb push_back
#define ii pair<int,int>
#define OK cerr <<"OK"<< endl
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define endl '\n'

int check(int k, int a, int b) {
	return (abs(a - k) == abs(b - k));
}

signed main () {
  
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;

  cin >> n;

  vector<int> arr(n + 1);

  vector<int> s(n);

  for(int &x: arr)
  	cin >> x;

  for(int &x: s) {
  	cin >> x;
  }

  int ans = 0;
  for(int i = 0; i < n; i++) {
  	int v = min(s[i], arr[i]);
  	ans += v;
  	arr[i] -= v;
  	s[i] -= v;

  	v = min(s[i], arr[i + 1]);
  	ans += v;
  	arr[i + 1] -= v;
  	s[i] -= v;
  }

  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int sz = 4e5+9;

int main()
{
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    ll ans = min(a, k);
    k -= min(a, k);
    k -= min(b, k);
    ans -= min(c, k);

    cout << ans << endl;
}


Measured memory_bytes: 3640