akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr ll MOD = 1000000007;
using std::cout;
using std::endl;
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::multiset;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, ll b) {
	ll ans = 1;
	while (b > 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		b /= 2;
		a *= a;
		a %= MOD;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a - b < b) { return comb(a, a - b); }
	ll c = 1;
	FOR(i, a - b + 1, a + 1) {
		c *= i;
		c %= MOD;
	}
	ll k = 1;
	FOR(i, 2, b + 1) {
		k *= i;
		k %= MOD;
	}
	c *= pow(k, MOD - 2);
	return c % MOD;
}
multiset<ll> prime_decomposition(ll n) {
	ll i = 2;
	multiset<ll> table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace(n);
		return table;
	}
	return table;
}
/*
-- bit --
REP(i, (1 << n)) {
	REP(j, n) {
		cout << (1 & (i >> j));
	}
	cout << endl;
}
*/


int main() {
	int n, m;
	cin >> n >> m;
	VL v(n);
	REP(i, n) { cin >> v[i]; }

	vector<VVL> dp(n + 1, VVL(2501, VL(51, 0)));

	FOR(i, 1, n + 1) {
		REP(j, 2501) {
			FOR(k, 1, 51) {
				if (j - v[i - 1] > 0) {
					dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - v[i - 1]][k - 1];
				} else {
					dp[i][j][k] = dp[i - 1][j][k];
				}
			}
		}
		dp[i][v[i - 1]][1] = dp[i][v[i - 1]][1] + 1;
	}
	ll c = 0;
	REP(j, 2501) {
		FOR(k, 1, 51) {
			if (k*m == j) {
				c += dp[n][j][k];
			}
		}
	}
	cout << c << endl;
}

Measured memory_bytes: 56192
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const int MAX_N = 4e3 + 10;
ll ans[MAX_N][MAX_N], hist[MAX_N][MAX_N];
string a, b;

void output(int i, int j) {
    if(i == 0 && j == 0) {
        return;
    }
    if(hist[i][j] == 2) {
        output(i - 1, j - 1);
        cout << a[i - 1];
    } else if(hist[i][j] == 1) {
        output(i - 1, j);
    } else if(hist[i][j] == -1) {
        output(i, j - 1);
    }
}

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> a >> b;
    ll ret = 0;
    for(int i = 0; i < MAX_N; i ++) {
        fill_n(ans[i], MAX_N, -mod);
    }
    ans[0][0] = 0;
    for(int i = 0; i <= a.size(); i ++) {
        for(int j = 0; j <= b.size(); j ++) {
            if(a[i] == b[j]) {
                if(chkmax(ans[i + 1][j + 1], ans[i][j] + 1)) {
                    hist[i + 1][j + 1] = 2;
                }
            }
            if(chkmax(ans[i + 1][j], ans[i][j])) {
                hist[i + 1][j] = 1;
            }
            if(chkmax(ans[i][j + 1], ans[i][j])) {
                hist[i][j + 1] = -1;
            }
        }
    }
    output(a.size(), b.size());
    return 0;
}



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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, T, A, H;
	double mint = 100000000;
	int mini = 0;
	cin >> N >> T >> A;
	rep(i, 0, N)
	{
		cin >> H;
		if (abs(A-(T - H * 0.006)) < mint)
		{
			mint = abs(A - (T - H * 0.006));
			mini = i;
		}
	}

	cout << mini+1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
const int MAX=2e5;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  ll N,A,B;
  cin >> N >> A >> B;
  ll ans;
  if((B-A)%2==0){
    ans=(B-A)/2;
  }
  else{
    ll l=max(A-1,B-1);
    ll r=max(N-A,N-B);
    ll pans1=min(l,r);
    ll pans2;
    if(A-1<=N-B){
      pans2=A+(B-A-1)/2;
    }
    else{
      pans2=N-B+1+(B-A-1)/2;
    }
    ans=min(pans1,pans2);
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <set>
#include <iostream>

using namespace std;
int main() {
	int n;
	cin >> n;
	set<int> st;
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;

		st.insert(x);
	}

	cout << st.size() << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		Set<String> dic=new HashSet<>();
		int n=sc.nextInt();
		String com,word;
		for(int i=0;i<n;i++){
			com=sc.next();
			word=sc.next();
			if(com.equals("insert")){
				dic.add(word);
			}
			else if(dic.contains(word)){
				System.out.println("yes");
			}
			else{
				System.out.println("no");
			}
		}
	}
}


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

int main(){
  int n;

  while(cin >> n, n){
    int ans = 0;

    for(int i = 1; i < n; i++){
      int sum = 0;
      for(int j = i; sum < n; j++){
        sum += j;
      }
      if(sum == n){
        ans++;
      }
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 1160
#include <stdio.h>

int N;
int a[114514];

int main(void) {
	int i;
	int minIndex, minValue;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &a[i]) != 1) return 1;
	}
	minIndex = 0;
	minValue = a[0];
	for (i = 1; i < N; i++) {
		if (a[i] < minValue) {
			minIndex = i;
			minValue = a[i];
		}
	}
	printf("%d\n", minIndex + 1);
	return 0;
}



