akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
vector<int> es[114514];
char buf[114514];
int C[114514];
int cnt[114514];
bool dised[114514];
int sb;
int ans;

int Dfs(int v, int p) {
  assert(!dised[v]);

  int x = 1; // deg
  if (es[v].size()%2 != C[v]) x++;
  else x--;

  int m = x;
  for (int u : es[v]) {
    if (u == p) continue;
    int res = Dfs(u, v);
    MX(sb, res+m);
    MX(m, res+x);
  }
  return max(m, 0);
}

int main() {
  scanf("%d", &N);
  rep(i, N-1) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u;
    --v;
    es[u].eb(v);
    es[v].eb(u);
  }
  scanf("%s", buf);
  rep(v, N) {
    C[v] = buf[v] == 'W';
  }

  queue<int> que;
  rep(v, N) {
    if (es[v].size() <= 1 && C[v] == 0) {
      dised[v] = true;
      que.push(v);
    }
  }

  while (!que.empty()) {
    int v = que.front(); que.pop();
    for (int u : es[v]) {
      if (C[u] == 1) continue;
      if (dised[u]) continue;

      cnt[u]++;
      if (cnt[u]+1 >= es[u].size()) {
        dised[u] = true;
        que.push(u);
      }
    }
  }

  rep(v, N) {
    if (dised[v]) continue;
    vector<int> nes;
    for (int u : es[v]) {
      if (dised[u]) continue;
      nes.eb(u);
    }
    es[v].swap(nes);
    if (C[v] == 0) {
      assert(es[v].size() > 1);
    }
  }

  rep(v, N) {
    if (dised[v]) continue;
    ans += es[v].size();
    if (C[v] != (es[v].size()%2)) ans++;
  }

  sb = 0;
  rep(v, N) {
    if (dised[v]) continue;
    Dfs(v, v);
    break;
  }
  //printf("ans=%d, sb=%d\n", ans, sb);

  printf("%d\n", ans-sb);
}


Measured memory_bytes: 12160
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
using ll = long long;

int main(){
    ll c,d,e,k,l,m,n,o=0,p,q,x,y,z,max1=0,ans=0;
    string s,t,u;
    cin>>n;
    ll a[n],b[n];
    for (ll i=0; i<n; i++) {
        cin>>a[i];
    }
    for (ll i=0; i<n; i++) {
        cin>>b[i];
    }
    for (ll i=0; i<n; i++) {
        ans+=max(a[i]-b[i],o);
    }
    
    cout<<ans<<endl;
}



Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		int h = scanner.nextInt();
		int w = scanner.nextInt();
		
		int[][] a = new int[h][w];
		int[] b = new int[w];
		
		int c[] = new int[h];
		
		for(int i=0; i<h; i++)
		{
			for(int j=0; j<w; j++)
			{
				a[i][j] = scanner.nextInt();
			}
		}
		
		for(int i=0; i<w; i++)
		{
			b[i] = scanner.nextInt();
		}
		
		for(int i=0; i<h; i++)
		{
			c[i] = 0;
			for(int j=0; j<w; j++)
			{
				c[i] += a[i][j]*b[j];
			}
		}
		
		for(int i=0; i<h; i++)
		{
			System.out.println(c[i]);
		}
	}
}

Measured memory_bytes: 40264
//In the Name of God
//Ya Ali

#include <bits/stdc++.h>

#define int long long

#define err(A) cout << #A << " = " << (A) << endl

using namespace std;

const int M = 998244353;
const int maxx = 1010101;

int n, k;

int sum[maxx];
int sm2[maxx];

int z[maxx];

int ans;

