akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;

ll n;
string a[305];
ll cnt;

int main()
{
    cin>>n;
    for(ll i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    for(ll i = 0; i < n; i++)
    {
        for(ll j = 0; j < n; j++)
        {
            rotate(a[j].begin(), a[j].begin() + 1, a[j].end());
        }
        bool v = false;
        for(ll j = 0; j < n; j++)
        {
            for(ll k = 0; k < n; k++)
            {
                if(a[j][k] != a[k][j]) v = true;
            }
        }
        cnt += (!v);
    }
    printf("%lld\n", cnt * n);
    return 0;
}


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

int main() {
  int T[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K; cin>>K;
  cout<<T[K-1]<<endl;;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

ll f(ll n) {
	if (n == 1) return 1;
	return 1 + 2*f(n/2);
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	cout << f(n) << endl;
}



Measured memory_bytes: 256
IDENTIFICATION DIVISION.
PROGRAM-ID. 171C.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
  SELECT STDIO ASSIGN TO KEYBOARD. 
*>
DATA DIVISION.
FILE SECTION.
FD STDIO.
01 INP        PIC X(700000).
*>
WORKING-STORAGE SECTION.
01 INW        PIC X(20).
01 N          PIC 9(06) COMP.
01 Q          PIC 9(06) COMP.
01 P1         PIC 9(06) COMP.
01 P2         PIC 9(06) COMP.
01 TBL1.
   03 A       PIC 9(06) OCCURS 100000.
01 B          PIC 9(06).
01 C          PIC 9(06).
01 I          PIC 9(06) COMP.
01 IDX        PIC 9(06) COMP.
01 CNT1       PIC 9(10) COMP.
01 OUT        PIC Z(9)9.
*>
PROCEDURE DIVISION.
  ACCEPT N.
*>
  OPEN INPUT STDIO.
  READ STDIO.
  CLOSE STDIO.
*>
  MOVE ZERO TO TBL1 CNT1.
  MOVE 1    TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
    MOVE INP(P1:P2 - P1) TO IDX
    ADD 1                TO A(IDX)
    ADD IDX              TO CNT1
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  ACCEPT Q.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > Q
    ACCEPT INW
    UNSTRING INW DELIMITED BY ' '
        INTO B C
    IF (A(B) > 0)
      COMPUTE CNT1 = CNT1 - A(B) * B + A(B) * C
      ADD  A(B) TO A(C)
      MOVE 0    TO A(B)
    END-IF
*>  
    MOVE CNT1 TO OUT
    DISPLAY FUNCTION TRIM(OUT) 
  END-PERFORM.
*>
  STOP RUN.


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

int main()
{
  int a,b;
  
  cin>>a>>b;
  
  if(a<b)
  {
    for(int i = 1; i <=b; i++)
      cout<<a;
  }
  else
  {
    for(int i = 1; i <= a; i++)
      cout<<b;
  }
}

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

using namespace std;

#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORD(i, m, n) for (int i = m; i >= n; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REP1(i, n) for (int i = 0; i <= n; ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int x = c - a, y = d - b;
	printf("%d %d %d %d", c - y, d + x, a - y, b + x);

	return 0;
}


Measured memory_bytes: 3784
import java.util.*;
public class Main {
	public static int LongestCommonSequence(String string1, String string2)
	{
		int max = 0;
		int len1 = string1.length() , len2 = string2.length();
		//table to find longest common sequence
		int[][] table = new int[len1 + 1][len2 + 1];
		//filling the table for max values
		for(int i = 1; i <= len1  ; i++)
		{
			for(int j = 1 ; j <= len2 ; j++)
			{
				if(string1.charAt(i-1) != string2.charAt(j-1))
				{
					table[i][j] = Math.max(table[i-1][j],table[i][j-1]);
				}
				if(string1.charAt(i-1) == (string2.charAt(j-1)))
				{
					table[i][j] = 1 + table[i-1][j-1];
				}
			}
		}
		max = table[len1][len2];
		return max;
	}
	
	public static void main(String args[])
	{
		Scanner in = new Scanner(System.in);
		int pairs = in.nextInt();
		for(int i = 0; i < pairs ; i ++)
		{
			String s1 = in.next();
			String s2 = in.next();
			int answer = LongestCommonSequence(s1,s2);
			System.out.println(answer);
		}
		
	}
}



Measured memory_bytes: 65192
def rec_z():
    for i in range(N):
        for j in range(Hmax+1):
            if j >= a[i]:
                dp[j] = min(dp[j], dp[j-a[i]] + b[i])
    return min(dp[H:Hmax+1])
 
 
H, N = map(int,input().split())
a = []
b = []
for i in range(N):
    aa, bb = map(int, input().split())
    a.append(aa)
    b.append(bb)
Hmax = H + max(a)
INF = 10**9
dp = [INF for _ in range(Hmax+1)] 
dp[0] = 0
print(rec_z())

Measured memory_bytes: 40304
#include <stdio.h>

int main()
{
  int n;
  scanf("%d",&n);
  int a[n];
  int i;
  i = 0;
  int counter;
  counter = 0;
  while (i < n)
  {
    scanf("%d",&a[i]);
    i++;
  }
  i = 0;
  while (i < n)
  {
    if (a[i] % 2 == 0)
    {
      a[i] /= 2;
    }
    else
    {
      printf("%d",counter);
      return (0);
    }
    i++;
    if (i == n)
    {
      counter++;
      i = 0;
    }
  }
}

Measured memory_bytes: 128
#include<stdio.h>

int main(void)
{
  double m, max, min;

  min = 1000000;
  max = 0;
  while(scanf("%lf",&m)!=EOF)
    {
      if(max<m)
	max = m;
      if(min>m)
	min = m;
    }
  printf("%.1f\n",max-min);
  return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <deque>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define ll long long
#define int ll
#define INF (1LL<<60)

int n, a[200001], sum[200001];
signed main(){

	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	for (int i = 0; i < n-1; i++){
		a[i + 1] += a[i];
	}

	int r = INF;
	for (int i = 0; i <= n - 2; i++){
		int c = abs(a[i] * 2 - a[n-1]);
		if (c < r) r = c;
	}

	cout << r << endl;


	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pop_back
#define in insert
#define ff first
#define ss second
#define  show for(int j=0;j<v.size();j++) cout<<v[j]<<" ";
#define ld long double
#define e endl
#define bc __builtin_popcount
#define MOD 1000000007
#define INT_SIZE 32
#define me(x) memset(x,0,sizeof(x))
ll fast_expo(ll x,ll p)
{if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;} else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main()
{
    int r;
    cin>>r;
    cout<<r*r;



}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define per(i, n) for(int i = (n)-1; i >= 0; --i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 

using ll = long long;

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

constexpr int MOD = 1e9+7;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;

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;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll mod){ll r=1;while(e>0){if(e&1)r=(r%mod)*(b%mod)%mod;b=(b%mod)*(b%mod)%mod;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i < v.size()-1)s<<", ";}s<<']';return s;}

int main(){

    ll n, a, b;
    scanf("%lld%lld%lld", &n, &a, &b);

    if((b-a)%2){
        ppp(min(a-1, n-b) + (b-a-1)/2 + 1);
    }
    else{
        ppp((b-a)/2);
    }

    return 0;
}


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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\n'
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e3 + 10;
const int inf = 0x3f3f3f3f;

ll a[maxn], b[maxn], c[maxn];
int x, y, z, k;

bool ok(ll mid){
  int cnt = 0;
  For(i, 1, x)
    For(j, 1, y)
      For(t, 1, z){
        if (a[i] + b[j] + c[t] < mid) break;
        ++cnt;
        if (cnt >= k) return true;
      }
  return false;
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout);
  cin >> x >> y >> z >> k;
  For(i, 1, x) cin >> a[i];
  For(i, 1, y) cin >> b[i];
  For(i, 1, z) cin >> c[i];

  sort(a + 1, a + x + 1, greater<ll>());  sort(b + 1, b + y + 1, greater<ll>());  sort(c + 1, c + z + 1, greater<ll>());

  ll l = a[x] + b[y] + c[z], r = a[1] + b[1] + c[1];

  while (l <= r){
    ll mid = (l + r) >> 1;
    if (ok(mid)) l = mid + 1;
    else r = mid - 1;
  }
  ll ans = l - 1;
//  cout << ans << '\n';
  vector<ll> res1, res2;
  int cnt = 0;

  For(i, 1, x)
    For(j, 1, y)
      For(t, 1, z){
        if (a[i] + b[j] + c[t] < ans) break;
        if (a[i] + b[j] + c[t] == ans && sz(res1) < k) res1.push_back(a[i] + b[j] + c[t]);
        if (a[i] + b[j] + c[t] > ans) res2.push_back(a[i] + b[j] + c[t]);
        if (sz(res2) >= k) {
          i = x; j = y; t = z;
        }
      }
  sort(All(res2), greater<ll>());
  for (auto val : res2) cout << val << '\n';
  For(i, 1, k - sz(res2)) cout << ans <<'\n';
return 0;
}



Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1e9+7, MAX = 1e9, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
long long sum = 0;

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

int main() {
    cin >> N >> M;
    ll x[1000],y[1000],z[1000];
    rep(i, N){
        cin >> x[i] >> y[i] >> z[i];
    }
    ll max_value = INF;
    rep(i, 8){
        vector<ll> vec;
        rep(j, N){
            ll sum = 0;
            if(i%2 == 0){
                sum += x[j];
            }else{
                sum -= x[j];
            }
            if((i/2)%2 == 0){
                sum += y[j];
            }else{
                sum -= y[j];
            }
            if((i/4)%2 == 0){
                sum += z[j];
            }else{
                sum -= z[j];
            }
            vec.push_back(sum);
        }
        sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end());
        ll sum = 0;
        rep(k, M) sum += vec[k]; 
        max_value = max(max_value, sum);
    }
    cout << max_value << endl;
    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
P = list(map(int, input().split()))
S =[0] * (N - K + 1)
S[0] = sum(P[0:K])

for i in range(1, N - K + 1):
    S[i] = S[i-1] - P[i-1] + P[i+K-1]

print((max(S) + K) / 2)

Measured memory_bytes: 25060
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define N 200002
using namespace std;


char s[N][11];
int a[N], c, p[N];

int cmp(int x, int y)
{
	return strcmp(s[x], s[y]) < 0;
}

int main() 
{
	int n, i, max = 0, j, pi, t;
				
	scanf("%d", &n);
	for(i = 0; i < n; i++) scanf("%s", s[i]), p[i] = i;
	sort(p, p + n, cmp);
	
	for(i = 0; i < n; i = j){
		pi = p[i];
		for(j = i + 1; j < n && !strcmp(s[pi], s[p[j]]); j++);
		t = j - i;
		if(t > max){
			max = t;
			a[c = 0] = pi;
		}
		else if(t == max) a[++c] = pi;
	}
	for(i = 0; i <= c; i++){
		puts(s[a[i]]);
	}
			
	return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
    
using namespace std;
typedef long long ll;
    
int main()
{
    vector<vector<int>> A(3, vector<int>(3));
    int N;
    vector<int> b(N);

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> A.at(i).at(j);
        }
    }
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> b.at(i);
    }

    vector<vector<bool>> result = {
        {false, false, false},
        {false, false, false},
        {false, false, false},
    };

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < N; k++) {
                if(A[i][j] == b[k]) {
                    result[i][j] = true;
                }
            }
        }
    }

    string ans = "No";
    for (int i = 0; i < 3; i++) {
        if (result[i][0] && result[i][1] && result[i][2]) {
            ans = "Yes";
        }
    }
    for (int i = 0; i < 3; i++) {
        if (result[0][i] && result[1][i] && result[2][i]) {
            ans = "Yes";
        }
    }
    if (result[0][0] && result[1][1] && result[2][2]) {ans = "Yes";}
    if (result[0][2] && result[1][1] && result[2][0]) {ans = "Yes";}
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 X, Y;
  std::cin >> X >> Y;
  std::cout << X + Y / 2 << std::endl;
  return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict


