akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        HashMap<Integer, Integer> map = new HashMap<>();
        int prevIndex = 0;
        int currIndex = 0;
        int index = 0;
        while(currIndex < str.length()) {
            while(str.charAt(currIndex) == 'R') currIndex++;
            index = currIndex - 1;
            while(currIndex < str.length() && str.charAt(currIndex) == 'L') currIndex++;
            int leftNum = index - prevIndex;
            int rightNum = currIndex - index - 2;
            map.put(index, (leftNum / 2) + (int)(Math.ceil(rightNum / 2.0)) + 1);
            map.put(index+1, (int)(Math.ceil(leftNum / 2.0)) + (rightNum / 2) + 1);
            prevIndex = currIndex;
        }
        for(int i = 0; i < str.length(); i++) {
            if(map.containsKey(i)) System.out.print(map.get(i) + " ");
            else System.out.print("0 ");
        }
        System.out.println();
    }
}


Measured memory_bytes: 51096
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

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

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

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: i32,
    r: i32,
  }

  if n >= 10 {
    puts!("{}\n", r);
  } else {
    puts!("{}\n", r + 100 * (10 - n));
  }
}


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


typedef long long ll;


int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	ll ans = 0;

	for (int i = 0; i < 60; ++i) {
		vector<ll> count(2);
		for (int j = 0; j < n; ++j)
			count[(a[j] >> i) & 1]++;
		ll mod = 1000000007;
		ll s = count[0] * count[1];
		s %= mod;
		for (int j = 0; j < i; ++j) {
			s *= 2;
			s %= mod;
		}
		ans += s;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

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

int main ( ){
    int N, A, B;
    cin >> N>> A >> B;

    if(N*A==B) {
        cout << B << endl;
    }
    else if(N*A>=B) {
        cout << B << endl;
    }
    else {
        cout << N*A << endl;
    }
}
    





Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);
//const ll mod = 998244353;

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