int power(int x, int y)
{
  int ret = 1;
  while (y)
    {
      if (y & 1)
	ret = ret * x % M;
      x = x * x % M;
      y >>= 1;
    }
  return ret;
}

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

  cin >> n;

  for (int i = 0; i < n; i ++)
    {
      int x;
      cin >> x;
      (sum[x] += x) %= M;
      (sm2[x] += x * x) %= M;
    }

  for (int i = 1; i <= maxx; i ++)
    for (int j = i + i; j < maxx; j += i)
      {
	(sum[i] += sum[j]) %= M;
	(sm2[i] += sm2[j]) %= M;
      }

  for (int i = 1; i < maxx; i ++)
    z[i] = ((sum[i] * sum[i] - sm2[i]) % M + M) % M;
  
  for (int i = maxx; i; i --)
    for (int j = i + i; j < maxx; j += i)
      (z[i] -= z[j]) %= M;

  for (int i = 1; i < maxx; i ++)
    (ans += z[i] * power(i, M - 2)) %= M;

  ans = ans * power(2, M - 2) % M;
  ans = (ans + M) % M;
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 23808
//解説AC
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  if (a + b > n + 1LL || a * b < n) {
    cout << -1 << endl;
    return 0;
  }
  if (a >= b) {
    for (int i = 0; i < a; i++) {
      cout << n - a + i + 1 << " ";
    }
    n -= a;
    if (b <= 2) {
      for (int i = 1; i <= n; i++) {
        cout << i << " ";
      }
    } else {
      b--;
      for (int i = 0; i < n % b; i++) {
        for (int j = 0; j < n / b + 1; j++) {
          cout << n - (i + 1) * (n / b + 1) + j + 1 << " ";
        }
      }
      int nn = n - (n % b) * (n / b + 1);
      b -= n % b;
      if (b) {
        n = nn;
        a = n / b;
        for (int i = 0; i < n; i++) {
          cout << n - (i / a + 1) * a + i % a + 1 << " ";
        }
      }
    }
  } else {
    int N = n;
    a ^= b;
    b ^= a;
    a ^= b;
    for (int i = 0; i < a; i++) {
      cout << N + 1 - (n - a + i + 1) << " ";
    }
    n -= a;
    if (b <= 2) {
      for (int i = 1; i <= n; i++) {
        cout << N + 1 - i << " ";
      }
    } else {
      b--;
      for (int i = 0; i < n % b; i++) {
        for (int j = 0; j < n / b + 1; j++) {
          cout << N + 1 - (n - (i + 1) * (n / b + 1) + j + 1) << " ";
        }
      }
      int nn = n - (n % b) * (n / b + 1);
      b -= n % b;
      if (b) {
        n = nn;
        a = n / b;
        for (int i = 0; i < n; i++) {
          cout << N + 1 - (n - (i / a + 1) * a + i % a + 1) << " ";
        }
      }
    }
  }
  cout << endl;
}

Measured memory_bytes: 2176
import math


def divisor(div, N):
    # 約数
    i = 1
    n = N

    while i <= math.sqrt(n):
        if n % i == 0:
            div.append([i, n // i])
        i += 1


N = int(input())

cnt = 0

for i in range(1, N + 1):
    if i % 2 == 0:
        continue

    div = []
    divisor(div, i)

    if len(div) == 4:
        cnt += 1

print(cnt)


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

int main(){
  int k;
  cin >> k;
  int t=0;
  for(int i=1;i<=k;++i){
    for(int j=1;j<=k;++j){
      for(int m=1;m<=k;++m){
        t+=gcd(gcd(i,j),m);
      }
    }
  }
  cout << t << endl;
  return 0;
}

Measured memory_bytes: 3512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// namespace
using namespace std;
// type
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
// input
#define INIT              ({ ios::sync_with_stdio(false); cin.tie(0); })
#define VAR(type, ...)    type __VA_ARGS__; var_scan(__VA_ARGS__);
template<typename T>
static void var_scan(T& t)
{
    cin >> t;
}
template<typename T, typename... R>
static void var_scan(T& t, R&... rest)
{
    cin >> t;
    var_scan(rest...);
}
// output
#define OUT(var)          cout << (var)
#define SPC               cout << ' '
#define TAB               cout << '\t'
#define BR                cout << '\n'
#define ENDL              cout << endl
#define FLUSH             cout << flush
// debug
#ifdef DEBUG
#define EPRINTF(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
#define DUMP(var)         cerr << #var << '\t' << (var) << '\n'
#define DUMPITERABLE(i) do {                            \
        cerr << #i << '\t';                             \
        for (const auto& it : i) { cerr << it << ' '; } \
        cerr << '\n';                                   \
} while (0)
#define DUMPITERABLE2(i2) do {                          \
        cerr << #i2 << '\t';                            \
        for (const auto& it : i2) {                     \
            for (const auto& it2: it) {                 \
                cerr << it2 << ' ';                     \
            }                                           \
        }                                               \
        cerr << '\n';                                   \
} while (0)
#else
#define EPRINTF(fmt, ...)
#define DUMP(var)
#define DUMPITERABLE(i)
#define DUMPITERABLE2(i)
#endif
// util
// [l, r)
#define REP(i, n)       for (int i = 0; i < (n); i++)
#define RREP(i, n)      for (int i = (n)-1; i >= 0; i--)
#define FOR(i, l, r)    for (int i = (l); i < (r); i++)
#define RFOR(i, r, l)   for (int i = (r)-1; i >= (l); i--)
#define REPLL(i, n)     for (ll i = 0; i < (n); i++)
#define RREPLL(i, n)    for (ll i = (n)-1; i >= 0; i--)
#define FORLL(i, l, r)  for (ll i = (l); i < (r); i++)
#define RFORLL(i, r, l) for (ll i = (r)-1; i >= (l); i--)

int main(void)
{
    INIT;
    VAR(int, x);
    if (x)
        OUT(0);
    else
        OUT(1);
    ENDL;
    return 0;
}


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

struct edg{
    int u, v, w;
    edg(int u, int v, int w):u(u),v(v),w(w){}
};

vector<int> O;
vector<edg> E;
int L;
int n, m;

