akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll n;
double ans, f = 1, x[10], y[10];
int main(){
  cin >> n;
  vector<ll> s(n);
  REP(i, n) s[i] = i;
  REP(i,n) cin >> x[i] >> y[i];
  REP(i,n) f *= i + 1;
  do{
      double now = 0;
      REP(i,n - 1){
          now += sqrt((x[s[i]] - x[s[i + 1]]) * (x[s[i]] - x[s[i + 1]]) + (y[s[i]] - y[s[i + 1]]) * (y[s[i]] - y[s[i + 1]]));
      }
      ans += now;
  }while(next_permutation(ALL(s)));
  cout << fixed << setprecision(10) << ans / f << endl;
}


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

int main() {
  int N,A;
  1 <= N <= 10000;
  0 <= A <= 1000;
  cin >> N >> A;
  if(N % 500 <= A) {
  cout << "Yes" << endl;
  }
  else {
  cout << "No" << endl;
  }
}

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

const int inf = 1e9;
const ll linf = 1e18;

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

    int h, a; cin >> h >> a;
    cout << (h + a - 1) / a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define int long long
#define ll long long
using namespace std;
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
signed main(){
    int n;
    cin>>n;
    vector<int>h(n);
    rep(i,n)cin>>h[i];
    for(int i=n-2;i>=0;i--){
        if (h[i] > h[i + 1] + 1) {
            cout<<"No"<<endl;
            return 0;
        }
        else if(h[i] == h[i + 1] + 1)h[i]=h[i+1];
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 1024
N, Y = [int(_) for _ in input().split()]
flag = False

for i in range(N+1):
    y = 10000*i
    if y > Y:
        break

    for j in range(N+1-i):
        k = N-i-j
        y1 = y+5000*j+1000*k
        if y1 == Y:
            flag = True
            break
        elif y1 > Y:
            break

    if flag:
        break

if flag:
    print(i, j, N-i-j)
else:
    print(-1, -1, -1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int m[3000];
int vis[3000];
int dis[3000];
vector<vector<int>>g;
void bfs(int nod){
    queue<int>q;
    q.push(nod);
    dis[nod]=0;
    while(q.size()){
        int cur=q.front();
        q.pop();
        if(vis[cur])continue;
        vis[cur]=1;
        m[dis[cur]]++;
        for(int i=0;i<g[cur].size();i++){
            if(dis[g[cur][i]]==-1){
            dis[g[cur][i]]=dis[cur]+1;
            q.push(g[cur][i]);
            }

        }
        
    }
}
int main(void){
    int n;
    cin>>n;
    int x;
    cin>>x;
    int y;
    cin>>y;
    g.resize(n+1);
    for(int i=1;i<n;i++)g[i].push_back(i+1),g[i+1].push_back(i);
    g[x].push_back(y);g[y].push_back(x);
    for(int i=1;i<=n;i++){memset(dis,-1,sizeof dis);bfs(i);memset(vis,0,sizeof vis);}
    for(int i=1;i<n;i++)cout<<m[i]/2<<"\n";
}


Measured memory_bytes: 384
s = gets.chomp
f = "R"
c = 0
xr = 0
x = 0
a = []
s.length.times do |i|
  a[i] = 0
end
s.length.times do |i|
  if s[i] == "R" && f == "R"
    c += 1
  elsif s[i] == "R" && f == "L"
    if (x - xr) % 2 == 0
      a[x] += c - c / 2
      a[x+1] += c / 2
    else
      a[x+1] += c - c / 2
      a[x] += c / 2
    end
    f = "R"
    xr = i
    c = 1
  elsif s[i] == "L" && f == "R"
    f = "L"
    x = i - 1
    c += 1
  elsif s[i] == "L" && f == "L"
    c += 1
  end
end
    if (x - xr) % 2 == 0
      a[x] += c - c / 2
      a[x+1] += c / 2
    else
      a[x+1] += c - c / 2
      a[x] += c / 2
    end
print a[0]
(s.length-1).times do |i|
  print " #{a[i+1]}"
end


Measured memory_bytes: 3068
import java.util.*
fun main(arg: Array<String>) {
    val N = nextInt()
    val A = listOfLong()
    val B = listOfLong().toLongArray()
    var P = PriorityQueue<Pair<Long, Int>>(N, Comparator { a, b ->  b.first.compareTo(a.first) })
    B.forEachIndexed { index, value ->  if (A[index] != value) P.add(Pair(value, index))}
    var ans = 0L
    while (!P.isEmpty()) {
        val p = P.poll()
        val at = p.second
        val lr = B[(N + at - 1) % N] + B[(N + at + 1) % N]
        if (B[at] - A[at] < lr) {
            ans = -1
            break
        }
        val t = (B[at] - A[at]) / lr
        B[at] -= lr * t
        ans += t
        if (A[at] != B[at]) P.add(Pair(B[at], at)) }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map { it.toLong() }


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

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

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

int main() {
	int n;
	cin >> n;
	int a[200300], b[200300];
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		b[i] = a[i];
	}
	sort(b, b + n);
	for (int i = 0;i < n;i++) {
		if (a[i] < b[n / 2])cout << b[n / 2] << endl;
		else cout << b[n / 2 - 1] << endl;
	}
}

Measured memory_bytes: 3712
module AOJ_Volume0044;

import std.stdio,std.string,std.conv;


int prime[1000000];

int main()
{
	prime[0] = prime[1] = 0;

	foreach(i;2..1000000)
	{
		prime[i] = 1;
	}
	foreach(i;2..1000000)
	{
		if(prime[i])
		{
			for(int j = i*2; j < 1000000 ;j += i)
			{
				prime[j] = 0;
			}
		}
	}

	string s;
	while((s = readln.chomp).length != 0)
	{
		int n = s.to!int;
		for(int i= n-1;i > 0;i--)
		{
			if(prime[i] == 1) 
			{
				write(i," ");
				break;
			}
		}
		for(int i = n+1; i < 1000000;i++)
		{
			if(prime[i] == 1) 
			{
				i.writeln;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 4960
while True:
    m,f,r = map(int,input().split())
    if m == -1 and f == -1 and r == -1:
        break
    
    sum = m + f
    
  
    
    if m == -1 or f == -1:
        print('F')
    elif sum >= 80:
        print('A')
    elif sum < 80 and sum >= 65:
        print('B')
    elif sum < 65 and sum >= 50:
        print('C')
    elif sum < 50 and sum >= 30:
        if r >= 50 :
            print('C')
        else:
            print('D')
    else:
        print('F')

Measured memory_bytes: 5592
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n; rd(n);
  auto a=readln.split.to!(long[]);

  long tot=0;
  for(auto i=0, j=0, s=0L; i<n; i++){
    while(j<n){
      if((s+a[j])==(s^a[j])) s+=a[j], j++;
      else break;
    }
    // [i, j) : valid
    tot+=(j-i).to!(long);
    s-=a[i];
  } 

  writeln(tot);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}


Measured memory_bytes: 10800
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();

    if(a < b) {
      for(int n = 0;n < b; n++) {
        System.out.print(a);
      }
    } else {
      for(int n = 0;n < a; n++) {
        System.out.print(b);
      }
    }
  }
}

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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int h = sc.nextInt();
		int w = sc.nextInt();
		int n = sc.nextInt();

		input = new char[h][w];
		board = new char[h + 1][w + 1];

		for(int i = 0; i < h; i++){
			String tmp = sc.next();

			for(int j = 0; j < w; j++){
				input[i][j] = tmp.charAt(j);
			}
		}

		for(int i = 0; i < h; i++){
			for(int j = 0; j < w - 1; j++){
				initBoard();
				boolean result = solve(j, i, n);

				if(result){
					System.out.println("YES");
					return;
				}
			}
		}

		System.out.println("NO");

	}

	static char[][] input;
	static char[][] board;

	static boolean solve(int x, int y, int n){
		int h = input.length;
		int w = input[0].length;

		char tmp = board[y][x];
		board[y][x] = board[y][x + 1];
		board[y][x + 1] = tmp;

//		System.out.println("swap "+"("+x+","+y+")");
//		printBoard();

		while(true){
			boolean change = false;
			for(int j = 0; j < w; j++){
				for(int i = 1; i < h; i++){
					if(board[i][j] != '.' && board[i - 1][j] == '.'){
						change = true;
//						System.out.println("drop event");
						for(int k = i - 1; k >= 0; k--){
							if(k == 0 || board[k - 1][j] != '.'){
								board[k][j] = board[i][j];
								board[i][j] = '.';
								break;
							}
						}
					}
				}
			}

//			System.out.println("drop");
//			printBoard();

			boolean delete[][] = new boolean[h][w];

			for(int i = 0; i < h; i++){
				int count = 0;
				for(int j = 0; j <= w; j++){
					if(j == 0 || board[i][j] != board[i][j - 1]){
						if(count >= n){
							for(int k = j - 1; k >= j - count; k--){
								delete[i][k] = true;
							}
						}
						count = 1;
					}
					else {
						count++;
					}
				}
			}
			for(int j = 0; j < w; j++){
				int count = 0;
				for(int i = 0; i <= h; i++){
					if(i == 0 || board[i][j] != board[i - 1][j]){
						if(count >= n){
							for(int k = i - 1; k >= i - count; k--){
								delete[k][j] = true;
							}
						}
						count = 1;
					}
					else {
						count++;
					}
				}
			}

			boolean allDeleted = true;
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					if(delete[i][j] && board[i][j] != '.'){
						change = true;
//						System.out.println("delete event");
						board[i][j] = '.';
					}

					if(board[i][j] != '.'){
						allDeleted = false;
					}
				}
			}
//			System.out.println("delete");
//			printBoard();

			if(allDeleted){
				return true;
			}

			if(!change){
				break;
			}
		}

		return false;
	}

	static void initBoard(){
		for(int i = 0; i < input.length; i++){
			Arrays.fill(board[i], '.');

			for(int j = 0; j < input[i].length; j++){
				board[i][j] = input[input.length - i - 1][j];
			}
		}

	}

	static void initDeleteFlag(boolean[][] delete){
		for(int i = 0; i < delete.length; i++){
			Arrays.fill(delete[i], false);
		}
	}

	static void printBoard(){
		int h = input.length;
		int w = input[0].length;

		for(int i = h - 1; i >= 0; i--){
			for(int j = 0; j < w; j++){
				System.out.print(board[i][j]);
			}
			System.out.println();
		}
	}

}



