akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>


struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)
    x=x->left;
  return x;

}
Node treeMaximum(Node x){
  while(x->right!=NIL)
    x=x->right;
  return x;

}


Node treeSearch(Node u, int k){
  while(u!=NIL&&k!=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right!=NIL)return treeMinimum(x->right);
  y=x->parent;
   while(y!=NIL&&x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL||z->right==NIL)y=z;
  else y=treeSuccessor(z);

  if(y->left!=NIL){
    x=y->left;
  }else{
    x=y->right;
  }

  if(x!=NIL){
    x->parent=y->parent;
  }

  if(y->parent==NIL){
    root=x;
  }else{
    if(y==y->parent->left){
      y->parent->left=x;
    }else{
      y->parent->right=x;
    }
  }

  if(y!=z){
    z->key=y->key;
  }
  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }else{
      x=x->right;
    }
  }
  z->parent = y;
  if(y==NIL){
    root=z;
  }else{
    if(z->key < y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}

void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



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

int main(){
  int N;
  cin >> N;
  int a[N];
  for(int i = 0; i < N; i++) cin >> a[i];

  int max_fm = 0;
  for(int i = 0; i < N; i++){
    max_fm += a[i] - 1;
  }

  cout << max_fm << endl;

  return 0;
}

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

int main(void)
{
    long long int a,b,c=0,i,j,k,n;

    cin >> a >> b;
    if(a>b) c+=a--;
    else c+=b--;
    if(a>b) c+=a--;
    else c+=b--;
    cout << c;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  if(n==1000||n==1110||n==1111||n==1112||n==1113||n==1114||n==1115||n==1116||n==1117||n==1118||n==1119||n==1222||n==1333||n==1444||n==1555||n==1666||n==1777||n==1888||n==1999||n==2000||n==2111||n==2220||n==2221||n==2222||n==2223||n==2224||n==2225||n==2226||n==2227||n==2228||n==2229||n==2333||n==2444||n==2555||n==2666||n==2777||n==2888||n==2999||n==3000||n==3111||n==3222||n==3330||n==3331||n==3332||n==3333||n==3334||n==3335||n==3336||n==3337||n==3338||n==3339||n==3444||n==3555||n==3666||n==3777||n==3888||n==3999||n==4000||n==4111||n==4222||n==4333||n==4440||n==4441||n==4442||n==4443||n==4444||n==4445||n==4446||n==4447||n==4448||n==4449||n==4555||n==4666||n==4777||n==4888||n==4999||n==5000||n==5111||n==5222||n==5333||n==5444||n==5550||n==5551||n==5552||n==5553||n==5554||n==5555||n==5556||n==5557||n==5558||n==5559||n==5666||n==5777||n==5888||n==5999||n==6000||n==6111||n==6222||n==6333||n==6444||n==6555||n==6660||n==6661||n==6662||n==6663||n==6664||n==6665||n==6666||n==6667||n==6668||n==6669||n==6777||n==6888||n==6999||n==7000||n==7111||n==7222||n==7333||n==7444||n==7555||n==7666||n==7770||n==7771||n==7772||n==7773||n==7774||n==7775||n==7776||n==7777||n==7778||n==7779||n==7888||n==7999||n==8000||n==8111||n==8222||n==8333||n==8444||n==8555||n==8666||n==8777||n==8880||n==8881||n==8882||n==8883||n==8884||n==8885||n==8886||n==8887||n==8888||n==8889||n==8999||n==9000||n==9111||n==9222||n==9333||n==9444||n==9555||n==9666||n==9777||n==9888||n==9990||n==9991||n==9992||n==9993||n==9994||n==9995||n==9996||n==9997||n==9998||n==9999) printf("Yes");
  else printf("No");
  return 0;
}

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

using namespace std;

int main()
{   int N;
    cin>>N;
    if(N==1){
        cout<<"Hello World"<<endl;
    }else if(N==2){
        int A,B;
        cin>>A>>B;
        cout<<A+B<<endl;
    }
    return 0;

}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}
fn main() {
    let _n = get!(usize);
    let v = get!([usize]);
    let mut ans = 0;
    for i in v.iter() {
        ans += *i - 1;
    }
    println!("{}", ans);
}


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

using namespace std;

int main()
{

    int x,y;
    cin>>x>>y;
    if(x==y)
    {
        while(x--)
        {
            cout<<y;
        }
    }
    else
    {
        int mi = min(x,y);
        int ma = max(x,y);
        while(ma--)
        {
            cout<<mi;
        }
    }
    
    
    return 0;
}

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

#define vec(v) vector<int>(v)
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define mapci(mp) map<char*,int>(mp)
#define mapcc(mp) map<char*,char*>(mp)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll q,h,s,d,n,m,ans=0;
    cin>>q>>h>>s>>d>>n;
    n*=4;
    m=n%8;
    m=n-m;
    ans+=min(min(min(q*8,h*4),s*2),d)*m/8;
    n-=m;
    m=n%4;
    m=n-m;
    ans+=min(min(q*4,h*2),s)*m/4;
    n-=m;
    m=n%2;
    m=n-m;
    ans+=min(q*2,h)*m/2;
    n-=m;
    ans+=q*n;
    cout <<ans<<endl;
    return 0;
}


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