N, M = map(int, input().split())

inter = []
goalable = defaultdict(lambda: False)
for i in range(M):
  start, end = map(int, input().split())
  if start == 1:
    inter.append(end)
  else:
    if end == N: 
      goalable[start] = True
      
for i in inter:
  if goalable[i]:
    print("POSSIBLE")
    sys.exit()
    
print("IMPOSSIBLE")

Measured memory_bytes: 28916
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n  = sc.nextInt();
    int[][] town = new int[n][2];
    
    for(int i=0; i<n; i++){
      for(int j=0; j<2; j++){
        town[i][j] = sc.nextInt();
      }
    }
    
    double x = 0;
    double y = 0;    
    double total = 0.0;
    
    for(int i=0; i<n; i++){
      for(int j=i+1; j<n; j++){
        x = (town[i][0]-town[j][0])*(town[i][0]-town[j][0]);
        y = (town[i][1]-town[j][1])*(town[i][1]-town[j][1]);
        total += Math.sqrt(x + y);
      }
    }
    
    System.out.println(total*2/n);
  }
}


Measured memory_bytes: 21844
#include <stdio.h>
int main(){
	int i,n,x,l,count,d;
	if(scanf("%d%d",&n,&x)==-1){
		return 1;
	};
	count=1;
	d=0;
	for(i=0;i<n;i++){
		scanf("%d",&l);
		if(d+l<=x){
			count+=1;
			d=d+l;
		}
		else{
			break;
		}
	}
	printf("%d",count);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
#include <iomanip>
using namespace std;
// type alias
typedef long long LL;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))

// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');

// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpf(args...) if(TRACE) { fprintf(stderr, ##args); putchar('\n'); }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
template<class Iter> void dumpc(Iter begin, Iter end) { if (TRACE) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; } }

// $ cp-batch BulletinBoard | diff BulletinBoard.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address BulletinBoard.cpp && ./a.out

/*
 
 1/17/2019
 
 16:19-
 
 */

int N,H,W;

void solve() {
  int res=(N-H+1)*(N-W+1);
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>H>>W;
  solve();
  
  return 0;
}


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

int main(){
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    if (A+B<C+D){
        cout<<"Right"<<endl;
    }else if(A+B>C+D){
        cout<<"Left"<<endl;
    }else{
        cout<<"Balanced"<<endl;
    }
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
    
int main()
{
  int n;
  cin>>n;
  vector<long long> v(n);
  for(int i=0;i<n;i++)
    cin>>v[i];
  vector<vector<long long>> dp(n,vector<long long>(n,0));
  vector<vector<long long>> sum(n,vector<long long>(n,0));
  for(int i=0;i<n;i++)
  {
    for(int j=i;j<n;j++)
      sum[i][j]=v[j]+((i==j)?0:sum[i][j-1]);
  }
  for(int l=1;l<n;l++)
  {
    for(int i=0;i<n-l;i++)
    {
      int j=i+l;
      dp[i][j]=1e14;
      for(int k=i;k<j;k++)
      dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+sum[i][j]);
    }
  } 
  cout<<dp[0][n-1]<<endl;
  return 0;
}

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

char buf[1<<15],*fs,*ft;
inline char getc() { return (ft==fs&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),ft==fs))?0:*fs++; }
template<typename T>inline void read(T &x)
{
    x=0;
    T f=1, ch=getchar();
    while (!isdigit(ch) && ch^'-') ch=getchar();
    if (ch=='-') f=-1, ch=getchar();
    while (isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
    x*=f;
}

char Out[1<<24],*fe=Out;
inline void flush() { fwrite(Out,1,fe-Out,stdout); fe=Out; }
template<typename T>inline void write(T x)
{
    if (!x) *fe++=48;
    if (x<0) *fe++='-', x=-x;
    T num=0, ch[20];
    while (x) ch[++num]=x%10+48, x/=10;
    while (num) *fe++=ch[num--];
    *fe++='\n';
}

int a[8];
int main()
{
	for (int i=1; i<=7; ++i) read(a[i]);
	ll ans=a[2];
	if (!a[1] || !a[4] || !a[5]) ans+=a[1]/2*2+a[4]/2*2+a[5]/2*2;
	else
	{
		ans+=(ll)a[1]+a[4]+a[5];
		if (a[1]%2==a[4]%2 && a[4]%2==a[5]%2);
		else --ans;
	}
	write(ans);
	flush();
	return 0;
}

Measured memory_bytes: 256
//omajinai c++
#include <iostream>
#include<cmath>

#include<vector>
#include <algorithm>
#include <limits>
#include <numeric>
#include <type_traits>
#include <map>
#include <string>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
constexpr auto mod = 1000000007;
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<string> s(n);
	rep(i, n) {
		cin >> s.at(i);
	}
	map<string, int> poll{};
	int m = 1;
	rep(i, n) {
		auto itr = poll.find(s.at(i));
		if (itr == poll.end()) {
			poll[s.at(i)] = 1;
		}
		else {
			itr->second++;
			m = max(itr->second, m);
		}

	}
	for (auto itr = poll.begin(); itr != poll.end(); itr++) {
		if (itr->second == m) {
			cout << itr->first << endl;
		}
	}
}

	


