akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define sz(a) int(a.size())
#define clr(a) memset(a,0,sizeof(a))
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int mod=1;
template<typename T=int>
T gi() {
    T x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
string to_string(string s) { return '"'+s+'"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b?"true":"false"); }
template<typename A,typename B> string to_string(pair<A,B> p) {
    return "("+to_string(p.fi)+","+to_string(p.se)+")";
}
template<typename T> string to_string(T v) {
    int fst=1;string ret="{";
    for(auto x:v) {
        if(!fst) ret+=",";
        fst=0,ret+=to_string(x);
    }
    ret+="}";return ret;
}
void dbg_out() { cerr<<endl; }
template<typename Head,typename... Tail> void dbg_out(Head H,Tail... T) {
    cerr<<" "<<to_string(H);
    dbg_out(T...);
}
#define dbg(...) cerr<<"{"<<#__VA_ARGS__<<"}:",dbg_out(__VA_ARGS__)

template<typename T>
int qpow(int a,T b) {
    int ret=1;
    while(b) {
        if(b&1) ret=1ll*ret*a%mod;
        a=1ll*a*a%mod,b>>=1;
    }
    return ret;
}

const int N=2e5+10;

int n,rmx=-inf,rmn=inf,bmx=-inf,bmn=inf;
pii a[N];
ll ans;

int main() {
    n=gi();
    for(int i=1;i<=n;i++) {
        a[i].fi=gi(),a[i].se=gi();
        if(a[i].fi>a[i].se) swap(a[i].fi,a[i].se);
        chkmax(rmx,a[i].fi);
        chkmin(rmn,a[i].fi);
        chkmax(bmx,a[i].se);
        chkmin(bmn,a[i].se);
    }
    ans=1ll*(rmx-rmn)*(bmx-bmn);
    rmx=bmx;
    sort(a+1,a+n+1);
    bmx=-inf,bmn=inf;
    for(int i=1;i<n;i++) {
        chkmax(bmx,a[i].se);
        chkmin(bmn,a[i].se);
        chkmin(ans,1ll*(max(bmx,a[n].fi)-min(bmn,a[i+1].fi))*(rmx-rmn));
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1920
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    string s; cin >> s;

    bool ans = true;
    REP(i, s.size()) {
        if (i % 2 == 0) {
            if (s[i] == 'L') {
                ans = false;
                break;
            }
        } else {
            if (s[i] == 'R') {
                ans = false;
                break;
            }
        }
    }
    cout << Yes(ans) << endl;
    
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long ans = 0l;
        for (int i = 0; i < n; i++) {
            ans += sc.nextLong() - 1;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 40696
n,m,x=gets.split.map(&:to_i)
a=n.times.map{gets.split.map(&:to_i)}
ans = Float::INFINITY
(1...2**n).each do |i|
  list=[]
  i.to_s(2).rjust(n,"0").each_char.with_index do |s,i|
    list << a[i] if s==?1
  end
  list=list.transpose
  money=list.shift.sum
  flag=true
  list.each {|l|flag = false if l.sum < x}
  ans = [ans,money].min if flag
end
p ans==Float::INFINITY ? -1 : ans


Measured memory_bytes: 14476
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

// https://drken1215.hatenablog.com/entry/2019/10/05/173700
// https://www.youtube.com/watch?v=-o4r74eJzV4

// i 段目, j 個残してる, 奇妙さ
int dp[55][55][55 * 55];
void solve() {
  int n, K;
  cin >> n >> K;

  // |i - pi| は, 1 ずつ繰り越していく
  dp[0][0][0] = 1;
  rep(i, n) rep(j, i + 1) rep(k, K + 1) { // debuged, K*K to K
    // 横と結ぶ
    // 残ってる j 分, 奇妙さを 1 繰越す
    add(dp[i + 1][j][k + j * 2], dp[i][j][k]);
    // 下, 下
    // 自分も含めて奇妙さを 1 繰越す
    add(dp[i + 1][j + 1][k + (j + 1) * 2], dp[i][j][k]);
    // 上, 下
    // 片方を上と結んでも保留の個数は変わらない
    // 下と結ぶ方は i 個目が保留だが, 上のどこかが結ばれる
    // dp[i][j][k] * j*2 : 上と結ぶ方は j 通りの選択肢があり, どっちを上と結ぶ方にするかの *2
    add(dp[i + 1][j][k + j * 2], 1LL * dp[i][j][k] * j * 2 % mod);
    // 上, 上
    // 減った 1 つ分以外奇妙さ 1 繰り越し
    // 選ぶ候補は残ってる j 個ずつ
    if (j - 1 >= 0) add(dp[i + 1][j - 1][k + (j - 1) * 2], 1LL * dp[i][j][k] * j * j % mod);
  }
  cout << dp[n][0][K] << endl;
  /*
  rep(i, n + 1) {
    cout << endl;
    rep(j, i + 1) { rep(k, K + 1) cout << dp[i][j][k] << " "; cout << endl; }
  }
  */
}


Measured memory_bytes: 33152
#include<bits/stdc++.h>
using namespace std ;
typedef  long long int ll ;
#define inf ll(1e18)
#define mod 1000000007
#define mod1 998244353
#define mod2 999983
ll power(ll a,ll n,ll m) ;
ll power(ll a,ll n,ll m)
{  if(n==0)
   return 1 ;
   ll x=power(a,n/2,m) ;
   if(n%2!=0)
    return (((a*x)%m)*(x)%m)%m ;
    else return (x*x)%m ;
}
map<ll,ll>::iterator itr ;
ll ans ;
double PI=3.14159265357 ;
int32_t main()
{ ll n,i,j,x,y,m,k,t,sum,count,cnt,b,c,d,j1,z,a,o,temp;
  ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
  cin>>n ;
  cnt=0 ;
  sum=0 ;
  while(n%2==0)
  {
      sum++ ;
      n=n/2 ;
  }
  x=0 ;
for(i=1;x+i<=sum;i++)
{
    x+=i ;
    cnt++ ;
}
for(i=3;i<=sqrt(n);i+=2)
{
    sum=0 ;
    while(n%i==0)
    {
        sum++ ;
        n=n/i ;
    }
      x=0 ;
for(j=1;x+j<=sum;j++)
{
    x+=j ;
    cnt++ ;
}

}
if(n!=1)
    cnt++ ;
cout<<cnt ;
return  0; }


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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int count1 = 0;
  int count2 = 0;
  for(int i=0; i<n;) {
    if(s.at(i) != '0') {
      count1++;
    } else {
      count2++;
    }
    i++;
    if(i>=n) {
      break;
    }
    
    if(s.at(i) != '1') {
      count1++;
    } else {
      count2++;
    }
    i++;
  }
  
  int ans = min(count1, count2);
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include<stack>
#include<queue>

#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007


using namespace std;

void solve()
{
    int N, M;
    cin >> N >> M;
    ll sum = 0;


    for (int i = 0; i < M; i++)
    {
        ll x;
        cin >> x;
        sum += x;
    }

    cout << max(-1LL, N - sum);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T = 1;
    //cin >> T;
    while (T--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3668
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=110;
LL gbs(LL a,LL b){
    return a/(__gcd(a,b))*b;
}
int main()
{
    int n;
    long long t[N];
    while(~scanf("%d",&n)){
        LL maxt=1;
        for(int i=0;i<n;i++){
            scanf("%lld",&t[i]);
            maxt=gbs(maxt,t[i]);
        }
        printf("%lld\n",maxt);
    }

    return 0;
}


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

using namespace std;
#define inf 1e9
int frog(vector<int> a,int n)
{
    vector<int> dp(n+1);
    dp[1]=0;
    for(int i=2;i<=n;i++)
    {
        int option1= abs(a[i-1]-a[i]) + dp[i-1];
        int option2= i==2? inf :abs(a[i-2]-a[i]) + dp[i-2];
        dp[i]=min(option1,option2);
    }
    return dp[n];
    
}

int main()
{
   int n;
   cin>>n;
   vector<int> v(n+1);
   for(int i=1;i<=n;i++)
   {
       cin>>v[i];
   }
   cout<<frog(v,n)<<endl;
   
   return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;

    bool  flag = false;
    for(int i = 0 ; i<s.length();i++)
    {
        if(s[i] == '9')
            flag = true;
    }
    if(flag)
        printf("Yes");
    else
        printf("No");
    return 0;
}


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

int main(){
    ll a,b,c;
    cin >> a >> b >> c;
    if(a%2 != 0 || b%2 != 0 || c%2 != 0){
        cout << 0 << endl;
        return 0;
    }
    if(a == b && b== c){
        cout << -1 << endl;
      	return 0;
    }
    int cnt = 0;
    while(true){
        ll x = (a+b)/2;
        ll y = (b+c)/2;
        ll z = (a+c)/2;
        a = x,b = y,c = z;
        cnt++;
        if(a%2 != 0 || b%2 != 0 || c%2 != 0){
            break;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [float('inf')]*N

dp[0] = 0
dp[1] = abs(H[1]-H[0])

for i in range(2, N):
    dp[i] = min([dp[i-v]+abs(H[i]-H[i-v]) for v in range(1, min(i, K)+1)])
print(dp[-1])


Measured memory_bytes: 55132
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define all(a)  (a).begin(),(a).end()
#define elif else if

signed main(){
  double a,b;
  cin>>a>>b;
  int d=-1;
  if(a==79&&b==100)
    cout<<d<<endl;
  else if(a==80&&b==99)
    cout<<d<<endl;


  else{
    for(double i=1; i<1001; i++){
      if(i*0.08>=a&&i*0.1>=b&&i*0.08<a+1&&i*0.1<b+1){
        d=i;
        break;
      }
      else if(i*0.08>=a+1&&i*0.1<b) 
        break;
      else if(i*0.08<a&&i*0.1>=b+1)
        break;
    }
    cout<<d<<endl;
  }
}



Measured memory_bytes: 256
C = input()
ALL = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

for i in range(26):
    if C == ALL[i]:
        print(ALL[i+1])
        break 

Measured memory_bytes: 3060
//
//  CPlibrary
//
//  Created by Tanmay Singh on 3/03/2020.
// INDIAN INSTITUTE OF TECHNOLOGY (BHU) , VARANASI
//  Copyright © 2020 Tanmay Singh. All rights reserved.
//#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
 
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <climits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
 
#define FAST(); ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define mod 1000000007
typedef long long int  bigint ;
typedef std::vector< int > vi;
typedef std::vector< long long int > vll;
typedef std::vector< vi > vvi;
 
using namespace std;

int main(){
    FAST() ;
    int N ; cin >> N ;
    int arr[N] ;
    for( int i = 0 ; i < N ; i++ )
        cin >> arr[i] ;
    bigint ans = pow(3,N) ;
    bigint minus = 1 ;
    for( int i = 0 ; i < N ; i++ ){
        if( arr[i] % 2 == 0 )
            minus *= 2 ;
    }
    cout << ans - minus << endl ;
    return 0 ;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
  int cnt = 0;
  string s;
  cin >> s;
  for(int i = 0; i < 3; i++){
    if(s[i] == '1'){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    string s;
    cin>>s;
    ll cnt1=0,cnt2=0;
    for(auto &I:s){
        if(I=='0'){cnt1++;}
        else{cnt2++;}
    }
    cout<<min(cnt1,cnt2)*2<<endl;
    
    
    return 0;
}


Measured memory_bytes: 512
a, b, c, x = map(int, [input() for i in range(4)])
ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if i * 500 + j * 100 + k * 50 == x:
                ans += 1
print(ans)

Measured memory_bytes: 9124
#include <stdio.h>

int main(){
  int n,matrix[11][11];

  while(1){
    int i,j;
    scanf("%d",&n);
    if(!n) break;
    for(i=0;i < n;i++){
      int sm = 0;
      for(j=0;j < n;j++){
        scanf("%d",&matrix[i][j]);
        sm += matrix[i][j];
      }
      matrix[i][n] = sm;
    }

    for(i=0;i <= n;i++){
      int sm=0;
      for(j=0;j < n;j++){
        sm += matrix[j][i];
      }
      matrix[n][i] = sm;
    }

    for(i=0;i <= n;i++){
      for(j=0;j <= n;j++){
        printf("%5d",matrix[i][j]);
      }
      puts("");
    }
  }

  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define l first
#define r second
using namespace std;
typedef pair<int, int> ii;

ii p[100005];

int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; ++i) cin >> p[i].l >> p[i].r;
	int l = 0, r = 1e9;
	int x, y;
	for (int i = 0; i < N; ++i) {
		if (p[i].l > l) {
			l = p[i].l;
			x = i;
		}
		if (p[i].r < r) {
			r = p[i].r;
			y = i;
		}
	}

	int ans = 0;
	for (int i = 0; i < N; ++i) {
		ans = max(max(p[i].r - p[i].l + 1, 0), ans);
	}
	ans += max(r - l + 1, 0);
	if (x == y) {		
		cout << ans << '\n';
		return 0;
	}

	sort(p, p + N, [](const ii& a, const ii& b) { return a.r < b.r || (a.r == b.r && a.l > b.l); });
	int s = 0;
	for (int i = 0; i < N - 1; ++i) {
		s = max(p[i].l, s);
		ans = max(max(r - s + 1, 0) + max(p[i + 1].r - l + 1, 0), ans);
	}
	cout << ans << '\n';
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef map<int,int> mint;
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int inf=1e9+100;
ll infi =1e18+100;

int num=1e9+7;

ll N,M;

ll frac(ll n){
	if(n==0) return 1;
	else return (n*(frac(n-1))%num)%num;
}

int main() {
	cin>>N>>M;
	if(N<M) swap(N,M);
	if(N==M+1){
		cout<<(frac(N)*frac(M))%num<<endl;
	}
	else if(N==M){
		cout<<(2*(frac(N)*frac(M))%num)%num<<endl;
	}
	else cout<<0<<endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

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

const int INF = 1<<29;
const int MAX = 510000; //nCrのr
const int MOD = 1000000007;

class mint {
public:
    long long x;
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    //mint operator-() const{ return mint(-x);}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

};
long long fac[MAX], finv[MAX], inv[MAX], facn[MAX];

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

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

int main(){
  int N, K; cin >> N >> K;
  vector<int> a(N);
  rep(i, N) cin >> a[i];
  COMinit();
  if (K == 1) {cout << 0 << endl; return 0;}

  //maxについての総和
  sort(a.begin(), a.end(), less<int>());
  mint n_max = 0;
  for (ll i = 1; i < N; ++i){
    n_max += a[i] * COM(i, K - 1);
    //cout << COM(i, K - 1) << endl;
  }
  //cout << "======" << endl;
  //minについての総和
  sort(a.begin(), a.end(), greater<int>());
  mint n_min = 0;
  for (ll i = 1; i < N; ++i){
    n_min += a[i] * COM(i, K - 1);
    //cout << COM(i, K - 1) << endl;
  }
  mint ans = n_max - n_min;
  cout << ans.x << endl;
}


Measured memory_bytes: 14592
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <limits>
#include <iomanip>
using namespace std;

int main(){

    int N;
    string S;
    cin >> N;
    cin >> S;

    int ncol = 1;
    for(int i = 1 ; i < N ; i++){
        if( S[i] != S[i-1] ) ncol++;
    }

    cout << ncol << endl;

}

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

long long calc(long long A, long long i){
    using ll = long long;
    if(A<(1LL<<i)) return 0;
    ll offset = (1LL<<i) - 1LL;
    ll anum_p = (A-offset)%(1LL<<(i+1));
    if(anum_p>(1LL<<i)) anum_p = (1LL<<i);
    ll anum = (A-offset)/(1LL<<(i+1)) * (1LL<<i) + anum_p;
    return anum;
}
int main(){
    using ll = long long;
    ll A, B; cin >> A >> B;
    ll N = (ll) log2(1e12) + 1;
    //cout << N << endl;
    ll ans = 0;
    for (ll i = 0; i < N; i++)
    {
        ll one = 0;
        if(A>0) one = calc(B, i) - calc(A-1, i);
        else one = calc(B,i);

        //cout << i << " " << one << " " << calc(B, i) << " " <<  calc(A-1, i) << endl;
        if(one % 2 == 1){
            ans += (1LL<<i);
        }
    }
    cout << ans << endl;
}


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

using namespace std;

typedef long long LL;

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

const int maxn = 4e2 + 5;
const int maxm = 1e5 + 5;

int n, m, u[maxm], v[maxm], ans, f[maxn];

bitset<maxn> g[maxn];

inline int read() {
	char ch = getchar(); int u = 0, f = 1;
	while(!isdigit(ch)) {if(ch == '-') f = -1; ch = getchar();}
	while(isdigit(ch)) {u = u * 10 + ch - 48;  ch = getchar();} return u * f;
}

int main() {
#ifndef ONLINE_JUDGE
	//freopen("c.in", "r", stdin);
	//freopen("c.out", "w", stdout);
#endif
	n = read(); m = read();
	
	for(register int i = 1; i <= m; ++i) u[i] = read(), v[i] = read();
	
	for(register int i = 1; i <= n; ++i) {
		g[i][i] = 1;
		for(register int j = m; j >= 1; --j) {
			if(g[i][u[j]] && g[i][v[j]]) {f[i] = 1; break;}
			if(g[i][u[j]] || g[i][v[j]]) g[i][u[j]] = g[i][v[j]] = 1;
		}
	}
	
	for(register int i = 1; i <= n; i++)
		for(register int j = i + 1; j <= n && !f[i]; j++)
			if(!f[j] && (g[i] & g[j]).none()) ans++;
			
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl S(POW(2, N));
  priority_queue<ll> C, D;
  REP(i, POW(2, N)) {
    cin >> S[i];
    C.push(S[i]);
  }

  D.push(C.top());
  C.pop();
  FOR(i, 0, N) {
    auto E = D;
    vl nokori;
    REP(j, POW(2, i)) {
      ll e = E.top();
      E.pop();
      while (C.size() > 0) {
        ll po = C.top();
        C.pop();
        if (e > po) {
          D.push(po);
          break;
        } else
          nokori.push_back(po);
      }
    }
    AUTO(no, nokori) C.push(no);
  }
  if (D.size() == POW(2, N)) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
  return 0;
}


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

#ifdef TESTING
  #include "dump.hpp"
#else
  #define DUMP(...)
  #define DEBUG(...)
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
#define SZ(a) int((a).size())
#define _REP(_1,_2,_3,_4,name,...) name
#define _REP4(i,b,e,s) for(decltype(e) _b=(b),_e=(e),i=_b+(0<(s)?0:(s));(0<(s)?i<_e:_e<=i);i+=(s))
#define _REP3(i,b,e) for(decltype(e) _b=(b),_e=(e),i=(_b<_e?_b:_b-1);(_b<_e?i<_e:_e<=i);(_b<_e?i++:i--))
#define _REP2(i,n) for(decltype(n) i=0,_n=(n);i<_n;i++)
#define _REP1(n) for(decltype(n) _i=0,_n=(n);_i<_n;_i++)
#define REP(...) _REP(__VA_ARGS__,_REP4,_REP3,_REP2,_REP1)(__VA_ARGS__)
#define FOR(it,c) for(auto&& it=begin(c);it!=end(c);it++)
#define ROF(it,c) for(auto&& it=rbegin(c);it!=rend(c);it++)
#define EB emplace_back
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define INT(n) int n;assert(0<scanf("%d",&n))
#define STR(s) string s;cin>>s
#define MSET(arr,val)  memset(arr,val,sizeof(arr))

int main(){
  STR(s); INT(x); INT(y);
  vector<int> fs = {0}, dx, dy;
  for(char c: s){
    if (c == 'T'){
      fs.PB(0);
    } else {
      (*fs.rbegin())++;
    }
  }
  REP(i, 1, SZ(fs)){
    if (fs[i] == 0){continue;}
    if (i % 2 == 0){
      dx.PB(fs[i]);
    } else {
      dy.PB(fs[i]);
    }
  }
  x -= fs[0];
  bool dpx[2][32001], dpy[2][32001];
  MSET(dpx, 0); MSET(dpy, 0);
  dpx[0][16000] = true; dpy[0][16000] = true;
  REP(i, SZ(dx)){
    REP(j, 32001){
      dpx[(i + 1) % 2][j] = false;
    }
    REP(j, 32001){
      if (dpx[i % 2][j]){
        if (0 <= j - dx[i]){
          dpx[(i + 1) % 2][j - dx[i]] = true;
        }
        if (j + dx[i] <= 32000){
          dpx[(i + 1) % 2][j + dx[i]] = true;
        }
      }
    }
  }
  REP(i, SZ(dy)){
    REP(j, 32001){
      dpy[(i + 1) % 2][j] = false;
    }
    REP(j, 32001){
      if (dpy[i % 2][j]){
        if (0 <= j - dy[i]){
          dpy[(i + 1) % 2][j - dy[i]] = true;
        }
        if (j + dy[i] <= 32000){
          dpy[(i + 1) % 2][j + dy[i]] = true;
        }
      }
    }
  }
  int ix = 16000 + x, iy = 16000 + y;
  if (0 <= ix && ix <= 32000 && dpx[SZ(dx) % 2][ix] && 0 <= iy && iy <= 32000 && dpy[SZ(dy) % 2][iy]){
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}

Measured memory_bytes: 512
h, w = gets.split.map(&:to_i)
mat=Array.new(h){gets.chomp.split("")}.transpose
 
def compression(mat)
  mat.each_with_index do |v,i|
    if v.all?{|a| a=="."}
      mat.delete_at(i)
      compression(mat)
    end
  end
  return mat
end
 
puts compression(compression(mat).transpose).map(&:join)

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<string,ll> si;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
#define sort(a) sort(a.begin(),a.end());
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define mp make_pair
#define F first
#define S second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define nl "\n"
const int MOD = 1e9+7;
const ld PI = 3.1415926535898;
const ll LLMAX = LLONG_MAX;
#define N (int)1e6+1

int main()
{
	ios
	int n,a,b,c;
	cin>>n;
	int prev1,prev2,prev3;
	cin>>prev1>>prev2>>prev3;
	for(int i=0;i<n-1;i++)
	{
		cin>>a>>b>>c;
		int p1=prev1,p2=prev2,p3=prev3;
		prev1=a+max(p2,p3);
		prev2=b+max(p1,p3);
		prev3=c+max(p1,p2);
	}
	cout<<max(prev1,max(prev2,prev3))<<nl;
}

Measured memory_bytes: 892
n,k = map(int,input().split())
a = [0]*n
b = [[]]*k
d = 0
cnt = 0
for i in range(k):
    d = input()
    b[i] = list(map(int,input().split()))
    l = len(b[i])
    for j in range(l):
        a[b[i][j]-1] = 1
for k in range(n):
    if a[k] == 0:
        cnt += 1
print(cnt)

Measured memory_bytes: 9212
n=int(input())
a=list(map(int,input().split()))
r=[0]*8
f=0

for i in range(n):
    if(a[i]>=3200):
        f+=1
    else:
        r[a[i]//400]=1;

c=sum(r)

print(1 if(c==0) else c,end=" ")
print(f+c)


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

const int KMAX = 100;
int blood[KMAX];

int main(){
	int N, K;
	while(cin >> N >> K){
		if(N == 0 && K == 0) break;
		for(int i = 0; i < K; i++){
			cin >> blood[i];
		}
		for(int i = 0; i < N; i++){
			for(int j = 0; j < K; j++){
				int needs;
				cin >> needs;
				blood[j] -= needs;
			}
		}
		bool f = false;
		for(int i = 0; i < K; i++){
			if(blood[i] < 0){
				f = true; break;
			}
		}
		if(f) cout << "No" << endl;
		else cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 856
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main(){

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    ll t = 1;
    //cin>>t;

    while(t--){

        ll r;
        cin>>r;

        ll ans = r * r;
        cout<<ans<<endl;



    }

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
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 <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    rep (i, n) cin >> a[i];
    int estimated = 0;
    ll ans = 0;
    bool valid = (a[0] == 0);
    reprev (i, n) {
        if (a[i] > estimated) ans += a[i];
        else if (a[i] < estimated) valid = false;
        estimated = max(0, a[i] - 1);
    }
    cout << (valid ? ans : -1) << "\n";
    return 0;
}

Measured memory_bytes: 1024
N = gets.to_i
a = [0] * (N+1)
names = [""]
N.times do |i|
    name, t = gets.chomp.split(/\s/)
    a[i+1] = a[i] + t.to_i
    names << name
end

title = gets.chomp

s = 0
names.each_with_index do |name, idx|
  if title == name
    s = idx
    break
  end
end
puts a[N] - a[s]

Measured memory_bytes: 14368
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
#define mp make_pair
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
const int  COMMAX = 510000;

long long fac[COMMAX], finv[COMMAX], inv[COMMAX];

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcd(int a,int b){return a*b / gcd(a,b);}
// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COMMAX; 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(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

struct UnionFind {
  vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  vector<int> rank;
  int num;
  UnionFind(int N) : par(N) , rank(N) { //最初は全てが根であるとして初期化
    num = N;
    for(int i = 0; i < N; i++){
      par[i] = i;
      rank[i] = 0;
    }
  }

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

  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
    if(rank[rx] < rank[ry]){
      par[rx] = ry;  
    }else{
      par[ry] = rx;
      if(rank[rx] == rank[ry])rank[rx]++;
    }
    num--;
  }

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

const int MS = 2;
const long long mod[] = {999999937LL, 1000000007LL}, base = 9973;
struct rolling_hash {
    int n;
    vector<long long> hs[MS], pw[MS];
    rolling_hash(){}
    rolling_hash(const string &s) {
        n = s.size();
        for (int i = 0; i < MS; i++) {
            hs[i].assign(n+1,0);
            pw[i].assign(n+1,0);
            hs[i][0] = 0;
            pw[i][0] = 1;
            for (int j = 0; j < n; j++) {
                pw[i][j+1] = pw[i][j]*base%mod[i];
                hs[i][j+1] = (hs[i][j]*base+s[j])%mod[i];
            }
        }
    }

    long long hash(int l, int r, int i) { return ((hs[i][r]-hs[i][l]*pw[i][r-l])%mod[i]+mod[i])%mod[i]; }

    bool match(int l1, int r1, int l2, int r2) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l1,r1,i)==hash(l2,r2,i);
        return ret;
    }

    bool match(int l, int r, long long h[]) {
        bool ret = 1;
        for (int i = 0; i < MS; i++) ret &= hash(l,r,i)==h[i];
        return ret;
    }
};

int main(){
  int n,r;
  cin >> n >> r;
  cout << r + 100 * (10-min(10,n)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstring>
#include<cstdio>
#include<string>
#include<iostream>
int a[10005],b[10005];
using namespace std;
int n,m;
int main() {
    string s,t;
    cin>>s>>t;
    n=s.length();m=t.length();
    if(n!=m){
    	printf("No\n");
    	return 0;
	}
    for(int i=0;i<n;i++) {
        if(a[s[i]]||b[t[i]]){
           if(a[s[i]]!=t[i]||b[t[i]]!=s[i]){
              printf("No\n");
              return 0;
           }
        }
        a[s[i]]=t[i];b[t[i]]=s[i];
    }
    printf("Yes\n");
}

Measured memory_bytes: 776
text  = []                                                                                                
ptext = []

while True:
    try:
        text = list(map(str,raw_input()))
        f = 0
        ptext = []

        for i in range(len(text)):
            if text[i] == '@':

                for k in range(int(text[i+1])-1):
                    ptext.append(text[i+2])

                f = 1

            else:
                if f == 0:
                    ptext.append(text[i])
                else:
                    f = 0

        print "".join(map(str,ptext))

    except EOFError:
        break
text  = []                                                                                                
ptext = []

while True:
    try:
        text = list(map(str,raw_input()))
        f = 0
        ptext = []

        for i in range(len(text)):
            if text[i] == '@':

                for k in range(int(text[i+1])-1):
                    ptext.append(text[i+2])

                f = 1

            else:
                if f == 0:
                    ptext.append(text[i])
                else:
                    f = 0

        print "".join(map(str,ptext))

    except EOFError:
        break

Measured memory_bytes: 4292
#include <bits/stdc++.h>
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()
 
using namespace std;
 

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

	string s ; cin >> s;
	int c = 0;
	int ans = 0;
	for(char ch : s){
		if(ch == 'R')c++;
		else{
			ans = max(ans , c);
			c = 0;
		}
	}
	ans = max(c , ans);
	cout << ans << endl;

	return 0;
}


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

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())

#define REP(a, b) for (int a = 0; a < (b); a++)
#define FOR(a, b, c) for (int a = (b); a <= (c); a++)
#define REPD(a, b) for (int a = (b) - 1; a >= 0; a--)
#define FORD(a, b, c) for (int a = (b); a >= (c); a--)

#define MIN(a, b) (a) = min((a), (b))
#define MAX(a, b) (a) = max((a), (b))

#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2> &p) {
  return is >> p.fi >> p.se;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  V<ll> a(n);
  REP(i, n) cin >> a[i];
  V<ll> sum(n);
  partial_sum(ALL(a), begin(sum));
  VV<ll> dp(n, V<ll>(n, LLONG_MAX / 2));
  REP(i, n) dp[i][i] = 0;
  FOR(len, 2, n) FOR(i, 0, n - len) {
    int j = i + len - 1;
    ll q = sum[j] - (i > 0 ? sum[i - 1] : 0LL);
    FOR(k, i, j) {
      MIN(dp[i][j], q + dp[i][k] + (k < j ? dp[k + 1][j] : 0LL));
    }
  }
  cout << dp[0][n - 1] << endl;
}


Measured memory_bytes: 1536
N,M = map(int,input().split())
A = list(map(int,input().split()))



def check(A,M):
    flag = 0
    condition = sum(A)/(4*M)
    if(M==1 and max(A)>condition):
        return "Yes"
    for i in A:
        if(i < condition):
            continue
        elif(i >= condition):
            flag+=1
            if(flag==M):
                return "Yes"
    return "No"

print(check(A,M))





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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int h, w; cin >> h >> w;
    int x, y, gx, gy; cin >> x >> y >> gx >> gy;
    x--; y--; gx--; gy--;
    vector<string> lis(h);
    vector<vector<int> > anslis(h, vector<int>(w, 1e9)), flag(h, vector<int>(w, 0));
    anslis[x][y] = 0;
    REP(i, 0, h){cin >> lis[i];}
    queue<Pii> que;
    queue<Pii> subq;
    que.push(Pii(x, y));
    while(!(subq.empty() && que.empty())){
        while(!que.empty()){
            Pii a = que.front();
            que.pop();
            int nx = a.first, ny = a.second;
            int f = 0;
            REP(i, 0, 4){
                int xx = nx + dx[i], yy = ny + dy[i];
                if(xx < h && xx >= 0 && yy >= 0 && yy < w && anslis[xx][yy] > anslis[nx][ny] && lis[xx][yy] == '.'){
                    anslis[xx][yy] = anslis[nx][ny];
                    que.push(Pii(xx, yy));
                }else if(xx < h && xx >= 0 && yy >= 0 && yy < w && lis[xx][yy] == '#' && flag[nx][ny] == 0){
                    f = 1;
                    flag[nx][ny] = 1;
                }
            }
            if(f){
                subq.push(Pii(nx, ny));
            }
        }
        if(anslis[gx][gy] != 1e9){
            cout << anslis[gx][gy] << endl;
            return 0;
        }
        while(!subq.empty()){
            Pii a = subq.front();
            subq.pop();
            int nx = a.first, ny = a.second;
            REP(i, -2, 3){
                REP(l, -2, 3){
                    int xx = nx + i, yy = ny + l;
                    if(xx < h && xx >= 0 && yy >= 0 && yy < w && anslis[xx][yy] > anslis[nx][ny]+1  && lis[xx][yy] == '.'){
                        anslis[xx][yy] = anslis[nx][ny] + 1;
                        que.push(Pii(xx, yy));
                    }
                }
            }
        }
        if(anslis[gx][gy] != 1e9){
            cout << anslis[gx][gy] << endl;
            return 0;
        }
    }
    if(anslis[gx][gy] == 1e9){
        cout << -1 << endl;
        return 0;
    }else{
        cout << anslis[gx][gy] << endl;
    }
}


Measured memory_bytes: 13508
#include <bits/stdc++.h> 
using namespace std; 
  
int N=1030;

vector<int> v[15];
int n,m;
int stb[15];
int c=0;

void printTheArray(int arr[], int n) 
{ 
     int i,j;
     int flag=0;
     for(i=0;i<m;i++)
     {
     	int x= v[i].size();
     	int f=0;
     	for(j=0;j<x;j++)
     	{
     		if(arr[v[i][j]-1]==1)
			 {
			 	f++;
			}	
		}
		if(f%2!=stb[i])
		{
			flag=1;
			break;
		}
	 }
	 if(flag==0)
	 {
	 	c++;
	 }
} 
  

void generateAllBinaryStrings(int n, int arr[], int i) 
{ 
    if (i == n) { 
        printTheArray(arr, n); 
        return; 
    } 
  
    arr[i] = 0; 
    generateAllBinaryStrings(n, arr, i + 1); 
  
    arr[i] = 1; 
    generateAllBinaryStrings(n, arr, i + 1); 
} 
  
int main() 
{ 
    cin >> n >> m;
    int i,j;
    for(i=0;i<m;i++)
    {
    	int x;
    	cin >> x;
    	for(j=1;j<=x;j++)
    	{
    		int f;
    		cin >> f;
			v[i].push_back(f);
		}
	}
  	for(i=0;i<m;i++)
  	{
  		cin >> stb[i];	
	}
    int arr[n];
	
    generateAllBinaryStrings(n, arr, 0); 
  
  	cout << c << endl;
    return 0; 
} 

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

using namespace std;

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

  int N, x;
  cin >> N;
  while (N--) {
    cin >> x;
    if (x%2 == 0) {
      if (x%3 != 0 && x%5 != 0) {
        cout << "DENIED" << endl;
        return 0;
      }
    }
  }
  cout << "APPROVED" << endl;

	return 0;
}



Measured memory_bytes: 256
S, k = open(0).read().split()
k = int(k)
x = set(sorted(S)[:min(k, len(S))])
A = set()
for i, c in enumerate(S):
    if c in x:
        s = ''
        for j in range(i, min(i+k, len(S))):
            s += S[j]
            A.add(s)
print(sorted(A)[k-1])

Measured memory_bytes: 3064
n,a,b = map(int,raw_input().split())
s = raw_input()
apb = 0
over = 0
for i in s:
    if i =='a':
        if apb >= a+b:
            print  'No'
        else:
            print 'Yes'
            apb+=1
    elif i == 'b':
        if apb < a+b and over <=b-1:
            print 'Yes'
            apb+=1
            over+=1
        else:
            print 'No'
    else:
        print 'No'

Measured memory_bytes: 3076
n = int(input())
input_array = input().split()
sum = min = max = int(input_array[0])
for i in range(1, n):
    temp = int(input_array[i])
    if (min > temp):
        min = temp
    if (max < temp):
        max = temp
    sum += temp
print(min, end = ' ')
print(max, end = ' ')
print(sum)


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

int main() 
{
    int l,r,d;
    cin >> l >> r >> d;

    int res = 0;

    for (int i=l; i<=r; i++) {
        if (i%d == 0) {
            res++;
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 3580
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc070_a.cpp
 * time   : Tue Apr 28 23:30:28 2020
 * quest  : A - Palindromic Number
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  cout << ((n % 10) == (n / 100) ? "Yes": "No") << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  int array[200005];
  cin>>n;
  
  int bit=0;
  for(int i=0;i<n;i++){
    cin>>array[i];
    bit^=array[i];
  }
  
  for(int i=0;i<n;i++){
    cout << (bit^array[i]) << endl;
  }
  return(0);
}

Measured memory_bytes: 4372
#include<bits/stdc++.h>
#define STDIO
#define MOD 1000000007
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
#define lowbit(x) ((x)&(-x))
#define INF MOD
using namespace std;
int a,b;
int main(){
	#ifndef STDIO
		freopen("input.in","r",stdin);
		freopen("output.out","w",stdout);
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>a>>b;
	for(int i=1;i<=6000;i++){
		double jj=i;
		if(floor(jj*0.08)==a&&floor(jj*0.10)==b){
			cout<<i<<endl;
			return 0;
		}
	}
	cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 256