akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {

	//float A, B, H, M,kaku;
	string T;
	cin >> T;
	
	//reverse(T.begin(), T.end());
	for (int i = 0; i < T.size(); i++) {
		char ch = T[i];

		if (T[i] == 'P' && T[i + 1] == '?') {
			T[i+1] = 'D';
		}
		else if (T[i] == 'D' && T[i + 1] == '?' && T[i + 2] == '?') {
			T[i+1] = 'P';
		}

		else if (T[i] == 'D' && T[i + 1] == '?'&& T[i+2]=='D') {
			T[i + 1] = 'P';
		}
		//else if (T[i] == '?' && T[i + 1] == '?') {
		//	T[i] = 'D';
		//}
		else if (T[i] == '?') {
			T[i] = 'D';
		}

	}
	//reverse(T.begin(), T.end());
	cout << T << endl;


}


Measured memory_bytes: 3764
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include<iomanip>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n)cin>>a[i];
  int cnt=1<<30;
  sort(all(a));
  vector<pair<int,int>>as;
  int t=a[0],cn=0;
  rep(i,n)
  {
    if(t==a[i])
    {
      cn++;
    }
    else
    {
      as.push_back({t,cn});
      cn=1;
      t=a[i];
    }
  }
  as.push_back({t,cn});
  int res=0;
  int l=as.size();
  for(int i=l-1;i>=0;i--)
  {
    if(as[i].second==0)continue;
    while(cnt>2*as[i].first)cnt/=2;
    pair<int,int> tp={cnt-as[i].first,1};
    int  f=lower_bound(all(as),tp)-as.begin();
    if(as[f].first==cnt-as[i].first)
    {
      if(i==f)
      {
        res+=as[f].second/2;
        as[f].second=as[f].second&1;
      }
      else
      {
        int tmp=min(as[i].second,as[f].second);
        res+=tmp;
        as[i].second-=tmp;
        as[f].second-=tmp;
      }
    }
  }
  cout<<res<<endl;
}


Measured memory_bytes: 3188
using System;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var x = new int[N];
            var y = new int[N];
            var h = new int[N];

            for (int i = 0; i < N; i++)
            {
                var str = Console.ReadLine();
                var strs = str.Split(' ');
                x[i] = int.Parse(strs[0]);
                y[i] = int.Parse(strs[1]);
                h[i] = int.Parse(strs[2]);
            }

            var MAX = 100;

            for (int posY = 0; posY <= MAX; posY++)
            {
                for (int posX = 0; posX <= MAX; posX++)
                {
                    int needH = -1;

                    for (int i = 0; i < N; i++)
                    {
                        if (h[i] > 0)
                        {
                            int tmp = h[i] + Math.Abs(posY - y[i]) + Math.Abs(posX - x[i]);
                            if (needH == -1)
                            {
                                needH = tmp;
                            }
                            else
                            {
                                if (needH != tmp)
                                {
                                    needH = -2;
                                    break;
                                }
                            }
                        }
                    }

                    if (needH == -2) continue;

                    for (int i = 0; i < N; i++)
                    {
                        if (h[i] == 0)
                        {
                            var dist = Math.Abs(posY - y[i]) + Math.Abs(posX - x[i]);
                            if (needH > dist)
                            {
                                needH = -2;
                                break;
                            }
                        }
                    }

                    if (needH == -2) continue;

                    Console.WriteLine(posX + " " + posY + " " + needH);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 13140
d,n = input().split()
d=int(d)
n=int(n)
if d==0:
    x=1
    a=[]
    for i in range(101):
        if not x==100:
            a.append(x)
        x+=1
    print(a[n-1])

if d==1:
    y=100
    b=[]
    for j in range(101):
        if not y==10000:
            b.append(y)
        y+=100
    print(b[n-1])

if d==2:
    c=[]
    z=10000
    for k in range(101):
        if not z==1000000:
            c.append(z)
        z+=10000
    print(c[n-1])




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

typedef long long ll;
typedef int64_t i6;
typedef std::vector<std::vector<int64_t> > Graph;

#define rep(i, n) for (int64_t i = 0; i < n; ++i)
#define rep2(i, n) for (int64_t i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))
#define Push_back(p, a, b) (p).push_back( make_pair( (a), (b) ) )

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;  } return 0;  }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;  } return 0;  }
template<typename V,typename T> bool find_num(V v, T num) { if ( find(ALL(v), num) == v.end() ) { return false; } return true; }

// π M_PI
// deg = rad*180/M_PI

int64_t func (int64_t x, int64_t y, int64_t z) {
    return x*x+y*y+z*z+x*y+y*z+z*x;
}

