akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
     string s;
     cin>>s;
     int flag=0;
     for(int i=0;i<4;i++){
     	if(i<3){
     	if(s[i]==s[i+1])
     	flag=1;}
     }
     if(flag==1)
     cout<<"Bad";
     else 
     cout<<"Good";
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var vs = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var cs = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

        var p = 0;
        for (int i = 0; i < vs.Length; i++)
        {
            var d = vs[i] - cs[i];
            if (d < 0)
            {
                continue;
            }

            p += d;
        }
        Console.WriteLine(p);
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
#include <math.h>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define EPS (1e-12)
inline double sq(double a) { return a*a; }

int n, a[10], b[10];

double at(int i, double y) {
    const int j = (i+1)%n;
    const double dx = a[j]-a[i], dy = b[j]-b[i];
    return a[i] + dx/dy*(y-b[i]);
}

double cut(double y) {
    vector<double> xs;
    rep(i, n) {
        const int j = (i+1)%n;
        if(b[i]==b[j]) continue;
        if(y <= min(b[i], b[j])) continue;
        if(y >= max(b[i], b[j])) continue;
        xs.push_back(at(i, y));
    }
    sort(xs.begin(), xs.end());
    if(xs.size()==4) return xs[3]-xs[2]+xs[1]-xs[0];
    else return xs.size()<2 ? 0 : xs.back()-xs.front();
}

int main() {
    for(;;) {
        scanf("%d", &n);
        if(n==0) return 0;
        rep(i, n) scanf("%d%d", a+i, b+i);
        vector<double> ws;
        rep(i, n) ws.push_back(b[i]-EPS), ws.push_back(b[i]+EPS);
        sort(ws.begin(), ws.end());
        double ans = 0;
        rep(i, n) {
            const int j = (i+1)%n;
            if(b[i]==b[j]) {
                ans += (cut(b[i]-EPS) + cut(b[i]+EPS)) * abs(a[j]-a[i]);
            }
            else {
                const int u = min(b[i], b[j]), v = max(b[i], b[j]);
                rep(k, ws.size()-1) {
                    const double l = ws[k], r = ws[k+1];
                    if(r<u || l>v) continue;
                    const double d = sqrt(sq(r-l) + sq(at(i, r)-at(i, l)));
                    ans += (cut(l) + cut(r)) * d;
                }
            }
        }
        printf("%.12f\n", ans);
    }
}

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

int main(){
  int A,p;p=0;
  cin >> A;
  int B;
  cin >> B;
  int w=10*(B+1);
  bool K[w];
  for(int i=10*B;i<10*(B+1);i++){K[i]=0
  ;}
  for(int i=10*B;i<10*(B+1);i++){
  if(100*A<=8*i&&100*(A+1)>8*i)K[i]=1
  ;}
  for(int i=10*B;i<10*(B+1);i++){
      if(K[i]){cout<<i<<endl;
      p++;
      break;}
  ;}
  if(p==0)cout<<-1<<endl;
   }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repm(i,m,n) for (int i = (m); i < (n); i++)
#define rrep(i,n) for (int i = (n); i >= 0; i--)
using namespace std;
typedef long long ll;

int main() {
  int N, T;
  cin >> N >> T;
  
  vector<int> c(N), t(N);
  rep(i,N) cin >> c.at(i) >> t.at(i);
  
  bool can = false;
  int cost = 1e9;
  rep(i,N) {
    if (t.at(i) <= T) {
      cost = min(c.at(i), cost);
      can = true;
    }
  }
  
  if (can) 
    cout << cost << endl;
  else 
    cout << "TLE" << endl;
}

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

int	get_idx(vector<int> &q, int v) {
	int L=0;
	int H=q.size()-1;
	while(true) {
		int M=(H+L)/2;
		if (M==L)
			return H;
		if (v<q.at(M))
			H=M;
		else
			L=M;
	}
}