Measured memory_bytes: 2188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
int DBG = 1;										/* デバッグプリント 提出時は0 */
/* main *************************************************************/
int a[100001],dp[100001],grp[100001]={0};

int main()
{
	int		g,c,i,j,k,n,x,y,pre,ans;
	
	scanf("%d", &n);
	for(i=1;i<=n;i++) scanf("%d", &a[i]);
	
	if (n>1) {
		ans = 1;
		grp[ans] = a[1];
		for(i=2;i<=n;i++) {
			if (grp[ans] >= a[i]) {
				grp[++ans] = a[i];
			} else {
				for(j=1;j<=ans;j++) {
					if (grp[j]<a[i]) {
						grp[j] = a[i];
						break;
					}
				}
			}
		}
	}

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


	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include <string>
#include <utility>
#include<array>
#include<set>
#define EPS (1e-7)
using namespace std;




int main() {

	int N;
	cin >> N;
	vector<int> a(9, 0);
	int tempa, ans = 0, mina;

	for (size_t i = 0; i < N; i++)
	{
		cin >> tempa;
		if (tempa >= 1 && tempa <= 399)a[0] += 1;
		else if (tempa >= 400 && tempa <= 799)a[1] += 1;
		else if (tempa >= 800 && tempa <= 1199)a[2] += 1;
		else if (tempa >= 1200 && tempa <= 1599)a[3] += 1;
		else if (tempa >= 1600 && tempa <= 1999)a[4] += 1;
		else if (tempa >= 2000 && tempa <= 2399)a[5] += 1;
		else if (tempa >= 2400 && tempa <= 2799)a[6] += 1;
		else if (tempa >= 2800 && tempa <= 3199)a[7] += 1;
		else if (tempa >= 3200)a[8] += 1;
	}

	for (size_t i = 0; i < 8; i++)
	{
		if (a[i] > 0) ans += 1;
	}
	mina = ans;

	ans += a[8];

	if (mina == 0) { mina = 1; }

	cout << mina << " " << ans << endl;

	return 0;
}

Measured memory_bytes: 256
L, R = map(int, input().split())

min = 2*1000000000

if R - L > 2019:
  R = L + 2019

for i in range(L,R):
    for j in range(i+1,R+1):
        if min > ((i % 2019) * (j % 2019))%2019:
            min = ((i % 2019) * (j % 2019))%2019

print(min)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _071
{
    class Program
    {
        static void Main(string[] args)
        {
            //
            ProblemB.Solve();
        }
    }

    class ProblemB
    {
        public static void Solve()
        {
            string S = Console.ReadLine();

            HashSet<char> alpha = new HashSet<char>()
            {
                'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
            };

            foreach (char item in S)
            {
                if (alpha.Contains(item))
                {
                    alpha.Remove(item);
                }
            }

            if (alpha.Count < 1)
            {
                Console.WriteLine("None");
            }
            else
            {
                Console.WriteLine(alpha.ToList().OrderBy(x=>x).First());
            }
        }

    }
}


Measured memory_bytes: 13596
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N, M, X, Y int
	fmt.Scan(&N, &M, &X, &Y)

	x := make([]int, N+1)
	y := make([]int, M+1)
	x[0] = X
	y[0] = Y
	for i := 0; i < N; i++ {
		fmt.Scan(&x[i+1])
	}
	for i := 0; i < M; i++ {
		fmt.Scan(&y[i+1])
	}

	sort.Ints(x)
	sort.Ints(y)

	ans := "No War"
	if x[0] <= y[len(y)-1] && y[0] <= x[len(x)-1] {
		ans = "War"
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    static int n;
    static long[] x, y;
    static bool[] picked;
    static Dictionary<Tuple<long, long>, int> h;
    
    static int check(long dx, long dy)
    {
	int ret = 0;
	for (int i = 0; i < n; i++) picked[i] = false;

	for (int i = 0; i < n; i++)
	{
	    if (picked[i]) continue;

	    ret++;
	    long xx = x[i], yy = y[i];

	    int j = 1;
	    while (h.ContainsKey(Tuple.Create(xx + dx * j, yy + dy * j)))
	    {
		int ni = h[Tuple.Create(xx + dx * j, yy + dy * j)];
		picked[ni] = true;
		j++;
	    }

	    j = 1;
	    while (h.ContainsKey(Tuple.Create(xx - dx * j, yy - dy * j)))
	    {
		int ni = h[Tuple.Create(xx - dx * j, yy - dy * j)];
		picked[ni] = true;
		j++;
	    }
	}

	return ret;
    }
    
    public static void Main()
    {
	n = int.Parse(ReadLine());
	x = new long[n];
	y = new long[n];
	h = new Dictionary<Tuple<long, long>, int>();
	for (int i = 0; i < n; i++)
	{
	    var tmp = ReadIntArray();
	    x[i] = tmp[0]; y[i] = tmp[1];
	    h.Add(Tuple.Create(x[i], y[i]), i);
	}

	picked = new bool[n];
	
	int ans = n;
	for (int i = 0; i < n-1; i++)
	{
	    for (int j = i+1; j < n; j++)
	    {
		long dx = x[j] - x[i];
		long dy = y[j] - y[i];
		ans = Math.Min(ans, check(dx, dy));
	    }
	}

	WriteLine(ans);
    }
}


Measured memory_bytes: 17608
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>

typedef long long int li;
typedef long double ld;


using namespace std;

int main(){
    int a,b;
    char n;
    while(true){
        cin >> a >> n >> b;
        if(n=='+'){
            cout << a+b << endl;
        }else if(n=='-'){
            cout << a-b << endl;
        }else if(n=='*'){
            cout << a*b << endl;
        }else if(n=='/'){
            cout << a/b << endl;
        }else{
            break;
        }
            
    }
    
    return 0;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

int ans = 100000000;

int main(){
    int N, Y; cin >> N >> Y;
    int sheets[3] = {10000,5000,1000};

    for(int i = 0; i <= 2000; i++){
        for (int j = 0; j <= 2000; j++){
            int k = N - i - j;
            if (k < 0) break;
            if (sheets[0]*i + sheets[1]*j + sheets[2]*k == Y){
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }

    cout << -1 << " " <<  -1 << " " << -1 << endl;
}


Measured memory_bytes: 3572
#include<iostream>
using namespace std;
int main() {
    double W,H,x,y;
    cin >> W >> H >> x >> y;
	cout << W*H/2 << " ";
	if(x == W/2 && y == H/2)
        cout << 1 << endl;
	else
        cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 256
var inputs = require('fs').readFileSync('/dev/stdin', 'utf8').split(" ");

a = ~~inputs[0];
b = ~~inputs[1];
c = ~~inputs[2];

x = Math.min(a,b,c)
z = Math.max(a,b,c)
y = a+b+c-x-z
console.log(`${x} ${y} ${z}`);




Measured memory_bytes: 15096
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
B = A[::-1]
C = N-1
ans = 0
if N%2 == 0:
  ans += B[0]
  for i in range(N//2-1):
    ans += 2*B[i+1]
else:
  ans += B[0]
  ans += B[N//2]
  for i in range(N//2-1):
    ans += 2*B[i+1]
print(ans)    

Measured memory_bytes: 31544
// ---------- begin chmin, chmax ----------
trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------

use proconio::*;
use std::cmp::*;

#[fastout]
fn run() {
    input! {
        n: usize,
        p: [(i64, i64, i64); n],
    }
    let mut cost = vec![0; 1 << n];
    for i in 1..(1 << n) {
        let mut a = vec![];
        let mut b = vec![];
        for (j, &(x, y, p)) in p.iter().enumerate() {
            if (i >> j) & 1 == 1 {
                a.push((x, p));
                b.push((y, p));
            }
        }
        let mut val = std::i64::MAX;
        for &(z, _) in a.iter() {
            let mut s = 0;
            for &(x, p) in a.iter() {
                s += (z - x).abs() * p;
            }
            val.chmin(s);
        }
        for &(z, _) in b.iter() {
            let mut s = 0;
            for &(x, p) in b.iter() {
                s += (z - x).abs() * p;
            }
            val.chmin(s);
        }
        cost[i] = val;
    }
    let mut ini = vec![0; 1 << n];
    for i in 1..(1 << n) {
        let mut s = 0;
        for (j, &(x, y, p)) in p.iter().enumerate() {
            if (i >> j) & 1 == 1 {
                s += min(x.abs(), y.abs()) * p;
            }
        }
        ini[i] = s;
    }
    let cnt: Vec<usize> = (0usize..(1 << n)).map(|p| p.count_ones() as usize).collect();
    let inf = std::i64::MAX / 100;
    let mut dp = vec![inf; 1 << n];
    dp[(1 << n) - 1] = 0;
    for i in (1..=n).rev() {
        let ans = dp.iter().zip(ini.iter()).map(|p| *p.0 + *p.1).min().unwrap();
        println!("{}", ans);
        for (bit, _) in cnt.iter().enumerate().skip(1).filter(|p| *p.1 <= i) {
            let v = dp[bit];
            let mut j = bit;
            while j > 0 {
                let x = bit ^ j;
                dp[x].chmin(v + cost[j]);
                j = (j - 1) & bit;
            }
        }
    }
    println!("0");
}

fn main() {
    run();
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll mod = 1e9+7;

ll gcd(ll a,ll b){
	if(b==0)return a;return gcd(b,a%b);
}
ll expo(ll base,ll pow){
    ll ans = 1;
    while(pow!=0){
        if(pow&1==1){ans = ans*base;}
        base *= base;pow/=2;}return ans;
}
ll inv(ll x){return expo(x,mod-2);}

int cnt[123456];

int main(){
    //freopen("ip.txt", "rt", stdin);
    //freopen("op.txt", "wt", stdout);
    int n;
    cin >> n;
    vector <int> vec(n+1), vec1;

    for(int i = 1; i <= n; i++){
        cin >> vec[i];
        if(vec[i] == i) vec1.push_back(i);
    }
    int ans = 0;
    for(int i = 0; i < vec1.size(); i++){
        if(i != vec1.size()-1){
           if(vec1[i+1] == vec1[i]+1){
              ans++;
              i++;
           }
           else ans++;
        }
        else ans++;
    }
    cout << ans;


}


Measured memory_bytes: 1276
H, W = [int(i) for i in input().split()]
while (H != 0) and (W != 0):
    a = t = ''
    for i in range(W+1):
        if i % 2 == 0: t += '#'
        else: t += '.'
    for i in range(H):
        if i % 2 == 0: a += t[:-1] + '\n'
        else: a += t[1:] + '\n'
    print(a)
    H, W = [int(i) for i in input().split()]


Measured memory_bytes: 5640
#include <bits/stdc++.h> 
#define lowbit(x) x&(-x)
using namespace std;
const int N = 5e4;
const int M = 2e3;

bool ab[N << 1],ac[N << 1],bc[N << 1];

inline bool check(char x,char y){
	return (x == '?' || y == '?' || x == y);
}

void init(string a,string b,int n,int m,bool *vis){
	for(int i = 0;i < n;++i)
		for(int j = 0;j < m;++j)
			if(!check(a[i],b[j])) vis[i-j+N] = 1;
	return ;
}

int main(){
	int A,B,C;
    string a,b,c;
    cin >> a;A = a.size();
    cin >> b;B = b.size();
    cin >> c;C = c.size();
    
    init(a,b,A,B,ab);
    init(a,c,A,C,ac);
    init(b,c,B,C,bc);
    
    int ans = 3*M;
    for(int i = -(M << 1);i <= (M << 1);++i){
    	for(int j = -(M << 1);j <= (M << 1);++j){
    		if(!ab[i+N] && !ac[j+N] && !bc[j-i+N]){
    			int l = min(0,min(i,j));
    			int r = max(A,max(B+i,C+j));
    			ans = min(ans,r-l);
			}
		}
	}
	printf("%d\n",ans);
    return 0;
}

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

namespace ziyuutyou
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var list = new List<int>();

            var aaa = str[0] + str[1];
            var bbb = str[0] - str[1];
            var ccc = str[0] * str[1];

            list.Add(aaa);
            list.Add(bbb);
            list.Add(ccc);

            Console.WriteLine(list.Max());

        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int m[1010];

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int res = min(n*a, b);

  cout << res << endl;
  return 0;
}


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

using namespace std;


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

    int n;
    cin >> n;
    int mgm[n+1];
    map<int,int> sCount;
    for(int i=1;i<=n;i++){
		sCount[i]=0;
	}
    for(int i=2;i<=n;i++){
		cin >> mgm[i];
		sCount[mgm[i]]++;
	}
	for(auto it=sCount.begin();it!=sCount.end();it++){
		printf("%d\n",it->second);
	}
	
	
	
}



Measured memory_bytes: 13908
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



string s;

signed main() {
	cin >> s;
	cout << count(all(s),'2') << endl;
}

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

int main(void){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; ++i){
        cin >> A[i];
    }

    auto max = max_element(A.begin(), A.end());
    int maxval = *max;
    size_t maxIndex = distance(A.begin(), max);

    for(int i=0; i<maxIndex; ++i){
        cout << maxval << endl;
    }

    auto max2 = max_element(A.begin(), A.end());

    A.erase(max);
    cout <<  *max_element(A.begin(), A.end()) << endl;
    

    for(int i=maxIndex+1; i<N; ++i){
        cout << maxval << endl;
    }

}


Measured memory_bytes: 2432
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int main() {
    int H, W; cin >> H >> W;
    vector<vector<int>> S(H, vector<int>(W, 100));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            char c; cin >> c;
            if (c == '.') S[i][j] = 0;
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (S[i][j] == 100) {
                for (int k = 0; k < 8; k++) {
                    if (0 <= i + dy[k] && i + dy[k] < H && 0 <= j + dx[k] && j + dx[k] < W) {
                        if (S[i + dy[k]][j + dx[k]] != 100) S[i + dy[k]][j + dx[k]]++;
                    }
                }
            }
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (S[i][j] == 100) cout << '#';
            else cout << S[i][j];
        }
        cout << endl;
    }

}


Measured memory_bytes: 3564
import sys

fin = sys.stdin.readline
num = str(fin()).split()[0]

readable = True
prev_num = num[0]
for i in range(1, 4):
    cur_num = num[i]
    if prev_num == cur_num:
        readable = False
    prev_num = cur_num

if readable:
    print('Good')
else:
    print('Bad')


Measured memory_bytes: 38472
#include <cstdio>
#include <cstdlib>
#include <algorithm>

const int maxn = 1e5 + 20;

int n;
int a[maxn];
int cnt[5];

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	
	for(int i = 1; i <= n; i++)
	{
		if(a[i] % 4 == 0) a[i] = 2;
		else if(a[i] % 2 == 0) a[i] = 1;
		else a[i] = 0;
	}
	
	for(int i = 1; i <= n; i++) cnt[a[i]]++;
	
	bool ans = true;
	
	for(int i = 1; i <= n; i++)
	{
		int bound = (i == 1 ? 0 : 2 - a[i - 1]);
		
		while(bound <= 2)
		{
			if(cnt[bound])
			{
				a[i] = bound;
				cnt[bound]--;
				break;
			}
			
			bound++;
		}
		
		if(bound > 2)
		{
			ans = false;
			break;
		}
	}
	
	printf("%s", ans ? "Yes" : "No");
	
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,mx=0;
    int arr1[26],arr2[26];
    string s;
    cin>>n>>s;
    for(int i=1;i<n;i++) {
        memset(arr1,0,sizeof arr1);
        memset(arr2,0,sizeof arr2);
        int cnt = 0;
        for(int j=i-1;j>=0;j--) {
            arr1[s[j]-'a']++;
        }
        for(int j=i;j<n;j++){
            arr2[s[j]-'a']++;
        }
        for(int i=0;i<26;i++) {
            if(arr1[i] && arr2[i]) cnt++;
        }
        mx = max(mx,cnt);
    }
    cout<<mx<<endl;
}


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


int main(){
    string s;
    cin >> s;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='?')cout << "D";
        else cout << s[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3756
#include<iostream>
#include<math.h>
using namespace std;

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

  double ans = N / 1.08;
  double m = floor(ans), n = ceil(ans);

  if (floor(m * 1.08) == N) cout << m << endl;
  else if (floor(n * 1.08) == N) cout << n << endl;
  else cout << ":(" << endl;

  return 0;
}


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

using namespace std;

using int64 = long long;

bool charange(vector< int > &A, vector< int > &B, int64 bit) {
  for(int k = 0; k < A.size(); k++) {
    bool dp[51] = {};
    dp[A[k]] = true;
    for(int i = 51; i > 0; i--) {
      if((bit >> i) & 1) {
        bool dp2[51];
        for(int j = 0; j < 51; j++) {
          dp2[j] = dp[j];
        }
        for(int j = 50; j >= 0; j--) {
          if(dp[j]) {
            dp2[j % i] = true;
          }
        }
        swap(dp, dp2);
      }
    }
    if(!dp[B[k]]) {
      return false;
    }
  }
  return true;
}

int main() {
  int N;
  cin >> N;
  vector< int > A(N), B(N);
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for(int i = 0; i < N; i++) {
    cin >> B[i];
  }
  int64 ret = (1LL << 51) - 1;
  if(!charange(A, B, ret)) {
    cout << -1 << endl;
    return 0;
  }
  for(int i = 50; i >= 0; i--) {
    if(charange(A, B, ret ^ (1LL << i))) {
      ret ^= 1LL << i;
    }
  }
  cout << ret << endl;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define INF 99999999

using namespace std;

typedef long long ll;

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int lsum[(int)s.size()+2]={0};
	int rsum[(int)s.size()+2]={0};
	for(int i = 1; i <= (int)s.size(); i++){
		if(s[i-1] == 'W')lsum[i]++;
		lsum[i] += lsum[i-1];
	}
	lsum[(int)s.size()+1] = lsum[(int)s.size()];
	for(int i = (int)s.size(); i; i--){
		if(s[i-1] == 'E')rsum[i]++;
		rsum[i] += rsum[i+1];
	}
	rsum[0] = rsum[1];
	int ans = INF;
	//for(int i = 0; i < (int)s.size()+2; i++)cout << lsum[i] << ' ' << rsum[i] << endl;
	for(int i = 0; i < (int)s.size(); i++){
		ans = min(ans, lsum[i]+rsum[i+2]);
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3076
<?php
while($num=trim(fgets(STDIN))){
    $num = array_map('intval',explode(" ",$num));
    if($num==[0,0])break;
    $n = $num[0];
    $x = $num[1];
    $count=0;
    for($i=1;$i<=$n;$i++){
        for($j=$i+1;$j<=$n;$j++){
            for($k=$j+1;$k<=$n;$k++){
                if(($i+$j+$k==$x) && ((($i!=$j) &&($j!=$k)) &&($i!=$k))){
                    $count++;
                }
            }
        }
    }
    echo $count."\n";
}
?>


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

int main() {
  int n; cin >> n;
  set<int> st;
  int tmp;
  rep(i,n) {
    cin >> tmp;
    st.insert(tmp);
  }
  if (st.size()==n) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 9600
import heapq
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
Tlist = [T-x * 0.006 for x in H]
ablist = [abs(A - x) for x in Tlist]
abheap = []
for i in range(N):
    heapq.heappush(abheap,(ablist[i], i))
ab, basho = heapq.heappop(abheap)
print(basho+1)

Measured memory_bytes: 3188
import java.util.Scanner

fun main(args: Array<String>){
    val scanner = Scanner(System.`in`)
    val sa = scanner.next()
    val sb = scanner.next()
    val a = Integer.parseInt(sa)
    val b = Integer.parseInt(sb)
    val aa = a*500
    if(aa >= b){
        println("Yes")
    } else {
        println("No")
    }
}

Measured memory_bytes: 29468
using System;
using System.Collections.Generic;

namespace MyProgram{
    class AtCoder{
        static void Main(){
            int[] input = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
            Array.Sort(input);
            int sum = 0;
            if((input[2]-input[0])%2 == 0){
                if((input[1]-input[0])%2==0){
                    sum = (2*input[2]-input[0]-input[1])/2;
                }else{
                    sum = (input[2]-input[0])/2 + (input[2]-input[1])/2 +2;
                }
            }else{
                if((input[2]-input[1])%2==0){
                    sum = (input[2]-input[0])/2 + (input[2]-input[1])/2 + 2;
                }else{
                    sum = (input[2]-input[0])/2 + (input[2]-input[1])/2 + 1;
                }
            }
            Console.WriteLine(sum);
        }
    } 
}

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

import math
import sys

A,B = input().split(" ")
s = str(input())

s_sp = s.split("-")

if (len(s_sp) != 2):
    print("No")
    sys.exit()

if (len(s_sp[0]) != int(A)) | (len(s_sp[1]) != int(B)):
    print("No")
    sys.exit()

if ((s_sp[0].isdigit()) & (s_sp[1].isdigit())):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		UINT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

void warshall_floyd(void);

ll d[10][10];	//d[i][j] i, j間の最短距離
void warshall_floyd( void )
{
	// Vは頂点数
	for (int i = 0; i < 10; i++) {			// 経由する頂点
		for (int j = 0; j < 10; j++) {		// 開始頂点
			for (int k = 0; k < 10; k++) {	// 終端
				d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
			}
		}
	}
}

int main()
{
	ll H = 0;
	ll W = 0;
	ll ret = 0;
	ll tmp = 0;

	cin >> H >> W;

	Rep(i, 10) {
		Rep(j, 10) {
			cin >> d[i][j];
		}
	}

	warshall_floyd();	// result is d[][]

	Rep(h, H) {
		Rep(w, W) {
			cin >> tmp;
			if ( 1 != tmp && -1 != tmp) {
				ret += d[tmp][1];
			}
		}
	}

	cout << ret << endl;

	return 0;
}





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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  int ans = 0;
  REPI(i, 1, N + 1) {
    if (i <= K) {
      ans += X;
    } else {
      ans += Y;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		String[] forecast = sc.next().split("");
		String[] actual = sc.next().split("");

		int count = 0;
		for (int i = 0; i < forecast.length; i++) {
			if (forecast[i].equals(actual[i])) {
				count++;
			}
		}
		System.out.println(count);

	}

}


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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
LL dp[(1<<12)+10];
int main()
{
    FastRead;
    LL n,m;
    cin>>n>>m;
    LL a[m+1],b[m+1],c[m+1];
    for(LL i=0; i<m; i++)
    {
        cin>>a[i]>>b[i];
        LL mask=0;
        for(LL j=0; j<b[i]; j++)
        {
            LL x;
            cin>>x;
            mask=mask|(1<<(x-1));
        }
        c[i]=mask;
    }
    for(LL i=0; i<(1<<n); i++)
        dp[i]=12345678;
    dp[0]=0;
    for(LL i=0; i<(1<<n); i++)
    {
        for(LL j=0; j<m; j++)
        {
            dp[i|c[j]]=min(dp[i|c[j]],dp[i]+a[j]);
        }
    }
//    for(LL i=0; i<(1<<n); i++)
//        cout<<dp[i]<<endl;
    if(dp[(1<<n)-1]==12345678)
        cout<<-1;
    else
        cout<<dp[(1<<n)-1];
}


Measured memory_bytes: 384
/*
これを入れて実行
g++ code.cpp
./a.out
*/

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = { -1, 0, +1, 0 };
int dx4[4] = { 0, +1, 0, -1 };
int dy8[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dx8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

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

ll lcm(ll a, ll b){
	return a / gcd(a, b) * b;
}

ll nCr(ll n, ll r){
	if (r == 0 || r == n){
		return 1;
	}
	else if (r == 1){
		return n;
	}
	return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
	r = n - r;
	ll ret = 1;
	for (ll i = n; i >= r + 1; i--) ret *= i;
	return ret;
}

//-----------------------ここから-----------

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

	string tgt = "keyence";

	for (int i = 0; i < s.size(); i++){
		for (int j = 0; j < s.size(); j++){
			if (i >= j) continue;
			if (s.substr(0, i + 1) + s.substr(j, s.size()) == tgt){
				cout << "YES" << endl;
				return 0;
			}
		}
	}

	cout << "NO" << endl;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;

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

    int n, m;
    cin >> n >> m;
    vector<P> A(m);
    map<int, vector<int>> mp1;
    map<P, int> mp2;
    for(int i = 0; i < m; i++){
        int p, y;
        cin >> p >> y;
        A[i] = {p, y};
        mp1[p].push_back(y);
    }

    for(auto &x : mp1){
        sort(x.second.begin(), x.second.end());
        int idx = 1;
        for(auto y: x.second){
            mp2[{x.first, y}] = idx;
            idx++;
        }
    }

    for(int i = 0; i < m; i++){
        P p = A[i];
        int f = p.first;
        int s = p.second;
        int c = mp2[p];
        cout << setfill('0') << right << setw(6) << f;
        cout << setfill('0') << right << setw(6) << c << endl;
    }

    return 0;
}

Measured memory_bytes: 19456
n = int(input())
h = list(map(int, input().split()))
dp = [0] * n
dp[0] = 0
for i in range(1, n):
    if i == 1:
        dp[i] = dp[0] + abs(h[i] - h[i - 1])
    else:
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))
print(dp[n - 1])

Measured memory_bytes: 13980
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int a[100'002];

int main()
{
    int n, x;
    cin >> n >> x;

    a[0] = a[n + 1] = 0;
    rep(i, n)
    {
        cin >> a[i + 1];
    }

    int64_t result = 0;
    irep(i, n)
    {
        int64_t s = (int64_t)a[i] + a[i + 1];
        int64_t b = max(s - x, 0L);
        a[i + 1] -= b;
        result += b;
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
    int a, b;
    int N;
    int s, f;
    int i;
    int flag;
    
    scanf("%d%d", &a, &b);
    
    scanf("%d", &N);
    flag = 0;
    for (i = 0; i < N; i++){
        scanf("%d%d", &s, &f);

        if (!(b <= s || f <= a)){
            flag = 1;
        }
    }
    
    if (flag == 1){
        printf("1\n");
    }
    else {
        printf("0\n");
    }
    
    return (0);
}




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

MOD = 10**9 + 7

def isValid(text) :  # 有効な4文字の文字列かチェック
    for i in range(4) :
        t = list(text)
        if i >= 1 :
            t[i] , t[i-1] = t[i-1] , t[i]  # swap
        if ''.join(t).count('AGC') >= 1 :
            return False
    return True

memo = [{} for _ in range(N+1)]

def search(currentIndex, prevText) :
    if currentIndex >= N :
        return 1
    if prevText in memo[currentIndex] :
        return memo[currentIndex][prevText]
    ret = 0

    for addText in 'ACGT' :
        if isValid(prevText + addText) :
            ret = (ret + search(currentIndex + 1,prevText[1:] + addText)) % MOD  # 左にシフト

    memo[currentIndex][prevText] = ret
    return ret

print(search(0,'ZZZ'))


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

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

    if(X < 600) cout << 8 <<endl;
    else if(X < 800) cout << 7 << endl;
    else if(X < 1000) cout << 6 << endl;
    else if(X < 1200) cout << 5 << endl;
    else if(X < 1400) cout << 4 << endl;
    else if(X < 1600) cout << 3 << endl;
    else if(X < 1800) cout << 2 << endl;
    else if(X < 2000) cout << 1 << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll r, g, b;

  cin >> r >> g >> b;
  ll num = 100*r + 10*g + b;
  if (num % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
     ll a,b,k;
    cin>>a>>b>>k;
    if(a<=k && (k-a)>=b)
    {
        cout<<"0"<<" "<<"0"<<endl;
    }
    else if(a<=k && (k-a)<b)
    {
        cout<<"0"<<" "<<b-(k-a)<<endl;
    }
    else if(a>k)
    {
        cout<<a-k<<" "<<b<<endl;
    }
    return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

const int INF = 1e9;

//テヲツ慊?・ツ、ツァテ」ツδ陛」ツδュテ」ツδシ
const int MAX_N = 510, MAX_K = 510;
const int MAX_V = 510 * 510;

struct edge{
    int to, cap, rev;
};

//vector<edge> G[MAX_N];
vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, int cap){
    G[from].push_back((edge){to, cap, (int)G[to].size()});
    G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}

int dfs(int v, int t, int f){
    if(v == t) return f;
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0){
            int d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t){
    int flow = 0;
    for(;;){
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if(f == 0) return flow;
        flow += f;
    }
}

//テ、ツコツ古ゥツδィテ」ツδ榲」ツδε」ツδ?」ツδウテ」ツつー
int N, K;
bool can[MAX_N][MAX_K];

int solve(){
    int s = N + K, t = s + 1;
    for(int i = 0; i < N; i++){
        add_edge(s, i, 1);
    }
    for(int i = 0; i < K; i++){
        add_edge(N + i, t, 1);
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < K; j++){
            if(can[i][j]){
                add_edge(i, N + j, 1);
            }
        }
    }
    return max_flow(s, t);
}

vector<int> prime_factor(int n){
	vector<int> res;
	for(int i=2;i*i<=n;i++){
        if(n % i == 0) res. push_back(i);
		while(n%i==0){
			n/=i;
		}
	}
	if(n!=1) res. push_back(n);
	return res;
}

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

signed main(){
    int m, n;
    while(1){
        cin >> m >> n;
        N = m; K = n;
        if(m + n == 0) break;
        // vector<edge> G[MAX_V];
        rep(i, 0, MAX_V) G[i].clear();
        rep(i, 0, 510) rep(j, 0, 510) can[i][j] = false;
        int b[510], r[510];
        // vector<int> bp[510], rp[510];
        rep(i, 0, m){
            cin >> b[i];
            // bp[i] = prime_factor(b[i]);
        }
        rep(i, 0, n){
            cin >> r[i];
            // rp[i] = prime_factor(r[i]);
        }
        rep(i, 0, m){
            // set<int> st;
            // rep(j, 0, bp[i].size()) st.insert(bp[i][j]);
            rep(j, 0, n){
                if(gcd(b[i], r[j]) != 1){
                    can[i][j] = true;
                    // can[j][i] = true;
                }
                // rep(k, 0, rp[j].size()){
                //     if(st.count(rp[j][k])){
                //         can[i][j] = true;
                //         break;
                //     }
                // }
            }
        }
        cout << solve() << endl;
    }
}

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

typedef long long LL;
#define MAXN 100010

int L[MAXN], R[MAXN];


struct nodeL
{
	int x;
	bool operator < (const nodeL &t)const
	{
		if (L[x] == L[t.x]) return x < t.x;
		return L[x] < L[t.x];
	}
};

struct nodeR
{
	int x;
	bool operator < (const nodeR &t)const
	{
		if (R[x] == R[t.x]) return x < t.x;
		return R[x] < R[t.x];
	}
};

set<nodeL> setL;
set<nodeR> setR;
 
void go(int &now, int &to, LL &tmp)
{
	int l = L[to], r = R[to];
	if (l <= now && now <= r) return;
	if (now < l) tmp += l - now, now = l;
	else if (now > r) tmp += now - r, now = r;
}
int main()
{
	//freopen("in.txt", "r", stdin);
	int n;	
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> L[i] >> R[i];
	
	LL ans = 0, tmp = 0;
	int now = 0, to;
	for (int i = 1; i <= n; ++i)
	{
		setL.insert((nodeL){i});
		setR.insert((nodeR){i});
	}
	for (int i = 1; i <= n; ++i)
	{
		//cout << setL.size() << " " << setR.size() << endl;
		if (i & 1)
		{
			to = (*setL.rbegin()).x;
			setL.erase((nodeL){to});
			setR.erase((nodeR){to});
		}
		else
		{
			to = (*setR.begin()).x;
			setL.erase((nodeL){to});
			setR.erase((nodeR){to});
		}
	//	cout << to << endl;
		//cout << now << " " << tmp << endl;
		go(now, to, tmp);
	}
	tmp += abs(now);
	ans = max(ans, tmp);
	now = 0; tmp = 0;
	for (int i = 1; i <= n; ++i)
	{
		setL.insert((nodeL){i});
		setR.insert((nodeR){i});
	}
	for (int i = 1; i <= n; ++i)
	{
		if (!(i & 1))
		{
			to = (*setL.rbegin()).x;
			setL.erase((nodeL){to});
			setR.erase((nodeR){to});
		}
		else
		{
			to = (*setR.begin()).x;
			setL.erase((nodeL){to});
			setR.erase((nodeR){to});
		}
	//	cout << to << endl;
		go(now, to, tmp);
		//cout << now << " " << tmp << endl;
	}
	tmp += abs(now);
	ans = max(ans, tmp);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12416
n=int(input())
g={}
ans=0
for i in map(int,input().split()):
    if g.get(i):g[i]+=1
    else:g[i]=1
    ans+=i
for i in range(int(input())):
    b,c=map(int,input().split())
    if g.get(b):
        cnt=g.pop(b)
        if g.get(c):g[c]+=cnt
        else:g[c]=cnt
        ans-=cnt*b
        ans+=cnt*c
    print(ans)

Measured memory_bytes: 21912