akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define AB_BHI_NI_DEGI                \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define int long long
#define pb push_back
#define N 100009
#define inf 1e18
const double PI = 3.141592653589793238462643383279;
int mod = 1e9 + 7;
//int mod = 998244353;
#define P pair<int, int>
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define vi vector<int>
#define ld long double
#define endl "\n"

void solve()
{
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int ans = 0;
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
            for (int k = j + 1; k < n; k++)
            {
                set<int> St;
                St.insert(a[i]);
                St.insert(a[j]);
                St.insert(a[k]);
                vi v;
                v.pb(a[i]), v.pb(a[j]), v.pb(a[k]);
                sort(all(v));
                if (St.size() == 3)
                {
                    if (v[0] + v[1] > v[2])
                        ans++;
                }
            }
    cout << ans << "\n";
}
int32_t main()
{
    AB_BHI_NI_DEGI
    int Test = 1;
    //cin >> Test;
    //init();
    while (Test--)
        solve();
    return 0;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;

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

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	ll ans = 0;
	rep(bit,1<<(n-1)){//列挙パターン 
		ll tmp = s[0]-'0';
		rep(i,(n-1)){//1を確認
			if(bit & 1<<i){
				ans += tmp;
				tmp = s[i+1]-'0';
			}
			else{
				tmp = 10*tmp + (s[i+1]-'0');
			}
		}
		ans += tmp;
	}
	cout << ans << endl;	
}


Measured memory_bytes: 256
import math

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

a_b= [list(map(int, input().split())) for _ in range(N_H[0])]
length =len(a_b)

a= [a_b[i][0] for i in range(length)]
b= [a_b[i][1] for i in range(length)]

counter = 0
i = 0
pattern = 0


a_max = max(a)
b_max = max(b)
a_max_idx = a.index(a_max)
b_a_max_idx = b[a_max_idx]

b.pop(a_max_idx)

b.sort()
b.reverse()

    
while True:
    if N_H[1] <= b_max and counter == 0:
        counter += 1
        print(counter)
        break
    
    if N_H[1] <= b_a_max_idx:
        counter += 1
        print(counter)
        break

    if i <= length-2:    
        if b[i] > a_max:
            N_H[1] -= b[i]

            i += 1

            counter += 1

            if N_H[1] <= 0:
                print(counter)
                break
        else:
            counter += math.ceil((N_H[1]-b_a_max_idx)/a_max)+1
            print(counter)
            break
    else:
            counter += math.ceil((N_H[1]-b_a_max_idx)/a_max)+1
            print(counter)
            break



Measured memory_bytes: 29372
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

const int N = 600;
vector<int> a[N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<ii> e(m);
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x; --y;
    a[x].push_back(y);
  }
  vector<double> dist(n);
  dist[n - 1] = 0;
  for (int i = n - 2; i >= 0; --i) {
    double sum = 0;
    for (auto& j : a[i]) {
      sum += dist[j];
    }
    dist[i] = sum / a[i].size() + 1;
  }
  double ret = dist[0];
  for (int k = 0; k < n - 1; ++k) {
    if (a[k].size() == 1) continue;
    vector<double> d(n);
    d[n - 1] = 0;
    for (int i = n - 2; i >= 0; --i) {
      double sum = 0, max_d = 0;
      for (auto& j : a[i]) {
        sum += d[j];
        max_d = max(max_d, d[j]);
      }
      if (i != k) {
        d[i] = sum / a[i].size() + 1;
      } else {
        d[i] = (sum - max_d) / (a[i].size() - 1) + 1;
      }
    }
    ret = min(ret, d[0]);
  }
  printf("%.10f\n", ret);
  return 0;
}


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

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

    int flag = 0;
    if(A % 3 == 0){
        flag = 1;
    }
    if(B % 3 == 0){
        flag = 1;
    }
    if((A+B) % 3 == 0){
        flag = 1;
    }

    if(flag == 1){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n)-1); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n)-1); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll INF = 1e18;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

/* template */