string shuffle(string str, int h){
string head=str.substr(0,h);
string tail=str.substr(h,str.size()-h);
return tail+head;
}

int main(){
string Input;
int m,H;
while(1){
cin >>Input;
if(Input=="-") break;
cin >>m;
for(int i=0;i<m;i++){
cin >>H;
Input=shuffle(Input,H);
}
cout <<Input <<endl;
}
return 0;
}

Measured memory_bytes: 3216
#include  <bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
int main(){
  int aa,ah,ta,th;
  cin>>th>>ta;
  cin>>ah>>aa;
  bool turn=true;
  while(true){  
    if(turn){
      if(ah-ta<=0){
        cout<<"Yes"<<"\n";  
        break;
      }
      else{
        ah-=ta;
      }
    }
    else{
        if(th-aa<=0){
          cout<<"No"<<"\n";
          break;  
        }
        else{
          th-=aa;
        }
    }
    turn=!turn;
  }
  return 0;
}

Measured memory_bytes: 3604
#include <iostream>

using namespace std;

int main() {
	int m;            // データセット数
	int n;            // 運用方法の種類数
	int max;          // 最終資金の最大値
	int init_money;   // 初期運用資金量
	int year;         // 運用年数
	int method;       // 運用方法 (0 = 単利, 1 = 複利)
	double rate;      // 年利率
	int commission;   // 毎年の手数料
	int final_money;  // 最終資金
	int sum_interest; // 利子累計
	
	//cout << "データセットの数: " << endl;
	cin >> m;
	for (int i = 0; i < m; i++) {
		max = 0;
		//cout << "初期運用資金量: " << endl;
		cin >> init_money;
		//cout << "運用年数: " << endl;
		cin >> year;
		//cout << "運用方法の種類数: " << endl;
		cin >> n;
		for (int j = 0; j < n; j++) {
			//cout << "単利or複利 年利率 毎年の手数料: " << endl;
			cin >> method >> rate >> commission;
			final_money = init_money;
			if (method == 1) {
				for (int k = 0; k < year; k++) {
					final_money =  static_cast<int> (final_money * (1 + rate)) - commission;
					//cout << final_money << endl;
				}
			} else {
				sum_interest = 0;
				for (int k = 0; k < year; k++) {
					sum_interest += static_cast<int> (final_money * rate);
					final_money -= commission;
				}
				final_money += sum_interest;
			}
			if (final_money > max) {
				max = final_money;
			}
		}
		cout << max << endl;
	}

	return 0;
}

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

int MOD = 1e9 + 7;
int n;
long long ans, a[500000];
long long deg[500000];
long long k[500000];

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	int r = 1;
	for (int i = 0; i < n; i++) deg[i] = r, r = 2 * r % MOD;
	deg[n] = r;
	for (int i = 0; i < n; i++) a[i] = a[i] * r % MOD;
	k[0] = 1;
	for (int i = 1; i < n; i++)
	{
		k[i] = (k[i - 1] * 2 + deg[i - 1]) % MOD;
	}
	for (int i = 0; i < n; i++)
	{
		ans = (ans + a[i] * deg[i] % MOD * k[n - i - 1]) % MOD;
	}
	cout << ans;
}

Measured memory_bytes: 9984
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define all(v)    ((v.begin()),(v.end()))
#define sz(v)     ((int)(v.size()))
#define forv(i, v) for(int i = 0; i < sz(v); ++i)
#define forn(i,n)   for(int i = 0; i < (int)(n); i++)
using namespace std;

typedef long long       ll;
typedef long double     ld;
typedef vector<int>     vi;
typedef vector<double>  vd;
typedef vector< vi >    vii;
typedef vector< vd >    vdd;
typedef vector<string>  vs;


int main()
{
	string a;
	vector<char>x, y;
	cin >> a;
	//cout << a;
	int q;
	scanf("%d", &q);
	bool r = true;
	while (q--) {
		int t;
		scanf("%d", &t);
		if (t == 1) r = !r;
		else {
			int f;
			scanf("%d", &f);
			char c;
			cin >> c;
			//cout << c;
			if (r) {
				if (f == 1) x.push_back(c);
				else y.push_back(c);
			}
			else {
				if (f == 1) y.push_back(c);
				else x.push_back(c);
			}
		}
	}
	if (r) {
		for (int i = x.size() - 1; i >= 0; i--) cout << x[i];
		cout << a;
		for (int i = 0; i < y.size(); i++) cout << y[i];
	}

	else {
		for (int i = y.size() - 1; i >=  0; i--) cout << y[i];
		for (int i = a.size() - 1; i >= 0; i--) cout << a[i];
		for (int i = 0; i < x.size(); i++ ) cout << x[i];
	}

	cout << "\n";
	return 0;
}