int main(void)
{
    ll n,ans=0;
    cin >> n;
    map<ll,ll> mp;
    rep(i,n){
        ll a;
        cin >> a;
        mp[a]++;
    }
    for(auto i:mp){
        if(i.second-i.first >= 0) ans += i.second-i.first;
        else ans += i.second;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){

    int N;
    cin >> N;
    int A[N];
    for(int i = 0;i < N;i++) cin >> A[i];

    int i=0,count=0,Button[N],k = 0;

    for(int i = 0;i <N;i++) Button[i] = -1;

    //bool stat = false;
    while(A[i] != 2){
        Button[i] ++;
        if(Button[i] == 1){
            count = -2;
            break;
        }
        i = A[i] -1;
        count ++;
        if(A[i] == 2) break;
/*
        for(int j=0;j<=k;j++){
            if(A[i] == Button[j]){
                count = -2;
                stat = true;
                break;
            }
        }
        if(stat) break;
        k++;
        */
    }

    count ++;
    if(A[i] == 1) count=-1;
    

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
    int A,B,C,K;
    cin >> A >> B >> C;
    cin >> K;   
    int D = max(max(A,B),C);
    for(int i=0; i<K; i++)
    {
    	D *= 2;
    }
    D -= max(max(A,B),C);
    cout << A + B + C + D <<endl;

	return 0;
}

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

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

using ll = long long;
using graph = vector<vector<int>>;

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

int main() {
  int N;
  cin >> N;
  vector<pair<int,int>> v(N-1);
  graph g(N);
  vector<vector<int>> ap(N);
  for(int i = 0; i < N-1; i++) {
    int x, y;
    cin >> x >> y;
    v[i]=make_pair(x-1,y-1);
    g[x-1].push_back(y-1);
    g[y-1].push_back(x-1);
    ap[x-1].push_back(i);
    ap[y-1].push_back(i);
  }
  int num = 0;
  for(int i = 0; i < N; i++) {
    chmax(num,(int)g[i].size());
  }
  cout<<num<<endl;
  vector<vector<bool>> cnt(N,vector<bool>(num+1));
  queue<int> q;
  q.push(0);
  vector<bool> seen(N,false);
  seen[0]=true;
  vector<int> col(N-1);
  while(!q.empty()){
    int t = q.front();
    q.pop();
    for(auto nv:g[t]){
      int k=0;
      if(seen[nv]) continue;
      seen[nv] = true;
      q.push(nv);
      for(auto i:ap[t]){
        if(v[i].first==nv||v[i].second==nv) {
          k=i;
          break;
        }
      }
      for(int i = 1; i <= num ; i++) {
        if(cnt[t][i]||cnt[nv][i]) continue;
        cnt[t][i]=true;
        cnt[nv][i]=true;
        col[k]=i;
        break;
      }
    }
  }
  for(int i = 0; i <N-1; i++) {
    cout<<col[i]<<endl;
  }
}

Measured memory_bytes: 319992
/* AtCoder Regular Contest 082. Task D, by Abreto<m@abreto.net>. */
#include <bits/stdc++.h>

using namespace std;
#define MAXN    100001

int N;
int p[MAXN];
int cnt;

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


Measured memory_bytes: 640
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int num[114514];
int main()
{
	string s,t="Z";
	cin>>s;
	s="Z"+s+"Z";
	int n=0,now=0,out=0;
	REP(i,1,s.size()){
		if(s[i]=='x') now++;
		else{
			t+=s[i];num[n]=now;now=0;n++;
		}
	}
	string u=t;reverse(All(t));
	if(u!=t){
		cout<<-1<<endl;return 0;
	}
	rep(i,n){
		out+=abs(num[i]-num[n-1-i]);
	}
	//rep(i,n) cout<<num[i]<<endl;
	cout<<out/2<<endl;
}


Measured memory_bytes: 1020
N, M = map(int, input().split())
people = [list(map(int, input().split())) for i in range(N)]
point = [list(map(int, input().split())) for i in range(M)]
ans = [-1] * N
def calc_dist(a, b):
    return abs(a[0] - b[0]) + abs(a[1] - b[1])


for i in range(len(people)):
    tmp = 1000000000
    for j in range(len(point)):
        dist = calc_dist(people[i], point[j])
        if dist < tmp:
            ans[i] = j
            tmp = dist

for i in ans:
    print(i+1)

Measured memory_bytes: 39664
using System;
using System.Collections.Generic;
using System.Text;

class Program {

	public void Proc() {
		string[] inpt1 = Console.ReadLine().Split(' ');
		int w = int.Parse(inpt1[0]);
		int h = int.Parse(inpt1[1]);
		int n = int.Parse(inpt1[2]);

		int[,] array = new int[w, h];

		for (int i = 0; i < n; i++) {
			string[] inpt2 = Console.ReadLine().Split(' ');
			array = Nurie(array, int.Parse(inpt2[0]), int.Parse(inpt2[1]), int.Parse(inpt2[2]));
		}

		int ans = GetAnswer(array, w*h);
		Console.WriteLine(ans);
	}

	public static int[,] Nurie(int[,] array, int x, int y, int type) {
		int xlen = array.GetLength(0);
		int ylen = array.GetLength(1);
		int[] v = new int[4];
		switch(type) {
			case 1:
				v[1] = ylen;
				v[3] = x;
				break;
			case 2:
				v[1] = ylen;
				v[2] = x;
				v[3] = xlen;
				break;
			case 3:
				v[1] = y;
				v[3] = xlen;
				break;
			case 4:
				v[0] = y;
				v[1] = ylen;
				v[3] = xlen;
				break;
		}
		for (int i = v[0]; i < v[1]; i++) {
			for(int j = v[2]; j < v[3]; j++) {
				array[j,i] = 1;
			}
		}
		return array;
	}

	public static int GetAnswer(int[,] array, int areaSize) {
		int cnt = 0;
		foreach(int i in array) {
			if (i == 1) {
				cnt++;
			}
		}
		return areaSize - cnt;
	}

	static void Main(string[] args) {
		Program prg = new Program();
		prg.Proc();
	}
}


Measured memory_bytes: 2776
#include <cstdio>
using namespace std;

int log(int a, int X){
	int n = 0;
	
	while(X > 0){
		X /= a;
		n++;
	}
	
	return n;
}

int main(){
	int a, b, sum;
	
	while(scanf("%d%d", &a, &b) != EOF){
		
		sum = a + b;
		
		printf("%d\n", log(10, sum));
	}
	
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;

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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
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 string dir = "DRUL";
*/
void pushback(string& s, char c){
    s.push_back(c);
}
void pushtop(string& s, char c){
    string tmp = "";
    tmp.push_back(c);
    s = tmp + s;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    string S;
    cin>>S;
    int Q;
    cin>>Q;
    int cnt = 0;
    deque<string> deq;
    deq.push_back(S);
    while(Q--){
        int q;
        cin>>q;
        if(q == 1){
            cnt++;
        }
        else{
            int f;char c;
            cin>>f>>c;
            if(cnt % 2 == 0){
                if(f == 1){
                    string tmp = "";
                    tmp.push_back(c);
                    deq.push_front(tmp);
                }
                else{
                    //pushback(S, c);
                    string tmp = "";
                    tmp.push_back(c);
                    deq.push_back(tmp);
                }
            }
            else{
                if(f == 1){
                    //pushback(S, c);
                    string tmp = "";
                    tmp.push_back(c);
                    deq.push_back(tmp);
                }
                else{
                    //pushtop(S, c);
                    string tmp = "";
                    tmp.push_back(c);
                    deq.push_front(tmp);
                }
            }
        }
        /*
        for_each(deq.begin(), deq.end(), [](string x) {
            cerr << x;
        });
        cerr<<endl;
        */
    }
    if(cnt % 2 == 1){
        for_each(deq.rbegin(), deq.rend(), [](string& x) {
            if(x.size() > 1){
                rep(i,(int)x.size()){
                    cout<<x[(int)x.size()-1-i];
                }
            }
            else cout << x;
        });
        cout<<endl;
    }
    else{
        for_each(deq.begin(), deq.end(), [](string& x) {

            cout << x;
        });
        cout<<endl;
    }
}

Measured memory_bytes: 11728
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

const int MAXN = 100000;
const ll inf = 1e9+1;

ll dp[MAXN][2];

ll solve(int i, int sign);

int N;
vector<ll> seq;

int main() {
    ios_base::sync_with_stdio(false);
    for (int i=0; i < MAXN; ++i) {
        dp[i][0] = dp[i][1] = -inf;
    }
    
    cin >> N;
    seq = vector<ll>(N);
    
    for (int i=0; i < N; ++i) cin >> seq[i];
    
    cout << solve(0, 0) << endl;
    return 0;
}


ll solve(int i, int sign) {
    int k = 1;
    if (sign) k = -1;
    
    if (i == N-2) {
        return max((k*seq[i]+seq[i+1]), -(k*seq[i]+seq[i+1]));
    }
    
    if (dp[i][sign] != -inf) return dp[i][sign];

    ll t1 = solve(i+1, 1), t2= solve(i+1, 0);
    
   // cout << i << " " << sign << " " << t1 << " " << t2 << endl;
    
    return (dp[i][sign] = max((-1 * k * seq[i]+ t1), ((k*seq[i] + t2))));
}


Measured memory_bytes: 7296
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int n = scan.nextInt();
		int d = s.length();

		int dp[][][] = new int[d+1][2][5];
		dp[0][0][0] = 1;

		for(int i = 0; i < d; i++){
			int k = s.charAt(i)-'0';
			for(int small = 0; small < 2; small++){
				for(int not0 = 0; not0 < 5; not0++){
					for(int j = 0; j <= ((small == 1)?9:k); j++){
						if(small == 1 || (j < k)){
							if(not0 == 4 || j == 0){
								dp[i + 1][1][not0] += dp[i][small][not0]; 
							}
							else{
								dp[i + 1][1][not0+1] += dp[i][small][not0]; 
							}
						}
						else{
							if(not0 == 4 || j == 0){
								dp[i + 1][0][not0] += dp[i][small][not0]; 
							}
							else{
								dp[i + 1][0][not0+1] += dp[i][small][not0]; 
							}
						}
					}
				}
			}
		}
		System.out.println(dp[d][1][n] + dp[d][0][n]);
	}
}

