akhauriyash/Code-Regression huggingface dataset:
/*
    if you can't see the repay
    Why not just work step by step
    rubbish is relaxed
    to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define lc (rt<<1)
#define rc (rt<<11)
#define mid ((l+r)>>1)

typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
ll mo(ll x,ll y) {return x + y >=mod?x+y-mod:x+y;}
int n;
struct mat
{
    ll jz[50][50];
};
mat mat_mul(mat x,mat y)
{
    mat res;
    memset(res.jz,0,sizeof(res.jz));
    for(int i = 0;i<n;++i)
        for(int k = 0;k<n;++k)
            for(int j = 0;j<n;++j)
                res.jz[i][j] = (res.jz[i][j]+x.jz[i][k]*y.jz[k][j]+mod)%mod;
    return res;
}
ll power_mod(ll P,mat res)
{
    mat ans;
    for(int i = 0;i<n;++i) ans.jz[i][i] = 1;
    while(P>0)
    {
        if(P&1)
            ans = mat_mul(ans,res);
        P = P>>1;
        res = mat_mul(res,res);
    }
    ll tmp = 0;
    for(int i = 0;i<n;++i)
        for(int j = 0;j<n;++j)
        {
            tmp += ans.jz[i][j];
            if(tmp>=mod) tmp-=mod;
        }
            return tmp;
}
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    ll k;
    mat res;
    scanf("%d%lld",&n,&k);
    for(int i = 0;i<n;++i)
        for(int j = 0;j<n;++j)
            scanf("%lld",&res.jz[i][j]);
    printf("%lld\n",power_mod(k,res));
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(void){
  int num;
  int a,b,c,d;
  int count=0;
  while(scanf("%d",&num)!=EOF){
    count=0;
    for(a=0;a<=9;a++){
      for(b=0;b<=9;b++){
        for(c=0;c<=9;c++){
          for(d=0;d<=9;d++){
            if((a+b+c+d)==num){
              count++;
            }
          }
        }
      }
    }
    printf("%d\n",count);
  }
  return 0;
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
import heapq
from math import ceil
n,d,a = map(int, input().split())
xh = [list(map(int, input().split())) for _ in range(n)]
xh.sort()

res = 0
b = []
heapq.heapify(b)
r = 0
for i in range(n):
    x,h = xh[i]

    while len(b)>0 and b[0][0]<=x:
        r += b[0][1]
        heapq.heappop(b)
    c = max(ceil((h-r)/a), 0)
    res += c
    r += c*a
    
    if c>0:
        heapq.heappush(b, (x+2*d+1, -c*a))

print(res)

Measured memory_bytes: 92632
#include "bits/stdc++.h"

#ifdef LOCAL_DEBUG
#include "bits/mytest.h"
#endif

using namespace std;


#pragma region user_defined
#define CLR(arr,val) fill(arr.begin(),arr.end(),val);
#define CLR0(arr)  CLR(arr,0)

#define d2clear(arr,data) for(int i =0;i<arr.size();i++){for(int j =0;j<arr[i].size();j++){arr[i][j]=data;}}
#define d2print(arr) for(int i =0;i<arr.size();i++){for(int j =0;j<arr[i].size();j++){cout<<arr[i][j];} cout<<endl;}
#define d2array(name,type,rows,cols,data) vector< vector<type>  > name(rows,vector<type>(cols,data))

#define forit(arr,it) for(auto it=arr.begin();it!=arr.end();it++)
#define rforit(arr,it) for(auto it=arr.rbegin();it!=arr.rend();it++)

#define LL long long
#define A(n) n.begin(),n.end()
#define maxn(a,b) ((a)=((a)>(b)?(a):(b)))
#define minn(a,b) ((a)=((a)<(b)?(a):(b)))

#define min(a,b)  ( (a)<(b)?(a):(b)   )
#define max(a,b)  ( (a)>(b)?(a):(b)  )
#define last(a)   a[a.size()-1]
#define first(a)  a[0]
#define println(a) cout<<a<<endl;
#define mp(a,b)  make_pair(a,b)
#pragma endregion

//#define MULTI_CASE
struct Solution{
	
	
	void solve(istream & cin = std::cin, ostream & cout = std::cout){
		string s; cin >> s;
		int cnt_max_p= s.length() / 2;
		int cnt_p = 0;
		int cnt_g = 0;
		for (int i = s.length() - 1; i >= 0; i--)
		{
			if (s[i] == 'g') cnt_g++;
			else if (s[i] == 'p') cnt_p++;
		}

		int wins = min(cnt_max_p, cnt_g);
		int loses = cnt_p;
		
		cnt_max_p -= wins;
		
		loses -= cnt_max_p;


		cout << wins-loses << endl;
		
		
 

	}

};


int main() {
#ifdef LOCAL_DEBUG 
 
	MyTest::Judge::JudgeNormal judge;
	MyTest::Config config;
	config.judge = &judge;
	MyTest::Test test(config);

	const string ITEM_NAME("D.cpp");
	const string FILE_NAME(__FILE__);
	auto it=FILE_NAME.find_last_of('\\');
	auto inputfile = FILE_NAME.substr(0, it + 1) + ITEM_NAME.substr(0, ITEM_NAME.find_last_of('.')) + "_input.txt";
	auto outputfile = FILE_NAME.substr(0, it + 1) + ITEM_NAME.substr(0, ITEM_NAME.find_last_of('.')) + "_output.txt";
	freopen(inputfile.c_str(), "r", stdin);
	//freopen(outputfile.c_str(), "w", stdout);
	
	while (test.ReadCaseInOneFile()) {
		test.Begin();
		Solution s;
		s.solve(test.Input(),test.Output());
		test.End();
	}
	test.DisplayInfo();
#else   //online judge
#ifdef MULTI_CASE 
	int t;cin>>t;
	while(t--){
		Solution s; 
		s.solve();
	}
#else
	Solution s;
	s.solve();
#endif
#endif
	

 
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int main(){
  int N;
  scanf("%d", &N);
  std::vector<int > A(N);
  for (int i=0; i<N; i++) {
    scanf("%d", &A[i]);
  }
  long long ans = 1e18;
  long long sum;
  int target[2]={1, 0};
  for (int j=0; j<2; j++){
    long long add = 0;
    sum=0;
    for (int i=0; i<N; i++){
      //printf("i=%d\n", i);
      sum += A[i];
      //printf("sum=%lld\n", sum);
      if (i%2==target[j]){
	// target = 1;
	if (sum<1){
	  add += 1-sum;
	  sum=1;
	  //printf("add=%lld\n", add);
	}
      } else {
	// target = -1
	if (sum>-1){
	  add += sum+1;
	  sum=-1;
	  //printf("add=%lld\n", add);
	}
      }
    }
    //printf("add=%lld\n", add);
    ans = std::min(ans, add);
  }
  std::cout << ans << std::endl;
  return 0;
}


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

int main(){
    int n, m;
    cin >> n >> m;
    int h[100000];
    bool bad[100000] = {0};
    for(int i=0;i<n;++i) cin >> h[i];
    for(int i=0;i<m;++i){
        int a, b;
        cin >> a >> b;
        --a; --b;
        if(h[a] <= h[b]) bad[a] = true;
        if(h[a] >= h[b]) bad[b] = true;
    }
    int ans = n;
    for(int i=0;i<n;++i) if(bad[i]) --ans;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4112
import math

a, b, h, m = map(float, input().split())
if (h == 12): 
  h = 0
if (m == 60): 
  m = 0

hour_angle = 0.5 * (h * 60 + m) 
minute_angle = 6 * m 
          
angle = abs(hour_angle - minute_angle) 
angle = min(360 - angle, angle) 

print(round(math.sqrt(a*a + b*b - 2*a*b*math.cos(math.radians(angle))), 20))

Measured memory_bytes: 9432
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int ans=1e9+7;
int A,B,C,l[15],n;
void dfs(int i,int a,int b,int c,int m)
{
	if(i==n+1){
      	if(!a||!b||!c) return ; 
	    else
	       {
	  	       ans=min(ans,abs(A-a)+abs(B-b)+abs(C-c)+m);
			   return;
	       }
		}
	 dfs(i+1,a+l[i],b,c,m+(a==0?0:10));
	 dfs(i+1,a,b+l[i],c,m+(b==0?0:10));
	 dfs(i+1,a,b,c+l[i],m+(c==0?0:10));
	 dfs(i+1,a,b,c,m);
}
int main()
{
   cin>>n>>A>>B>>C;
   for(int i=1;i<=n;i++) cin>>l[i];
   dfs(1,0,0,0,0);
   cout<<ans;


return 0;
}


Measured memory_bytes: 256
n, m = list(map(int, input().split()))
ans = 1
a = lambda x, y: x*y % (10**9+7)
if n==m:
    for i in range(1, n+1):
        ans = a(ans, i)
    print((ans**2*2)%(10**9+7))
elif abs(n-m)==1:
    for i in range(1, n+1):
        ans = a(ans, i)
    for i in range(1, m+1):
        ans = a(ans, i)
    print(ans%(10**9+7))
else:
    print(0)

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

// utility
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define rer(i, l, u) for (int(i) = (int)(l); (i) <= (int)(u); ++(i))
#define reu(i, l, u) for (int(i) = (int)(l); (i) < (int)(u); ++(i))

#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n", (x) ? "Yes" : "No")
#define F first
#define S second


char s[11];


signed main()
{
    ios_base::sync_with_stdio(false);
    // ⬇︎⬇︎⬇︎⬇︎⬇︎⬇︎⬇︎⬇︎⬇︎⬇︎⬇︎⬇︎⬇︎⬇︎
// 前から順に見ていって、「数字があるたびに現在の値を 10 倍して今書いてある数字だけ足す」
//「‘+(’ が出てきたら現在の値が ‘+(’ の直前の整数に等しいので、それを答えに足す」
//「最後は ‘+(’ が登場せずに数式が終わるので、そこは別に足す」
    int n, i, j;
    long long ans = 0;
    
    scanf("%s", s);
    
    n = strlen(s);
    
    if (n == 1) {
        printf("%s\n", s);
        
        return 0;
    }
    
    for (i = 0; i < (1 << (n - 1)); i++) {
        long long x = 0;
        
        for (j = 0; j < n; j++) {
            x *= 10;
            x += s[j] - '0';
            
            if ((i >> j) & 1) {
                ans += x;
                x = 0;
            }
        }
        
        ans += x;
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 3796
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	if (N >= 30)cout << "Yes\n";
	else cout << "No\n";
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
/*    #include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;       */
using namespace std;

