akhauriyash/Code-Regression huggingface dataset:
S = input()
N = len(S)

ans = [1]*N


# 左から1ずつカウントしていって、Rの時のことだけ考える
for i,s in enumerate(S):
    if s=="R":
        s2 = S[i+1]
        if s2 == "R":
            ans[i+2] += ans[i]
            ans[i] = 0


# 右から1ずつカウントしていって、Lの時のことだけ考える
for i in range(N-1,-1,-1):
    s = S[i]
    if s=="L":
        s2 = S[i-1]
        if s2 == "L":
            ans[i-2] += ans[i]
            ans[i] = 0

print(*ans)

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

using namespace std;

typedef long long ll;

const int N = 310;
const int MOD = 1e9 + 7;

struct node
{
	int l, x;

	node (int a, int b)
	{
		l = a, x = b;
	}
	node () { }
};
vector <node > com[N];

int n, m;
ll f[N][N][N];

inline int read()
{
	int x = 0, ch = '~';

	while(!(ch >= '0' && ch <= '9')) ch = getchar();
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1), x += ch - '0', ch = getchar();

	return x;
}

bool check(int k, int i, int j)
{
	bool flag = true;

	for(int c = 0; c < (int )com[k].size(); c++)
	{
		int l = com[k][c].l, x = com[k][c].x, cnt = 0;

		if(k >= l) cnt++;
		if(i >= l) cnt++;
		if(j >= l) cnt++;

		if(cnt != x)
		{
			flag = false;
			break;
		}
	}

	if(!flag)
		f[k][i][j] = 0;

	return flag;
}

int main()
{
	n = read(), m = read();
	for(register int k = 1; k <= m; k++)
	{
		int l = read(), r = read(), x = read();
		com[r].push_back(node(l, x));
	}

	f[1][0][0] = 3;

	for(register int k = 1; k < n; k++)
		for(int i = 0; i < k; i++)
			for(int j = 0; !j || j < i; j++)
			{
				if(!check(k, i, j)) continue;

				f[k + 1][i][j] += f[k][i][j], f[k + 1][i][j] %= MOD;
				f[k + 1][k][i] += f[k][i][j], f[k + 1][k][i] %= MOD;
				f[k + 1][k][j] += f[k][i][j], f[k + 1][k][j] %= MOD;
			}

	ll answ = 0;
	for(register int k = 0; k < n; k++)
		for(int i = 0;!i || i < k; i++)
			if(check(n, k, i))
				answ += f[n][k][i], answ %= MOD;

	printf("%lld", answ);

	return 0;
}

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