Measured memory_bytes: 21972
#include <stdio.h>

int main(){
	int n;
	scanf("%d", &n);
	char inp[10001];
	scanf("%s", inp);

	for(int i=0; inp[i]!='\0';i++){
		if(inp[i]+n>'Z'){
			inp[i]=inp[i]+n-26;
		}else{
			inp[i]+=n;
		}
	}
	printf("%s", inp);
	return 0;
}

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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int a,b; cin >> a >> b;
  int ans = -INF;
  ans = max(ans,a+b);
  ans = max(ans,a-b);
  ans = max(ans,a*b);

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


Measured memory_bytes: 3588
#include <cstdio>
#include <cstring>
const int N = 2e5 + 100;
int num[N], data[N * 2], n, m, a[N], *cnt = data + N;

int main() {
#ifdef lol
	freopen("t.in", "r", stdin);
	freopen("t.out", "w", stdout);
#endif

	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
		++num[a[i]];
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j < num[i]; ++j)
			++cnt[i - j];
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		if (!cnt[i]) ++ans;
	while (m--) {
		int u, v, t;
		scanf("%d%d", &u, &v);
		t = a[u];
		--cnt[t - num[t] + 1];
		if (t - num[t] + 1 > 0  && cnt[t - num[t] + 1] == 0)
			++ans;
		--num[t];
		++cnt[v - num[v]];
		if (v - num[v] > 0 && cnt[v - num[v]] == 1)
			--ans;
		++num[v];
		a[u] = v;
		printf("%d\n", ans);
	}
	
	return 0;
}


Measured memory_bytes: 3840
import math
def f(n):
    return math.factorial(n)
n,a,b=map(int,input().split())
V=[int(i) for i in input().split()]
V.sort()
if n==a:
  print(sum(V)/a)
  print(1)
else:
  ans=sum(V[n-a:])/a
  count1=V[n-a:].count(V[n-a])
  count2=V[:n-a].count(V[n-a])
  print(ans)
  if count1==a:
    ans2=0
    for i in range(min(count2+1,b-a+1)):
      ans2+=f(count1+count2)/f(count1+i)/f(count2-i)
    print(round(ans2))
  else:
    print(round(f(count1+count2)/f(count1)/f(count2)))

Measured memory_bytes: 3064
#include"iostream"

using namespace std;

