akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <math.h>
using namespace std;

int F[100][10];
int P[100][11];
int N;

int main()
{
	cin >> N;
	
	memset(F, 0, sizeof(F));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> F[i][j];
		}
	}
	
	memset(P, 0, sizeof(P));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= 10; j++) {
			cin >> P[i][j];
		}
	}
	
	int num = 0;
	int ind = 0;

	int ans = 0;

	int max = 0;

	for (int i = 1; i <= 1024; i++) {
		ind = i;
		for (int j = 0; j < N; j++) {
			for (int k = 9; k >=0; k--) {
				num += (ind / pow(2, k)) * F[j][k];
				ind = ind % (int)pow(2, k);
			}
			ans += P[j][num];
			ind = i;
			num = 0;
		}
		if (i == 1) max = ans;
		else if (max < ans) {
			max = ans;
		}
		num = 0;
		ans = 0;
	}

	cout << max << endl;

    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace BlackJack
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputNumbers = Console.ReadLine().Split();
            int firstNumber = int.Parse(inputNumbers[0]);
            int secondNumber = int.Parse(inputNumbers[1]);
            int thirdNumber = int.Parse(inputNumbers[2]);

            if (firstNumber + secondNumber + thirdNumber >= 22)
            {
                Console.WriteLine("bust");
            }
            else
            {
                Console.WriteLine("win");
            }
        }
    }
}

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