Measured memory_bytes: 31312
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int N,A,B,ans = 0;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N >> A >> B;
	vector<int> P(N);
	vector<bool> F(N,true);
	for(auto &x: P){
		cin >> x;
	}

	sort(P.begin(),P.end());

	REP(i,N - 2){
		int temp = ans;
		if(P[i] <= A && F[i]){
			FOR(j,i + 1,N - 1){
				if(P[j] >= A + 1 && P[j] <= B && F[j]){
					FOR(k,j + 1,N){
						if(P[k] >= B + 1 && F[k]){
							F[i] = false;
							F[j] = false;
							F[k] = false;
							ans++;
						}
						if(temp != ans) break;

					}
				}
				if(temp != ans) break;
			}
		}else if(P[i] > A){
			break;
		}else{

		}
		if(temp != ans) i = 0;
	}

	cout << ans << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<stdio.h>
#define rep(i,n)for(int i=0;i<n;i++)
//printf("%.yf\n",x); xを小数点以下y桁で
using namespace std;
int main() {
    int s;
    cin >> s;
    int m = s / 60;
    s -= m * 60;
    int h = m / 60;
    m -= h * 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}



Measured memory_bytes: 3104
# -*- coding: utf-8 -*-
# kakomon toku
import math
import sys
import itertools
import numpy as np

