akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;

    

    void calc()
    {
        cin = new Scanner();
        int a, b, W;
        W = cin.nextInt();
        a = cin.nextInt();
        b = cin.nextInt();
        if (a > b) swap(ref a, ref b);
        int ans = Math.Max(0, b - W - a);
        Console.WriteLine(ans);
    }

    //swap
    void swap<T>(ref T a, ref T b)
    {
        T c = a;
        a = b;
        b = c;
    } 
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

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

int main() {
	while (true) {
		int n;
		cin >> n;

		if (n == 0)
			break;
		char c[100];
		for (int i = 0;i < n;i++) {
			cin >> c[i];
		}

		int cnt[26] = { 0 };

		for (int i = 0;i < n;i++) {
			cnt[(int)(c[i] - 'A')]++;

			int max1 = -1;
			int max2 = -1;

			for (int j = 0;j < 26;j++) {
				if (cnt[j] > max1) {
					max2 = max1;
					max1 = cnt[j];
				}
				else if (cnt[j] > max2) {
					max2 = cnt[j];
				}
			}

			if (max1 - max2 > n - (i + 1)) {
				for (int j = 0;j < 26;j++) {
					if (cnt[j] == max1) {
						cout << (char)(j + 'A') << ' ';
						break;
					}
				}
				cout << (i + 1) << endl;
				break;
			}

			if (i == n - 1) {
				cout << "TIE" << endl;
				break;
			}
		}

	}
	return 0;
}

Measured memory_bytes: 3092
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
#define MOD  1000000007

int n,a,b;
int main(int argc, char const *argv[]) {

  std::cin >> n >> a >> b;
  std::cout << min(a,b) <<  ' ' << max(0,(min(a,b)-(n-max(a,b)))) <<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char s[101],t[101];
    int i,j;

    scanf("%s %s",s,t);

    int len = strlen(s);
    for (i = 0; i < len; i++)
    {
        for(j = 0; j < len; j++)
        {
            if(t[(i + j) % len] != s[j])break;
        }
        if(j == len)break;
    }
    printf(i != len ? "Yes" : "No");
}

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

using namespace std;