Measured memory_bytes: 1024
import std;

alias Book = Tuple!(int, "cost", int[], "ss");

int calc(int x, Book[] books) {
    auto n = books.length;
    auto m = books[0].ss.length;

    int ans = int.max;
    for (int i = 0; i < (1 << n); i++) {
        int cost = 0;
        auto ss = new int[m];
        for (int j = 0; j < n; j++) {
            if (i & (1 << j)) {
                cost += books[j].cost;
                foreach (k, s; books[j].ss) {
                    ss[k] += s;
                }
            }
        }

        if (ss.all!(e => e >= x)) {
            ans = min(ans, cost);
        }
    }
    return ans == int.max ? -1 : ans;
}

void main() {
    int n, m, x; scan(n, m, x);
    Book[] books;
    foreach (_; 0..n) {
        auto t = readints;
        books ~= Book(t[0], t[1..$]);
    }
    writeln(calc(x, books));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T=string)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readints = reads!int;


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


def prime_numbers(n):
    """
    n以下の素数列挙
    O(n)
    """
    eratosthenes = [2] * (n + 1)
    eratosthenes[1] = 1
    num_sum = 1
    for i in range(2, n // 2 + 1):
        k = 2
        while True:
            if i * k < n + 1:
                eratosthenes[i * k] += 1
                k += 1
            else:
                break

    return eratosthenes, num_sum


eratos, num_sum = prime_numbers(N)
ans = 0
for i in range(N):
    ans += eratos[i+1]*(i+1)
print(ans)

Measured memory_bytes: 145632
#include <stdio.h>

    int main()      /*this code is written by 190042146*/
{
    int n, m;

    scanf("%d%d", &n, &m);

    int i, ara[m];
    long long int sum=0;

    for (i=0;i<m;i++)
    {
        scanf("%d", &ara[i]);
    }

    for (i=0;i<m;i++)
    {
        sum=sum+ara[i];
    }

    if (sum>n)
    {
        printf("-1");
    }

    else
    {
        printf("%d",n-sum);
    }


    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll x, n;
    cin >> x >> n;
    vl p(n);
    cin >> p;
    map<ll, ll> mp;
    each(e, p) mp[e]++;
    ll ans = ll_inf;
    ll diff = ll_inf;
    rep(i, x * 2) {
        if (mp[i] > 0) continue;
        if (abs(x - i) < diff) {
            diff = abs(x - i);
            ans = i;
        }
        if (abs(x - i) == diff) {
            ans = min(ans, i);
        }
    }
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}


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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'

int n;
signed main()
{
    cin >> n;
    int res = 0;
    REP(i, n+1){
        if (i % 3 == 0 || i % 5 == 0) continue;
        res+=i;
    }
    cout << res << endl;
    return 0;

}

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

namespace ABC142C
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var res = new Dictionary<int,int>();
            for (int i = 0; i < n; i++)
            {
                res.Add(a[i], i);
            }
            
            foreach (var item in res.OrderBy(e => e.Key))
            {
                Console.Write("{0} ", item.Value + 1);
            }
        }
    }
}


Measured memory_bytes: 28888
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint a(N);
    REP(i,N) cin>>a[i];

    sort(ALL(a));
    int x=a[N-1],y=a[0];
    REP(i,N-1){
        if(abs(2*a[i]-x)<abs(2*y-x)) y=a[i];
    }
    cout<<x<<' '<<y<<endl;

}


Measured memory_bytes: 1024
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#include <bits/stdc++.h>
#define pb(X) push_back(X)
#define x first
#define y second
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
using namespace std;

typedef pair<int, int> pii;

int n, a, b, c, d;