int	main() {
	int N;
	cin >>N;
	vector<int> A(N, 0);
	for (int i=0; i<N; i++)
		cin >>A.at(i);
	vector<int> q;
	q.push_back(A.back());
	for (int i=N-2; i>=0; i--) {
		if (A.at(i)>=q.back()) {
			q.push_back(A.at(i));
			continue;
		}
		if (A.at(i)<q.at(0)) {
			q.at(0)=A.at(i);
			continue;
		}
		int I=get_idx(q, A.at(i));
		q.at(I)=A.at(i);
	}
	cout <<q.size() <<endl;
	return 0;
}



Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<V>;
using VVV = vector<VV>;
using VL = vector<ll>;
using VVL = vector<VL>;
using VVVL = vector<VVL>;
template<class T> using VE = vector<T>;
template<class T> using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
ll upper = MOD + MOD;
ll under = -upper;
ll UPPER = MOD * MOD;
ll UNDER = -UPPER;
const long double pi = 3.141592653589793;
int main() {
	int r, c, k;
	cin >> r >> c >> k;
	VVL v(r + 1, VL(c + 1, 0));
	rep(i, k) {
		int x, y, va;
		cin >> x >> y >> va;
		v[x][y] = va;
	}
	VVVL dp(r + 1, VVL(c + 1, VL(4, 0)));
	rep(i, r + 1) rep(j, c + 1) rep(k, 4) {
		int e = v[i][j] != 0;
		if (k + e <= 3) {
			if (j + 1 <= c) chmax(dp[i][j + 1][k + e], dp[i][j][k] + v[i][j]);
			if (i + 1 <= r) chmax(dp[i + 1][j][0], dp[i][j][k] + v[i][j]);
		}
		if (i + 1 <= r) chmax(dp[i + 1][j][k], dp[i][j][k]);
		if (j + 1 <= c) chmax(dp[i][j + 1][k], dp[i][j][k]);
	}
	rep(i, 3) dp[r][c][i] += v[r][c];
	ll ans = 0;
	rep(i, 4) chmax(ans, dp[r][c][i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 707104
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int A, B, C;
    cin >> A >> B >> C;
    for (int i = 1; i <= B; i++) {
        if ((A * i) % B == C) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3592
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int n,a;
  std::cin >> n >>a;
  bool ans=false;
  if(n%500<=a) ans=true;

  if(ans)printf("Yes\n");
  else printf("No\n");
  return 0;
}


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

int main(){
    int S, W; cin >> S >> W;

    if(S > W) cout << "safe" << endl;
    else cout << "unsafe" << endl;
    return 0;
}

Measured memory_bytes: 3624
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q, curr;
ll l[ohara], r[ohara];
pq que2;
rpq que1;

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

  cin >> n;
  rep(i, 3 * n) cin >> a[i];
  rep(i, n) que1.push(a[i]), curr += a[i];
  rrep(i, 2 * n, 3 * n) que2.push(a[i]);
  l[n - 1] = curr;
  rrep(i, n, 2 * n) {
    que1.push(a[i]);
    curr += a[i];
    curr -= que1.top();
    que1.pop();
    l[i] = curr;
  }

  curr = 0;
  rrep(i, 2 * n, 3 * n) curr += a[i];
  r[2 * n] = curr;
  rrrep(i, 2 * n - 1, n) {
    que2.push(a[i]);
    curr += a[i];
    curr -= que2.top();
    que2.pop();
    r[i] = curr;
  }

  ans = -LINF;
  rrep(i, n - 1, 2 * n) {
    ans = max(ans, l[i] - r[i + 1]);
    // debug(l[i]);
    // debug(r[i + 1]);
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 8724
def mmult(A, B):
    global mod
    n, m, l = len(A), len(B), len(B[0])
    ret = [[0]*l for _ in range(n)]
    for i in range(n):
        for j in range(m):
            for k in range(l):
                ret[i][k] = (ret[i][k]+A[i][j]*B[j][k])%mod
    return ret
def mpow(A, n):
    if n == 0: return [[1 if i==j else 0 for j in range(len(A))] for i in range(len(A))]
    if n % 2: return mmult(mpow(A, n-1), A)
    return mpow(mmult(A, A), n//2)

mod = 10**9+7
N, K = map(int, input().split())
X = [[int(a) for a in input().split()] for _ in range(N)]
print(sum([sum(x) for x in mpow(X, K)]) % mod)

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

#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   //0-origin昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) //1-origin昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  //0-origin降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   //1-origin降順
//rep2 -> 第二引数 m から n 回繰り返し ex) m=5 n=3 なら i=5,i=6,i=7 まで
#define rep2(i,m,n) for(int i = ((int)(m)); i < ((int)(n))+((int)(m)); i++)
#define SIZE(x) ((int)((x).size()))
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;
template<typename T> bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1;} return 0;}
template<typename T> bool chmin(T &a, const T &b){ if(a>b){ a=b; return 1;} return 0;}


/*FUNCs=================================================*/
int k, x;

/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    cin >> k >>x;
    for(int i = x-k+1; i < x+k; i++){
        cout << i << (i == x+k-1 ? '\n' : ' ');
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }


ll a[220000];
ll x[410000];
ll y[410000];
int main(){
    ll n,k,ans=0;
    cin>>n;
    rep(i,1,n+1)cin>>a[i];
    rep(i,1,n+1)if(i+a[i]<=4e5)x[a[i]+i]++;
    rep(i,1,n+1)if(i-a[i]<=4e5&&i>=a[i])y[i-a[i]]++;
    rep(i,0,4e5+1)ans+=x[i]*y[i];
    cout<<ans;
}

Measured memory_bytes: 9836
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    rep(i, n) cin >> v[i];

    rep(i, n - k) {
        if (v[i] < v[i + k]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

}


Measured memory_bytes: 4044
def sol():
    mod=1000000007
    ans=0
    n=int(input())
    a=[int(i) for i in input().split()]
    x=[[0]*63 for i in range(n+1)]
    l=[(2**i)%mod for i in range(63)]

    for i in range(n):
        d=a[i]
        cnt=0
        for j in range(63):
            if d&1:
                x[i+1][cnt]=x[i][cnt]+1
            else:
                x[i+1][cnt]=x[i][cnt]
            cnt+=1
            d=d>>1

    for i in range(1,n):
        for j in range(63):
            p=x[i][j]-x[i-1][j]
            if p:
                ans+=l[j]*((n-i)-(x[-1][j]-x[i][j]))
            else:
                ans+=l[j]*(x[-1][j]-x[i][j])
            ans%=mod
    print(ans)

if __name__=="__main__":
    sol()

Measured memory_bytes: 207308
import java.util.Scanner;

public class Main {

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

        if ("a".equals(c) || "i".equals(c)
                || "u".equals(c) || "e".equals(c)
                || "o".equals(c)) {
            System.out.println("vowel");
            return;
        }
        System.out.println("consonant");
    }

}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pf push_front
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ge(a, b) get<(b)>((a))
#define SZ(x) (x).size()
#define endl '\n'
#define FOR(a, b, c) for (auto(a) = (b); (a) < (c); ++(a))
#define ROF(a, b, c) for (auto(a) = (b); (a) > (c); --(a))
#define F0R(a, b) FOR ((a), 0, (b))
#define R0F(a, b) ROF ((a), (b), -1)
#define CEIL(a, b) ((a) + (b)-1) / (b)
#define CLR(a, b) memset((a), (b), sizeof((a)))
template <typename t> bool ckmin(t& a, const t& b) {return a > b ? a = b, true : false;}
template <typename t> bool ckmax(t& a, const t& b) {return a < b ? a = b, true : false;}
#ifndef DEBUG
#define DEBUG 0
#endif
#define dout \
if (DEBUG) std::cerr

struct mod {
  static const ll p = 1e9 + 7;
  ll val;
  mod() : val(0) {}
  mod(ll val) : val(val % p) {}
  mod operator+(mod o) { return mod(val + o.val); }
  mod operator-(mod o) { return mod(val - o.val + p); }
  mod operator*(mod o) { return mod(val * o.val); }
  mod operator/(mod o) { return mod(*this * pow(o, p - 2)); }
  static mod pow(mod a, mod b) {
    mod res = 1;
    for (; b.val; b.val >>= 1, a = a * a)
      if (b.val & 1) res = res * a;
    return res;
  }
  friend istream& operator>>(istream& i, mod& m) {
      i >> m.val;
      m.val %= mod::p;
      if (m.val < 0) m.val += mod::p;
      return i;
  }
  friend ostream& operator<<(ostream& o, mod m) {
    return o << m.val;
  }
};


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

    ll n, k;
    cin >> n >> k;

    mod res = 0LL;
    FOR(i, k, n + 2) {
        ll left = (i - 1)*i/2;
        ll right = n*(n + 1)/2 - (n - i)*(n - i + 1)/2;

        res = res + (right - left + 1);
        dout << "l: " << left << ", r: " << right << endl;
    }
    cout << res << endl;
}




Measured memory_bytes: 3652
use std::io::Read;
fn main() {
    let buf = {
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    };
    let out = solve(buf);
    print!("{}", out);
}
fn solve(buf: String) -> String {
    let mut sc = io::Scanner::new(&buf);
    let n: usize = sc.read();
    let q: usize = sc.read();
    let queries: Vec<(usize, usize, usize)> =
        (0..q).map(|_| (sc.read(), sc.read(), sc.read())).collect();

    let mut seg = SegmentTree::<Sum>::new(n);
    let mut res = String::new();

    for query in queries {
        if query.0 == 0 {
            seg.add(query.1, query.2);
        } else {
            res.push_str(&seg.query(query.1, query.2 + 1).to_string());
            res.push_str("\n");
        }
    }
    res
}
pub mod io {
    use std::str::{FromStr, SplitWhitespace};
    pub struct Scanner<'a> {
        iter: SplitWhitespace<'a>,
    }
    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }
        pub fn read<T: FromStr>(&mut self) -> T {
            self.iter
                .next()
                .unwrap()
                .parse()
                .ok()
                .expect("parsing failed")
        }
        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.read()).collect()
        }
    }
}

