akhauriyash/Code-Regression huggingface dataset:
object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val Array(a, b, c) = readLine.trim.split(' ').map(_.toInt)
  val single = math.min(a, c)//cを食べてからaを食べる
  val double = math.min(c - single, b)//aと一緒に食べなかったcとbを一緒に食べる
  val singleN = math.max(b - double, 0)//cと一緒に食べなかったbをそのまま食べる
  val restC = math.min(c - single - double, 1)//最後に余ったcを食べる
  println(
    single + double * 2 + singleN + restC
  )
  @inline
  def lowerBound[T](array: Array[T], target: T)(implicit ord: Ordering[T]): Int = {
    var left = 0
    var right = array.length
    while (left < right){
      val mid = (left + right) / 2
      if (ord.compare(array(mid), target) < 0){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }
  @inline
  def upperBound[T](array: Array[T], target: T)(implicit ord: Ordering[T]): Int = {
    var left = 0
    var right = array.length
    while (left < right){
      val mid = (left + right) / 2
      if (ord.compare(array(mid), target) <= 0){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }
  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}

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

int main() {
  int N, Y;
  cin >> N >> Y;

  rep(i1, N + 1) {
    rep(i5, N - i1 + 1) {
      int i10 = N - i1 - i5;
      if (i1 * 1000 + i5 * 5000 + i10 * 10000 == Y) {
        cout << i10 << " " << i5 << " " << i1 << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let N:i64 = sc.read();
    for i in 1..50_001{
        let t:f64 = (i as f64)*1.08;
        if (t as i64) == N{
            println!("{}", i);
            return
        }
    }
    println!(":(");
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
        .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}




Measured memory_bytes: 4352
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
using namespace std;



int main() {
	int x,n;
	
	cin >> x >> n;
	vector<int> p(102,0);
	int ans = -1,y,ab = 110;
	for (int i = 0; i < n; i++){
		cin >> y;
		p[y] = 1;
	}
	for (int i = 0; i <= x; i++){
		if(p[x-i] == 0){
			ans = x - i;
			break;
		}
		if(p[x+i] == 0){
			ans = x + i;
			break;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
map<ll,ll>m;
int main()
{   ll n,q;cin>>n;
     ll a[n],ans=0;
     for(ll i=0;i<n;i++){
         cin>>a[i];
         ans+=a[i];
         m[a[i]]++;
     }
    cin>>q;
    while(q--){
        ll x,y;cin>>x>>y;
        ans-=(m[x]*x);
        ans+=(m[x]*y);
        m[y]+=m[x];
        m[x]=0;
        cout<<ans<<endl;
    }
 
 
 
 
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }


void compute() {

}

int main() {
  int A,P;
  cin >> A >> P;
  P = P + A * 3;
  cout << (int)(P/2) << endl;
  compute();
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
#include<math.h> 
#include<stdlib.h>
#include<map>
#include<set>
#include<time.h>
#include<bitset>
#include<list>
const int inf=2e9;
const int md=1e9+7;
using namespace std;
long long f[5],ans;
int main(){
	f[0]=inf;
	for (int i=1;i<=4;i++)
	cin>>f[i],f[i]=min(f[i],f[i-1]*2);
	long long N;cin>>N;
	ans=(N%2)*f[3]+N/2*f[4];
	cout<<ans<<endl;
	return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

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

const ll maxf = 10000000;
ll fact[maxf+5];
ll ifact[maxf+5];

void fact_init(){
  fact[0] = 1;
  for(ll i=1; i<=maxf; i++) fact[i] = (fact[i-1] * i) % MOD;
  ifact[maxf]=modpow(fact[maxf],MOD-2);
  for(ll i=maxf; i>=1; i--) ifact[i-1] = (ifact[i] * i) % MOD;
}

ll comb(ll n, ll r){
  if(n<r || n<0 || r<0) return 0;
  if(fact[0] == 0) fact_init();
  return ((fact[n] * ifact[n-r]) % MOD * ifact[r]) % MOD;
}

ll naive_comb(ll n, ll r){
  ll res = 1;
  for (ll i = n; i > n - r; i--) res = res * i % MOD;
  for (ll i = 1; i <= r; i++) res = (res * modpow(i, MOD-2)) % MOD;
  return res;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n+1);
  map<ll,ll> m;
  ll x;
  rep(i,n+1){
    cin>>a[i];
    m[a[i]]++;
    if(m[a[i]]==2) x=a[i];
  }
  
  ll l,r;
  bool flg=false;
  rep(i,n+1){
    if(a[i]==x){
      if(!flg){
        flg=true;
        l=i;
      }else{
        r=i;
      }
    }
  }
  
  rep(i,n+1){
    ll d=comb(l+n-r,i);
    ll ans=(comb(n+1,i+1)-d+MOD)%MOD;
    // cout<<l+n-r<<' '<<i+1<<' '<<comb(n+1,i+1)<<' '<<comb(l+n-r,i)<<' '<<ans<<endl;
    cout<<ans<<endl;
  }
  
}

Measured memory_bytes: 164480
import math
N, M = map(int, input().split())
mod = 10**9+7

if(abs(N-M) == 1):
    print((math.factorial(N)*math.factorial(M))%mod)
elif(N==M):
    print((2*math.factorial(N)*math.factorial(M))%mod)
else:
    print(0)

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


def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x % y)


ans = float("Inf")
for i in range(n - 1):
    ans = min(ans, gcd(a[i], a[i + 1]))
print(ans)

Measured memory_bytes: 115352
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


def str_inp():
    '''
    文字列をリストとして読み込む
    '''
    return list(input()[:-1])


n = inp()
a = inpl()
a.sort(reverse=True)
tmp = 1
now = 0
ans = 0
for i in range(n - 1):
    ans += a[now]
    tmp += 1
    if tmp == 2:
        tmp = 0
        now += 1
print(ans)


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

vector< vector<int> >ans(10+1,vector<int>(330+1,0));

void rec(int n,int use,int sum,int depth){
  if(sum!=0)ans[n][sum]++;
  for(int i=0;i<10;i++){
    if( (use>>i)&1 )continue;
    rec(n+1,use^(1<<i),sum+depth*i,depth+1);
  }
  return;
}

int main()
{
  int n,s;  rec(0,0,0,1);
  while(cin>>n>>s)cout<<ans[n][s]<<endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

ll n;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cin >> n;

    vector<ll> a(n);
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum ^= a[i];
    }

    for (int i = 0; i < n; ++i)
        cout << (sum ^ a[i]) << " \n"[i == n - 1];
}

Measured memory_bytes: 4780
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include <ctime>
#include<list>
#include <numeric>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
#include <array>
using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
	~debug() { cerr << endl; }
	template<class c> typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {
		cerr << boolalpha << i; return *this;
	}

	template<class c, int=0> typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {
		return *this << range(begin(i), end(i));
	}

sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c&) { ris; }
#endif
};
#define watch(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(int i = 0; i < n; i++)
#define FORAB(i, a, b) for(int i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))
#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int128 LLL;
typedef long long LLL;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PLL > VPL;
typedef vector<PII > VP;
typedef vector<double> VD;
typedef vector<vector<int>> VVI;
typedef long double ld;

const LL MOD = 998244353;

void solve(int ks) {
	string s;
	cin >> s;
	int a = count(ALL(s), '0');
	int b = count(ALL(s), '1');
	cout << MIN(a, b) * 2 << endl;
}

int main()
{
#ifdef LOCAL
	double start_time = clock();
	freopen("C:\\Home\\ContestCodes\\sample.in", "r", stdin);
	//	freopen("out.out", "w", stdout);
#endif


	if (0) {
		int T;
		scanf("%d", &T);
		//AIN(T, 1, 25);
		for (int ks = 1; ks <= T; ks++) {
			solve(ks);
			fprintf(stderr, "%d done\n", ks);
		}
	}
	else {
		solve(0);
	}

#ifdef LOCAL
	double end_time = clock();
	fprintf(stderr, "Time = %lf\n", (end_time - start_time) / CLOCKS_PER_SEC);
#endif

	return 0;
}


Measured memory_bytes: 512
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const n = Number(stdin.split('\n')[0])
const a = stdin
  .split('\n')[1]
  .split(' ')
  .map(Number)

const ans = () => {
  let count = 0
  let nums = [...a]

  while (1) {
    const evenes = nums.filter(v => v % 2 === 0)

    if (evenes.length === a.length) {
      count++
      nums = evenes.map(v => v / 2)
    } else {
      break
    }
  }

  console.log(count)
}

ans()


Measured memory_bytes: 7500
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define endl "\n"
typedef long long ll;
#define traceV(v) for(auto x:v)cout<<x<<" ";cout<<endl
#define traceM(mp) for(auto x:mp)cout<<x.first<<" "<<x.second<<endl
#define MOD 1000000007

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

  ll K; cin>>K;
  if(K<=9){cout<<K<<endl; return 0;}

  ll cnt = 9; // ルンルンをカウント
  ll res = 10;
  while(cnt!=K) {   // ルンルンのカウントがKになるまで
    // 数値の各桁の数字をそれぞれ格納した配列arr
    ll arr[10] = {0}; ll v = res; string s = to_string(res);
    rep(j,s.size()) {
      arr[s.size()-1-j] = (v%10);
      v/=10;
    }

    //
    bool isRun = true;
    rep(j,s.size()-1) {
      // ルンルンでない場合
      if(abs(arr[j]-arr[j+1])>=2) {
        // ケース1
        if(arr[j]>arr[j+1]) {
          ++arr[j+1];
          reps(k,j+2,s.size())arr[k]=0;
        }
        // ケース2
        else {
          ++arr[j];
          reps(k,j+1,s.size())arr[k]=0;
        }
        isRun = false;
        break;
      }
    }
    if(isRun) {
      ++cnt;
      ++res;
      continue;
    }

    // 配列を数値に戻して，iを更新
    ll val = 0;
    rep(j, s.size()) {
      val += arr[j]*pow(10,s.size()-j-1);
    }
    // 最新のルンルンに更新
    res = val;
  }
  cout << res-1 << endl;

  return 0;
}


Measured memory_bytes: 640
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;
 
class Program
 {
  
        static void Main(string[] args)
        {
          //入力を受け取る
          int N = int.Parse(Console.ReadLine());
          var H = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
          var res = "Yes";
          for(int i = N-1; i > 0 ;i--){
            if(H[i]-H[i-1] >= 0){
            } else if(H[i]-H[i-1] == -1){
             H[i-1]--;
            }else{
             res = "No";
             break;
            }
          }
          Console.Write(res);
        }
 }

Measured memory_bytes: 30300
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;

void solve() {
	int n;
	cin >> n;
	
	int m = 0;
	while(m < n) {
		m += 1000;
	}
	
	if(m == n) cout << 0 << endl;
	else cout << m - n << endl;
}

int main(){
#define MULTITEST 0
#if MULTITEST   
 
    CASET {
        solve();
    }
    
#else

    solve();
    
#endif

    return 0;
}

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

int main()
{
    int N, A, B;
    cin >> N >> A >> B;
    vector<int> h(N);
    for (int i = 0; i < N; i++)
    {
        cin >> h.at(i);
    }

    int64_t l = 0, r = 1e9;
    while (l + 1 < r)
    {
        int64_t x = (l + r) / 2;

        int64_t cnt = 0;
        for (int i = 0; i < N; i++)
        {
            int64_t hi = h.at(i);
            hi -= x * B;
            cnt += max((int64_t)0, (hi + A - B - 1) / (A - B));
        }
        if (cnt <= x)
            r = x;
        else
            l = x;
    }
    cout << r << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define All(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main() {
  Cin(int, n);
  Cins(int, n, a);
  Cins(int, n, b);
  Cins(int, n - 1, c);

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += b[a[i] - 1];
    if (i)
      if (a[i - 1] + 1 == a[i]) ans += c[a[i - 1] - 1];
  }

  cout << ans << endl;
}

int main() {
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};



int main(){
    int n;cin >> n;
    if(n%2) cout << n / 2 << endl;
    else cout << n / 2 - 1 << endl;
    return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, K = map(int, read().split())

dp = [1.0] * (200_010)
for n in range(K - 1, 0, -1):
    dp[n] = 0.5 * dp[2 * n]

print(sum(dp[1:N + 1]) / N)

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

int n, m;
int s[10002];

int main(){
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> s[i];
  }

  int c = 0;

  cin >> m;
  for(int i = 0; i < m; i++){
    int x;
    cin >> x;

    for(int j = 0; j < n; j++){
      if(s[j] == x){
        c++;
        break;
      }
    }
  }

  cout << c << endl;
}

Measured memory_bytes: 1200
from itertools import permutations
N,M,R=map(int,input().split())
r=list(map(int,input().split()))
inf=10**9
d=[[inf]*N for i in range(N)]
for i in range(M):
  A,B,C=map(int,input().split())
  d[A-1][B-1]=C
  d[B-1][A-1]=C
for k in range(N):
  for i in range(N):
    for j in range(N):
      d[i][j]=min(d[i][j],d[i][k]+d[k][j])
ans=inf      
for l in permutations(r):
  start=0
  for j in range(R-1):
    start+=d[l[j]-1][l[j+1]-1]
  ans=min(start,ans)
print(ans)

Measured memory_bytes: 48088
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	string s; cin >> s;
	int r = 0;
	rep(i, 0, N) {
		if (s[i] == 'R')r++;
		else r--;
	}
	if (r > 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 N, A, B;
  std::cin >> N >> A >> B;
  std::cout << std::min(N * A, B) << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
int pw(int n,int k){
  int res=1;
  while(k){
    if(k&1)res*=n;res%=MOD;
    n*=n;n%=MOD;
    k>>=1;
  }
  return res;
}
//main
signed main(){
  int N;cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  int ans=1;
  v[0]=1;
  int res=N;int c=0;
  for(int i=1;i<N;i++){
    v[i]=min(v[i],v[i-1]+2);
    if(v[i]==v[i-1]+1){
      ans*=(i+1-c);ans%=MOD;
      v[i]=v[i-1];
      res--;c++;
    }
  }
  for(int i=2;i<=res;i++)ans*=i,ans%=MOD;
  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#   ????????? n ?¬?????????????????????????p ??????????????? 1???2???3????????? ?????????????????????????????¢????±???????????????°??????
import math
#   ?¬??????°n????¨??????\???????????????
n = int(input())
#   ????????????x????¨??????\???????????????
x = list(input())
x = "".join(x).split()
#   ????????????y????¨??????\???????????????
y = list(input())
y = "".join(y).split()
#   p=1,2,????????§???????????????????????????????????¢???????´?????????????
#   ?????????????????????
dxy = [0 for i in range(4)]
#   p=1???????????????????????????????????¢????¨????
for i in range(0, n):
    dxy[0] += math.fabs(int(x[i]) - int(y[i]))
#   p=2
for i in range(0, n):
    dxy[1] += (math.fabs(int(x[i]) - int(y[i]))) ** 2
dxy[1] = math.sqrt(dxy[1])
#   p=3
for i in range(0, n):
    dxy[2] += (math.fabs(int(x[i]) - int(y[i]))) ** 3
dxy[2] = math.pow(dxy[2], 1.0 / 3.0)
#   p=????????§
dxy[3] = math.fabs(int(x[0]) - int(y[0]))
for i in range(1, n):
    if dxy[3] < math.fabs(int(x[i]) - int(y[i])):
        dxy[3] = math.fabs(int(x[i]) - int(y[i]))
#   ??????
for i in range(0, 4):
    print("{0}".format(dxy[i]))

Measured memory_bytes: 7884
// B - Chocolate
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N,D,X; cin>>N>>D>>X;
	int ans = X;
	while(N--){
		int a; cin>>a;
		rpz(j, D){
			if(j*a+1 > D) break;
			ans++;
		}
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	final boolean DEBUG = false;

	class PriorityQueue {
		final int MAX_HEAP = 2000000 + 1;
		int[] heap;
		int h, startIndex;
		PriorityQueue() {
			this.heap = new int[MAX_HEAP];
			this.h = 0;
			this.startIndex = 1;
		}
		void insert(int k) {
			h++;
			this.heap[h] = k;
			int i = h;
			while (i > 1 && heap[i] > heap[i / 2]) {
				int tmp = heap[i];
				heap[i] = heap[i / 2];
				heap[i / 2] = tmp;
				i = i / 2;
			}
		}
		void extract() {
			System.out.println(heap[1]);
			heap[1] = heap[h];
			h--;
			maxHeapify(1);
		}
		void maxHeapify(int i) {
			int left = 2 * i;
			int right = 2 * i + 1;
			int largest = 0;
			if (left <= h && heap[left] > heap[i])
				largest = left;
			else
				largest = i;

			if (right <= h && heap[right] > heap[largest])
				largest = right;

			if (largest != i) {
				int tmp = heap[i];
				heap[i] = heap[largest];
				heap[largest] = tmp;
				maxHeapify(largest);
			}
		}
		void buildMaxHeap() {
			for (int i = h / 2; i >= 1; i--)
				maxHeapify(i);
		}
		void printDebug() {
			System.out.print("debug: ");
			for (int i = startIndex; i <= (h % MAX_HEAP); i++)
				System.out.print(heap[i] + " ");
			System.out.println();
		}
	}

	void run() {
		Scanner scan = new Scanner(System.in);
		PriorityQueue que = new PriorityQueue();
		while (true) {
			String inst = scan.next();
			switch (inst) {
			case "insert":
				int k = scan.nextInt();
				if (DEBUG)
					System.out.println("insert " + k);
				que.insert(k);
				break;
			case "extract":
				if (DEBUG)
					System.out.print("expact: ");
				que.extract();
				break;
			case "end":
				return;
			}
			if (DEBUG)
				que.printDebug();
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}



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

ll a[3000];
ll dp[3000][3000];

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int l = 1; l <= n; l++) {
    for (int i = 0; i+l <= n; i++) {
      dp[l][i] = max(a[i]-dp[l-1][i+1], a[i+l-1]-dp[l-1][i]);
    }
  }
  cout << dp[n][0] << endl;
}


Measured memory_bytes: 70016
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextInt();
        long power = 1;
        for (long i = 1; i < n + 1; i++) {
            power *= i;
            power %= 1000000000 + 7;
            //power = i * (power % (1000000000 + 7));
        }
        System.out.println(power);
    }

}


Measured memory_bytes: 21588
def main():
    N = int(input())
    X = input()
    MOD = sum(map(lambda x: x == '1',X))
    lowNumber = []
    for i in range(MOD + 1):
        anscur = i
        cnt = 1
        while anscur != 0:
            oneCount = bin(anscur).count('1')
            anscur %= oneCount
            cnt += 1
        lowNumber.append(cnt)
    if MOD == 0:
        print("1" + "\n1" * (N-1))
        return 0
    if MOD == 1 and X[-1] == '1':
        print("2\n" * (N-1) + "0")
        return 0
    if MOD == 1 and X[-1] == '0':
        ans = ''
        for i in range(N):
            if X[i] == '1':
                ans += '0'
            elif i != N-1:
                ans += '1'
            else:
                ans += '2'
            if i != N-1:
                ans += '\n'
        print(ans)
        return 0
    MODP1 = MOD + 1
    MODM1 = MOD - 1
    POWEROFTWOP1 = [0] * 200001
    POWEROFTWOM1 = [0] * 200001
    POWEROFTWOP1[0] = 1
    POWEROFTWOM1[0] = 1
    for i in range(1,N):
        POWEROFTWOP1[i] = (POWEROFTWOP1[i-1] * 2) % MODP1
        POWEROFTWOM1[i] = (POWEROFTWOM1[i-1] * 2) % MODM1
    xMODP1 = 0
    xMODM1 = 0
    for i in range(N):
        if X[i] == '1':
            xMODP1 += POWEROFTWOP1[N - i - 1]
            xMODP1 %= MODP1
            xMODM1 += POWEROFTWOM1[N - i - 1]
            xMODM1 %= MODM1
    ans = ""
    for i in range(N):
        if X[i] == '0':
            anscur = xMODP1
            anscur += POWEROFTWOP1[N - i - 1]
            anscur %= MODP1
        if X[i] == '1':
            anscur = xMODM1
            anscur -= POWEROFTWOM1[N - i - 1]
            anscur %= MODM1
        ans += str(lowNumber[anscur])
        if i != N-1:
            ans += '\n'
    print(ans)
                    
main()

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i = 0; i <= 100; i ++){
        int cakes = i * 4;
        if(cakes > n) break;
        int donuts = n - cakes;
        if(donuts >= 0 and donuts % 7 == 0){
            return 0 * printf("Yes\n");
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int isIncludedInS(int x);
 
int n,q;
int S[100000];
int count = 0;
 
main(){
 
  int i;
  int tmp;
 
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&S[i]);
  }
 
  scanf("%d",&q);
  for(i=0; i<q; i++){
    scanf("%d",&tmp);
    count += isIncludedInS(tmp);
  }
 
  printf("%d\n",count);
 
  return 0;
 
}
 
int isIncludedInS(int x){
 
  int i,j;
  int min,max;
  int middle;
 
  min = 0;
  max = n-1;
  while(min <= max){
    middle = (max+min)/2;
    if(x > S[middle]){
      min = middle + 1;
    }else if(x < S[middle]){
      max = middle - 1;
    }else if(x == S[middle]){
      return 1;
    }
  }
  return 0;
 
}

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

int main()
{
  int n;
  cin>>n;
  int c1=0, c2=0, c3=0, c4=0;
  while(n--)
  {
    string s;
    cin>>s;
    if(s=="AC")
      c1++;
    else if(s=="WA")
      c2++;
    else if(s=="TLE")
      c3++;
    else if(s=="RE")
      c4++;
  }
  cout<<"AC"<<" x "<<c1<<endl;
  cout<<"WA"<<" x "<<c2<<endl;
  cout<<"TLE"<<" x "<<c3<<endl;
  cout<<"RE"<<" x "<<c4<<endl;
}


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


using namespace std;


bool check(long long M, int N, long long val) {
    if (M / val < N) return false;

    return true;
}


int main() {
    int N;
    long long M;
    cin >> N >> M;

    long long ans = 0;

    for (long long i = 1; i * i <= M; i++) {
        if (M % i == 0) {
            if (check(M, N, i)) {
                ans = max(ans, i);
            }
            if (check(M, N, M / i)) {
                ans = max(ans, M / i);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#define rep(i,n) for(int i = 0;i<(n);i++);
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
	if (a < b)swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
int main() {
	ll N,K;
	cin >> K >> N;
	vector<ll> n(N);
	vector<ll> dist(N);
	for (int i = 0; i < N; i++) {
		cin >> n[i];
	}
	for (int i = 0; i < N; i++) {
		if (i < N - 1)dist[i] = n[i + 1] - n[i];
		else dist[i] = K - n[i] + n[0];
	}
	sort(all(dist));
	cout << K - dist[N - 1] << endl;
}

Measured memory_bytes: 3328
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 105
#define ll long long
#define inf 0x3f3f3f3f
char S[N];
int n, m, f[N][2], g[N][2];
ll ans;
int main()
{
	scanf("%s%d", S + 1, &n);
	m = strlen(S + 1);
	f[1][0] = 0;
	f[1][1] = 1;
	g[1][0] = (S[1] == S[m]) ? inf : 0;
	g[1][1] = 1;
	for (int i = 2; i <= m; i++)
	{
		f[i][0] = (S[i] == S[i - 1]) ? f[i - 1][1] : f[i - 1][0];
		f[i][1] = min(f[i - 1][0], f[i - 1][1]) + 1;
		g[i][0] = (S[i] == S[i - 1]) ? g[i - 1][1] : g[i - 1][0];
		g[i][1] = min(g[i - 1][0], g[i - 1][1]) + 1;
	}
	ans = 1ll << 60;
	ans = min(ans, (ll)f[m][1] * n);
	ans = min(ans, f[m][0] + (ll)g[m][0] * (n - 1));
	ans = min(ans, (ll)f[m][0] * (n + 1) / 2 + (ll)g[m][1] * (n - (n + 1) / 2));
	printf("%lld\n", ans);
}


Measured memory_bytes: 256
N, A, B = map(int, input().split())
S = input()

num = 0
num_b = 0

for i in range(N):
    if S[i] == "a":
        if num < A + B:
            print("Yes")
            num += 1
        else:
            print("No")
    elif S[i] == "b":
        if num < A + B and num_b < B:
            print("Yes")
            num += 1
            num_b += 1
        else:
            print("No")
    else:
        print("No")


Measured memory_bytes: 4016
#include <stdio.h>

#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

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

    string S, reverse_S;
    cin >> S;
    int len;
    len = S.length();
    int counter = 0;
    for (int i = 0; i < len/2; i++) {
        debug(S[i], S[len - i - 1]);
        if (S[i] != S[len - i - 1]) {
            counter++;
        }
    }
    cout << counter << endl;

    return 0;
}


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

typedef long long ll;

ll A, B, C, D;

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

int main() {
  cin >> A >> B >> C >> D;
  ll lcm = C * D / gcd(C, D);
  ll ans = (B - A + 1) - ((B / C) - ((A-1) / C) + (B / D) - ((A-1) / D) - ((B / lcm) - ((A-1) / lcm)));
  cout << ans << endl;
  return 0;
}



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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7

struct Time {
	Time() :h(0), m(0), idx("") {}
	Time(string time, string _idx) :idx(_idx) {
		h = (time[0] - '0') * 10 + (time[1] - '0');
		m = (time[3] - '0') * 10 + (time[4] - '0');
	}
	int h, m;
	string idx;
	int diff(const Time& opp)const {
		return trans() - opp.trans();
	}
	int trans() const {
		return h * 60 + m;
	}
};

int main()
{
	while (true) {
		int n;
		cin >> n;
		if (!n)break;

		Time goddess;
		map<string, Time> mp;
		map<string, int> res;
		REP(i, n) {
			string date, time, kind, id;
			cin >> date >> time >> kind >> id;
			Time tgt(time, id);

			if (kind == "I") {
				(tgt.idx == "000" ? goddess : mp[tgt.idx]) = tgt;
			}
			else {
				if (tgt.idx == "000") {
					for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
						string name = itr->first;
						Time opp = itr->second;
						res[name] += opp.diff(goddess) > 0
							? tgt.diff(opp)
							: tgt.diff(goddess);
					}
					goddess = Time();
				}
				else {
					if (goddess.h != 0 || goddess.m != 0) {
						Time in = mp[tgt.idx];
						res[tgt.idx] += in.diff(goddess) > 0
							? tgt.diff(in)
							: tgt.diff(goddess);
					}
					mp.erase(tgt.idx);
				}
			}

		}
		int mm = 0;
		for (auto itr = res.begin(); itr != res.end(); ++itr)
			mm = max(mm, itr->second);
		cout << mm << endl;
	}
	return 0;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define F first
#define S second
#define mod 1000000007
#define INF 9000000000000000000
signed main(void){
    int r;cin>>r;cout<<3*r*r<<endl;
}

Measured memory_bytes: 768
/*
██╗  ██╗ █████╗ ██████╗ ███████╗███████╗███╗   ███╗        ██╗  ██╗██╗  ██╗ █████╗ ██╗     ███████╗██████╗
██║ ██╔╝██╔══██╗██╔══██╗██╔════╝██╔════╝████╗ ████║        ██║ ██╔╝██║  ██║██╔══██╗██║     ██╔════╝██╔══██╗
█████╔╝ ███████║██████╔╝█████╗  █████╗  ██╔████╔██║        █████╔╝ ███████║███████║██║     █████╗  ██║  ██║
██╔═██╗ ██╔══██║██╔══██╗██╔══╝  ██╔══╝  ██║╚██╔╝██║        ██╔═██╗ ██╔══██║██╔══██║██║     ██╔══╝  ██║  ██║
██║  ██╗██║  ██║██║  ██║███████╗███████╗██║ ╚═╝ ██║███████╗██║  ██╗██║  ██║██║  ██║███████╗███████╗██████╔╝
╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═╝     ╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═════╝
Believe in yourself ,( try and try and then try ), You can do it
*/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define clr(arr, x) memset(arr, x, sizeof arr)
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
#define OO 0x3f3f3f3f3f3f3f3fLL
const int oo = 0x3f3f3f3f, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
void K_K(){
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int n, w;
const int mx = 100 * 1e3 + 1;
vector<pair<int, ll>>arr;
ll dp[105][mx];
ll sol(int idx, int val){
	if (idx == n){
		if (!val)
			return 0;
		return OO;
	}
	if (val < 0)
		return OO;
	ll &ret = dp[idx][val];
	if (~ret)
		return ret;
	return ret = min(sol(idx + 1, val),
		sol(idx + 1, val - arr[idx].second) + arr[idx].first);
}
int main(){
	K_K();
	cin >> n >> w;
	arr.resize(n);
	clr(dp, -1);
	for (int i = 0; i < n; i++){
		cin >> arr[i].first >> arr[i].second;
	}
	int ans = 0;
	for (int i = 1; i < mx; i++){
		if (sol(0, i) <= w){
			ans = i;
		}
	}
	cout << ans;
}

Measured memory_bytes: 85660
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  long sum=0;
  cin >> N;
  for (int i=1; i<=N; i++)
  {
    if (i%3==0 || i%5==0) continue;
    else sum +=i;
  }
  cout << sum << endl;
}

Measured memory_bytes: 3620
#include <stdio.h>

int abs(int i){
	if(i > 0){
		return i;
	}else{
		return -i;
	}
}

int diff(int a,int b){
	if(a>b){
		return a - b;
	}else{
		return b - a;
	}
}

int minn(int ary[],int n)
{
	int min = ary[0];
	int i;
	for(i = 0; i < n; i++){
		if(min > ary[i]){
			min = ary[i];
		}
	}
	
	return min;
}
	

int main(void)
{
	int n;
	scanf("%d",&n);
	
	int w[n];
	
	int i,j;
	
	for(i = 0; i < n; i++){
		scanf("%d",&w[i]);
	}
	
	int  total = 0;
	
	int s1[n],ans[n];
	
	for(i = 0; i < n; i++){
		total += w[i];
	}
	
	for(i = 0; i < n; i++){
		s1[i] = 0;
		for(j = 0; j <= i; j++){
			s1[i] += w[j];
		}
	}
	
	for(i = 0; i < n; i++){
		ans[i] = total - s1[i];
		ans[i] = diff(s1[i],ans[i]);
	}
	
	printf("%d\n",minn(ans,n));
	
	return 0;
}
	
	
	
	
	
		
	

	
			
	
	
	
	
	

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		if (N>1){
			System.out.println(K*(int)(Math.pow(K-1, N-1)));
		}
		else if(N==1){
			System.out.println(K);
		}
	}

}

Measured memory_bytes: 9804
#include<iostream>
#include <string>
using namespace std;
int main()
{
    // 整数の入力
  int n;
  int cnt[4] = {};

//  cout << cnt[0] << cnt [1] << cnt[2] << cnt[4];

  cin >> n;

  for(int i = 0; i < n; i++) {
    string str;
    cin >> str;
    if(str == "AC") {
      cnt[0]++;
    } else if(str == "WA") {
      cnt[1]++;
    } else if(str == "TLE") {
      cnt[2]++;
    } else {
      cnt[3]++;
    }
  }

  cout << "AC x " << cnt[0] << '\n';
  cout << "WA x " << cnt[1] << '\n';
  cout << "TLE x " << cnt[2] << '\n';
  cout << "RE x " << cnt[3];

    return 0;
}


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

string back(string s) {
  int n = s.size();
  string ret;
  int abc[3] = {0};
  vector<bool> used(n);
  bool ok = false;

  for (int i = 0; i < n - 2; i++) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
      used[i] = used[i + 1] = used[i + 2] = true;
      ok = true;
    }
  }
  if (!ok)
    return "NG";
  for (int i = 0; i < n; i++) {
    if (used[i])
      continue;
    abc[s[i] - 'A']++;
  }
  if (abc[0] > 0 && abc[1] > 0 && abc[2] > 0)
    return "NG";
  char c = abc[0] == 0 ? 'A' : abc[1] == 0 ? 'B' : 'C';
  for (int i = 0; i < n; i++) {
    if (!used[i])
      ret.push_back(s[i]);
    else {
      ret.push_back(c);
      i += 2;
    }
  }

  return ret;
}

int main() {
  string s;
  cin >> s;
  while (s.size() > 3)
    s = back(s);
  if (s == "ABC")
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3252
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<iomanip>
#include<map>
using namespace std;
typedef pair<int, pair<int, int> >PP;
typedef long long ll;
typedef pair<int, int>P;
typedef vector<int>vec;
int inf=-1;
ll mod = pow(10, 9) + 7;
 
ll Min(ll a,ll b){
    if(a<b){
        return a;
    }
    else{
        return b;
    }
}
 
int main(){
    long double n;cin>>n;
    ll ans=mod*mod;
    for(ll i=1;i<=ll(sqrt(n));i++){
        if(ll(n)%i==0){
            ll j=n/i;
            ans=Min(ans,i+j-1ll-1ll);
        }
    }
    cout <<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>


#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;
typedef string::const_iterator State;

int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0 ,0 };


int main(void) {

	int n;
	int a, b, c, d;
	int pos;
	int now;
	int mini;
	int count = 0;

	cin >> n;
	vector< pair<int, int> > red(n), blue(n);

	FOR(i, 1, n) {
		cin >> a >> b;
		red[i - 1].first = a;
		red[i - 1].second = b;
	}
	FOR(i, 1, n) {
		cin >> c >> d;
		blue[i - 1].first = c;
		blue[i - 1].second = d;
	}

	sort(red.begin(), red.end());
	sort(blue.begin(), blue.end());

	FOR(i, 0, n-1) {
		pos = -1;
		RFOR(j, n-1, 0) {
			if (blue[i].first > red[j].first) {
				pos = j;
				break;
			}
		}
		mini = -100;
		FOR(j, 0, pos) {
			if (blue[i].second > red[j].second) {
				if (mini < red[j].second) {
					mini = red[j].second;
					now = j;
				}
			}
		}
		if (mini != -100) {
			count++;
			red[now].first = 200;
			red[now].second = 200;
		}
		sort(red.begin(), red.end());
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
from itertools import combinations_with_replacement


n, m, q = map(int, input().split())
QUERY = [tuple(map(int, input().split())) for _ in range(q)]

ans = 0
for A in combinations_with_replacement(range(1, m + 1), n):
    temp = 0
    for a, b, c, d in QUERY:
        a -= 1; b -= 1
        if A[b] - A[a] == c:
            temp += d
    ans = max(ans, temp)

print(ans)


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;


int main() {
    string s;cin>>s;
    ll k;cin>>k;

    char ans;
    bool jdg=true;

    rep(i,k){
        if(s[i]!='1'){
            ans=s[i];
            jdg=false;
            break;
        }
    }

    if(jdg){
        cout<<1<<endl;
    }
    else {
        cout<<ans<<endl;
    }
}



Measured memory_bytes: 256
(* O(h w) *)
let h, w = Scanf.scanf " %d %d" @@ fun a b -> a, b
let b = ref 0
let sss = Array.init h @@ fun _ ->
  Array.init w @@ fun _ -> Scanf.scanf " %c" @@ fun c -> if c = '#' then incr b; c
let ds = Array.make_matrix h w @@ -1
let _ =
  let q = Queue.create () in
  ds.(0).(0) <- 0;
  Queue.push (0, 0) q;
  while not @@ Queue.is_empty q do
    let y0, x0 = Queue.pop q in
    let f (dy, dx) =
      let y, x = y0 + dy, x0 + dx in
      if 0 <= y && y < h && 0 <= x && x < w && ds.(y).(x) = -1 && sss.(y).(x) <> '#' then
        (ds.(y).(x) <- ds.(y0).(x0) + 1;
        Queue.push (y, x) q) in
    List.iter f [0, -1; -1, 0; 0, 1; 1, 0]
  done;
  let g = ds.(h - 1).(w - 1) in
  Printf.printf "%d\n" @@ if g = -1 then -1 else h * w - !b - ds.(h - 1).(w - 1) - 1

Measured memory_bytes: 1408
N=int(input())
T=list(map(int,input().split()))
M=int(input())

PP=[]
XX=[]

for i in range(M):
    P, X = map(int,input().split())
    PP.append(P)
    XX.append(X)
    
for j in range(0,M):
    TT=T[:]
    PPP=PP[j]
    TT[PPP-1]=XX[j]
    total=sum(TT)
    print(total)

Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <list>

using namespace std;

int main()
{
	long L, R;

	cin >> L >> R;

	if (R == L + 1L)
	{
		cout << ((L%2019L) * (R%2019L)) % 2019L;
		return 0;
	}

	if (2019L <= R - L + 1L)
	{
		cout << 0;
		return 0;
	}

	long i1 = L;
	long j1 = L+1;

	long i2 = R - 1;
	long j2 = R;


	long div1 = (i1*j1) / 2019;
	long div2 = (i2*j2) / 2019;

	long min_mod = 2019;
	long i_tmp = -1;
	for (long i = L; i < R; ++i)
	{
		for (long j = i + 1; j <= R; ++j)
		{

			long tmp = ((i % 2019L)*(j % 2019L));
			tmp = tmp % 2019L;

			if (tmp < min_mod)
			{
				min_mod = tmp;
				i_tmp = i;
			}
		}

	}
	cout << min_mod;
	return 0;

	//if (div1 == div2)
	{
		int mod1 = (i1*j1) % 2019;
		int mod2 = (i2*j2) % 2019;

		cout << min(mod1, mod2);
		return 0;
	}








	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
vector<int> res;
int n,q;
int main()
{
    cin >> n >> q;
    string s;
    cin >> s;
    res.resize(n+1);
    res[0] = 0;
    rep(i,n){
        if(s[i] == 'A'){
            if(i+1 < n && s[i+1] == 'C')res[i+1]++;
        }
        if(i+2 <= n)res[i+2] += res[i+1];
    }
    
    
    while(q--){
        int l,r;
        cin >> l >> r;
        l--;
        int ans = res[r] - res[l];
        if(r < n &&s[r-1] == 'A' &&  s[r] == 'C')ans--;
        cout << ans << endl;

    }
    
    return 0;
}


Measured memory_bytes: 1408
def C():
    n, k = map(int, input().split())
    ans = 0
    if k%2 == 0:
        x = n // (k)
        ans += x*x*x
        y = (n + (k//2)) // (k)
        ans += y*y*y
    else:
        x = n // k
        ans += x*x*x
    print(ans)

if __name__ == '__main__':
    C()

Measured memory_bytes: 2940
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a;
    int b;
    a = sc.nextInt();
    b = sc.nextInt();
    while(a != 0 || b != 0){
      System.out.println(a > b ? b + " " + a : a + " " + b );
      a = sc.nextInt();
      b = sc.nextInt();
    }
  }
}

Measured memory_bytes: 35620