int main() {
  int N;
  int x;

  cin >> N;

  x = N-(N/10)*10;

  if(x == 2 ||
     x == 4 ||
     x == 5 ||
     x == 7 || 
     x == 9){
       cout << "hon" << endl;
  }
  else if(x == 0 ||
          x == 1 ||
          x == 6 ||
          x == 8){
       cout << "pon" << endl;
          }
  else{
      cout << "bon" << endl;
  }

  return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define COUT(x) cout << (x) << endl
using namespace std;
typedef pair<int,int> P;
typedef long long int ll;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;


int main() {
    int n;
    string s;
    cin >> n >> s;
    ll rcnt = 0, gcnt = 0, bcnt = 0, cnt = 0;
    rep(i, n) {
        if(s[i] == 'R') rcnt++;
        else if(s[i] == 'G') gcnt++;
        else if(s[i] == 'B') bcnt++; 
    }
    for(int i = 1; i < n - 1; i++) {
        if(i < n - i - 1) {
            for(int j = 1; j <= i; j++) {
                if((s[i] != s[i + j]) && (s[i] != s[i - j]) && (s[i + j] != s[i - j])) cnt++;
            }
        } else {
            for(int j = 1; j <= n - i - 1; j++) {
                if((s[i] != s[i + j]) && (s[i] != s[i - j]) && (s[i + j] != s[i - j])) cnt++;
            }
        }
    }

    COUT(rcnt * gcnt * bcnt - cnt);    
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define mp 	    make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define mod        1000000007
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
ll power(ll a , ll b,ll modi)
{
    a%=modi;
    ll res = 1 ;
    while(b)
    {
        if(b%2) {
            res = (res * a) % modi ;
        }
        b/=2 ;
        a = (a*a) % modi ;
    }
    return res ;
}
//ll a[100001];
ll f[100001];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
	//cin>>t;
	while(t--)
	{
	ll n;
	cin>>n;
	ll sum=0;
	for(ll i=1;i<=n;i++){
        ll x;
        cin>>x;
        f[x]++;
        sum+=x;
        }
    int q;
    cin>>q;
    while(q--){
        ll b,c;
        cin>>b>>c;
        ll ch=(c-b)*f[b];
        f[c]+=f[b];
        f[b]=0;
        sum+=ch;
        cout<<sum<<endl;
    }
	}
return 0;
}


Measured memory_bytes: 4388
#include <iostream>
using namespace std;
int main(){
  int hour ,minute ,second ,hour1 ,minute1 ,second1;
  for( int i=0 ; i<3 ; i++ ){ 
    cin >> hour >> minute >> second >> hour1 >> minute1 >> second1;
    
    if( second1 >= second ){
      second1 -= second;
    }
    else{
      minute1--;
      second1 += 60;
      second1 -= second;
    }

    
    if( minute1 >= minute ){
      minute1 -= minute;
    }
    else{
      hour1--;
      minute1 += 60;
      minute1 -= minute;
    }

    hour1 -= hour;
  
    cout << hour1 << " " << minute1 << " " << second1 << endl;
  }
}

Measured memory_bytes: 1160
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;

long long solve(long long n, long long k){
    if(n<k)return solve(k,n);
    if(n%k==0)return k*(2*(n/k)-1);
    long long res = 2*k*(n/k) + solve(k,n%k);
    return res;
}

int main(int argc, char const *argv[]) {
    long long n,x;cin>>n>>x;
    cout<< n + solve(x,n-x)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 505
using namespace std;
typedef long long ll;

ll n, ans=4e18, a[N][N], pl[N][N], mn[N][N], d[N][N];
int main() {
	ll i, j, k, t;
	cin >> n;
	for(i=1; i<=n; i++) for(j=1; j<=n; j++) if(i!=j) scanf("%lld", &a[i][j]);
	for(i=1; i<=n; i++) for(j=1; j<=n; j++) pl[i][j] = pl[i-1][j] + pl[i][j-1] - pl[i-1][j-1] + (i>j ? a[i][j] : 0);
	for(i=1; i<=n; i++) for(j=1; j<=n; j++) mn[i][j] = mn[i-1][j] + mn[i][j-1] - mn[i-1][j-1] + (i<j ? a[i][j] : 0);
	for(i=1; i<=n; i++) {
		d[i][1] = mn[i][i];
		for(j=2; j<=i; j++) {
			d[i][j] = 4e18;
			t = mn[i][i] - mn[i][j-1] - mn[j-1][i] + mn[j-1][j-1];
			for(k=1; k<j; k++) {
				d[i][j] = min(d[i][j], d[j-1][k] + t + pl[i][k-1] - pl[j-1][k-1]);
			}
		}
	}
	for(i=1; i<=n; i++) ans = min(ans, d[n][i]);
	cout << ans;
	return 0;
}

Measured memory_bytes: 8192
#include <stdio.h>

int main(void) {
	char s[3][101];
	int pos[3], turn;

	scanf("%s %s %s", s[0], s[1], s[2]);

	pos[0] = pos[1] = pos[2] = turn = 0;
	while (s[turn][pos[turn]])
		turn = s[turn][pos[turn]++] - 'a';
	printf("%c\n", 'A' + turn);

	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
int h,w,u[405][405],num,c1,c2;
char mp[405][405];
long long ans;
void go(int x,int y)
{
	if(mp[x][y]=='#')
		c1++;
	else
		c2++;
	u[x][y]=num;
	if(x>1&&u[x-1][y]==-1&&mp[x-1][y]!=mp[x][y])
		go(x-1,y);
	if(y>1&&u[x][y-1]==-1&&mp[x][y-1]!=mp[x][y])
		go(x,y-1);
	if(x<h&&u[x+1][y]==-1&&mp[x+1][y]!=mp[x][y])
		go(x+1,y);
	if(y<w&&u[x][y+1]==-1&&mp[x][y+1]!=mp[x][y])
		go(x,y+1);
}
int main(){
	scanf("%d%d",&h,&w);
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			cin>>mp[i][j];
	memset(u,-1,sizeof(u));
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
		{
			if(u[i][j]==-1)
			{
				c1=c2=0;
				go(i,j);
				num++;
				ans+=((long long)(c1*c2));
			}
		}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 20992
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <iomanip>       // fixed, setprecision
using namespace std;

int main()
{
  int64_t N, c = 0;
  cin >> N;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  for (int i = 1; i < N; i++)
  {
    if (A[i - 1] > A[i])
    {
      c += A[i - 1] - A[i];
      A[i] = A[i - 1];
    }
  }
  cout << c << endl;
}


Measured memory_bytes: 4336
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    string S1,S2;
    cin>>S1>>S2;
    int cou=0;
    for(int i=0;i<S1.size();i++){
        if(S1[i]==S2[i])cou++;
    }
    cout<<cou<<endl;
    return 0;
}


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

#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int N = 21;
const int M = (1LL<<N);
int a[N][N];
int dp[N][M];
int pw[N+5];
int n;


int cnt[M];
const int MOD = 1e9 + 7;

void solve()
{
    pw[0] = 1;
    for(int i=1;i<=N;i++) pw[i] = pw[i-1]<<1;
    
    cin >> n;
    f(i,n) f(j,n) cin >> a[i][j];
    
    f(i,n) if(a[0][i] == 1) dp[0][pw[i]] = 1;
        
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<pw[n];j++)
        {
            if(cnt[j] != i) continue; 
        
            for(int k=0;k<n;k++)
            {
                if(a[i][k] == 1 && ( (j&pw[k]) == 0))
                    dp[i][j|pw[k]]=(dp[i][j|pw[k]] + dp[i-1][j])%MOD;
            }
        }
    }
    
    cout << dp[n-1][pw[n]-1]; 
}

signed main()
{
    f(i,M) cnt[i] = __builtin_popcount(i);
    
    fast;
    solve();
}

Measured memory_bytes: 170240
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include<map>
#include <sstream>
#include <deque>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdio>
const int M = 1e9 + 7;
#define ll long long int
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
using namespace std;

//insta  -------  __ansh7
//MSDIAN




int main()
{
    fastio

    ll a,b,c;
    cin>>a>>b>>c;

    ll k;
    cin>>k;

    ll count=0;


    while(b<=a)
    {
        b=b*2;
        count++;
    }

    while(c<=b)
    {
        c=c*2;
        count++;
    }

   
   


    if(count<=k)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    









  

  
    
 



    




    return 0;
}

Measured memory_bytes: 3632
// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(a - c) <= d || (abs(a - b) <= d) && (abs(c - b) <= d)) {
    cout << "Yes" << '\n';
  }
  else cout << "No" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3656
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int main () {
  string S[2];
  cin >> S[0] >> S[1];
  int now = 0;
  while (S[now].size() > 0) {
    cout << S[now][0];
    S[now].erase(0, 1);
    now = 1 - now;
  }
  cout << endl;
}


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