Measured memory_bytes: 26752
#include<stdio.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<stack>
#include<string.h>
using namespace std;
int map[30][30];
int n;
int b[30],mmax=0;
void asd(int i) {
	int j, k,er;
	if (i == n + 1) {
		er = 0;
		for (j = 1; j <= n; j++) {
			for (k = 1; k <= n; k++) {
				if (map[j][k] != 0) {
					if (b[j] == 1) {
						if (map[j][k] == 1 && b[k] == 0 || map[j][k] == -1 && b[k] == 1) er = 1;
					}
				}
			}
		}
		if (er == 0) {
			int cnt = 0;
			for (j = 1; j <= n; j++) cnt += b[j];
			if (mmax < cnt) mmax = cnt;
		}
		return;
	}
	b[i] = 1;
	asd(i + 1);
	b[i] = 0;
	asd(i + 1);
}
int main() {
	int i, j,m;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", &m);
		for (j = 1; j <= m; j++) {
			int x, y;
			scanf("%d %d", &x, &y);
			if (y == 0) y = -1;
			map[i][x] = y;
		}
	}
	asd(1);
	printf("%d", mmax);
	return 0;
}

Measured memory_bytes: 128
class Node
    attr_accessor :parent, :rank
    def initialize(n)
        @parent = n
        @rank = 0
    end
end

class UnionFindTree
    def initialize(n)
        @nodes = (0..n).to_a.map { |i| Node.new(i) }
    end
    def find(x)
        return x if @nodes[x].parent == x
        return @nodes[x].parent = find(@nodes[x].parent)
    end
    def unite(a, b)
        a = find(a)
        b = find(b)
        return if a == b
        if @nodes[a].rank < @nodes[b].rank
            @nodes[a].parent = b
        else
            @nodes[b].parent = a
            @nodes[b].rank += 1 if @nodes[a].rank == @nodes[b].rank
        end
    end
    def same?(a, b)
        find(a) == find(b)
    end
end
loop do
    n,m = gets.split.map(&:to_i)
    break if n == 0 && m == 0
    e = m.times.map{gets.split.map(&:to_i)}.sort{|a,b| a[2]<=>b[2]}
    min = Float::INFINITY
    e.size.times do |i|
        uf = UnionFindTree.new(n)
        count = n
        i.upto(m-1) do |j|
            if !uf.same?(e[j][0],e[j][1])
                uf.unite(e[j][0],e[j][1])
                count -= 1
                if count == 1
                    min = e[j][2] - e[i][2] if e[j][2] - e[i][2] < min
                    break
                end
            end
        end
    end
    p min != Float::INFINITY ? min : -1
end

Measured memory_bytes: 6208
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
long long n,i,k,ans;
struct nyh{
	long long x,y,z;
}o[105];
double ans2;
long long read(){
	long long xx=0;
	char ch=getchar();
	while(ch<'0'||ch>'9')
		ch=getchar();
	while(ch>='0'&&ch<='9'){
		xx=xx*10+ch-'0';
		ch=getchar();
	}
	return xx;
}
long long pus(long long xx,int flagg){
	if(xx>=10)
		pus(xx/10,0);
	putchar(xx%10+'0');
	if(flagg==1)
		putchar(' ');
	if(flagg==2)
		putchar('\n');
}
int ss(long long j,long long u,long long v){
	if(j>n){
		ans=max(ans,u*u+v*v);
		return 0;
	}
	if(j<=10||u*u+v*v<=(u+o[j].x)*(u+o[j].x)+(v+o[j].y)*(v+o[j].y))
		ss(j+1,u+o[j].x,v+o[j].y);
	if(j<=10||u*u+v*v>(u+o[j].x)*(u+o[j].x)+(v+o[j].y)*(v+o[j].y))
		ss(j+1,u,v);
}
bool cmp(nyh u,nyh v){
	return u.z<v.z;
}
int main(){
	n=read();
	for(i=1;i<=n;i++)
		scanf("%lld%lld",&o[i].x,&o[i].y);
	for(i=1;i<=1000;i++){
		srand(i*i*123+i*456);
		for(k=1;k<=n;k++)
			o[k].z=rand();
		sort(o+1,o+n+1,cmp);
		ss(1,0,0);
	}
	ans2=sqrt(ans);
	printf("%.13lf\n",ans2);
	return 0;
}

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