a,b,c,d = map(int, input().split())

if abs(a-c)<=d :
    print("Yes")
elif abs(a-b)<=d and abs(b-c)<=d :
    print("Yes")
else:
    print("No")



Measured memory_bytes: 21796
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int m, k;
    cin >> m >> k;
    if(k >= (1<<m)){
        cout << -1 << endl;
        return 0;
    }
    if(m == 0){
        cout << "0 0" << endl;
        return 0;
    }
    if(m == 1){
        if(k == 0){
            cout << "0 0 1 1" << endl;
        }
        if(k == 1){
            cout << - 1<< endl;
        }
        return 0;
    }
    vector<int>ans;
    for(int i = (1<<m) - 1; i >= 0; i--){
        if(i!=k)ans.push_back(i);
    }
    ans.push_back(k);
    rep(i,1<<m)if(i!=k)ans.push_back(i);
    ans.push_back(k);
    rep(i,ans.size()){
        if(i>0)cout << " ";
        cout <<ans[i];
    }
    cout << endl;
}

Measured memory_bytes: 2932
#include <iostream>
#include <functional>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <vector>
#define ll long long
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n

#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define FOR(i,m,n) for(int (i)=(m);(i)<(n); i++)
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define WREP(i,in,j,jn) REP(i,in)REP(j,jn)
using namespace std;
//-------------------------------------------

int main(void){
	string S,T,U;
	int A,B;
	cin>>S>>T>>A>>B>>U;
	if(U==S)cout<<A-1<<" "<<B;
	else cout<<A<<" "<<B-1;
	return 0;
}


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

using namespace std;
#define int long long
#define pb push_back
#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define vin(vec) for(auto &elem:vec)cin>>elem
#define vi vector<int>
template<class L,class R> ostream& operator<<(ostream& cout,pair<L, R> P)
{return cout<<'('<<P.first<<','<< P.second<<')';}
template<class T> ostream& operator<<(ostream& cout,vector<T> V)
{cout<<"[ ";for(auto v:V)cout<<v<<' ';return cout<<']';}
#define show(x) cout<<#x<<" : "<<x<<'\n';


signed main(){
	fio;
	int t=1;
	// cin>>t;
	while(t--){
		int n, k;
		cin>>n>>k;
		vector<int> v(n, 0);
		vin(v);
		vector<int> dp(n, INT_MAX);
		dp[n-1]=0;
		// dp[n-2]=abs(v[n-1]-v[n-2]);
		for(int i=n-2; i>=0; i--){
			for(int j=1; j<=k; j++){
				if(i+j<n)
					dp[i]=min(dp[i+j] + abs(v[i]-v[i+j]), dp[i]);
			}
		}
		cout<<dp[0]<<'\n';
	}
}

Measured memory_bytes: 4764
import fractions
a,b,c,d=map(int, input().split())
ans = 0
f=fractions.gcd(c,d)
f2=c*d//f

bf = b//f2
af = (a-1)//f2

cb = b//c
ca = (a-1)//c

db = b//d
da = (a-1)//d

print(b-a+1-(cb-ca)-(db-da)+(bf-af))

Measured memory_bytes: 10584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool comp(vector<ll> v1, vector<ll>v2){
  return v1[1] < v2[1];
}
int main(){
  ll N; cin >> N ;
  ll A[N+1], B[N+1];
  for(ll i=1; i<=N; i++) {
    cin >> A[i] >> B[i] ;
  }

  vector<vector<ll>> temp;
  for(ll i=1; i<=N; i++) {
    temp.push_back({A[i],B[i]});
  }
  sort(temp.begin(), temp.end(), comp);
  ll tot=0;
  for(vector<ll> v:temp) {
    tot+= v[0];
    if(tot<=v[1]){continue;}else{cout << "No"; return 0;}
  }
  cout << "Yes";
  

}


Measured memory_bytes: 15660
#include <map>
#include <set>
#include <cmath>
#include <ctime> 
#include <queue>
#include <stack>
#include <bitset> 
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <iostream>
#include <algorithm>

#define fi first
#define se second
#define pb push_back
#define MP std::make_pair
#define PII std::pair<int, int>
#define all(x) (x).begin(), (x).end()
#define CL(a, b) memset(a, b, sizeof a)
#define rep(i, l, r) for (int i = (l); i <= (r); ++ i)
#define per(i, r, l) for (int i = (r); i >= (l); -- i)
#define PE(x, a) for (int x = head[a]; x;x = edge[x].next)

typedef long long ll;

template <class T>
inline void rd(T &x) {
    char c = getchar(), f = 0; x = 0;
    while (!isdigit(c)) f = (c == '-'), c = getchar();
    while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
    x = f ? -x : x;
}