type Sum = usize;

impl Monoid for Sum {
    fn mempty() -> Sum {
        0
    }
    fn mappend(a: Sum, b: Sum) -> Sum {
        a + b
    }
}
impl SegmentTree<Sum> {
    pub fn add(&mut self, k: usize, a: Sum) {
        let b = self.data[k + self.n - 1];
        self.update(k, Sum::mappend(b, a));
    }
}

pub trait Monoid: Copy {
    fn mempty() -> Self;
    fn mappend(a: Self, b: Self) -> Self;
}
pub struct SegmentTree<M> {
    n: usize,
    data: Vec<M>,
}
impl<M: Monoid> SegmentTree<M> {
    pub fn new(n: usize) -> SegmentTree<M> {
        let mut m = 1;
        while m <= n {
            m *= 2;
        }

        SegmentTree {
            n: m,
            data: vec![M::mempty(); 2 * m],
        }
    }
    pub fn update(&mut self, k: usize, a: M) {
        let mut k = k + self.n - 1;
        self.data[k] = a;
        while k > 0 {
            k = (k - 1) / 2;
            self.data[k] = M::mappend(self.data[k * 2 + 1], self.data[k * 2 + 2]);
        }
    }
    pub fn query(&self, l: usize, r: usize) -> M {
        self.query_range(l, r, 0, 0, self.n)
    }
    pub fn query_range(&self, a: usize, b: usize, k: usize, l: usize, r: usize) -> M {
        if r <= a || b <= l {
            M::mempty()
        } else if a <= l && r <= b {
            self.data[k]
        } else {
            let vl = self.query_range(a, b, k * 2 + 1, l, (l + r) / 2);
            let vr = self.query_range(a, b, k * 2 + 2, (l + r) / 2, r);
            M::mappend(vl, vr)
        }
    }
}