int main()
{	
	char str[1200];
	
	cin.getline(str, sizeof(str));

	for (int i = 0; i < sizeof(str); i++){
		if ('a' <= str[i] && str[i] <= 'z'){
			cout << char(toupper(str[i]));
		}
		else if ('A' <= str[i] && str[i] <= 'Z'){
			cout << char(tolower(str[i]));
		}
		else if (str[i] == NULL){
			break;
		}
		else{
			cout << str[i];
		}
	}
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 3128
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

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

    vector<ll> a(n);
    ll total = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        total += a[i];
    }

    vector<ll> ans(n, 0);

    ll others = 0;
    for(int i = 1; i < n; i += 2){
        others += a[i];
    }
    ans[0] = total - 2 * others;

    for(int i = 0; i < n; i++){
        if(i == n - 1) continue;
        ans[i + 1] = a[i] * 2 - ans[i];
    }

    for(int i = 0; i < n; i++){
        if(i != n - 1){
            cout << ans[i] << " ";
        } else {
            cout << ans[i] << endl;
        }
    }
}

Measured memory_bytes: 2944
#include<cstdio>
#define N 500005
#define p 998244353
#define ll long long
int a[N],b[N],c[N],d[N],i,m,n,x;
int main()
{
    scanf("%d%d",&m,&n);
    for(*a=*b=a[1]=b[1]=1,i=2;i<=m||i<=n;i++)a[i]=(ll)a[i-1]*i%p,b[i]=(ll)(p-p/i)*b[p%i]%p;
    for(*c=*d=i=1;i<=m||i<=n;i++)b[i]=(ll)b[i-1]*b[i]%p,c[i]=c[i-1]*(m+1ll)%p,d[i]=d[i-1]*(n+1ll)%p;
    for(i=0;i<=m&&i<=n;i++)x=(x+(ll)b[m-i]*b[n-i]%p*d[m-i]%p*c[n-i]%p*(i&1?p-b[i]:b[i]))%p;
    return 0*printf("%d\n",(ll)a[m]*a[n]%p*x%p);
}

Measured memory_bytes: 7936
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

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

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


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

	int kkt = 89;
	while (kkt) {
		int n, q; scanf("%d %d", &n, &q);
		if (n == 0 && q == 0) break;
		vector<int> cnt(110);
		for (int i = 0; i < n; i++) {
			int m; scanf("%d", &m);
			for (int j = 0; j < m; j++) {
				int x; scanf("%d", &x);
				cnt[x]++;
			}
		}

		int res = 0;
		int mx = 0;
		for (int i = 0; i <= 100; i++) {
			if (cnt[i] >= q) {
				if (chmax(mx, cnt[i])) {
					res = i;
				}
			}
		}
		printf("%d\n", res);
	}
	return 0;

}


Measured memory_bytes: 3120
def main():
    import itertools
    h,w,k = map(int,input().split())
    C = []
    for _ in range(h):
        C.append(list(input()))


    H = list(range(h))
    W = list(range(w))

    ans = 0
    for i in range(h+1):
        for t in itertools.combinations(H,i):
            t = set(t)
            for j in range(w+1):
                for t2 in itertools.combinations(W,j):
                    t2 = set(t2)

                    count = 0
                    for x in range(h):
                        if not x in t:
                            for y in range(w):
                                if not y in t2:
                                    if C[x][y] == '#':
                                        count += 1

                    if count == k:
                        ans += 1


    print(ans)




main()

Measured memory_bytes: 9216
#include<cstdio>
#include<algorithm>
using namespace std;
int box[100001]={0},a[100001],b[100001],c[100001],p[100000];
int main(void)
{
	int n,m,i,mn,mx,cnt;
	long long sum;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d",&p[i]);
	}
	for(i=1;i<n;i++){
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
	}
	for(i=0;i<m-1;i++){
		mn=min(p[i],p[i+1]);
		mx=max(p[i],p[i+1]);
		box[mn]++;
		box[mx]--;
	}
	cnt=0;
	sum=0;
	for(i=1;i<n;i++){
		cnt+=box[i];
		sum+=min((long long)a[i]*cnt,(long long)b[i]*cnt+c[i]);
	}
	printf("%lld\n",sum);
	return 0;
}


Measured memory_bytes: 4600
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;
namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var nt = ReadIntArray();
            var n = nt[0];
            var t = nt[1];
            var a = ReadIntArray();
            var maxProfit = 0;
            var buyCost = a[0] + 1;
            var count = 0;

            var b = new int[a.Length];
            var max = 0;
            for (int i = 0; i < a.Length; i++)
            {
                max = Math.Max(max, a[a.Length - 1 - i]);
                b[b.Length - 1 - i] = max;
            }

            for (var i = 0; i < a.Length - 1; i++)
            {
                if (buyCost > a[i])
                {
                    buyCost = a[i];
                    if (b[i] - buyCost > maxProfit)
                    {
                        maxProfit = b[i] - buyCost;
                        count = 1;
                    }
                    else if(b[i] - buyCost == maxProfit)
                    {
                        count++;
                    }
                }
            }
            Console.WriteLine(count);
        }
    }

    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
    }
}