int main() {
	INIT
	cin >> a >> b;
	long long ans = 0;
	int T = b;
	vector<pii> A(a);
	for (int i = 0; i < a; ++i) {
		cin >> c >> d;
		A[i] = {c, d};
	}
	sort(A.begin(), A.end());
	for (int i = 0; i < a; ++i) {
		int t = min(T, A[i].y);
		T -= t;
		ans += 1ll * t * A[i].x;
		if (!T) break;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

class Main {
	public static void main (String[] args) {
		Scanner sc=new Scanner(System.in); 
		String s=sc.next();
		int i=0;
		while(i<3){
		    if(s.charAt(i)=='1')
		        System.out.print("9");
		    else
		        System.out.print("1");
		  i++;
		}
	}
}

Measured memory_bytes: 21844
N = int(input())
cordinates = [list(map(int, input().split())) for i in range(N)]

for t, x, y in cordinates:
    # x+yは時刻t毎に偶奇が入れ替わる
    if (x+y) > t or (x+y+t)%2:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 27300
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n")
  // tmp0 = input[0].split(" ")
  // N = Number(tmp0[0])
  // M = Number(tmp0[1])
  N = Number(input[0])
  A = Number(input[1])
  B = Number(input[2])
  C = Number(input[3])
  D = Number(input[4])
  E = Number(input[5])

  route = [A,B,C,D,E]
  min_route = Math.min(...route)
  min_route_index = route.indexOf(Math.min(...route))
  console.log(Math.ceil(N / min_route) + 4)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
//Main("10000000007\n2\n3\n2\n7\n11\n")

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,h[20],cnt=1;
	cin>>n;
	for(int i=0;i<n;i++) cin>>h[i];
	for(int i=1;i<n;i++){
		bool ok=true;
		for(int j=0;j<i;j++) if(h[j]>h[i]) ok=false;
		if(ok==true) cnt++;
	}
	cout<<cnt<<endl;
	return 0;
} 


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n, r;
    while(cin >> n >> r && n*r != 0){
        int lst[n];
        for(int i=0; i<n; i++) {
            lst[i] = n-i;
        }
        for(int x=0; x<r; x++){
            int p, c;
            cin >> p >> c;
            if(p == 1) {
            }
            else {
                int sub[c];
                for(int j=0; j<c; j++) {
                    sub[j] = lst[p-1+j];
                }
                for(int k=p-2; k>=0; k--) {
                        lst[k+c] = lst[k];
                }
                for(int i=0; i<c; i++) {
                    lst[i] = sub[i];
                }
            }
        }
        cout << lst[0] << endl;
    }
}