int main(){
    cin >> L;
    for(int i = 0; L; i++, L >>= 1){
        if(L & 1){
            O.push_back(i);
        }
    }
    n = O.back() + 1; O.pop_back();
    for(int i = 1; i < n; i++){
        E.emplace_back(i, i+1, 1 << i-1);
        E.emplace_back(i, i+1, 0);
    }
    int w = 1 << n-1;
    while(!O.empty()){
        int z = O.back() + 1; O.pop_back();
        E.emplace_back(z, n, w);
        w += 1 << z-1;
    }
    cout << n << ' ' << E.size() << '\n';
    for(edg &e : E){
        cout << e.u << ' ' << e.v << ' ' << e.w << '\n';
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;

ll solve() {
    int a, b, c, k; cin >> a >> b >> c >> k;
    if (k <= a) {
        return k;
    } else if (k <= a + b) {
        return a;
    } else if (k < a + b + c) {
        return a - 1 * (k - a - b); 
    } else {
        return a - c;
    }
}

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

	cout << solve() << endl;
}


Measured memory_bytes: 3648
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    int b = Integer.parseInt(clean(sc.nextLine()));
    sc.close();
    long r = (a * b) / 100;
    System.out.println(r);
  }
  
  private static String clean(String n) {
    int s = n.length();
    String ns = "";
    for(int i = 0; i < s; i++) {
      char c = n.charAt(i);
      if(c != ' ' && c != '.') ns += c;
    }
    return ns;
  }
}

Measured memory_bytes: 39048
N, K = map(int, input().split())
X = list(map(int, input().split()))

ans = float('inf')
for i in range(N - K + 1):
    l = X[i]
    r = X[i + K - 1]

    if l >= 0:
        ans = min(ans, abs(r))
    elif r <= 0:
        ans = min(ans, abs(l))
    else:
        ans = min(ans, 2 * abs(r) + abs(l), 2 * abs(l) + abs(r))

print(ans)


Measured memory_bytes: 14228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  ll n, m, l; cin >> n >> m >> l;
  vector<vector<ll>> d(n, vector<ll>(n, LINF));
  for(int i=0;i<n;++i) {
    d[i][i] = 0;
  }
  for(int i=0;i<m;++i) {
    int a, b, c; cin >> a >> b >> c;
    a--; b--;
    d[a][b] = c;
    d[b][a] = c;
  }
  for(int k=0;k<n;++k) {
    for(int i=0;i<n;++i) {
      for(int j=0;j<n;++j) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  vector<vector<ll>> ans(n, vector<ll>(n, LINF));
  for(int i=0;i<n;++i) {
    ans[i][i] = 0;
    for(int j=0;j<n;++j) {
      if(d[i][j] <= l) ans[i][j] = 1;
    }
  }
  for(int k=0;k<n;++k) {
    for(int i=0;i<n;++i) {
      for(int j=0;j<n;++j) {
        ans[i][j] = min(ans[i][j], ans[i][k] + ans[k][j]);
      }
    }
  }
  int q; cin >> q;
  while(q > 0) {
    q--;
    int s, t; cin >> s >> t;
    s--; t--;
    cout << (ans[s][t] >= LINF ? -1 : ans[s][t] - 1) << endl;
  }
}


Measured memory_bytes: 1920
def judge(s)
  s.size.times do |i|
    return false unless ((s[i] == 'h') || (s[i] == 'i'))

    if (i % 2) == 0 then
      return false unless s[i] == 'h'
    else
      return false unless s[i] == 'i'
    end
  end

  return true
end
 
s = gets.chomp
unless s.size % 2 == 0 then
  puts 'No'
else
  puts (judge(s) ? 'Yes' : 'No')
end

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

typedef long long ll;
using namespace std;
const ll INF = 1e18L + 5;

int main()
{
    ll n,w,sum_val=0,ans=0;
    scanf("%lld %lld",&n,&w);
    ll val[n],wgt[n];
    
    for(int i=0;i<n;i++)
    {
        scanf("%lld %lld",wgt+i,val+i);
        sum_val += val[i];
    }

    vector <ll> dp(sum_val+1,INF);
    dp[0] = 0;

    for(int i=0;i<n;i++)
    {
        for(int j=sum_val-val[i];j>=0;j--)
        {
            dp[j+val[i]] = min(dp[j+val[i]],dp[j]+wgt[i]);
        }
    }
    for(int i=0;i<=sum_val;i++)
    {
        if(dp[i]<=w)
            ans = max(ans, (ll)i);
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
using ll = long long;

int main(){
    int n;
    cin>>n;
    vector<int> a(n+2);
    ll sum=0;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=abs(a[i-1]-a[i]);
    }
    sum+=abs(a[n]-0);
    for(int i=1;i<=n;i++){
        cout<<sum-(abs(a[i-1]-a[i])+abs(a[i]-a[i+1]))+abs(a[i-1]-a[i+1])<<endl;
    }
}

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

#define ll long long 

void max_self(ll& a, ll b) {
    a = max(a, b);
}

int main() {
    int n,w;
    cin>>n>>w;
    vector<ll> dp(w+1, 0);
    for(int i = 0; i<n; i++){
		int weight, value;
		cin>>weight >> value;
		for(int j = w-weight; j >= 0; j--){
			dp[j+weight] = max(dp[j+weight], dp[j] + value);
			//cout<<j<<" " ;
		} 
		}
	//cout<<endl;
	ll ans = 0;
	for(int i = 0; i<=w; i++){
		ans = max(ans, dp[i]);
		}
	cout<< ans <<endl;
    
    }


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define M 100001
using namespace std;
int GCD(int a, int b)
{
	while (b != 0)
	{
		int d = a;
		a = b;
		b = d % a;
	}
	return a;
}
int main()
{
	int n;
	cin >> n;
	int a[M];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int c[M], b[M];
	b[0] = a[0];
	for (int i = 1; i < n; i++)
		b[i] = GCD(b[i - 1], a[i]);
	c[n - 1] = a[n - 1];
	for (int i = n - 2; i >= 0; i--)
		c[i] = GCD(c[i + 1], a[i]);
	int ans = 0;
	for (int i = 0; i < n; i++)
		if (i == 0)
			ans = max(ans, c[1]);
		else if (i == n - 1)
			ans = max(ans, b[n - 2]);
		else
		{
			int k = GCD(b[i - 1], c[i + 1]);
			ans = max(ans, k);
		}
	cout << ans;
	return 0;
}

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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

// chmax, chmin
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; }

int main() {
    int T,D,S;
    cin >> D >> T >> S;
    
    if ( D <= T * S ) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 3604
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>

using namespace std;

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

typedef vector<int> vi;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		int cnt = 0;
		while(n >= 5)
			cnt += n /= 5;
		printf("%d\n", cnt);
	}

	return 0;
}