int main(){
  int L{}, R{}, d{};

  int cuenta = 0;

  cin >> L >> R >> d;
  
  while (L != R+1){
    if(L % d == 0){
      ++cuenta;
    }
    L++;
  }

  cout << cuenta << endl;
  return 0;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int Dfs(int l, int mult, int node, vector<tuple<int, int, int>>& v) {
  if (l == 1) {
    return node;
  }
  if (l % 2 == 0) {
    v.push_back({node, node + 1, 0});
    v.push_back({node, node + 1, mult});
    return Dfs(l / 2, mult * 2, node + 1, v);
  }
  int n = Dfs(l - 1, mult, node, v);
  v.push_back({node, n, (l - 1) * mult});
  return n;
}

int main() {
  in(int, l);
  vector<tuple<int, int, int>> v;
  int n = Dfs(l, 1, 0, v);
  out(n + 1, v.size());
  for (auto [a, b, c] : v) {
    out(a + 1, b + 1, c);
  }
}


Measured memory_bytes: 3612
#include<stdio.h>
#include<stdlib.h>
int main()
{
  int N;
  char *S;
  int x=0,max=0;
  
  scanf("%d",&N);
  S=(char*)malloc(sizeof(char)*N);
  scanf("%s",S);
  
  for(int i=0;i<N;i++){
    if(S[i]=='I') x++;
    else x--;
    if(x>max) max=x;
  }
  printf("%d",max);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int maxn=100+10;
int n,arr[maxn];
int main()
{
    cin>>n;
    for(int i=0;i<n;i++) cin>>arr[i];
    for(int i=0;i<n;i++){
        int v=arr[i];
        int j=i-1;
        while(j>=0&&arr[j]>v){
            arr[j+1]=arr[j];
            j--;
        }
        arr[j+1]=v;
        for(int i=0;i<n;i++){
            if(i) cout<<" "<<arr[i];
            else cout<<arr[i];
        }cout<<"\n";
    }
    return 0;
}



Measured memory_bytes: 3100
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
mi = min(a, b, c, d, e)
ma = max(a, b, c, d, e)
if ma - mi > k:
    print(":(")
else:
    print("Yay!")


Measured memory_bytes: 3060
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Sparsh Sanchorawala
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BTrickOrTreat solver = new BTrickOrTreat();
        solver.solve(1, in, out);
        out.close();
    }

    static class BTrickOrTreat {
        public void solve(int testNumber, InputReader s, PrintWriter w) {
            int n = s.nextInt(), k = s.nextInt();
            int[] f = new int[n];
            for (int i = 0; i < k; i++) {
                int m = s.nextInt();
                while (m-- > 0) {
                    f[s.nextInt() - 1] = 1;
                }
            }
            int res = 0;
            for (int i = 0; i < n; i++)
                res += 1 ^ f[i];
            w.println(res);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 32892
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int h, w; cin >> h >> w;

    int a[h][w];
    rep(i, h){
        rep(j, w){
            cin >> a[i][j];
        }
    }

    int cnt = 0;
    vector<int> vstr[4];
    rep(i, h){
        rep(j, w-1){
            if(a[i][j] % 2 == 1){
                vstr[0].push_back(i+1);
                vstr[1].push_back(j+1);
                vstr[2].push_back(i+1);
                vstr[3].push_back(j+2);
                cnt++;
                a[i][j+1]++;
                a[i][j]--;
            }
        }
    }

    rep(i, h-1){
        if(a[i][w-1] % 2 == 1){
            vstr[0].push_back(i+1);
            vstr[1].push_back(w);
            vstr[2].push_back(i+2);
            vstr[3].push_back(w);
            cnt++;
            a[i][w-1]--;
            a[i+1][w-1]++;
        }
    }

    cout << cnt << endl;
    rep(i, cnt){
        cout << vstr[0][i] << " " << vstr[1][i] << " ";
        cout << vstr[2][i] << " " << vstr[3][i]  << endl;
    }

    return 0;
}

Measured memory_bytes: 5220
import sys
# input = sys.stdin.readline

def readlines(n):
    for _ in range(n):
        yield map(int, input().split())


def main():
    n, m, x = map(int, input().split())
    a = set(map(int, input().split()))

    zeroside = 0
    for i in range(1, x):
        if i in a:
            zeroside += 1

    nside = 0
    for i in range(x, n+1):
        if i in a:
            nside += 1

    print(min(zeroside, nside))    

main()


Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		while (in.hasNext()) {
			int w = in.nextInt();
			int h = in.nextInt();
			if (w != 0 && h != 0) {
				char[][] tile = new char[h + 2][];
				int fx = -1;
				int fy = -1;
				tile[0] = new char[w + 2];
				Arrays.fill(tile[0], '#');
				for (int y = 0; y < h; y++) {
					sb.setLength(0);
					sb.append('#').append(in.next()).append('#');
					String line = sb.toString();
					tile[y + 1] = line.toCharArray();
					if (line.contains("@")) {
						fy = y + 1;
						fx = line.indexOf('@');
					}
				}
				tile[h + 1] = new char[w + 2];
				Arrays.fill(tile[h + 1], '#');
				tile[fy][fx] = '.';
				fill(fx, fy, tile);
				int count = 0;
				for (char[] l : tile) {
					for (char c : l) {
						if (c == '@') count++;
					}
				}
				System.out.println(count);
			} else {
				break;
			}
		}
	}

	private static void fill(int fx, int fy, char[][] tile) {
		if (tile[fy][fx] == '.') {
			tile[fy][fx] = '@';
			fill(fx + 1, fy, tile);
			fill(fx - 1, fy, tile);
			fill(fx, fy + 1, tile);
			fill(fx, fy - 1, tile);
		}
	}
}

Measured memory_bytes: 12000
n = gets.to_i
s = []

n.times do
  tmp = gets.chomp.split('').sort
  hash = {}
  tmp.each do |moji|
    if hash[moji.to_sym]
      hash[moji.to_sym] += 1
    else
      hash[moji.to_sym] = 1
    end
  end
  s << hash
end
result = s.shift

s.each do |h|
  result.each do |k,v|
    tmp = [v, h[k] || 0].min
    result[k] = tmp
  end
end

puts result.filter{|k,v| !v.zero? }.map{|k,v| k.to_s * v}.join