Measured memory_bytes: 2988
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i,s,n) for(int i=s;i< (int)n; i++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  int x,y;
  cin >>x>>y;
  rep(i,x+1){
      if(i*2+(x-i)*4==y){
        cout <<"Yes"<<endl;
        return 0;
      }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3632
A,B,C=map(int,input().split())
cnt=0

if A%2==B%2!=C%2:
    A,B=A+1,B+1
    cnt=1
elif B%2==C%2!=A%2:
    B,C=B+1,C+1
    cnt=1
elif C%2==A%2!=B%2:
    C,A=C+1,A+1
    cnt=1

A,B,C=min(A,B,C),A+B+C-min(A,B,C)-max(A,B,C),max(A,B,C)

print(cnt+(C-A)//2+(C-B)//2)

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

typedef long long int ll;

vector<ll>x,y,z;
ll sign[2]={1,-1};

ll absSum(int pos,int i,int j,int k){
    return (x[pos]*sign[i]+y[pos]*sign[j]+z[pos]*sign[k]);
}

int main(){
    int n, m;
    scanf("%d %d",&n,&m);
    for (int i = 0; i < n; i++){
        ll a,b,c;
        scanf("%lld %lld %lld",&a,&b,&c);
        x.push_back(a);
        y.push_back(b);
        z.push_back(c);
    }

    ll res = 0;

    for (ll i=0;i<2;i++){
        for (ll j=0;j<2;j++){
            for (ll k=0;k<2;k++){
                vector<ll>temp;
                for (int l=0;l<n;l++) temp.push_back(absSum(l,i,j,k));
                sort(temp.begin(),temp.end());
                ll maxx = 0;
                for (int l = n-1,o=0; l >=0 and o<m; l--,o++) maxx += temp[l];
                res = max(res,maxx);
            }
        }
    }
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 256
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

ans = -float('inf')
for i in range(1, 1 << 10):
    bit = [0] * 10
    for d in range(10):
        bit[d] = 1 if (i >> d) & 1 else 0
    profit = 0
    for j in range(N):
        cnt = sum(F[j][k] & bit[k] for k in range(10))
        profit += P[j][cnt]
    ans = max(ans, profit)

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,y; cin>>n>>y;
  int ans10000=-1,ans5000=-1,ans1000=-1;
  for(int i=0; i<=n; i++){
    for(int j=0; j+i<=n; j++){
      if(i*10000+j*5000+(n-i-j)*1000 == y){
        ans10000=i; ans5000=j; ans1000=n-i-j;
      }
    }
  }
  cout<<ans10000<<' '<<ans5000<<' '<<ans1000<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define run ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
#define mod 1000000007
#define ms(a,x) memset(a,x,sizeof(a))


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


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

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;

int main(void) {
  int n;
  cin >> n;
  vi h(n);
  rep(i,n) cin >> h[i];
  int cnt = 0;
  rep(i,n){
    while(h[i]>0){
      rep2(j,i,n){
        if(h[j]<1) break;
        h[j]--;
      }
      cnt++;
    }
  }
  cout << cnt << endl;
        
        
  
}






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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int k;
  cin >> k;
  int numOdd = k / 2;
  int numEven = k - k / 2;

  int ans = numOdd * numEven;
  cout << ans << endl;
  return 0;
}


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

template<class T, class U>
auto binary_diff(T t, U u) -> decltype(auto) {
#ifndef INCLUDE_GUARD_CMATH
#include <cmath>
#endif // INCLUDE_GUARD_CMATH
	return max(t, u) - min(t, u);
}

int main() {
	int H, W; cin >> H >> W;
	vector<vector<int>> v(H, vector<int>(W));
	int distance; vector<int> ans;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> v[i][j];
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			ans.push_back(0);
			for (int k = 0; k < H; k++) {
				for (int l = 0; l < W; l++) {
					if (k != i && l != j) {
						distance = min(binary_diff(i, k), binary_diff(j, l));
						ans[ans.size() - 1] += v[k][l] * distance;
					}
				}
			}
		}
	}
	cout << *min_element(ans.begin(), ans.end()) << endl;
	return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll=long long;

int main(){
    ll n,i,k,lmax=0;
    cin>>k>>n;
    vector<int> a(n);
    for(i=0;i<n;i++) cin>>a[i];
    for(i=0;i<n-1;i++) if(lmax<a[i+1]-a[i]) lmax=a[i+1]-a[i];
    if(lmax<a[0]+k-a[n-1]) lmax=a[0]+k-a[n-1];
    cout<<k-lmax;
    return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

bool solve(const string& s)
{
    int n = s.size();
    if(n % 2 != 0)
        return false;

    for(int i=0; i<n; ++i){
        if(s[i] != "hi"[i%2])
            return false;
    }
    return true;
}

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

    if(solve(s))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int H,i;
  scanf("%d",&H);
  int id[H+1];
  id[0]=0;
  for(i=1;i<=H;i++){
    scanf("%d",&id[i]);
  }

  for(i=1;i<=H;i++){
    printf("node %d: key = %d, ",i,id[i]);
    if(i/2>0)printf("parent key = %d, ",id[i/2]);
    if(2*i<=H)printf("left key = %d, ",id[2*i]);
    if(2*i+1<=H)printf("right key = %d, ",id[2*i+1]);
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2040
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int A = scan.nextInt(), B = scan.nextInt();
        int tmp = A - B * 2;
        if (tmp > 0) {
            System.out.println(tmp);
        } else {
            System.out.println("0");
        }
    }
}


Measured memory_bytes: 21716
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  getline(cin,str);
  cout << str[0];
  for(int i=0; i<str.size();i++){
  if(str[i]==' '){
   cout << str[i+1];
  }
  }
  cout << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
const ll p=1e9+7;
ll n, a[N], f[N], last[N];
int main()
{
	scanf( "%lld", &n );
	for ( int i=1; i<=n; i++ ) 
	  scanf( "%lld", &a[i] );
	f[1]=1; last[a[1]]=1;
	for ( int i=2; i<=n; i++ )
	{
		if ( a[i]==a[i-1] ) { f[i]=f[i-1]; last[a[i]]=i; continue; }
		f[i]=(f[i-1]+f[last[a[i]]])%p;
		last[a[i]]=i;
	}
	printf( "%lld", f[n] );
	return 0;
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> D(N);
    for (int i = 0; i < N; i++) {
        cin >> D[i];
    }
    if (N == 1) {
        cout << D[0] << endl;
        return 0;
    }
    sort(D.begin(), D.end());
    vector<int> pos;
    pos.push_back(0);
    int ans1 = INT_MAX, ans2 = INT_MIN;
    {
        pos.push_back(D[0]);
        for (int i = 1; i < N; i++) {
            int min1 = INT_MAX, min2 = INT_MAX;
            for (int e : pos) {
                min1 = min(min1, abs(e - D[i]));
                min2 = min(min2, abs(e - 24 + D[i]));
            }
            if (min1 >= min2) {
                pos.push_back(D[i]);
            } else {
                pos.push_back(24 - D[i]);
            }
        }
        sort(pos.begin(), pos.end());
        for (int i = 1; i < pos.size(); i++) {
            ans1 = min(ans1, min(pos[i] - pos[i - 1], 24 - pos[i] + pos[i - 1]));
        }
        ans1 = min(ans1, min(pos[pos.size() - 1] - pos[0], 24 - pos[pos.size() - 1] + pos[0]));
    }
    {
        pos.push_back(24 - D[0]);
        for (int i = 1; i < N; i++) {
            int min1 = INT_MAX, min2 = INT_MAX;
            for (int e : pos) {
                min1 = min(min1, abs(e - D[i]));
                min2 = min(min2, abs(e - 24 + D[i]));
            }
            if (min1 >= min2) {
                pos.push_back(D[i]);
            } else {
                pos.push_back(24 - D[i]);
            }
        }
        sort(pos.begin(), pos.end());
        for (int i = 1; i < pos.size(); i++) {
            ans2 = min(ans2, min(pos[i] - pos[i - 1], 24 - pos[i] + pos[i - 1]));
        }
        ans2 = min(ans2, min(pos[pos.size() - 1] - pos[0], 24 - pos[pos.size() - 1] + pos[0]));
    }
    cout << max(ans1, ans2) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define REP(i, n) for (LL i = 0; i < (int)(n); i++)
#define REP2(i, n) for (LL i = 1; i <= (int)(n); i++)
#define FOR(i, m, n) for (LL i = m; i n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define int long long
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main() {
  int n,x,ans=0;
  cin >> n>>x;
  vector<int> d(n);
  REP(i, n){
    cin >> d[i];
    ans+=d[i];
    if(x<ans){
      cout << i+1;
      return 0;
    }
  }
  cout << n+1;
}



Measured memory_bytes: 3624
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/B-OneDimensionalWorldsTale.py
#

n, y, x, y = map(int, input().split())
x_under = [int(i) for i in input().split()]
y_under = [int(i) for i in input().split()]
max_x_under = max(x_under)
min_y_under = min(y_under)

for z in range(x+1, y+1):
    if max_x_under < z <= min_y_under:
        print("No War")
        exit()

print("War")


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
typedef pair<ll,ll> P;
typedef pair<ll,P> P2;
ll min_cost[100005][3];
vector<ll> node[100005];
int main(){
  ll n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    ll u,v;
    cin>>u>>v;
    node[u].push_back(v);
  //  node[v].push_back(u);
  }
  ll s,t;
  cin>>s>>t;
  for(int i=0;i<=n;i++){
    for(int j=0;j<3;j++) min_cost[i][j]=174417441744;
  }
  min_cost[s][0]=0;
  priority_queue<P2,vector<P2>,greater<P2>> pque;
  pque.push(P2(0,P(s,0)));
  while(!pque.empty()){
    P2 p=pque.top();
    pque.pop();
    ll cos=p.first,pos=p.second.first,mo=p.second.second;
    for(int i=0;i<node[pos].size();i++){
      int to=node[pos][i];
      int nmo=(mo+1)%3;
      if(cos+1<min_cost[to][nmo]){
        min_cost[to][nmo]=cos+1;
        pque.push(P2(cos+1,P(to,nmo)));
      }
    }
  }
  /*for(int i=1;i<=n;i++){
    for(int j=0;j<3;j++) cout<<min_cost[i][j]<<" ";
    cout<<endl;
  }*/
  ll ans=min_cost[t][0];
  if(ans%3!=0) ans=174417441744;
  cout<<(min_cost[t][0]==174417441744?-1:min_cost[t][0]/3)<<endl;
}


Measured memory_bytes: 8180
#include <bits/stdc++.h>
using namespace std;
using lli=long long int;
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
using vi=vector<int>;  using vs=vector<string>; using gi=greater<int>;
#define soao(c) sort((c).begin(),(c).end()) //昇順
#define sodo(c) sort((c).begin(),(c).end(),gi()) //降順
#define rev(c) reverse((c).begin(), (c).end())

int main() {
  int K; cin>>K;
  int sum=0;
  rep(i,K){
    rep(j,K){
      rep(k,K){
        sum+=__gcd(__gcd(i,j),k);
      }
    }
  }
  cout<<sum<<endl;
}


  


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

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

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include <sstream>
#include <stdio.h>
#define rep(x,y) for(int x = 0; x < (y); x++)
#define REP(x,z,y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(),x.end()
#define length(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str,sp_word) istringstream stream(str); string res; while(getline(stream,res,sp_word))
#define rm_space(x) x.erase(remove(all(x),' '),x.end())

using namespace std;

int main(){
  int N;
  scanf("%d",&N);
  printf("ABC%d\n",N);
  return 0;
}

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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;

  vector<ll> va(n), vb(n), vc(n);
  for (int i = 0; i < n; ++i) cin >> va[i];
  for (int i = 0; i < n; ++i) cin >> vb[i];
  for (int i = 0; i < n; ++i) cin >> vc[i];

  sort(va.begin(), va.end());
  sort(vb.begin(), vb.end());
  sort(vc.begin(), vc.end());

  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    auto it_a = upper_bound(va.rbegin(), va.rend(), vb[i], greater<ll>());
    auto it_c = upper_bound(vc.begin(), vc.end(), vb[i]);

    ans += distance(it_a, va.rend()) * distance(it_c, vc.end());
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 5620
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
//S.size()
//配列名.Length()
using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;


int main(void){
	int A,B; cin>>A>>B;
  if(abs(A-B) % 2 == 1)cout<<"IMPOSSIBLE";
  else{
    cout<<min(A,B) + abs(A-B)/2;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll n,d,ans,a[200005],ml[200005],mr[200005];
int main(void){
    cin>>n>>d;
    ans=d*(n-1);
    for(int i=0;i<n;i++){
        cin>>a[i];
        ans+=a[i];
    }
    for(int i=0;i<n;i++)mr[i]=INF,ml[i]=INF;
    ml[0]=a[0];
    for(ll i=1;i<n;i++){
        ml[i]=min(ml[i-1],a[i]-i*d);
    }
    mr[n-1]=a[n-1]+d*(n-1);
    for(ll i=n-2;i>=0;i--){
        mr[i]=min(mr[i+1],a[i]+i*d);
    }
    for(ll i=1;i+1<n;i++){
        ans+=min(i*d+ml[i],mr[i]-i*d);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4992
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, a, b = input_int_list()
    X = input_int_list()
    dp = [0] * (n)
    for i in range(1, n):
        dp[i] = min(dp[i - 1] + (X[i] - X[i - 1]) * a, dp[i - 1] + b)

    print(dp[n - 1])
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 85412
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long a,b,c;
	cin >> a >> b >> c;
	if(c<a+b) printf("No\n");
	else if(4*a*b<(c-a-b)*(c-a-b))
	printf("Yes\n");
	else
	printf("No\n");
	return 0;
} 

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N=input()

#約数列挙
def make_divisors(n):
    divisors=[]
    for i in range(1, int(n**0.5)+1):
        if n%i==0:
            divisors.append(i)
            if i!=n/i:
                divisors.append(n/i)
    return divisors

#整数N-1の約数は全て答えにカウントして良い
ans=set(make_divisors(N-1))

K=make_divisors(N)  #Nの約数の集合
#整数Nの約数について条件にマッチングするかを1つ1つ調べる
for k in K:
    if k==1: continue
    n=N
    while n%k==0:
        n/=k
    else:
        if n==1 or n%k==1:
            ans.add(k)
print len(ans)-1

Measured memory_bytes: 30188
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n, m;
    cin >> n >> m;
    vector<P> table(n);
    for(int i = 0; i < n; ++i){
        int a, b;
        cin >> a >> b;
        table[i] = P(a, b);
    }

    // 給料昇順でソート (a に関しては昇順)
    sort(table.begin(), table.end(), [](const P& p1, const P& p2){
        if(p1.second == p2.second){
            return p1.first < p2.first;
        }
        return p1.second > p2.second;
    });

    // 何日後までの仕事が受け取れるかという上限を集合として持っておく
    set<int> bound;
    for(int i = 1; i <= m; ++i) bound.insert(i);

    int ans = 0;
    for(int i = 0; i < n; ++i){
        auto it = bound.lower_bound(table[i].first);

        // bound の中に a 以上の値がない、つまりその仕事ができない
        if(it == bound.end())   continue;

        ans += table[i].second;

        // 後々の自由度のために、上限の中でぎりぎりの値を集合から取り除く
        bound.erase(it);
    }
    
    cout << ans << endl;
}

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

int main() {
  string S; cin >> S; // 入力文字列
  string Ans = "No";  // 回答文字列

  // if ( S.size() % 2 != 0 ) {;}
  // else {
  //   rep(i,S.size()-1){
  //     if ( i % 2 == 0 ) {
  //       if (debug) {cout << i << ":" <<  S.at(i) << ":" << S.at(i+1) << endl;}
  //       if ( S.at(i) = 'h' && S.at(i+1)=='i' ) { Ans="Yes";}
  //       else {Ans="No";break;}
  //     }
  //   }
  // }

  if ( S == "hi"
      || S=="hihi"
      || S=="hihihi"
      || S=="hihihihi"
      || S=="hihihihihi") { Ans="Yes";}

  cout << Ans << endl;
}



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

int gcd(int a, int b);

int main() {
    int k;
    cin >> k;

    int sum = 0;
   for (int a=1; a<=k; a++) {
       for (int b=1; b<=k; b++) {
           for (int c=1; c<=k; c++) {
               sum += gcd(a, gcd(b, c));
           }
       }
   }

   cout << sum << endl;
}

int gcd(int a, int b) {
    if (a < b) {
        int tmp = a;
        a = b;
        b = tmp;
    }

    int r = 0;
    while(a % b != 0) {
        r = a % b;
        a = b;
        b = r;
    }

    return b;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(20 + 5);

int n, m, c;
int b[MAX_N];

int ans = 0;

int main(void) {
  // Here your code !
  scanf("%d %d %d", &n, &m, &c);

  for (int i = 0; i < m; ++i) {
    scanf("%d", &(b[i]));
  }

  for (int i = 0; i < n; ++i) {
    int tmp = 0;
    for (int j = 0; j < m; ++j) {
      int a;
      scanf("%d", &a);
      tmp += b[j] * a;
    }

    if ((tmp + c) > 0) ans += 1;
  }

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

  return 0;
}


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

signed main(){
	string S,T; cin>>S>>T;
	vector<vector<int>> dp(S.size()+10,vector<int>(T.size()+10));
	for(int i=0;i<S.size();i++){
		for(int j=0;j<T.size();j++){
			if(S[i]==T[j])dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
			dp[i+1][j+1]=max(dp[i+1][j+1],dp[i+1][j]);
			dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j+1]);
		}
	}
	
	string ans="";
	int i=S.size(),j=T.size();
	while(i>0 && j>0){
		if(dp[i][j]==dp[i-1][j])i--;
		else if(dp[i][j]==dp[i][j-1])j--;
		else{
			ans+=S[i-1];
			i--; j--;
		}
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
}

Measured memory_bytes: 71168
import java.util.Scanner;
public class Main {
	

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int as = 0;
		int bs = 0;
		for(int i = 0; i < 4; i++) {
			as += stdIn.nextInt();
		}
		for(int i = 0; i < 4; i++) {
			bs += stdIn.nextInt();
		}
		
		if(as < bs) {
			System.out.println(bs);
		}
		else if(as > bs) {
			System.out.println(as);
		}
		else {
			System.out.println(as);
		}
		
		
	}
}

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

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
const int MOD = 1000000007;
const int INF = 100100100;
const double EPS = 0.000000001;

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  char S[53][53];

  cin >> H >> W;
  FOR(i, 1, H+1) {
    FOR(j, 1, W+1) {
        cin >> S[i][j];
    }
  }
  FOR(i, 0, H+2) {
    FOR(j, 0, W+2) {
      if((i == 0) || (j == 0) || (i == H+1) || (j == W+1)) S[i][j] = '.';
    }
  }

  bool ans = true;
  FOR(i,1,H+1) {
    FOR(j,1,W+1) {
      if(S[i][j] == '#'){
        if((S[i+dy[0]][j+dx[0]] == '#') || (S[i+dy[1]][j+dx[1]] == '#') || (S[i+dy[2]][j+dx[2]] == '#') || (S[i+dy[3]][j+dx[3]] == '#')) {
        }
        else ans = false;
      }
    }
  }

  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

constexpr int B = 45, N = 100009;
int n;
long long k, a[N], dp[B][2];

long long go(int b, int j) {
  if(b == -1) return 0;
  if(dp[b][j] != -1) return dp[b][j];
  long long& ans = dp[b][j] = 0;
  int x = bool((1LL << b) & k);

  long long one = 0, zero = 0;
  for(int i = 1; i <= n; ++i) {
    one += ((1LL << b) & a[i]) ^ (1LL << b);
    zero += (1LL << b) & a[i];
  }

  if(j) {
    ans = max(ans, max(one, zero) + go(b - 1, 1));
  } else {
    if(!x) ans = zero + go(b - 1, 0);
    else ans = max(zero + go(b - 1, 1), one + go(b - 1, 0));
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  memset(dp, -1, sizeof dp);
  cin >> n >> k;
  for(int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  cout << go(B - 1, 0) << '\n'; 
}

Measured memory_bytes: 1024
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Haiku
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  s[5] = s[13] = ' ';
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define hell 1000000007
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
void solve(){
    int x;
    cin>>x;
    rep(i,1,10){
        if(x%i==0){
            if(x/i<10){
                cout<<"Yes\n";
                return;
            }
        }
    }
    cout<<"No\n";
    return;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    int tests = 1;
    //cin>>tests;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
import math
n,a,b = map(int,input().split())
hako = a+b
hako_include = math.floor(n/hako)

nokori = n-hako_include*hako
if nokori >= a:
  print(hako_include*a + a)
else:
  print(hako_include*a + nokori)
  

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int n = S.size();
    int cnt = 0;
    for(int i=0;i<n/2;i++){
        if(S[i] != S[n-1-i]) cnt++;
    }
    cout << cnt << endl;
}

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

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
int main(){
	vector<char> c(10);
	int count=0,max=0;
	string S;
	cin>>S;
	for(int i=0;i<S.size();i++){
		c[i]=S[i];
		if(c[i]=='A'||c[i]=='C'||c[i]=='G'||c[i]=='T'){
			count++;
			if(count>max)max=count;
		}else{
			count=0;
		}
	}
	cout<<max<<endl;
	return 0;
}

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

#define int long long

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	// C
	int k, a, b;
	cin >> k >> a >> b;
	long long ans = -1;
	if (b - a <= 2 ) {
		ans = k + 1;
	} else {
		if (k + 3 < a) {
			ans = k + 1;
		} else {
			k -= a - 1;
			ans = a + (b - a) * (k / 2) + k % 2;
		}
	}
	cout << ans << endl;
	return 0;	
}

Measured memory_bytes: 256
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int a, b, ans;
  scanf("%d%d", &a, &b);
  ans = (a + b) % 2;
  if (ans == 0)
    printf("%d\n", (a + b) / 2);
  else
    puts("IMPOSSIBLE");
}

Measured memory_bytes: 128
n = int(input())
a1, a2 = list(map(int, input().split())), list(map(int, input().split()))

c0 = sum(a1) + a2[n-1]
cb = c0

for i in range(n-1, 0, -1):
    ci = cb - a1[i] + a2[i-1]
    cb = ci

    if ci > c0:
        c0 = ci

print(c0)


Measured memory_bytes: 3316