Measured memory_bytes: 22112
#include<bits/stdc++.h>
using namespace std;
#define P pair<int,int>
int main(){
  int n,m,ans=0;
  vector<P> req(100000);
  cin >> n >> m;
  int dep = n;
  for(int i=0;i<m;i++){
    cin >> req[i].first >> req[i].second;
  }
  sort(req.begin(), req.end(), greater<P>());
  for(int i=0;i<m;i++){
    if(req[i].second > dep) continue;
    ans++;
    dep = req[i].first;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define LL long long
#define mp make_pair
#define fir first
#define sec second
#define pii pair<LL,LL>
#define MAXN 100010
#define MAXM 200010
#define INF 1e16
using namespace std;
map<pii,LL> ys;
priority_queue<pii,vector<pii>,greater<pii> > pq;
LL SZ;
struct node
{
	LL begin,end,value,next;
}edge[6*MAXM+10];
LL cnt,Head[2*MAXM+MAXN+10],dis[2*MAXM+MAXN+10];
vector<pii> vec[1000010];
LL read()
{
	LL s=0,fh=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')fh=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+(ch-'0');ch=getchar();}
	return s*fh;
}
void addedge(LL bb,LL ee,LL vv)
{
	edge[++cnt].begin=bb;edge[cnt].end=ee;edge[cnt].value=vv;edge[cnt].next=Head[bb];Head[bb]=cnt;
}
void addedge1(LL bb,LL ee,LL vv)
{
	addedge(bb,ee,vv);addedge(ee,bb,vv);
}
void dijkstra(LL start)
{
	LL i,u,v;
	for(i=1;i<=SZ;i++)dis[i]=INF;dis[start]=0LL;
	pq.push(mp(dis[start],start));
	while(!pq.empty())
	{
		u=pq.top().sec;pq.pop();
		for(i=Head[u];i!=-1;i=edge[i].next)
		{
			v=edge[i].end;
			if(dis[v]>dis[u]+edge[i].value)
			{
				dis[v]=dis[u]+edge[i].value;pq.push(mp(dis[v],v));
			}
		}
	}
}
int main()
{
	LL N,M,i,p,q,c,pp,qq,ans,mxc=0;
	N=read();M=read();
	memset(Head,-1,sizeof(Head));cnt=1;
	for(i=1;i<=M;i++)
	{
		p=read();q=read();c=read();
		vec[c].push_back(mp(p,q));mxc=max(mxc,c);
	}
	
	memset(Head,-1,sizeof(Head));cnt=1;
	SZ=N;
	for(c=1;c<=mxc;c++)
	{
		for(vector<pii>::iterator it=vec[c].begin();it!=vec[c].end();it++)
		{
			p=((*it).fir);q=((*it).sec);
			if(ys[mp(c,p)]==0LL)ys[mp(c,p)]=++SZ;
			if(ys[mp(c,q)]==0LL)ys[mp(c,q)]=++SZ;
			pp=ys[mp(c,p)];qq=ys[mp(c,q)];
			addedge1(pp,qq,0LL);
			addedge1(pp,p,1LL);
			addedge1(qq,q,1LL);
		}
	}
	/*
	printf("\n");
	for(i=1;i<=cnt;i++)printf("%lld %lld %lld\n",edge[i].begin,edge[i].end,edge[i].value);
	printf("\n");
	*/
	dijkstra(1);
	
	ans=INF;
	for(c=1;c<=mxc;c++)
	{
		if(ys[mp(c,N)]!=0)ans=min(ans,dis[ys[mp(c,N)]]);
	}
	if(ans==INF){printf("-1");return 0;}
	printf("%lld",(ans-1LL)/2LL+1LL);
	return 0;
}

Measured memory_bytes: 164208
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		int ar[]=new int[n];
		for(int i=0;i<n;i++)
		{
			ar[i]=scan.nextInt();
		}
		int bit[][]=new int[n][20];
//		int 
		int x=5;
//		System.out.println(x&(1<<0));
//		System.out.println(x&(1<<2));
//		System.out.println(x&(1<<3));
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<20;j++)
			{
				if((ar[i]&(1<<j))>=1)
				{
					bit[i][j]=1;
				}
			}
		}
		
		long ans=0;
		int tem[]=new int[20];
		int right=0;
	for(int left=0;left<n;left++)
	{
		while(right<n) {
			
			boolean good=true;
			for(int i=0;i<20;i++){
				if((tem[i]==1) && (bit[right][i]==1))
				{
//					System.out.println("ok"+" "+left+" "+right);
					good=false;
//					System.out.println(good);
					break;
				}
			}
			if(good==false){
//				System.out.println("WTFFF");
				break;
				
			}
			else{
				for(int i=0;i<20;i++)
				{
					if(bit[right][i]==1)
					{
						tem[i]=1;
					}
				}
				right++;
			}
				
			}
				
				ans+=right-left;
				
				for(int i=0;i<20;i++)
				{
					if(bit[left][i]==1)
					{
						tem[i]=0;
					}
				}
//			System.out.println(left+" "+right);	
			}
			System.out.println(ans);
			
		}
	}



Measured memory_bytes: 106320
class UnionFind(): 
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n 
        
    def find(self, x): 
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
            
    def union(self, x, y): 
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x,y = y,x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        
    def same(self, x, y): 
        return self.find(x) == self.find(y)  
        
N,M = map(int,input().split())
p = list(map(int,input().split()))
uf = UnionFind(N+1)
for i in range(M):
    x,y = map(int,input().split())
    uf.union(x,y)
cnt = 0
for i in range(1,N+1):
    if uf.same(i,p[i-1]):
        cnt += 1
print(cnt)        
    