int arr[1024];
int main()
{
    int n;
    //freopen("test.txt", "r", stdin);
    while(scanf("%d", &n)==1)
    {
        n <<= 1;
        for(int i=0; i<n; ++i)
            scanf("%d", arr+i);
        sort(arr, arr+n);
        int ans = 0;
        for(int i=0; i<n; i+=2)
            ans += arr[i];
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 128
from itertools import product

n = int(input())
s = input()
nums = [str(i) for i in range(10)]

cnt = 0
for num in product(nums, repeat=3):
    i = 0
    for e in s:
        if num[i] == e:
            i += 1
        if i == 3:
            break

    if i == 3:
        cnt += 1

print(cnt)


Measured memory_bytes: 42392
#include<stdio.h>

int main(){
    
    char ch[1000];
    int x,i,j;
    
    while(1){
        
        for(i = 0; ;i++){
            scanf("%c",&ch[i]);
            if(ch[i]=='\n')break;
        }
        
        x = 0;
        for(j = 0; j < i; j++){
            x += ch[j] - '0';
        }
        
        if(x==0)break;
        printf("%d\n",x);
    }
    return 0;
}

Measured memory_bytes: 536
#include<iostream>
#include<string>
using namespace std;
int main(void){
  string s,t;
  cin>>s>>t;
  int c(0);
  for(int i(0);i<s.size();i++){
    s=s.back()+s.substr(0,s.size()-1);
    if(s==t){
      c++;
      break;
    }
  }
  if(c==0)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main() 
{
    fast;
    string s;
    cin>>s;
    //cout<<s;
    for(ll i=0;i<2;i++)
    {
        //cout<<s[i];
        if(s[i]!=s[i+1])
        {
            cout<<"Yes";
            exit(0);
        }
    }
    cout<<"No";
    return 0;
}

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


int main(void){
	string s,t;
	int res = 0;
	cin >> s;
	cin >> t;

	for(int i = 0; i < s.size(); i++){
		if(s[i] != t[i]) res++;
	}
	cout << res << endl;
	
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
#define load ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ll long long
#define ull unsigned long long
#define fori(i,n) for (int i=0; i<int(n);i++)
#define srt(v) sort(v.begin(), v.end())
#define MOD 1000000007
const int INF = 1e9;
const double PI = 3.14159265358979323846;
ll gcd(ll a, ll b) {
    return b != 0 ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}
ll spow(ll base, ll exp){
	ll ans = 1;
	for(ll i=0;i<exp;i++) ans = ans * base % MOD;
	return ans;
}
ll divide(ll a, ll b){
	return a * spow(b, MOD-2) % MOD;
}
template<typename T> void print(const T &x){cout<<x<<endl;}
template<typename T=int> vector<T> read(size_t n){
  vector<T> arr(n);
  for(size_t i=0;i<n;i++) cin>>arr[i];
  return arr;
}

void solve(){
	
}

int main(){
	//~ load;
	//~ int t;
	//~ cin >> t;
	//~ while(t--){
		//~ solve();
	//~ }
	
	int n;
	cin >> n;
	auto v = read(n);
	int result = v[0];
	int maxNum = v[0];
	for(int x : v){
		result = __gcd(result, x);
		maxNum = max(maxNum, x);
	}
	if (result != 1){
		print("not coprime\n");
		return 0;
	}
	
	vector<int> prime(maxNum + 1, 0);
	// build the sieve of eratosthenes
	for(int i=2; i<=maxNum; i++){
		if(prime[i]) continue;
		for(int j=i; j<=maxNum; j+=i){
			prime[j] = i;
		}
	}

	// check the prime if duplicate or not, if yes then setwise
	unordered_map<int, int> m;
	for(int x : v){
		int temp = x;
		while(temp != 1){
			int p = prime[temp];
			while(temp%p == 0){
				temp /= p;
			}
			m[p]++;
		}
	}
	for(auto x : m){
		if (x.second > 1){
			print("setwise coprime\n");
			return 0;
		}
	}
	print("pairwise coprime\n");
}



Measured memory_bytes: 14372
#include<bits/stdc++.h>
using namespace std;
struct compare
{
    bool operator()(const string& first, const string& second)
    {
        return first.size()>second.size();
    }
};
void solve()
{
    string s;
    cin>>s;
    vector<string>v; string temp;
    for(int i=0; i<s.size(); i++)
    {
        temp.push_back(s[i]);
        if(v.size()==0)
        {
             v.push_back(temp);
             temp.clear();
        }
        else
        {
            if(v[v.size()-1]!=temp)
            {
                v.push_back(temp);
                temp.clear();
            }
        }

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

}

int main()
{
    int t;
    t=1;
    while(t--)
    {
        solve();

    }
}


Measured memory_bytes: 10996
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <tuple>
#include <vector>
#include <map>
#include <iterator>
#include <cmath>

using namespace std;
using lint = long long int;

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

	int count = 0;
	for (int digit = 1; ; digit+=2) {
		int max = pow(10, digit) - 1;
		int min = pow(10, digit - 1);
		if (min > n)
			break;
		int max2 = std::min(max, n);
		count += max2 - min + 1;
		if (max2 == n)
			break;
	}
	cout << count;

	return 0;
}

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

using namespace std;

#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using Pint = pair<int, int>;
const ll mod = 1e9+7;

int dp[101][4][2];

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

  int n = s.size();

  dp[0][0][0] = 1;
  REP(i,n)REP(j,K+1)REP(k,2) {
    int ni=i+1, nj=j, nk=k;
    int nd = s[i]-'0';
    // printf("nd: %d\n", nd);
    REP(d,10) {
      nj=j, nk=k;
      if(d!=0) nj++;
      if(nj>K) continue;
      if(k==0 && d<nd) nk=1;
      if(k==0 && d>nd) continue;
      dp[ni][nj][nk] += dp[i][j][k];
      // printf("d:%d, dp[%d][%d][%d]: %d -> dp[%d][%d][%d]: %d\n", d,i,j,k,dp[i][j][k],ni,nj,nk,dp[ni][nj][nk]);
    }
  }

  int ans = dp[n][K][0] + dp[n][K][1];
  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 256
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in1(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in1(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N;
    in1(N);

    vll x(N), y(N), h(N);
    rep(i, N) in3(x[i], y[i], h[i]);

    int nonzero = -1;
    ll X, Y = 0;

    rep(i, N)
    {
        if (h[i] != 0)
        {
            nonzero = i;
            X = x[i];
            Y = y[i];
            break;
        }
    }

    repse(cx, 0, 100)
    {
        repse(cy, 0, 100)
        {
            ll H = h[nonzero] + abs(cx - X) + abs(cy - Y);

            bool flg = true;

            rep(i, N)
            {
                ll tmp = max(H - abs(cx - x[i]) - abs(cy - y[i]), 0LL);

                if (h[i] != tmp)
                {
                    flg = false;
                    break;
                }
            }

            if (flg)
            {
                cout << cx << " " << cy << " " << H << endl;
                return 0;
            }
        }
    }
    

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,cnt=0;
  string s,t;
  cin >> n;
  for(int i=0; i<n; i++){
    //cout << i << endl;
    s = to_string(i+1);
    bool sa=0,go=0,na=0,igai=0;
    for(int j=0; j<s.size(); j++){
      t = s.substr(j,1);
      if(t == "3"){
        sa = 1;
        continue;
      }
      if(t == "5"){
        go = 1;
        continue;
      }
      if(t == "7"){
        na = 1;
        continue;
      }
      if(!(t=="3"||t=="5"||t=="7")){
        igai = 1;
        if(s.size()!=1&&j!=s.size()-1){
          i+=pow(10,s.size()-1-j)-1;
        }
        break;
      }
    }
    if((sa&&go&&na)&&!igai){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
int main()
{
   ll N;cin >> N;
   cout << N*(N-1)/2 << endl;
   return 0;
}

Measured memory_bytes: 256
class Problem
  attr_accessor :a, :b, :n, :m, :h, :w, :x, :y, :s ,:t, :k, :l

  def initialize
    @n,@l = gets.to_s.split.map{ |v| v.to_i }
  end

  def solve
    if 0 < l
      solve_plus
    elsif l + n - 1 < 0
      solve_minus
    else
      solve_0
    end
  end

  def solve_0
    ans = 0
    l.upto(l+n-1) do |i|
      ans += i
    end
    ans
  end

  def solve_plus
    ans = 0
    (l+1).upto(l+n-1) do |i|
      ans += i
    end
    ans
  end

  def solve_minus
    ans = 0
    l.upto(l+n-2) do |i|
      ans += i
    end
    ans
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end


Measured memory_bytes: 14300
#include <iostream>
#include <stdio.h>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;


int main(void)
{
	int H, W; cin >> H >> W;
	vector<string> S(H + 2);
	rep(i, 0, W + 2) {
		S[0].push_back('.');
		S[H + 1].push_back('.');
		//S[0][i] = '.';
		//S[H + 1][i] = '.';
	}
	rep(i, 1, H + 1) {
		cin >> S[i];
		S[i].insert(0, ".");
		S[i].push_back('.');
	}

	rep(i, 1, H + 1) {
		
		rep(j, 1, W + 1) {
			int tmp = 0;
			if (S[i][j] == '.') {
				if (S[i - 1][j - 1] == '#')tmp++;
				if (S[i][j - 1] == '#')tmp++;
				if (S[i + 1][j - 1] == '#')tmp++;
				if (S[i - 1][j + 1] == '#')tmp++;
				if (S[i][j + 1] == '#')tmp++;
				if (S[i + 1][j + 1] == '#')tmp++;
				if (S[i - 1][j] == '#')tmp++;
				if (S[i + 1][j] == '#')tmp++;
				//S[i][j] = (char)tmp;
				cout << tmp;
			}
			else cout << "#";
		}
		cout << endl;
	}



	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define mod 1000000007
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

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


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
int main(){
	int n;
	scanf("%d",&n);
	int a[n]={};
	int b[n]={};
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n;i++){
		scanf("%d",&b[i]);
	}
	long long int p=0;
	long long int q=0;
	for(int i=0;i<n;i++){
		if(a[i]>b[i])p+=(a[i]-b[i]);
		else q+=(b[i]-a[i])/2;
	}
	if(p>q)printf("No\n");
	else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define siz(s) (int)s.size()
#define pb push_back

template<class T> inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
void cmps(vector<int>&v,int &i){
	i=lower_bound(all(v),i)-v.begin();
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int N;
vector<int>G[200005];
int A[200005];
int idx[200005],moto[200005];
int ans[200005],suu[200005];
void dfs(int x,int p){
	int i=lower_bound(suu,suu+N,A[x])-suu;
	idx[x]=i;moto[x]=suu[i];
	suu[i]=A[x];
	ans[x]=lower_bound(suu,suu+N,inf)-suu;
	for(int i:G[x])if(i!=p){
		dfs(i,x);
	}
	suu[idx[x]]=moto[x];
}
signed main(){
	cin>>N;
	rep(i,N)cin>>A[i];
	rep(i,N)suu[i]=inf;
	rep(i,N-1){
		int a,b;cin>>a>>b;a--;b--;
		G[a].pb(b);G[b].pb(a);
	}
	dfs(0,0);
	rep(i,N)cout<<ans[i]<<endl;
}


Measured memory_bytes: 33832
#include<stdio.h>
int main(void) {
	char n[100000];
	scanf("%s", n);

	int i,j;
	int count = 0;
	
	for (i = 0; n[i] != '\0'; i++) {
		if (n[i] == n[i + 1]) {
			count++;
			for (j = i + 2; n[i] == n[j]; i++) {
				count++;
				if (count >= 3) {
					printf("Yes\n");
					break;
				}
			}
		}
		if (count >= 3) {
			break;
		}
		if (n[i + 2] == '\0') {
			printf("No\n");
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 128
MAX=2019
def resolve():
    l,r = map(int,input().split())
    if abs(l-r)>=MAX:
        print(0)
        exit(0)
    ans = 10**9
    for i in range(l,r+1):
        for j in range(i+1,r+1):
            ans = min(ans,(i*j)%MAX)
    
    print(ans)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 38896
def cin; gets.split.map(&:to_i) end

# exit if $0 != __FILE__

# n, *x = cin
# s = gets.chomp

# puts n
n = gets.to_i
r = []
n.times do |i|
  l = gets.split
  r << [i + 1, l[0], l[1].to_i]
end

r.sort! do |a, b|
  s = a[1] <=> b[1]
  next s if s != 0
  -(a[2] <=> b[2])
end

r.each do |x|
  puts x[0]
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
bool ans=true;
int y[100005],a[100005],b[100005],m[100005];
int main()
{
	int n;
	cin>>n;
	for(int i=0; i<n; i++)
	{
		cin>>m[i]>>a[i]>>b[i];
	}
	int p=0,q=0;
	for(int i=0; i<n; i++)
	{
		y[i]=m[i];
		if(i!=0)
		m[i]=m[i]-y[i-1];
		int c=abs(a[i]-p)+abs(b[i]-q)-m[i];
		if(abs(c)%2==0&&c<=0)
		{
			ans=true;
			p=a[i]; q=b[i];
		}
		else
		{
			ans=false;
			break;
		}
	}
	if(ans==true)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

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

int main()
{
	int n;
	vector<int> a;
	cin >> n;
	a.resize(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}

	long long ret = 0;
	for (auto& i : a) {
		ret += (i - 1);
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
using namespace std;
typedef long long llong;

int main()
{
	int r, D, x;
	cin >> r >> D >> x;
	for (int i = 1; i <= 10; i++)
	{
		x = r * x - D;
		cout << x << "\n";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
typedef long long ll;
const ll mod = 1e9 + 7;

int main(){
    fastio;
    ll n, k, ans = 0;
    cin >> n >> k;
    for(ll i = k; i <= n + 1; ++i){
        ll mini = (i * (i - 1)) / 2;
        ll maxi = n * i - mini;
        ans = (ans + maxi - mini + 1) % mod;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3584
#include <stdio.h>
#define TRUE 1
#define FALSE 0
int solve(int,int);
int n,A[2000],q,m[2000];
int main(){
  
  int i,flag;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m[i]);
  }
  for(i=0;i<q;i++){
    flag=solve(0,m[i]);
    if(flag==TRUE) printf("yes\n");
    else if(flag==FALSE) printf("no\n");
  }

  return 0;

}
int solve(int i,int m){
  int k;
  if(m==0) return TRUE;

  if(i>=n) return FALSE;

  if(k=solve(i+1,m) || solve(i+1,m-A[i])) return k;
}

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


int main()
{
  int n;
  cin >> n;
  vector<tuple<string, int, int>> r;
  rep(i, n)
  {
    string s;
    int p;
    cin >> s >> p;
    r.emplace_back(s, -p, i + 1);
  }
  sort(r.begin(), r.end());
  rep(i, n)
    printf("%d\n", get<2>(r[i]));
  return 0;
}

Measured memory_bytes: 256
import java.io.*;
public class Main {
	public static void main (String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		try{
			String line = reader.readLine();
			int x = Integer.parseInt(line);
			int tri = (int) Math.pow(x,3);
			System.out.println(tri);
		}catch(IOException e) {
			System.out.println(e);
		}catch(NumberFormatException e) {
			System.out.println("??°????????\?????????????????????");
		}
	}
}

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

int n;
void solve()
{
    vector<ll> a, l(n + 2), r(n + 2);
    a.push_back(0);
    rep(i, n)
    {
        ll ai;
        cin >> ai;
        a.push_back(ai);
    }
    a.push_back(0);
    l[0] = 0, r[n + 1] = 0;
    for (int i = 1; i <= n + 1; i++)
    {
        l[i] = l[i - 1] + abs(a[i] - a[i - 1]);
    }
    for (int i = n; i >= 0; i--)
    {
        r[i] = r[i + 1] + abs(a[i] - a[i + 1]);
    }
    for (int i = 1; i <= n; i++)
    {
        ll ans = l[i] + r[i];
        ans = ans - abs(a[i] - a[i - 1]);
        ans = ans - abs(a[i] - a[i + 1]);
        ans = ans + abs(a[i - 1] - a[i + 1]);
        cout << ans << endl;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    solve();
    return 0;
}


Measured memory_bytes: 3700
# 偶数チェック
def Even(n):
    if n%2 == 0:
        return True
    else:
        return False
    

S = list(input())

s1 = []
s2 = []

if Even(len(S)):
    s1 = S[:int(len(S)/2)]
    s2 = S[int(len(S)/2):]
    s2.reverse()
else:
    s1 = S[:int(len(S)//2)]
    s2 = S[int(len(S)//2)+1:]
    s2.reverse()

    
counter = 0
for i in range(len(s1)):
    if s1[i] != s2[i]:
        counter += 1
        
print(counter)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int c[3][3];
  rep(i,3)rep(j,3) cin >> c[i][j];

  bool ok = true;
  int d1 = c[2][1]-c[2][0], d2 = c[2][2]-c[2][1];
  rep(i,2){
    if(c[i][1]-c[i][0]!=d1) ok = false;
    if(c[i][2]-c[i][1]!=d2) ok = false;
  }
  d1 = c[1][2]-c[0][2], d2 = c[2][2]-c[1][2];
  rep(j,2){
    if(c[1][j]-c[0][j]!=d1) ok = false;
    if(c[2][j]-c[1][j]!=d2) ok = false;
  }
  cout << (ok?"Yes":"No") << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (long long i = 0; i < (long long) (n); ++i)
#define pb emplace_back
#define endl '\n'

template<typename T> void _dbg(const char*_s,T _h) { cerr<<_s<<" = "<<_h<<"\n"; }

template<typename T, typename... Ts> void _dbg(const char*_s,T _h,Ts... _t) {
    for(int _b=0;((_b+=*_s=='(')-=*_s==')')!=0||*_s!=',';)cerr<<*_s++;
    cerr<<" = "<<_h<<",";_dbg(_s+1,_t...);
}

#define int long long

#ifdef LOCAL
    #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
    #define dbg(...)
#endif

const int N = 500 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, m;

bool read() {
    if (!(cin >> n >> m))
        return false;

    return true;
}

void solve(int id = 0) {
    n %= m;
    cout << min(n, m - n) << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    srand(time(nullptr));

    int T;
    T = 1;

    while (read())
        solve(T++);

    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>

using namespace std;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define INF 11111111111111111
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<ll, ll> pll;

ll n = 0, m = 0, k = 0, ans = 0, sum = 0, cnt = 0, temp = 0;
string s;
bool flag;

//--------------------------------------------------------------------------

#define MAX 10000

int main(void) {
  cin >> n;
  vll a;

  a.push_back(0);
  FOR(i, 0, n) {
	cin >> temp;
	a.push_back(temp);
	sum += llabs(a[i + 1] - a[i]);
  }
  a.push_back(0);
  sum += llabs(a[n + 1] - a[n]);

  FOR(i, 1, n + 1) {
	temp = llabs(a[i + 1] - a[i - 1]) - llabs(a[i + 1] - a[i]) - llabs(a[i] - a[i - 1]);
	cout << sum + temp << endl;
  }

  return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

int N;
int X[10];

void solve() {
  int t = 0;
  rep (i, 5) {
    int s = (N + X[i] - 1) / X[i];
    chmax(t, i + s + (4 - i));
  }

  cout <<t << endl;
}

signed main() {
  cin >> N;
  rep (i, 5) {
    cin >> X[i];
  }

  solve();

  return 0;
}

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

using namespace std;

int main() {
  int n;
  ll c = 0, d = 0, pm = 0, mp = 0;
  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    pm += a;
    mp += a;
    if(pm * (i % 2 ? -1 : 1) <= 0) {
      c += abs(pm) + 1;
      pm = i % 2 ? -1 : 1;
    }
    if(mp * (i % 2 ? -1 : 1) >= 0) {
      d += abs(mp) + 1;
      mp = i % 2 ? 1 : -1;
    }
  }
  printf("%lld\n", min(c, d));
}

Measured memory_bytes: 384
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#define ll long long
using namespace std;
int main()
{
    int a;

    while(scanf("%d",&a)!=EOF){

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] d = new int[n];
		for (int i = 0; i < d.length; i++) {
			d[i] = sc.nextInt();
		}
		sc.close();

		long ans = 0;
		for (int i = 0; i < d.length; i++) {
			for (int j = i + 1; j < d.length; j++) {
				ans += d[i] * d[j];
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 23380
#include <iostream>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;

constexpr int INF = 1e9+7;

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> D(M);
    vector<int> idx(N, -1);
    for(int i=0; i<M; ++i) {
        cin >> D[i];
        D[i]--;
        idx[D[i]] = i;
    }
    vector<vector<int>> v(N, vector<int>(K));
    for(int i=0; i<N; ++i) {
        for(int j=0; j<K; ++j) {
            cin >> v[i][j];
            v[i][j]--;
        }
    }
    vector<int> dp(1 << M, INF);
    dp[(1 << M) - 1] = 0;
    queue<int> que;
    que.push((1 << M) - 1);
    while(!que.empty()) {
        int now = que.front(); que.pop();
        for(int k=0; k<K; ++k) {
            int next = 0;
            for(int i=0; i<M; ++i) {
                if((now >> i) & 1 && idx[v[D[i]][k]] != -1) {
                    next |= (1 << idx[v[D[i]][k]]);
                }
            }
            if(dp[next] != INF) {
                continue;
            }
            dp[next] = dp[now] + 1;
            que.push(next);
        }
    }
    cout << dp[0] << endl;
}


Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
   int n,x;
   cin >> n >> x;
   int ans =0;
   vector<int> v(n+1);
   v[0] = 0;
   rep(i,n){
      int tmp;
      cin >> tmp;
      v[i+1] = v[i] + tmp;
   }
   rep(i,n+1){
      if (v[i] <= x) ans++;
   }
   cout << ans << endl;

   return 0;
}

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

if B-A <= 2 or A >= K+1:
    print (K+1)

else:

    ans = A
    K -= A-1

    if K % 2 == 1:
        ans += 1
        K -= 1

    ans += (B-A) * (K // 2)

    print (ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

map<ll, int> primeFactorize(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      ++ret[i];
      n /= i;
    }
  }
  if( n != 1 ) ret[n] = 1;
  return ret;
}

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

  ll n; cin >> n;
  cout << n << ":";
  for (auto e : primeFactorize(n)) {
    while (e.second--) cout << " " << e.first;
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 3204
#include <iostream>
#include <climits>
using namespace std;
int n,W;
int main(){
	cin>>n>>W;

	int w[n+1];
	long long v[n+1];
	for(int i=1;i<=n;i++)
		cin>>w[i]>>v[i];

	long long ks[W+1][n+1];

	for(int i=0;i<=W;i++){
		for(int j=0;j<=n;j++){
			ks[i][j]=0;
			if(i-w[j]>=0 && j>=1)//taking ith item in knapsck
				ks[i][j]=max(ks[i][j],ks[i-w[j]][j-1]+v[j]);
			if(j>=1)//knapsack without ith item
				ks[i][j]=max(ks[i][j],ks[i][j-1]);
		}
	}

	cout<<ks[W][n];

}


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

int main() {
  long long n, tim = 0, cou = 0, sum = 0;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  for (long i = 0; i < n; i++) {
    cin >> b[i];
  }
  sort(b.begin(), b.end());
  for (long i = 0; i < n; i++) {
    cin >> c[i];
  }
  sort(c.begin(), c.end());

  int u = 0;
  for (int i = 0; i < n; i++) {
    decltype(a)::iterator it = upper_bound(a.begin(), a.end(), b[i] - 1);

    cou = it - a.begin();

    decltype(c)::iterator its = lower_bound(c.begin(), c.end(), b[i] + 1);

    tim = its - c.begin();
    tim = n - tim;
    sum += cou * tim;

    cou = tim = 0;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1408
m,i,j,t,u;z[2002],*a=z,*b=z+999;main(n){for(;m=scanf("%d",&n)-++n;printf("%d\n",m))for(i=n;i--;j=a,a=b,b=j)for(j=n;j--;t>m?m=t:0)b[j]=t=n+~i&&getchar()>45?fmin(u=a[j],t<u?t:u)+1:0;}

Measured memory_bytes: 0
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
long long A,B,l,r,L,R;
int main()
{
	scanf("%lld%lld",&A,&B);
	for(int i=61;i>=0;i--)
	if(((A>>i)&1)^((B>>i)&1)) break;
	else if((A>>i)&1) A-=(1ll<<i),B-=(1ll<<i);
	int lim=61;
	while(lim>=0)
	{
		if(((A>>lim)&1)!=((B>>lim)&1))
		{
			l=A&((1ll<<lim+1)-1),r=(1ll<<lim)+l;
			int tt=lim-1;
			while(tt>=0&&!((B>>tt)&1)) tt--;
			R=(1ll<<lim)+(1ll<<tt+1)-1;
			break;
		}
		lim--;
	}
	long long ans=0;
	if(R>=r) ans=(1ll<<lim+1)-l;
	else ans=(1ll<<lim+1)-r+R-l+1;
	printf("%lld\n",ans);
}

Measured memory_bytes: 3796
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef    long long   ll;
typedef    long double   ld;
//typedef    unordered_set<ll>   usll;
//typedef    unordered_multiset<ll>   umsll;
typedef    multiset<ll>   msll;
typedef    set<ll>   sll;
typedef    vector<ll>   vll;
typedef    pair<ll,ll>   pll;
typedef    vector<pll>   vpll;
typedef    priority_queue<ll>   pqll;
typedef    vector<int>   vi;
typedef    set<int>   si;
typedef    multiset<int>   msi;
//typedef    unordered_multiset<int>   umsi;
//typedef    unordered_set<int>   usi;
typedef     pair<int,int>   pi;
typedef    vector<pi>   vpi;
typedef    set<pi>   spi;
typedef    priority_queue<int>   pqi;
typedef    tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>   ind_set;
typedef    tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>   ind_setll;
#define    in   insert
#define    fi   first
#define    se   second
#define    pb   push_back
#define    mp   make_pair
#define    be   begin
#define    en   end
#define    itr   iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define    mo   1000000007
#define    inf  9223372036854775807
#define    ninf   -inf
#define    ima   2147483647
#define    imi   -ima
#define    oncnt    __builtin_popcount
#define    zerobegin   __builtin_clz
#define    zeroend   __builtin_ctz
#define    parity   __builtin_parity
#define    all(x)   x.be(),x.en()
#define    eps   1e-9
#define    coutd   cout<<setprecision(10)<<fixed
#define    mems(dp,x)   memset(dp,x,sizeof(dp))
const    ld   PI=3.14159265359;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}


int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{
	

int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
int c=0;
for(int i=1;i<n-1;i++)
{
	int b[3];
	b[0]=a[i-1];
	b[1]=a[i];
	b[2]=a[i+1];
	sort(b,b+3);
	if(a[i]==b[1])
	c++;
}
	
	cout<<c;
	
	


}return 0;}

Measured memory_bytes: 256
def is_ok(s):
    if s[1:] in ['AGC', 'ACG', 'GAC']:
        return False
    if s[0] == 'A' and s[2:] == 'GC':
        return False
    if s[:2] == 'AG' and s[3] == 'C':
        return False
    return True


m = 1000000007

N = int(input())

d = {}
for i in 'ACGT':
    for j in 'ACGT':
        for k in 'ACGT':
            d[i + j + k] = 1
for k in ['AGC', 'ACG', 'GAC']:
    del d[k]

for i in range(N - 3):
    t = {}
    for k in d:
        for i in 'ACGT':
            s = k + i
            if is_ok(s):
                t.setdefault(s[1:], 0)
                t[s[1:]] += d[k]
                t[s[1:]] %= m
    d = t

print(sum(d.values()) % m)


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

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  if ( A>K) {
    cout << K << endl;
  }
  else if (A+B >= K){
    cout << A << endl;
  }
  else if( A+B+C >= K){ 
    cout << A-(K-A-B) << endl;
  }
}


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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 1e5 + 10, LOG_N = 20;

int N, L, Q, Nr[MAX_N];
int P[LOG_N][MAX_N];
int main() {
	cin >> N; for(int i=1; i<=N; i++) scanf("%d", &Nr[i]); cin >> L >> Q;
	for(int l=1, r=1; l<=N; l++) {while(r+1<=N && Nr[r+1]-Nr[l] <= L) r++; P[0][l] = r;}
	for(int p=1; p<LOG_N; p++) for(int i=1; i<=N; i++) P[p][i] = P[p-1][P[p-1][i]];
	while(Q--) {
		int x, y; scanf("%d%d", &x, &y);
		if(x > y) swap(x, y);
		int ans = 0;
		for(int p=LOG_N-1; p>=0; p--) if(P[p][x] < y) ans += (1<<p), x = P[p][x];
		printf("%d\n", ans+1);
	}
	return 0;
}


Measured memory_bytes: 9088
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<sstream>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000000+7
using namespace std;
typedef long long ll;

int N, A, B, C;
vector<int> l;
int dfs(int cur, int a, int b, int c){
  if(cur == N)
    return min(min(a,b),c)>0 ? abs(a-A) + abs(b-B) + abs(c-C) - 30 : MAX;
  int ret0 = dfs(cur+1, a, b, c);
  int ret1 = dfs(cur+1, a+l[cur], b, c) + 10;
  int ret2 = dfs(cur+1, a, b+l[cur], c) + 10;
  int ret3 = dfs(cur+1, a, b, c+l[cur]) + 10;

  return min(min(ret0, ret1), min(ret2, ret3));
}

int main(){
  cin >> N >> A >> B >> C;
  rep(i, 0, N)  {
    int n;  cin >> n;
    l.push_back(n);
  }
  cout << dfs(0, 0, 0, 0);
  return 0;
}

Measured memory_bytes: 256
/*
        Choo Lo jo mujhe tum kabhi, kho na jaoon main raat din
    Nazaron mein tum ho basey
        Keh do jo tum ek baar, Mere ho bas tum mere
    Nazaron mein tum ho basey
*/
 
#include<bits/stdc++.h>
#include<cstdio>
 
#define deb(x) cout << #x << " -> " << x << el
#define db double
#define ll long long int
#define ull unsigned long long int
#define umap unordered_map
#define sc(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define sclu(x) scanf("%llu", &x)
#define scd(x) scanf("%lf", &x)
#define pass cout<<"pass\n"
#define vi vector<int>
#define pb push_back
#define vec vector
#define el "\n"
#define pii pair<int, int>
#define pll pair<long long, long long>
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define umap unordered_map
#define f(i,x,y) for(int i=x;i<y;++i)
#define ff(i,x,y) for(int i=x;i<=y;++i)
#define mem(x) memset(x, 0, sizeof(x))
#define mems(x,y) memset(x, y, sizeof(x))
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ppi pair<int, pii>
#define mat vector<vector<ll> > 
#define mod 1000000007
#define MAX 100005
 
using namespace std;

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

	vec<db> heads(n + 1, 0.0);

	for(int coin = 1; coin <= n; ++coin) {
		db p; cin >> p;

		if(coin == 1) {
			heads[0] = 1.0 - p;
			heads[1] = p;
			continue;
		}

		vec<db> dp(coin + 1, 0.0);

		for(int i = 0; i < coin; ++i) dp[i + 1] = heads[i] * p;

		for(int i = 0; i < coin; ++i) dp[i] += heads[i] * (1.0 - p);

		ff(i,0,coin) heads[i] = dp[i];
	}

	db ans = 0.0;

	for(int i = n; i >= n / 2 + 1; --i) ans += heads[i];

	printf("%1.10lf\n", ans);
 
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int n; cin >> n;
    int ans = 0;
    REP(i,1,pow(10,5)){
        if(pow(i,2)<=n){
            ans = pow(i,2);
        }else{
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

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

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

  ll n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  rep(i, n) rep(j, n) if (i != j) ans = max(ans, abs(a[i] - a[j]));
  cout << ans << endl;
  return 0;
}


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

using namespace std;

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

    for (int i = 0; i < s.length(); i++) {
        if (s[i] == '1') {
            cout << "9";
        } else {
            cout << "1";
        }
    }
    cout << endl;
    return 0;
}


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

namespace ABC117A
{
    class MainClass
    {

        static double[] s;
       
        public static void Main(string[] args)
        {

            s = Array.ConvertAll(Console.ReadLine().Split().ToArray(), double.Parse);
           

            double ans = s[0] / s[1];

            Console.WriteLine(ans);

            return;


        }
    }
}


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

using namespace std;

int main()
{
    int a,b,c,d;
    cin >> a>>b>>c>>d;
    
    while(a>0 && c>0){
        c-=b;
        if(c>0)
        a-=d;
    }
    
    if(a>c)
    cout << "Yes";
    else 
    cout << "No";

    return 0;
}

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	int counts = 1;
	bool up = false;
	bool down = false;
	for(int i = 1; i < n; i++){
		int dif = a[i] - a[i-1];
		if(dif > 0) up = true;
		if(dif < 0) down = true;
		if(up && down){
			counts++;
			up = down = false;
			continue;
		}
	}
	cout << counts << endl;
}

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

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

  string s = to_string(n);

  int t = 0;
  for(int i=0; i<s.size(); i++) {
    t += (int)(s[i] - '0');
  }

  if(n % t == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<sys/mman.h>
#define read() Read<ll>()
#define lowbit(i) i&(-i)
using namespace std;
typedef long long ll;
const int N=1e5+5;
namespace pb_ds{   
    namespace io{
        const int MaxBuff=1<<15;
        const int Output=1<<23;
        char B[MaxBuff],*S=B,*T=B;
		#define getc() ((S==T)&&(T=(S=B)+fread(B,1,MaxBuff,stdin),S==T)?0:*S++)
        char Out[Output],*iter=Out;
        inline void flush(){
            fwrite(Out,1,iter-Out,stdout);
            iter=Out;
        }
    }
    template<class Type> inline Type Read(){
        using namespace io;
        register char ch;
        register Type ans=0; 
        register bool neg=0;
        while(ch=getc(),(ch<'0' || ch>'9') && ch!='-');
        ch=='-'?neg=1:ans=ch-'0';
        while(ch=getc(),'0'<= ch && ch<='9') ans=ans*10+ch-'0';
        return neg?-ans:ans;
    }
    template<class Type> inline void Print(register Type x,register char ch='\n'){
        using namespace io;
        if(!x) *iter++='0';
        else{
            if(x<0) *iter++='-',x=-x;
            static int s[100]; 
            register int t=0;
            while(x) s[++t]=x%10,x/=10;
            while(t) *iter++='0'+s[t--];
        }
        *iter++=ch;
    }
}
using namespace pb_ds;
int main(){
	ll x=read(),y=read(),ans=0;
	for (;x<=y;x<<=1) ++ans;
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  map<string, int> words;

  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    string w;
    cin >> w;
    ++words[w];
  }

  int M;
  cin >> M;
  for (int i = 0; i < M; ++i) {
    string w;
    cin >> w;
    --words[w];
  }

  int ans = 0;
  for (map<string,int>::iterator itr = words.begin(); itr != words.end(); ++itr) {
    ans = max(ans, itr->second);
  }

  cout << ans << 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 REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int main() {
    string S,T;
    cin >> S;
    cin >> T;
    int len = S.size();

    int ans = 0;
    REP(i,len){
        if(S[i] != T[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3852
let N = Int(readLine()!)!
let a = readLine()!.split(separator: " ").map { Int($0)! }

/// dp[leftSlime][rightSlime]
/// leftSlime〜rightSlimeを合体させる最小コスト
var dp = Array(repeating: Array(repeating: Optional<Int>.none, count: N), count: N)

func getMinimumCost(from leftSlime: Int, through rightSlime: Int) -> Int {
    /// 区間内にスライムが1体以上いること
    guard leftSlime < rightSlime else {
        /// 区間内にスライムがいない、つまり操作が発生しないのでコスト0
        dp[leftSlime][rightSlime] = 0
        return 0
    }

    /// 既に計算済みならそれを返す
    guard dp[leftSlime][rightSlime] == nil else { return dp[leftSlime][rightSlime]! }

    var cost = Int.max
    var size = a[leftSlime]
    for i in stride(from: leftSlime, to: rightSlime, by: 1) {
        let cost0 = getMinimumCost(from: leftSlime, through: i)
        let cost1 = getMinimumCost(from: i + 1, through: rightSlime)
        cost = min(cost, cost0 + cost1)

        size += a[i + 1]
    }

    dp[leftSlime][rightSlime] = cost + size
    return cost + size
}

print(getMinimumCost(from: 0, through: N - 1))


Measured memory_bytes: 10836