#define ll long long
#define ull unsigned long long
#define f(a, b) for (ll i = a; i < b; i++)
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define pl pair<ll, ll>
#define vll vector<ll>
#define pll vector<pair<ll, ll>>
#define ld long double
#define fr(a, b) for (ll j = a; j >= b; j--)
#define fi(a, b) for (ll j = a; j < b; j++)
#define fii(a, b) for (ll k = a; k < b; k++)
#define print(x) cerr << #x << " is " << x << endl;
//      typedef tree<ll ,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "rt", stdin);
//     freopen("output.txt", "wt", stdout);
// #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n;
    cin >> n;
    ll a[n];
    f(0, n) cin >> a[i];
    multiset<ll> s;
    ll ans = 0;
    fr(n - 1, 0)
    {
        auto it = s.upper_bound(a[j]);
        if (it == s.end())
            ans++;
        else
            s.erase(it);
        s.insert(a[j]);
    }
    cout << ans;

    return 0;
}


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

int main(){
    int a, b;
    cin >> a >> b;
    if( a < b ){
        cout << "a < b" << endl;
    }else if( a > b ){
        cout << "a > b" << endl;
    }else{
        cout << "a == b" << endl;
    }
}

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

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

bool f(char c){
	if(c == 'a')return true;
	if(c == 'i')return true;
	if(c == 'o')return true;
	if(c == 'u')return true;
	if(c == 'e')return true;
	return false;
}
int main(void){
	char c;
	scanf("%c", &c);
	puts(f(c) ? "vowel" : "consonant");
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int a[100], b[100];
  char op[100];
  int i, j;

  i=0;
  do{
    scanf("%d %c %d", &a[i], &op[i], &b[i]);
    i++;
  }while(op[i-1] != '?');

  for(j=0; j<i-1;j++){
    switch(op[j]){
    case '+':
      printf("%d\n",a[j]+b[j]);
      break;
    case '-':
      printf("%d\n", a[j]-b[j]);
      break;
    case '/':
      printf("%d\n", a[j]/b[j]);
      break;
    default:
      printf("%d\n", a[j]*b[j]);
        break;
    }
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
using namespace std;
 
int main(){
  char alpabet;
  cin >> alpabet;
  
  if(alpabet == 'a' || alpabet == 'i' || 
     alpabet == 'u' || alpabet == 'e' || alpabet == 'o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

class Dice {
    public:
        int D1;
        int D2;
        int D3;
        int D4;
        int D5;
        int D6;

        Dice(int d1, int d2, int d3, int d4, int d5, int d6);
        void Rotate_E();
        void Rotate_N();
        void Rotate_S();
        void Rotate_W();

};

Dice::Dice(int d1, int d2, int d3, int d4, int d5, int d6) {
    D1 = d1;
    D2 = d2;
    D3 = d3;
    D4 = d4;
    D5 = d5;
    D6 = d6;
}

void Dice::Rotate_E() {
    int tmp;

    tmp = D3;
    D3 = D1;
    D1 = D4;
    D4 = D6;
    D6 = tmp;
}

void Dice::Rotate_N() {
    int tmp;

    tmp = D5;
    D5 = D1;
    D1 = D2;
    D2 = D6;
    D6 = tmp;
}

void Dice::Rotate_S() {
    int tmp;

    tmp = D5;
    D5 = D6;
    D6 = D2;
    D2 = D1;
    D1 = tmp;
}

void Dice::Rotate_W() {
    int tmp;

    tmp = D3;
    D3 = D6;
    D6 = D4;
    D4 = D1;
    D1 = tmp;
}

int main () {

    int d1, d2, d3, d4, d5, d6;
    cin >> d1 >> d2 >> d3 >> d4 >> d5 >> d6;
    Dice Dice1(d1, d2, d3, d4, d5, d6);

    int q;
    cin >> q;

    for (int i = 0; i < q; i++) {
        int a, b;
        cin >> a >> b;

        if (Dice1.D3 == b || Dice1.D4 == b) {
            Dice1.Rotate_E();
        }

        while (Dice1.D2 != b) {
            // cout << "Now Loading\n" << endl;
            Dice1.Rotate_N();
        }

        while (Dice1.D1 != a) {
            // cout << "Now Loading2\n" << endl;
            Dice1.Rotate_E();
        }

        cout << Dice1.D3 << endl;
    }

    return 0;
}


Measured memory_bytes: 3104
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    vector<int> a(n);
    for(auto &x:a)cin >> x;

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

    cout << ans << endl;

    return 0;
}


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

inline void Yes(){
    cout << "Yes" << "\n";
}
inline void No(){
    cout << "No" << "\n";
}
typedef pair<int,int> P;

int main(){
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++){
        cout << 'x';
    }
    cout << "\n";
}

Measured memory_bytes: 256
//https://drken1215.hatenablog.com/entry/2020/06/21/225500
//勉強させて頂いた記事

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)

//基本の形からの派生？
//桁ごとに考えたら上手くいく

int main(){
    ll n;
    cin>>n;
    string res="";
    while(n){
        n--;
        res+=(char)('a'+(n%26));
        n/=26;
        //cout<<n<<endl;
    }
    //reverse!
    reverse(ALL(res));
    cout<<res<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 3608
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

struct td{
    int t;
    int d;
};

bool cmp_d   (struct td& lhs, struct td& rhs){ return lhs.d < rhs.d; }
bool cmp_gr_d(struct td& lhs, struct td& rhs){ return lhs.d > rhs.d; }

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    uint N, K; cin >> N >> K;
    vector<struct td> vTD(N); for(uint i=0; i<N; ++i){ cin >> vTD[i].t >> vTD[i].d; }
    sort(vTD.begin(), vTD.end(), cmp_gr_d);
    
    unordered_map<int, int> htUN; // a hash table for counting number of used types
    vector<struct td> vTD_rm;     // for remove
    vector<struct td> vTD_add;    // for add
    
    int64 sum =0ll;
    for(uint i=0; i<K; ++i){
        sum += vTD[i].d;
        ++htUN[ vTD[i].t ];
        if(htUN[ vTD[i].t ]>=2){ vTD_rm.push_back( vTD[i] ); }
    }
    sort(vTD_rm.begin(), vTD_rm.end(), cmp_d);
    
    for(uint i=K; i<N; ++i){
        if( htUN[ vTD[i].t ] != 0 ){ continue; }
        vTD_add.push_back( vTD[i] );
    }
//    sort(vTD_add.begin(), vTD_add.end(), cmp_gr_d); // dont need to sort. Because of the vTD is already sorted.
    
    int64 numT = K - vTD_rm.size(); // num of type
    int64 point = sum + numT*numT;
    uint ri=0, ai=0;
    while( ri<vTD_rm.size() && ai<vTD_add.size() ){
        if( htUN[ vTD_rm [ri].t ] == 1 ){ ++ri; continue; }
        if( htUN[ vTD_add[ai].t ] >= 1 ){ ++ai; continue; }
        
        sum -= vTD_rm [ri].d; --htUN[ vTD_rm [ri].t ]; ++ri;
        sum += vTD_add[ai].d; ++htUN[ vTD_add[ai].t ]; ++ai;
        
        ++numT;
        
        int64 tmp = sum + numT * numT;
        point = max(point, tmp);
    }
    cout << point << endl;
    
    return 0;
}


Measured memory_bytes: 5540
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt(), K = scn.nextInt();
		double[] P = new double[N+1];
		P[0] = 0;
		for(int i = 0;i < N;i++) {
			double p = scn.nextInt();
			P[i+1] = P[i] + (p+1)*0.5;
		}
		double ans = -1;
		for(int i = 0;i < N-K+1;i++) {
			ans = Math.max(P[i+K]-P[i], ans);
		}
		System.out.println(ans);
	}

}

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