int main()
{
	int r, d,x;
	cin >> r >> d >> x;
	int xx[11] = { 0 };
	xx[0] = x;
	for (int i =1; i < 11; i++)
	{
		xx[i ] = r * xx[i-1] - d;
		cout << xx[i] << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

string s;
ll n,ans=0;

void dfs(ll x,ll y,ll z){
  if(x==n){
    ans += y+z;
  }else{
    dfs(x+1,y+z,s[x+1]-'0');
    dfs(x+1,y,10*z+s[x+1]-'0');
  }
}
 
int main(){
    string s;
    cin >> s;
    ll ans=0;
    for (int bit = 0; bit < (1<<(s.size()-1));bit++){
        vector<ll> x;
        for (ll i=0;i<s.size();i++) {
            if (bit & (1<<i)) {
                x.push_back(i);
            }
        }
        bool z[s.size()];
        fill(z,z+s.size(),false);
        for (ll i=0;i<x.size();i++){
            z[x[i]]=true;
        }
        ll count=s[0]-'0';
        for (ll i=1;i<s.size();i++){
            if (z[i-1]){
                count=count*10+(s[i]-'0');
            }else{
                ans+=count;
                count=s[i]-'0';
            }
        }
        ans+=count;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int a[3];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  FOR(i, 0, 3) cin >> a[i];
  sort(a, a+3);
  cout << (a[2]==a[1]+a[0] ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  ITP1_10-D
//
//  Created by ?????¶??? on 15/8/15.
//  Copyright (c) 2015??´ ?????¶???. All rights reserved.
//

#include <iostream>
#include <cmath>
#include <vector>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main() {

    int n;
    cin >> n;
    
    double x[n],y[n];
    
    for (int i = 0; i < n; ++i) {
        cin >> x[i];
    }
    
    for (int i = 0; i < n; ++i) {
        cin >> y[i];
    }
    
    // p = 1 ???????????????????????¢
    
    double result_1 = 0;
    for (int i = 0; i < n; i++) {
        
        result_1 += abs(x[i] - y[i]);
    }
    
    
    // p = 2 ???????????????????????¢
    
    double result_2 = 0;
    for (int i = 0; i < n; i++) {
        result_2 +=  pow(abs(x[i] - y[i]), 2.0);
    }
    
    result_2 = sqrt(result_2);
    
    // p = 3
    
    double result_3 = 0;
    for (int i = 0; i < n; i++) {
        result_3 += pow(abs((x[i] - y[i])), 3.0);
    }
    result_3 = cbrt(result_3);
    
    // max ?????§????????§????????¢
    vector<double> tempList;
    
    for (int i = 0; i < n; i++) {
        
        double temp = abs(x[i] - y[i]);
        tempList.push_back(temp);
    }
    
 
    auto it = max_element(tempList.begin(), tempList.end());
    double result_4 = *it;
    
    printf("%.6f\n", result_1);
    printf("%.6f\n", result_2);
    printf("%.6f\n", result_3);
    printf("%.6f\n", result_4);
    
    return 0;
}

Measured memory_bytes: 1340
S = str(input())  # 'abcdef'
T = str(input())  # 'acd'

N = len(T)

s_list = []
for i in range(len(S) - N + 1):
    s = S[i:i + N]
    s_list.append(s)
# s_list -> 'abc', 'bcd', 'cde', 'def'

answer = N  # 全文字入れ替えが最大値なので初期値として設定
for s in s_list:
    counter = 0  #  入れ替え文字数カウント用
    # 一文字ずつ比較して、違ったら入れ替えないといけないのでカウント
    for i in range(N):
        if s[i] != T[i]:
            counter += 1
    answer = min(answer, counter)  # 入れ替え文字数が少ない方を採用

print(answer)


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

// 参考:http://drken1215.hatenablog.com/entry/2019/09/16/014600
int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<vector<int>> dp(n+1, vector<int>(n+1));

	// dpテーブルをつくる
	// dp[i][j] i文字目からとj文字目からとの最長の長さ
	// 後ろから見ていく

	for(int i=n-1;i>=0;i--){
		for(int j=n-1;j>=0;j--){
			if(s[i]==s[j]) dp[i][j]=dp[i+1][j+1]+1;
		}
	}

	// 入力例　10 abcdabcdab
	//   a b c d a b c d a b
	// a10 0 0 0 6 0 0 0 2 0
	// b 0 9 0 0 0 5 0 0 0 1
	// c 0 0 8 0 0 0 4 0 0 0
	// d 0 0 0 7 0 0 0 3 0 0
	// a 6 0 0 0 6 0 0 0 2 0
	// b 0 5 0 0 0 5 0 0 0 1
	// c 0 0 4 0 0 0 4 0 0 0
	// d 0 0 0 3 0 0 0 3 0 0
	// a 2 0 0 0 2 0 0 0 2 0
	// b 0 1 0 0 0 1 0 0 0 1

	// この入力例の時答えは4になるはずである
	// 4より大きい値がdpテーブルに乗るのは文字の被りを許しているから
	// 例えばdp[1][5]=5は".bcdabcdab"と".....bcdab"のペアの一致数
	// 一つ目の文字列の文字被り部分をxに置き換えると ".bcdaxxxxx"
	// このようにj-i文字部分のみとをマッチしているか見ればよい
	// 文字被りがあればj-i文字が最大となり被りがなければそのままdp[i][j]が最大

	int ans = 0;
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			if(dp[i][j]<=j-i) ans=max(ans, dp[i][j]);
		}
	}

	cout<<ans<<endl;
}


Measured memory_bytes: 98176
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
const long long mod = 1000000007;
int main(){
  long long n, m;
  cin >> n >> m;
  if(n - m >= 2 || n - m <= -2){
    cout << 0 << endl;
    return 0;
  }
  long long ans = 1;
  FOR(i,1,n+1){
    ans *= i;
    ans %= mod;
  }
  FOR(i,1,m+1){
    ans *= i;
    ans %= mod;
  }
  if(n == m) ans *= 2;
  cout << ans % mod << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int n, q;
vvint e;
vint t, ans;

void dfs(int pos, int ps, int par){
    ans[pos] = ps + t[pos];
    rep(i, e[pos].size()){
        if(e[pos][i] != par){
            dfs(e[pos][i], ans[pos], pos);
        }
    }
    return;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    cin>>n>>q;
    e = vector<vint>(n);
    t = vint(n, 0);
    ans = vint(n, 0);
    rep(i, n-1){
        int a,b;cin>>a>>b;
        e[a-1].push_back(b-1);
        e[b-1].push_back(a-1);
    }
    rep(i, q){
        int p,x;cin>>p>>x;
        t[p-1] += x;
    }
    dfs(0, 0, -1);
    rep(i, n){
        if(i!=0){
            cout << ' ';
        }
        cout << ans[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 24320
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,n;
    cin>>m>>n;
    for(int i=0;i<=m;i++)
     for(int j=0;j<=m;j++)
      for(int k=0;k<=m,i+j+k<=m;k++)
            if(i+j+k==m&&i*1000+j*5000+k*10000==n){
                cout<<k<<" "<<j<<" "<<i<<"\n";
                return 0;   
            }
    cout<<"-1 -1 -1\n";
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = Integer.parseInt(scanner.nextLine()); // 500
        int b = Integer.parseInt(scanner.nextLine()); // 100
        int c = Integer.parseInt(scanner.nextLine()); //  50
        int x = Integer.parseInt(scanner.nextLine());

        int answer = 0;
        for (int i = 0; i <= a; i++) {
            for (int j = 0; j <= b; j++) {
                for (int k = 0; k <= c; k++) {
                    if (i * 500 + j * 100 + k * 50 == x) {
                        answer++;
                    }
                }
            }
        }

        System.out.println(answer);
        scanner.close();
    }
}


Measured memory_bytes: 26988
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

int main()
{
    ll W, H;
    while (cin >> W >> H)
    {
        if (W == 0 && H == 0)
        {
            break;
        }
        repi(i, W, 0)
        {
            repi(j, H, 0)
            {
                cout << ((i + j) % 2 == 0 ? "#" : ".");
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3104
k,s=map(int,input().split())
u=min(k,s)
sum=0
if s-2*k>=0:
    for i in range(s-2*k,u+1):
        if s-i<2*k:
            sum+=2*k-s+i+1
        else:
            sum+=1
    print(sum)
elif s-k>=0:
    for i in range(u+1):
        if s-i<k:
            sum+=s-i+1
        else:
            sum+=2*k-s+i+1
    print(sum)
else:
    for i in range(u+1):
        if s-i<2*k:
            sum+=s-i+1
        else:
            sum+=1
    print(sum)




Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		long total = 0;
		
		for(int i = 1; i <= n; i++) {
			if(i % 3 != 0 && i % 5 != 0) {
				total += i;
			}
		}
		
		System.out.println(total);
	}

}


Measured memory_bytes: 27180
#include<iostream>
#include<string>
#include<random>
#include<chrono>
#include<map>
#include<fstream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const long long mod = 1000000007;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
int bp(int i, int j) {
	if (i) {
		if (i + 1 >= pow(2, j + 1))
		{
			if (i + 3 == pow(2, j + 2)) return pow(2, j + 1) - 1;
			else return pow(2, j) + bp(i - pow(2, j + 1) + 1, j - 1);
		}
		else return bp(i - 1, j - 1);
	}
	else return 0;
}
signed main() {
	int N, X;
	cin >> N >> X;
	cout << bp(X, N) << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
k = int(input())
x = list(map(int, input().split())) 
a = 0
l = 0
while n>a:
    if (k/2)>=x[a]:
        l+=2*x[a]
        a+=1
    else:
        l+=2*(k-x[a])
        a+=1
else:
    print(l)



Measured memory_bytes: 2940
import copy

n, q = map(int, input().split())
s = input()

cnt = [0]
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        cnt.append(cnt[-1] + 1)
    else:
        cnt.append(cnt[-1])

for i in range(q):
    l, r = map(int, input().split())
    print(cnt[r-1] - cnt[l-1])

Measured memory_bytes: 11768
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    char N[5];

    scanf("%s", N);

    int A, B, C, D;

    A = N[0] - '0';
    B = N[1] - '0';
    C = N[2] - '0';
    D = N[3] - '0';

    if(A + B + C + D == 7){
        printf("%d+%d+%d+%d=7\n", A, B, C, D);
    }else if(A + B + C - D == 7){
        printf("%d+%d+%d-%d=7\n", A, B, C, D);
    }else if(A + B - C + D == 7){
        printf("%d+%d-%d+%d=7\n", A, B, C, D);
    }else if(A - B + C + D == 7){
        printf("%d-%d+%d+%d=7\n", A, B, C, D);
    }else if(A + B - C - D == 7){
        printf("%d+%d-%d-%d=7\n", A, B, C, D);
    }else if(A - B + C - D == 7){
        printf("%d-%d+%d-%d=7\n", A, B, C, D);
    }else if(A - B - C + D == 7){
        printf("%d-%d-%d+%d=7\n", A, B, C, D);
    }else{
        printf("%d-%d-%d-%d=7\n", A, B, C, D);
    }

    return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
#define ll long long
bool prime(int n)
{
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0)return false;
    }
    return true;
}
int main()
{
    int mod=1e9+7;
    int n;cin>>n;
    ll res=1;
    for(int i=2;i<=n;i++)
    {
        if(prime(i)==true)
        {
            ll z=n;
            ll cnt=0;
            while(z>0)
            {
                cnt+=z/i;
                z/=i;
            }
            res=(res*(cnt+1))%mod;
        }
    }
        cout<<res<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,L;
  cin>>N>>L;
  int sum=N*(2*L+N-1)/2;
  int ans;
  
  if(L<=0&&L+N-1>=0){
    cout<<sum<<endl;
  }
  else{
  if(abs(L)<abs(L+N-1)){
    ans=sum-L;
  }
  else {
ans=sum-(L+N-1);
  }
  
  cout<<ans<<endl;
}
}


      
      
    
    
  

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

#define ll long long
#define ld long double
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define sz(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/

using namespace std;

	map <int,bool> m;
int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n,k,cnt=0;
	cin >>n >>k; int i,j,a,d;
	for (i=0;i<k;i++) {
		cin>>d;
		for (j=0;j<d;j++) {
			cin >>a;
			m[a]=1;
		}
	}
	for (i=1;i<=n;i++) {
		if (m[i]==0)
		cnt++;
	}
	cout <<cnt;
	return 0;
}
/******************************************************************************
******************************************************************************/


Measured memory_bytes: 3640
#include<iostream>
#include<vector>
#include<cmath>
#include<utility>
using namespace std;
typedef long long LL;
#define F first
#define S second

int main() {
	LL a, b;
	cin >> a >> b;
	if (abs(a - b) >= 2)cout << "Alice" << endl;
	else cout << "Brown" << endl;
	return 0;
}

Measured memory_bytes: 256
/*

Author: @karngyan
Team: BlundersPride

*/

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
using namespace std;

using ll = long long;
using ld = long double;
using vll = std::vector< ll >;
using pll = std::pair< ll, ll >;
using vvll = std::vector<vll>;
using vpll = std::vector< pll >;


#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define eb emplace_back
#define rep(i, begin, end) for(__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define max3( a, b, c ) max( a , max(b , c))
#define cres(c,n) (c).clear(),(c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define cntll(a) __builtin_popcountll((a))
#define ff first
#define ss second
#define mk make_pair
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it){}
template<typename T , typename... Args>
void err(istream_iterator<string> it , T a , Args... args)
{
	cerr << *it << " = " << a << endl;
	err(++it , args ... );
}

ll sum(){ return 0; }
template<typename T, typename... Args>
auto sum(T a, Args... args){ return a + sum(args...);}
const ll MOD = 1e9+7;
////////////////////////////////////////////////////////////////////////////////////////////////////////


signed main()
{
	fast;
////////////////////////////////////////////////////////////////////////////////////////////


	ll n , m;
	cin >> n >> m;
	vll l(m) , r(m);
	
	ll x = 0 ,y = 0;
	rep(i,0,m){
		cin >> l[i] >> r[i];
		l[i]--, r[i]--;

		if(i == 0){
			x = l[i] , y = r[i];
		}
		else{
			x = max(x , l[i]);
			y = min(y , r[i]);
		}
	}

	ll ans = y - x + 1;
	if(ans <= 0)
		ans = 0;
	cout<<ans<<endl;

	
	return 0;
}




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

int main(){
  char str[10005];
  int N,i;
  scanf("%d%s",&N,str);
  for(i = 0;str[i];i++){
    str[i] = 'A' + (str[i] - 'A' + N) % 26;
  }
  printf("%s",str);
}

Measured memory_bytes: 128
import itertools

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

l = []
k = []
for i in range(1, N+1):
    l.append(str(i))

for i in range(K):
    d = int(input())
    array = input().strip().split()
    k.append(array)
                
k = list(itertools.chain.from_iterable(k))

k = [x for x in set(k) if k.count(x) >= 1]

for i in range(len(k)):
    for j in range(len(l)):
        if k[i] == l[j]:
            l[j] = 0

cnt = 0

for i in l:
    if i == 0:
        cnt += 1

print(len(l) - cnt)

Measured memory_bytes: 67876
import sys
n = int(input())
h = list(map(int, input().split()))

if n==1:
  print("Yes")
  sys.exit(0)
elif n==2:
  if h[0]-1 > h[1]:
    print("No")
  else:
    print("Yes")
  sys.exit(0)

diff = [h[i+1]-h[i] for i in range(n-1)]

#連続減少の確認
flag = False

for d in diff:
  if d<0:
    if flag==True:
      print("No")
      sys.exit(0)
    else:
      flag=True
  elif d>0:
    flag=False
    
#print(diff)

if min(diff) < -1:
  print("No")
else:
  print("Yes")


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

bool judgeKaibun(int x){
    int x1=x,y=0,z=0;
    bool kaibun=false;
    for(int i=0;i<5;i++){
        y=x%10;
        z+=y*pow(10,4-i);
        x/=10;
    }
    if(x1==z)kaibun=true;
    
    return kaibun;
}

int main(){
    int a,b;
    cin >> a >> b;
    int res;
    for(int i=a;i<=b;i++){
        if(judgeKaibun(i)==true)res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
import math
while 1:
    e = int(input().strip())
    if e ==0:break
    m=e
    z =0
    while z**3 <= e:
        y = int(math.sqrt(e-z**3))
        x = e - y**2- z**3 
        if x < 0:break
        if m > x+y+z: m = x+y+z    
        z+=1
    print(m)
        


Measured memory_bytes: 5672
#include<stdio.h>
int main()
{
    int day,rank,x,y,sum,r,r2;
    scanf("%d %d",&day,&rank);
    scanf("%d %d",&x,&y);
    if(day<rank){
        printf("%d",day*x);
    }
    else {
    sum=rank*x;
    r=day-rank;
    r2=r*y;
    printf("%d",sum+r2);
    }


}


Measured memory_bytes: 128
from collections import Counter
input()
angles = sorted(((key, value) for key, value in Counter(map(int, input().split())).items() if value > 1), key=lambda t: t[0])
try:
    square = angles[-1][0] ** 2 if angles[-1][1] > 3 else angles[-1][0] * angles[-2][0]
except:
    square = 0
print(square)

Measured memory_bytes: 24104
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(ll &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
ll a[4],n,res=6e18;
ll solve(ll n, int S){
	assert((S>>2&1)&&(S>>3&1));
	ll res=0;
	/*if(S>>3&1)res+=n/8*a[3],n%=8;
	if(S>>2&1)res+=n/4*a[2],n%=4;
	if(S>>1&1)res+=n/2*a[1],n%=2;
	if(S>>0&1)res+=n/1*a[0],n%=1;*/
	res+=n/8*a[3],n%=8;res+=n/4*a[2],n%=4;
	return res;
}
int main() {
	rep(i,0,3)read(a[i]);rep(i,1,3)a[i]=min(a[i],a[i-1]*2);
	read(n);
	n*=4;
	cout<<solve(n,15);
	return 0;
}


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

typedef long long ll;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    REP(i, N) cin >> A[i] >> B[i];

    ll res = 0;
    for(int i=N-1;i>=0;i--){
        ll tmp = (A[i]+res)%B[i];
        tmp = (tmp==0?tmp:B[i]-tmp);
        res += tmp;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
da = list(map(int,input().split()))

k = [[0 for i in range(2)]for j in range(10001)]
i = 0
su = 0
j = 0

while da[0] + da[1] != 0:
	i = 0
	su = 0
	j = 0
	for i in range(da[0]):
		k[i][0],k[i][1] = map(int,input().split())


	k = sorted(k,key = lambda x: x[1],reverse = True)

	while j != i + 1:
		if da[1] > k[j][0]:
			da[1] -= k[j][0]
			j += 1
		elif da[1] <= k[j][0] and da[1] > 0:
			su += (k[j][0] - da[1]) * k[j][1]
			da[1] = 0
			j += 1
		else:
			su += k[j][0] * k[j][1]
			j += 1

	print(su)

	da = list(map(int,input().split()))

	k = [[0 for i in range(2)]for j in range(10001)]



Measured memory_bytes: 8204
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String input = sc.next();
		int red = 0;
		int blue = 0;
		while (input.length() != 1) {
			if (input.charAt(0) == '0') {
				red++;
			} else {
				blue++;
			}
			input = input.substring(1);
		}
		if (input.charAt(0) == '0') {
			red++;
		} else {
			blue++;
		}
		int ans = 0;
		if (red > blue) {
			ans = blue * 2;
		} else {
			ans = red * 2;
		}
		System.out.println(ans);
		
	}

}


Measured memory_bytes: 346556
#include <iostream>
using namespace std;
typedef long long ll;

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

    if(x - (k-1) < -1000000) {
        for(int i = -1000000; i < x + k; i++) {
            if(i != -1000000) cout << " ";
            cout << i;
        }
        cout << endl;
    }
    else if(1000000 < x + k -1) {
        for(int i = x-(k-1); i < 1000001; i++) {
            if(i != x -(k-1)) cout << " ";
            cout << i;
        }
        cout << endl;
    }
    else {
        for(int i = x - (k-1); i < x + k; i++) {
            if(i != x - (k-1)) cout << " ";
            cout << i;
        }
        cout << endl;
    }
    return 0;
}


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

#define sc scanf
#define pf printf
#define CIN ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ull unsigned long long int
#define ll  long long int
#define db double
#define fl float
#define vi vector<int>
#define vl vector<ll>
#define qin queue<int>
#define pb push_back
#define pob pop_back
#define ft front
#define bk back
#define mp make_pair
#define pii pair<int,int>
#define all(c) c.begin(), c.end()
#define MOD 1000000007
#define pll __builtin_popcountll
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater<ll>())



int main()
{
    CIN;

    ll n,m,x;
    cin>>n>>m>>x;

    vl u(n),v(m),su(n+1),sv(m+1);


    for(ll i=0;i<n;i++)
        cin>>u[i];

    for(ll i=0;i<m;i++)
        cin>>v[i];


    for(ll i=0;i<n;i++)
        su[i+1]=su[i]+u[i];

    for(ll i=0;i<m;i++)
        sv[i+1]=sv[i]+v[i];

    //for(ll i=0;i<sv.size();i++) cout<<sv[i]<<endl;

    ll cnt=0;

    for(ll i=0;i<=n;i++)
    {
        ll p=x-su[i];

        if(p<0)
            continue;

        ll l=lower_bound(sv.begin(),sv.end(),p)-sv.begin();


        if(l>m || sv[l]>p)
            l--;

        cnt=max(i+l,cnt);
    }

    cout<<cnt<<endl;


    return 0;
}


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

    void solve() {
        string s;
        cin >> s;
        stack<char> st;
        for(ll i = 0; i < s.length(); i++) {
            if(st.empty()) st.push(s[i]);
            else {
                if(st.top() == 'g' && s[i] == 'p') st.pop();
                else st.push(s[i]);
            }
        }
        //cout << st.size() << endl;
        ll p = 0, r = 0;
        while(!st.empty()) (st.top() == 'p' ? p++:r++), st.pop();
        ll cnt = -(p+1)/2 + (p%2 ? (r+1)/2 : r/2);
        cout << cnt << endl;
    }

    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      //ll ti;   cin >> ti;  while(ti--)
      solve();
      return 0;
    }


Measured memory_bytes: 512
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        List<Integer> p = new ArrayList<>();
        for(int i=0; i<n; i++) {
            p.add(sc.nextInt());
        }
        Collections.sort(p);
        int total = 0;
        for(int i=0; i<k; i++) {
            total += p.get(i);
        }
        System.out.println(total);
    }
}

