akhauriyash/Code-Regression huggingface dataset:
using System;


namespace ConsoleApplication37
{
    class Program
    {
        static void Main(string[] args)
        {
            string n = Console.ReadLine();
            int o = int.Parse(n);
            //???????????????
            String[,] t = new string[4 , 13];
            //???????????????
            bool[,] b = new bool[4 ,13];
            //????????°???????????????
            for (int i = 0; i < o; i++)
            {
                //??\????????¢
                String[] ss = Console.ReadLine().Split(' ');
                int suuzi = int.Parse(ss[1]);
                //??\???????????????????????´??????????????????
                switch (ss[0])
                {
                    case "S":
                        b[0, suuzi - 1] = true;
                        break;

                    case "H":
                        b[1, suuzi - 1] = true;
                        break;

                    case "C":
                        b[2, suuzi - 1] = true;
                        break;

                    case "D":
                        b[3, suuzi - 1] = true;
                        break;
                }
            }
                //???????????\???????????°
                string sut = " ";
                //?????????????????????????????????
                for (int tate = 0; tate < 4; tate++)
                {
                    for (int yoko = 0; yoko < 13; yoko++)
                    {
                        //bool???false?????¢???
                        if(b [ tate , yoko ] ==false)
                        {
                            // b[tate,yoko]?????°????????????????????????????????????
                            switch (tate)
                            {
                                case 0:
                                    sut = "S";
                                    break;

                                case 1:
                                    sut = "H";
                                    break;

                                case 2:
                                    sut = "C";
                                    break;

                                case 3:
                                    sut = "D";
                                    break;
                            }
                            t[tate, yoko] = sut + " " +  (yoko + 1);
                            Console.WriteLine(t [ tate , yoko ]);
                        }
                    }
                }
        }
    }
}

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

int main()
{
    unsigned long long int A, B;
    cin >> A >> B;
    unsigned long long int min = A;
    vector<unsigned long long int> g;
    if (B < min)
    {
        min = B;
    }
    for (int i = 1; i < min + 1; i++)
    {
        if (A % i == 0 && B % i == 0)
        {
            g.push_back(i);
        }
    }
    unsigned long long int GCD = *max_element(g.begin(), g.end());
    unsigned long long int LCM = A * B / GCD;
    cout << LCM << endl;
}

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

using ll = long long;

//constant
const double EPS = 1e-10;
ll MOD = 1000000007;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { std::cout << e << std::endl; }
template<typename T> void view(const std::vector<T>& v) { for (const auto& e : v) { std::cout << e << " "; } std::cout << std::endl; }
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

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

// ***************************************

const ll INF = 1e+20;
vector<vector<ll>> dp;

int main(void) {

	int N;
	cin >> N;

	vector<ll> A(N);
	for (auto& a : A) {
		cin >> a;
	}
	vector<ll> dp(N, 1e10);
	dp[0] = 0;

	REP(i, N - 1) {
		chmin(dp[i + 1], dp[i] + abs(A[i] - A[i + 1]));
		if (i <= N - 3) {
			chmin(dp[i + 2], dp[i] + abs(A[i] - A[i + 2]));
		}
	}
	cout << dp[N - 1] << endl;

	return 0;
}

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