vector<int> bfs(int s,const graph &g){
    int _size = g.size();
    vector<int> c(_size,-1);
    c[s] = 0;
    queue<int> que;
    que.push(s);
    while(!que.empty()){
        int x = que.front();
        que.pop();
        for(auto nx: g[x]){
            if(c[nx]<0){
                que.push(nx);
                c[nx] = c[x]+1;
            }
        }
    }
    return c;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string n; cin >> n;
    rep(i,0,n.size()){
        if(n[i]=='7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
// #define INF __INT32_MAX__
#define INF 1e9
#define LINF __LONG_LONG_MAX__

int main() {
    int R, G, B, N; cin >> R >> G >> B >> N;
    const int N_MAX = 3000;

    ll cnt = 0;
    for (int i = 0; i <= N_MAX; i++) {
        for (int j = 0; j <= N_MAX; j++) {
            int x = N - i * R - j * G;
            int k = x / B;

            if (k < 0 || k > N_MAX) continue;
            if ((i * R + j * G + k * B) == N) {
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3608
#include<stdio.h>
int main()
{
	int a, b, c,temp;
	scanf("%d%d%d", &a, &b, &c);

	if (a > b) {
		temp = b;
		b = a;
		a = temp;
	}
	if (b > c) {
		temp = c;
		c = b;
		b = temp;
	}
	if (a > b) {
		temp = b;
		b = a;
		a = temp;
	}

	printf("%d %d %d\n", a, b, c);
	return 0;
	

}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define T() long long t;cin>>t;for(long long i=1;i<=t;i++)
#define INF (int)MAX_INT
#define INFS (int)MIN_INT
#define mod 1000000007
#define FOR(a, b, n) for(int a = b; a < n; a++)
#define REP(a,c, b) for(int a = c; a < b; a++)
#define FORD(a, b, c) for(int a = b; a >= c; a--)
#define REPD(a, c,b) for(int a = b-1; a >= c; a--)
#ifdef HOHOHO
#define DEBUG(x) cerr << #x << " : " << x << '\n'
#define DEBUGV(x) cerr << #x << " : { "; REP(_it, x.size()) cerr << x[_it] << ' '; cerr << "}" << '\n'
#define DEBUGA(x, y) cerr << #x << " : { "; REP(_it, y) cerr << x[_it] << ' '; cerr << "}" << '\n'
#define PRINTF(...) fprintf(stderr,__VA_ARGS__)
#define CHECKPOINT cerr << "OK LINE #" << __LINE__ << '\n'
#else
#define DEBUG(x) {}
#define DEBUGV(x) {}
#define DEBUGA(x, y) {}
#define PRINTF(...) {}
#define CHECKPOINT {}
#endif
#define RESET(a, b) memset(a, b, sizeof a)
#define EPS 1e-9
#define m_p make_pair
#define pb push_back
#define fi first
#define se second
#define RALL(x) x.rbegin(), x.rend()
#define all(x) x.begin(), x.end()
#define ALL(x, y) x, x+y
#define SZ(x) ((int)x.size())
#define  pi(a)  pair<a, a> 
#define  vi(a)  vector<a> 
#define  vii vector<pi>
#define  vs vector<string>
template<class T> T sqr(T x){ return x*x; }
template<class T> T binPow(T p, int q, int MOD) {
    if(q == 1) return p % MOD;
    if(q & 1) return p*(binPow(p, q-1, MOD) % MOD) % MOD;
    else return sqr(binPow(p, q/2, MOD) % MOD) % MOD;
}

ll nxt() {
    ll TemporaryVariable;
    cin >> TemporaryVariable;
    return TemporaryVariable;
}
const double PI = acos(-1.0);
#define MAXN 100001
const int G = 2e5 + 5;

 
int main(){
  ios::sync_with_stdio(false);

   int n;cin>>n;
   if(n==1)cout<<0<<endl;
   else
   cout<<1<<endl;

    #ifdef HOHOHO   
    fprintf(stderr, "%.3lf\n", clock() / (double) CLOCKS_PER_SEC );
#endif
}



























   




























       





















Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
#include<string>
typedef long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define repm(i,a,b) for(int i=(a);i>(b);i--)
#define F first
#define S second
using namespace std;
const ll INF = 1e12;
const double PI = 3.1415926535897932;
const int i_INF = 2147483647;
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 n;
double sum = 0;
int m = 1;

int main() {
	cin >> n;
	rep(i, 1, n + 1)m = m * n;
	int mm = m / n;
	vector<double> x(n);
	vector<double> y(n);
	rep(i, 0, n) {
		cin >> x[i];
		cin >> y[i];
	}
	rep(i, 0, n)rep(j, i + 1, n) {
		double s = (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]);
		sum += pow(s, 0.5) * 2 * mm;
	}
	printf("%.11f\n", sum / m);;

	return 0;
}

Measured memory_bytes: 384
import qualified Data.ByteString.Char8 as C
import           Data.Maybe ( fromJust, isNothing )

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  [n,y] <- readInts
  putStrLn $ f n y

type Mai = Int
type Yen = Int
type Pochi = (Int,Int,Int)

minPochi :: Yen -> Pochi
minPochi y = (a,b,c)
  where
    (a,r) = y `quotRem` 10000
    (b,s) = r `quotRem` 5000
    c     = s `quot` 1000

canPay :: Mai -> Yen -> Maybe Pochi
canPay n y = h i
  where
    i = minPochi y
    h :: Pochi -> Maybe Pochi
    h p@(a,b,c)
      | m == 0 = Just p
      | m > 3 && b > 0 = h (a, b-1, c+5)
      | m > 0 && a > 0 = h (a-1,b+2,c)
      | otherwise = Nothing
      where
        m = n-(a+b+c)

f n y
  | isNothing p = "-1 -1 -1"
  | otherwise   = show a ++ " " ++ show b ++ " " ++ show c
  where
    p = canPay n y
    Just (a,b,c) = p

Measured memory_bytes: 380
#include<iostream>
#include<string>
using namespace std;
int main(){
	string a,b,c;
	cin>>a>>b>>c;
	string ans;
	ans+=(a[0]-32);
	ans+=(b[0]-32);
	ans += (c[0] - 32);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque

N = int(input())
eg = []
v_cnt = [0 for i in range(N)]
v_to = [[] for i in range(N)]
v_ans = [0 for i in range(N)]
v_visited = [False for i in range(N)]

for i in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    eg.append((a, b))
    v_cnt[a] += 1
    v_cnt[b] += 1
    v_to[a].append(b)
    v_to[b].append(a)

c = [int(i) for i in input().split()]
c.sort()

v_m = 0
for i in range(N):
    if v_m < v_cnt[i]:
        v_m = i

q = deque([v_m])
while len(q) > 0:
    i = q.popleft()

    v_ans[i] = c.pop()
    v_visited[i] = True
    for ni in v_to[i]:
        if not v_visited[ni]:
            q.append(ni)

ans = 0
for a, b in eg:
    ans += min(v_ans[a], v_ans[b])

print(ans)
print(*v_ans)

Measured memory_bytes: 7212
x, k, d = map(int, input().split())
x = abs(x)
ans = 1000000000000000
m = x // d
if m > k:
    print(abs(x-k*d))
else:
    if (k%2==0 and m%2==1) or (k%2==1 and m%2==0):
        m += 1
    ans = min(ans,x-m*d)
    """
    if m+2 <= k:
        ans = min(ans,ans+2*d)
        ans = min(ans,ans-2*d)
        """
    print(abs(ans))

Measured memory_bytes: 8924
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		if(a < b){
			if(b < c){
			System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}else{
			System.out.println("No");
		}
	}
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define bk back()
#define pb push_back

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(x,a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

// FILE I/O
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
    // cin.exceptions(cin.failbit);
    // throws exception when do smth illegal
    // ex. try to read letter into int
    if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

int32_t main() {

    setIO();

    int n; n = 5; vi arr(n); trav(x,arr) cin >> x;

    F0R(i,n) {
        if (arr[i] == 0) cout << i+1 << " ";
    }

}


Measured memory_bytes: 3652
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>


using namespace std;
int main() {

	int a, b;
	cin >> a >> b;

	a += b;
	if (a % 2)a++;
	cout << a / 2 << endl;

	return 0;
}

Measured memory_bytes: 256
using Yorukatsu055.Questions;
using Yorukatsu055.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Yorukatsu055.Questions
{
    /// <summary>
    /// https://atcoder.jp/contests/abc067/tasks/abc067_a
    /// </summary>
    public class QuestionA : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var ab = inputStream.ReadIntArray();
            if (CanDivideBy3(ab[0]) || CanDivideBy3(ab[1]) || CanDivideBy3(ab[0] + ab[1]))
            {
                yield return "Possible";
            }
            else
            {
                yield return "Impossible";
            }
        }

        bool CanDivideBy3(int n) => n % 3 == 0;
    }
}


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

#region Base Classes

namespace Yorukatsu055.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 Yorukatsu055.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: 11348
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    int n, m;
    cin >> n >> m;
    int Count = 0;
    while(n > 0)
    {
        Count++;
        n /= m;
    }
    cout << Count << endl;
    return 0;
}


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

using P=pair<int,int>;
vector<int> res;
vector<vector<P>> g;

void dfs(int v,int p,int c){
  res[v]=c;
  for(auto nv : g[v]){
    if(nv.first==p) continue;
    if(nv.second & 1) dfs(nv.first,v,1-c);
    else dfs(nv.first,v,c);
  }
}

int main(){
  int n;
  cin >> n;
  g.assign(n,vector<P>());
  for(int i=0;i<n-1;++i){
    int u,v,w;
    cin >> u >> v >> w;
    u--;
    v--;
    g[u].push_back(P(v,w));
    g[v].push_back(P(u,w));
  }
  res.assign(n,0);
  dfs(0,-1,1);
  for(auto v : res) cout << v << endl;
  return 0;
}


Measured memory_bytes: 8960
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    string s;
    cin>>s;
    int cnt[26]={};
    rep(i,s.length())cnt[s[i]-'a']++;
    int o=0;
    rep(i,26)o+=cnt[i]%2;
    if(s.length()%2==0&&o||s.length()%2&&o>1){
        cout<<0<<endl;
        return;
    }
    rep(i,26)cnt[i]/=2;
    int ans=1;
    int f[41]={1};
    REP(i,1,40)f[i]=i*f[i-1];
    int n=s.length()/2;
    rep(i,26){
        if(cnt[i]){
            ans*=f[n]/f[cnt[i]]/f[n-cnt[i]];
            n-=cnt[i];
        }
    }
    cout<<ans<<endl;
}


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

int main(){
	int n,W;
	cin >> n >> W;
	int weight[n];
	int value[n];
	for(int i = 0;i<n;i++){
		cin >> weight[i] >> value[i];
	}

	long long int dp[n+1][W+1];
  for (int i = 0; i <= n; i++) 
   { 
       for (int w = 0; w <= W; w++) 
       { 
           if (i==0 || w==0) 
               dp[i][w] = 0; 
           else if (weight[i-1] <= w) 
                 dp[i][w] = max(value[i-1] + dp[i-1][w-weight[i-1]],  dp[i-1][w]); 
           else
                 dp[i][w] = dp[i-1][w]; 
       } 
   } 

	cout << dp[n][W]  << endl;
	return 0;
}

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

#define ll long long int
#define str string

ll MOD = 1000000007, INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Max = INF, Min = -1;
ll a = 0, b = 0, c = 0, n = 0, sum = 0;
ll A[500000] = {}, B[500000] = {}, ruiseki[500000] = {}, dp[100][10] = {};
int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
vector <ll> v;
str S;
bool check = false, check2 = false;

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

int main() {

	//Code Line
	cin >> n;
	for (int i = 0; i < n; i++) cin >> A[i];

	for (int i = n-1; i >= 0; i--) {
		a = 0;
		for (int j = i; j < n; j += i + 1) {
			if (B[j])a++;
		}
		if (A[i] != a % 2)b++,B[i]++;

	}
	cout << b << endl;
	for (int i = 0; i < n; i++) if (B[i])cout << i+1 << endl;
	cin >> n;
	return 0;
}


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

int main()
{
	int a, b;
	cin >> a >> b;
	int preAns = a * b;
	for (int i = 1; i <= 3; i++) {
		if ((preAns * i)%2) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 int main(){
     int x,y,d;
     cin >> x >> y;

     for (int i=0;i<y;i++){
         cin >>d;
         x-=d;
         if (x<0){
             cout << -1 << endl;
             return 0;
         }
     }
     cout << x << endl;

return 0;
 }

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int d,w;
int f[100][100];
int valid(int x,int y,int dx,int dy){
	int e = 1000000000;
	int in = 0;
	int res = 0;
	for(int i=0;i<dx;i++){
		e = min(e,f[x+i][y]);
		e = min(e,f[x+i][y+dy-1]);
	}
	for(int i=0;i<dy;i++){
		e = min(e,f[x][y+i]);
		e = min(e,f[x+dx-1][y+i]);
	}
	for(int i=1;i<dx-1;i++){
		for(int j=1;j<dy-1;j++){
			in = max(in,f[x+i][y+j]);
		}
	}
	if(in >= e)return -1;
	for(int i=1;i<dx-1;i++){
		for(int j=1;j<dy-1;j++){
			res += e-f[x+i][y+j];
		}
	}
	return res;
}
int sol(int x ,int y){
	int res = 0;	
	for(int i=3;x+i<=d;i++){
		for(int j=3;y+j<=w;j++){
			res = max(res,valid(x,y,i,j));
		}
	}
	return res;
}
bool solve(){
	cin >> d >> w;
	if(d+w==0)return false;
	for(int i=0;i<d;i++){
		for(int j=0;j<w;j++){
			cin >> f[i][j];
		}
	}
	int ans = 0;
	for(int i=0;i<d;i++){
		for(int j=0;j<w;j++){
			ans = max(ans,sol(i,j));
		}
	}
	cout << ans << endl;
	return true;
}
int main(){
	while(solve()){}
	return 0;
}


Measured memory_bytes: 3100
/*

Coded by peyha X

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int NMAX=100+1,VMAX=1e5+1,AUCUN=-1,INF=1e9;

int n,w,poids[NMAX],value[NMAX];
int bestPoids[VMAX];


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> n >> w;
	
	for(int i=1;i<=n;i++){
		cin >> poids[i] >> value[i];
	}
	
	for(int p=0;p<VMAX;p++){
		bestPoids[p]=INF;
	}
	int ans=0;
	
	bestPoids[0]=0;
	
	for(int id=1;id<=n;id++){
		
		for(int v=VMAX-1;v>=0;v--){
			
			if(bestPoids[v]+poids[id]<=w){
				
				bestPoids[v+value[id]]=min(bestPoids[v+value[id]],bestPoids[v]+poids[id]);
				ans=max(ans,v+value[id]);
			}
		}
	}
				
	cout << ans << '\n';
	
	
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n,k;
  cin >> n >> k;
  if(k==2) {
    ll ans=(n/2)*(n/2)*(n/2)+((n+1)/2)*((n+1)/2)*((n+1)/2);
    cout << ans << endl;
  }
  else if(k%2) {
    ll ans=(n/k)*(n/k)*(n/k);
    cout << ans << endl;
  }
  else {
    n/=(k/2);
    ll ans=(n/2)*(n/2)*(n/2)+((n+1)/2)*((n+1)/2)*((n+1)/2);
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scanner=new Scanner(System.in);
        String S=scanner.next();
        int result=0;
        for(int i=0;i<4;i++){
            char c=S.charAt(i);
            if(c=='+'){
                result++;
            }else{
                result--;
            }
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 21076
import collections
n = int(input())
s = [input().strip() for u in range(n)]
r = [dict(collections.Counter(m)) for m in s]
t = ["".join(["{}{}".format(k, m[k]) for k in sorted(m.keys())]) for m in r]
u = dict(collections.Counter(t))
print(int(sum([v*(v-1)/2 for v in u.values()])))

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



int main()
{
    
    long long a,b,c,d;
    long long ans;
    
    cin >> a >> b >> c >> d;

    if (a >= 0 && b >= 0 && d >= 0)
        ans = b * d;
    else if (a >= 0 && b >= 0 && d < 0)
        ans = a * d;
    else if (a < 0 && b >= 0 && c >= 0 && d >= 0)
        ans = b * d;
    else if (a < 0 && b >= 0 && c < 0 && d >= 0)
        if (a * c > b * d)
            ans = a * c;
        else
            ans = b * d;
    else if (a < 0 && b >= 0 && d < 0)
        ans = a * c;
    else if (b < 0 && c >= 0 && d >= 0)
        ans = b * c;
    else if (b < 0 && c < 0 )
        ans = a * c;
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main() {
    long long int A, B;
    cin >> A >> B;
    long long int ans=0;
    ans = A%2 ? ans^A : ans;
    ans = B%2 ? ans : ans^B;
    if(ans==0) {
        if(((B-A+1)/2)%2!=0) {
            ans = ans^1;
        }
    } else if(A%2!=B%2) {
        if(((B-A+1)/2)%2==0) {
            ans = ans^1;
        }
    } else {
        if(((B-A)/2)%2!=0) {
            ans = ans^1;
        }
    }

    cout << ans << endl;


    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int main()
{
	cin>>s;
	int i;
	for(i=0;i<s.size();i++)
		if(s[i]=='C')break;
	for(;i<s.size();i++)
		if(s[i]=='F')break;
	if(i==s.size())
		cout<<"No\n";
	else cout<<"Yes\n";
	return 0;
}


Measured memory_bytes: 256
#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, M;
  cin >> N >> M;
  if (N == M)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000
#define ll long long int
using namespace std;




int main(){
ll N,M; cin>>N>>M;
ll need = 0;
vector < pair <ll,ll> > mise(0);
for(int i=0;i<N;i++){
  ll aaa,bbb; cin>>aaa>>bbb;
  mise.push_back(make_pair(aaa,bbb));
}

 // firstが小さい順、secondが小さい順にソート
  sort(mise.begin(), mise.end());
int it=0;
  for(;;){
    if(M <= mise[it].second) {

      need += M*mise[it].first;
      break;

    } else {

      M = M - mise[it].second;
      need += mise[it].second * mise[it].first;
      it++;


    }
  }

  cout<<need<<endl;



return 0;


}

Measured memory_bytes: 2420
# coding:utf-8

NIL =  None

class Node():
	def __init__(self, key, pri):
		self.key = key
		self.pri = pri
		self.right = NIL
		self.left = NIL


def rightRotate(t):
	s = t.left
	t.left = s.right
	s.right = t
	return s

def leftRotate(t):
	s = t.right
	t.right = s.left
	s.left = t
	return s

def insert(t, key, pri):
	if t == NIL:
		return Node(key, pri)
	if key == t.key:
		return t

	if key < t.key:
		t.left = insert(t.left, key, pri)
		if t.pri < t.left.pri:
			t = rightRotate(t)
	else :
		t.right = insert(t.right, key, pri)
		if t.pri < t.right.pri:
			t = leftRotate(t)

	return t

def erase(t, key):
	if t == NIL:
		return NIL
	if key == t.key:
		if t.right == NIL and t.left == NIL:
			return NIL
		elif t.left == NIL:
			t = leftRotate(t)
		elif t.right == NIL:
			t = rightRotate(t)
		else :
			if t.left.pri > t.right.pri:
				t = rightRotate(t)
			else :
				t = leftRotate(t)
		return erase(t, key)

	if key < t.key:
		t.left = erase(t.left, key)
	else:
		t.right = erase(t.right, key)

	return t

def find(t, key):
	if t == NIL:
		return False
	if key == t.key:
		return True

	if key < t.key:
		return find(t.left, key)
	else:
		return find(t.right, key)


head = Node(-1, 2000000001)

def print_priorder(t):
	if t == NIL:
		return

	if t != head:
		print(" " + str(t.key), end='')

	print_priorder(t.left)
	print_priorder(t.right)

def print_inorder(t):
	if t == NIL:
		return

	print_inorder(t.left)
	if t != head:
		print(" " + str(t.key), end='')
	print_inorder(t.right)


n = int(input()) # 命令の数

for i in range(n):
	inst = input().split()

	if inst[0] == "insert":
		insert(head, int(inst[1]), int(inst[2]))

	elif inst[0] == "find":
		if find(head, int(inst[1])):
			print("yes")
		else :
			print("no")

	elif inst[0] == "delete":
		erase(head, int(inst[1]))

	elif inst[0] == "print":
		print_inorder(head)
		print()
		print_priorder(head)
		print()


Measured memory_bytes: 52024
#include <stdio.h>
int main(void){
    int n;
    scanf("%d", &n);
    int a[n];
    for (int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    
    int flag = 1;
    for (int i = 0; i < n; i++){
        if (a[i] % 2 == 0){
            if (a[i] % 3 != 0 && a[i] % 5 != 0) flag = 0;
        }
    }
    if (flag) printf("%s\n", "APPROVED");
    else printf("%s\n", "DENIED");

    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    string s;
    cin >> s;
    cout << s.substr(0, 4) << ' ' << s.substr(4) << endl;
    return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
 
    using namespace std;
 
    typedef long long ll;
    typedef long double ld;
 
    typedef pair<int, int> pi;
    typedef pair<ll,ll> pl;

    typedef vector<int> vi;
    typedef vector<ll> vl;
    typedef vector<pi> vpi;
    typedef vector<pl> vpl;
    typedef vector<vi> vvi;

    #define FOR(i, a, b) for (int i=a; i<(b); i++)
    
    #define sz(x) (int)(x).size()
    #define mp make_pair
    #define pb push_back
    #define f first
    #define s second
    #define lb lower_bound
    #define ub upper_bound
    #define all(x) x.begin(), x.end()
 
    template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
    template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
    
    #define trav(container, it) for(typeof(container.begin()) it=container.begin(); it!=container.end(); it++)
 
    const int MOD = 1000000007;
    const char nl = '\n';
 
    int main() 
    {
        ios_base::sync_with_stdio(0); cin.tie(0);
            int n;cin>>n;

            ll temp=7%n,count=1;

            if(n%2 == 0) cout<<-1;
            else
            {
                while(temp != 0)
                {
                    ++count;
                    temp = (temp*10 + 7)%n;
                    if(count>n) {count=-1;break;}
                }
                cout<<count;
            }
    }


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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);
	int i,j;
	ll n,k;
	cin>>n>>k;
	ll a[n];
	for(i=0;i<n;i++){
		cin>>a[i];
		a[i]--;
	}
	VI v(n,-1);
	v[0]=0;
	ll te=0;
	ll loop;
	ll m;
	VI ans(202020,-1);
	ans[0]=0;
	while(1){
		if(v[a[te]]==-1){
			v[a[te]]=v[te]+1;
			ans[v[te]+1]=a[te];
		} 
		else {
			loop = v[te]+1-v[a[te]];
			m = v[te];
			break;
		}
		te = a[te];
	}
	if(k>m){
		ll u = k-m;
		k -= (u+loop-1)/loop * loop;
	}
	cout<<ans[k]+1<<endl;
}

Measured memory_bytes: 7936
a, b = map(int, input().split())
l = [[int(i) for i in input().split()] for i in range(b)] 

for i in range(b):
    l[i].append(i)

l = sorted(l,key=lambda x: (x[0],x[1]))

l[0].append(1)
for i in range(1,b):
    if l[i][0] != l[i-1][0]:
        l[i].append(1)
    else:
        l[i].append(l[i-1][3] + 1)

for i in range(b):
    l[i].append(str(l[i][0]).zfill(6) + str(l[i][3]).zfill(6))

l = sorted(l,key=lambda x: (x[2]))

for i in range(b):
    print(l[i][4])


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

int main(){
 int a,b;
 string s;
 cin >> a >> b >>s;
 int check =0;
 for(int i=0;i<s.size();i++){
   if(s.at(i)=='-') check ++;
 }
 if(s.at(a)=='-'&&s.size()==a+b+1&&check ==1){
   cout <<"Yes" << endl;
 }
 else{
   cout <<"No" << endl;
 }
}


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

#ifdef LOCAL
  #include <contest/local.hpp>
#else
  #define LOG(...) do {} while (false)
#endif

#define REP(i,n) for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)
#define ALL(x) (x).begin (), (x).end ()

using namespace std;

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

  unsigned n;
  cin >> n;

  multiset <int> group;
  vector <int> a;

  REP (i, n)
  {
    int value;
    cin >> value;
    a.emplace_back (value);
  }

  auto i = a.begin ();
  group.insert (* i);

  for (++ i; i != a.end (); ++ i)
  {
    auto && elem = * i;
    auto ite = group.lower_bound (elem);
    if (ite != group.begin ())
    {
      -- ite;
      group.erase (ite);
    }
    group.insert (elem);
#ifdef LOCAL
    cerr << "dump: ";
    for (auto && eeeeee : group)
    {
      cerr << eeeeee << " ";
    }
    cerr << endl;
#endif
  }
  cout << group.size () << endl;
}



Measured memory_bytes: 5368
#!/usr/bin/env python3

def main():
    n = int(input())
    a = largest_nonlarger_dividor(n)
    b = n // a
    print(len(str(b)))

def largest_nonlarger_dividor(n):
    assert n > 0
    res = 1
    for i in range(2, int(n ** 0.5) + 10):
        if i ** 2 > n:
            break
        if n % i == 0:
            res = i
    return res

main()



Measured memory_bytes: 3064
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()


using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;




int main(){
    int n;
    cin >> n;
    vector<vector<int>> v(n, vector<int>(26, 0));

    rep(i, n){
        string s;
        cin >> s;

        for(char c : s){
            v[i][c - 'a']++;
        }
    }
    string res = "";
    vector<int> list(26, INF);
    rep(i, 26){
        rep(j, n){
            list[i] = min(list[i], v[j][i]);
        }
    }
    rep(i, 26){
      char c = 'a' + i;
        rep(j, list[i])res.push_back(c);
    }
    cout << res << endl;
}


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

int main(){
    int n;
    char s[4000];
    long long int sum = 0;
    scanf("%d",&n);
    scanf("%s",s);
    long long int rnum = 0;
    long long int gnum = 0;
    long long int bnum = 0;
    for(int i = 0;i < n;i++){
        if(s[i] == 'R'){
            rnum++;
            continue;
        }else if(s[i] == 'G'){
            gnum++;
            continue;
        }else{
            bnum++;
            continue;
        }
    }
    sum = rnum*gnum*bnum;
    for(int i = 1;i < n - 1;i++){
        for(int j = 1;i - j >=0 && i + j < n;j++){
            if(s[i] != s[i - j] && s[i] != s[i + j] && s[i - j] != s[i + j]){
                sum--;
            }
        }
    }
    printf("%lld",sum);
    return 0;
}


Measured memory_bytes: 1704
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}

int MOD = 1000000007;
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
struct Matrix {
    int f[3][3];
    Matrix() {memset(f,0,sizeof(f));}
    friend Matrix operator * (const Matrix &a,const Matrix &b) {
	Matrix c;
	for(int i = 0 ; i < 3 ; ++i) {
	    for(int j = 0 ; j < 3 ; ++j) {
		for(int k = 0 ; k < 3 ; ++k) {
		    update(c.f[i][j],mul(a.f[i][k],b.f[k][j]));
		}
	    }
	}
	return c;
    }
    void unit() {
	for(int i = 0 ; i < 3 ; ++i) f[i][i] = 1;
    }
}A,B,ans;
int N,M,x[MAXN];
Matrix fpow(Matrix a,int c) {
    Matrix res,t = a;
    res.unit();
    while(c) {
	if(c & 1) res = res * t;
	t = t * t;
	c >>= 1;
    }
    return res;
}
void Solve() {
    read(N);read(M);
    ans.unit();
    A.f[0][1] = 2;A.f[0][2] = 1;A.f[0][0] = 1;
    A.f[1][2] = 1;A.f[1][1] = 1;
    A.f[2][2] = 2;A.f[2][0] = 1;A.f[2][1] = 2;
    B = A;B.f[2][0] = 0;B.f[2][1] = 0;B.f[2][2] = 1;
    int p = 0;
    for(int i = 1 ; i <= M ; ++i) {
	read(x[i]);
	ans = ans * fpow(A,x[i] - p);
	ans = ans * B;
	p = x[i] + 1;
    }
    ans = ans * fpow(A,N - p);
    out(ans.f[0][2]);enter;
    
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(ll i=(n);i<(x);++i)
#define rem(i,n,x) for(ll i=(n);i>=(x);--i)
#define SORT(x) sort(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define setp(x) setprecision(x)
using ll = long long;

int main() {
	int n; cin >> n;
	vector<vector<int>> t(n);
	vector<pair<int, int>> p;
	rep(i, 1, n) {
		int a, b; cin >> a >> b; a--; b--;
		t[a].pb(b);
		t[b].pb(a);
		p.pb(make_pair(a, b));
	}

	int num = 0; // 色の数
	map<pair<int, int>, int> cmp; // 辺の色
	vector<bool> used(n, 0); used[0] = 1; // 巡回済み
	
	vector<int> cbox(n, 0);
	queue<int> que; que.push(0);
	while (!que.empty()) {
		int tp = que.front(); que.pop();
		if (num < t[tp].size()) num = t[tp].size();
		int color = 1;
		for (int x : t[tp]) {
			if (used[x]) continue;
			if (color == cbox[tp]) color++;
			cbox[x] = cmp[make_pair(tp, x)] = cmp[make_pair(x, tp)] = color++;
			used[x] = 1;
			que.push(x);
		}
	}

	cout << num << endl;
	for (auto x : p) cout << cmp[x] << endl;

	return 0;
}

Measured memory_bytes: 19700
#include <cstdio>

int main() {
 	int a, b, c, d;
  	scanf(" %d %d %d %d", &a, &b, &c, &d);
  
  	int A = a + b;
  	int B = c + d;
  
  	if (A > B) {
     	printf("Left\n"); 
    } else if (A < B) {
      	printf("Right\n");
    } else {
      	printf("Balanced\n");
    }
  
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
#include <ctime>
#include <ostream>
using namespace std;
typedef long long ll;
#define pb push_back
#define scand(n) scanf("%d",&n)
#define scanlld(n) scanf("%lld",&n)
#define scans(str) scanf("%s",str)

int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL
    ll a,b,c,d;
    scanlld(a);
    scanlld(b);
    scanlld(c);
    scanlld(d);
    printf("%lld",max(a*b,c*d));
    return 0;
}


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

int main(){
	int n, m, k;
	cin >> n >> m;
	
	vector<int> v;
	for(int i=1 ; i <= 2*n ; i++ ){
		v.push_back( i );
	}
	for(int i=0 ; i < m ; i++ ){
		vector<int> t(2*n);
		cin >> k;
		
		if( k > 0 ){
			for(int j=0 ; j < k ; j++ ){
				t[2*n-k+j] = v[j];
			}
			for(int j=k ; j < 2*n ; j++ ){
				t[j-k] = v[j];
			}
		}else{
			for(int j=0 ; j < 2*n ; j += 2 ){
				t[j] = v[j/2];
				t[j+1] = v[n+j/2];
			}
		}
		v = t;
	}
	for(int i=0 ; i < v.size() ; i++ ){
		cout << v[i] << endl;
	}
}

Measured memory_bytes: 0
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int x = sc.nextInt();
        int y = sc.nextInt();
        boolean dirx = true;
        int[] a = new int[8000];
        int[] b = new int[8000];
        int aindex=0;
        int bindex=0;
        int sum=0;
        for(int i=0;i<s.length();i++){
            if(s.charAt(i)=='F') {
                sum++;
            } else {
                if(dirx) {
                    a[aindex] = 2*sum;
                    aindex++;
                    x+=sum;
                    sum=0;
                    dirx = false;
                } else {
                    b[bindex] = 2*sum;
                    bindex++;
                    y+=sum;
                    sum=0;
                    dirx = true;
                }
                sum = 0;
            }
        }
        //last remainder
        if(sum>0){
            if(dirx){
                a[aindex] = 2*sum;
                aindex++;
                x+=sum;
            } else {
                b[bindex] = 2*sum;
                bindex++;
                y+=sum;
            }
        }
        boolean xans;
        boolean yans;
        x -= a[0];
        if (aindex==1){
            xans = x==0;
        } else {
            if(x<0){
                xans = false;
            } else {
                boolean[][] xdp = partialSumDP(a, aindex, x,1);
                xans = xdp[aindex-1][x];
            }
        }
        if(y<0){
            yans = false;
        } else {
            boolean[][] ydp = partialSumDP(b, bindex, y,0);
            yans = ydp[bindex][y];
        }

        if(xans & yans) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
    public static boolean[][] partialSumDP(int[] series,int length, int maxsum, int startindex){
        boolean dp[][] = new boolean[length+1-startindex][maxsum+1];
        dp[0][0] = true;
        for(int i=1;i<length+1-startindex;i++){
            for(int s=0;s<maxsum+1;s++){
                if(s-series[i-1+startindex]>=0) {
                    dp[i][s] = dp[i-1][s] | dp[i-1][s-series[i-1+startindex]];
                } else {
                    dp[i][s] = dp[i-1][s];
                }
            }
        }
        return(dp);
    }
}

Measured memory_bytes: 53588