akhauriyash/Code-Regression huggingface dataset:
#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;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const 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[ohara], k, q;
ll f[ohara], fr[ohara], dat[ohara];

ll mod_pow(ll xx, ll nn, ll mod) {
  ll ret = 1;
  while (nn > 0) {
    if (nn & 1) ret = ret * xx % mod;
    xx = xx * xx % mod;
    nn >>= 1;
  }
  return ret;
}

ll ncr(ll nn, ll r) {
  if (nn < r) return 0;
  return f[nn] * fr[r] % MOD * fr[nn - r] % MOD;
}

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

  cin >> n >> k;
  rep(i, n) cin >> a[i];
  sort(a, a + n);
  rep(i, n) sum[i] = a[i];
  rrep(i, 1, n) sum[i] += sum[i - 1];
  f[0] = 1;
  rrep(i, 1, n + 3) { f[i] = f[i - 1] * i % MOD; }
  fr[n + 2] = mod_pow(f[n + 2], MOD - 2, MOD);
  rrrep(i, n + 1, 0) { fr[i] = fr[i + 1] * (i + 1) % MOD; }

  rep(i, n) {
    ll cost = sum[n - 1];
    if (i >= 1) cost -= sum[i - 1];
    cost -= sum[n - i - 1];
    cost %= MOD;
    dat[i] = cost;
  }

  rrep(i, k - 1, n) {
    ll cost;
    cost = ncr(i - 1, k - 2);
    cost *= (dat[i]);
    cost %= MOD;
    ans += cost;
    ans %= MOD;
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 13312
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int a = ni();
        int b = ni();
        int x = ni();

        if(x*2 <= a*a*b){
            double ans = Math.atan((2.0*x)/(a*b*b*1.0));
            out.println(90-ans/Math.PI*180);
        }else{
            double ans = Math.atan(2.0*(a*b-x/(a*1.0))/(a*1.0)/(a*1.0));
            out.println(ans/Math.PI*180);
        }
 
    }

    final int mod = 1000000007;
    final BigInteger MOD = BigInteger.valueOf(mod);
    int upperBound(ArrayList<Long> list, Long target){
        int i = Collections.binarySearch(list, target, new UpperBoundComparator<Long>());
        return ~i;
    }
    class UpperBoundComparator<T extends Comparable<? super T>> implements Comparator<T>{
        public int compare(T x, T y){
            return (x.compareTo(y) > 0) ? 1 : -1;
        }
    }
    int lowerBound(ArrayList<Long> list, Long target){
        int i = Collections.binarySearch(list, target, new LowerBoundComparator<Long>());
        return ~i;
    }
    class LowerBoundComparator<T extends Comparable<? super T>> implements Comparator<T>{
        public int compare(T x, T y){
            return (x.compareTo(y) >= 0) ? 1 : -1;
        }
    }
    int mul(int x, int y){
        int val = (int)((x * 1L * y) % mod);
        return val>=0 ? val : val+mod;
    }
    int add(int x, int y) {
        x += y;
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 33176
# include <algorithm>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <string>
# include <vector>

typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b; cin >> a>> b;
    if (b == 1) {
        cout << 0 << endl;
        return 0;
    }
    int ans = 1;
    b -= a;
    while (b > 0) {
        b-=a-1;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
/**
 * author: BueVonHun 🐼🎋
 * More Info: https://github.com/Bue-von-hon
**/

#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <cstring>
#include <cmath>

typedef long long ll;
using namespace std;

#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
#define mp make_pair
#define pii pair<int,int>
#define piii pair<int,pii>
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
#define X first
#define Y second
#define rep(i, n) for (int i = 0; i < (n); i++)

template <class T> T _min(T a,T b){return (a<b ? a : b);}
template <class T> T _max(T a,T b){return (a>b ? a : b);}
template<class T> void read(T& x) {cin >> x;}

int tc, nm = 2*1e5;
int parent[200000], rnk[200000], sz[200000];
int find(int x) {
    if (x == parent[x]) return x;
    else return parent[x]=find(parent[x]);
}

void merge(int x, int y) {
    x = find(x); y = find(y);
    if (y==x) return;
    if (rnk[x] < rnk[y]) {
        parent[x]=y;
        sz[y]+=sz[x];
    } else {
        parent[y]=x;
        sz[x]+=sz[y];
    }
    if (rnk[x]==rnk[y]) rnk[x]++;
}

int main(void) {
    fast_cin();

    int n, m;
    cin >> n >> m;
    fill(sz, sz+200000,1);
    rep(i, n) {
        parent[i]=i;
    }

    rep(i, m) {
        int x,y;
        cin >> x >> y;
        if (find(x) != find(y)) {merge(x,y);}
    }
    int mx = 0;
    for(int i=1; i<=n; i++) mx = max(mx, sz[find(i)]);
    cout << mx;
    return 0;
}


Measured memory_bytes: 5852
using System;
using System.IO;
using System.Linq;

class Program{
    static void Main(string[] args){
        var arr = Console.ReadLine().Split();
        var N = int.Parse(arr[0]);
        var M = int.Parse(arr[1]);
        var C = int.Parse(arr[2]);
        var B = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var answer = 0;
        for (int i = 1; i <= N; i++){
            var A = Console.ReadLine().Split().Select(int.Parse);
            var sum = 0;
            var j = 0;
            foreach (var a in A){
                sum += a * B[j];
                j++;}
            if (sum + C > 0) answer++;}
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 28352
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> v(h);
    REP(i, h) cin >> v[i];
    REP(i, h) cout << v[i] << endl << v[i] << endl;
    return 0;
}

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

using namespace std;

struct Dsu {
    int n;
    vector<int> p;
    
    Dsu(int _n) { n = _n; p.resize(n); init(); }
    inline void init() {
        for (int i = 0; i < n; i++) {
            p[i] = i;
        }
    }
    inline int find(int x) {
        return p[x] == x ? x: p[x] = find(p[x]);
    }
    inline bool join(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        p[y] = x; return true;
    }
    inline bool check(int x, int y) {
        return find(x) == find(y);
    }
};

using ll=long long ;
void solve() {
    int n,m;
    cin >> n >> m;
    vector<int> a(n), b(n);
    vector<vector<int>> g(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int _ = 0; _ < m; _++) {
        int x,y;
        cin >> x >> y;
        x--;y--;
        g[x].emplace_back(y);
        g[y].emplace_back(x);
    }
    vector<int> id(n);
    iota(id.begin(), id.end(), 0);
    sort(id.begin(), id.end(), [&](int i, int j){
            return a[i]-b[i] < a[j]-b[j];
            });
    Dsu d(n);
    vector<ll> base(n);
    vector<ll> need(n);
    for (int i = 0; i < n; i++) {
        base[i] = b[i];
        need[i] = max(a[i], b[i]);
    }
    vector<bool> trk(n, false);
    for (int u: id) {
        trk[u] = true;
        set<int> s;
        for (int v: g[u]) {
            if (trk[v]) {
                s.insert(d.find(v));
            }
        }
        if (s.empty()) continue;
        for (int v: s) {
            base[u] += base[v];
            d.join(u, v);
        }
        ll leaving_need = max(a[u]-b[u], 0);
        ll optim = 1e18;
        for (int v: s) {
            ll leaving = max(need[v], leaving_need);
            ll before = base[u] - base[v];
            optim = min(optim, leaving + before);
        }
        need[u] = optim;
    }
    ll res = need[d.find(0)];
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 10620
#include<iostream>
//#include<string>
#include<bits/stdc++.h>
using namespace std;
string x,y;
void input()
{
    cin >> x >> y;
}
    void cheack()
    {
        y.pop_back();
        if(x==y)
        {
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
int main()
{
    input();
    cheack();
    return 0;
}


Measured memory_bytes: 3640
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.math.BigInteger; 
public class Main
{
     static Scanner sc=new Scanner(System.in);
    static PrintWriter out=new PrintWriter(System.out);
    static void pn(Object o)
     {
    out.println(o);
    out.flush();
    
    }
    static void p(Object o)
    {
    out.print(o);
    out.flush();
    }
    static void pni(Object o)
    {
    out.println(o);System.out.flush();
    }
        static int I() throws IOException
    { 
    return sc.nextInt();
    }
    static long L()throws IOException
    {
    return sc.nextLong();
    }
    static double D()throws IOException
    {
    return sc.nextDouble();
    }
    static String S()throws IOException
    {
    return sc.next();
        }
     static void process() throws IOException
     {
         String s=S();long k=0;
          for(int i=0;i<s.length();i++)
          {
             k=k+((int)s.charAt(i)-48);
            }
          if(k%9==0)
          {
              pn("Yes");
            }
            else
            {
                pn("No");
            }
        }
        public static void main(String[] args) throws IOException
{
   try
{
        process();
 }
catch(Exception e)
{
return;
}
}
             
         
       }
   

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

class Program
{
    static void Main(string[] args)
    {
        var A = sc.ReadInt();
        var B = sc.ReadInt();
        if (A == 1) A = 14;
        if (B == 1) B = 14;
        if (A > B)
        {
            Console.WriteLine("Alice");
        }
        else if (A < B)
        {
            Console.WriteLine("Bob");
        }
        else
        {
            Console.WriteLine("Draw");
        }
    }

    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<stdio.h>
using namespace std;

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

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    println(problemHitachia(s))
}

fun problemHitachia(s: String): String {
    return when (s) {
        "hi", "hihi", "hihihi", "hihihihi", "hihihihihi" -> "Yes"
        else -> "No"
    }
}

Measured memory_bytes: 31136
N,K = list(map(lambda x:int(x),input().split()))
P = list(map(lambda x:int(x),input().split()))
s = [0]*(len(P)-K+1)
for i in range(len(P)-K+1):
    if i==0:
	    s[i] = sum(P[i:i+K])
    else:
        s[i] = s[i-1]-P[i-1]+P[i+K-1]
    
ans  = max(s)/2. + K/2.
print(ans)

Measured memory_bytes: 24548
/**
*
* Author : MeGa
*
*/
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <string.h>

using namespace std;

int main(){

#ifndef ONLINE_JUDGE
    //freopen("in","r",stdin);
#endif
     ios::sync_with_stdio(false);
     cin.tie(0);
     int n;
     cin>>n;
     vector<int>v(n,0);
     long long sum  = 0;
     for(int i = 0; i < n ; i++){
         cin>>v[i];
         sum+=v[i];
     }
     if(sum % 10){
            cout<<sum<<endl;
            return 0;
     }
        
    long long  best  = -1;
    for(int i = 0 ; i < n; i++){
        if((sum-v[i])%10){
            best = max(best,sum-v[i]);
        }
    }
    if(best!=-1){
        cout<<best<<endl;
    }else{
        cout<<0<<endl;
    }
    

     


    
   

}

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

int main(){
    string s;
    cin >> s;
    int maxLen = 0;
    for(int i = 0; i < s.size(); i++)
    {
        int j = 0;
        while(i + j < s.size()){
            if (s[i + j] == 'A' || s[i + j] == 'C' || s[i + j] == 'G' || s[i + j] == 'T') {
                j++;
            }
            else {
                break;
            }
        }
        maxLen = max(maxLen, j);
    }
    cout << maxLen << "\n";
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

  static int a;

  public static void main(String[] args) throws Exception {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(System.out);

    String[] in = br.readLine().split(" ");
    a = Integer.parseInt(in[0]);

    br.close();

    out.println(a + a*a + a*a*a);

    out.flush();

  }
}

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

long long N, A, B;
int X[100000];

int main() {
  cin >> N >> A >> B;
  for (int i=0; i<N; i++) {
    cin >> X[i];
  }
  long long d = 0;
  for (int i=1; i<N; i++) {
    d += min(B, A*(X[i]-X[i-1]));
  }
  cout << d << "\n";
  return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main (){
int i,j,k;

scanf ("%d %d %d",&i,&j,&k);

if (i==1&&j==0&&k==0){
printf ("Close\n");
}

else if (i==0&&j==1&&k==0){
printf ("Close\n");
}

else if (i==1&&j==1&&k==0){
printf ("Open\n");
}

else if (i==0&&j==0&&k==1){
printf ("Open\n");
}

else if (i==0&&j==0&&k==0){
printf ("Close\n");
}

return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define INF 1e9
typedef long long ll;
typedef struct{
  int n_q,bonus,point;
}T;

int main(void){
  int D,G;cin >> D >> G; 
  G/=100;
  vector<T> v(D);
  int i,j,k;REP(i,D){
    cin >> v[i].n_q >> v[i].bonus;
    v[i].bonus/=100;
    v[i].point = (i+1);
  }
  //dp[i][j]:i点付けられた問題までを見て合計がjとなる最小の問題数
  int dp[D+1][G+1];
  REP(i,D+1)REP(j,G+1)dp[i][j] = INF;
  REP(i,D+1)dp[i][0] = 0;
  REP(i,D)REP(j,G){
    int point = j;
    dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
    REP(k,v[i].n_q){
      point += v[i].point;
      if(k==v[i].n_q-1) point += v[i].bonus;
      point = min(point,G);
      dp[i+1][point] = min(dp[i+1][point],dp[i][j]+k+1);
      if(point==G) break;
    }
  }
  int ans=INF;
  REP(i,D+1) ans=min(ans,dp[i][G]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4736
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	long long a, b, e = 0;
	cin >> a;
	for (int h = 1; h <= a; h++) {
		cin >> b;
		if (b % 2 == 1) {
			e++;
		}
	}
	if (e % 2 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	cin >> e;
}

Measured memory_bytes: 256
n = int(input())
ans = [0]*10005
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            s = x*x + y*y + z*z + x*y + y*z + z*x
            if s <= n:
                ans[s] += 1

for i in range(1, n+1):
    print(ans[i])


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

int main(){
    string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) == b.at(0) && b.at(b.size() -1) == c.at(0)) {
cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
  

}


Measured memory_bytes: 256
a,b=map(int,input().split())
i=1
ans=0
while 2**(i-1)<=b:
  if i==1:
    d=(b-a+1)//2
    if a%2==b%2==1:
      d+=1
    ans+=d%2    
  else:
    x=a%(2**i)
    y=b%(2**i)
    d1=min(2**(i-1),2**i-x)
    d2=max(y-2**(i-1)+1,0)
    if (d1+d2)%2==1:
      ans+=2**(i-1)
  i+=1
print(ans)

Measured memory_bytes: 38468
#![allow(clippy::needless_range_loop)]
#![allow(unused_macros)]
#![allow(dead_code)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: chars,
    }
    let modded = s
        .iter()
        .rev()
        .map(|x| (*x as u8 - b'0') as usize)
        .scan((1, 0), |state, x| {
            let (exp_10, last) = *state;
            let res = (x * exp_10 + last) % 2019;
            *state = (exp_10 * 10 % 2019, res);
            Some(res)
        })
        .collect::<Vec<_>>();
    let mut cnt = vec![0isize; 2019];
    cnt[0] = 1;
    for modl in modded.iter() {
        cnt[*modl] += 1;
    }
    let ans: isize = cnt.iter().map(|x| x * (x - 1) / 2).sum();
    println!("{}", ans);
}


Measured memory_bytes: 4940
//include
//------------------------------------------
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;

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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//debug
//-------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
vector<int> intersection[103];

int search() {
    int odd = 0;
    if (intersection[1].size() % 2 != 1 || intersection[2].size() % 2 != 1) {
        return 0;
    }
    FOR(i, 3, 103) {
        if (intersection[i].size() % 2 == 1) {
            return 0;
        }
    }
    return 1;
}

void init() {
    REP(i, 103) {
        intersection[i].clear();
        intersection[i].shrink_to_fit();
    }
}

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

    while(1) {
        int s, d;
        cin >> s >> d;
        if (cin.eof()) break;

        intersection[s].push_back(d);
        intersection[d].push_back(s);

        if (!s && !d) {
            if(search()) {
                cout << "OK" << endl;
            } else {
                cout << "NG" << endl;
            }
            init();
        }
    }

    return 0;
}

Measured memory_bytes: 3148
a,b=map(int,input().split())
cnt=1
if abs(a-b)<=1:
    print('Brown')
else:
    print('Alice')


# if b>a:
#     a,b=b,a
# a=a-b
# b=0
# mod_a=a%3
# if a==3:
#     print('Alice')
# elif mod_a==2:
#     print('Alice')
# elif mod_a==1:
#     print('Brown')
# elif (mod_a==0)and(a!=3):
#     print('Brown')
# if (mod_a==3)and(mod_b==3):
#     print('Alice')
# elif (mod_a==3)and(mod_b==1):
#     print('Alice')
# elif (mod_a==1)and(mod_b==3):
#     print('Alice')
# elif (mod_a==2)and(mod_b==0):
#     print('Alice')    
# elif (mod_a==0)and(mod_b==2):
#     print('Alice')
# else:
#     print('Brown')

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

def par(a):
    if P[a] < 0: return a
    t = par(P[a])
    P[a] = t
    return t
def unite(a, b):
    if par(a) == par(b): return 0
    C[par(a)], C[par(b)] = C[par(a)] + C[par(b)], C[par(a)] + C[par(b)]
    if P[par(b)] == P[par(a)]:
        P[par(b)] = par(a)
        P[par(a)] -= 1
    elif P[par(b)] > P[par(a)]:
        P[par(b)] = par(a)
    else:
        P[par(a)] = par(b)
N, H, W = map(int, input().split())
P = [-1 for i in range(H+W)]
C = [1] * (H+W)
X = []
for _ in range(N):
    r, c, a = map(int, input().split())
    X.append((a, r-1, c+H-1))
X = sorted(X)
ans = 0
while X:
    a, r, c = X.pop()
    unite(r, c)
    if C[par(r)]:
        ans += a
        C[par(r)] -= 1
print(ans)

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

int binary_search(int S[], int T, int min, int max)
{
    if (min > max) return -1;
    int target = (min + max) / 2;
    if (T == S[target]) return target;
    if (T > S[target]) return binary_search(S, T, target + 1, max);
    return binary_search(S, T, min, target - 1);
}
int main()
{
    int n;
    cin >> n;
    int S[n];
    for (int i = 0; i < n; i++) {
        cin >> S[i];
    }
    int q;
    cin >> q;
    int C = 0;
    for (int i = 0; i < q; i++) {
        int T;
        cin >> T;
        if (binary_search(S, T, 0, n - 1) != -1) {
            C++;
        }
    }
   cout << C << endl;
    return 0;
}

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

const int MAXN = 1E5+2;

vector<pair<int, int> > g[MAXN];
vector<int> col(MAXN, 0);
int n, m;

void dfs(int u, int p, int color){
	int cur = 1;
	for(pair<int, int> v: g[u]){
		if(v.first==p) continue;
		if(cur == color) ++cur;
		col[v.second] = cur;
		dfs(v.first, u, cur);
		++cur;
	}
}

signed main(){
	cin >> n;
	for(int i=1; i< n; ++i){
		int u, v; cin >> u >> v;
		g[u].push_back({v, i});
		g[v].push_back({u, i});
	}
	int ans = 0;
	for(int i=1; i<= n; ++i) ans = max(ans, (int)g[i].size());
	dfs(1, 0, 0);
	cout << ans << "\n";
	for(int i=1; i< n; ++i){
		cout << col[i] << "\n";
	}
}

Measured memory_bytes: 9472
use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;
use std::thread;

fn exec() {
    let mut sc = Scanner::new();
    let n: usize = sc.ne();
    let a: Vec<i64> = (0..n).map(|_| sc.ne()).collect();
    fn solve(mut a: Vec<i64>) -> bool {
        let sum = a.iter().fold(0, |acc, &x| acc + x - 1);
        if sum & 1 == 1 {
            return true;
        }
        let cnt_odd = a.iter().fold(0, |cnt, &x| (x & 1) + cnt);
        if cnt_odd > 1 {
            return false;
        }
        let oddi = a.iter().position(|&x| x & 1 == 1).unwrap();
        if a[oddi] == 1 {
            return false;
        }
        a[oddi] -= 1;
        let gcd = a.iter().fold(0, |l, &r| __gcd(l, r));
        a = a.iter().map(|&x| x / gcd).collect();
        !solve(a)
    }
    println!("{}", if n > 1 && solve(a) { "First" } else { "Second" });
}

fn __gcd(a: i64, b: i64) -> i64 {
    match b {
        0 => a,
        _ => __gcd(b, a % b),
    }
}

const DEFAULT_STACK: usize = 16 * 1024 * 1024;
fn main() {
    let builder = thread::Builder::new();
    let th = builder.stack_size(DEFAULT_STACK);
    let handle = th.spawn(|| { exec(); }).unwrap();
    let _ = handle.join();
}

#[allow(dead_code)]
struct Scanner {
    stdin: Stdin,
    id: usize,
    buf: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.stdin.read_line(&mut res) {
            Ok(0) => return None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.len() == 0 {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert!(self.buf[l] != b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => panic!("parse error"),
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}


Measured memory_bytes: 4860
import numpy as np

n = int(input())
w = []
for i in range(n):
    w.append(input())
result = 'Yes'

l = len(w)
w_ = list(set(w))
l_ = len(w_)

if l != l_:
    result='No'

for i in range(n-1):
    if w[i][-1] != w[i+1][0]:
        result = 'No'

print(result)

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

int main(){
  ll n,j=1,l=0,s=0;
  cin >> n;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
  }
  if(n<=2)
    s++;
  else{ 
  while(j<n-1){
    if(a[l]<a[l+1]){
      if(a[j]<=a[j+1]){
        j++;
        continue;
      }else if(a[j]>a[j+1]){
        l=j+1;
        j+=2;
        s++;
      }
    }else if(a[l]>a[l+1]){
      if(a[j]>=a[j+1]){
        j++;
        continue;
      }else if(a[j]<a[j+1]){
        l=j+1;
        j+=2;
        s++;
      }
    }else{
      l++;
      j++;
    }
  }
  s++;
  }
  cout << s;
}

Measured memory_bytes: 1024
#include<set>
#include<queue>
#include<cstdio>

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

using namespace std;

typedef long long ll;

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

ll to_ll(const int a[4][4]){
	ll res=0;
	rep(i,4) rep(j,4) res|=(ll)a[i][j]<<3*(i*4+j);
	return res;
}

void burst(const int a[4][4],int b[4][4]){
	rep(i,4) rep(j,4) b[i][j]=a[i][j];

	bool drop[4][4][4]={};
	while(1){
		bool next[4][4][4]={};
		rep(k,4) rep(i,4) rep(j,4) if(drop[k][i][j]) {
			int y=i+dy[k],x=j+dx[k];
			if(0<=y && y<4 && 0<=x && x<4){
				if(b[y][x]==0){
					next[k][y][x]=true;
				}
				else{
					b[y][x]++;
				}
			}
		}

		bool end=true;
		rep(i,4) rep(j,4) if(b[i][j]>=5) {
			end=false;
			b[i][j]=0;
			rep(k,4) next[k][i][j]=true;
		}
		rep(k,4) rep(i,4) rep(j,4) {
			drop[k][i][j]=next[k][i][j];
			if(next[k][i][j]) end=false;
		}
		if(end) return;
	}
}

int main(){
	ll S0=0;
	rep(i,16){
		int a; scanf("%d",&a);
		S0|=(ll)a<<3*i;
	}

	int ans=-1;
	set<ll> memo;
	memo.insert(S0);
	queue< pair<int,ll> > Q; Q.push(make_pair(0,S0));
	while(!Q.empty()){
		int c=Q.front().first;
		ll S=Q.front().second; Q.pop();

		if(c>5) break;
		if(S==0){ ans=c; break; }

		int a[4][4];
		rep(i,4) rep(j,4) a[i][j]=(S>>3*(i*4+j))&7;

		rep(i,4) rep(j,4) {
			a[i][j]++;

			int a2[4][4];
			burst(a,a2);
			ll S2=to_ll(a2);

			if(memo.count(S2)==0){
				memo.insert(S2);
				Q.push(make_pair(c+1,S2));
			}

			a[i][j]--;
		}
	}

	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 14312
n=int(input())
h=[int(i) for i in input().split()]
p0=0
p1=abs(h[1]-h[0])
for i in range(2,n):
    p2=min(abs(h[i]-h[i-2])+p0,abs(h[i]-h[i-1])+p1)
    p0,p1=p1,p2
print(p1)

Measured memory_bytes: 13800
# -*- coding: utf-8 -*-


def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    ans = 0

    for i in range(1, n + 1):
        if i % 15 == 0:
            pass
        elif i % 5 == 0:
            pass
        elif i % 3 == 0:
            pass
        else:
            ans += i

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9088
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int right = 0, left = 0;
        int N = s.nextInt();
        String str = s.next();
        char[] cstr = str.toCharArray();
        for(int i = 0; i < N; i++){
            if(cstr[i] == ')'){
                if(left > 0){
                    left--;
                }else
                    right++;
            } else {
                left++;
            }
        }
        String ans = "";
        for(int i = 0; i < right; i++)
            ans = ans + "(";
        ans = ans + str;
        for(int i = 0; i < left; i++)
            ans = ans + ")";
        System.out.println(ans);
    }
}


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

int gcd(int x,int y){
    if(x<y)swap(x,y);
    while(y){
        int r=x%y;
        x=y;
        y=r;
        if(x<y)swap(x,y);
    }
    return x;
}

int main(){
    int a,b;
    cin>>a>>b;
    cout<<gcd(a,b)<<endl;
    return 0;
}


Measured memory_bytes: 3100
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
AC=[False]*n
WA=[0]*n
for _ in range(m):
    p,s=input().split()
    p=int(p)-1
    if s=='AC':
        AC[p]=True
    else:
        if AC[p]:
            continue
        WA[p]+=1
ac=0
wa=0
for i in range(n):
    if AC[i]:
        ac+=1
        wa+=WA[i]
print(ac,wa)

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

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

int main(){
    int N, T;
    cin >> N >> T;
    vector<int> t(N);
    rep(i, N) cin >> t[i];

    ll x = 0, time = 0;
    rep(i, N-1){
        if(t[i+1] < t[i] + T){
            x += t[i+1] - t[i];
        }else{
            x += T;
        }
    }
    x += T;

    cout << x << endl;

    return 0;
}

Measured memory_bytes: 1024
#多めのピザができてもOK
a,b,c,x,y=map(int,input().split())
if a+b<=2*c:
    print(x*a+y*b)
else:
    if x<=y:
        print(min(2*x*c+(y-x)*b,2*y*c))
    else:
        print(min(2*y*c+(x-y)*a,2*x*c))


Measured memory_bytes: 38256
#include <stdio.h>

int main(void){
    int n,s,i,line[20000],ans,sum,o;
    for(;ans=0,scanf("%d %d",&n,&s),n+s;){
        for(i=0;i<n;i++)
            scanf("%d",&line[i]);
        for(i=0;i<n-1;i++)
            for(o=i+1;sum=0,o<n;o++){
                sum+=line[i]+line[o];
                if(sum > s)
                    ans++;
            }
        printf("%d\n",ans);
    }
    return 0;
}

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

int insertion_sort(vector<int> &A, int n, int g) {
  int cnt = 0;

  for (int i = g; i < n; i++) {
    int v = A.at(i);
    int j = i - g;

    while (j >= 0 && A.at(j) > v) {
      A.at(j+g) = A.at(j);
      j = j-g;
      cnt++;
    }

    A.at(j+g) = v;
  }

  return cnt;
}

void shell_sort(vector<int> A, int n) {
  vector<int> G;
  int g = 1;
  // n=1 の配列についても、g=1 で通常の挿入ソートを行うように、必ず G[0]=1 がセットされるようにする
  //
  // NOTE: (g < n) の条件のみだと、1<1 という判定で G[0]=1 がセットされなくなる
  while (g == 1 || g < n) {
    G.push_back(g);
    g = 3 * g + 1;
  }

  // 1行目 : 整数m
  int m = (int) G.size();
  cout << m << endl;

  // 2行目 : m個の整数Gi
  // 1, 4, 13, ... という数列を ..., 13, 4, 1 に並べ替える
  sort(G.rbegin(), G.rend());
  for (int i = 0; i < m; i++) {
    if (i > 0) { cout << " "; }
    cout << G.at(i);
  }
  cout << endl;

  int cnt = 0;
  for (int i = 0; i < m; i++) {
    cnt += insertion_sort(A, n, G.at(i));
  }

  // 3行目 : Gを用いた場合のプログラムが終了した直後のcnt
  cout << cnt << endl;

  // 4行目 : ソート後のA
  for (int i = 0; i < n; i++) {
    cout << A.at(i) << endl;
  }
}

int main() {
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A.at(i);
  }

  shell_sort(A, n);
  return 0;
}



Measured memory_bytes: 10736
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def prime_factorization(n):
    res = []
    for i in range(2, int(pow(n, 0.5)) + 1):
        if n % i == 0:
            ex = 0
            while n % i == 0:
                ex += 1
                n //= i
            res.append(ex)
    if n != 1:
        res.append(1)
    return res


def resolve():
    n = int(input())
    div = prime_factorization(n)

    res = 0
    for ex in div:
        i = 1
        while ex > 0:
            ex -= i
            if ex < 0:
                break
            i += 1
            res += 1
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9468
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define sz(a) (int)((a).size())
#define NoType ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair

typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//find_by_order(x) -> returns an iterator to the element at a given position
//order_of_key(x) -> returns the position of a given element

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;

const int mod = (int)1e9 + 7;
const int MAXN = 1e5+12;
//indexed_set s;

string s,t;

int main() {

    cin >> s >> t;
    vector<string>v;
    for (int i = 0; i < s.size(); i++) {
        if (i + sz(t) > sz(s)) break;
        string cur="";
        for (int j = i; j < i + sz(t); j++) {
            cur.pb(s[j]);
        }
        v.pb(cur);
    }
    int mn = MAXN;
    for (int i = 0; i < v.size(); i++) {
        int cnt=0;
        for (int j = 0; j < v[i].size(); j++) {
            if (v[i][j] != t[j]) cnt++;
        }
        mn = min(mn, cnt);
    }

    cout << mn;

return 0;
}


Measured memory_bytes: 3792
d=int(input())
c=list(map(int,input().split()))
c_days=[0]*26

fir_ans=0
for i in range(d):
    s=list(map(int,input().split()))
    ss=sorted(s, reverse=False)
    for k in range(26):
        num=ss[k]
        n=s.index(num)
        if c_days[n]==0:

            fir_ans+=num
            continue 
    c_days[n]=i+1
    print(n+1)
    '''
    for l in range(26):
        los=c[l]*(i+1-c_days[l])
        fir_ans-=los
    print(fir_ans)
    '''


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

using namespace std;

#define int long long
#define fr(i, n) for(int i=0;i<n;i++)
#define frr(i, n) for(int i=n;i>=0;i--)
#define fra(i, a, n) for(int i=a;i<n;i++)
#define frra(i, a, n) for(int i=a;i>=n;i--)
#define f(i, a) for(auto &i:a)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define ff first
#define ss second
#define endl '\n'

typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef set<int> si;
typedef unordered_map<int, int> uii;
typedef unordered_set<int> usi;

const int mod = 1e9 + 7;
const int MAXN = 2e5 + 5;
const int inf = LONG_LONG_MAX;
const double eps = 1e-9;
const double pi = 3.14159265358979323;

int power(int x, int y) {
    int res = 1;
    while (y) {
        if (y & 1)res = (res * x) % mod;
        x = (x * x) % mod;
        y >>= 1;
    }
    return res;
}

void solve() {
    //CODE BEGIN
    int n;
    cin >> n;
    vi a(n);
    fr(i, n)cin >> a[i];
    vi dp(n);
    dp[1] = a[1] - a[0];
    fra(i, 1, n)dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
    cout << dp[n - 1] << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int test = 1;
//    cin >> test;
    for (int i = 0; i < test; ++i) {
//        cout << "Case #" << i + 1 << ": ";
        solve();
    }
    return 0;
}


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

using namespace std;

int main()
{
  int N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<int> l(N);
  for (int i = 0; i < N; i++)
    cin >> l[i];
  int ans = 1e9;
  for (int a = 0; a < (1 << N); a++)
    for (int b = 0; a + b < (1 << N); b++)
    {
      int tmp = 0;
      vector<int> stick[3], cost(3, (int)1e5);
      vector<pair<int, int>> change[3];
      for (int i = 0; i < N; i++)
        if (a & (1 << i))
          stick[0].push_back(l[i]);
        else if (b & (1 << i))
          stick[1].push_back(l[i]);
        else
          stick[2].push_back(l[i]);
      for (int i = 0; i < 3; i++)
        for (int j = 0; j < (1 << stick[i].size()); j++)
          if (j != 0)
          {
            int tmp = 0, cost = -1;
            for (int k = 0; k < stick[i].size(); k++)
              if (j & (1 << k))
              {
                cost++;
                tmp += stick[i][k];
              }
            change[i].push_back({cost * 10, tmp});
          }
      if (change[0].size() == 0 || change[1].size() == 0 || change[2].size() == 0)
        continue;
      for (pair<int, int> t : change[0])
        cost[0] = min(cost[0], abs(t.second - A) + t.first);
      for (pair<int, int> t : change[1])
        cost[1] = min(cost[1], abs(t.second - B) + t.first);
      for (pair<int, int> t : change[2])
        cost[2] = min(cost[2], abs(t.second - C) + t.first);
      ans = min(ans, cost[0] + cost[1] + cost[2]);
    }
  cout << ans << endl;

  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;

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

    int n;
    cin >> n;

    vector<int> a(n + 1);
    REP(i, n + 1) cin >> a[i];

    vector<int> b(n);
    REP(i, n) cin >> b[i];

    ll ans = 0;
    REP(i, n) {
        ans += min(a[i], b[i]);
        if (b[i] - a[i] > 0) {
            int margin = min(b[i] - a[i], a[i + 1]);
            ans += margin;
            a[i + 1] = max(a[i + 1] - margin, 0);
        }
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>
#include <list>
#include <queue>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int gcd(int a, int b) {
  if(b <= 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

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

  int N,X; cin>>N>>X;
  vector<int> cities(N);
  for(int i=0; i<N; i++) {
    int x; cin>>x;
    cities[i] = x;
  }
  sort(cities.begin(), cities.end());

  int D = abs(X - cities[0]);
  for(int i=1; i<N; i++) {
    D = gcd(D, abs(X - cities[i]));
  }

  cout << D << endl;
}


Measured memory_bytes: 640
# coding: utf-8

import sys
import math
import collections
import itertools
from inspect import currentframe
INF = 10 ** 10
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def MI() : return map(int, input().split())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def chkprint(*args) : names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}; print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

N = I()

print(math.ceil(N / 2))


Measured memory_bytes: 43504
#include<bits/stdc++.h>
#define ll long long int
#define ff first
#define ss second
#define eps 1e-9

using namespace std;

int main()
{

    ll t,n,m,f,a,b,c,l,r,q,k,x,y,z,ans,mn,mx,sum=0;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    map<string,ll> mp;
    string exp;
    cin>>n;

    mx = 0;
    for(int i=0;i<n;i++)
    {
        cin>>exp;
        mp[exp]++;
        mx = max(mp[exp],mx);
    }

    for(auto it= mp.begin();it!=mp.end();it++)
    {
        if(it->second == mx)
        {
            cout<<it->first<<endl;
        }
    }




}


Measured memory_bytes: 19172
S = input().strip()
Q = int(input())
queries = []
for _ in range(Q):
  q = input().split()
  queries.append(q)

flip = False
s_0 = ''
s_n = ''
for q in queries:
  if q[0] == '1':
    flip = not flip
  else:
    if (q[1] == '1' and not flip) or (q[1] == '2' and flip):
      s_0 += q[2]
    else:
      s_n += q[2]
if flip:
  print(s_n[::-1] + S[::-1] + s_0)
else:
  print(s_0[::-1] + S + s_n)

Measured memory_bytes: 40436
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: print('Yes' if b else 'No')
YESNO=lambda b: print('YES' if b else 'NO')

def main():
    N=int(input())
    A=list(map(int,input().split()))
    dp=[[-INF]*3 for _ in range(N+10)]
    dp[0][0]=0
    for i in range(N+1):
        for j in range(3):
            if j+1<3:
                dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j])
            if i<N:
                dp[i+2][j]=max(dp[i+2][j],dp[i][j]+A[i])
    if N%2:
        print(dp[N+1][2])
    else:
        print(dp[N+1][1])
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 115040