#define int long long

signed main() {
    int a, b, x, y, t;
    rd(a), rd(x), rd(b), rd(y), rd(t);
    if (a == b) {
        puts("YES"); return 0;
    }
    if (x <= y) {
        puts("NO"); return 0;
    }
    int dis = abs(a - b);
    puts(dis <= (x - y) * t ? "YES" : "NO");
    return 0;
}

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

int main(){
  int n; cin >> n;
  vector<long long> a(n);
  long long l = 0;
  for(int i = 0; i < n; i++){
  	cin >> a[i];
  	l += a[i];
  }
  
  long long m = 2020202020;
  for(int i = 0; i < n; i++){
  	m = min(m, abs(l-2*a[i]));
  	if(i != n-1) a[i+1] += a[i];
  }
  cout << m << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
constexpr long INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;

struct UnionFind {
    vector<int> par, weight;
    UnionFind(int n) : par(n,-1), weight(n) {}
    void unite(int x, int y, int w = 0) {
        x = find(x); y = find(y);
        if (x == y) return;
        if (par[x] > par[y]) swap(x, y), w = -w;
        par[x] += par[y];
        par[y] = x;
        return;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int find(int x) {
        if(par[x] < 0) return x;
        int r = find(par[x]);
        return par[x] = r;
    }
    int sizeOf(int x) { return -par[find(x)]; }
};

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int n, q, c, x, y; cin >> n >> q;
    UnionFind uf(n);
    REP(i,q) {
        cin >> c >> x >> y;
        if(c) {
            if(uf.same(x, y)) cout << 1;
            else cout << 0;
            cout << endl;
        } else uf.unite(x, y);
    }

    return 0;
}



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

const long long INF = 1e18L + 5;
const int N = 405;
long long dp[N][N];

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

	int n;
	cin >> n;
	vector<int> all;
	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;
		all.push_back(x);
	}

	for (int l = n - 1; l >= 0; l--)
	{
		for (int r = l + 1; r < n; r++)
		{
			dp[l][r] = INF;
			long long cost = 0;
			for (int i = l; i <= r; i++)
				cost += (long long)all[i];
			for (int i = l; i < r; i++)
				dp[l][r] = min(dp[l][r], cost + dp[l][i] + dp[i + 1][r]);
		}
	}
	cout << dp[0][n - 1] << "\n";
}

Measured memory_bytes: 1536
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}

