akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

int main(int argc, char* argv[])
{
    int n;
    scanf("%ld", &n);
    vector<int> a(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
        a[i]-=(i+1);
    }
    sort(a.begin(), a.end());
    int m = a[(n-1)/2];
    ll sum=0;
    for(i=0; i<n; i++) {
        sum += abs(a[i]-m);
    }
    printf("%lld\n", sum);
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};


signed main(void) {
	int N, K,L;
	cin >> N >> K>>L;
	UnionFind road(N);
	UnionFind train(N);
	int p, q;
	rep(i, K) {
		cin >> p >> q;
		p--;
		q--;
		road.unite(p, q);
	}
	rep(i, L) {
		cin >> p >> q;
		p--;
		q--;
		train.unite(p, q);
	}

	map<pair<int, int>, int> count;

	rep(i, N)
	{
		count[make_pair(road.root(i), train.root(i))]++;
	}

	rep(i, N) cout << count[make_pair(road.root(i), train.root(i))] << ' ';
	cout << endl;
}


Measured memory_bytes: 15104
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
    long long  n,a,b;
    cin>>n>>a>>b;
    if(n==1&&a!=b)
    {
        cout<<0<<endl;
    }
    else if(a>b)
    {
        cout<<0<<endl;
    }
    else if(a==b)
    {
        cout<<1<<endl;
    }
    else if(n>1&&a<b)
    {
        cout<<(b-a)*(n-2)+1<<endl;
    }
    else
        cout<<0<<endl;
    return 0;
}


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

using namespace std;

int main(){

	int a, b, c, d, ans;
	cin >> a >> b >> c >> d;

	ans = min(b,d)-max(a,c);
	if( ans >= 0 ) {
		cout << ans << endl;
	}
	else{
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
fun main() {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map { it.toInt() }
    var ans = 0
    for(i in 0 until N){
        if(i % 2 == 0 && A[i] % 2 == 1) ans++
    }
    println(ans)
}

Measured memory_bytes: 36324
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1073741824
#pragma GCC optimization ("O3")
using namespace std;
const int N = 100*1000+5;
#define all(x) begin(x),end(x)
int main()
{
   
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    int n,m;
    cin >> n >> m;
    if(n*500 >= m)
    	cout << "Yes";
    else
    	cout << "No";
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main{

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine());
		
		for (int j = 0; j < N; j++) {
			String[] arr = br.readLine().split(" ");
			
			int[] lens = new int[3];
			for (int i = 0; i < 3; i++) {
				lens[i] = Integer.parseInt(arr[i]);
			}
			
			Arrays.sort(lens);
			
			if (lens[2] * lens[2] == lens[0] * lens[0] + lens[1] * lens[1]) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}			
		}

	}

}

Measured memory_bytes: 26280
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner num = new Scanner(System.in);
        int H = 0;
        int W = 0;

        while((H = num.nextInt()) != 0 && (W = num.nextInt()) != 0){
            for(int i = 0; i < H; i++) {
                for(int j = 0; j < W; j++) {
                    if(i != 0 && i != H - 1 && j != 0 && j != W - 1) {
                        System.out.print(".");
                    } else {
                        System.out.print("#");
                    }
                }
                System.out.print("\n");
            }
            System.out.print("\n");
        }
    }
}


Measured memory_bytes: 36576
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
double S(double a, double b, double c){
  double s = (a + b + c) / 2;
  return sqrt(s * (s - a) * (s - b) * (s - c));
}

int main(){
  double a, l, x;
  while(cin>>a>>l>>x){
    double ans = S(a, l, l) + 2 * S(l, (l + x) / 2, (l + x) / 2);
    printf("%.8f\n", ans);
  }
  return 0;
}

Measured memory_bytes: 1240
import sys
input = sys.stdin.readline
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        if i == 0:
            return 0
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
aas = "abcdefghijklmnopqrstuvwxyz"
N = int(input().strip())
S = [" "]+list(input().strip())
Q = int(input().strip())
cbt = dict()
for c in aas:
    cbt[c] = Bit(N)
    for i, a in enumerate(S):
        if i == 0:
            continue
        if a == c:
            cbt[c].add(i, 1)

for _ in range(Q):
    t, i, c = input().split()
    t = int(t)
    if t == 1:
        i = int(i)
        if S[i] != c:
            cbt[S[i]].add(i, -1)
            cbt[c].add(i, 1)
            S[i] = c
    else:
        l, r = int(i), int(c)
        s = 0
        for a in aas:
            bt = cbt[a]
            s += (bt.sum(r)-bt.sum(l-1)>0)
        print(s)


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