Measured memory_bytes: 14344
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    string a, b;
    cin >> a >> b;
    if (a.size() == b.size()) {
        if (a == b) OUT("EQUAL")
        else if (a > b) OUT("GREATER")
        else OUT("LESS")
    } else if (a.size() > b.size()) OUT("GREATER")
    else OUT("LESS")

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
namespace mp = boost::multiprecision;// 任意長整数型
using bint = mp::cpp_int;// 仮数部長が32の浮動小数点数型
using real32 = mp::number<mp::cpp_dec_float<32>>;// 仮数部長が1024の浮動小数点数型
using real1024 = mp::number<mp::cpp_dec_float<1024>>;// ついでに有理数型
using rat = boost::rational<bint>;
*/
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
vector<pair<string,bool>>t;
int main(){ //srand((unsigned)time(NULL));
  for (int i = 0; i < 4; i++) {
    for (int l = 1; l <= 13; l++) {
      string x; char c;
      if(i == 0)c = 'S';
      else if(i == 1)c = 'H';
      else if(i == 2)c = 'C';
      else if(i == 3)c = 'D';
      x = c + to_string(l);
      t.pb(make_pair(x,true));
    }
  }
  ll n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string x;
    char c; ll a;
    cin >> c >> a;x = c + to_string(a);
    for (int l = 0; l < t.size(); l++) {
      if(t[l].first == x)t[l].second = false;
    }
  }
  for (int i = 0; i < t.size(); i++) {
    if(t[i].second){
      string x="";
      for (int l = 1; l < t[i].first.length(); l++) {
        x += t[i].first[l];
      }
      cout << t[i].first[0] << " " << x << endl;
    }  
  }
}



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

int main() {
  string S;
  cin >> S;
  sort(S.begin(), S.end()); 
  int cnt;
  bool b = true;
  for(char c = 'a'; c <= 'z'; c++) {
    cnt = 0;
    for(int i = 0; i < S.size(); i++) {
      if(S.at(i) == c) {
        cnt++;
      }
    }
    if(cnt%2 == 1) {
      b = false;
      break;
    }
  }
  if(b) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }
}



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

ll n,q;
string s;
vector<char> t,d;

int f(ll x){
    if(x<0)return -1;
    if(n<=x)return 1;
    rep(i,q){
        if(t[i]==s[x]){
            x+=(d[i]=='R'?1:-1);
        }
        if(x==-1)return -1;
        if(x==n)return 1;
    }
    return 0;
}

int main(){
    cin>>n>>q>>s;
    t.resize(q);
    d.resize(q);
    rep(i,q)cin>>t[i]>>d[i];
    ll l=-1,r=n;
    while(l<r-1){
        ll mid=(r+l)/2;
        if(f(mid)==-1)l=mid;
        else r=mid;
    }
    ll num=r;
    l=-1; r=n;
    while(l+1<r){
        ll mid=(l+r)/2;
        if(f(mid)==1)r=mid;
        else l=mid;
    }
    cout<<r-num<<endl;
}

Measured memory_bytes: 900
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            long MOD = 1000000007;

            int N = sc.nextInt();
            int K = sc.nextInt();

            long[] fact = new long[N + 1];
            fact[0] = 1;
            for (int i = 1; i <= N; i++) {
                fact[i] = fact[i - 1] * i % MOD;
            }

            long ans = 0;
            for (int i = 0; i <= K; i++) {
                if (N - i <= 0) {
                    break;
                }

                ans = (ans + combination(fact, N, N - i, MOD) * combination(fact, N - 1, i, MOD)) % MOD;
            }

            System.out.println(ans);
        }
    }

    static long combination(long[] fact, int N, int K, long MOD) {
        long comb = fact[N];
        long factK = fact[K];
        long factM = fact[N - K];

        long m = MOD - 2;
        while (m > 0) {
            if (m % 2 == 1) {
                comb = comb * factK % MOD;
                comb = comb * factM % MOD;
                m--;
            }

            factK = factK * factK % MOD;
            factM = factM * factM % MOD;
            m = m / 2;
        }

        return comb;
    }

}


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

using namespace std;

int main(void) {
	int num, k, buf, i = 0, sum = 0, ans = 0;
	cin >> num >> k;
	vector<int> d(num + 1, 0);
	for (; i < num; i++) {
		scanf("%d", &buf);
		if (d[buf] == 0)
			sum++;
		d[buf]++;
	}
	if (sum <= k) {
		printf("0\n");
		return 0;
	}
	sort(d.begin(), d.end());
	for (i = num - sum + 1; k < sum; i++) {
		ans += d[i];
		k++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		double x=0,y=0,angle=0;
		
		while(true){
			String string = sc.nextLine();
			String[] string_array = string.split(",");
			double[] double_input = {Double.valueOf(string_array[0]), Double.valueOf(string_array[1])};
			
				if(double_input[0]==0 && double_input[1]==0) break;
				
			x=x + double_input[0]*Math.cos(Math.toRadians(90-angle));
			y=y + double_input[0]*Math.sin(Math.toRadians(90-angle));
			angle=angle+double_input[1];
		}
		
		System.out.println((int)x);
		System.out.println((int)y);
	}
}