int main() {
	int n; cin >> n;
	int h[100100];
	for (int i = 0; i < n; ++i)cin >> h[i];
	bool ok = true;
	if (n == 1) {
		cout << "Yes" << endl;
		return 0;
	}
	for (int i = 1; i < n; ++i) {
		if (h[i] != h[i - 1]) {
			h[i] -= 1;
		}
	}
	for (int i = 1; i < n; ++i) {
		if (h[i] < h[i - 1]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
inline int Abs(int A) { return A<0?-A:A; }
int main(){
    int X,N;
    bool Alw[128];
    for(int i=0;i<=101;i++) Alw[i]=1;
    cin>>X>>N;
    for(int i=1;i<=N;i++){
        int Tmp;
        cin>>Tmp;
        Alw[Tmp]=0;
    }
    int Ans=0;
    for(int i=1;i<=101;i++)
        if(Alw[i]&&Abs(Ans-X)>Abs(i-X))
            Ans=i;
    cout<<Ans;
    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <limits>
#include <numeric>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <stack>

using namespace std;

#define INFint (1<<30)
#define BOUND 27182818284
#define MAT 2

typedef long long ll;
typedef long long int lli;
typedef pair<ll, ll> P;

ll MOD = 1000000007;
const ll INF = (1ll<<60);
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

int findGCD(vector<int> arr) {
    int result = arr[0];
    for (auto a: arr) {
        result = gcd(a, result);
    }
    return result;
}

template<typename T>
T lcm(T m, T n) {
    // 引数に0がある場合は0を返す
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    fill((T *) array, (T *) (array + N), val);
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

struct UnionFind {
    int n, cnt;
    vector<ll> par, rank, sz;

    UnionFind(ll n) : n(n), cnt(n), par(n), rank(n), sz(n, 1) { iota(par.begin(), par.end(), 0); }

    ll find(ll x) {
        if (x == par[x]) return x;
        return par[x] = find(par[x]);
    }

    bool same(ll x, ll y) { return find(x) == find(y); }

    ll size(ll x) { return sz[find(x)]; }

    void unite(ll x, ll y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
            sz[y] += sz[x];
        } else {
            par[y] = x;
            sz[x] += sz[y];
            if (rank[x] == rank[y]) {
                rank[x]++;
            }
        }
        cnt--;
    }
};

int main() {
    int N,M,A,B,C; cin >> N;
    int ans=0;

    cout << N*N << endl;
    return 0;
}

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

#define REP(i, s, n) for(int i = s; i < n; ++i)
#define rep(i, n)		 REP(i, 0, n)
#define SORT(c)			 sort((c).begin(), (c).end())
#define IINF	INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long				ll;
typedef pair <int, int> ii;

/*
struct point{
	ll x;
	ll y;
	point(){x = 0;y = 0;}
	point(ll x, ll y):x(x), y(y){}
};
*/


int main() {

	int sx, sy, tx, ty;
	cin >>sx>> sy>> tx >>ty;
	
	rep(i, ty - sy) cout << 'U';
	rep(i, tx - sx) cout << 'R';
	rep(i, ty - sy) cout << 'D';
	rep(i, tx - sx) cout << 'L';
	cout << 'L';
	rep(i, ty - sy + 1) cout << 'U';
	rep(i, tx - sx + 1) cout << 'R';
	cout << "DR";
	rep(i, ty - sy + 1) cout << 'D';
	rep(i, tx - sx + 1) cout << 'L';
	cout << 'U' <<endl;
	return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
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; }

lli sum[200100];
int main(){

	lli n;
	cin>>n;

	REP(i,0,n-1){
		lli a;
		cin>>a;
		a--;
		sum[a]++;
	}

	REP(i,0,n)cout<<sum[i]<<endl;

    return 0;
}


Measured memory_bytes: 5152
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<endl
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  srand((unsigned)time(NULL));
  int T;
  R T;
  ll n=26;
  ll c[n];
  rep(i,n) R c[i];
  ll a[T][n];
  rep(i,T)rep(j,n) R a[i][j];
  ll d[n];
  mem(d);
  ll ans=0;
  rep(k,T) {
    ll x;
    R x;
    x--;
    ans+=a[k][x];
    rep(i,n) d[i]-=c[i];
    d[x]=0;
    rep(i,n) ans+=d[i];
    pr(ans);
  }
}

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


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long LL;
typedef unsigned long long ULL;
const LL LINF = 0x3f3f3f3f3f3f3f3f; 
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1e9+7;
const ULL P = 131;
const int N = 2e5+7;

int a[N];
map<int,int> mp;

int main()
{
	int n,k;
	cin>>n;
	LL ans=0;
	for(int i=1;i<=n;i++){
		cin>>k;
		int t = k - i;
		t = -t;
		//cout<<t<<endl;
		if(mp[t]!=0) ans+=(LL)mp[t];
		mp[k+i]++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 20588
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*

*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  ll N,M; cin>>N>>M;
  if(M==0){
    if (N==1)
      cout<<0<<endl;
    if (N==2)
      cout<<10<<endl;
    if (N==3)
      cout<<100<<endl;
    return 0;
  }
  vector<pair<ll,ll>> Z(M,{0,0});
  rep(i, M){
    ll s,c; cin>>s>>c;
    Z[i]={N-s,c};
  }
  ll end=1;
  ll low = 1;
  rep(i,N) end *= 10;
  low = end/10;
  if (low < 10) low = 0;
  for(ll i=low; i<=end; i++){
    ll a,b,c;
    a = i/100;
    b = (i/10)%10;
    c = i%10;
    rep(j,M){
      ll z1=Z[j].first, z2=Z[j].second;
      if (z1 == 0 && c != z2)
        break;
      if (z1 == 1 && b != z2)
        break;
      if (z1 == 2 && a != z2)
        break;
      if (j==M-1){
        cout <<i <<endl;
        return 0;
      }
    }
  }
  cout <<-1 <<endl;
}


Measured memory_bytes: 3640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;


int h, w, n;
vector<PI> ptv;
set<PI> pts;
set<PI> nbr;
int main(void){
  cin >> h >> w >> n;
  REP(i, 0, n) {
    int a, b;
    cin >> a >> b;
    ptv.push_back(PI(a, b));
    pts.insert(PI(a, b));
  }
  ll a[10] = {0};
  REP(i, 0, ptv.size()) {
    PI cur = ptv[i];
    int cnt = 0;
    REP(dx, -1, 2) {
      REP(dy, -1, 2) {
	PI t(cur.first + dx, cur.second + dy);
	if (t.first >= 2 && t.first <= h - 1 && t.second >= 2 && t.second <= w - 1) {
	  nbr.insert(t);
	}
      }
    }
  }
  for (set<PI>::iterator it = nbr.begin(); it != nbr.end(); ++it) {
    PI cur = *it;
    int cnt = 0;
    REP(dx, -1, 2) {
      REP(dy, -1, 2) {
	PI t(cur.first + dx, cur.second + dy);
	if (pts.count(t)) {
	  cnt++;
	}
      }
    }
    assert (cnt >= 1 && cnt <= 9);
    a[cnt]++;
  }
  a[0] = (ll)(h - 2) * (w - 2);
  REP(i, 1, 10) {
    a[0] -= a[i];
  }
  REP(i, 0, 10) {
    cout << a[i] << endl;
  }
}


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

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N=sc.nextInt();
        boolean[] A=new boolean[N];
        Arrays.fill(A, false);
        int M=sc.nextInt();
        int X=sc.nextInt();
        X--;
        for(int i=0;i<M;i++){
            int a=sc.nextInt();
            a--;
            A[a]=true;
        }
        int ans=0;
        for(int i=X;i<N;i++){
            if(A[i]==true)ans++;
        }
        int answer=0;
        for(int i=X;i>=0;i--){
            if(A[i]==true)answer++;
        }
        System.out.println(Math.min(ans, answer));
    }
}

Measured memory_bytes: 21588
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#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=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

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

    set<string> st;
    char prev_tail;
    REP(i, n) {
        string s;
        cin >> s;
        if (i == 0) {
            prev_tail = s[s.size()-1];
            st.insert(s);
            continue;
        }

        if (st.find(s) != st.end()) {
            cout << "No" << endl;
            return 0;
        } else if (prev_tail != s[0]) {
            cout << "No" << endl;
            return 0;
        }
        prev_tail = s[s.size()-1];
        st.insert(s);
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main()
{
    int a, b;

    cin >> a >> b;

    if( a >= b )
        cout << 1 << endl;
    else
    {
        if( b % a == 0 )
            cout << b / a << endl;
        else
            cout << b / a + 1 << endl;
    }

    return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define FU(i, l, r) for (register int i = (l), _end_ = (int)(r); i <= _end_; ++ i)
#define FD(i, r, l) for (register int i = (r), _end_ = (int)(l); i >= _end_; -- i)
#define X first
#define Y second
#define Set(a, b) memset(a, b, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define SZ(a) ((int)(a).size())
#define lowbit(x) x & (-x)
#define pii pair<int, int>
#define LL long long
#define INF 0x3f3f3f3f
#define file(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout);
using namespace std;

template <typename T> inline bool chkmax(T &a, T b) {return (a < b) ? a = b, 1 : 0;}
template <typename T> inline bool chkmin(T &a, T b) {return (b < a) ? a = b, 1 : 0;}

template <typename T> inline T read() {
    static T  __; static char c_; static bool flag_;
    __ = 0; c_ = getchar(); flag_ = false;
    while (c_ > '9' || c_ < '0') {flag_ |= c_ == '-';  c_ = getchar();}
    while (c_ >= '0' && c_ <= '9') {__ = (__ << 1) + (__ << 3) + (c_ ^ 48); c_ = getchar();}
    return flag_ ? -__ : __;
}

template <typename T> inline T write(T a) {
        if (a < 0) {putchar('-'); a = -a;}
        if (a > 9) write(a / 10);
        putchar(a % 10 + '0');
	return 0;
}

const int maxN = 40 + 4;

int n, m, sum[maxN][maxN], dx, dy, ans, dp[maxN][maxN][maxN][maxN], vis[maxN][maxN][maxN][maxN];
char tmp;

inline int getsum(int x, int y, int u, int v)
{
    if (x > u || y > v)
        return 0;
    return sum[u][v] - sum[x-1][v] - sum[u][y-1] + sum[x-1][y-1];
}

inline void Input()
{
	ios::sync_with_stdio(false);
    cin >> n >> m;
    for (register int i = 1; i <= n; ++ i)
    {
        for (register int j = 1; j <= m; ++ j)
        {
            cin >> tmp;
            sum[i][j] += sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + (tmp == '#');
            if (tmp == 'P')
                dx = i, dy = j;
        }
    }
	return;
}

int DFS(int lx, int ly, int rx, int ry)
{
	if (! chkmax(vis[lx][ly][rx][ry], 1))
		return dp[lx][ly][rx][ry];
	
	int &ans = dp[lx][ly][rx][ry] = INF;
	chkmin(ans, getsum(lx,ly,dx,dy));
	chkmin(ans, getsum(lx,dy,dx,ry));
	chkmin(ans, getsum(dx,ly,rx,dy));
	chkmin(ans, getsum(dx,dy,rx,ry));
	
    FU(i, lx + 1, dx) FU(j, ly + 1, dy) 
        chkmin(ans, DFS(i, j, rx, ry) + getsum(i, ly, rx, j - 1) + getsum(lx, j, i - 1, ry));
    FU(i, dx, rx - 1) FU(j, dy, ry - 1) 
        chkmin(ans, DFS(lx, ly, i, j) + getsum(i + 1, ly, rx, j) + getsum(lx, j + 1, i, ry));
    FU(i, dx, rx - 1) FU(j, ly + 1, dy) 
        chkmin(ans, DFS(lx, j, i, ry) + getsum(lx, ly, i, j - 1) + getsum(i + 1, j, rx, ry));
    FU(i, lx + 1, dx) FU(j, dy, ry - 1) 
        chkmin(ans, DFS(i, ly, rx, j) + getsum(lx, ly, i - 1, j) + getsum(i, j + 1, rx, ry));
	
	return ans;
}

int main()
{
	Input();
	write(DFS(1,1,n,m));
	putchar('\n');
    return 0;
}


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

using namespace std;
using LL = long long;
const int N = 1024;
const int INF = 1E9;
const double EPS = 1E-9;

int a[N];
int n, m;

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

#ifdef CF_DEBUG
    freopen("../cf/input.txt","r",stdin);
#endif
    LL n,k;
    cin>>n>>k;
    cout<<min(n%k,k-n%k);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define  rep(i,n) for(li i=0;i<(n);i++)
using namespace std;
typedef vector<int> vi;
typedef long int li;
typedef unsigned long long ull;


int main(int argc,char* argv[])
{
    li N,K;
    cin>>N>>K;
    cout<<(li)pow(K-1,N-1)*K<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  int cand = a+b;
  cand = max(cand,a-b);
  cand = max(cand,a*b);
  cout << cand << endl;
  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
long long INF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
    vector<pair<int,int>> prime;
    int n,a=2;
    long long ans=1;
    scanf("%d",&n);

    while(a<=n){
        int k=a;
        for(int i=0;k!=1&&i<prime.size();){
            if(k%prime[i].first){
                ++i;
                continue;
            }else{
                if(prime[i].first==0) printf("#%d!\n",i);
                k/=prime[i].first;
                ++prime[i].second;
            }
        }
        if(k!=1) prime.push_back(make_pair(k,1));
        ++a;
    }

    REP(i,prime.size()) ans = ans*(prime[i].second+1)%MOD;

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


Measured memory_bytes: 256
#include<iostream>
#include<string>
//SUN,MON,TUE,WED,THU,FRI,SAT
using namespace std;
int main(){
  string s;cin >> s;
  if(s == "SUN") cout << 7 << endl;
  else if (s=="MON") cout << 6 << endl;
  else if (s=="TUE") cout << 5 << endl;
  else if (s=="WED") cout << 4 << endl;
  else if (s=="THU") cout << 3 << endl;
  else if (s=="FRI") cout << 2 << endl;
  else cout << 1 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <string>

using namespace std;

#define LL long long

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

LL mod(LL x, LL md) {
	return ((x % md) + md) % md;
}

class Mint {
public:
	static LL md;
	LL x;
	Mint(LL _x) {
		x = mod(_x, md);
	}
	Mint(const Mint &y) {
		x = mod(y.x, md);
	}
};

void MintMyExgcd(LL a, LL b, LL &x, LL &y) {
	// solve equation ax + by = 1 (mod m)
	LL md = Mint::md;
	if (b == 0) {
		y = 0;
		x = 1;
		return ;
	}
	MintMyExgcd(b, a % b, x, y);
	LL t = y;
	y = mod(x - (a / b) * y, md);
	x = t;
}

LL MintNY(LL x) {
	if (x == 0) {
		return 1;
	}
	LL md = Mint::md;
	LL a, b;
	MintMyExgcd(x, md, a, b);
	while (a < 0) {
		a += md;
	}
	return a;
}

/* LL gcd(LL a, LL b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
} */

Mint operator+(Mint a, Mint b) {
	return Mint(mod(a.x + b.x, Mint::md));
}
Mint operator-(Mint a, Mint b) {
	return Mint(mod(a.x - b.x, Mint::md));
}
Mint operator*(Mint a, Mint b) {
	return Mint(mod(a.x * b.x, Mint::md));
}
Mint operator/(Mint a, Mint b) {
	Mint c = Mint(MintNY(b.x));
	return Mint(mod(a.x * c.x, Mint::md));
}

Mint operator-(Mint a) {
	return Mint(-a.x);
}
bool operator==(Mint a, Mint b) {
	return a.x == b.x;
}
bool operator!=(Mint a, Mint b) {
	return a.x != b.x;
}
bool operator>(Mint a, Mint b) {
	return a.x > b.x;
}
bool operator<(Mint a, Mint b) {
	return a.x < b.x;
}
bool operator>=(Mint a, Mint b) {
	return a.x >= b.x;
}
bool operator<=(Mint a, Mint b) {
	return a.x <= b.x;
}

void operator+=(Mint &a, Mint b) {
	a = a + b;
}
void operator-=(Mint &a, Mint b) {
	a = a - b;
}
void operator*=(Mint &a, Mint b) {
	a = a * b;
}
void operator/=(Mint &a, Mint b) {
	a = a / b;
}

ostream& operator<<(ostream &out, Mint a) {
	out << a.x;
	return out;
}

istream& operator>>(istream &in, Mint &a) {
	in >> a.x;
	return in;
}

Mint factorial(LL n) {
	if (n == 0) {
		return Mint(1);
	}
	Mint res = 1;
	for (LL i = 1; i <= n; ++i) {
		res *= i;
	}
	return res;
}
Mint multiRange(LL s, LL t) {
	Mint res = 1;
	for (LL i = s; i <= t; ++i) {
		res *= i;
	}
	return res;
}

Mint getC(LL n, LL k) {
	if (n - k < k) {
		return getC(n, n - k);
	}
	return multiRange(n - k + 1, n) / factorial(k);
}

Mint getA(LL n, LL k) {
	return multiRange(n - k + 1, n);
}

Mint countNonNegativeDivision(LL n, LL k) {
	return getC(n + k - 1, k - 1);
}
Mint countPositiveDivision(LL n, LL k) {
	if (n < k) {
		return 0;
	}
	if (k <= 0) {
		return 0;
	}
	return getC(n - 1, k - 1);
}
Mint quickMod(Mint a, LL b) {
	Mint res = 1;
	while (b > 0) {
		if (b % 2) {
			res *= a;
		}
		a *= a;
		b /= 2;
	}
	return res;
}

LL Mint::md = 1000000007;

int n;

int main() {
	LL res = 0;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		if ((i % 3) && (i % 5)) {
			res += (LL)(i);
		}
	}
	cout << res << endl;
	return 0;
}

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

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

  string s;
  cin >> s;

  for (int i = 0; i < s.length(); ++i) cout << 'x';
  cout << '\n';

  return (0);
}


Measured memory_bytes: 3648
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class A
{
	public static void Main()
	{
		string[] args = Console.ReadLine().Split(' ');
		int A = Int32.Parse(args[0]);
		int B = Int32.Parse(args[1]);
		int C = Int32.Parse(args[2]);
		
		bool ans = false;
		if(A < B)
		{
			ans = ((A < C) && (C < B)) ? true : false;
		}
		else
		{
			ans = ((A > C) && (C > B)) ? true : false;			
		}		
		Console.WriteLine(ans ? "Yes" : "No");
	}	
}





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

int main(){
  string s;
  cin >> s;
  int size = 0;
  vector<int> t(s.size(),2);
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '0'){
      t[size] = 0;
      size++;
    }
    else if(s[i] == '1'){
      t[size] = 1;
      size++;
    }
    else {
      if(size >= 1){
      t[size-1] = 2;
      size--;
      }
    }
  }
  for(int i = 0; i < size;i++){
    cout << t[i];
  }
}


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

 using namespace std;

int main () 
{
  int n;
  cin>>n;
  bool a[3]={false};
  int count=0;
  int i=0;
  int flag=0;
  while(n--)
  {
    int a,b;
    cin>>a>>b;
   
   i++;
    if(a==b )
    {
      count++;
    }
    
    
    if(count!=i)
    {
      i=0;
      count=0;
     
    }
    if(count==i && count==3)
    {
      flag=1;
    }
    
  }

  if(flag==1)
    cout<<"Yes";
  else
    cout<<"No";
return 0;

 
}




Measured memory_bytes: 3632
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 1000010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

string s;
int n, dp[MAXN][2];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> s;
    n = SZ(s);
    dp[n][0] = 0;
    dp[n][1] = 1000000000;
    FORE(i,n-1,0) {
        dp[i][0] = dp[i][1] = 1000000000;
        FOR(j,0,1) {
            int x = s[i] - '0' + j;
            FOR(k,0,9) {
                if (k >= x) dp[i][0] = min(dp[i][0], dp[i+1][j] + 2*k - x);
                else dp[i][1] = min(dp[i][1], dp[i+1][j] + 10 + 2*k - x);
            }
        }
    }
    cout << min(dp[0][0], dp[0][1] + 1);
    return 0;
}


Measured memory_bytes: 9116
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;

namespace AOJ
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var Ti = Sarray();
            var Q = Sarray()[0];
            var Si = Sarray();
            var Sh = new HashSet<long>();
            for (var i = 0; i < Q; ++i)
            { Sh.Add(Si[i]); }
            var Th = new HashSet<long>();
            for (var i = 0; i < N;++i)
            { Th.Add(Ti[i]); }
            var cnt = 0;
            foreach (var si in Sh)
            {
                if (Ti.Contains(si)) ++cnt;
            }
            WriteLine(cnt);
        }
    }
}