Measured memory_bytes: 39216
#include<cstdio>
#include<vector>
#include<string>
using namespace std;

const int maxn = 30;

struct Node
{
	int parent;
	int left;
	int right;
	Node() {}
};

Node Tree[maxn];
int H[maxn], D[maxn], deg[maxn];

void init(int n) {
	for (int i = 0; i < n; i ++){
		H[i] = 0;
		Tree[i].parent = -1;
	}
}

void build(int n) {
	for (int i = 0; i < n; i ++) {
		int id, left, right;
		scanf("%d%d%d", &id, &left, &right);
		Tree[id].left = left;
		Tree[id].right = right;
		Tree[left].parent = id;
		Tree[right].parent = id;
	}
}

int sibling(int now){
	if(Tree[now].parent == -1)
		return -1;
	if(Tree[Tree[now].parent].left == now && Tree[Tree[now].parent].right != -1)
		return Tree[Tree[now].parent].right;
	if(Tree[Tree[now].parent].right == now && Tree[Tree[now].parent].left != -1)
		return Tree[Tree[now].parent].left;
	return -1;
}

int height(int now){
	int h1 = 0, h2 = 0;
	if(Tree[now].left != -1)
		h1 = height(Tree[now].left) + 1;
	if(Tree[now].right != -1)
		h2 = height(Tree[now].right) + 1;
	return (H[now] = h1 > h2 ? h1 : h2); 
}