Measured memory_bytes: 17148
#include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (b); i > (a); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada ios_base::sync_with_stdio(false)
#define int long long
int nCr(int n, int k)
{
    int C[n + 1][k + 1];
    int i, j;
    for (i = 0; i <= n; i++)
    {
        for (j = 0; j <= min(i, k); j++)
        {
            //Base case
            if (j == 0 || j == i)
                C[i][j] = 1;
            else
            {
                C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
            }
        }
    }
    return C[n][k];
}

signed main()
{
    rootdada;
    string s;//Sunny, Cloudy, Rainy, 
    cin>>s;
    if(s=="Sunny")
        cout<<"Cloudy"<<endl;
    else if(s=="Cloudy")
        cout<<"Rainy"<<endl;
    else
    {
        cout<<"Sunny"<<endl;
    }
    
}

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

using namespace std;

void a();
void b();
void c();


int main()
{
	c();
    return 0;
}

void a()
{
	int A, B;
	cin >> A >> B;
	if (A + B >= 10)
	{
		cout << "error" << endl;
	}
	else {
		cout << A + B << endl;
	}
	return;
}

void b()
{
	string S;
	cin >> S;
	for (int i = 0; i < S.size() - 1; i++)
	{
		for (int j = i + 1; j < S.size(); j++)
		{
			if (S[i] == S[j])
			{
				cout << "no" << endl;
				return;
			}
		}
	}
	cout << "yes" << endl;
	return;
}

void c()
{
	int N;
	cin >> N;
	vector<int> s(N);
	int maxv = 0;
	for (auto &si : s)
	{
		cin >> si;
		maxv += si;
	}
	if (maxv % 10 != 0)
	{
		cout << maxv << endl;
		return;
	}
	sort(s.begin(), s.end());
	for (auto si : s)
	{
		if (si % 10 != 0)
		{
			cout << maxv - si << endl;
			return;
		}
	}
	cout << 0 << endl;
	return;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }


int main() {
  string s;
  cin >> s;
  int len = s.size();
  vector<vector<int>> dp(len+1, vector<int>(13, 0));

  dp[0][0] = 1;

  rep(i, len){
    rep(j, 13){
      if(s[i] == '?'){
        rep(k, 10){
          int m =(j * 10 + k)% 13;
          dp[i + 1][m] = (dp[i + 1][m] + dp[i][j]) % MOD;
        }
      } else {
        int k = s[i] - '0';
        int m = (j * 10 + k) % 13;
        dp[i + 1][m] = (dp[i + 1][m] + dp[i][j]) % MOD;
      }
      
    }
  }

  cout << dp[len][5] % MOD << ln;
}
  


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

using namespace std;

#define LL long long
#define FOE(i, s, t) for (int i = s; i <= t; i++)

LL ret;
map<LL, int> M;

int n;

vector<LL> S;

#define K 600001
int p[K];
int p1[K], cnt, cnt2;
LL p2[K], p3[K];

void init(){
        FOE(i, 2, 100000) if (!p[i]){
                for (int j = i + i; j <= 100000; j += i) p[j] = 1;
                cnt++;
                p1[cnt] = i;
                if (i <= 2155) {
                        cnt2 = cnt;
                        p3[cnt] = (LL)i * i * i;
                        p2[cnt] = (LL)i * i;
                }
        }
}

LL decompose(LL id){
        FOE(i, 1, cnt2){
                LL m3 = p3[i];
                while (id % m3 == 0) id /= m3;
        }
        return id;
}

void handle(LL id){
        if (id == 1){
                ret++;
                return;
        }

        LL opp = 1, cnt3 = M[id];

        LL left = id;

        FOE(i, 1, cnt2){
                LL m2 = p2[i];
                LL m1 = p1[i];

                if (id % m2 == 0) {
                        opp *= m1; left /= m2;
                }
                else if (id % m1 == 0) {
                        opp *= m2; left /= m1;
                }

                if (opp > (LL)10000000000){
                        ret += cnt3; return;
                }
        }

        LL y = sqrt(left);
        if (y * y == left && !p[y]){
                opp = opp * y;
        }
        else {
                if (left > (LL)100000 || opp * left > (LL)10000000000){
                        ret += cnt3; return;
                }
                opp = opp * left * left;
        }
        if (opp > (LL)10000000000){
                ret += cnt3; return;
        }

        LL cnt2 = M[opp];
        if (cnt2 > cnt3) cnt3 = cnt2;
        ret += cnt3;

        M[opp] = 0; M[id] = 0;
}

int main(){
        scanf("%d", &n);
        init();
//      cout << cnt2 << endl;
        FOE(i, 1, n){
                LL d; scanf("%lld", &d);

                d = decompose(d);
//              cout << "decomposed: " << d << endl;
                if (d != -1) {
                        M[d]++; S.push_back(d);
                }
        }

        sort(S.begin(), S.end());
        FOE(i, 1, n) if (i == 1 || S[i - 2] != S[i - 1]){
                LL foc = S[i - 1];
                handle(foc);
        }

        cout << ret << endl;
        return 0;
}


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