int main(void){
    int N;
    cin >> N;
    long long int A[N];
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A,A+N);
    for(int i=0;i<N;i++){
        if(A[i]==A[i+1]){
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
    return 0;
}

Measured memory_bytes: 5096
(defn input [[H _]]
  (if (zero? H)
    '()
    (cons (apply list (read-line))
      (input (list(dec H))))))


(defn getHW []
  (->> (clojure.string/split (read-line) #"\s") (map #(Integer/parseInt %))))

(defn GridCompression [A]
  (->> A
    (remove (fn [x](every? #(= \. %) x)))
    (apply map list)
    (remove (fn [x](every? #(= \. %) x)))
    (apply map str)
    (map #(format "%s\n" %))
    (apply str)))


(println (GridCompression (input (getHW))))

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

int c[10][10];

void floyd() {
    for (int k=0; k<=9; ++k) {
        for (int i=0; i<=9; ++i) {
            for (int j=0; j<=9; ++j) {
                c[i][j]=min(c[i][j], c[i][k]+c[k][j]);
            }
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

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

    for (int i=0; i<=9; ++i) {
        for (int j=0; j<=9; ++j) {
            cin >> c[i][j];
        }
    }

    floyd();

    int sum=0;
    for (int i=1; i<=h; ++i) {
        for (int j=1; j<=w; ++j) {
            int x;
            cin >> x;
            if (x!=-1) {
                sum+=c[x][1];
            }
        }
    }

    cout << sum;

    return 0;
}


Measured memory_bytes: 3644
l, r = list(map(int, input().split()))

MOD = 2019

a = 0

if r - l >= MOD:
    a = 0

else:
    x = l % MOD
    y = r % MOD
    if x > y:
        a = 0
    else:
        a = 2018
        for i in range(x, y):
            for j in range(i+1, y+1):
                a = min(a, i * j % MOD)

print(a)

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

void SME(int N, int L, vector<int> a){
  
  deque<int> Q;
  
  for(int i=0;i<N;i++){
    
    if( Q.size() && Q.front() <= i - L ) Q.pop_front();
    
    while( Q.size() && a[i] < a[ Q.back() ] ) Q.pop_back();
    
    Q.push_back( i );
    
    if( L <= i + 1 ){
      
      cout << a[ Q.front() ];
      
      if( i != N - 1 ) cout << ' ';
      
    }
    
  }
  
  cout<<endl;
  
}

signed main(){
  
  int N, L;
  cin >> N >> L;
  
  vector<int> a;
  
  for(int i=0;i<N;i++){
    
    int ai;
    cin>>ai;
    
    a.push_back( ai );
    
  }
  
  SME( N, L, a );
    
  return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll n;
vector<P> es;

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

  cin>>n;
  if(n==1){
    cout<<"No"<<endl;
    return 0;
  }

  for(ll i=1;i<(n%2==0?n-1:n);i+=2){
    es.push_back(P(0,i)); es.push_back(P(i,i+1));
    if(i==1)es.push_back(P(i+1,n));
    es.push_back(P(0,n+1+i)); es.push_back(P(n+1+i,n+i));
  }

  if(n%2==0){
  bool ok=false;
  repl(a,1,n){
    ll b=((n+1)^a);
    if(a!=b&&b<n){
      if(a%2==0){
        es.push_back(P(n-1,a-1));
      }else{
        es.push_back(P(n-1,a-1+n));
      }
      if(b%2==0){
        es.push_back(P(n-1+n,b-1));
      }else{
          es.push_back(P(n-1+n,b-1+n));
        }
        ok=true;
        break;
      }
    }
    if(!ok){
    cout<<"No"<<endl;
    return 0;
  }
  }

  cout<<"Yes"<<endl;
  rep(i,es.size())cout<<es[i].fi+1<<" "<<es[i].se+1<<endl;

  return 0;
}


Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	vector<string> W(N);
	rpz(i, N) cin>>W[i];

	// for(auto e:W) cout<<e<<"\n";//

	rpz(now, N-1){
		string nowW = W[now], nextW = W[now+1];
		// printf("%c %c\n",nowW[nowW.size()-1], nextW[0]);//
		if(nowW[nowW.size()-1] != nextW[0]){
			puts("No");
			return 0;
		}
	}

	rpz(now, N){
		rpz(pre, now){
			if(W[now] == W[pre]){
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
}


Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		long a = long.Parse(input[0]);
		long b = long.Parse(input[1]);
    long c = long.Parse(input[2]);
    long d = long.Parse(input[3]);
    long answer = b-a+1;
    long cc = b/c-(a-1)/c;//cで割り切れる個数
    long dd = b/d-(a-1)/d;
    long lcm = c*d/Gcd(c,d);
    long cd = b/lcm-(a-1)/lcm;
    answer -= cc+dd-cd;
    //Console.WriteLine(cc+" "+dd+" "+cd);
		Console.WriteLine(answer);
	}

  static long Gcd(long a, long b) 
      {//引数a,bの最大公約数を返す
           if (a < b)
               return Gcd(b, a);//入れ替え
           while (b != 0) 
           {
               long changeTo = a % b;
               a = b;
               b = changeTo;
           }
           return a;
       }
}

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

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int main() {
	string s;
	cin >> s;
	if (s.size() < 4 || s.substr(0, 4) != "YAKI") {
		cout << "No\n";
	}
	else {
		cout << "Yes\n";
	}
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
	
	string s;
	cin >> s;
	
	string ans="";
	
	rep(i,s.size()){
		if(s[i]=='B'){
			if(ans!=""){
				ans.pop_back();
			}
		}
		else{
			ans.push_back(s[i]);
		}
	}
			
	
	
    cout << ans << endl;
    
    return 0;

}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        OutputStream pr = System.out;
        PrintWriter out = new PrintWriter(pr);
        int n = sc.nextInt();
        double d =0.0;
        for(int i=0;i<n;i++){
            double val = sc.nextDouble();
            double ans = 1/val;
            d+=ans;
        }
        d=1/d;
        out.print(d);
        out.close();
    }
    public static long gcd(long a,long b){
        if(a==0){
            return b;
        }else{
            return gcd(b%a,a);
        }
    }
}

Measured memory_bytes: 25556
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
	public static void main(String[] args)throws IOException {
		FastReader sc = new FastReader();
		PrintWriter pw = new PrintWriter(System.out);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long k = sc.nextLong();
		long ans = 0;
		while (k != 0) {
			if (k != 0 && a <= k) {
				ans = ans + a;
				k = k - a;
			} else if (k != 0 && a > k) {
				ans = ans + k;
				k = 0;
			}
			if (k != 0 && b <= k) {
				k = k - b;
			} else if (k != 0 && b > k) {
				k = 0;
			}
			if (k != 0 && c <= k) {
				ans = ans + (-1) * c;
				k = k - c;
			} else if (k != 0 && c > k) {
				ans = ans - k;
				k = 0;
			}
		}
		System.out.println(ans);


	}
}





class FastReader {
	BufferedReader br;
	StringTokenizer st;

	public FastReader() {
		br = new BufferedReader(new
		                        InputStreamReader(System.in));
	}

	String next() {
		while (st == null || !st.hasMoreElements()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException  e) {
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}

	int nextInt() {
		return Integer.parseInt(next());
	}

	long nextLong() {
		return Long.parseLong(next());
	}

	double nextDouble() {
		return Double.parseDouble(next());
	}

	String nextLine() {
		String str = "";
		try {
			str = br.readLine();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return str;
	}
}

Measured memory_bytes: 32960
#include<stdio.h>
#define N 100

int main(){
  int i,j,n,A[N],v,x;

  scanf("%d",&n);
 
  for(i = 0 ; i < n ; i++){
    scanf("%d",&A[i]);
  }
  
  for(x = 0 ; x < n ; x++){
    printf("%d",A[x]);
    if(x < n-1) printf(" ");
  }
    printf("\n");
  
  for(i = 1 ; i < n ; i++){
    v = A[i];
    j = i - 1;
    
    while( j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }
    for(x = 0 ; x < n ; x++){
      printf("%d",A[x]);
      if(x < n-1) printf(" ");
    }
    printf("\n");
    
  }
  return 0;
}

Measured memory_bytes: 604
package main

import (
	"fmt"
)

func min(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	minDist := 0
	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		minDist += min(x, k-x)
	}

	fmt.Println(2 * minDist)
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define INF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))

Int n;
Int sz[216000];
Int dp[5010][5010][2];
Int res;
Int u, v;
vector<Int> edge[5400];
Int a[5400];
Int tmp[5010][2];
Int dfs(Int x, Int last= -1){
  if(a[x] > 0)dp[x][0][0] = a[x];
  else dp[x][0][1] = a[x];
  sz[x] = 1;
  for(Int i = 0;i < edge[x].size();i++){
    Int to = edge[x][i];
    if(to == last)continue;
    dfs(to, x);
    for(Int j = 0;j < sz[x] + sz[to];j++)tmp[j][0] = tmp[j][1] = INF;
    for(Int j = sz[x] - 1;j >= 0;j--){
      for(Int k = sz[to] - 1;k >= 0;k--){
	tmp[j+k][0] = min(tmp[j+k][0], dp[x][j][0] + dp[to][k][0]);
	tmp[j+k][1] = min(tmp[j+k][1], dp[x][j][1] + dp[to][k][1]);
	tmp[j+k][1] = min(tmp[j+k][1], dp[x][j][0] + dp[to][k][1]);
	tmp[j+k][1] = min(tmp[j+k][1], dp[x][j][1] + dp[to][k][0]);
	if(dp[to][k][1] < 0 || dp[to][k][0] != INF){
	  tmp[j+k+1][0] = min(tmp[j+k+1][0], dp[x][j][0]);
	  tmp[j+k+1][1] = min(tmp[j+k+1][1], dp[x][j][1]);
	}
      }
    }
    for(Int j = 0;j < sz[x] + sz[to];j++){
      dp[x][j][0] = tmp[j][0];
      dp[x][j][1] = tmp[j][1];
    }
    sz[x] += sz[to];    
  }
}
int main(){
  cin >> n;
  for(Int i = 0;i < n;i++)
    for(Int j = 0;j < n;j++)
      dp[i][j][0] = dp[i][j][1] = INF;
  for(Int i = 0;i < n;i++)cin >> a[i];
  for(Int i = 0;i < n-1;i++){
    cin >> u >> v;u--,v--;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  dfs(0);
  for(Int i = n-1;i >= 0;i--){
    if(dp[0][i][0] != INF)res = i;
    if(dp[0][i][1] < 0)res = i;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 394112
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n := r.nextInt()
	mp := map[string]int{}
	for i := 0; i < n; i++ {
		r.Scan(true)
		mp[r.nextString()]++
	}

	for _, v := range []string{"AC", "WA", "TLE", "RE"} {
		fmt.Fprintln(stdout, v, "x", mp[v])

	}
}


Measured memory_bytes: 3712
using namespace std;
#include 		<bits/stdc++.h>
#define	fi 		first
#define se 		second
#define pb 		push_back
#define mp 		make_pair
#define maxn	500005
#define inf		int(21e8)
#define mod		int(1e9+7)
#define db		double
#define ll		long long
#define si 		stack<int>
#define qi 		queue<int>
#define vi 		vector<int>
#define pi 		pair<int, int>
#define pq  	priority_queue< int, vector<int>, greater<int> >
ll gcd(ll a, ll b) {return b ? gcd(a, b) : a;}
map<string, int> ss;
int main() {
	ss.clear();
	int n;
	cin >> n;
	string s;
	for(int i = 1; i <= n; i ++) {
		cin >> s;
		ss[s] ++;
	}
	cout << "AC x " << ss["AC"] << endl;
	cout << "WA x " << ss["WA"] << endl;
	cout << "TLE x " << ss["TLE"] << endl;
	cout << "RE x " << ss["RE"] << endl;
	system("pause");
	return 0;
}

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

int main() {
  
  int H, N, X = 0;
  cin >> H >> N;
  
  vector<int> A(N);
  
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
    X += A.at(i);
  }
  
  if(X >= H) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 3780
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val adj = Array(n) { mutableSetOf<Pair<Int, Int>>() }
    for (i in 0 until n - 1) {
        val u = sc.nextInt() - 1
        val v = sc.nextInt() - 1
        val c = sc.nextInt()
        adj[u].add(v to c)
        adj[v].add(u to c)
    }
    val q = sc.nextInt()
    val k = sc.nextInt() - 1
    val dist = Array(n) { 0L }
    val que: Queue<Pair<Int, Long>> = ArrayDeque()
    que.add(k to 0)
    val visited = Array(n) { false }
    visited[k] = true
    while (que.count() > 0) {
        val (v, d) = que.poll()
        dist[v] = d
        for ((w, c) in adj[v]) {
            if (!visited[w]) {
                visited[w] = true
                que.add(w to d + c)
            }
        }
    }
    for (i in 0 until q) {
        val x = sc.nextInt() - 1
        val y = sc.nextInt() - 1
        println(dist[x] + dist[y])
    }
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 123452
MOD = 10**9+7
n = int(input())
a = list(map(int, input().split()))
cnt = [0 for _ in range(n)]
ans = 1
for x in a:
    if x > 0:
        ans *= cnt[x-1] - cnt[x]
    else:
        ans *= 3 - cnt[0]
    cnt[x] += 1
    ans %= MOD
print(ans)


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

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

    stack<int> stk;
    string s;
    while(cin >> s){
        if(s == "+"){
            int a = stk.top();
            stk.pop();
            int b = stk.top();
            stk.pop();
            stk.push(a + b);
        }
        else if(s == "-"){
            int a = stk.top();
            stk.pop();
            int b = stk.top();
            stk.pop();
            stk.push(b - a);
        }
        else if(s == "*"){
            int a = stk.top();
            stk.pop();
            int b = stk.top();
            stk.pop();
            stk.push(a * b);
        }
        else{
            stk.push(stoi(s));
        }
    }
    cout << stk.top() << endl;
    return 0;
}

Measured memory_bytes: 3228
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 3000+1;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}

ll dp[Max+2][Max+2][4];
ll ara[Max+2][Max+2];

ll n,m;

ll call(ll i,ll j,ll cnt)
{
   // if(i==1 && j==2 || (i==2 && j==1))

  // cout<<i<<" "<<j<<" "<<cnt<<" "<<val<<endl;
    if(i>n || j>m )
        return 0;

        ll &ret=dp[i][j][cnt];


        if(ret!=-1)return ret;

        ret=0;

        if(cnt==3)
        {
            ret=max(call(i+1,j,0),call(i,j+1,cnt));
        }
        else
        {
            if(ara[i][j])
            {
ret=max3(ara[i][j]+call(i,j+1,cnt+1),call(i,j+1,cnt),ara[i][j]+call(i+1,j,0));
            }
            else{

            ret=max(call(i+1,j,0),call(i,j+1,cnt));
            }
        }

        return ret;

}
int main()
{

    fastread();

    ll i,j,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;

    bool flag=false;

    string str;

    cin>>n>>m>>k;

    while(k--)
    {
        cin>>a>>b>>c;

        ara[a][b]=c;
    }
    memset(dp,-1,sizeof(dp));

    cout<<call(1,1,0)<<endl;






}



Measured memory_bytes: 356336
#include<stdio.h>
#include<string.h>
 
int main( void ) 
{
    char s[202],p[101];
    int i,j,k;
    int len=0;
     
    scanf( "%s", s );
    scanf( "%s", p );
     
    len=strlen( s );
    memmove( s+len, s, len+1 ); 
     
    i=j=0;
    while( 1 ) {    
        if( p[0] == s[i] ) {
            j=0;
            k=i;    
            while( p[j] == s[k] ) {
                j++;
                k++;            
             }
            if( '\0' == p[j] ) {
                printf( "Yes\n" );
                break;
            }        
        } else {
            j=0;
        }
        if( '\0' == s[i++] ) {
            printf( "No\n" );   
            break;
        }
    }
 
    return 0;
}

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

int n;

int calc(vector< int > p) {
    int sum = 0;
    for(int i = 1; i < n; i++) {
        if(p[i] > 0) {
            sum += p[i] * 2;
            p[i + 1] = max(0, p[i + 1] - p[i]);
        }
    }
    return sum + p[n];
}

int main() {

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

    int sum = 100000000;
    for(int i = 0; i <= 3; i++) {
        sum = min(sum, calc(p) + i);
        p[1] = max(0, p[1] - 1);
    }
    cout << sum << endl;
}

Measured memory_bytes: 3204
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int count = scanner.nextInt();
	int lhs = 0;
    int rhs = scanner.nextInt();
    
    int[] balls = new int[count];
    for (int ix = 0; ix < count; ix++) {
      balls[ix] = scanner.nextInt();
    }
    
    int answer = 0;
    for (int ix = 0; ix < balls.length; ix++) {
      answer += Math.min(balls[ix], rhs - balls[ix]);
    }
    
	System.out.println(answer * 2);
  }
}


Measured memory_bytes: 22740
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] acc = new long[n];
        for(int i = 0; i < n; ++i) acc[i] = (i == 0) ? sc.nextLong() : acc[i - 1] + sc.nextLong();
        long ans = Long.MAX_VALUE;
        for(int i = 0; i < n - 1; ++i) {
            long left = acc[i];
            long right = acc[n - 1] - acc[i];
            ans = Math.min(ans, Math.abs(left - right));
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 82808
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val A = input.nextInt()
    val B = input.nextInt()
    var price = -1
    
    for (p in 1..1000) {
      val price8 = (p * 2) / 25
      val price10 = p / 10
      
      if (price8 == A && price10 == B) {
        price = p
        break
      }
    }
    
    println(price)
  }
}

Measured memory_bytes: 36368
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String[] sn=sc.nextLine().split(" ");
int num=Integer.parseInt(sn[0]);
int num2=Integer.parseInt(sn[1]);

if(1>num-num2*2){
System.out.println(0);

}else{

System.out.println(num-num2*2);
}

	}
}

Measured memory_bytes: 22608
def K(n):
    return 0.5 * (n + 1)

def d():
    n, k = list(map(int, input().split()))
    p = list(map(int, input().split()))

    pionta = None
    ire = [None for i in range(k)]
    d = {}
    d[0] = 0

    ss = 0
    for i in range(0, n):
        if k < i + 1:
            pionta = i % k
        if pionta is None:
            ire[i] = p[i]
        else:
            ss += p[i] - ire[pionta]
            d[ss] = i
            ire[pionta] = p[i]


    max_s = max(d.keys())
    i = d[max_s]
    m = 0
    for i2 in range(i-k+1, i+1):
        m += K(p[i2])
    return m
print(d())

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

int main(){
    int k;  cin >> k;
    queue<string>que;
    rep(i, 9)   que.push(to_string(i+1));
    string ans;
    rep(i, k){
        ans = que.front();
        que.pop();
        int n = ans.size();
        --n;
        if(ans[n] == '0'){
            rep(i, 2)   que.push(ans + to_string(i));
        }else if(ans[n] == '9'){
            rep(i, 2)   que.push(ans + to_string(i+8));
        }else{
            rep(i, 3)   que.push(ans + to_string((ans[n]-'0')-1 + i));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 10752
N = int(input())
S = [x for x in input()]

def p(S):
  s = len(S)
  e = 0
  cnt = 0
  while s != e:
    cnt += 1
    if cnt > N:break
    s = len(S)
    for i in range(s-1):
      if i >= len(S)-1:break
      if S[i] == S[i+1]:S.pop(i)
      e = len(S)
  return len(S)

print(p(S))

Measured memory_bytes: 4212
N=int(input())
a=[0]
i=0
if N==1:
    print(1)
    exit()
while a[-1]<=100:
    a.append(2**i)
    i+=1
for i in range(1,len(a)):
    if a[i]>N:
        print(a[i-1])
        exit()


Measured memory_bytes: 2940
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second



void Prime_factorize(vector<ll>& v,ll n){
    if(n<=1) return;
    ll l=ll(sqrt(n));
    FOR(i,2,l){
        if(n%i==0){
        Prime_factorize(v,i);Prime_factorize(v,ll(n/i));return;
        }
    }
    v.PB(n);return;
}


signed main(){
    ll n;cin >> n;
    map<ll,ll> m;
    FOR(i,1,n){
        vector<ll> v;Prime_factorize(v,i);
        REP(j,v.size()){
            if(m.find(v[j])==m.end()){
                m.insert(MP(v[j],1));
            }else{
                m[v[j]]++;
            }
        }
    }
    vector<ll> ans(5,0);
    for(auto i=m.begin();i!=m.end();++i){
        if(i->S>=74){
            ans[0]++;
        }
        if(i->S>=24){
            ans[1]++;
        }
        if(i->S>=14){
            ans[2]++;
        }
        if(i->S>=4){
            ans[3]++;
        }
        if(i->S>=2){
            ans[4]++;
        }
    }
    ll rans=0;
    if(ans[3]>=2 && ans[3]+ans[4]>=3){
        rans+=ll((ans[4]-2)*ans[3]*(ans[3]-1)/2);
    }
    //cout << rans << endl;
    rans+=ans[0];
    rans+=(ans[1]*(ans[4]-1));
    rans+=(ans[2]*(ans[3]-1));
    cout << rans << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;
int main()
{
   //IOS;
   int k;
   cin >> k;
   string s;
   cin >> s;
   int L=s.length();
   if(L<=k) cout << s;
   else
   {
       rep(i,0,k-1){
           cout<<s[i];
       }
       cout<<"...";
   }
   
}


Measured memory_bytes: 3628
#include <stdio.h>

int main()
{
  int r, g, b, x;
  //整数の入力
  scanf("%d %d %d", &r, &g, &b);
  //処理
  r = r * 100;
  g = g * 10;
  x = r + g + b;
  //出力
  if(x % 4 == 0)
  {
    printf("YES\n");
  }
  else
  {
    printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { };
};
using Graph = vector<vector<int>>;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));

typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
//-0.4620981203755741
long ggd(long a, long b) {//最小公倍数，最大公約数
	if(a<b)swap(a,b);
	if (b == 0) {
		return a;			
	}
	return ggd(b, a % b);
}
long lcm(long number1,long number2){
	return number1/ggd(number1,number2)*number2;	
}
int main(){
    ll a,b,c,d;
    std::cin >> a>>b>>c>>d;
    ll ans=0;
    a--;
    ans-=a/c;
    ans+=b/c;
    //std::cout << ans << std::endl;
    ans-=a/d;
    ans+=b/d;
    //std::cout << ans << std::endl;
    c=lcm(c,d);
    ans+=a/c;
    ans-=b/c;
    //std::cout << ans << std::endl;
    
    std::cout << (b-a)-ans << std::endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;

long long a[200000];
const long long T=1e18;

int main()
{
	int n=0;scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	sort(a+1,a+n+1);if(a[1]==0){puts("0");return 0;}
	__int128 x=1;
	for(int i=1;i<=n;i++)
	{
		x=x*a[i];if(x>T){puts("-1");return 0;}
	}
	printf("%lld",(long long)x);
}


Measured memory_bytes: 2520
#include<stdio.h>
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int dp[850][850];
//dp[i][j]=i,j,S-i-jに分けられるか？

int a[60];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",a+i);
	dp[0][0]=1;
	for(int k=0;k<n;k++){
		for(int i=840;i>=0;i--)for(int j=840;j>=0;j--){
			if(i>=a[k])dp[i][j]|=dp[i-a[k]][j];
			if(j>=a[k])dp[i][j]|=dp[i][j-a[k]];
		}
	}
	int ans=3000;
	int sum=0;
	for(int i=0;i<n;i++)sum+=a[i];
	for(int i=0;i<840;i++)for(int j=0;j<840;j++)if(dp[i][j]){
		ans=min(ans,max(i,max(j,sum-i-j)));
	}
	printf("%d\n",ans);
}



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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, k, ans = 0;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i], a[i]--;

  int logk = floor(log2(k));
  vector<vector<ll>> doubling(logk + 1, vector<ll>(n));
  rep(i, n) doubling[0][i] = a[i];

  rep(i, logk) rep(j, n) doubling[i + 1][j] = doubling[i][doubling[i][j]];

  int now = 0;
  for (int i = 0; i < logk + 1; ++i)
    if ((k >> i) & 1) now = doubling[i][now];

  cout << now + 1 << endl;
  return 0;
}


Measured memory_bytes: 100208
H,W = input().split()

H = int(H)
W = int(W)

t = H * W

mod = t % 2

if H != 1 and W != 1:
    if mod == 0:
        print(int(t/2))
    else:
        print(int(t/2) + 1)
else:
    print(1)

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int x,a,b; cin>>x>>a>>b;
	cout<<(abs(x-a)<abs(x-b)?'A':'B')<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  int dp[n];
  dp[0]=0;
  dp[1]=abs(arr[1]-arr[0]);
  for(int i=2;i<n;i++)
  {
    dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
  }
  cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b float64
	fmt.Scan(&a, &b)

	ans := -1
	for i := 0; i < 1009; i++ {
		if math.Floor(float64(i)*0.08) == a && math.Floor(float64(i)*0.1) == b {
			ans = i
			break
		}

	}

	fmt.Println(ans)

}


Measured memory_bytes: 512
import itertools
A = [[int(_) for _ in input().split()] for _ in range(3)]
N = int(input())
B = set([int(input()) for _ in range(N)])
C = [[False] * 3 for _ in range(3)]
for i, j in itertools.product(range(3), range(3)):
    if A[i][j] in B:
        C[i][j] = True
f = False
for i in range(3):
    if all(C[i][j] for j in range(3)):
        f = True
for j in range(3):
    if all(C[i][j] for i in range(3)):
        f = True
if all([C[0][0], C[1][1], C[2][2]]):
    f = True
if all([C[0][2], C[1][1], C[2][0]]):
    f = True
print('Yes' if f else 'No')


Measured memory_bytes: 3064
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter


val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (n, q) = readIntegerList()
    val s = br.readLine()!!
    val sums = IntArray(n + 1)
    for (i in 1 until s.length) {
        sums[i + 1] = sums[i] + if (s[i - 1] == 'A' && s[i] == 'C') 1 else 0
    }
    repeat(q) {
        val (l, r) = readIntegerList()
        val ans = sums[r] - sums[l]
        out.println(ans)
    }
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 58608
/**
 * Give N, K
 * Let f(x) be the number of seqs whose gcd equals x.
 * f(x) = (K/x)^N - f(2x) - f(3x) - ... - f(mx) (where mx <= K)
 */
#include <bits/stdc++.h>
using namespace std;

const int64_t MAGIC = 1e9 + 7;

int64_t calcPower(int64_t x, int64_t n) {
  if (n == 0) return 1;
  int64_t ret = 1;
  while (n) {
    if (n & 1) {
      ret = (ret * x) % MAGIC;
    }
    n >>= 1;
    x = (x * x) % MAGIC;
  }
  return ret;
}

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

  int N, K;
  cin >> N >> K;

  int64_t ans = 0;
  vector<int64_t> dp(K);

  for (int i = K; i >= 1; --i) {
    dp[i-1] = calcPower(K / i, N);
    for (int j = i+i; j <= K; j += i) {
      dp[i-1] = (dp[i-1] + MAGIC - dp[j-1]) % MAGIC;
    }
    ans = (ans + dp[i-1] * i) % MAGIC;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3988
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<long, long, greater<long> >::iterator;

ll F(ll in) {
	if (in % 2 == 0) {
		return in / 2;
	}
	else {
		return 3 * in + 1;
	}
}

// 2036
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	// long long?
	int N;
	cin >> N;

	vector<int> vH(N, 0);
	rep(i, N) cin >> vH[i];

	int l = 0;
	int r = 0;
	int num = 0;
	while (1) {
		int i = 0;
		while (1) {
			if (vH[i] >= 1) {
				l = i;
				break;
			}
			if (i == N - 1) break;
			i++;
		}

		if (i == N - 1 && vH[i] == 0) break;

		r = i;
		while (1) {
			if (vH[i] == 0) {
				r = i;
				break;
			}
			if (i == N - 1) {
				r = i+1;
				break;
			}
			i++;
		}

		for (int j = l; j != r; ++j) {
			vH[j]--;
		}
		num++;
	}

	cout << num << endl;

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int n;
string s;

int main() {
	cin >> n >> s;
	string t = s.substr(n / 2);
	
	cout << (s == t + t ? "Yes" : "No") << endl;
	
	return 0;
}


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

using namespace std;

int main(){
  int N;
  cin >> N;
  
  vector<vector<int>> graph(N);
  vector<int> d(N, 0);
  for(int i = 0; i < N - 1; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  
  vector<int> c(N);
  for(int i = 0; i < N; i++) cin >> c[i];
  
  sort(c.rbegin(), c.rend());
  
  int M = 0;
  queue<int> q;
  d[0] = c[0];
  for(int post : graph[0]) if(!d[post]) q.push(post);
  for(int i = 1; i < N; i++){
    int cur = q.front();
    q.pop();
    M += (d[cur] = c[i]);
    for(int post : graph[cur]) if(!d[post]) q.push(post);
  }
  
  cout << M << endl;
  for(int i = 0; i < N - 1; i++) cout << d[i] << ' ';
  cout << d[N - 1] << endl;
  
  return 0;
}

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

int main(void) {
    int n;
    long long ans = 1;
    vector<int> prime;
    cin >> n;
    for (int i = 2; i <= n; i++) {
        bool flag = true;
        for (int j = 2; j * j <= i; j++) {
            if (i != j && !(i % j)) {
                flag = false;
                break;
            } 
        }
        if (flag)
            prime.push_back(i);
    }
    cin >> n;
    for (auto item : prime) {
        int zohe = 0;
        for (int i = 2; i <= n; i++) {
            int ehoz = i;
            while (!(ehoz % item)) {
                zohe++;
                ehoz /= item;
            }
        }
        ans = ans * (zohe + 1) % 1000000007;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
m=10**9+7
def cmb(x,y):
    c=1
    for i in range(1,y+1):
        c=(c*(x-i+1)*pow(i,m-2,m))%m
    return c
print((pow(2,n,m)-1-cmb(n,a)-cmb(n,b))%m)

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong N, M;
  priority_queue<llong> que;

  cin >> N >> M;
  for (llong in, i = 0; i < N; ++i) {
    cin >> in;
    que.push(in);
  }

  for (int i = 0; i < M; ++i) {
    llong now = que.top();
    que.pop();
    que.push(now/2);
  }

  llong sum = 0;
  while (que.size()) {
    sum += que.top();
    que.pop();
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define iFOR(i, a, b) for(int i=(a); i>=(b); --i)
#define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin())

using namespace std;

typedef pair<int,int> PII;
typedef long long LL;
typedef double DD;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<DD,DD> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;
const LL mod = 1000000007;
vector<int> g[100005];
int ans[100005];
queue<int> bfs;
int main(){
    int n, m;
    scanf("%d %d",&n,&m);
    memset(ans, -1, sizeof ans);
    FOR(i, 1, m){
        int a, b;
        scanf("%d %d",&a,&b);
        g[a].eb(b); g[b].eb(a);
    }
    ans[1]=0;
    bfs.push(1);
    while(!bfs.empty()){
        int u = bfs.front();
        bfs.pop();
        for(int e : g[u]){
            if(ans[e] != -1) continue;
            ans[e] = u; bfs.push(e);
        }
    }
    printf("Yes\n");
    FOR(i, 2, n) printf("%d\n",ans[i]);
	return 0;
}
/*
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */

Measured memory_bytes: 10644
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    string s;
    vector<char> cs;
    cin >> s;
    if (s.size() != 4) goto fail;
    for (auto c : s) {
      cs.push_back(c);
    }
    sort(cs.begin(), cs.end());
    if (cs[0] != cs[1]) goto fail;
    if (cs[2] != cs[3]) goto fail;
    if (cs[0] == cs[3]) goto fail;
    cout << "Yes" << endl;
    return 0;
fail:
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 384