Measured memory_bytes: 19196
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		long max = 0;
		
		long[]h = new long[n];
		
		for(int i = 0; i < n; i++) {
			h[i] = stdIn.nextLong();
		}
		
		boolean flag = false;
		
		for(int i = 0; i < n-1; i++) {
			max = Math.max(max, h[i]);
			
			if(h[i] > h[i+1]) {
				if(h[i]-1 > h[i+1] || h[i]-1 != max - 1) {
					flag = true;
				}
			}
		}
		
		if(flag) {
			System.out.println("No");
		}else {
			System.out.println("Yes");
		}
		
				
	}

}


Measured memory_bytes: 49892
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;



int main(){
	

	string str1,str;
	int I=0;int map[17][17]={};
	while(cin>>str){
		int K=0;
		for(int j=1;j<13;j++){
			if(str[j-1]-'0'==1){K++;map[1][j]=K;}
			else map[1][j]=0;
		}

	for(int i=2;i<=12;i++)
	{cin>>str;
	for(int j=1;j<13;j++)
		if(str[j-1]-'0'==1){K++;map[i][j]=K;}
		else map[i][j]=0;
	}

	

	for(int i=1;i<=12;i++)
	for(int j=1;j<=12;j++){
		if(map[i][j]>0){int q=map[i][j];
	if(map[i+1][j]<q&&map[i+1][j]>0)q=map[i+1][j];
	if(map[i-1][j]<q&&map[i-1][j]>0)q=map[i-1][j];
	if(map[i][j+1]<q&&map[i][j+1]>0)q=map[i][j+1];
	if(map[i][j-1]<q&&map[i][j-1]>0)q=map[i][j-1];
	int R[]={map[i][j],map[i+1][j],map[i-1][j],map[i][j+1],map[i][j-1]};
	for(int ii=1;ii<=12;ii++)
	for(int jj=1;jj<=12;jj++)
		for(int gg=0;gg<5;gg++)
			if(map[ii][jj]==R[gg]&&map[ii][jj]>0)map[ii][jj]=q;

	}
	}
	bool F[155]={};

	

for(int i=0;i<=12;i++)
	for(int j=0;j<=12;j++)
		if(map[i][j]>0)F[map[i][j]]=true;

int C=0;
for(int i=1;i<=150;i++)
	if(F[i]==true)C++;

cout<<C<<endl;
	}
	return 0;
}

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