#define MAX 2000
#define LRMAX 1999
#define ANSMAX 3999

using namespace std;

int light_1d(int (*a)[MAX], int l, int i, int j, int d){
  int s = 0;

  while(true){
    if(d==0){
      j++;
      if(j>l-1 || a[i][j] == 1) break;
      s++;
    }
    else if(d==1){
      j--;
      if(j<0 || a[i][j] == 1) break;
      s++;
    }
  }

  return s;
}

int light_4d(int (*a)[MAX], int (*a_flip)[MAX], int H, int W, int i, int j, int ans){
  int center = 1;

  int up = light_1d(a_flip, H, j, i, 1);
  if(H-(i+1)<=ans-(center+LRMAX+up)) return 0;

  int down = light_1d(a_flip, H, j, i, 0);
  if(W<=ans-(center+up+down)) return 0;

  int left = light_1d(a, W, i, j, 1);
  if(W-(j+1)<=ans-(center+up+down+left)) return 0;

  int right = light_1d(a, W, i, j, 0);
  if(center+up+down+left+right<=ans) return 0;

  int sum = center + up + down + left + right;

  return sum;
}

int main(void){

  int H, W;
  string S;
  int a[MAX][MAX], a_flip[MAX][MAX];
  int result, ans = 0;

  cin >> H >> W;
  for(int i=0; i<H; i++){
    cin >> S;
    for(int j=0; j<W; j++){
      if(S[j]=='.') a[i][j] = 0;
      else if(S[j]=='#') a[i][j] = 1;
      a_flip[j][i] = a[i][j];
    }
  }

  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(a[i][j]==1) continue;
      if((result = light_4d(a, a_flip, H, W, i, j, ans))!=0) ans = result;
      if(ans==ANSMAX) break;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 34856
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
typedef vector<int> vi;
#define MOD 1000000007
#define INF 1000000000000000007LL

const int N = 100005;
 
// it's swapnil07 ;)
 
#ifdef SWAPNIL07
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
#else
#define endl '\n'
#define trace(...)
#define end_routine()
#endif


void solve(){
    int n, m, x; cin>>n>>m>>x;
    int mx = pow(2, n);
    int v[n][m];
    int c[n];
    For(i, 0, n){
        cin>>c[i];
        For(j, 0, m){
            cin>>v[i][j];
        }
    }
    int ans = INF;
    for(int z=1; z<mx; z++){
        int mask = z;
        int arr[m];
        int cost = 0;
        memset(arr, 0, sizeof(arr));
        for(int i=0; i<n; i++){
            if(mask%2){
                cost += c[i];
                for(int j=0; j<m; j++){
                    arr[j]+=v[i][j];
                }
            }
            mask /= 2;
        }
        bool fl = true;
        for(int j=0; j<m; j++){
            if(arr[j]<x)
                fl=false;
        }
        if(fl){
            ans = min(ans, cost);
        }
    }
    if(ans == INF){
        cout<<-1;
    }
    else
        cout<<ans;
}


signed main()
{
    fast
    #ifdef SWAPNIL07
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    int t=1;
    // cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }
    return 0;
}





Measured memory_bytes: 4124
#C
inf = float("inf")
H,W = map(int,input().split())
A = [list(map(int,input().split())) for i in range(H)]

ans = inf
for i in range(H):
    for j in range(W):
        yoko = i
        tate = j
        
        kari = 0
        for h in range(H):
            for w in range(W):
                if h != yoko and w != tate:
                    kari+=A[h][w]*(min(abs(yoko-h),abs(tate-w)))
        ans = min(kari,ans)

print(ans)



Measured memory_bytes: 5620
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
using namespace std;
const int N=200010;
typedef long long ll;
int n,prd,fail[N],k=0;
char a[N];
ll l,r,pre[N][30];
inline ll fib(ll p,int c){
	if(p<=n) return pre[p][c];
	if(p<=n*2) return pre[n][c]+pre[p-n][c];
	ll ret1=pre[n][c]+pre[prd][c],ret2=pre[n][c],a=n+prd,b=n;
	while(p>a+b){
		ll c=ret1; ret1+=ret2; ret2=c;
		c=a; a+=b; b=c;
	}
	return ret1+fib(p-a,c);
}
inline ll cal(ll p,int c){
	if(p<=n) return pre[p][c];
	if(n%prd==0){
		ll ret=1LL*(p-n)/prd*pre[prd][c]+pre[n][c];
		p%=prd;
		return ret+pre[p][c];  
	}
	else return fib(p,c);
}
 
int main(){
	scanf("%s",a+1);
	n=strlen(a+1)/2;
	for (int i=1;i<=n;i++){
		for (int j=0;j<26;j++) pre[i][j]=pre[i-1][j];
    	pre[i][a[i]-'a']++;
	}
	scanf("%lld%lld",&l,&r);
	for(int i=2;i<=n;i++){
		while (k&&a[k+1]!=a[i]) k=fail[k];
		if (a[k+1]==a[i]) k++;
		fail[i]=k;
	}
	prd=n-fail[n];
	for(int i=0;i<26;i++)
		printf("%lld ",cal(r,i)-cal(l-1,i));
	return 0;
}

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

ll ara[100010];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll i, j, k, l, m, n, sum=0, nc=0, mn=1000000010;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>ara[i];
        sum += abs(ara[i]);
        if(ara[i]<0)
            nc++;
        mn = min(mn, abs(ara[i]));
    }
    if(nc%2)
        sum -= 2*mn;

    cout<<sum<<endl;

    return 0;
}


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