int a, b, k, val;
int gcd(int a, int b){
	if(b==0) return a;

	return gcd(b, a%b);
}
int main(){
	scanf("%d %d %d", &a, &b, &k);
	val = gcd(a,b);
	for(int i = val; i >= 1; i--){
		if(a%i==0 && b%i==0) k--;
		if(k==0){
			printf("%d\n", i);
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <iomanip>
#include <set>
#include <sstream>
#include <cmath>
#include <deque>
#include <bitset>
using namespace  std;
typedef pair<string, int> Psi;
typedef pair<long long , long long> P;
typedef long long int64;
#define REP(i, n) for(int (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(int (i)=0; (i)<(a); ++i)
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define FST first
#define SND second
int A, B, C, N;
int L[10];
long long rec(int idx, long long a, long long b, long long c){
    if(idx == N){
        if(!a or !b or !c) return 1LL<<31;
        return abs(A-a)+abs(B-b)+abs(C-c);
    }
    int64 recA = rec(idx+1, a+L[idx], b, c);
    int64 recB = rec(idx+1, a, b+L[idx], c);
    int64 recC = rec(idx+1, a, b, c+L[idx]);
    int64 rec0 = rec(idx+1, a, b, c);
    if(a) recA+=10;
    if(b) recB+=10;
    if(c) recC+=10;
    return min(min(recA, recB), min(recC, rec0));
}
int main(){
    cin >> N >> A >> B >> C;
    REP(i, N) cin >> L[i];
    cout << rec(0, 0, 0, 0) << endl;
    return 0;
}

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

string T,P;
int FE[10005];

void FuncionError();
void Aparece();

int main(){
	cin>>T;
	cin>>P;
	FuncionError();
	Aparece();
	return 0;
}
void FuncionError(){
	FE[0]=-1;
	for(int i=0;i<P.size();){
		int pos = FE[i];
		while(pos>=0 && (P[pos]!=P[i])){
			pos = FE[pos];
		}
		FE[++i] = ++pos;
	}
}
void Aparece(){
	int pos = 0;
	//cout<<T.size()<<"\n";
	for(int i = 0;i<T.size();i++){
		while(pos>=0 && (T[i]!=P[pos])){
			pos = FE[pos];
		}
		pos++;
		if(pos==P.size()){
			cout<<i-P.size()+1<<"\n";
			pos = FE[pos];
		}	
	}
}



Measured memory_bytes: 4000
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 100010
using namespace std;
typedef long long ll;
int n;
ll a[maxn];
ll b[maxn];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)  scanf("%lld",&a[i]);
	for(int i=1;i<=n+1;i++)  b[i]=abs(a[i]-a[i-1]);
	ll sum=0;
	for(int i=1;i<=n+1;i++)  sum+=b[i];
	for(int i=1;i<=n;i++)
	{
		ll ans=sum;
		ans-=b[i]+b[i+1];
		ans+=abs(a[i+1]-a[i-1]);
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i[] = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<int>;
using vec2 = vector<vector<int>>;

int main(){
  int a;cin >> a;
  cout << a + a*a + a*a*a;
}


Measured memory_bytes: 3616
k, a, b = [int(x) for x in input().split()]

if b - a > 1 and a < k:
    bk = b + ((k - (a + 1)) // 2) * (b - a) + (k - (a + 1)) % 2
else:
    bk = k + 1
    
print(bk)

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

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

  for (int i = N; i <= 999; i++)
  {
    int buf = i;
    int a = buf % 10;
    buf /= 10;
    int b = buf % 10;
    buf /= 10;
    int c = buf % 10;
    if (a == b && b == c)
    {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3640
import Foundation

let arr=readLine()!.characters.split{$0==" "}.map{Int(String($0))!}
let a=arr[0]
let b=arr[1]
var c=0
if a > 1 {
  for i in 0..<a {
    c+=i
}
}
if b > 1 {
    for i in 0..<b {
    c+=i
}
}
 
print(c)

Measured memory_bytes: 6888
t = gets.to_s.to_i

t.times do

  n = gets.to_s.to_i
  a = gets.to_s.split.map{|t| t.to_i }
  s = gets.to_s.chomp
  
  f = false
  bases = []
  (0...n).reverse_each do |i|
    bases.each do |base|
      a[i] = a[i] ^ base if a[i] > a[i] ^ base
    end
    if a[i] != 0
      if s[i] == '0'
        bases.push a[i]
      else
        f =  true
        break
      end
    end
  end
  
  puts f ? 1 : 0
end

Measured memory_bytes: 14648
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.buffer.readline

n, m, q = [int(i) for i in input().strip().split()]
abcd = []
canditates = []
ans = 0


for _ in range(q):
    abcd.append([int(i) for i in input().strip().split()])


def helper(_min, _max, cur, res):
    if res == 0:
        canditates.append(list(cur))
    else:
        for i in range(_min, _max):
            cur.append(i)
            helper(i, _max, cur, res - 1)
            cur.pop()


helper(1, m + 1, [], n)

for A in canditates:
    _temp = 0
    for a, b, c, d in abcd:
        if A[b - 1] - A[a - 1] == c:
            _temp += d

    ans = max(ans, _temp)

print(ans)


Measured memory_bytes: 23028
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), cout, ", ") << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, ostream &os = cout, string sep = " ")
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), os, ", ") << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    A2IN(ll, X, ll, L, N);
    vii A(N);
    REP(i, N)
    {
        A[i] = ii(X[i] + L[i], X[i] - L[i]);
    }
    SORT(A);
    ll ans = 0;
    ll r = -INF;
    REP(i, N)
    {
        if (r <= A[i].second)
        {
            ++ans;
            r = A[i].first;
        }
    }
    OUT(ans);
}