int main() {
    int64_t n;
    cin >> n;
    int64_t x = 1;
    std::vector<int64_t> v;
    while (1) {
        int64_t y = 1;
        while (1) {
            int64_t z = 1;
            while (1) {
                int64_t num = func(x, y, z);
                if (num > 10000) break;
                v.push_back(num);
                z++;
            }
            if (z == 1) break;
            y++;
        }
        if (y == 1) break;
        x++;
    }

    Sort(v);

    int64_t pin = 0;
    rep2(i, n) {
        if ( !find_num(v, i) ) {
            cout << 0 << endl;
        } else {
            int64_t ans = 0;
            int64_t boo = 0;
            for (int64_t j = pin; j <= v.size(); ++j) {
                if (boo == 1) {
                    if ( v[j] == i ) {
                        ans++;
                        pin = j;
                    } else {
                        break;
                    }
                }

                if (v[j] == i) boo = 1;
            }
            cout << ans+1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 7092
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

class Solution {
public:
    int solve(vector<string>& S, int K) {
        int n = S.size();
        int m = S[0].length();

        int res = n * m;

        vector<vector<int>> cnts(n, vector<int>(m, 0));
        vector<int> H(n, 0);
        for (int i = 0; i < (1 << (n - 1)); ++i) {
            int h = 1;
            for (int k = 0; k < n; ++k) {
                if (i & (1 << k)) {
                    ++h;
                }
            }
            for (int j = 0; j < m; ++j) {
                for (int k = 0, r = 0, sum = 0; k < n; ++k) {
                    sum += S[k][j] == '1';
                    if (k == n - 1 || (i & (1 << k))) {
                        cnts[r++][j] = sum;
                        sum = 0;
                    }
                }
            }

            fill(H.begin(), H.end(), 0);

            int ans = h - 1;
            for (int j = 0; j < m; ++j) {
                bool ok = true; 
                for (int k = 0; k < h; ++k) {
                    H[k] += cnts[k][j];
                    if (H[k] > K) {
                        ok = false;
                        break;
                    }
                }
                if (!ok) {
                    ++ans;
                    for (int k = 0; k < h; ++k) {
                        H[k] = cnts[k][j];
                        if (H[k] > K) {
                            ans = 1 << 24;
                        }
                    }
                }
            }
            res = min(res, ans);
        }

        return res;
    }
};

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    Solution sol;
    int n, m, k;
    cin >> n >> m >> k;
    vector<string> S(n);
    for (int i = 0; i < n; ++i) {
        cin >> S[i];
    }

    cout << sol.solve(S, k) << "\n";

    return 0;
}

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

using namespace std;

void solve()
{
    int n;
    cin >> n;

    vector<long double> v(n, 0);
    for(int i = 0; i < n; ++i)
        cin >> v[i];

    int base = n;
    vector<vector<long double> > dp(n, vector<long double>(2 * base + 1));
    dp[0][base + 1] = v[0];
    dp[0][base - 1] = 1.0 - v[0];

    for(int i = 1; i < n; ++i)
    {
        for(int j = -i; j <= i; ++j)
        {
            dp[i][j + 1 + base] += dp[i - 1][j + base] * v[i];
            dp[i][j - 1 + base] += dp[i - 1][j + base] * (1.0 - v[i]);
        }
    }

    long double answer = 0;
    for(int i = 1; i <= n; ++i)
        answer += dp[n - 1][i + base];

    cout.precision(10);
    cout << fixed << answer << '\n';
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //srand (time(0));

    solve();
}






Measured memory_bytes: 281600
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x[3][3],a;
	cin>>x[0][0]>>x[0][1]>>x[1][1];
	a=x[1][1]*3;
	x[0][2]=a-x[0][1]-x[0][0];
	x[2][1]=a-x[0][1]-x[1][1];
	x[2][0]=a-x[0][2]-x[1][1];
	x[1][0]=a-x[0][0]-x[2][0];
	x[1][2]=a-x[1][0]-x[1][1];
	x[2][2]=a-x[2][0]-x[2][1];
	cout<<x[0][0]<<" "<<x[0][1]<<" "<<x[0][2]<<endl<<x[1][0]<<" "<<x[1][1]<<" "<<x[1][2]<<endl<<x[2][0]<<" "<<x[2][1]<<" "<<x[2][2]<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def keta(x):
    res = 0
    for s in str(x):
        res += int(s)
    return res


def main():
    N, A, B = map(int, input().split())
    ans = 0
    for i in range(1, N + 1):
        tmp = keta(i)
        if A <= tmp <= B:
            ans += i

    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second
#define rf(i,a,b) for(int (i) = (a); (i) <= (b); (i)++)
#define rb(i,b,a) for(int (i) = (b); (i) >= (a); (i)--)
#define watch(x) cout << (#x) << " = " << (x) << endl
#define test(t) int(testCnt) = 0; int(t); cin >> (t); while(t -- && ++testCnt)

const int INF = 2e9 + 7;
const int MAXA = 1e5 + 10;
const ll MOD = (ll) 1e9 + 7;
const ll INFLL = 9e18 + 7;

typedef pair<int, int> ii;
typedef pair<ii, int> II;
typedef vector<int> vi;
typedef vector<ii> vii;

int n, W, w[MAXA];
ll ans, f[110][MAXA], v[MAXA];

ll solve(int i, int j) {
    if(f[i][j] != -1) return f[i][j];
    if(i == n + 1 || j == 0) return 0;
    if(w[i] > j) return f[i][j] = solve(i + 1, j);
    return f[i][j] = max(solve(i + 1, j), v[i] + solve(i + 1, j - w[i]));
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
      // freopen("in.in", "r", stdin);
    #endif
    cin >> n >> W;
    rf(i, 1, n) cin >> w[i] >> v[i];
    memset(f, -1, sizeof(f));
    solve(0, W);
    cout << f[0][W];
    return 0;
}


Measured memory_bytes: 86272
(* --------------Encoder-------------- *)
(* -----function----- *)
let encoder = float_of_string (read_line ())

(* -------test------- *)
(*let test1 = (encoder = 0.0)*)
(* ----------------------------------- *)

(* --------------Decoder-------------- *)
(* -----function----- *)
let decoder ans = string_of_float ans

(* -------test------- *)
(* ----------------------------------- *)

(* --------------Processor-------------- *)
(* -----function----- *)
(* purpose
 *      与えられた半径から周長を求める
*)

(* function type
        processor : float -> float
*)
let rec processor r = 2.0 *. Float.pi *. r
(* -------test------- *)
let test1 = (processor 0.0 = 0.0)
let test2 = (processor 1.0 = 6.28318530717958623200)
(* ----------------------------------- *)


(* ----------------main---------------- *)
(*let () = print_endline (decoder (processor encoder))*)
let main () =
        Printf.fprintf stdout "%.20f\n" (processor encoder)
let _ = main ()
(* ------------------------------------ *)


Measured memory_bytes: 3836
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Security.Principal;
using System.Text;
class Simple{
    private int N;
    private long[] a, b;
    void Solve(){
        //input
        N = io.Int;
        a = new long[N];
        b = new long[N];
        for(int i = 0; i < N; ++i){
            a[i] = io.Int;
            b[i] = io.Int;
        }
        //cal
        var cnt = 0L;
        for(int i = N - 1; i >= 0; --i) if((a[i] + cnt) % b[i] != 0) cnt += b[i] * ((a[i] + cnt) / b[i] + 1) - (a[i] + cnt);
        //ret
        Console.WriteLine(cnt);
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream(){
        Solve();
        io.writeFlush();
    }
}
class SimpleIO{
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[]{' '};
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
    public SimpleIO(){
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next(){
        if(BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while(st == "") st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}


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

int main(){
    string s;
    cin >> s;
    map<char, int> mp;
    rep(i, s.length()) {
        ++mp[s[i]];
    }
    if ( mp['N'] >= 1 && mp['S'] >= 1 && mp['E'] >= 1 && mp['W'] >= 1 ) {
        cout << "Yes" << endl;
    }
    else if ( mp['N'] >= 1 && mp['S'] >= 1 && mp['E'] == 0 && mp['W'] == 0 ) {
        cout << "Yes" << endl;
    }
    else if ( mp['N'] == 0 && mp['S'] == 0 && mp['E'] >= 1 && mp['W'] >= 1 ) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Queue;
import java.util.Scanner;

// queue
public class Main {

	
	static class Process{
		String name;
		int time;
		public Process(String name, int time) {
			this.name = name;
			this.time = time;
		}
		public String toString(){
			return name + " " + time;
		}
	}
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int T = scan.nextInt();
		int totalTime = 0;
	
		Queue<Process> queue = new ArrayDeque<Process>();
		ArrayList<Process> output = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			String name = scan.next();
			int time = scan.nextInt();
			Process process = new Process(name, time);
			queue.offer(process);
		}
		while(true){
            Process process = queue.poll();
            if (process == null) break;
            if (T < process.time) {
				totalTime += T;
				process.time -= T;
				queue.offer(process);
			}else{
				totalTime += process.time;
				output.add(new Process(process.name, totalTime));
			}
        }
		
		for (int i = 0; i < output.size(); i++) {
			System.out.println(output.get(i));
		}
		
		scan.close();
	}

}

Measured memory_bytes: 70260
(N, K), As, Fs = readlines.map{|l| l.split.map(&:to_i)}

afps = As.sort.zip(Fs.sort.reverse).map{|a, f| [a, f, a*f]}
puts (0 .. 10**12).bsearch {|x| afps.select{|_, _, p| p > x}.inject(0){|s, (a, f, _)| s + a - x/f} <= K}

Measured memory_bytes: 85304
#include<cstdio>
using namespace std;
using ll = long long;
const static int MOD = 1000000007;

int main(){
	ll X, Y;
	scanf("%lld %lld", &X, &Y);
	if(X - Y >= -1 && Y - X >= -1) printf("Brown\n");
	else printf("Alice\n");
	return 0;
}

Measured memory_bytes: 128
import copy

n = int(input().split()[0])
a_list = []

for _ in range(n):
    a_list.append(int(input().split()[0]))

kouho_list = sorted(a_list)
max_n = max(kouho_list)
second_max_n = kouho_list[-2]

max_list = [str(max_n) if x != max_n else str(second_max_n) for x in a_list]
max_str = '\n'.join(max_list)

print(max_str)


Measured memory_bytes: 30496
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long  n, a, b, c, d, e, x,count=0;
    cin >> n >> a >> b >> c >> d >> e;
    x=min(a,min(b,min(c,min(d,e))));
    count=(n+(x-1))/x+4LL;
    cout << count;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var N = NextInt();
            var a = LongList();
            var r = new long[N + 2];
            var l = new long[N + 2];

            for (int i = 1; i <= N; i++) {
                l[i] = Gcd(a[i - 1], l[i - 1]);
                r[N + 1 - i] = Gcd(a[N - i], r[N + 2 - i]);
            }

            Console.WriteLine(
                Enumerable.Range(1, N).Max(x => Gcd(l[x - 1], r[x + 1]))
            );
        }
    }

    class MyMath {
        public const long mod = 1000000007;

        public static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }

        public static List<long> Factor(long n) {
            var list = new List<long>();
            n = DivideToLimit(n, 2, list);
            n = DivideToLimit(n, 3, list);
            long sqrt = Sqrt(n);
            for (int i = 5; i <= n && i <= sqrt; i += 4) {
                n = DivideToLimit(n, i, list);
                i += 2;
                n = DivideToLimit(n, i, list);
            }
            if (n > 1) list.Add(n);
            return list;
        }

        public static long Sqrt(long n) {
            if (n < 0) return 0;
            long a = 0, tmp = 0, b = 0;
            for (int i = 62; i >= 0; i -= 2) {
                tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0;
                a = a << 1 | tmp;
                n -= (((b << 1) + 1) * tmp) << i;
                b = (b << 1) + tmp + tmp;
            }
            return a;
        }

        static long DivideToLimit(long divisor, long dividend, List<long> list) {
            while (divisor % dividend == 0) {
                list.Add(dividend);
                divisor /= dividend;
            }
            return divisor;
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }
    }
}

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

using namespace std;

const int MAXN = 6+2;

int N,K;
void solve(){
	string s;
	cin>>s;
	int gCnt=0, pCnt = 0;
	for (char ch:s){
		if (ch=='g'){
			gCnt++;
		}
		else{
			pCnt++;
		}
	}
	cout<< (gCnt-pCnt)/2 << '\n';
}

int main(){
//	freopen("in.txt","r",stdin);
	std::ios::sync_with_stdio(false);

//	int TestCase;
//	cin>>TestCase;
//	for (int i=0;i<TestCase;i++){
		solve();
//	}

	return 0;
}



Measured memory_bytes: 512
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
ll factorialNumInverse[N + 1]; 
  
// array to precompute inverse of 1! to N! 
ll naturalNumInverse[N + 1]; 
  
// array to store factorial of first N numbers 
ll fact[N + 1]; 
  
// Function to precompute inverse of numbers 
void InverseofNumber(ll p) 
{ 
    naturalNumInverse[0] = naturalNumInverse[1] = 1; 
    for (int i = 2; i <= N; i++) 
        naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p; 
} 
// Function to precompute inverse of factorials 
void InverseofFactorial(ll p) 
{ 
    factorialNumInverse[0] = factorialNumInverse[1] = 1; 
  
    // precompute inverse of natural numbers 
    for (int i = 2; i <= N; i++) 
        factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; 
} 
  
// Function to calculate factorial of 1 to N 
void factorial(ll p) 
{ 
    fact[0] = 1; 
  
    // precompute factorials 
    for (int i = 1; i <= N; i++) { 
        fact[i] = (fact[i - 1] * i) % p; 
    } 
} 
  
// Function to return nCr % p in O(1) time 
ll Binomial(ll N, ll R, ll p) 
{ 
    // n C r = n!*inverse(r!)*inverse((n-r)!) 
    ll ans = ((fact[N] * factorialNumInverse[R]) 
              % p * factorialNumInverse[N - R]) 
             % p; 
    return ans; 
} 
void solve()
{
    ll n,k;
    cin>>n>>k;
    vl v;
    v.pb((ll)-mod);
    rep(i,n)
    {
        ll c;
        cin>>c;
        v.pb(c);
    }
    sort(all(v));
    ll ans=0;
    for(int i=1;i<=n-k+1;i++)
    {
        ll temp=Binomial(n-i,k-1,mod);
        temp*=(v[i]);
        temp%=mod;
        temp+=mod;
        temp%=mod;
        ans-=temp;
        ans+=mod;
        ans%=mod;
    }
    for(int i=k;i<=n;i++)
    {
        ll temp=Binomial(i-1,k-1,mod);
        temp*=(v[i]);
        temp%=mod;
        temp+=mod;
        temp%=mod;
        ans+=temp;
        ans+=mod;
        ans%=mod;
    }
    cout<<ans<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    ll p = 1000000007; 
    InverseofNumber(p); 
    InverseofFactorial(p); 
    factorial(p); 
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 24824
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-8;

long long int N, M, K, L, R, H, W;
//int N, M, K, L, R, H, W;


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

	cin >> N;
	vector<long long int>p(N);
	vector<long long int>s(N);
	for (int i = 0; i < N; i++) {
		cin >> p[i] >> s[i];
	}
	long long int ans = s.back();
	long long int box = s.back() - p.back();
	for (int i = N - 2; i >= 0; i--) {
		box = max(box + s[i], s[i]-p[i]);
		ans = max(ans, box + p[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3456
N = gets.to_i
A = gets.chomp.split.map(&:to_i)

step_sum = 0
height = A[0]
1.upto(N-1) do |i|
  if A[i] < height
    step_sum += height - A[i]
  else
    height = A[i]
  end
end

print step_sum

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

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

	vector<int> h(n);
	int max_height = 0;
	int count = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> h.at(i);
		if (max_height <= h.at(i))
		{
			count++;
		}
		max_height = max(max_height, h.at(i));
	}

	cout << count << endl;
}


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n-1;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long

typedef pair<ll, ll> LP;

const int nmax = 8;
bool graph[nmax][nmax];


ll dfs(ll v, ll n, bool* visited){
	bool all_visited = true;
	REP(i, n){
		if (!visited[i]){ all_visited = false; break; }
	}
	if (all_visited){ return 1; }
	int ret = 0;
	REP(i, n){
		if (graph[v][i]==false){ continue; }
		if (visited[i]){ continue; }
		visited[i] = true;
		ret += dfs(i, n, visited);
		visited[i] = false;
	}
	return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, m;
	cin >> n >> m;
	REP(i, m){
		int a, b;
		cin >> a >> b;
		graph[a-1][b-1] = graph[b-1][a-1] = true;
	}
	bool visited[n];
	REP(i, n){ visited[i] = false; }
	visited[0] = true;
	cout << dfs(0, n, visited) << endl;
	return 0;

}

Measured memory_bytes: 256
import sys
import math

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    def meguru_bisect(ok, ng):
        """
        is_okを定義して下さい
        :param ok: 取りうる最小の値-1
        :param ng: 取りうる最大の値+1
        :return: is_okを満たす最小(もしくは最大)の値
        """
        while abs(ok - ng) > 1:
            mid = (ok + ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok

    def is_ok(x):
        cnt = 0
        for i in range(n):
            if A[i] > x:
                cnt += (A[i] + x - 1) // x - 1

        return cnt <= k

    n, k = map(int, input().split())
    A = list(map(int, input().split()))

    res = meguru_bisect(10 ** 9 + 1, 0)
    print(math.ceil(res))


if __name__ == '__main__':
    resolve()

Measured memory_bytes: 30916
#include <bits/stdc++.h>
using namespace std;
 
int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}
 
int main(){
    int M, K;
    cin >> M >> K;
    if(M == 1){
        if(K == 0){
            cout << "0 0 1 1" << endl;
        }else{
            cout << -1 << endl;
        }
        return 0;
    }
    int MX = 1<<M;
    if(K >= MX){
        cout << -1 << endl;
        return 0;
    }
    vector<int> ans;
    for(int i=0; i<MX; i++) if(i != K) ans.push_back(i);
    ans.push_back(K);
    for(int i=MX-1; i>=0; i--) if(i != K) ans.push_back(i);
    ans.push_back(K);
    for(int i=0; i<2*MX; i++) cout << ans[i] << " \n"[i==2*MX-1];
    return 0;
}

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

int main() {
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());

    int N, M;
    cin >> N >> M;
    string A[N], B[M];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < M; i++) {
        cin >> B[i];
    }

    // テンプレート画像の左上の点を動かす
    for (int y0 = 0; y0 < N-M+1; y0++) {
        for (int x0 = 0; x0 < N-M+1; x0++) {
            // チェック
            bool isOK = true;
            for (int y = 0; y < M; y++) {
                for (int x = 0; x < M; x++) {
                    if (B[y][x] != A[y+y0][x+x0]) {
                        isOK = false;
                    }
                }
            }
            if(isOK) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define ff first
#define ss second
#define pb push_back
#define mod 1000000007
#define pl pair<lli,lli>
#define vl vector<lli>
#define vvl vector<vl>
#define INF (lli)1e18

vvl cost;
vl a;

lli solve(lli i,lli j)
{
	if(i>=j)
		return 0;
	if(cost[i][j]!=-1)
		return cost[i][j];
	lli k,ans=INF;
	for(k=i;k<j;k++)
		ans=min(ans,solve(i,k)+solve(k+1,j)+a[j]-a[i-1]);
	return cost[i][j]=ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli n,i,ans;
    cin>>n;
    a.resize(n+1);
    cost.resize(n+1,vl(n+1,-1));
    for(i=1;i<=n;i++)
    {
    	cin>>a[i];
    	a[i]+=a[i-1];
    }
    ans=solve(1,n);
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>
#include <string>
using namespace std;


int main() {
  string S;
  cin >> S;
  
  int sfront = stoi(S.substr(0,2));
  int send = stoi(S.substr(2));
  
  string ans = "";
  if ( 1 <= sfront && sfront <= 12) {
   	if ( 1 <= send && send <= 12 ) {
      ans = "AMBIGUOUS";
    } else {
      ans = "MMYY";
    }
  } else {
   	if ( 1 <= send && send <= 12 ) {
      ans = "YYMM";
    } else {
      ans = "NA";
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }



int MAX = 8;

int main() {
	vector< vcs > b(7);
	b[0].pb("11"); b[0].pb("11");
	b[1].pb("1"); b[1].pb("1"); b[1].pb("1"); b[1].pb("1");
	b[2].pb("1111");
	b[3].pb("01"); b[3].pb("11"); b[3].pb("10");
	b[4].pb("110"); b[4].pb("011");
	b[5].pb("10"); b[5].pb("11"); b[5].pb("01");
	b[6].pb("011"); b[6].pb("110");
	
	vcs m(MAX);
	string tes;
	
	while (cin >> tes) {
		if (tes=="") continue;
		
		m[0] = tes;
		for_(i, 1, MAX) cin >> m[i];
	
		for_(k, 0, 7) {
			vcs bl = b[k];
			int Y = (int)bl[0].sz, X = (int)bl.sz;
		
			bool flag = false;
			for_(i, 0, MAX-X+1) for_(j, 0, MAX-Y+1){
				bool f = true;
				for_(x, 0, X) for_(y, 0, Y) {
					if (m[i+x][j+y] != bl[x][y]) f = false;				
				}
				if (f) flag = true;
			}
		
			if (flag) {
				char ans = 'A' + k;
				cout << ans << endl;
				break;
			}
		}
	}
	
	return 0;
}

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

using namespace std;

int main(int argc, char *argv[])
{
  string S;
  int out = 0;
  cin >> S;
  for (int i=0; i<6; ++i) {
    if (S[i] == '1')
      out++;
  }
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;


const int INF = 10000000;
const long long INFL = (1LL<<40);
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

template< typename T >
struct edge{
    int src, to;T cost;
    edge(int to,T cost) :src(-1),to(to),cost(cost){}
    edge(int src, int to, T cost) :src(src),to(to),cost(cost){}edge
    &operator=(const int &x){
        to =x;
        return *this;
    }
    operator int() const{ return to;}
};



int main() {
    int a, b, k;cin>>a>>b>>k;
    set<int> out;
    for(auto i = 0; i<k; i++){
        if(a+i<=b){
            out.insert(a+i);
        }
        if(b-i>=a){
            out.insert(b-i);
        }
    }
    for(auto j:out)cout<<j<<endl;
    return 0;
}







Measured memory_bytes: 256
import math  # noqa
import bisect  # noqa
import queue  # noqa


if __name__ == '__main__':
    N, M = map(int, input().split())
    PY = []
    for i in range(M):
        P, Y = map(int, input().split())
        PY.append([Y, P, i + 1])
    PY.sort()

    # cnt: key=県, value=すでに幾つの市がその県に属しているか
    # res: [市の番号, 県の番号, 順番]
    cnt = {}
    res = []
    for y, p, i in PY:
        if p not in cnt:
            cnt[p] = 1
        else:
            cnt[p] += 1
        res.append([i, p, cnt[p]])

    res.sort()
    for i, p, x in res:
        print('{:06}{:06}'.format(p, x))


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

ll chk(ll x, ll b) {
  ll sum = 0;
  while (x) {
    sum += x % b;
    x /= b;
  }
  return sum;
}

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

  ll n, s;
  cin >> n >> s;
  ll ans = (n == s ? n + 1 : -1);
  for (ll b = 2; b * b <= n; ++b)
    if (chk(n, b) == s) ans = (ans == -1 ? b : min(ans, b));

  for (ll b = 1; b * b <= n; ++b) {
    auto bb = (n - s) / b + 1;
    if (bb >= 2 && chk(n, bb) == s) ans = (ans == -1 ? bb : min(ans, bb));
  }
  cout << ans;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000)

s = 'HAKUTYUMU' + input()


while s != 'HAKUTYUMU':
    next_s = s

    if s[-5:] == 'dream':
        next_s = s[:-5]
    if s[-7:] == 'dreamer':
        next_s = s[:-7]
    if s[-5:] == 'erase':
        next_s = s[:-5]
    if s[-6:] == 'eraser':
        next_s = s[:-6]

    if s == next_s:
        print('NO')
        exit()

    s = next_s

print('YES')


Measured memory_bytes: 9220
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

LL a[100];

int main(){
	int n;
	scanf("%d",&n);
	a[0] = 2;
	a[1] = 1;
	for(int i = 2;i <= n;i++){
		a[i] = a[i - 1] + a[i - 2];
	}
	printf("%lld",a[n]);
}

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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N, M, A, B, C;
    vector< vector<int> > G;
    void input() {
        cin >> N >> M >> A >> B >> C;
        G.resize(N);
        for (int i = 0; i < M; i++) {
            int u, v; cin >> u >> v; u--; v--;
            G[u].push_back(v);
        }
    }

    void solve() {
        vector<bool> fin(N, false);
        fin[N - 1] = true;
        for (int t = 1; t <= N; t++) {
            vector<bool> pfin = fin;
            for (int k = 0; k < N; k++) {
                bool used[N][101];
                memset(used, 0, sizeof(used));
                queue< pair<int, int> > Q;
                Q.push(make_pair(k, 0));
                used[k][0] = true;
                while (!Q.empty()) {
                    auto c = Q.front(); Q.pop();
                    int v = c.first, d = c.second;
                    if (d >= 100) continue;
                    for (int i = 0; i < G[v].size(); i++) {
                        int u = G[v][i];
                        if (!used[u][d + 1]) {
                            Q.push(make_pair(u, d + 1));
                            used[u][d + 1] = true;
                        }
                    }
                }
                int flag = 0;
                for (int i = 0; i < N; i++) {
                    if (pfin[i] && used[i][A]) flag |= 1;
                    if (pfin[i] && used[i][B]) flag |= 2;
                    if (pfin[i] && used[i][C]) flag |= 4;
                }
                if (flag == 7) fin[k] = true;
            }
            pfin = fin;
            if (fin[0]) {
                cout << t << endl;
                return;
            }
        }
        cout << "IMPOSSIBLE" << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

Measured memory_bytes: 3180
#include <iostream>
#include <map>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;

typedef pair<int,int> P;

int h;
char t[1002][100];
P c[4];

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

void solve(int x,int y,int d,int cidx){
	t[y][x] = ' ';

	int nd = -1;
	int nx,ny;
	for(int i=d;i!=(d+7)%8;i=(i+1)%8){
		nx = x + dx[i];
		ny = y + dy[i];
		if(nx>=0 && nx<100 && ny>=0 && ny<h && t[ny][nx]=='*'){
			nd = i;
			break;
		}
	}

	if(nd == -1) return;

	if(d != nd){
		c[cidx] = P(x,y);
		solve(nx,ny,nd,cidx+1);
	}
	else{
		solve(nx,ny,nd,cidx);
	}
}

int main(void){
	bool firstFlg = true;

	while(cin>>h,h){
		memset(t,' ',sizeof(t));
		if(firstFlg) firstFlg = false;
		else cout<<"----------\n";

		getchar();
		for(int i=0;i<h;i++){
			fgets(t[i],100,stdin);
		}

		map<int,int> ans;

		for(int i=0;i<h;i++){
			int len = strlen(t[i]);
			for(int j=0;j<len;j++){
				if(t[i][j] == '*'){
					c[0] = P(j,i);
					solve(j,i,2,1);

					int area =
						((c[1].first - c[0].first + 1) + (c[2].first - c[3].first + 1)) *
						(c[2].second - c[1].second + 1) / 2;
					ans[area]++;
				}
			}
		}

		for(map<int,int>::iterator i=ans.begin();i!=ans.end();i++){
			cout<<i->first<<" "<<i->second<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 0
def run_length(data, init=''):
    length = []
    tmp = init
    cnt = 0
    for c in data:
        if tmp != c:
            length.append(cnt)
            cnt = 0
        tmp = c
        cnt += 1
    length.append(cnt)
    return length


def resolve():
    n = int(input())
    s = input()
    length = run_length(s, '')
    print(len(length) - 1)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9664
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
  string s;
  int k;
  ll cnt1=0,cnt2=0;
  cin >> s >> k;
  if(s == string(s.size(),s[0])) {
	cout << s.size() * k / 2 << endl;
    return 0;
  }
  string t = s+s;
  rep(i,s.size()-1) if(s[i] == s[i+1]) s[i+1] = '#',cnt1++;
  rep(i,t.size()-1) if(t[i] == t[i+1]) t[i+1] = '#',cnt2++;
  cout << cnt1 + (cnt2-cnt1)*(k-1) << endl;
  return 0;
}
  


Measured memory_bytes: 256
fun main(args: Array<String>) {
    var n= readLine()
    var c= n!!.toInt()
    var array= mutableListOf<MutableList<Int>>()
    for(i in Array(c-1,{it})){
        var r= readLine()
        var array2=r!!.split(" ")
        var array3= mutableListOf<Int>()
        for(j in arrayOf(0,1,2)){
            array3.add(array2[j].toInt())
        }
        array.add(array3)
    }
    for(j in Array(c-1,{it})) {
        var a=Array(c-j-1,{it+j})
        var t = 0
        for (i in a) {
            t = time(t, array[i][0], array[i][1], array[i][2])
        }
        println(t)
    }
    println(0)
}

fun time(i:Int,c:Int,s:Int,f:Int):Int{
    var k=s
    while(k<i){
        k+=f
    }
    var t=k+c
    return t
}

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

int main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    int x[110], y[110];
    int i;
    for(i=0; i<N; ++i) cin >> x[i];
    for(i=0; i<M; ++i) cin >> y[i];
    int maxx=0, miny=0;
    for(i=1; i<N; ++i) if(x[i]>x[maxx]) maxx=i;
    for(i=1; i<M; ++i) if(y[i]<y[miny]) miny=i;
    if(x[maxx]<Y && y[miny]>X && x[maxx]<y[miny]) cout << "No War" << endl;
    else cout << "War" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define ll long long int
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define F first
#define S second
#define mset(x,v) memset(x, v, sizeof(x))
#define left(x) 2*x
#define right(x) (2*x) + 1
#define ALL(t) (t).begin(),(t).end() 
#define ret return 0
#define all(x) x.begin(),x.end()
int main()
{
    boost;
            ll n,ans=0;
            cin>>n;
            if(n%2==0)
            cout<<n<<endl;
            else
            cout<<(2*n)<<endl;
}
      

Measured memory_bytes: 256
#include <stdio.h>

 int main(){
 int a,b;scanf("%d%d",&a,&b);
 if(a<b){
 for(int i=0;i<b;i++)printf("%d",a);
 }else{
 for(int i=0;i<a;i++)printf("%d",b);
 }
 printf("\n");
 }

Measured memory_bytes: 128
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BC
import           Data.Maybe            (fromJust)
import qualified Data.Vector.Unboxed   as VU

main :: IO ()
main = do
  n <- readLn
  as <- getInts
  putStr . unlines . map show $ solve n as

solve :: Int -> [Int] -> [Int]
solve n as =  map skip [1 .. n] where
  va = VU.fromList  $ 0 : as ++ [0]
  d = sum $ zipWith cost [0 .. n + 1] [1 .. n + 1]
  skip i = d - cost (i - 1) i - cost i (i + 1) + cost (i - 1) (i + 1)
  cost i j = abs $ va VU.! i - va VU.! j

readInts :: BC.ByteString -> [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words

getInts :: IO [Int]
getInts = readInts <$> BC.getLine

getIntss :: IO [[Int]]
getIntss = map readInts . BC.lines <$> BC.getContents


Measured memory_bytes: 7420
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
using namespace std;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return w*s;}
char s1[1000100],s2[1000010];
ll n,m;
ll lcm;
unordered_map<ll,ll> mp;
int main()
{
	n=read(),m=read();
	lcm=n*m/__gcd(n,m);
	scanf("%s",s1+1);
	scanf("%s",s2+1);
	for(rint i=1;i<=n;++i)
	{
		ll tmp=(lcm/n)*(i-1)+1;
		mp[tmp]=i;
	}
	for(rint i=1;i<=m;++i)
	{
		ll tmp=(lcm/m)*(i-1)+1;
		if(mp.count(tmp))
		{
			if(s1[mp[tmp]]!=s2[i])
			{
				cout<<"-1";return 0;
			}
		}
	}cout<<lcm;
	return 0;
}




Measured memory_bytes: 4260
# python3
# -*- coding: utf-8 -*-
import sys
import math
#from math import gcd
from itertools import count, permutations
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint

INF = float('inf')

ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
sys.setrecursionlimit(1000000000)


def lcm(a, b):
    return (a * b) // gcd(a, b)


# main
n,m = mis()
alist = lmis()

alist.sort()
alist.reverse()

min = sum(alist) * float(1/(4*m))

for i in range(m):
    if alist[i] < min:
        print('No')
        exit(0)

print('Yes')


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int A;
    long long B,N;
    cin>>A>>B>>N;
    long long x=0;
    if(N>=B){
        x=B-1;
    }else{
        x=N;
    }
    double ans=floor((A*x)/B);
    cout<<(long long)ans << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    deque<int> d;
    for(int i=1; i<=n; i++){
        int a;
        cin >> a;
        if(i%2==1){
            d.push_back(a);
        }
        else d.push_front(a);
    }
    if(n%2==1){
        for(int i=0; i<n; i++){
            int a = d.back();
            cout << a << " ";
            d.pop_back();
        }
        cout << endl;
    }
    else{
        for(int i=0; i<n; i++){
            int a = d.front();
            cout << a << " ";
            d.pop_front();
        }
        cout << endl;
    }
}

Measured memory_bytes: 4460
<?php
$debug = false;
list($a, $b, $q) = ints();
for ($i = 0; $i < $a; ++$i) {
    list($s[]) = ints();
}
for ($i = 0; $i < $b; ++$i) {
    list($t[]) = ints();
}
sort($s);
sort($t);
for ($i = 0; $i < $q; ++$i) {
    list($x) = ints();

    // 右にある物のうち最も左の神社と左にある物のうち最も右にある神社の距離
    list($ls, $rs) = nibutan($a, $s, $x);
    // 右にある物のうち最も左の神社と左にある物のうち最も右にある神社の距離
    list($lt, $rt) = nibutan($b, $t, $x);

    $tmp = [];
    // 左にのみ進む
    $tmp[] = max($ls, $lt);
    // 右にのみ進む
    $tmp[] = max($rs, $rt);
    // 右の神社と左の寺
    $tmp[] = min($rs, $lt) * 2 + max($rs, $lt);
    // 左の神社と右の寺
    $tmp[] = min($ls, $rt) * 2 + max($ls, $rt);

    if ($debug) {
        var_dump($x, $ls, $rs, $lt, $rt);
    }

    $ans[] = min($tmp);
}
echo implode(PHP_EOL, $ans);
function nibutan($n, $arr, $x)
{
    $ok = $n;
    $ng = -1;
    while (abs($ok - $ng) > 1) {
        $mid = intdiv($ok + $ng, 2);
        if ($arr[$mid] > $x) $ok = $mid;
        else $ng = $mid;
    }
    $r = $ok !== $n ? abs($arr[$ok] - $x) : PHP_INT_MAX;
    $l = $ng !== -1 ? abs($arr[$ng] - $x) : PHP_INT_MAX;
    return [$l, $r];
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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


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

    set<char> ans;
    rep(i,s.size()) ans.insert(s[i]);

    if( ans.size() == 3 ) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256