int64_t gcd(int64_t a,int64_t b){
  while(b!=0){
    int64_t temp=a%b;
    a=b;
    b=temp;
  }
  return a;
}

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

int main(){
  int64_t N,M;
  cin >> N >> M;
  int64_t L=lcm(N,M);
  string S,T;
  cin >> S >> T;
  int64_t a=0;
  int64_t b=0;
  while(1){
    if((a>=N)||(b>=M)){
      break;
    }
    if(a*(L/N)==b*(L/M)){
      if(S.at(a)==T.at(b)){
        a++;
        b++;
      }else{
        cout << -1 << endl;
        return 0;
      }
    }else if(a*(L/N)<b*(L/M)){
      a++;
    }else{
      b++;
    }
  }
  cout << L << endl;
  return 0;
}


Measured memory_bytes: 3748
h,w,a,b=map(int,input().split())
ans=[['0']*w for _ in range(h)]
if a==0:
  for i in range(b):
    for j in range(w):
      ans[i][j]='1'
elif b==0:
  for i in range(h):
    for j in range(a):
      ans[i][j]='1'
else:
  for i in range(b):
    for j in range(a):
      ans[i][j]='1'
  for i in range(b,h):
    for j in range(a,w):
      ans[i][j]='1'
for i in range(h):
  print(''.join(ans[i]))

Measured memory_bytes: 11892
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b) //最大公約数
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}

ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}

ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}

ll sum(ll n) { //整数sまでの合計
	if (n == 0) {
		return 0;
	}

	int s = sum(n - 1);
	return s + n;
}

bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}

// ===============================================================

int main() {
	string s;
	ll k;
	cin >> k;
	cin >> s;
	if (s.size() <= k) {
		cout << s << endl;
	}
	else {
		cout << s.substr(0, k) << "..." << endl;
	}
}

Measured memory_bytes: 3684
fn read<T: std::str::FromStr>() -> T {
   let mut s = String::new();
   std::io::stdin().read_line(&mut s).ok();
   s.trim().parse().ok().unwrap()
}

fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
   let s = read::<String>();
   s.split(delimiter)
      .map(|e| e.parse().ok().unwrap())
      .collect::<Vec<T>>()
}

fn main() {
   let nk = readn::<i64>(" ");
   let n = nk[0];
   let k = nk[1];
   let l = n / k;
   let ans = std::cmp::min((n - k * l).abs(), (n - k * (l + 1)).abs());
   println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll ok = 9999999999;
    ll ng = 99999999999;
    while (ng-ok>1) {
        string a;
        ll mid = (ok + ng) / 2;
        cout << '?' << " " << mid << endl;
        cin >> a;
        if (a == "N")ok = mid;
        else ng = mid;
    }
    ll yy = ng;
    while (yy > 10) {
        yy /= 10;
    }
    if (yy==9) {
        ll now = 1;
        while (true) {
            cout << '?' << " " << now << endl;
            string f;
            cin >> f;
            if (f == "N") {
                break;
            }
            now *= 10;
        }
        cout << '!' << " " << ng/(100000000000/now) << endl;
    }
    else {
        ll now = 10000000000;
        while (true) {
            cout << '?' << " " << now - 1 << endl;
            string a;
            cin >> a;
            if (a == "N")break;
            now /= 10;
            ng /= 10;
            if (ng < 10)break;
        }
        cout << '!' << " " << ng << endl;
    }
}

Measured memory_bytes: 3700
using Yorukatsu038.Questions;
using Yorukatsu038.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu038.Questions
{
    /// <summary>
    /// ARC079 B
    /// </summary>
    public class QuestionE : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            const int n = 50;
            var k = inputStream.ReadLong();
            var div = k / n;
            var mod = (int)(k % n);

            var upper = n * 2 + div - mod;
            var lower = n + div - (mod + 1);

            yield return n;
            yield return string.Join(" ", Enumerable.Repeat(upper, mod).Concat(Enumerable.Repeat(lower, n - mod)));
        }
    }
}