using namespace std;

#define int long long
#define MP make_pair
#define F first
#define S second
#define pi pair<int,int> 
#define sz(s) ((int)s.size())

const unsigned mod = 1e9 + 7;
const unsigned N = 5e5 + 4;

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

  int k, n;
  cin >> k >> n;
  vector<int> v(n);
  for (int &x: v) {
    cin >> x;
  }
  int x = 0;
  vector<int> ans;
  for (int i = 1; i < n; ++i) ans.push_back(v[i] - v[i-1]);
  ans.push_back(k-v[n-1]+v[0]);
  sort(ans.begin(), ans.end());
  for (int i = 0; i + 1 < ans.size(); ++i)
    x += ans[i];

  cout << x << '\n';
  
  return 0;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int INF=INT_MAX,MOD=1e9+7;

bool is_prime(int n){
    if(n<2) return 0; //素数は2以上
	if(n==2 || n==3) return 1; //2,3は素数
    if(n%2==0 || n%3==0) return 0; //2,3の倍数を消去
    //以降素数は6k±1にしかない
    if(n%6!=1 && n%6!=5) return 0;
    for(int i=5;i*i<=n;i+=6){
        if(n%i==0) return 0; //6k-1
        if(n%(i+2)==0) return 0; //6k+1
    }
    return 1;
}

int main(){
    int n; cin>>n;
    int cnt=0;
    rep(i,n){
        int x; cin>>x;
        if(is_prime(x)) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 3068