Measured memory_bytes: 3328
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]



    print(a*b)


resolve()

Measured memory_bytes: 61628
import java.util.*;
import static java.lang.System.out;
import static java.lang.Math.*;

class Main{
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    while(scan.hasNext()){
      double x[] = new double[4];
      double y[] = new double[4];
      for(int i=0;i<4;i++){
        x[i] = scan.nextDouble();
        y[i] = scan.nextDouble();
      }
      double a = (x[0] - x[1]) * (x[2] - x[3]);
      double b = (y[0] - y[1]) * (y[2] - y[3]);
      if((float)a + (float)b == 0) out.println("YES");
      else out.println("NO");
    }
  }
}

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

typedef long long ll;
using namespace std;

int main()
{
    int n, k;
    ll t[2] = {};
    cin >> n >> k;
    for (int i = 1; i <= n; i++){
        if (i % k == 0){
            t[0]++; //kが約数
        }
        if(k % 2 == 0 && i % k == k / 2){
            t[1]++;
        }
    }

    ll ans = t[0] * t[0] * t[0] + t[1] * t[1] * t[1];

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
 * You Siki
 * Born to be King!
 */

#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>

//using namespace std;

const int LIMIT = 10000000;

char in[LIMIT], *p = in;

__inline int nextInt(void) {

    register int res = 0;
    register bool neg = false;

    while (*p < '0' || *p > '9')
        if (*p++ == '-')neg ^= 1;

    while (*p >= '0' && *p <= '9')
        res = res * 10 + *p++ - '0';

    return neg ? -res : res;

}

const int N = 500005; 

struct Point {
	
	int x, y, id;
	
	Point(void){};
	Point(int a, int b, int c):x(a), y(b), id(c){};
	
}; 

int cmpX(const void *a, const void *b) {
	
	Point *pa = (Point *)a;
	Point *pb = (Point *)b;
	
	return pa->x - pb->x; 
	
}

int cmpY(const void *a, const void *b) {
	
	Point *pa = (Point *)a;
	Point *pb = (Point *)b;
	
	return pa->y - pb->y; 
	
}

bool cmpx(Point a, Point b) {
	return a.x < b.x;
}

bool cmpy(Point a, Point b) {
	return a.y < b.y;
}

int cmpInt(const void *a, const void *b) {
	
	int *x = (int *)a;
	int *y = (int *)b;
	
	return *x - *y;
	
}

signed main(void) {

	fread(p, 1, LIMIT, stdin);
	
	int n = nextInt();
	
	Point *X = new Point[n];
	Point *Y = new Point[n];
	
	for (register int i = 0; i < n; ++i) {
		X[i].id = Y[i].id = i;
		X[i].x = Y[i].x = nextInt();
		X[i].y = Y[i].y = nextInt();
	}
	
	qsort(X, n, sizeof(Point), cmpX);
	qsort(Y, n, sizeof(Point), cmpY);
	
	int q = nextInt();
	
	for (register int i = 0; i < q; ++i) {
		
		int sx = nextInt();
		int tx = nextInt();
		int sy = nextInt();
		int ty = nextInt();
		
		int lx = std::lower_bound(X, X + n, Point(sx, 0, 0), cmpx) - X;
		int rx = std::upper_bound(X, X + n, Point(tx, 0, 0), cmpx) - X;
		
		int ly = std::lower_bound(Y, Y + n, Point(0, sy, 0), cmpy) - Y;
		int ry = std::upper_bound(Y, Y + n, Point(0, ty, 0), cmpy) - Y;
		
		int *ans = new int[n], tot = 0;
		
		if (rx - lx < ry - ly) {
			for (register int i = lx; i < rx; ++i)
				if (X[i].y >= sy && X[i].y <= ty)
					ans[tot++] = X[i].id;
		}
		else {
			for (register int i = ly; i < ry; ++i)
				if (Y[i].x >= sx && Y[i].x <= tx)
					ans[tot++] = Y[i].id;
		}
		
		qsort(ans, tot, sizeof(int), cmpInt);
		
		for (register int i = 0; i < tot; ++i)
			printf("%d\n", ans[i]);
		putchar('\n');
		
		delete(ans);
		
	}

}

Measured memory_bytes: 26852
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <math.h>
#include <deque>
#include <stack>

using namespace std;

typedef long long ll;

int main(void){
  ll n;
  cin >> n;
  ll sum = n * (n + 1) / 2;
  cout << sum - n << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


const int MAX = 1110000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void comb_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long comb(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll mod_pow(ll x, ll n, ll mod){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    if(n > k) cout << 0 << endl;
    else cout << 1 << endl;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,b;
    cin >> a >> b;
    int coin=0;
    for (int i=0; i<2; i++) {
        if (a>b){
            coin = coin+a;
            a = a-1;
        }
        else {
            coin = coin+b;
            b = b-1;
        }
    }
    cout << coin << endl;
}

Measured memory_bytes: 256
//
//  main.cpp
//  AOJ_V0_0001
//
//  Created by anzai on 2015/08/06.
//  Copyright (c) 2015??´ anzai. All rights reserved.
//

#include<iostream>
using namespace std;

int main(){
    
    int array[10] = {0};
    
    for (int i = 0; i < 10; i++) {
        cin >> array[i];
        
    }
    int first = 0;
    int second = 0;
    int third = 0;
    for (int i = 0; i < 10; i++) {
        if (first <= array[i]) {
            third = second;
            second = first;
            first = array[i];
        }
        else if (second <= array[i]){
            third = second;
            second = array[i];
        }
        else if (third <= array[i]){
            third = array[i];
        }
    }
    cout << first << endl;
    cout << second << endl;
    cout << third << endl;
    
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <fstream>
#include <algorithm>       // for next_permutation
#include <vector>

#define DEBUG 0
#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

//Stone
//dp[i]:石がi個のとき、先手が勝てるかどうか

int main() {
    int N,K;
    cin >> N >> K;
    vector <int> a(N);
    REP(i,N)
    {
        cin >> a[i];
    }
    //sort(a.begin(),a,end());


    vector <bool> dp(K+1, false);
    
    //のこり0のときは先手の負け
    dp[0] = false;
    int cnt = 0;
    for(int i = 1; i <= K; ++i)
    {
        for(int j = 0; j < N; ++j)
        {
            if(i >= a[j])
            {
                //or = 
                dp[i] =  dp[i] || !dp[i-a[j]];
            }
        }
    }

    string win[2] = {"Second", "First"};

    string res = win[dp[K]];

    cout << res << endl;

    return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 200010;

int n, k;
int a[N];
LL res;

int main()
{
    scanf("%d%d", &n, &k);
    for(int i = 0; i < n; i++) scanf("%d", a + i);

    sort(a, a + n);

    for(int i = 0; i < n - k; i++) res += a[i];

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


Measured memory_bytes: 1024
#include <iostream>
#include <stdint.h>
using namespace std;

int main(){

    int64_t A, B, K;
    cin >> A >> B >> K;

    if (A < K) {
        K -= A;
        A = 0;
    }
    else {
        A -= K;
        K = 0;
    }
    if (B < K) {
        K -= B;
        B = 0;
    }
    else {
        B -= K;
        K = 0;
    }

  
    cout << A << " " << B;

    return 0;
}


Measured memory_bytes: 888
#include<stdio.h>
int main(){
  int N,cnt=0,i,min;
  scanf("%d",&N);
  char S[N+1];
  scanf("%s",S);
  
  for(i=0;i<N;i++){
    if(S[i]=='.')cnt++;
  }
  if(S[0]=='.'){
    cnt--; 
    min=cnt;
  }
  else {
    min=cnt; 
    cnt++;
  }

  for(i=1;i<N;i++){
    if(S[i]=='.')cnt--;
    else cnt++;
    if(cnt<min){
      min=cnt;
    }
  }
  printf("%d\n",min);

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<int> a(n+1);
    vector<vector<int>> x(n+1, vector<int>(n));
    vector<vector<int>> y(n+1, vector<int>(n));

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (a[i] != 0)
            for (int j = 1; j <= a[i]; j++) cin >> x[i][j] >> y[i][j];
    }

    int ans = 0;
    for (int is = (1<<n)-1; is >=0 ; is--) {
        int tmp = 0;

        bool okflag = true;
        for (int i=1; i<=n; i++) {
            if(is>>(i-1)&1) {
                if (a[i] != 0)
                    for (int j = 1; j <= a[i]; j++) {
                        if ((is>>(x[i][j]-1)&1) != (y[i][j])) {
                            okflag = false;
                            break;
                        }
                    }
            }
            if(!okflag) break;
        }
        if(!okflag) continue;
        rep(k, n) {
            if (is>>k&1) tmp++;
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

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

const int INF = 1 << 28;

struct Primal_Dual
{
  typedef pair< int, int > Pi;
 
  struct edge
  {
    int to, cap, cost, rev;
  };
  vector< vector< edge > > graph;
  vector< int > potential, min_cost, prevv, preve;
 
  Primal_Dual(int V):graph(V){}
 
  void add_edge(int from, int to, int cap, int cost)
  {
    graph[from].push_back((edge){to, cap, cost, (int)graph[to].size()});
    graph[to].push_back((edge){from, 0, -cost, (int)graph[from].size() - 1});
  }
 
  int min_cost_flow(int s,int t,int f)
  {
    
    int V = graph.size(), ret = 0;
    priority_queue< Pi, vector< Pi >, greater< Pi > > que;
    potential.assign(V, 0);
    prevv.assign(V, -1);
    preve.assign(V, -1);

    while(f > 0){
      min_cost.assign(V, INF);

      que.push(Pi(0, s));
      min_cost[s] = 0;
      while(!que.empty()){
        Pi p = que.top(); que.pop();
        if(min_cost[p.second] < p.first) continue;
        for(int i = 0; i < graph[p.second].size(); i++){
          edge& e = graph[p.second][i];
          int nextCost = min_cost[p.second] + e.cost + potential[p.second] - potential[e.to];
          if(e.cap > 0 && min_cost[e.to] > nextCost){
            min_cost[e.to] = nextCost;
            prevv[e.to] = p.second, preve[e.to] = i;
            que.push(Pi(min_cost[e.to], e.to));

          }
        }
      }

      if(min_cost[t] == INF) return(ret);
      for(int v = 0; v < V; v++) potential[v] += min_cost[v];
      int addflow = f;
      for(int v = t; v != s; v = prevv[v]){
        addflow = min( addflow, graph[prevv[v]][preve[v]].cap);
      }
      f -= addflow;
      ret += addflow * potential[t];
      for(int v = t; v != s; v = prevv[v]){
        edge& e = graph[prevv[v]][preve[v]];
        e.cap -= addflow;
        graph[v][e.rev].cap += addflow;
      }
    }
    return(ret);
  }
};

int main()
{
  int N, A[1000], B[1000];
  cin >> N;
  vector< int > nums;
  for(int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
    nums.push_back(A[i]);
    nums.push_back(B[i]);
  }
  sort(nums.begin(), nums.end());
  nums.erase(unique(nums.begin(), nums.end()), nums.end());
 
  int s = N + nums.size() + 1, g = s + 1;

  Primal_Dual MCF(g + 1);
  int ret = 0;
  for(int i = 0; i < N; i++) {
    A[i] = lower_bound(nums.begin(), nums.end(), A[i]) - nums.begin();
    B[i] = lower_bound(nums.begin(), nums.end(), B[i]) - nums.begin();
    MCF.add_edge(s, i, 1, 0);
    MCF.add_edge(i, N + A[i], 1, nums[A[i]]);
    MCF.add_edge(i, N + B[i], 1, nums[B[i]]);
    MCF.add_edge(i, N + nums.size(), 1, nums[A[i]] + nums[B[i]]);
    ret += nums[A[i]] + nums[B[i]];
  }

  for(int i = 0; i < nums.size(); i++) {
    MCF.add_edge(N + i, g, 1, 0);
  }

  MCF.add_edge(N + nums.size(), g, INF, 0);
  for(int i = 0; i < N; ++i) {
    ret -= MCF.min_cost_flow(s, g, 1);
  }
  cout << ret << endl;
}

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

using namespace std;


void Main()
{
    int X, ans;
    cin >> X;

    ans = (1000 * (X / 500)) + (5 * ((X % 500)  / 5));
    cout << ans;

}


int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

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

int main()
{
	stack<int> stk;
	int n;

	while(cin>>n) {
		if (n) stk.push(n);
		else {
			cout << stk.top() << endl;
			stk.pop();
		}
	}
	return 0;
}


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

using namespace std;

int main() 
{
    int n, m, i;
    scanf("%d", &n);
    
    vector<int> v1;
    vector<int> v2;
    
    for(i = 0; i < n; i++)
    {
        scanf("%d", &m);
        v1.emplace_back(m);
        v2.emplace_back(m);
    }
    
    if(prev_permutation(v1.begin(), v1.end()))
    {
        for(i = 0; i < n-1; i++)
            printf("%d ", v1[i]);
        printf("%d\n", v1[i]);
    }

    for(i = 0; i < n-1; i++)
        printf("%d ", v2[i]);
    printf("%d\n", v2[i]);
    
    if(next_permutation(v2.begin(), v2.end()))
    {
        for(i = 0; i < n-1; i++)
            printf("%d ", v2[i]);
        printf("%d\n", v2[i]);
    }
    
    return 0;
}


Measured memory_bytes: 3296
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 % 2 == 0){
            System.out.println("Even");
        }
        else{
            System.out.println("Odd");
        }
    }
}


Measured memory_bytes: 21460
n = int(input())
#indexが負の場合、末尾から参照されるので多めにとる
dp = [0]*100200
dp[0] = 1
for i in range(0,100200):
    if dp[i-105]:
        dp[i] = 1
    if dp[i-104]:
        dp[i] = 1
    if dp[i-103]:
        dp[i] = 1
    if dp[i-102]:
        dp[i] = 1
    if dp[i-101]:
        dp[i] = 1
    if dp[i-100]:
        dp[i] = 1
 
print(dp[n])

Measured memory_bytes: 3828
# ARC097D - Equals
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)


def dfs(v: int, color: int) -> None:
    seen[v] = 1  # make vertex v searched
    group[v] = color
    for u in G[v]:  # search vertices available from v recursively
        if not seen[u]:  # skip if already searched
            dfs(u, color)


def main():
    # check i and Pi are connected components or not
    global G, seen, group
    N, M = tuple(map(int, input().split()))
    P = tuple(map(int, input().split()))
    E = tuple(tuple(map(int, input().split())) for _ in range(M))
    G = [[] for _ in range(N + 1)]  # construct a graph (1-idx)
    for v, u in E:
        G[v] += [u]
        G[u] += [v]
    seen, group = [0] * (N + 1), [0] * (N + 1)
    color = 1
    for i in range(1, N + 1):  # connected components have the same color
        if not seen[i]:
            dfs(i, color)
            color += 1
    ans = sum(group[i] == group[p] for i, p in enumerate(P, 1))
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 90944
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void){

    int N; cin>>N;
    string S; cin>>S;
    vector<int> A(N), B(N);
    int cnt=0;

    for (int i = 0; i < N; ++i) {
        A[i]=cnt;
        if(S[i]=='W') cnt++;

    }

    cnt=0;
    for (int i = N-1; i >= 0; --i) {
        B[i]=cnt;
        if(S[i]=='E') cnt++;
    }

    for (int i = 0; i < N; ++i) {
        //cout<<B[i]<<endl;
    }

    vector<int> C(N);
    for (int i = 0; i < N; ++i) {
        C[i]=A[i]+B[i];
    }
    int ans = *min_element(C.begin(), C.end());
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4228
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？


x,y,z=mii()

print(z,x,y)






Measured memory_bytes: 65516
using System;
using System;
class ProgramB
    {
        static void Main(string[] args)
        {
            
            //入力
            string[] input = Console.ReadLine().Split(' ');
            long a = long.Parse(input[0]);
            long b = long.Parse(input[1]);
            long k = long.Parse(input[2]);


            if(a >= k)
            {
                Console.Write(a - k);
                Console.Write(' ');
                Console.Write(b);

            }
            else
            {
                Console.Write('0');
                Console.Write(' ');
                if(a+b >= k)
                    Console.Write(a + b - k);
                else
                {
                    Console.Write('0');
                }
            }    
                
        }
    }

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

int main(){
  double r;
  cin >> r;
  double ans = 2 * M_PI * r;
  cout << fixed << setprecision(20) << ans << endl;
}

Measured memory_bytes: 3788
let pow x n =
  let rec aux i tmp = if i = 1 then tmp else aux (i - 1) (tmp * x) in
  aux n x

let f n m =  (1900 * m) * (pow 2 m) + (100 * (n - m)) * (pow 2 m)

let () = Scanf.scanf "%d %d" f |> Printf.printf "%d\n"

Measured memory_bytes: 384
//dijkstra算法
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

//INFTY要足够大
const int INFTY = 1 << 21;

const int N = 10000;

vector<pair<int,int> >Graph[N];

int n;

void dijkstra(int u0) {
	int *d = new int[n];
	char *color = new char[n];
	for (int i=0; i<n; i++) {
		d[i] = INFTY;
		color[i] = 'W';
	}

	d[u0] = 0;
	color[u0] = 'G';
	priority_queue<pair<int,int> > PQ;
	PQ.push(make_pair(0,u0));

	while (!PQ.empty()) {
		pair<int,int> f = PQ.top();
		PQ.pop();
		int u = f.second;

		color[u] = 'B';

		//if (d[u] < f.first * -1) continue;

		for (int i=0; i<Graph[u].size(); i++) {
			pair<int,int> p = Graph[u][i];
			int v = p.first;
			if (color[v] != 'B'&& d[v] > d[u] + p.second) {
				d[v] = d[u] +p.second;
				color[v] = 'G';
				PQ.push(make_pair(d[v] * -1,v));
			}
		}
	}
	for (int i=0; i<n; i++) {
		cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
	}
}

int main() {

	cin >> n;

	for (int i=0; i<n; i++) {
		int u,k;
		cin >> u >> k;

		for (int j = 0; j<k; j++) {
			int v,c;
			cin >> v >> c;
			Graph[u].push_back(make_pair(v,c));
		}
	}
	dijkstra(0);
	return 0;
}


Measured memory_bytes: 8196
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define int long long int
#define pp pair<int,int>
#define endl "\n"
#define PI 3.14159265
int MAX = INT_MAX;
const int mod=1e9+7;
const int INF =INT_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        int m,n,x;
        cin>>m>>n>>x;
        vector<int>row(m+1,0),col(n+1,0);
        set<pair<int,int> >s;
        for(int i=0;i<x;i++)
        {
            int i1,j1;
            cin>>i1>>j1;
            s.insert({i1,j1});
            row[i1]++;col[j1]++;
        }
        int r;
        int mx1=0;
        for(int i=1;i<=m;i++)
        {
            if(row[i]>mx1){r=i;mx1=row[i];}
        }
       int ans1=0;
       for(int i=1;i<=n;i++)
       {
           pp d={r,i};
           if(s.find(d)!=s.end())ans1=max(ans1,mx1+col[i]-1);
           else ans1=max(ans1,mx1+col[i]);
       }
        int c;
        int mx2=0;
        for(int i=1;i<=n;i++)
        {
            if(col[i]>mx2){c=i;mx2=col[i];}
        }
       int ans2=0;
       for(int i=1;i<=m;i++)
       {
           pp d={i,c};
           if(s.find(d)!=s.end())ans2=max(ans2,mx2+row[i]-1);
           else ans2=max(ans2,mx2+row[i]);
       }

     cout<<max(ans1,ans2)<<endl;

    }
}


Measured memory_bytes: 26700
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

x,y,z = get_nums_l()

print( z, x, y )


Measured memory_bytes: 38256
import math

n = int(input())
m = n

answer = 0
i = 2
while i ** 2 <= m:
    t = 0
    while n % i == 0:
        n //= i
        t += 1
    answer += int((-1+math.sqrt(1+8*t)) / 2)
    i += 1

if n > 1000000:
    answer += 1

print(answer)


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

#define ll long long
#define ul 100000
// #define ul 10
#define fo(i,a,b) for(int i=a;i<b;++i)
#define mod 1000000007
#define sff fflush(stdout)

int A[ul+5];
vector<int> v[ul+5];
bool visit[ul+5];
vector< pair<int,int> > stc[ul+5];
bool cover[ul+5];

bool comp(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second < b.second);
}

pair<int,int> root[ul+5];
int frq[ul+5];


void dfs(int x,int c)
{
	visit[x] = true;
	root[x] = make_pair(x,A[x]);
	stc[c].push_back(make_pair(x,A[x]));
	for(int i=0;i<v[x].size();i++)
	{
		if(!visit[v[x][i]]) dfs(v[x][i],c);
	}
	return;
}

int main()
{
	int n,m;
	int x,y;
	cin>>n>>m;
	fo(i,0,n) cin>>A[i];
	fo(i,0,m)
	{
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	fo(i,0,n) visit[i] = false;
	int scc =0;
	fo(i,0,n)
	{
		if(!visit[i]) {dfs(i,scc); scc++;}
	}
	
	if((scc-1)>(n/2)) cout<<"Impossible\n";
	else if(scc==1) cout<<"0\n";
	else
	{
		sort(root,root+n,comp);
		// cout<<"debug2"<<'\n';
		for(int i=0;i<n;i++) cover[i] = false;
		ll ans = 0;
		fo(i,0,scc) sort(stc[i].begin(), stc[i].end(),comp);
		fo(i,0,scc) {ans += stc[i][0].second; cover[stc[i][0].first] = true;}
		// cout<<"debug3"<<'\n';
		int cnt = 0;
		for(int i=0;;i++)
		{
			if(cnt+2==scc) break;
			int xx = root[i].first;
			int yy = root[i].second;
			// cout<<i<<'\n';
			if(!cover[xx]) {ans+= yy;cnt++;}
		}
		cout<<ans<<'\n';
	}
}


Measured memory_bytes: 10492
import sys
if __name__ == "__main__":
    N = int(input())
    P = []
    Q = [0]*(N+1)
    for i in range(1, N+1):
        p = int(input())
        Q[p] = i

    # 1 4 5 2 3 -> 4 5を移動
    # 1 4 5 3 2 -> 3 4 5 を移動
    # 5 2 1 3 4 -> 1 5 を移動
    cur = 1
    max_cur = 1
    for i in range(1, N):
        if Q[i] < Q[i+1]:
            cur += 1
            max_cur = max(cur, max_cur)
        else:
            cur = 1
    print(N - max_cur)


Measured memory_bytes: 12916
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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

vector<ll> a;
vector<ll> sum;

//dp
vector<vector<ll>> table;

ll dp(ll i,ll j){
  if(j-i==1) return 0;
  if(table.at(i).at(j)<INF) return table.at(i).at(j);
  
  ll ret=INF;
  for(int k=i+1;k<j;k++){
    chmin(ret,dp(i,k)+dp(k,j)+sum.at(k)-sum.at(i)+sum.at(j)-sum.at(k));
  }
  
  return table.at(i).at(j)=ret;
}

int main()
{
  ll N; cin>>N;
  a=vector<ll>(N); rep(i,N) cin>>a.at(i);
  
  //累積和
  sum=vector<ll>(N+1,0); rep(i,N) sum.at(i+1)=sum.at(i)+a.at(i);
  
  //dp
  table=vector<vector<ll>>(N,vector<ll>(N+1,INF));
  
  cout<<dp(0,N)<<endl;
  return 0;
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int dx = x2 - x1, dy = y2 - y1;
    int x3 = x2 + (-dy), y3 = y2 + dx;
    int ddx = -dy, ddy = dx;
    int x4 = x3 + (-ddy), y4 = y3 + ddx;
    print(x3, y3, x4, y4);

    return 0;
}


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> L(K), R(K);
    for (int i = 0; i < K; i++) cin >> L[i] >> R[i];
    vector<ll> dp(N+1, 0), sum(N+1, 0);
    dp[1] = 1;
    sum[1] = 1;
    ll mod = 998244353;
    for (int i = 2; i <= N; i++) {
        for (int j = 0; j < K; j++) {
            int mr = max(i-L[j], 0), ml = max(i-R[j]-1, 0);
            dp[i] += sum[mr]-sum[ml]+mod;
        }
        dp[i] %= mod;
        sum[i] = (sum[i-1]+dp[i])%mod;
    }
    cout << dp[N]%mod << endl;
    return 0;
}


Measured memory_bytes: 6420
s = str(input())
n = len(s)
for i in reversed(range(n-1)):
    s_ = s[0:i]
    if len(s)%2 ==1:
        continue
    else:
        t = s_[0:(i//2)]
        if s_ == t + t:
            print(len(s_))
            exit()


Measured memory_bytes: 2940
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,long double> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll n, l;
	cin>>n>>l;
	deque<P> q;
	long double s = 0.0;
	cout.precision(20);
	rep(i, n){
		long double t;
		ll v;
		cin>>t>>v;
		if(i){
			ll e = v;
			while(e>0){
				P p = q.front(); q.pop_front();
				ll d = min(e, p.fst);
				e -= d;
				s -= d*p.snd;
				if(p.fst-d>0) q.push_front(P(p.fst-d, p.snd));
			}
		}
		s += v*t;
		while(!q.empty() && q.back().snd>t){
			P p = q.back();
			//cerr<<i<<" "<<p.fst<<" "<<p.snd<<" "<<v<<" "<<t<<endl;
			ll v2 = v+p.fst;
			long double t2 = (v*t+p.fst*p.snd)/v2;
			v = v2;
			t = t2;
			q.pop_back();
		} 
		q.push_back(P(v, t));
		cout<<s/l<<endl;
	}
	return 0;
}


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

const int N = 1e5 + 10;

int k;
int dis[N];

int main() {
  //  freopen("input.in", "r", stdin);
  //  freopen("output.out", "w", stdout);

    scanf("%d", &k);

    deque <int> q;
    for (int i = 0; i < N; ++i) dis[i] = 1e9 + 7;
    dis[1] = 0; q.push_back(1);
    while (!q.empty()) {
        int x = q.front(); q.pop_front();
        if (x == 0) {
            printf("%d\n", dis[x] + 1);
            return 0;
        }
        if (dis[x * 10 % k] > dis[x]) {
            dis[x * 10 % k] = dis[x];
            q.push_front(x * 10 % k);
        }
        if (dis[(x + 1) % k] > dis[x] + 1) {
            dis[(x + 1) % k] = dis[x] + 1;
            q.push_back((x + 1) % k);
        }
    }

    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

long long gcd(long long m,long long n){
    if(n==0){
        return m;
    }
    return gcd(n,m%n);
}
 
long long lcm(long long a,long long b){
    long long g=gcd(a,b);
    return a/g*b;
}

int main() {
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    sort(all(a));
    if(k>a[n-1]){
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }

    int g=0;
    rep(i,n) g=gcd(g,a[i]);
    rep(i,n){
        if(a[i]==k){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
    }

    if(k%g==0){
        cout<<"POSSIBLE"<<endl;
    }
    else{
        cout<<"IMPOSSIBLE"<<endl;
    }

}

Measured memory_bytes: 3772
#include<iostream>

using namespace std;

int main()
{
	int x = 0, i = 0;
	
	while(1){
		i++;
		
		cin >> x;
		
		if(x == 0)
			break;
		
		cout << "Case " << i << ": " << x << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160