namespace Yorukatsu038
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionE();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace Yorukatsu038.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace Yorukatsu038.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int ma = 0;
  REP(i, 0, n-2){
    REP(j, i+1, n-1){
      chmax(ma, abs(a[i]-a[j]));
    }
  }

  cout << ma << endl;

  return 0;
}


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

int main(){

    string s;
    cin>>s;

    int c = 0;
    
    string a[3] = {"Sunny", "Cloudy", "Rainy"};


    for(int i = 0; i < 3;i++){
        if(a[i] == s){
            cout<<a[(i+1) % 3];
        }
    }

}

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

using namespace std;

typedef long long ll;
#define mems(p) memset(p,-1,sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"

const int mxN = 5e5 + 1;
const ll MOD = 1e9 + 7;

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

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

int main() {
	fast();
	int x, n;
	cin >> x >> n;
	vector<bool> vals(201, false);
	for (int i = 0; i < n; ++i)
	{
		int a;
		cin >> a;
		vals[a] = true;
	}
	for (int i = 0; i < 60; ++i)
	{
		if (x - i < 0 || vals[x-i] == false) {
			cout << x-i << nl;
			break;
		} else if (vals[x+i] == false) {
			cout << x+i << nl;
			break;
		}
	}
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define PER(i, a, b) for (long long i = a; i >= b; --i)
#define maxclr(a) memset((a), 0x3f, sizeof(a))
#define minclr(a) memset((a), 0xcf, sizeof(a))
#define clr(a) memset((a), 0, sizeof(a))
#define ull unsigned long long
#define ll long long
using namespace std;

inline ll read(){
	ll s = 0, w = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9'){
		if (ch == '-') w *= -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9'){
		s = s * 10 + ch - '0';
		ch = getchar();
	}
	return s * w;
}

inline void work(){
	ll n = read(), a = read(), b = read(), ans = 0;
	if (a == 0) puts("0");
	else {
		ll m = n / (a + b);
		n %= a + b;
		ll ans = m * a;
		if (n > a) ans += a;
		else ans += n;
		printf("%lld\n", ans);
	}
}