using namespace std;

int main()
{
    int L , R;  cin >> L >> R;
    ll Ans = 1e18;
    for(ll i = L;i<=min(L + 4020 , R);i++){
        for(ll j = i + 1;j<=min(L + 4020 , R);j++){
            Ans = min(Ans , (i * j)%2019);
        }
    }
    cout << Ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  unsigned long long int YUNI = 0, OOT, KYR, JNY, OOTJNY = 10;
  long double A, B, C;
  int D;
  cin >> OOT >> B;
  
  C = OOT * B;
  YUNI = C;
  
  cout << YUNI << endl;
  //cout << C << endl;
}

Measured memory_bytes: 3732
object Main extends App {

  import scala.io.StdIn._

  val n = readInt()
  val piles = Array.tabulate(n){_ ⇒
    val Array(a, b) = readLine.trim.split(' ').map(_.toInt)
    Pile(b, a)
  }
  println(solve(piles))
  def solve(piles: Array[Pile]): Int = {
    val memo = Array.tabulate(piles.length){i ⇒ Array.tabulate(piles.length - i){_ ⇒ None: Option[Int]}}
    memo.indices.foreach(i ⇒ memo(i)(0) = Some(0))
    def sub(left: Int, right: Int): Int = {
      memo(left)(right - left) match {
        case Some(r) ⇒ r
        case None ⇒ (left until right).map{mid ⇒ sub(left, mid) + sub(mid + 1, right) + piles(left).top * piles(mid).bottom * piles(mid + 1).top * piles(right).bottom}.min.also(m ⇒ memo(left)(right - left) = Some(m))
      }
    }
    sub(0, piles.length - 1)
  }
  case class Pile(bottom: Int, top: Int) {
    def merge(right: Pile): Pile = Pile(right.bottom, top)
    def cost(right: Pile): Int = bottom * top * right.bottom * right.top
  }
  implicit class Extension[T](val value :T) extends AnyVal {
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
  }
}


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

int main () {
    int x, n;
    cin >> x >> n;

    if (n == 0) {
        cout << x << endl;
    }
    else {
        vector<int> p(n, 0);
        for (int i = 0; i < n; ++i) {
            cin >> p[i];
        }

        int minval = INT_MAX;
        int ans = 0;
        int a = x;
        int b = x;
        while (true) {
            a--;
            if (find(p.begin(), p.end(), a) == p.end() && abs(x - a) < minval) {
                minval = abs(x - a);
                ans = a;
                break;
            }

            if (find(p.begin(), p.end(), b) == p.end() && abs(x - b) < minval) {
                minval = abs(x - b);
                ans = b;
                break;
            }

            b++;
            if (find(p.begin(), p.end(), b) == p.end() && abs(x - b) < minval) {
                minval = abs(x - b);
                ans = b;
                break;
            }
        }
        cout << ans << endl;
    }

}




Measured memory_bytes: 3632
#include<iostream>
#include<map>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdlib>
#include<math.h>
#include<set>
#include<array>
using namespace std;

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



#define rep(p) for(int i=0;i<(p);i++)
typedef pair<int, int> pii;

typedef long long ll;
typedef pair<ll, ll>pll;
const int MOD = 1000000007;
const int INF = 1 << 29;