Measured memory_bytes: 0
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main(void) {
	ll n, ans = 1;
	cin >> n;
	vector<ll> a(n);
	rep(i, 0, n) {
		cin >> a[i];
		if (a[i] == 0) {
			puts("0");
			return 0;
		}
	}
	rep(i, 0, n) {
		if (ans / 1000 * a[i] > 1000000000000000 || ans * a[i] > 1000000000000000000) {
			puts("-1");
			return 0;
		}
		ans *= a[i];
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 3996
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
int main(){
	int a;
	cin>>a;
	string s="";
	int t=-1;
	while(a){
		if(a%2){
			a+=t;
			s="1"+s;
		}else s="0"+s;
		a/=2;
		t*=-1;
	}
	if(s=="")s="0";
	cout<<s<<endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string a,b;
    cin>>a;
    for(int i=0;i<a.size();i++)
    {
        cout<<'x';
    }
}

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

const int Max = 1005;
int c[Max][Max];

void lcs(string s1, string s2)
{
    //memset(c, 0, sizeof(c));
    for(int i=0; i<=s1.size(); i++)
    {
        c[i][0] = 0;
    }
    for(int i=0; i<=s2.size(); i++)
    {
        c[0][i] = 0;
    }
    s1 = " " + s1;
    s2 = " " + s2;
    for(int i=1; i<=s1.size(); i++)
    {
        for(int j=1; j<=s2.size(); j++)
        {
            if(s1[i]==s2[j]) c[i][j] = c[i-1][j-1]+1;
            else
            {
                c[i][j] = max(c[i][j-1], c[i-1][j]);
            }
        }
    }
}
int main()
{
    int n;
    cin >> n;
    string s1, s2;
    for(int i=0; i<n; i++)
    {
        cin >> s1 >> s2;
        lcs(s1, s2);
        cout << c[s1.size()][s2.size()] << endl;
    }
    return 0;
}



Measured memory_bytes: 7068
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 500005;
const int mod = 1000000007;

struct ST {
  int l, r, val;
}st[maxn * 4];
string s;
void up(int id){
  st[id].val = st[id<<1].val | st[id<<1|1].val;
}
void build(int id, int l ,int r){
  st[id].l = l,st[id].r = r;
  st[id].val = 0;
  if(l==r){
    st[id].val = (1<<(s[l-1]-'a'));
    return;
  }
  int m = (l+r)>>1;
  build(id<<1,l,m);
  build(id<<1|1,m+1,r);
  up(id);
}

void upd(int id, int pos, int val){
  if(st[id].l==st[id].r){
    st[id].val = (1<<val);
    return;
  }
  int m = (st[id].l+st[id].r)>>1;
  if(pos<=m)upd(id<<1,pos,val);
  else upd(id<<1|1,pos,val);
  up(id);
}
int query(int id, int l, int r){
  if(st[id].l==l&&st[id].r==r){
    return st[id].val;
  }
  int m = (st[id].l+st[id].r)>>1;
  if(r<=m)return query(id<<1,l,r);
  if(l>m)return query(id<<1|1,l,r);
  return query(id<<1,l,m)|query(id<<1|1,m+1,r);
}

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
 int n,q;
 cin>>n>>s>>q;
 build(1,1,n);
 while(q--){
   int o;
   cin>>o;
   if(o==1){
     int p;
     char c;
     cin>>p>>c;
     upd(1, p,c-'a');
   } else {
     int x,y;
     cin>>x>>y;
     int tt = query(1,x,y);
     int ret = 0;
     for(int i=0;i<26;i++)if(tt&(1<<i))ret++;
     cout<<ret<<endl;
   }
 }
 return 0;
}

Measured memory_bytes: 15236
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
#n = int(input())
a, v = map(int, sys.stdin.readline().split())
#s = input()
#a = list(map(int, sys.stdin.readline().split()))
     

b, w = map(int, sys.stdin.readline().split())
t = int(input())


if a > b:
    x = a - b
if b > a:
    x = b - a

if x <= t * (v-w):
    print("YES")
else:
    print("NO")
    





















Measured memory_bytes: 9928
//https://www.cnblogs.com/shuitiangong/
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<climits>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define endl '\n'
#define rtl rt<<1
#define rtr rt<<1|1
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid+1, r
#define maxx(a, b) (a > b ? a : b)
#define minn(a, b) (a < b ? a : b)
#define zero(a) memset(a, 0, sizeof(a))
#define INF(a) memset(a, 0x3f, sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define _test printf("==================================================\n")
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> P2;
const double pi = acos(-1.0);
const double eps = 1e-7;
const ll MOD =  1000000007LL;
const int INF = 0x3f3f3f3f;
const int _NAN = -0x3f3f3f3f;
const double EULC = 0.5772156649015328;
const int NIL = -1;
template<typename T> void read(T &x){
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
const int maxn = 1e2+10;
int n, m, d[maxn]; vector<int> edge[maxn];
bool bfs() {
    INF(d);
    queue<int> que;
    que.push(1);
    while(!que.empty()) {
        int u = que.front(); que.pop();
        if (!d[u]) continue;
        d[u] = 0;
        for (auto it : edge[u])
            if (d[it]) que.push(it);
    }
    for (int i = 1; i<=n; ++i)
        if (d[i]) return true;
    return false;
}
int main(void) {
    while(~scanf("%d%d", &n, &m)) {
        for (int i = 0, a, b; i<m; ++i) {
            scanf("%d%d", &a, &b);
            edge[a].push_back(b);
            edge[b].push_back(a);
        }
        int ans = 0;
        for (int i = 1; i<=n; ++i) {
            for (auto it = edge[i].begin(); it != edge[i].end(); ++it) {
                int tmp = *it;
                edge[i].erase(it);
                ans += bfs();
                edge[i].insert(edge[i].begin(), tmp);
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();

        while (n >= 1000) {
            n = n - 1000;
        }
        if (n != 0 && 1000 >= n) {
            n = 1000 - n;
        }

        out.println(n);
    }
}

Measured memory_bytes: 35752
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep_start(a,i,n) for(ll i=a;i<=n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define rev1(i,n) for(ll i=n;i>0;i--)
#define sort(x) sort(x.begin(),x.end())
#define reverse(x) reverse(x.begin(),x.end())
#define zero0(x,n) fill(x.begin(),x.begin()+n,0)
#define zero1(x,n) fill(x.begin(),x.begin()+n,1)
#define zero(x) fill(x.begin(),x.end(),0)
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int> >
#define vb vector<bool>
#define pii pair<int,int>
#define F first
#define S second
#define INF 1e9+7
typedef long long int ll;

bool palin(string s){
    int l=s.length();
    bool palindrome=true;
    rep(i,l/2) if(s[i]!=s[l-i-1]) palindrome=false;
    return palindrome;
}

void solve(){
    string s;
    cin>>s;
    int n=s.length();
    if(palin(s) && palin(s.substr(0,(n-1)/2)) && palin(s.substr((n+3)/2-1))) cout<<"Yes";
    else cout<<"No";
}

signed main() {
    // your code goes here
    IOS
    ll t=1;
    //cin>>t;
    rep1(i,t){
        solve(); 
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N, H; cin >> N >> H;
	vector<pair<int, int>>vec(N);
	int mx = 0;
	rep(i, 0, N) {
		int a, b; cin >> a >> b;
		chmax(mx, a);
		vec[i] = make_pair(b, a);
	}
	sort(all(vec), greater<pair<int,int>>());
	int dmg = 0, ans = 0;
	rep(i, 0, N) {
		if (mx < vec[i].first) {
			dmg += vec[i].first;
			ans++;
		}
		if (dmg >= H)break;
	}
	H -= dmg;
	if (H > 0) ans += (H + mx - 1) / mx;
	cout << ans << "\n";

	return 0;
}

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

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

  vector<int> P(N),Q(N);
  for(int i = 0;i < N;i++) {
    cin >> P.at(i);
    Q.at(P.at(i)-1) = i;
  }

  int M = 0,num = 1;
  for(int i = 0;i < N-1;i++) {
    if(Q.at(i) < Q.at(i+1)) num++;
    else {
      M = max(M,num);
      num = 1;
    }
  }

  M = max(M,num);
  cout << N-M << endl;


}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string arr,brr;
  cin>>arr>>brr;
  int i,j;
  int l1,l2;
  l1=arr.length();
  l2=brr.length();
  int cnt=0;
  for(i=0;i<l1;i++)
  {
    if(arr[i]==brr[i])
      cnt++;
  }
  if(cnt==l1)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<ctime>
#include<climits>
#include<queue>
#include<cmath>
#include<vector>
using namespace std;
const int N=2010;
int n;
int a[N],book[N],map[N][N];
vector<int> v[N];
priority_queue<int> q;
void ff(int x)
{
	book[x]=1;
	for(int i=2;i<=n;i++) 
	{
		if(book[i] || map[x][i]==0) continue;
		v[x].push_back(i);
		ff(i);
	}
}
int main()
{
    int i,j,x;
    scanf("%d",&n);
    for(i=1;i<=n;i++) scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(i=1;i<=n;i++) for(j=i+1;j<=n;j++) if(__gcd(a[i],a[j])>1) map[i][j]=map[j][i]=1;
    for(i=1;i<=n;i++) if(!book[i]) ff(i),q.push(i);
	while(!q.empty())
    {
    	x=q.top(),q.pop();
    	cout<<a[x]<<" ";
    	for(i=0;i<v[x].size();i++) q.push(v[x][i]); 
	}
}

Measured memory_bytes: 16256
#include<iostream>
using namespace std;
int main(void){
    string n;
    cin >> n;
    int a1 = 0, a2 = 0;
    for(int i = 0; i < 3; i++){
        if(n[0] == n[i]){
            a1 += 1;
        }
    }
    if(a1 == 3){
        cout << "Yes" <<endl;
        return 0;
    }
    for(int i = 1; i < 4; i++){
        if(n[1] == n[i]){
            a2 += 1;
        }
    }
    if(a2 == 3){
        cout << "Yes" <<endl;
    }else if(a1 != 3 && a2 != 3){
        cout << "No" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
//Author: Herson Rezende - 2ºSemestre de CC - UFBA - 2020
//Site: hrezend.github.io/resume-web
#include <bits/stdc++.h>
#define desync ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define all(x) (x.begin(), x.end())
#define rall(x) (x.rbegin(), x.rend())
#define mkp(x,y) (make_pair(x,y))
#define out(x) cout << x << endl
using namespace std;

int main(){
	desync;
	int n, count_ac = 0, count_wa = 0, count_tle = 0, count_re = 0;
	string input;
	
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> input;
		if(input == "AC"){
			count_ac++;
		}
		else if(input == "RE"){
			count_re++;
		}
		else if(input == "TLE"){
			count_tle++;
		}
		else if(input == "WA"){
			count_wa++;
		}
	}
	
	cout << "AC x " << count_ac << endl;
	cout << "WA x " << count_wa << endl;
	cout << "TLE x " << count_tle << endl;
	cout << "RE x " << count_re << endl;
}


Measured memory_bytes: 3632
def main():
    n = int(input())

    dic = {}

    for _ in range(n):
        cmd, key = input().split(' ')

        if 'insert' == cmd:
            dic[key] = key

        if 'find' == cmd:
            if key in dic:
                print('yes')
            else:
                print('no')

if __name__ == '__main__':
    main()



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


public class C
{
	public static void Main()
	{
		int N = Int32.Parse(Console.ReadLine());
		long[] T = new long[N];
		for(int i = 0; i < N; i++)
			T[i] = Int64.Parse(Console.ReadLine());

		long lcm = T[0];
		for(int i = 1; i < N; i++)
			lcm = getLcm(lcm, T[i]);
		Console.WriteLine(lcm);
	}

	private static long getGcd(long x, long y)
	{
		return (y == 0) ? x : getGcd(y, x % y);
	}

	private static long getLcm(long x, long y)
	{
		long gcd = getGcd(x,y);
		return (x/gcd) * y;  // x * y / gcd => overflow
	}
}





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

using namespace std;

#define int long long
#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll N=1e5+10,M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
const int INF=1e9+7;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}

#define trace(...) cerr<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma=strchr(names+1,',');
    cerr.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1,args...);
}

int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    cin >> a >> b;
    for(int i=1; i<=100000; i++){
        if((8*i)/100 == a && (10*i)/100 == b){
            cout << i;
            return 0;
        }
    }
    cout << -1;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        String s = scanner.next();
        int[] a = new int[2019];
        int n = s.length();
        int ten = 1;
        int total = 0;
        a[0]++;
        for(int i = 1; i <= n; i++){
            total += (s.charAt(n-i) - '0') * ten;
            ten = ten * 10 % 2019;
            total %= 2019;
            a[total]++;
        }
        int ans = 0;
        for(int i = 0; i < 2019; i++){
            ans += a[i] * (a[i] - 1) / 2;
        }
        System.out.println(ans);
    }
}


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

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
    cout << "vowel" << endl;
    }
  else {
    cout << "consonant" << endl;
    }
}

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