using namespace std;

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

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

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b){
  return (a % b == 0) ? b : gcd(b, a % b);
}

int main(){
  int N;
  ll M;
  while(cin >> N >> M){
    vector<ll> a(N);
    vector<int> p(N);
    REP(i, N) cin >> a[i];
    REP(i, N) cin >> p[i];
    static ll F[1 << 20] = {};
    // 包除原理 (チャレンジブック p.264)
    FOR(S, 1, 1 << N){
      int sign = (__builtin_popcount(S) % 2 == 0) ? -1 : 1;
      ll lcm = 1;
      for (int i = 0; i < N; i++) if(S >> i & 1){
        lcm /= gcd(lcm, a[i]);
        if((double)lcm * a[i] > 1e18){
          lcm = LLONG_MAX;
          break;
        }
        lcm *= a[i];
      }
      F[S] = sign * (M / lcm);
    }
    // 高速ゼータ変換 (http://topcoder.g.hatena.ne.jp/iwiwi/20120422/1335065228)
    REP(i, N)REP(S, 1 << N){
      if(0 == (S & (1 << i))){
        F[S | 1 << i] += F[S];
      }
    }
    double ans = 0;
    REP(S, 1 << N){
      double prob = 1;
      REP(i, N) {
        if(S >> i & 1) prob *= p[i] / 100.0;
        else prob *= (100.0 - p[i]) / 100.0;
      }
      ans += prob * F[S];
    }
    printf("%.8lf\n", ans);
  }
  return 0;
}

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