int main() {
	
	
	double a, b, x;
	cin >> a >> b >> x;
	
	double sa=0,hen = 2*x/(a*b);

	if (hen > a) {
		
		hen=a;
		sa = 2 * x / (a*a) - b;
		
	}
	

	printf("%.10f",atan((b - sa) / hen) * 180 / (atan(1) * 4));
	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    lint n,k,roop,extra,ans=0;cin>>n>>k;
    if(k==0){
        cout<<n*n<<endl;
        return 0;
    }
    for(int i=k+1;i<=n;i++){
        roop=n/i;
        extra=n%i;
        ans+=roop*(i-k)+max(0LL,extra-k+1);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3584
s = input()
n = len(s)
a = s[:(n-1)//2]
b = s[(n+3)//2-1:]

t = s[::-1]
c = t[:(n-1)//2]
d = t[(n+3)//2-1:]
if (a==b) and (b==c) and (c==d) and (d==a):
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back
#define popf pop_front
#define int long long int
#define vi         vector<int>
#define vll        vector<ll>
#define vpii       vector<pair<int,int>>
#define vpll       vector<pair<ll,ll>>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(container) int((container).size())
#define rep(i,a,b) for(i=a;i<b;i++)
#define tr(container,it)   for(auto it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())      //set,map etc.
#define cpresent(container, element) (find(all(container),element) != container.end())    //vector
#define hell 1000000007
#define PI 3.14159265
#define mod 998244353
#define fs first
#define sc second
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
void solve()
{
  string s;
  cin>>s;
  s='.'+s;
  if(s[3]==s[4] && s[5]==s[6])
    {

      cout<<"Yes";
    }
  else
    cout<<"No";
}
signed main()
{
  fastio
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  int t;
  t=1;
  //cin>>t;
  while(t--)
  solve();
  TIME
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool compare(pair<ll, ll> x, pair<ll, ll> y){
    return x.first > y.first;
}
int main()
{
    ll n, m;
    cin>>n>>m;
    ll a[n];
    for (int i=0; i<n; i++)cin>>a[i];
    vector<pair<ll, ll> > b(m);
    for (int i=0; i<m; i++){
        ll x, y;
        cin>>x>>y;
        b[i] = {y, x};
    }
    sort(a, a+n);
    sort(b.begin(), b.end(), compare );
    // for (int i=0; i<m; i++){
    //     cout<<b[i].first<<" "<<b[i].second<<endl;
    // }
    int s = 0;
    int idx = 0;
    while(s<n && idx<m && b[idx].first > a[s]){
        ll inc = b[idx].second;
        while(s<n && b[idx].first > a[s] && inc > 0){
            a[s] = b[idx].first;
            s++;
            inc--;
        }
        idx++;
    }
    ll sum = 0;
    for (int i=0; i<n; i++)sum+= a[i];
    cout<<sum<<endl;
}

Measured memory_bytes: 5528
from sys import stdin

A = int(stdin.readline().rstrip())
B = int(stdin.readline().rstrip())
C = int(stdin.readline().rstrip())
X = int(stdin.readline().rstrip())

ans = 0
for i in range(A + 1):
    for j in range(B + 1):
        for k in range(C + 1):
            if 500 * i + 100 * j + 50 * k == X:
                ans += 1

print(ans)


Measured memory_bytes: 3060
N, M = [int(i) for i in input().split()]

ac, wa = 0, 0
hist_ac, hist_wa = [0] * N, [0] * N
for i in range(M):
    p, s = input().split()
    p = int(p) - 1
    if hist_ac[p] == 0:
        if s == "AC":
            hist_ac[p] = 1
            ac += 1
            wa += hist_wa[p]
        else:
            hist_wa[p] += 1
print(ac, wa)


Measured memory_bytes: 4596
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
#define itn int
#define all(c) c.begin(),c.end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define ll long long
#define ull unsigned long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
using namespace std; 

const double PI = 3.1415926536;
int days[13] = {0, 31, 28, 31, 30, 31,30, 31, 31, 30, 31, 30, 31};

template<typename T>
ostream& operator <<(ostream& out, const vector<T>& mas) {
    for (const auto& x : mas) {
        out << x << ' ';
    }
    return out;
}

void ok() {
    cout << "YES" << '\n';
}

void no() {
    cout << "NO" << '\n';
}

inline ll nxt() {
    ll x;
    cin >> x;
    return x;
} 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int t1 = nxt(), y = nxt();
    for (int i = 0; i <= t1; i++) {
        int t2 = t1 - i;
        int cur = i * 2 + t2 * 4;
        if (cur == y) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 3648
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
using namespace std;
using ll = long long;
using P =pair<int,int>;

int main() {
    long long int N,A,B,C,D,E,F;
    cin>>N>>A>>B;
    C=(A+B);
    D=N/C;
    E=D*A;
    F=N%C;
    if(A==0){
        cout<<0<<endl;
    }
    else{
        if(F<=A){
            cout<<E+F<<endl;
        }
        else{
            cout<<E+A<<endl;
        }
    }
    
}

    
        

   
    
    
    
    
    
    
    
    

    



Measured memory_bytes: 764
//二次元配列
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main(void){
    int i, j, N,  M, **A, *K, a;
    scanf("%d %d", &N, &M);
    int ANS=0;
    if((K=malloc(sizeof(int)*N)) == NULL) exit(1);
    if((A=malloc(sizeof(int *)*N)) == NULL) exit(1);
    for(i=0; i<N; i++){
        if((A[i]=malloc(sizeof(int)*M)) == NULL) exit(1);
    }
    //all 0
    for(i=0; i<N; i++) for(j=0; j<M; j++) A[i][j]=0;
    for(i=0; i<N; i++){
        scanf("%d", K+i);
        for(j=0; j<K[i]; j++){
            scanf("%d", &a);
            A[i][a-1] = 1;
        }
    }
    for(j=0; j<M; j++){
        a=1;
        for(i=0; i<N; i++) a *= A[i][j];
        if(a==1) ANS++;
    }
    printf("%d\n", ANS);
    for(i=0; i<N; i++) free((void *)A[i]);
    free((void *)A);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>

using namespace std;

double heron(double a,double b,double c){
  double s=(a+b+c)/2;
  return sqrt(s*(s-a)*(s-b)*(s-c));
}

int main(void){

  double a,l,x;
  while(cin >> a >> l >> x){
    double ans=0.0;
    ans+=heron(l,l,a);
    ans+=heron((l+x)/2,(l+x)/2,l)*2;
    printf("%.10f",ans);
    cout << endl;
  }
  return 0;
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if(a > b) {
		if(a > c) cout << a * 10 + b + c;
		else cout << c * 10 + b + a;
	} else {
		if(b > c) cout << b * 10 + a + c;
		else cout << c * 10 + b + a;
	}
	cout << endl;
	return 0;
}


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


int main()
{
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort( a , a+3);
    int ans=0;
    ans += a[2] -a[1];
    a[0] += a[2] -a[1];
    ans +=ceil ((a[2] -a[0])/double(2) ) + (a[2] -a[0])%2;
    cout<<ans;

}

Measured memory_bytes: 3612
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long x = sc.nextLong();
        long count = 0;


        count =(b / x) - (a / x);
        if(a % x == 0){
            
                count++;
            }
        System.out.println(count);
    }
}




Measured memory_bytes: 24020
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N,G; cin>>N>>G;
    vint p(N),c(N);
    REP(i,N) cin>>p[i]>>c[i];

    int ans=1e18;
    for(int S=0;S<(1<<N);S++){
        int score=0,cnt=0;

        REP(i,N){
            if(S>>i&1){
                score+=100*(i+1)*p[i]+c[i];
                cnt+=p[i];
            }
        }
        if(score<G){
            for(int i=N-1;i>=0;i--){
                if(S>>i&1) continue;
                REP(j,p[i]-1){
                    if(score<G){
                        score+=100*(i+1);
                        cnt++;
                    }
                }
            }
        }
        if(score>=G) ans=min(ans,cnt);
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <utility>
#include <numeric>
#include <map>
#include <iomanip>
#include <queue>
using namespace std;

const int INF = 1000000000;
void chmin(int &a, int b) {if(a > b) a = b;}

int main(){
	long long N, M; cin >> N >> M;

	cout << abs((N-2)*(M-2)) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    cin>>h>>w;
    while(h!=0){
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if((i+j)%2==0){cout<<"#";}
                else{cout<<".";}
            
        }cout<<endl;
        }
       cout<<endl;    
        cin>>h>>w;
    }
}


Measured memory_bytes: 3092
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, k, q, a;
    cin >> n >> k >> q;
    vector<int> p(n+1, k);
    for (int i = 0; i < q; ++i) {
        cin >> a;
        ++p[a];
    }

    int ok = q + 1;
    for (int i = 1; i <= n; ++i) {
        if (p[i] >= ok) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, s=0;
  cin >> N;
  for(int i=1; i<N; i++) s+=i;
  cout << s << endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split())

A = list(map(int,input().split()))

dic = {}

for i in A:

    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

lis = []

for i in dic:

    lis.append(dic[i])

lis.sort()

ans = 0

num = len(lis) - K
if num < 0:
    num = 0

for i in range(num):
    ans += lis[i]

print (ans)

Measured memory_bytes: 32284
#include<iostream>
#include<fstream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<math.h>
#define FIO ios_base::sync_with_stdio(0);  cin.tie(0);
#define PI 3.14159265358979323846
#define mod 998244353
#define ll long long
#define vll vector<long long>  
#define all(c) c.begin(), c.end()
// Used to traverse in any STL container with iterators
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
// Find whether element is present in given container or not
#define present(container, element) (container.find(element) != container.end())
// Finds whether element in present container is present in vector or not
#define cpresent(container, element) (find(all(container),element) != container.end())
using namespace std;




int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    FIO

    ll n;
    cin>>n;
    string str;
    int ac=0,wa=0,tle=0, re=0;
    while(n--){
        cin>>str;
        if(str== "AC")ac++;
        if(str=="TLE")tle++;
        if(str=="RE")re++;
        if(str =="WA")wa++;
    }
        cout<<"AC x "<<ac<<endl;
        cout<<"WA x "<<wa<<endl;
        cout<<"TLE x "<<tle<<endl;
        cout<<"RE x "<<re<<endl;
    
}

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

int main(void){
    int n;
    char *a, *b, *t, *u, arr1[512], arr2[512], ans[256], *d;
    for(scanf("%d", &n);n--;){
        memset(arr1, 0, sizeof(arr1));
        memset(arr2, 0, sizeof(arr2));
        a = arr1+128;
        b = arr2+128;
        scanf(" %81[0123456789] %81[0123456789]", a, b);
        t = a;
        u = b;
        while(t-a < 81 && *t) ++t;
        while(u-b < 81 && *u) ++u;
        if(t-a >= 81){
            puts("overflow"); continue;
        }
        if(u-b >= 81){
            puts("overflow"); continue;
        }
        a = t; b = u;
        *a = *b = '0';
        --a; --b;
        t = a; u = b;
        while(*t || *u){
            if(!*t) *t = '0';
            if(!*u) *u = '0';
            --t; --u;
        }
        *t = *u = '0';
        d = t = ans+127;
        while(*a){
            int r = (*a + *b - 2 * '0') + (*(a+1) + *(b+1) - 2 * '0')/10;
            if(!*(a-1) && !r) break;
            *d = r % 10 + '0';
            *a += r / 10;
            --d; --a; --b;
        }
        ++d;
        if(t - d >= 80){
            printf("overflow\n");
            continue;
        }
        printf("%s\n", d);
    }
    return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

int main(){
    std::ios_base::sync_with_stdio(false);
    
    int n,m; cin >> n >> m;
    std::vector<bool> a(n+1, true);
    rep(i,m){
        int k; cin >> k;
        a[k] = false;
    } 

    std::vector<int> ans(n+1,0);
    ans[0] = 1;

    rep(i,n+1){
        if(!a[i]) continue;
        if(i+1<n+1 && a[i+1]) ans[i+1] = (ans[i+1]+ans[i])%MOD;
        if(i+2<n+1 && a[i+2]) ans[i+2] = (ans[i+2]+ans[i])%MOD;
    }

    cout << ans[n] << endl;



    
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;

const int INF = INT_MAX / 4;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( ui i = (ui)( m ); i < (ui)( n ); i++ )
#define EACH( v, c ) for ( __typeof( c.front() ) &v : c )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define RALL( c ) (c).rbegin(), (c).rend()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

bool isPrime( int n )
{
	if ( n < 2 )
	{
		return false;
	}

	for ( int i = 2; i <= sqrt( n ); i++ )
	{
		if ( !( n % i ) )
		{
			return false;
		}
	}

	return true;
}

int main()
{
	while ( true )
	{
		int n;
		cin >> n;

		if ( !n )
		{
			break;
		}

		int count = 0;

		for ( int i = n + 1; i <= n * 2; i++ )
		{
			if ( isPrime( i ) )
			{
				count++;
			}
		}

		cout << count << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#define MAX 510000
#define MOD 1000000007
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}

ll fac[MAX], finv[MAX], inv[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;
}
signed main(){
  init_io();
  COMinit();
  ll n,k,ma_sum=0,mi_sum=0;
  cin >> n >> k;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  for(int i=0;i<n-k+1;i++){
    ll num = COM(n-i-1,k-1);
    mi_sum += (a[i]*num)%MOD;
    ma_sum += (a[n-i-1]*num)%MOD;
    mi_sum %= MOD;
    ma_sum %= MOD;
  }
  ll ans = ma_sum - mi_sum;
  while(ans<0) ans+= MOD;
  ans %= MOD;
  cout << ans << endl;
}


Measured memory_bytes: 13056
#include <stdio.h>

#define MAX_NUMBER	(999999)

int primeFlag[ MAX_NUMBER + 1 ];
int IsPrime( int number );

int main( void )
{
	int num;
	int i;
	
	primeFlag[0] = 0;
	for( i = 1; i <= MAX_NUMBER; i++ )
	{
		primeFlag[i] = primeFlag[ i - 1 ] + IsPrime( i );
	}
	
	while( scanf( "%d", &num ) != EOF )
	{
		if( num == 0 )break;
		printf( "%d\n", primeFlag[ num ] );
	}
	
	return ( 0 );
}

int IsPrime( int number )
{
	int i;
	
	if( number < 2 )
	{
		return ( 0 );
	}
	else if( number == 2 )
	{
		return ( 1 );
	}
	
	if( number % 2 == 0 )
	{
		return ( 0 );
	}
	
	for( i = 3; i * i <= number; i += 2 )
	{
		if( number % i == 0 )
		{
			return ( 0 );
		}
	}
	
	return ( 1 );
}

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

#define ndl "\n"
#define f first
#define s second
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll long long
#define faster ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const ll M = 1e9+7;
const int N = 2*1e5+5;
const ll INF = 1e18;
const double EPS = 1e-6;

ll n,t,dp[N],ans;
pll a[N];

int main () {
	faster;
	cin>>n>>t;
	for (int i = 1; i<=n; i++) {
		cin>>a[i].f>>a[i].s;
	}
	sort(a+1,a+1+n);
	for (int i = 1; i<=n; i++) {
		for (int j = t-1; j>=0; j--) {
			dp[j+a[i].f] = max(dp[j+a[i].f],dp[j]+a[i].s);
		}
	}
	for (int i = 0; i<=6000; i++) ans = max(ans,dp[i]);
	cout<<ans;

    return 0;
}


Measured memory_bytes: 2304
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
const int N=1e5+10;
int n,l,q,cnt=1,dp[N][35],x[N],pw[35]={1},ans;
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
template<typename I>inline void swp(I&a,I&b){I t=a; a=b; b=t;}
int main()
{
//	freopen("Tak and Hotels.in","r",stdin);
	read(n);
	for(RG int i=1;i<=n;i++) read(x[i]);
	read(l,q);
	for(RG int i=1;i<=n;i++) while(x[i]>x[cnt]+l) dp[cnt++][0]=i-1;
	for(RG int i=1;i<=20;i++)
	{
		pw[i]=pw[i-1]<<1;
		for(RG int j=1;j<=n;j++) if(dp[j][i-1]) dp[j][i]=dp[dp[j][i-1]][i-1];
	}
	for(RG int i=1,a,b;i<=q;i++)
	{
		read(a,b); ans=0;
		if(a>b) swp(a,b);
		for(RG int j=20;j>=0;j--) if(dp[a][j] && dp[a][j]<b) a=dp[a][j], ans+=pw[j];
		printf("%d\n",ans+1);
	}
	return 0;
}

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

double a, b, x;
double pi = acos(-1);

int main() {
	scanf("%lf%lf%lf", &a, &b, &x);
	double half = a*a*b/2;
	
	double ang;
	if (x>half) {
		x = a*a*b-x;
		ang = 90 - atan(a / (x/a/a) / 2) / pi * 180;
	} else ang = atan(b / (x/a/b) / 2) / pi * 180;
	printf("%.10lf\n", ang);
	
	return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  string s;
  cin >> s;

  int ans = 0;
  for (auto e : s) {
    if (e == '1') ++ans;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    char str[105]={0};
    scanf("%s", str);

    long len=strlen(str);
    char str2[20]={0};
    sprintf( str2, "%c%ld%c", str[0], len-2, str[len-1]);

    printf("%s\n", str2);

    return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10000000)
 
N = int(input())
H = list(list(map(int,input().split())) for _ in range(N))
#sub problem: max cost from 0 to ith day
memo = {}
def rec(i, choice):
  if (i, choice) in memo:
    return memo[(i, choice)]
  if i == len(H):
    return 0
  m = max(H[i][j] + rec(i+1,j) for j in range(3) if j != choice)
  memo[(i, choice)] = m
  return m
print(max(rec(0, j) for j in range(3)))

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

using namespace std;

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   int N; cin >> N;
   vector<int> A(3 * N);
   for (int i = 0; i < 3 * N; ++i) cin >> A[i], --A[i];
   vector<vector<int>> dp(N, vector<int>(N, -1e9));
   dp[A[0]][A[1]] = dp[A[1]][A[0]] = 0;
   vector<int> best_row(N, -1e9);
   best_row[A[0]] = 0;
   best_row[A[1]] = 0;
   int best = 0;
   int offset = 0;
   for (int cur = 2; cur + 2 < 3 * N; cur += 3) {
      if (A[cur] == A[cur + 1] && A[cur] == A[cur + 2]) {
         offset++;
         continue;
      }
      vector<tuple<int, int, int>> changes;
     changes.reserve(20 * N);
      if (A[cur] == A[cur + 1] || A[cur] == A[cur + 2] || A[cur + 1] == A[cur + 2]) {
         int diff = A[cur] ^ A[cur + 1] ^ A[cur + 2];
         int same = (A[cur] + A[cur + 1] + A[cur + 2] - diff) >> 1;
         for (int z = 0; z < N; ++z) {
            changes.emplace_back(diff, z, dp[same][z] + 1);
            changes.emplace_back(z, diff, dp[z][same] + 1);
         }
      }
      for (int i = 0; i < 3; ++i) {
         int x = A[cur + i];
         int y = A[cur + (i + 1) % 3];
         int z = A[cur + (i + 2) % 3];
         changes.emplace_back(y, z, dp[x][x] + 1);
         changes.emplace_back(z, y, dp[x][x] + 1);
         for (int t = 0; t < N; ++t) {
            changes.emplace_back(x, t, best_row[t]);
            changes.emplace_back(t, x, best_row[t]);
         }
      }
      for (int i = 0; i < 3; ++i) {
         for (int j = 0; j < 3; ++j) if (i ^ j) {
            changes.emplace_back(A[cur + i], A[cur + j], best);
         }
      }
      for (auto c : changes) {
         int x, y, z;
         tie(x, y, z) = c;
         dp[x][y] = max(dp[x][y], z);
         best = max(best, z);
         best_row[x] = max(best_row[x], z);
      }
   }
   best = max(best, dp[A.back()][A.back()] + 1);
   cout << best + offset << '\n';
   return 0;
}


Measured memory_bytes: 19080
#include<bits/stdc++.h>
using namespace std;
int a[100000];
int b[100000];

int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>a[i];
		cin>>b[i];
	}
	
	int s,e;
	for(int i=0;i<m;i++){
		if (i==0) 
		{
			s = a[i];
			e = b[i];
			continue;
		}
		
		if((a[i] > e) || (b[i] < s))
		{
			cout<<0<<endl; 
			return 0;
		}
		else
		{
			s = (a[i] >= s? a[i]:s);
			e = (b[i] <= e? b[i]:e);
		}
	}
	
	cout<<(e - s + 1)<<endl;
	
	return 0;
} 

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

#define MAX 32
typedef pair<int,int> pi;

inline bool isinside(int H, int W, pi p){
  return 0<=p.first&&p.first<H && 0<=p.second&&p.second<W;
}

int cnt;
int ans[MAX][MAX];

void solve(int H, int W, int n, int area[], pi pos[], int M[][MAX], int now){

  /*
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      if( j > 0 ) cout << ' ';
      cout << M[i][j];
    }
    cout << endl;
  }
  cout << " --------------- " << endl;
  */

  if( now > n ){
    ++cnt;
    for(int i = 0; i < H; ++i){
      for(int j = 0; j < W; ++j){
	ans[i][j] = M[i][j];
      }
    }
    return ;
  }
  int A = area[now];
  if( A > 0 ){
    for(int h = 1; h <= A; ++h){
      if( A % h == 0 ){
	int w = A / h;
	for(int i = 0; i < h; ++i){
	  for(int j = 0; j < w; ++j){
	    pi st(pos[now].first-i,pos[now].second-j);
	    pi ed(st.first+h-1,st.second+w-1);
	    if( isinside( H,W,st ) && isinside( H,W,ed ) ){

	      //	      cout << " NOW : " << now << ' ' << st.first << ' ' << st.second << ' ' << h << ' ' << w << endl;
	      
	      int tM[MAX][MAX];
	      for(int ti = 0; ti < H; ++ti){
		for(int tj = 0; tj < W; ++tj){
		  tM[ti][tj] = M[ti][tj];
		}
	      }
	      
	      for(int ti = 0; ti < h; ++ti){
		for(int tj = 0; tj < w; ++tj){
		  if( M[st.first+ti][st.second+tj] != now && M[st.first+ti][st.second+tj] != 0 ) goto next;
		  M[st.first+ti][st.second+tj] = now;
		}
	      }
	      solve( H,W,n,area,pos,M,now+1 );
	      
	    next:;
	      for(int ti = 0; ti < H; ++ti){
		for(int tj = 0; tj < W; ++tj){
		  M[ti][tj] = tM[ti][tj];
		}
	      }
	    }
	  }
	}
      }
    }
  }else{
    solve( H,W,n,area,pos,M,now+1 );
  }
  return ;
}

int main()
{
  while(true){
    int H,W,n;
    int area[MAX]={0,};
    pi pos[MAX];
    int M[MAX][MAX]={{0,},};
    cin >> W >> H >> n;
    if( H == 0 && W == 0 && n == 0 ) break;

    for(int i = 0; i < n; ++i){
      int b,k;
      cin >> b >> k;
      area[b]=k;
    }
    
    for(int i = 0; i < H; ++i){
      for(int j = 0; j < W; ++j){
	cin >> M[i][j];
	if( M[i][j] > 0 ){
	  pos[ M[i][j] ] = pi(i,j);
	}
      }
    }

    cnt = 0;
    solve( H,W,n,area,pos,M,1 );

    if( cnt == 1 ){
      for(int i = 0; i < H; ++i){
	for(int j = 0; j < W; ++j){
	  if( j > 0 ) cout << ' ';
	  cout << ans[i][j];
	}
	cout << endl;
      }
    }else{
      cout << "NA" << endl;
    }
    
  }  
  return 0;
}

Measured memory_bytes: 924
from heapq import heappop, heappush

n, nTake = map(int, input().split())
a = sorted([tuple(map(int, input().split())) for _ in range(n)], key=lambda x: (-x[1], x[0]))

totalTaste = 0
same = []
types = set()
for i in range(nTake):
    type, taste = a[i]
    totalTaste += taste
    if type not in types:
        types.add(type)
    else:
        heappush(same, taste)

rem = []
typesRem = set()
for i in range(nTake, n):
    type, taste = a[i]
    if type not in types and type not in typesRem:
        typesRem.add(type)
        heappush(rem, -taste)

ret = totalTaste + len(types) ** 2
curTotal = totalTaste
add = 1
while same and rem:
    worst = heappop(same)
    best = heappop(rem)
    curTotal = curTotal - worst - best
    ret = max(ret, curTotal + (len(types) + add) ** 2)
    add += 1
print(ret)

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int cnt=0, ans;
    for(int i = 100; i >= 0; i--)
    {
        if(a%i==0 && b%i==0){
            cnt++;
        }
        if(cnt==c){
            ans=i;
            break;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
// ABC081B - Break Number

#include <bits/stdc++.h>
using namespace std;

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

	int ans = 2;
	while (1) {
		if (ans > N) {
			break;
		}
		ans *= 2;
	}

	cout << ans / 2 << endl;

	return 0;
}


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

int main () {

    int N, K, Q;
    scanf("%d %d %d", &N, &K, &Q);

    vector<int> p(N, 0);

    vector<int> A(Q);
    for (int i = 0; i < Q; i++) {
        scanf("%d", &A[i]);
        A[i]--;

        p[0] += -1;
        p[A[i]] += 1;
        if (A[i] != N-1) {
            p[A[i]+1] += -1;
        }
    }

    for (int i = 1; i < N; i++) {
        p[i] += p[i-1];
    }

    for (int i = 0; i < N; i++) {
        if (K + p[i] > 0) {
            printf("Yes\n");
        }
        else {
            printf("No\n");
        }
    }

    return 0;
}

Measured memory_bytes: 1408
using System;

public class Test
{
	static public void Main( )
	{

		var n = int.Parse( Console.ReadLine() );
		string[] data = Console.ReadLine().Split( ' ' );
		var max = Int64.MinValue;
		var min = Int64.MaxValue;
		var sum = Int64.Parse( "0" );
		for( var i=0; i<n; i++ ) {
			var v = Int64.Parse( data[i] ) ;
			if( max < v ) {
				max = v ;
			}
			if( v < min ) {
				min = v;
			}
			sum += v;
		}
		Console.WriteLine( "{0} {1} {2}" , min, max, sum );
	}
}

Measured memory_bytes: 19964