void depth(int now, int dep){
	D[now] = dep;
	if(Tree[now].left != -1)
		depth(Tree[now].left, dep + 1);
	if(Tree[now].right != -1)
		depth(Tree[now].right, dep + 1);
}

void degree(int now){
	int d = 0;
	if(Tree[now].left != -1){
		d += 1;
		degree(Tree[now].left);
	}
	if(Tree[now].right != -1){
		d += 1;
		degree(Tree[now].right);
	}
	deg[now] = d;
}

string part(int now){
	if(Tree[now].parent == -1)
		return "root";
	if(deg[now] == 0)
		return "leaf";
	else
		return "internal node";
}

void print(int n){
	for(int i = 0; i < n; i ++){
		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n", i, Tree[i].parent, sibling(i), deg[i], D[i], H[i], part(i).c_str());
	}
}

int main()
{
	int n;
	while(~scanf("%d", &n)){
		int root;
		init(n);
		build(n);
		for(int i = 0; i < n; i ++)
			if(Tree[i].parent == -1)
				root = i;
		height(root);
		depth(root, 0);
		degree(root);
		print(n);
	}
	return 0;
}


Measured memory_bytes: 2840
mod = 998244353
n, k = map(int, input().split())
lr = [list(map(int, input().split())) for i in range(k)]
for i in range(k):
    lr[i][1] += 1

dp = [0]*n
dp[0] = 1
for i in range(1,n):
    dp[i] = dp[i-1]
    if i == 1:
        dp[1] = 0
    for l,r in lr:
        if i - l >= 0:
            dp[i] += dp[i-l]
        if i - r >= 0:
            dp[i] -= dp[i-r]
        dp[i] %= mod
print(dp[n-1])

Measured memory_bytes: 16792