Measured memory_bytes: 14452
n,k=map(int,input().split())
p=[int(i)-1for i in input().split()]
c=list(map(int,input().split()))
ans=-10**9
for i in range(n):
    start=i
    cycle=[0]
    for _ in range(n):
        i=p[i]
        cycle+=[cycle[-1]+c[i]]
        if i==start:break
    S,L=cycle[-1],len(cycle)-1
    if S<=0:ans=max(ans,max(cycle[1:k+1]))
    else:ans=max(ans,max(0,k//L-1)*S+max(max(cycle[:k+1]),max(cycle[:k%L+1])+S*(k>L))) 
print(ans)

Measured memory_bytes: 84264
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#define fuck(x) cout<<"["<<x<<"]";
#define FIN freopen("input.txt","r",stdin);
#define FOUT freopen("output.txt","w+",stdout);
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

const int MX = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;

struct Edge {
    int v, nxt;
} E[MX * 2];
int Head[MX], erear;
void edge_add(int u, int v) {
    E[erear].v = v;
    E[erear].nxt = Head[u];
    Head[u] = erear++;
}
void edge_init() {
    erear = 0;
    memset(Head, -1, sizeof(Head));
}

int n, IN[MX], root;
int A[MX], ok = 1;

void DFS(int u, int f) {
    LL sum = 0;
    int Max = 0, child = 0;
    for(int i = Head[u]; ~i; i = E[i].nxt) {
        int v = E[i].v;
        if(v == f) continue;
        DFS(v, u);
        sum += A[v];
        Max = max(Max, A[v]);
        child++;
    }
    if(!child) return;

    LL x = sum - A[u], y = 2LL * A[u] - sum;
    LL opt = min(sum - Max, sum / 2);

    if(x < 0 || y < 0 || x > opt || (u == root && y)) {
        ok = 0; return;
    }
    A[u] = y;
}

int main() {
    // FIN;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%d", &A[i]);
    }
    edge_init();
    for(int i = 1; i <= n - 1; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        edge_add(u, v);
        edge_add(v, u);
        IN[u]++; IN[v]++;
    }

    if(n == 2) {
        if(A[1] == A[2]) printf("YES\n");
        else printf("NO\n");
        return 0;
    }

    for(int i = 1; i <= n; i++) {
        if(IN[i] != 1) root = i;
    }

    DFS(root, -1);
    printf("%s\n", ok ? "YES" : "NO");
    return 0;
}

Measured memory_bytes: 10112
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#define file(s) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout);
using namespace std;
typedef long long ll;
const int MAXN = 200005;
const int MAXM = 550000;
const int ESIZE = MAXN << 1;
const int MOD = 924844033, G = 5;
int n, m;
int et, fir[MAXN], to[ESIZE], ne[ESIZE];
int jc[MAXN] = {1}, inv[MAXN];
int siz[MAXN];
int A[MAXM], B[MAXM], rev[MAXM];

int quick_pow(int a, int x) {
    int res = 1;
    while (x) {
        if (x & 1)
            res = 1ll * res * a % MOD;
        a = 1ll * a * a % MOD, x >>= 1;
    }
    return res;
}

void link(int u, int v) {
    to[++et] = v, ne[et] = fir[u], fir[u] = et;
}

void dfs(int o, int fa) {
    siz[o] = 1;
    for (int i = fir[o]; i; i = ne[i])
        if (to[i] != fa) {
            dfs(to[i], o);
            siz[o] += siz[to[i]];
        }
}

void ntt(int *A, int n, bool t) {
    for (int i = 0; i < n; i++)
        if (i < rev[i])
            swap(A[i], A[rev[i]]);
    for (int i = 1, gn, g, x, y; i < n; i <<= 1) {
        gn = quick_pow(G, (MOD - 1) / (i << 1));
        for (int j = 0; j < n; j += i << 1) {
            g = 1;
            for (int k = 0; k < i; k++) {
                x = A[j + k], y = 1ll * A[j + k + i] * g % MOD;
                A[j + k] = (x + y) % MOD, A[j + k + i] = (x - y + MOD) % MOD;
                g = 1ll * g * gn % MOD;
            }
        }
    }
    if (!t) {
        reverse(A + 1, A + n);
        int inv = quick_pow(n, MOD - 2);
        for (int i = 0; i < n; i++)
            A[i] = 1ll * A[i] * inv % MOD;
    }
}

void mul(int n, int m) {
    m += n, n = 1;
    int Log = 0;
    while (n <= m)
        n <<= 1, Log++;
    for (int i = 0; i < n; i++)
        rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (Log - 1));
    ntt(A, n, 1), ntt(B, n, 1);
    for (int i = 0; i < n; i++)
        A[i] = 1ll * A[i] * B[i] % MOD;
    ntt(A, n, 0);
}

ll calc_C(int n, int r) {
    return n < r ? 0 : 1ll * jc[n] * inv[r] % MOD * inv[n - r] % MOD;
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        jc[i] = 1ll * jc[i - 1] * i % MOD;
    inv[n] = quick_pow(jc[n], MOD - 2);
    for (int i = n; i; i--)
        inv[i - 1] = 1ll * i * inv[i] % MOD;
    for (int i = 1, x, y; i < n; i++) {
        scanf("%d %d", &x, &y);
        link(x, y), link(y, x);
    }
    dfs(1, 0);
    for (int i = 2; i <= n; i++) {
        A[siz[i]] = (A[siz[i]] + jc[siz[i]]) % MOD;
        A[n - siz[i]] = (A[n - siz[i]] + jc[n - siz[i]]) % MOD;
    }
    for (int i = 0; i <= n; i++)
        B[n - i] = inv[i];
    mul(n, n);
    for (int i = n + 1; i <= n << 1; i++) {
        A[i] = 1ll * A[i] * inv[i - n] % MOD;
        printf("%lld\n", (n * calc_C(n, i - n) % MOD - A[i] + MOD) % MOD);
    }
    return 0;
}


Measured memory_bytes: 22784
def is_integer_string?(str)
  Integer(str)
  true
rescue ArgumentError
  false
end

array = gets.split(' ').map do |i|
  if is_integer_string? i
    i.to_i
  else
    i
  end