int editdistance(string a, string b)
{
    int dp[a.size() + 1][b.size() + 1];
    rep(i, a.size() + 1) rep(j, b.size() + 1)
    {
        dp[i][j] = INF;
    }
    rep(i, a.size() + 1) dp[i][0] = i;
    rep(j, b.size() + 1) dp[0][j] = j;
    for (int i = 1; i < a.size() + 1; i++)
        for (int j = 1; j < b.size() + 1; j++)
        {
            if (a[i - 1] == b[j - 1])
            {
                dp[i][j] = dp[i - 1][j - 1] + 0;
            }
            else
            {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            }

            dp[i][j] = min({dp[i][j], dp[i][j - 1] + 1, dp[i - 1][j] + 1});
        }
    return dp[a.size()][b.size()];
}

int main()
{

    string s1, s2;
    cin >> s1 >> s2;
    cout << editdistance(s1, s2) << endl;
    return 0;
}



Measured memory_bytes: 7112
def floor_pow2(n):
    res = 0
    while 2**res <= n:
        res += 1
    return res-1
 
n = int(input())
n -= 1
 
if n <= 3:
    N = 2
    M = n+1
    print(N, M)
    for i in range(M):
        print(1, 2, i)
    exit(0)
 
# output
N = floor_pow2(n) + 1
M = 0
 