Measured memory_bytes: 13204
import sys
input = sys.stdin.readline
from collections import Counter

N, mod = map(int, input().split())
S = list(input().rstrip())

if mod == 2 or mod == 5:
    ans = 0
    for i, s in enumerate(S):
        if int(s)%mod==0:
            ans += i+1
else:
    dp = [0]
    t = 1
    for s in reversed(S):
        dp.append((dp[-1]+int(s)*t)%mod)
        t = t*10%mod

    ans = 0
    C = Counter(dp)
    for v in C.values():
        ans += v*(v-1)//2

print(ans)

Measured memory_bytes: 13352
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

void solve()
{
	int arr[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin>>k;
	cout<<arr[k-1];	
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

vvll memo(202, vll(202, -1));

ll gcd(ll a, ll b) {
  if(memo[a][b] != -1) {
    return memo[a][b];
  } if(memo[b][a] != -1) {
    memo[a][b] = memo[b][a];
    return memo[b][a];
  } else {
    ll res = b ? gcd(b, a%b) : a;
    memo[a][b] = res;
    return res;
  }
}

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  int K;
  cin >> K;
  
  ll s = 0;
  for(int a=1; a<=K; a++) {
    for(int b=1; b<=K; b++) {
      for(int c=1; c<=K; c++) {
        s += gcd(gcd(a, b), c);
      }
    }
  }
  fin(s);
}

Measured memory_bytes: 3984
fun main(args: Array<String>) {
    val (H, W, D) = readLine()!!.split(" ").map { it.toInt() }
    val A = mutableListOf<IntArray>()
    (1..H).forEach {
        val ai = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
        A.add(ai)
    }
    // O(HW) Create function to retrieve the poistion of num N in O(1)
    val numToPosition = Array(H * W + 1, { Pair(-1, -1) })
    (0 until H).forEach {h ->
        (0 until W).forEach {w ->
            val num = A[h][w]
            numToPosition[num] = Pair(h, w)
        }
    }
    fun getPositionByNumber(num: Int) : Pair<Int, Int> {
        return numToPosition[num]
    }

    val Q = readLine()!!.toInt()

    // Return cost
    fun useMagic(i: Int, j: Int, x: Int, y: Int) : Int {
        return Math.abs(x - i) + Math.abs(y - j)
    }

    val a = IntArray(H * W + 1)
    a.fill(0)

    // O(HW)
    (1..D).forEach {d ->
        var r = d
        a[r] = 0
        while (r + D <= H * W) {
            val (i, j) = getPositionByNumber(r)
            val (x, y) = getPositionByNumber(r + D)
            a[r + D] = a[r] + useMagic(i, j, x, y)
            r += D
        }
    }

    // O(Q)
    (1..Q).forEach {
        val (L, R) = readLine()!!.split(" ").map { it.toInt() }
        println(a[R] - a[L])
    }
}


Measured memory_bytes: 76664
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pi=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
void Yes(bool c) { if (c)print("Yes"); else print("No"); };
void YES(bool c) { if (c)print("YES"); else print("NO"); };

int divisor(int n){
    int i = 1;
    vi v;
    while(i*i<=n){
        if(n%i==0){
            v.pb(i);
            if(i!=n/i) v.pb(n/i);
        }
        i++;
    }
    // sort(ALL(v));
    // return v;
    return v.size();
}

void solve() {
    int n;
    cin >> n;
    int ans = 0;
    for(int i=1;i<=n;i+=2){
        if(divisor(i)==8){
            ans++;
        }
    }
    print(ans);
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 3632
#!/usr/bin/python

def main():
    N = [int(x) for x in input().split()]
    max_1 = max(N)
    N[N.index(max(N))] = max(N) - 1
    max_2 = max(N)
    print(max_1+max_2)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(abs(a - b) >= abs(a - c) && abs(a - b) >= abs(b - c)){
    cout << abs(a - c) + abs (b - c) << endl;
  }else if(abs(a - c) >= abs(a - b) && abs(a - c) >= abs(b - c)){
    cout << abs(a - b) + abs(b - c) << endl;
  }else{
    cout << abs(a - b) + abs(a - c) << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main 
{
	public static void main(String[] args)
    {
        Scanner sc = new Scanner (System.in);
        String a=  sc.next();
        String b = sc.next();
        int c = sc.nextInt();
        int d = sc.nextInt();
        String result = sc.next();
        if (a.equals(result)) {
          c--;
          System.out.println(c + " " + d);
        }
        else {
          d--;
          System.out.println(c + " " + d);
        }
}
    }

Measured memory_bytes: 21844
#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)
#define pb push_back
#define fst first
#define snd second

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

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

#define MAX 200010
int N,K;
ll A[MAX][2];

void solve() {

}

int main() {
  if( 0 ) {
    cout << 200000 << " " << 200000 << endl;
    rep(i,200000) {
      cout << 0 << " ";
    }
    return 0;
  }
  cin >> N >> K;
  rep(i,N) cin >> A[i][0];
  rep(i,K) {
    int cur = i & 1;
    int nex = ( cur + 1 ) & 1;
    rep(_,N) A[_][nex] = 0;
    rep(j,N) {
      int L = j - A[j][cur];
      int R = j + A[j][cur];
      L = max(0,L);
      R = min(R,N-1);
      ++A[L][nex];
      --A[R+1][nex];
    }
    bool found = false;
    if( A[0][nex] != N ) found = true;
    REP(j,1,N) {
      A[j][nex] += A[j-1][nex];
      if( A[j][nex] != N ) found = true;
    }
    if( !found ) {
      rep(j,N) {
	if( j ) printf(" ");
	cout << A[j][nex];
      } puts("");
      return 0;
    }
  }

  rep(i,N) {
    if( i ) printf(" ");
    cout << A[i][K&1];
  } puts("");
  
  return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  if((a < c && c < b) || (b < c && c < a)) {
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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

MOD = 10**9 + 7
M = 2*N

fact = [1]*(M+1)
rfact = [1]*(M+1)
r = 1
for i in range(1, M+1):
  fact[i] = r = r * i % MOD
rfact[M] = r = pow(fact[M], MOD-2, MOD)
for i in range(M, 0, -1):
  rfact[i-1] = r = r * i % MOD

rev = pow(A+B, MOD-2, MOD)

p = 0
b = B * rev % MOD
e = 1
for k in range(N):
    v = fact[N+k-1] * rfact[N-1] * rfact[k] % MOD
    v = v * e * (N + k) % MOD
    e = e * b % MOD
    p += v
p *= pow(A * rev % MOD, N, MOD) * 100 * rev % MOD

q = 0
b = A * rev % MOD
e = 1
for k in range(N):
    v = fact[N+k-1] * rfact[N-1] * rfact[k] % MOD
    v = v * e * (N + k) % MOD
    e = e * b % MOD
    q += v
q *= pow(B * rev % MOD, N, MOD) * 100 * rev % MOD

print((p + q) % MOD)

Measured memory_bytes: 18932
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int
#define LD long double

LL MOD = 1000000007;

struct D{
    LL p;
    int count = 0;
};

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

    vector<D> list;

    int count = 0;
    LL sub_n = n;
    int j = 0;


    if(sub_n % 2 == 0){
        list.push_back({2,count});
        while(sub_n % 2 == 0){
            sub_n /= 2;
            count++;
        }

        list[j++].count = count;
    }

    for(int i = 3; i <= sqrt(n); i += 2){
        if(sub_n % i == 0){
            int count = 0;
            list.push_back({i,count});
            while(sub_n % i == 0){
                sub_n /= i;
                count++;
            }
            list[j++].count = count;
        }
    }

    if(sub_n != 1){
        list.push_back({sub_n,1});
    }

    int ans = 0;

    cerr << list.size() << endl;

    for(int i = 0; i < list.size(); ++i){
        cerr << list[i].p << " " << list[i].count << endl;
        for(int j = 1,k = 1; j <= list[i].count; j += k){
            k++;
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3724
import java.util.*;

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

        int A = sc.nextInt();
        int B = sc.nextInt();
        int T = sc.nextInt();
        int ans = 0;

        for(int i=1; A*i<=T; i++){
            ans += B;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  int n, x, ans=0;
  cin >> n >> x;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  sort(all(a));
  if(x - accumulate(all(a), 0) > 0) {
    cout << n-1;
    exit(0);
  }
  rep(i, n) {
    if(x - a.at(i) >= 0) {
      ans++;
      x -= a.at(i);
    }
    else{
      break;
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a*b==c*d)cout<<a*b<<endl;
    else cout<<max(a*b,c*d)<<endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
sum = 1
if 0 in a:
    print(0)
else:
    for i in range(n):
        sum *= a[i]
        if(sum > 10 ** 18):
            print(-1)
            break
    else:
        print(sum)


Measured memory_bytes: 21472
#include<stdio.h>

int N,U,K,V,G[105][105]={0},i,j;
int main()
{
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		scanf("%d%d",&U,&K);
		for(j=0;j<K;j++)
		{
			scanf("%d",&V);
			G[U][V]=1;
		}
	}
	for(i=1;i<=N;i++)
		for(j=1;j<=N;j++)
			printf("%d%c",G[i][j],j==N?'\n':' ');
	return 0;
}

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

int main(void) {
	char s[51], t[51];
	int len_s, len_t;
	char ans[51] = "";
	memset(ans, '~', sizeof ans - 1);

	scanf("%s%n ", s, &len_s);
	scanf("%s%n", t, &len_t);

	for (int i = 0; i < len_s - len_t + 1; i++) {
		int ok = 1;
		for (int j = 0; j < len_t; j++)
			ok &= s[i + j] == t[j] || s[i + j] == '?';
		if (ok) {
			char tmp[51];

			strcpy(tmp, s);
			for (int j = 0; j < len_t; j++)
				tmp[i + j] = t[j];
			for (int j = 0; j < len_s; j++)
				if (tmp[j] == '?')
					tmp[j] = 'a';

			if (strcmp(tmp, ans) < 0)
				strcpy(ans, tmp);
		}
	}

	puts(ans[0] == '~' ? "UNRESTORABLE" : ans);

	return 0;
}


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

using namespace std;

int main(){
  int n;
  string s, t;
  cin >> n >> s >> t;
  for(int i=n;i>=1;i--){
    bool is_ok=true;
    for(int j=0;j<i;j++){
      if(s[n-i+j]!=t[j]){
        is_ok=false;
        break;
      }
    }
    if(is_ok){
      cout << 2*(n-i) + i << endl;
      return 0;
    }
  }
  cout << 2*n << endl;
}



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

int main() {
    string S;
    cin >> S;

    int c0 = 0, c1 = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == '0') c0++;
        else c1++;
    }

    cout << 2*min(c0, c1) << endl;

    return 0;
}

Measured memory_bytes: 512
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 100000

int n;

int input() {
	if (scanf("%d", &n) < 0) return 0;
	return 1;
}

void init() {
}

long solve() {
	long a=1, b=1;
	for (int i=0; i<n; i++) {
		long c, d;
		scanf("%ld %ld", &c, &d);
		long k = max((a+c-1)/c, (b+d-1)/d);
		a=c*k, b=d*k;
		//printf("%ld %ld:%ld %ld\n", c, d, a, b);
	}
	return a+b;
}

void output(long ans) {
	printf("%ld\n", ans);
}

void cleanup() {
}

int main() {
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





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

struct dice{
	int top;
	int front;
	int left;
	int right;
	int back;
	int bottom;
};

void ClockwiseTop(dice *X){
	int c = X->front;
	X->front  = X->right;
	X->right  = X->back;
	X->back   = X->left;
	X->left   = c;
}

void ClockwiseFront(dice *X){
	int c = X->top;
	X->top    = X->left;
	X->left   = X->bottom;
	X->bottom = X->right;
	X->right  = c;
}

void ClockwiseRight(dice *X){
	int c = X->top;
	X->top    = X->front;
	X->front  = X->bottom;
	X->bottom = X->back;
	X->back   = c;
}

void ClockwiseBottom(dice *X){
	ClockwiseTop(X);
	ClockwiseTop(X);
	ClockwiseTop(X);
}

void ClockwiseBack(dice *X){
	ClockwiseFront(X);
	ClockwiseFront(X);
	ClockwiseFront(X);
}

void ClockwiseLeft(dice *X){
	ClockwiseRight(X);
	ClockwiseRight(X);
	ClockwiseRight(X);
}

void TwiceClockwiseTop(dice *X){
	ClockwiseTop(X);
	ClockwiseTop(X);
}

void TwiceClockwiseRight(dice *X){
	ClockwiseRight(X);
	ClockwiseRight(X);
}

char Judge(dice A, dice B){
	if(B.front  == A.top) ClockwiseRight(&B);
	if(B.right  == A.top) ClockwiseBack(&B);
	if(B.left   == A.top) ClockwiseFront(&B);
	if(B.back   == A.top) ClockwiseLeft(&B);
	if(B.bottom == A.top) TwiceClockwiseRight(&B);	

	if(B.right  == A.front) ClockwiseTop(&B);
	if(B.left   == A.front) ClockwiseBottom(&B);
	if(B.back   == A.front) TwiceClockwiseTop(&B);
	
	if(B.top    != A.top   ) return 'F';
	if(B.front  != A.front ) return 'F';
	if(B.right  != A.right ) return 'F';
	if(B.left   != A.left  ) return 'F';
	if(B.back   != A.back  ) return 'F';
	if(B.bottom != A.bottom) return 'F';
	return 'T';
}

dice Enter(dice X){
	cin >> X.top;
	cin >> X.front;
	cin >> X.right;
	cin >> X.left;
	cin >> X.back;
	cin >> X.bottom;
	return X;
}

int main(){
	//?????????????????????????????¢?????°????????\?????????
	dice A = Enter(A);
	dice B = Enter(B);
	//???????????????????????¨?????????
	if(Judge(A, B) == 'F') cout << "No"  << endl;
	if(Judge(A, B) == 'T') cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<tuple>
#include<map>
#define DB double
#define LL long long
#define PP std::pair<DB,DB>
#define MPP std::make_pair
#define TT std::tuple<int,int,int>
#define INF (100000000000000000)
int N, K;
LL A[100010];
LL m[100010];
LL M[100010];
LL ans, sum;
int main() {
	std::cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		std::cin >> A[i];
		m[i] = m[i - 1];
		M[i] = M[i - 1];
		if (A[i] > 0)M[i] += A[i];
		else m[i] += A[i];
	}
	for (int i = K; i <= N; i++) {
		ans = std::max(ans, M[N] + m[i] - m[i - K]);
	}
	for (int i = K; i <= N; i++) {
		ans = std::max(ans, M[N] - M[i] + M[i - K]);
	}
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cmath>
#include<cstdlib>

using namespace std;

int main() {
   int N;
   cin >> N;
   
   int ans;

   if (N%2 == 0) ans = N;
   else ans = 2 * N;

   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
#define INF 1000000000
using namespace std;
typedef long long ll;

struct edge { ll n, d, e; };
struct state {
  ll n, l, s;
  bool operator<(const state &state) const { return s > state.s; }
};

int main(void) {
  int N, M, L;
  while(cin >> N >> M >> L, N || M || L) {
    vector<edge> G[100];

    REP(i, 0, M) {
      int A, B, D, E;
      cin >> A >> B >> D >> E;
      G[A - 1].push_back((edge) { B - 1, D, E });
      G[B - 1].push_back((edge) { A - 1, D, E });
    }

    ll dp[100][101];
    REP(i, 0, N) REP(j, 0, L + 1) dp[i][j] = INF;
    dp[0][0] = 1;

    priority_queue<state> q;
    q.push((state) { 0, 0, 0 });
    while(q.size()) {
      state c = q.top();
      q.pop();

      if(c.n == N - 1) {
        cout << c.s << endl;
        break;
      }

      if(dp[c.n][c.l] <= c.s) continue;
      dp[c.n][c.l] = c.s;

      REP(i, 0, G[c.n].size()) {
        q.push((state) { G[c.n][i].n, c.l, c.s + G[c.n][i].e });
        if(c.l + G[c.n][i].d <= L) {
          q.push((state) { G[c.n][i].n, c.l + G[c.n][i].d, c.s });
        }
      }
    }
  }

  return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N+1);
  vector<int> B(N);
  vector<int> b(N);
  int64_t ans=0;
  for(int i=0;i<N+1;i++){
    cin >> A.at(i);
  }
  for(int i=0;i<N;i++){
    cin >> B.at(i);
  }
  for(int i=0;i<N;i++){
    b.at(i)=0;
  }
  
  for(int i=0;i<N-1;i++){
    if(A.at(i)>B.at(i)){
      ans = ans+B.at(i);
      B.at(i)=0;
    }
    else{
      if(A.at(i)+A.at(i+1) > B.at(i)){
        ans = ans + B.at(i);
        A.at(i+1) = A.at(i+1) + A.at(i) - B.at(i);
      }
      else{
        ans = ans + A.at(i) +  A.at(i+1);
        A.at(i+1) = 0;
      }
    }
  }
  if(A.at(N-1)>B.at(N-1)){
      ans = ans+B.at(N-1);
    }
    else{
      if(A.at(N-1)+A.at(N) > B.at(N-1)){
        ans = ans + B.at(N-1);
      }
      else{
        ans = ans + A.at(N-1) +  A.at(N);
      }
    }
  
  
  cout << ans << endl;
  
  
  
}

Measured memory_bytes: 1536
<?php
while($lines = fgets(STDIN)) {
    $tmp[] = trim($lines);
}

$total = 0;
$str = '';
foreach($tmp as $a){
    list($b1, $b2) = explode(' ', $a);
    $odd = ($b1*$b2) %2;
}

$result = $odd ? 'Odd' : 'Even';
echo $result. "\n";

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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll HIGHINF = (ll)1e18;
const ll LOWINF = (ll)1e15;
const long double PI = 3.1415926535897932384626433;

template<typename T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template<typename... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

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

	
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>

#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 MOD 1000000007
#define INF 1000000000

using namespace std;

int main(void) {
	int n, k;
	int max = 0;
	int gcd = 1;
	int a[100001];

	cin >> n >> k;
	FOR(i, 1, n) {
		cin >> a[i];
		if (a[i] > max) {
			max = a[i];
		}
	}
	sort(a, a + n);
	RFOR(i, a[1], 2) {
		FOR(t, 1, n) {
			if (a[t] % i != 0) {
				break;
			}
			if (t == n) {
				gcd = i;
				break;
			}
		}
		if (gcd != 1) {
			break;
		}
	}
	if ((k % gcd)==0 && k <= max) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string.h>
#include <vector>
using namespace std;

const int MAXN = 100000, MOD = 1000000007;

int t[MAXN + 10];

void add(int v, int d)
{
    for (; v <= MAXN; v += (v & (-v)))
        t[v] += d;
}

int sum(int r)
{
    int ans = 0;
    for (; r > 0; r -= (r & (-r)))
        ans += t[r];
    return ans;
}

int sum(int l, int r)
{
    return sum(r) - sum(l - 1);
}

int index(vector<int> p, int mod)
{
    int n = p.size();
    memset(t, 0, sizeof t);
    for (int i = 1; i <= n; ++i)
        add(i, 1);
    int fact[MAXN + 10];
    fact[0] = 1 % mod;
    for (int i = 1; i <= n; ++i)
        fact[i] = fact[i - 1] * 1ll * i % mod;
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        int id = sum(p[i] - 1);
        ans = (ans + id * 1ll * fact[n - 1 - i]) % mod;
        add(p[i], -1);
    }
    return ans;
}

int parity(vector<int> p)
{
    int n = p.size();
    memset(t, 0, sizeof t);
    int ans = 0;
    for (int i = n - 1; i >= 0; --i)
    {
        int smaller = sum(p[i] - 1);
        ans = (ans + smaller) % 2;
        add(p[i], 1);
    }
    return ans;
}

int main()
{
    cin.sync_with_stdio(false);
    int CASE = 1;
    int n, k;
    vector<int> p, q;
    cin >> n >> k;
    p.resize(n);
    q.resize(n);
    for (int i = 0; i < n; ++i)
        cin >> p[i];
    for (int i = 0; i < n; ++i)
        q[i] = i + 1;
    if (k == n)
    {
        int start = -1;
        for (int i = 0; i < n; ++i)
        {
            if (q[i] == p[0])
            {
                start = i;
                break;
            }
        }
        bool good = true;
        for (int i = 0; i < n; ++i)
        {
            if (p[i] != q[(i + start) % n])
            {
                good = false;
                break;
            }
        }
        if (good)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    else if (k % 2 == 0)
    {
        int id = index(q, MOD);
        cout << "Yes" << endl;
    }
    else
    {
        if (parity(p) == parity(q))
        {
            int id = index(q, MOD);
            if (index(q, 2) == 1)
                id = (id + MOD - 1) % MOD;
            id = id * 500000004ll % MOD;
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 4652
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
  int A,B,C,X,Y;
  cin >> A >> B >> C >> X >> Y;
  int Ans = 0;
  int minA = min(X,Y);
  if(A+B>=2*C){
    Ans += 2*C*minA;
    X = X - minA;
    Y = Y - minA;
    if(X>0){
      if(A>=2*C){
        Ans += 2*X*C;
      }else{
        Ans += A*X;
      }
    }else{
      if(B>=2*C){
        Ans += 2*Y*C;
      }else{
        Ans += B*Y;
      }
    }
  }else{
    Ans += A*X + B*Y;
  }

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


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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin >> s;
	for (int i=0; i<3; i++) 
		if (s[i]==s[i+1]) {
		cout << "Bad\n";;
		return 0;
	}
	cout << "Good" << endl;
	return 0;
}

Measured memory_bytes: 256