end
stack = []
array.each do |value|
  if value.is_a?(String)
    pops = [stack.pop, stack.pop]
    eval("stack << #{pops[1]} #{value} #{pops[0]}")
    next
  end
  stack << value
end

puts stack



Measured memory_bytes: 6968
#include <stdio.h>
#include <string.h>

typedef struct{
  int data;
}dice;

void roll(char move,dice *a,dice *b,dice *c,dice *d,dice *e,dice *f)
{
  dice temp_a,temp_b;
  
  if(move == 'E'){//???
    temp_a = *c; //??????temp_a???
    *c = *a; //?????????
    temp_b = *f; //??????temp_b???
    *f = temp_a; //???(temp_a)??????
    temp_a = *d; //??????temp_a???
    *d = temp_b; //???(temp_b)??????
  }
  else if(move == 'N'){//???
    temp_a = *e;
    *e = *a; //?????????
    temp_b = *f;
    *f = temp_a; //?????????
    temp_a = *b;
    *b = temp_b; //?????????
  }
  else if(move == 'S'){//???
    temp_a = *b;
    *b = *a; //?????????
    temp_b = *f;
    *f = temp_a; //?????????
    temp_a = *e;
    *e = temp_b; //?????????
  }
  else if(move == 'W'){//???
    temp_a = *d;
    *d = *a; //?????????
    temp_b = *f;
    *f = temp_a; //?????????
    temp_a = *c;
    *c = temp_b; //?????????
  }
  *a = temp_a; //??±?????????
}

void spin(char move,dice *a,dice *b,dice *c,dice *d)
{
  dice temp;

  temp = *a; //??±?????????
  if(move == 'R'){ //???????????????????????????????¨??????????
    *a = *b;
    *b = *d;
    *d = *c;
    *c = temp;    
  }
  else if(move == 'L'){  //??????????????????????????????????¨??????????
    *a = *c;
    *c = *d;
    *d = *b;
    *b = temp;
  }

}

int main(void)
{
  int i,j,k;
  int da[5];
  int q;
  int top,front;

  for(i=0; i<6; i++){
    scanf("%d",&da[i]);
  }
  
  dice one[6] = {
    {da[0]}, //?????????????????°???
    {da[1]},
    {da[2]},
    {da[3]},
    {da[4]},
    {da[5]},
  };

  scanf("%d",&q);

  for(i=0; i<q; i++){
    scanf("%d%d",&top,&front);

    for(j=0; j<6; j++){
      if(one[j].data == top){
	break;
      }
    } //?????¨???top????????????one[j]???

    //?????????top???????????????
    if(j==1){
      roll('N',&one[0],&one[1],&one[2],&one[3],&one[4],&one[5]);
    }
    else if(j==2){
      roll('W',&one[0],&one[1],&one[2],&one[3],&one[4],&one[5]);
    }
    else if(j==3){
      roll('E',&one[0],&one[1],&one[2],&one[3],&one[4],&one[5]);
    }
    else if(j==4){
      roll('S',&one[0],&one[1],&one[2],&one[3],&one[4],&one[5]);
    }
    else if(j==5){
      roll('S',&one[0],&one[1],&one[2],&one[3],&one[4],&one[5]);
      roll('S',&one[0],&one[1],&one[2],&one[3],&one[4],&one[5]);
    }
    
    for(k=0; k<6; k++){
      if(one[k].data == front){
	break;
      }
    } //?????¨???front????????????one[k]???

    //?¬????front???????????????
    if(k==2){
      spin('R',&one[1],&one[2],&one[3],&one[4]);
    }
    else if(k==3){
      spin('L',&one[1],&one[2],&one[3],&one[4]);
    }
    else if(k==4){
      spin('R',&one[1],&one[2],&one[3],&one[4]);
      spin('R',&one[1],&one[2],&one[3],&one[4]);
    }
    
    printf("%d\n",one[2].data);
  }

  return(0);
}

Measured memory_bytes: 596
#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
    int a,b,x;
    scanf("%d %d %d",&a,&b,&x);
    if(a>x)
        printf("NO\n");
    else if(a+b>=x)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


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

int main() {
	char s[4], t[4];
	cin >> s;
	cin >> t;
	if (s[0] == t[2] && s[1] == t[1] && s[2] == t[0]) cout << "YES";
	else cout << "NO";
	return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/23  Problem: 068_arc_b / Link: https://arc068.contest.atcoder.jp/tasks/arc068_b?lang=en  ----- */
/* ------問題------

すぬけくんはカードゲームで遊ぶことにしました。 N 枚からなるカードの山があり、上から i 枚目のカードには整数 Ai が書かれています。
すぬけくんはこのカードの山に対し 0 回以上、以下の操作を行い、残ったカードに書かれた値が互いに異なるようにしたいです。最大で何枚のカードを残すことが可能か求めなさい。なお、N は奇数であり、少なくとも 1 枚のカードを残すことが可能であることが保証されます。
操作：カードの山から任意の 3 枚のカードを抜き出す。抜き出したカードのうち書かれた値が最大であるようなカード 1 枚と最小であるようなカード 1 枚の合計 2 枚を選んで食べる。その後残った 1 枚をカードの山に戻す。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	cin >> N;
	VI a(N);
	VI cnt(100005);
	FOR(i, 0, N) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	VI pq;
	FOR(i, 0, 100005) {
		if (cnt[i])pq.push_back(cnt[i]);
		
	}
	int even = 0;
	FOR(i, 0, SZ(pq)) {
		if (pq[i] % 2 == 0)even++;
	}
	ans = SZ(pq);
	if (even% 2 == 1)ans--;
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1660