int main(){
	work();
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int a,b,c,d,e,sum;
int s[5];
int i=0,j=0;
int main (){
		for (i=0;i<5;i++){
			scanf("%d",&s[i]);
		}
		sum=0;
		for(j=0;j<5;j++){
			if(40>s[j]) sum=sum+40;
			else  sum=sum+s[j];
			}
		printf("%d\n",sum/5);
	return 0;
}

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

using namespace std;

int main(){
//ifstream cin("tst.in");
int n;
cin >> n;
long long x;
vector <long long> a;
for (int i = 1; i <= n; i++) {
	cin >> x;
	a.push_back(x);
}
sort(a.begin(),a.end());
int l=a[a.size()-1]; //left
int r=l;             // right
int i=0,j=a.size()-2;
long long sum=0;
while(i<j){
        int li=abs(l-a[i]),ri=abs(r-a[i]);
        int lj=abs(l-a[j]),rj=abs(r-a[j]);
        if(li>ri||lj>rj){ //left side
                if(li>lj){
                        sum+=li;
                        l=a[i++];
                }else{
                        sum+=lj;
                        l=a[j--];
                }
        }else{
                if(ri>rj){
                        sum+=ri;
                        r=a[i++];
                }else{
                        sum+=rj;
                        r=a[j--];
                }
        }
        //cout<<l<<"---"<<r<<"------"<<i<<"---"<<j<<"----------"<<sum<<endl;
}
sum+=max(abs(l-a[i]),abs(r-a[i]));
cout<<sum<<endl;
return 0;
}

Measured memory_bytes: 1400
#include<cstdio>
#include<algorithm>
#define maxn 100005
#define LL long long
#define INF (LL)(1e16)
using namespace std;
int n,a[maxn],f[maxn];
LL sum,ans=-INF,pre[maxn];
int main()
{
	scanf("%d%d",&n,&a[1]);
	for(int i=2;i<=n;i++)
	{
		char s[5];
		scanf("%s",s);
		if(s[0]=='-') f[i]=1;
		scanf("%d",&a[i]);
	}
	for(int i=n;i>0;i--) pre[i]=pre[i+1]+a[i];
	int la=1;
	while(la<=n&&!f[la]) sum+=1ll*a[la++];
	while(la<=n)
	{
		int la1=la+1; LL sum1=0;
		while(la1<=n&&!f[la1]) sum1+=1ll*a[la1++];
		if(la1<=n) ans=max(ans,sum-sum1-a[la]+pre[la1]);
		sum+=sum1-a[la]; la=la1; 
	}
	ans=max(ans,sum);
	printf("%lld\n",ans);
}

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

using namespace std;

int main(){
  int n;
  int ans = 0;
  cin >> n;
  while (n > 0) {
    ans += n % 10;
    n /= 10;
  }
  if (ans == 1) {
    cout << 10 << endl;
  } else {
    cout << ans << endl;
  }
  return(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for( int i=a; i<b; i++ )
#define REP(i,n) rep(i,0,n)
#define INF 1000000
using lli = long long int;
using ulli = unsigned long long int;
typedef pair<int, int> P;

struct edge{ int u, v; lli cost; };
struct DirectedGraph
{
  int vertex_num;
  int edge_num;
  vector<edge> edge_list;
  vector< vector<int> > adj_list;
	vector< vector<lli> > distance_matrix;
};


template <typename T>
vector<int> argsort(const vector<T> &v) {

  // initialize original index locations
  vector<int> idx(v.size());
  iota(idx.begin(), idx.end(), 0);

  // sort indexes based on comparing values in v
  sort(idx.begin(), idx.end(),
       [&v](int i1, int i2) {return v[i1] < v[i2];});

  return idx;
}

template<typename T>
void displayVector(vector<T> v)
{
	lli n = v.size();
	REP(i,n){
		cout << v[i] << " " ;
	}
	cout << endl;
}

int count_comb(int a, int b, int c){
  if(a!=b && b!=c){ return 6; }
  else if( a==b && b==c){ return 1; }
  else{ return 3; }
}

string sub(string str, int start, int end){
  // require : start < end
  return str.substr(start, end-start+1);
}

vector<int> count( string s){
  vector<int> res(26);
  REP(i, s.size() ){
    int num = s[i] - 'a';
    res[ num ] ++; 
  }

  return res;
}

int main(){
  int n; cin >> n;
  string s; cin >> s;
  int res = 0;
  rep(i, 1, n){
    string s1 = sub(s, 0, i);
    string s2 = sub(s, i+1, n-1);

    vector<int> hist1 = count(s1);
    vector<int> hist2 = count(s2);
    int tmp = 0;
    REP(j, 26){
      if(hist1[j] && hist2[j]) tmp++;
    }
    if( tmp > res ){ res = tmp; }
  }

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

Measured memory_bytes: 3648
#include<stdio.h>

int main(void)
{
    int i, j, k;
    int n, x, cnt;
    
    while (1) {
        cnt = 0;
        scanf("%d %d", &n, &x);
        
        if ( n == 0 && x == 0)
            break;
        for ( i=1; i<=n; ++i)
            for ( j=i+1; (k = x-i-j) > j; ++j) {
                if ( k <= n)
                    ++cnt;
            }
        printf("%d\n", cnt);
    }
    
    return 0;
}


Measured memory_bytes: 2112
import fractions
from functools import reduce


N = int(input())
a = list(map(int, input().split()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

sum_a = (lcm_list(a)-1)

ans = 0
for i in a:
    ans = (sum_a % i) + ans

print(ans)

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

int main(){
    char a[3];
    bool f1 = false, f2 = false, f3 = false;
    for(int i = 0; i < 3; i++)
    {
        scanf("%c", &a[i]);
    }
    for(int i = 0; i < 3; i++)
    {
        if(a[i] == 'a')
        {
            f1 = true;
        }
        else if(a[i] == 'b')
        {
            f2 = true;
        }
        else
        {
            f3 = true;
        }
    }
    if(f1 == true && f2 == true && f3 == true)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
}


Measured memory_bytes: 888
n=int(input())
t=list(map(int,input().split()))
a=list(map(int,input().split()))
mod=10**9+7
h1=[[-1,-1]for _ in range(n)]
h1[0]=[t[0],t[0]]
for i in range(n-1):
	if t[i+1]>t[i]:
		h1[i+1]=[t[i+1],t[i+1]]
	else:
		h1[i+1]=[1,t[i+1]]
h2=[[-1,-1]for _ in range(n)]
a.reverse()
h2[-1]=[a[0],a[0]]
for i in range(n-1):
	if a[i+1]>a[i]:
		h2[-i-2]=[a[i+1],a[i+1]]
	else:
		h2[-i-2]=[1,a[i+1]]
ans=1
for i in range(n):
	ran=min(h1[i][1],h2[i][1])-max(h1[i][0],h2[i][0])+1
	if ran<=0:
		ans=0
		break
	ans*=ran
	ans%=mod
print(ans if ans>=0 else 0)


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

int main() {
  string a,b,c;
  cin >> a>>b>>c;
  char A=a.at(0)-'a'+'A';
  char B=b.at(0)-'a'+'A';
  char C=c.at(0)-'a'+'A';
  cout<<A<<B<<C<<endl;
}

Measured memory_bytes: 256