#define forn(x,n,s) for(int i = x; i < n; i += s )
#define forr(x,n,s) for(int i = x; i>=n; i -= s)

using namespace std;

void go(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  #ifndef ONLINE_JUDGE
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
  #endif
}

int main(){
    go();

    // code here
    long long int n;cin>>n; 
    string sol = "";
    while(n){
        n--;
        char temp = 'a' + (n%26);
        sol = temp + sol;
        n /= 26;
    }
    cout<<sol;
}






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

int main()
{
    int n;
    cin >> n;
    //vector<string> box(n);
    string a;
    set<string> s;
    rep(i,n){
    cin >> a;
    s.insert(a);
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 19232
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint 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 COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
    lint dp[3100][3100];
  int main(){
     lint n,t;
     cin>>n>>t;
     P p[n];
     rep(i,n){
         lint a,b;
         cin>>a>>b;
         p[i]=make_pair(a,b);
     }
     sort(p,p+n);
    rep(i,n){
        rep(j,t+1){
            if(j-p[i].first>=0)chmax(dp[i+1][j],dp[i][j-p[i].first]+p[i].second);
             chmax(dp[i+1][j],dp[i][j]);
        }
    }
    lint ans=0;
    rep(i,n){
        ans=max(ans,dp[i][t-1]+p[i].second);
    }
    cout<<ans<<endl;
    }
      
    
  

Measured memory_bytes: 76304
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  //入力
  int N;
  std::cin >> N;
  std::vector<int> L;
  int l;
  while (std::cin >> l) {
    L.push_back(l);
  }
  //ソート
  std::sort(L.begin(), L.end());
  
  //大きい方から2つ選んで、小さい方をたす。
  int size = L.size();
  int result;
  for(int i = 0; i < N; i++) { 
    for(int j = 0; j < 2; j++) {
      size = size - 1;
    }
    result += L[size];
  }
  std::cout << result << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL  long long
#define LIM 400


LL dp[LIM+5][LIM+5], ara[LIM+5], csum[LIM+5];
bool vis[LIM+5][LIM+5];
int n;

LL f(int lft, int rht){
    if(lft == rht) return 0;
    if(lft > rht) return 1e15;
    if(vis[lft][rht]) return dp[lft][rht];
    vis[lft][rht] = 1;
    LL ans = 1e15;
    for(int k = lft; k <  rht; k++){
        LL cur = f(lft, k) + f(k+1, rht) + (csum[rht] - csum[lft-1]);
        ans = min(ans, cur);
    }
    return dp[lft][rht] = ans;
}

int main(){
    cin>>n;
    for(int i = 1; i <= n; i++) cin>>ara[i];
    for(int i = 1; i <= n; i++) csum[i] = csum[i-1] + ara[i];
    LL res = f(1, n);

    cout<<res<<'\n';
}




Measured memory_bytes: 5056
#include<stdio.h>
int main( ){
  int n,a[100];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(int j=n-1;j>=0;j--){
    printf("%d",a[j]);
    if(j!=0)printf(" ");
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 2736
#include <bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

int search(int A[],int n,int key){
  int i=0;
  A[n]=key;
  while(A[i]!=key) i++;
  return i!=n;
}

int main(){
  int i,n,A[10001],q,key,sum=0;
  cin>>n;
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  cin>>q;
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(search(A,n,key)) sum++;
  }
  cout<<sum<<endl;
  return 0;
}


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

int main()
{
    int x, y;
    int group[13];

    group[1] = group[3] = group[5] = group[7] = group[8] = group[10] = group[12] = 1;
    group[4] = group[6] = group[9] = group[11] = 2;
    group[2] = 3;

    cin >> x >> y;

    if (group[x] == group[y]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

int main(){
  int N,count=0;
  cin >> N;
  for(int i=0;i<N;i++){
    int A=log10(i+1)+1;
    if(A%2==1){
      count++;
    }
  }
  cout << count << endl;
} 

Measured memory_bytes: 3972
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (int i = 0; i < (o);i++)
#define rep_s(i, o) for (int i = 1; i < (o);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }


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

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

ull middle(ull a, ull b, ull c) 
{ 
    // Checking for b 
    if ((a <= b && b < c) || (c <= b && b < a)) 
       return b; 
  
    // Checking for a 
    else if ((b <= a && a < c) || (c <= a && a < b)) 
       return a; 
  
    else
       return c; 
} 

int main() {
    const ull INF = 1e9 + 7;
    ull a, b, c;
    cin >> a >> b >> c;
    ull blocks[3] = {a, b, c};
    ull min_block = min({a,b,c});
    ull max_block = max({a,b,c});
    ull mid_block = middle(a,b,c);

    ull min_blocks_for_cuboid = 0;
    if (a%2 != 0 && b%2 != 0 && c%2 != 0) min_blocks_for_cuboid = min({a*b, b*c, c*a});
    else min_blocks_for_cuboid = 0;
    cout << min_blocks_for_cuboid << endl;
    return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	
	long long int N, K, res = -1000000009;
	vector<long long int> P, C;
	vector<vector<long long int>> loopLS;
	vector<vector <long long int>> DP;
	cin >> N >> K ;
 
	P.resize(N+1);
	C.resize(N+1);
	loopLS.resize(N+1);	
 
	for(int i = 1; i<N+1; i++){
		long long int tmp;
		cin >> tmp;
		P[i] = tmp;
	}
	for(int i = 1; i<N+1; i++){
		long long int tmp;
		cin >> tmp;
		C[i] = tmp;
	}
 
	for(int i = 1; i<N+1; i++){
		int tmpIdx = i, loopLength = 0;
		long long int loopSum = 0;
		rep(j, N+1){
			tmpIdx = P[tmpIdx];
			loopSum += C[tmpIdx];
			if(tmpIdx == i){
				loopLength = j+1;
				loopLS[i].push_back(loopLength);
				loopLS[i].push_back(loopSum);
				break;
			}
		}

	}
 
	for(int i = 1; i<N+1; i++){
		int tmpIdx = i;
		long long int sum = 0;
		rep(j, N+1){
			if(j+1 > K){
				break;
			}
			tmpIdx = P[tmpIdx];
			sum += C[tmpIdx];
			
			if(loopLS[i][1] <= 0 || K < loopLS[i][0]){
				res = max(res, sum);
			}else{
				res = max(res, sum + loopLS[i][1] * ((K-(j+1))/loopLS[i][0]));
			}
			
		}
		
	}
 
	
	cout << res;
 
	return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n, m;
vector<int> g[maxn], rg[maxn];

int tout[maxn];
int cloc = 1;
bool viz[maxn];

void dfs(int at) {
    if (viz[at]) return;
    viz[at]=true;
    for (int to: g[at]) {
	dfs(to);
    }
    
    tout[at] = cloc++;
}
    

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

    cin>>n>>m;
    for (int i=0; i<n-1+m; i++) {
	int u,v;
	cin>>u>>v;
	g[u].push_back(v);
	rg[v].push_back(u);
    }


    int root=1;
    while (root<=n && rg[root].size()) root++;
    assert(root<=n);
    dfs(root);

    for (int i=1; i<=n; i++) {
	if (root==i) {
	    cout<<"0\n";
	    continue;
	}

	assert(rg[i].size());
	int x=rg[i][0];
	for (int p: rg[i]) {
	    if (tout[p] < tout[x]) {
		x=p;
	    }
	}
	cout<<x<<"\n";
    }
    
    
    return 0;
}


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

int main(){
	int n;
	cin>>n;
	long long s=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				s+=__gcd(__gcd(i,j),k);
			}
		}
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int k;
 
int gcd(int a, int b){
    if(b == 0) return a;
 
    return gcd(b, a%b);
}
 
int main(){
   
   string s;
   cin >> s;

    int num = s.size();
    int cnt = 0;
    rep(i,num/2){
        if(s[i]==s[num-1-i]) continue;
        else cnt++;
    }

    cout << cnt;

    return 0;
}

Measured memory_bytes: 256
import numpy as np
N, M = map(int, input().split())
tmp = np.array([1]*M)
for n in range(N):
  K_A = list(map(int,input().split()))
  # K = K_A[0]
  A = K_A[1:]
  tmp_n = np.array([0]*M)
  for a in A:
    tmp_n[a-1] = 1
  tmp = tmp*tmp_n
print(sum(tmp))

Measured memory_bytes: 12616
from collections import Counter
from itertools import product

N=int(input())
V=list(map(int,input().split()))

# 出現回数
O_cnt,E_cnt=Counter(V[::2]),Counter(V[1::2])
O_cnt[-1]=0
E_cnt[-2]=0

# 出現回数順
O_key,E_key=O_cnt.most_common(2),E_cnt.most_common(2)

ans=float('inf')

for O_k,E_k in product(O_key,E_key):
    if O_k[0]!=E_k[0]:
	    ans=min(ans,N-O_k[1]-E_k[1])
print(ans)


Measured memory_bytes: 18656
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()


int w[10];
int k[10];

int main() {
  rep(i, 10) cin >> w[i];
  rep(i, 10) cin >> k[i];

  sort(w, w+10);
  sort(k, k+10);
  cout << w[9]+w[8]+w[7] << " " << k[9]+k[8]+k[7] << "\n";
  return 0;
}

Measured memory_bytes: 1172