# G[i] = [to, len]
G = [[] for i in range(N)]
 
for i in range(1,N,1):
    G[i].append([i-1, 2**(i-1)])
    G[i].append([i-1, 0])
    M += 2
 
bias = 2 ** (N - 1)
u = n - bias
 
while True:
    if u <= 1:
        G[-1].append([u, bias])
        M += 1
        break
 
    tu = floor_pow2(u)
    G[-1].append([tu, bias])
    bias += 2 ** tu
    u -= 2 ** tu
    M += 1
 
print(N, M)
for ix, es in enumerate(G):
    for e in es:
        print(N-ix, N-e[0], e[1])

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

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> mp(h);
    for(int i=0; i<h; i++) cin >> mp.at(i);

    int ans = 1 << 30;
    for(int bit=0; bit < (1<<(h-1)); bit++)
    {
        vector<int> sakai;
        for(int i=0; i<h-1; i++)
        {
            if(bit & (1<<i))
            {
                sakai.push_back(i);
            }
        }
        int sun = sakai.size();
        sakai.push_back(h);
        vector<int> whites(sakai.size(), 0);
        for(int i=0; i<w; i++)
        {
            int ban = 0;
            int add = 0;
            bool can_add = true;
            for(int j=0; j<h; j++)
            {
                if(j > sakai.at(ban))
                {
                    ban++;
                    add = 0;
                }
                if(mp.at(j).at(i) == '1') whites.at(ban)++;
                if(whites.at(ban) > k)
                {
                    sun = 1 << 30;
                    break;
                }
                if(i+1 < w && mp.at(j).at(i+1) == '1')
                {
                    add++;
                    if(whites.at(ban) + add > k && can_add)
                    {
                        sun++;
                        can_add = false;
                    }
                }
            }
            if(!can_add) whites.assign(whites.size(), 0);
            if(sun == 1 << 30) break;
        }
        chmin(ans, sun);
        sun--;
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int x,k;
  cin>>x>>k;
  int r[k];
  for(int i=0;i<k;i++) cin>>r[i];
  int q;
  cin>>q;
  int t[q],a[q];
  for(int i=0;i<q;i++) cin>>t[i]>>a[i];

  int L=0,R=x;//[L,R]
  int lb[k],ub[k];
  fill_n(lb,k,0);
  fill_n(ub,k,x);
  
  int j=0,p=0,d=0;
  int lv=0,uv=x;
  for(int i=0;i<q;i++){
    while(j<k&&r[j]<=t[i]){
      if(j%2==0) p+=r[j]-d;
      else p-=r[j]-d;
      if(j%2==0){
	lv=max(lv-(r[j]-d),0LL);
	uv=max(uv-(r[j]-d),0LL);
      }else{
	lv=min(lv+(r[j]-d),x);
	uv=min(uv+(r[j]-d),x);
      }
      
      L=max(L,p);
      R=min(R,x+p);
      lb[j]=L;
      ub[j]=R;
      d=r[j++];
      
      
    }
    //cout<<i<<" "<<j<<":"<<p<<endl;
    //cout<<L<<" "<<R<<endl;
    if(L<=a[i]&&a[i]<=R){
      int c=a[i]-p;
      if(j%2==0) c=max(c-(t[i]-d),0LL);
      else c=min(c+(t[i]-d),x);
      cout<<c<<endl;
    }else if(a[i]<L){
      int c=lv;
      if(j%2==0) c=max(c-(t[i]-d),0LL);
      else c=min(c+(t[i]-d),x);
      cout<<c<<endl;
    }else if(R<a[i]){
      int c=uv;
      if(j%2==0) c=max(c-(t[i]-d),0LL);
      else c=min(c+(t[i]-d),x);
      cout<<c<<endl;
    }else{
      cout<<"?"<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define int long long
#define P(x) cout << x << endl
#define D(x) P(#x << ": " << x)
#define F(i,n) for (int i=0; i<(int)(n); i++)
#define DEC(i,n) for (int i=(int)(n); --i>=0;)
#define S(s) (int)((s).size())
#define ALL(v) v.begin(), v.end()
#define MI(a,v) a = min(a,(v))
#define MA(a,v) a = max(a,(v))
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;

signed main() {
    int a,b,c; cin>>a>>b>>c;
    if (a%2 == 0 && b%2 == 0 && c%2 == 0 && a == b && b == c)
        P(-1);
    else {
        int cnt=0;
        while (!(a%2 || b%2 || c%2)) {
            int d=(a+b)/2, e=(a+c)/2, f=(b+c)/2;
            cnt++;
            a = d, b = e, c = f;
        }
        P(cnt);
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int mt[10];
int main()
{
    for (int i = 0; i < 10; i++)
        cin >> mt[i];
    for (int t = 1; t <= 3; t++)
    {
        int maxv = -1, mark = 0;
        for (int i = 0; i < 10; i++)
        {
            if (mt[i] > maxv)
            {
                maxv = mt[i];
                mark = i;
            }
        }
        cout << maxv << endl;
        mt[mark] = -100;
        maxv = -1;
        mark = 0;
    }
    return 0;
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
typedef long long ll;
typedef pair<ll, ll> P;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 100 + 5;
const int MAX_N = 1e5 + 5;

int main() {
    string s, t;
    cin >> s >> t;
    ll ans = 0;
    vector<vector<int>> alphabets(26);

    int sz_s = s.size();
    int sz_t = t.size();

    rep(i, sz_s) { alphabets[s[i] - 'a'].push_back(i); }
    rep(i, sz_s) { alphabets[s[i] - 'a'].push_back(i + sz_s); }

    int checking_index = 0;
    rep(i, sz_t) {
        int ch = t[i] - 'a';
        if (alphabets[ch].size() == 0) {
            puts("-1");
            return 0;
        }

        checking_index = *lower_bound(alphabets[ch].begin(), alphabets[ch].end(), checking_index) + 1;

        if (checking_index >= sz_s) {
            ans += sz_s;
            checking_index -= sz_s;
        }
    }
    ans += checking_index;
    cout << ans << endl;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n * m, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a.at(i * m + j);
    }
  }
  vector<int> b(m, 0);
  for (int i = 0; i < m; i++) {
    cin >> b.at(i);
  }
  vector<int> c(n, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      c.at(i) += a.at(i * m + j) * b.at(j);
    }
  }
  for (int i = 0; i < n; i++) cout << c.at(i) << endl;
}


Measured memory_bytes: 3132
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var h = new int[10];
			for (int i = 0; i < 10; i++)
				h[i] = int.Parse(Console.ReadLine());
			Array.Sort(h, (x, y) => { return y - x; });
			Console.WriteLine(h[0]);
			Console.WriteLine(h[1]);
			Console.WriteLine(h[2]);
		}
	}
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define watch(x) cout<<"->"<<#x<<" : "<<x<<endl;
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c)) 
#define all(v) (v).begin(),(v).end()
typedef long long ll;
typedef unsigned long long llu;
const double PI = 2*acos(0.0);
#define int long long
signed main()
{
	//freopen("","r",stdin);
	//freopen("","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a,b;
	cin>>a>>b;
	int n = (a*a) - (b*b);
	int d = (2*a) - (2*b);
	int k = n/d;
	if(abs(a-k)==abs(b-k))
		cout<<k<<endl;
	else 
		cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

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

int main() {
string s;
int n;
cin>>s;
n=s.length();
if(n%2==0){
    if(s[0]==s[n-1]){
        cout<<"First"<<endl;
    }else{
        cout<<"Second"<<endl;
    }
}else{
    if(s[0]==s[n-1]){
        cout<<"Second"<<endl;
    }else{
        cout<<"First"<<endl;
    }
}
	return 0;
}

Measured memory_bytes: 512
def inpl(): return [int(i) for i in input().split()]
from collections import defaultdict

N,M = inpl()
edge = defaultdict(lambda: [])
for _ in range(M):
    a, b = inpl()
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

Qu = [0] 
ctr = 1
color = [0 for _ in range(N)]
color[0] = -1
while ctr < N:
    st = Qu.pop()
    for i in edge[st]:
        if color[st] == -color[i]:
            continue
        if color[i] == 0:
            color[i] = -color[st]
            Qu.append(i)
            ctr += 1
sumc = sum(color)
ans =(N**2-sumc**2)//4-M
for i in range(N):
    for j in edge[i]:
        if color[i] == color[j]:
            ans = N*(N-1)//2-M
            break
    else:
        continue
    break
print(ans)

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

const int INF = 1e9 + 5;

int main(){
  int n, w;
  cin >> n >> w;
  
  vector<int> peso(n), valor(n);
  for(int i=0; i < n; i++){
    cin >> peso[i] >> valor[i];
  }
  int total_valor = 0;

  for(int x : valor){
    total_valor += x;
  }

  // Ahora recorrere un vector de 'total_valor' casillas, para asignar en cada casilla.. un valor de peso menor o igual a 'W'

  vector<int> dp(total_valor + 1, INF);
  dp[0] = 0;

  for(int item=0; item < n; item++){
    for(int valor_actual=total_valor-valor[item]; valor_actual >= 0; valor_actual--){
      dp[valor_actual+valor[item]] = min(dp[valor_actual+valor[item]], dp[valor_actual] + peso[item]);
    }   
  }
  int ans = 0;
  for(int i=0; i < total_valor + 1; i++){
    if(dp[i] <= w){ 
      ans = max(ans, i); 
    }   
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<iterator>
#include<cmath>
#include<string>
#include<algorithm>
#include<sstream>
#include<queue>
#include<list>
#include<deque>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<chrono>


/*  auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stop - start);
pr(duration.count());    */


#define FastIO      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define pb          push_back
#define siz         100009
#define mp          make_pair
#define ll          long long int
#define fileout     freopen("output.txt","w",stdout)
#define filein      freopen("input.txt","r",stdin)
#define pi          acos(-1.0)
#define all(x)      x.begin(),x.end()
#define ull		    unsigned long long int
#define m(a)	    memset(a,0,sizeof(a))
#define f(i,n)	    for(ll i=0;i<n;i++)
#define sc(a)	    scanf("%lld",&a)
#define pr(a)	    printf("%lld\n",a)
const ll inf = 1000000000000000;
ll in = 1000000000000000000;
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
int main()
{
	FastIO;
	ll t, a, i, j, k, m,n, q,b,c;
	string s;
	char ch;
	cin >> ch;
	//cout << (int)'A' << " " << (int)'a' << endl;
	if (ch >= 'A' && ch <= 'Z')
		cout << 'A' << endl;
	else
		cout << 'a' << endl;
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){

	int n;
	cin >> n;

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

	vector<int> cnt(n);
	for(int i=0; i<n; i++){
		if( a[i] >= n ){
			cout << 0 << endl;
			return 0;
		}
		cnt[ a[i] ]++;
	}

	bool f = true;
	if( n%2 == 0 ){
		for(int i=1; i<n; i+=2){
			if( cnt[i] == 2 ) continue;
			else{
				f = false;
				break;
			}
		}
		if( !f ){
			cout << 0 << endl;
			return 0;
		}
	}else{
		for(int i=0; i<n; i+=2){
			if( cnt[i] == 1 && i == 0 ) continue;
			if( cnt[i] == 2 ) continue;
			else{
				f = false;
				break;
			}
		}
		if( !f ){
			cout << 0 << endl;
			return 0;
		}
	}
	
	long long int ans = 1;
	for(int i=0; i<n/2; i++){
		ans *= 2;
		ans %= 1000000000+7;
	}
	ans %= 1000000000+7;
	cout << ans << endl;


	return 0;

}

Measured memory_bytes: 1024
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define NIL -1
using namespace std;
struct _Node {
	int parent;
	int left;
	int right;
};
_Node T[100001];
vector<long long> arr(87, 0);
int main(void)
{
	ios::sync_with_stdio(false);
	int tate, yoko;
	cin >> tate >> yoko;
	vector<vector<int>> arr(10, vector<int>(10, 10000000));
	vector<vector<int>> d(10, vector<int>(10, 0));
	for (int i = 0; i < 10; i++)
	{
		for (int j = 0; j < 10; j++)
		{
			cin >> arr[i][j];
		}
	}
	for (int i = 0; i < 10; i++)      // 経由する頂点
		for (int j = 0; j < 10; j++)    // 開始頂点
			for (int k = 0; k < 10; k++)  // 終端
				arr[j][k] = min(arr[j][k], arr[j][i] + arr[i][k]);
	int count = 0;
	for (int i = 0; i < yoko; i++)
	{
		for (int j = 0; j < tate; j++)
		{
			int a;
			cin >> a;
			if (a != -1)
			{
				count += arr[a][1];
			}
		}
	}
	cout << count << "\n";
}

Measured memory_bytes: 256
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define po pop()
#define pu push
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
string en="\n";
string sp=" ";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    bool f=0,ff=0;string st; char ch;
    while(cin>>n>>k)
    {
        vi v;
        rep(i,n)
        {
            cin>>x;
            v.pb(x);
        }
        sort(all(v));
        s=0;
        rep(i,k)s+=v[i];
        cout<<s<<en;
    }
}




Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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; }
int main(){
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    int min_f = INT32_MAX;
    for(ll i = 1; i*i <= n; i++) {
        if(n%i != 0) continue;
        ll a = i;
        ll b = n/i;
        chmin(min_f,(int)(to_string(b).size()));
    }
    cout << min_f << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
const int INF = 1<<30;

int main(){
    int n, m, s, t;
    cin >> n >> m;
    vector<int> G[300010];
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        G[a].push_back(b+n);
        G[a+n].push_back(b+2*n);
        G[a+2*n].push_back(b);
    }
    cin >> s >> t;
    vector<int> d(300010, INF);
    d[s] = 0;
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({d[s], s});
    while(!que.empty()){
        P p = que.top();
        que.pop();
        int step = p.first, q = p.second;
        for(auto x : G[q]){
            if(d[x] > step + 1){
                d[x] = step + 1;
                que.push({d[x], x});
            }
        }
    }
    cout << (d[t] == INF ? -1 : d[t]/3) << endl;
    return 0;
}

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

int main(){
    long long backBlack, ans = 0;
    bool yetWhite = true;
    string S;
    cin >> S;
    backBlack = S.length() - 1;

    for(int i=S.length()-1; i>= 0; i--){
        if(S[i] == 'W') yetWhite = false;
        if(yetWhite) backBlack--;
        
        if(S[i] == 'B' && !yetWhite){
            ans += backBlack - i;
            backBlack--;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3760
#include <iostream>

using namespace std;

long long lucas(long long l1, long long l2, int n) {
  if (n == 1) return l2;
  if (n == 0) return l1;
  return lucas(l2, l1 + l2, n - 1);
}

int main() {
  int n;
  cin >> n;
  cout << lucas(2, 1, n) << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		char[][] s = new char[h][w];
		int blankCount = 0;

		for (int i = 0; i < h; i++) {
			String str = sc.next();
			for (int j = 0; j < w; j++) {
				s[i][j] = str.charAt(j);
				if (s[i][j] == '.') {
					blankCount++;
				}
			}
		}

		// BFS
		Queue<Pos> queue = new LinkedList<Pos>();
		queue.add(new Pos(0, 0, 0));
		s[0][0] = '/';
		int totalStep = -1;
		while(queue.peek() != null) {
			Pos p = queue.poll();
			if (p.y == h - 1 && p.x == w - 1) {
				totalStep = p.step;
				break;
			} else {
				// Up
				if (p.y - 1 >= 0 && s[p.y - 1][p.x] == '.') {
					s[p.y - 1][p.x] = '/';
					queue.add(new Pos(p.y - 1, p.x, p.step + 1));
				}
				// Down
				if (p.y + 1 < h && s[p.y + 1][p.x] == '.') {
					s[p.y + 1][p.x] = '/';
					queue.add(new Pos(p.y + 1, p.x, p.step + 1));
				}
				// Left
				if (p.x - 1 >= 0 && s[p.y][p.x - 1] == '.') {
					s[p.y][p.x - 1] = '/';
					queue.add(new Pos(p.y, p.x - 1, p.step + 1));
				}
				// Right
				if (p.x + 1 < w && s[p.y][p.x + 1] == '.') {
					s[p.y][p.x + 1] = '/';
					queue.add(new Pos(p.y, p.x + 1, p.step + 1));
				}
			}
		}

		if (totalStep == -1) {
			System.out.println(totalStep);
		} else {
			System.out.println(blankCount - totalStep - 1);
		}
	}

	private static class Pos {
		int y;
		int x;
		int step;

		Pos(int y, int x, int step) {
			this.y = y;
			this.x = x;
			this.step = step;
		}
	}
}


Measured memory_bytes: 22996
n=int(input())
rs=[[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]
for _ in range(n):
    b,f,r,v=map(int,input().split())
    rs[b-1][f-1][r-1] += v
for b in range(4):
    if b > 0: print('#'*20)
    for f in range(3):
        print('',' '.join(map(str,rs[b][f])))
            

Measured memory_bytes: 7760
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////




int main() {

	ll N, C;
	cin >> N >> C;
	vector<ll> A(N + 1), B(N + 1);

	repn(i, N) cin >> A[i];
	repn(i, N) cin >> B[i];

	ll p[500][500];
	rep(i, 500)p[i][0] = 1;

	rep(i, 500)repn(j, 499) {
		p[i][j] = p[i][j - 1] * i%MOD;
	}

	vector<vector<ll>> v(N+1, vector<ll>(C + 1, 0));

	repn(i, N) {
		rep(j, C+1) {
			for (ll k = A[i]; k <= B[i]; k++) {
				v[i][j] += p[k][j];
				v[i][j] %= MOD;
			}

			//cout << i<<j<<v[i][j] << endl;
		}
	}

	vector<vector<ll>> dp(N + 1, vector<ll>(C + 1, 0));
	dp[0][0] = 1;

	repn(n, N)rep(u, C+1) {
		rep(t, u + 1) {
			ll x = dp[n - 1][t] * v[n][u - t];
			x %= MOD;
			dp[n][u] += x;
			dp[n][u] %= MOD;
		}
		//cout << n << u << dp[n][u] << endl;
	}

	cout << dp[N][C];

	system("PAUSE");

}





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


 //vector<bool> w{false,false,false};
 
 int max(int a,int b){
     return (a>=b) ? a : b ;
 }



int max1(int a,int b,int c){
    
    if(a>=b){
        if(a>=c){
           // w[0]=true;
            return a;
        }
        else{
          //  w[2]=true;
            return c;
        }
    }
    else{
        if(b>=c){
          //  w[1]=true;
            return b;
        }
        else{
          //  w[2]=true;
            return c;
        }
    }
}

int main() {
    int n,a;
    cin>>n;
    int arr[n][3];
    for(int i=0;i<n;i++){
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    }
    int res[n+1][4];
    res[0][1]=0;
    res[0][2]=0;
    res[0][3]=0;
    res[1][1]=arr[0][0];
    res[1][2]=arr[0][1];
    res[1][3]=arr[0][2];
    for(int i=2;i<=n;i++){
        for(int j=0;j<4;j++){
            if(j==0)
                res[i][j]=0;
            if(j==1)
                res[i][j]=arr[i-1][j-1]+max(res[i-1][j+1],res[i-1][j+2]);
            if(j==2)
                res[i][j]=arr[i-1][j-1]+max(res[i-1][j-1],res[i-1][j+1]);
            if(j==3)
                res[i][j]=arr[i-1][j-1]+max(res[i-1][j-1],res[i-1][j-2]);
        }
    }
    int ans=max1(res[n][1],res[n][2],res[n][3]);
    cout<<ans<<endl;
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;
int N, K;
ll dp[110][100010];
ll pSum[100010];
int a[110];


int main ()
{
    cin >> N >> K;
    for(int i = 0; i < N; i++) cin >> a[i];
    memset(dp, 0, sizeof(dp));
    memset(pSum, 0, sizeof(pSum));

    dp[0][0] = 1;

    for(int n = 0; n < N; n++)
    {
        for(int k = 0; k <= K; k++) pSum[k + 1] = (pSum[k] + dp[n][k]) % MOD;
        for(int k = 0; k <= K; k++)
        {
            dp[n + 1][k] = pSum[k + 1] - pSum[max(0, k - a[n])];
            dp[n + 1][k] = (dp[n + 1][k] + MOD) % MOD;
        }
        memset(pSum, 0, sizeof(pSum));
    }

    cout << dp[N][K] << endl;
}


Measured memory_bytes: 87040