akhauriyash/Code-Regression huggingface dataset:
using System;

namespace ABC045C
{
  class Program
  {
    static void Main(string[] args)
    {
      string S = Console.ReadLine();
      long res = long.Parse(S);

      for (int size = 1; size < S.Length; size++) {
        System.Collections.Stack stack = new System.Collections.Stack(size);
        int pushNum = 1;
        long sum = 0;

        do {
          if (stack.Count == size) {
            // Goal
            res += sum + long.Parse(S.Substring((int)stack.Peek()));

            pushNum = (int)stack.Pop();
            if (stack.Count > 0) {
              sum -= long.Parse(S.Substring((int)stack.Peek(), pushNum - (int)stack.Peek()));
            } else {
              sum -= long.Parse(S.Substring(0, pushNum));
            }
            pushNum++;
          } else if (pushNum > S.Length - size + stack.Count) {
            pushNum = (int)stack.Pop();
            if (stack.Count > 0) {
              sum -= long.Parse(S.Substring((int)stack.Peek(), pushNum - (int)stack.Peek()));
            } else {
              sum -= long.Parse(S.Substring(0, pushNum));
            }
            pushNum++;
          } else if (!stack.Contains(pushNum)) {
            if (stack.Count > 0) {
              sum += long.Parse(S.Substring((int)stack.Peek(), pushNum - (int)stack.Peek()));
            } else {
              sum += long.Parse(S.Substring(0, pushNum));
            }

            stack.Push(pushNum);
            pushNum++;
          } else {
            pushNum++;
          }

        } while (stack.Count > 0 || pushNum <= S.Length - size);
      }

      Console.WriteLine(res);

    }
  }
}


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

using namespace std;


int main() {
    int n,h;
    cin>>n>>h;
    //cout<<n<<h<<endl;
    int ar[n];
    for(int i=0;i<n;i++)
    cin>>ar[i];
    int b[n];
    b[0]=0;
    b[1]=ar[1]-ar[0];
    if(b[1]<0)
    b[1]=b[1]*(-1);
    int y;
    for(int i=2;i<n;i++)
    {
        int x=INT_MAX;
        for(int j=h;j>0;j--)
        {
            if(i>=j)
            {  // cout<<i<<" "<<j<<endl;
                y=ar[i]-ar[i-j];
                if(y<0)
                y=y*(-1);
                int c=b[i-j]+y;
                if(x>c)
                x=c;
                //cout<<x<<endl;
            }
           // cout<<"l"<<endl;
            b[i]=x;
        }
        //cout<<"l"<<endl;
    }
    cout<<b[n-1]<<endl;
    return 0;
}



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

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int a, b;
  scanf("%d %d", &a, &b);

  printf("%d\n", 2 * b - a);
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

int w;
int h;
bool a[100][100];
int counter = 0;
int hor[3] = {-1,0,1};
int ver[3] = {-1,0,1};
int cnt = 0;
int i;
int j;
int i2;
int j2;

void dfs(int row,int col){
  if(row>=h || col>=w || row<0 || col<0 || a[row][col]==0){
    return;
  }
  a[row][col] = 0;
  for(int i2=0;i2<3;i2++){
    for(int j2=0;j2<3;j2++){
      dfs(row+hor[i2],col+ver[j2]);
    }
  }
}
int main() {
  while(1){
    cnt = 0;
    cin >>w;
    cin >>h;
    if(w==0 || h==0) break;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
      cin>>a[i][j];
      }
    }
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        if(a[i][j]==1){
          cnt++;
          dfs(i,j);
        }
      }
    }
    printf("%d\n",cnt);
  }
}


Measured memory_bytes: 3336
import sys

input = sys.stdin.readline

m, d = map(int, input().split())
answerCount = 0

for m_local in range(1, m + 1):
    for d_local in range(1, d + 1):
        d10 = d_local // 10
        d1 = d_local % 10
        if d1 >= 2 and d10 >= 2 and d1 * d10 == m_local:
            answerCount += 1

print(answerCount)


Measured memory_bytes: 2940
#include<cstdio>
#include<iostream>
#define Max 15
using namespace std;
int n;
int number[Max];
bool flag=false;
void DFS(int l1,int r1,int l2,int r2,int cnt); 
int main()
{
	cin>>n;
	while(n--){
		for(int i=0;i<10;i++)
		{
			cin>>number[i];
		}
		flag=0;
		DFS(0,0,0,0,0);
		if(flag)printf("YES\n");
		else printf("NO\n");
	}
}
void DFS(int l1,int r1,int l2,int r2,int cnt)
{
	if(l2<l1||r2<r1) return ;//出现了上面的球反而小 失败 
	if(cnt==10)
	{
		flag=true;
		return;
	}
	DFS(l2,r1,number[cnt],r2,cnt+1);//往左面放第二个球 那个球放在第一个位置上 
	DFS(l1,r2,l2,number[cnt],cnt+1);                //往右面放第二个球 那个球放在第一个位置上
}



Measured memory_bytes: 3012
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    vector<P> a(100005, {0, 0}), b(100005, {0, 0});
    REP(i, 100001){
        a.at(i).second=i;
        b.at(i).second=i;
    }
    rep(i, n){
        cin >> v.at(i);
        if(i % 2 == 0)a[v.at(i)].first++;
        else b[v.at(i)].first++;
    }
    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    if(a[0].second==b[0].second){
        cout << min(n-b[0].first-a[1].first, n-a[0].first-b[1].first);
    }
    else cout << n-a[0].first-b[0].first;
}

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

int main(){

    int k,s;
    int ans=0;
    cin>>k>>s;


    for(int i=0;i<=k;i++){
        for(int j=0;j<=k;j++){
            if(s-i-j>=0&&s-i-j<=k) ans++;
        }
    }

    cout<<ans;






    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main()
{
    int n;
    int out[4]={0};
    vector<string> out_str={"AC","WA","TLE","RE"};
    
    scanf("%d",&n);
    
    while(n--)
    {
        char inp[4];
        
        scanf("%s",inp);
        
        if(inp[0]=='A')
            out[0]++;
        
        if(inp[0]=='W')
            out[1]++;
        
        if(inp[0]=='T')
            out[2]++;
        
        if(inp[0]=='R')
            out[3]++;
    }
    
    for(int i=0;i<4;i++)
        cout<<out_str[i]<<" x "<<out[i]<<"\n";

    return 0;
}

Measured memory_bytes: 3664
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<set>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define INF 1000000100
#define rep(i,n) for (int i=0;i<n;i++)

const int maxN=100010;

int main(){
    int N,Q;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    cin >> Q;
    int B[Q], C[Q];
    rep(i,Q){
        cin >> B[i] >> C[i];
    }

    map<int,int> mp;
    rep(i,maxN) mp[i]=0;
    ll sum=0;
    rep(i,N){
        sum += A[i];
        mp[A[i]] += 1;
    }
    rep(i,Q){
        sum += mp[B[i]] * (C[i]-B[i]);
        mp[C[i]] += mp[B[i]];
        mp[B[i]] = 0;
        cout << sum << endl;
    }
    return 0;
}

Measured memory_bytes: 9060
#include<iostream>
#include<string>
#include<algorithm>
#include <vector>

using namespace std;
int main(void){
    int n,m,a,b;
    int* array;

    cin >> n >> m;

    array=new int[n];
    for(int i=0;i<n;i++)array[n]=n;

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

    for(int i=0;i<n;i++)cout << array[i] << endl;
}

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

int main() {
    vector <int> a(3);
    for(int i=0;i<3;++i) cin >> a[i];
    sort(a.begin(),a.end());
    bool ok=false;
    if(a[0]==a[1] && a[1]!=a[2]) ok=true;
    if(a[1]==a[2] && a[0]!=a[1]) ok=true;
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    
}



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

using namespace std;

const int maxn = 100001;
int T[4*maxn + 1];
int N, Q, q, a, b;


int update( int ini, int fin, int nd, int s, int v ){

	if( s > fin || s < ini )
		return T[nd];

	if( ini == fin ){
		T[nd] += v;
		return T[nd];
	}

	int m = ( ini + fin ) >> 1;
	int l = ( nd << 1 );
	int r = l | 1;

	int v1 = update( ini, m, l, s, v);
	int v2 = update( m + 1, fin, r, s, v);
	T[nd] = v1 + v2;
	return T[nd];          
}


int query( int ini, int fin, int nd, int qi, int qe ){

	if( qi > fin || qe < ini )
		return 0;

	if( qi <= ini && fin <= qe )
		return T[nd];

	int m = ( ini + fin ) >> 1;
	int l = nd << 1;
	int r = l | 1;

	int v1 = query( ini, m, l, qi, qe );
	int v2 = query( m + 1, fin, r, qi, qe);
	return v1 + v2;
}


int main( void ){

	//freopen("input.in", "r", stdin);
    scanf("%d%d", &N, &Q);

    for( ; Q > 0; --Q ){
    	scanf("%d%d%d", &q, &a, &b);
    	if( q )
    		--a, --b, printf("%d\n", query( 0, N - 1, 1, min(a, b), max(a,b) ) );
    	else
    		--a, update( 0, N - 1, 1, a, b );	
    }

	return 0;
}

Measured memory_bytes: 2212
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 1000000000
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, K, h[111111];

  std::cin >> N >> K;

  for (int i = 0; i < N; i ++)
    std::cin >> h[i];

  std::sort(h, h + N);

  int dm = INF, d;

  for (int i = 0; i + K - 1 < N; i ++)
    if ((d = h[i + K - 1] - h[i]) < dm)
      dm = d;

  std::cout << dm << std::endl;

  return 0;
}


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

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> d(K);
	vector<vector<int>> A(K, vector<int>());
	rep(i, K) {
		cin >> d[i];
		A[i].resize(d[i]);
		rep(j, d[i]) cin >> A[i][j];
	}

	vector<bool> snuke(N, false);
	rep(i, K) {
		rep(j, d[i]) {
			snuke[A[i][j] - 1] = true;
		}
	}

	int ans = 0;
	rep(i, N) {
		if(!snuke[i]) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<sys/time.h>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int ri()
{
	register int x=0;register bool f=0;register char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=getchar();};
	return f?-x:x;
}
void wi(int x)
{
	if(x<0)	x=-x,putchar('-');
	if(x>9)	wi(x/10);
	putchar('0'+x%10);
}
const int N=1e5+7;
int t[N],x[N],y[N];
void gg()
{
	puts("No");
	exit(0);
}
int main()
{
	int n=ri(),i,d,dt;
	for(i=1;i<=n;i++)
	{
		t[i]=ri(),x[i]=ri(),y[i]=ri();
		d=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);dt=t[i]-t[i-1];
		if(d>dt)	gg();
		if((dt-d)%2!=0)	gg();
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef pair<int, int> P;

bool compare(P &lhs, P &rhs) {
    return lhs.second > rhs.second;
}

vector<P> formatter(vector<int> A) {
    sort(A.begin(), A.end());
    vector<P> ret;
    int before = A[0];
    int count = 0;
    for(int i = 0; i < A.size(); i++) {
        if(before == A[i]) {
            count++;
        } else {
            ret.push_back(make_pair(count, before));
            before = A[i];
            count = 1;
        }

        if( i == A.size() - 1) {
            ret.push_back(make_pair(count, before));
        }
    }

    sort(ret.begin(), ret.end(), compare);
    return ret;
}

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

    vector<int> A(N, 0);
    vector<int> T(2*N, 0);

    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    vector<P> ret = formatter(A);

    for(int i = 0; i < M; i++) {
        int b, c;
        cin >> b >> c;
        ret.push_back(make_pair(b, c));
    }
    sort(ret.begin(), ret.end(), compare);

    long long count = 0;
    long long total = 0;
    for(int i = 0; i < ret.size(); i++) {
        int diff = N - ret[i].first;
        if(count >= diff) {
            //cout << N-count << endl;
            total += (long long)(ret[i].second)*(N-count);
            count = N;
            //cout << "total:" << total << endl;
            break;
        } else {
            count += ret[i].first;
            total += (long long)(ret[i].first) * ret[i].second;
            //cout << "total:" << total << endl;
        }
    }

    cout << total << endl;
}


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

namespace atcorder_BeginnerContest_120
{
    class Program
    {

        static void Main(string[] args)
        {

            string str = Console.ReadLine();
           
            int allLen = str.Length;
            int len1 = str.Replace("0", "").Length;
            int len0 = allLen - len1;

            int ret = 0;
            if (len0 < len1)
            {
                ret = len0 * 2;
            }
            else
            {
                ret = len1 * 2;
            }

            Console.WriteLine(ret);

        }
    }
}


Measured memory_bytes: 13536
#include <iostream>
#include <string>
#include<iomanip>
#include <algorithm>
#include <map>
#include <vector>
#include<queue>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include <map>
#include<string.h>
#include<sstream>
#include<stack>
#include<unordered_map>
#include <iostream>
#include <stdio.h>
#include <ctype.h>
#include <cstdio>
#include <cstdlib>
#define ll long long
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 2e5 + 5, inf = 1e9 + 7;
const double ep = 0.0000000001;
const double pi = 3.14159265359;
	
	long long   dp[100005][105];
int main()
{
	int  n, m;
	cin >> n >> m;
	pair <int ,int >arr[105];
	for (int i = 1; i <= n; ++i) {
		cin >> arr[i].first>>arr[i].second;//weight ///price 
	}
	
	dp[m][0] = 0;
	if (m >= arr[0].first) {
		dp[m-arr[0].first][0] = arr[0].second;//m-arr[0].first -->ro7 3la w ely hy5leny 4-1[3][0][cap][item]
	}
	ll  ans=0;//
	for (int item = 1; item <= n; item++) {//colom
		for (int w = 1; w <= m; w++) {//row
				    ll op1 = dp[w][item-1 ];
					ll op2 = 0;
	               if (w >= arr[item].first) 
					 op2 = arr[item].second + dp[w - arr[item].first][item - 1]; 
					dp[w ][item] = max(op1, op2);
						}
			 }	
	  cout << dp[m][n];
	return 0;
}

Measured memory_bytes: 82304
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
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; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  string s;
  cin>>s;
  if(sz(s)<=n){
    COUT(s);
  }
  else{
    rep(i,n){
      cout<<s[i];
    }
    cout<<"...";
  }
}


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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;

#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define ff it->first
#define ss it->second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define LOOP_IT(it,s) for(auto it=(s).begin();it!=(s).end();++it)


#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

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


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}


template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif










int main(int argv, char* argc[])
{
    FASTIO

    int n;
    cin>>n;
    set<string> st;
    rep(i,n)
    {
        string s;
        cin>>s;
        st.insert(s);
    }
    cout<<st.size();

    return 0;
}


Measured memory_bytes: 19236
#include<stdio.h>

int num[50];

int fibonacci(int n){
  if (n==0 || n==1) return num[n]=1;
  if(num[n]!=-1) return num[n];
  return num[n]=fibonacci(n-1)+fibonacci(n-2);
}

int main(){
  int n,i;
  
  for(i=0;i<45;i++) num[i]=-1;

  scanf("%d",&n);
  printf("%d\n",fibonacci(n));

  return 0;
}



Measured memory_bytes: 2132
/**
 *   author: Shubham Srivastava
 *   created: 12 January 2020  17:29:29
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define MOD 1000000007
#define INF 0x7fffffff
#define sorti(v) sort(v.begin(),v.end())
#define sortd(v) sort(v.rbegin(),v.rend())
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
ll parent[2000005];

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    char c;cin>>c;
    cout<<char(c+1);
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

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

    int sum = 0;
    while(0 < n) {
        if (n % 10 == 2) sum++;
        n /= 10;    
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define plll pair<ll,pll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;


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

    bool dp[100010];
    ll n,k;
    cin>>n>>k;
    ll arr1[n];
    for(ll i=0;i<n;i++)
    {
        cin>>arr1[i];
    }
    for(ll i=0;i<arr1[0];i++)
    {
        dp[i]=false;
    }
    for(ll i=arr1[0];i<100010;i++)
    {
        dp[i]=false;
        for(ll j=0;j<n;j++)
        {
            if(i<arr1[j])
            {
                break;
            }
            if(!dp[i-arr1[j]])
            {
                dp[i]=true;
            }
        }
    }
    if(dp[k])
    {
        cout<<"First";
    }
    else
    {
        cout<<"Second";
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    ll n;
    cin >> n;
    vector<ll> a(n, 0), b(n, 0);
    ll sum = 0, count = 0;
    bool zero = false;
    rep1(i, n){
        cin >> a[i];
        sum += abs(a[i]);
        b[i] = abs(a[i]);
        if (a[i]<0) count++;
        if (a[i]==0) zero = true;
    }
    ll ans;
    sort(b.begin(), b.end());
    if (count%2==0 || zero) ans = sum;
    else ans = sum - 2*b[0];
    cout << ans << endl;
    //printf("%.12f", ans);
}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using pi = pair<int,int>;
#define ff first
#define ss second
#define mp make_pair
void setIO() {
ios_base::sync_with_stdio(0); cin.tie(0); // see Fast Input & Output
}
// the code that we provide requires everything above this line to compile
int main() {
setIO();
    ll n;
    cin >> n;

    vector<ll> vals;
    for(int i = 0; i < n; i++){
        ll x;
        cin >> x;
        vals.pb(x);
    }
    ll cur = 1000;
    ll cur_buy = 0;

    for(int j = 1; j < n; j++){
        if(vals[j] < vals[cur_buy]){
            cur_buy = j;
        }
        else{
            ll num_stock = cur / vals[cur_buy];
            ll profit = num_stock * (vals[j] - vals[cur_buy]);
            cur += profit;
            cur_buy = j;
        }
    }
    

    cout << cur << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

int main()
{ 

    ll n;
    string s;
    cin>>n>>s;

    vector<ll> v[10];

    for(ll i=0;i<n;i++)
    	v[s[i]-48].pb(i);
    ll ans=0;

    

    for(ll i=0;i<10;i++)
    {
    	if(v[i].empty())
    		continue;
    	else
    	{	ll x=v[i][0];

       		for(ll j=0;j<10;j++)
       		{
       			if(upper_bound(v[j].begin(),v[j].end(),x)==v[j].end())
       				continue;
       			else
       			{
       				ll y=*upper_bound(v[j].begin(),v[j].end(),x);

       				for(ll k=0;k<10;k++)
       				{
       					if(upper_bound(v[k].begin(),v[k].end(),y)==v[k].end())
       				continue;
       			else
       				 ans++;
       				}
       			}
       		}
    }
    }

    cout<<ans<<endl;
   }

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(false);
	ll N, T, ans=0;
	ll last=-INF;

	cin >> N >> T;
	rep(i,N){
		ll t;
		cin >> t;
		ans += min(T, t-last);
		last = t;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N,X,Y = map(int,input().split())
ans = [0 for i in range(N)]
for i in range(N):
    for j in range(i+1,N):
        c = abs(X-i-1) + abs(Y-j-1)
        ans[min(j-i-1,c)] += 1

for i in range(N-1):
    print(ans[i])

Measured memory_bytes: 3444
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace q5
{
    class Program
    {
        static void Main(string[] args)
        {
            var input1 = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
            var X = input1[0];
            var Y = input1[1];
            var A = input1[2];
            var B = input1[3];
            var C = input1[4];
            var p = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).OrderBy(x => -x).ToArray();
            var q = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).OrderBy(x => -x).ToArray();
            var r = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).OrderBy(x => -x).ToArray();
            var Z = 0;


            var Xm = (X - A);
            for (var i = 0; i < Xm; i++)
            {
                Z += 1;
                X -= 1;
            }
            var Ym = (Y - B);
            for (var i = 0; i < Ym; i++)
            {
                Z += 1;
                Y -= 1;
            }

            var pIdx = X-1;
            var qIdx = Y-1;
            for (var i=0; i<C; i++)
            {
                var v = r[Z];
                if (pIdx != -1 && (qIdx == -1 || p[pIdx] <= q[qIdx]) && p[pIdx] < v)
                {
                    X -= 1;
                    Z += 1;
                    pIdx -= 1;
                }
                else if (qIdx != -1 && (pIdx == -1 || q[qIdx] <= p[pIdx]) && q[qIdx] < v)
                {
                    Y -= 1;
                    Z += 1;
                    qIdx -= 1;
                }
                if (Z >= C)
                    break;
            }


            var result = 0L;
            for (var i = 0; i < X; i++)
            {
                result += p[i];
            }
            for (var i = 0; i < Y; i++)
            {
                result += q[i];
            }
            for (var i = 0; i < Z; i++)
            {
                result += r[i];
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 44176
#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 X,Y; cin>>X>>Y;
    int ans=1;
    while(X*2<=Y){
        X*=2;
        ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, bufio.MaxScanTokenSize)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	defer out.Flush()

	n, _ := strconv.Atoi(next())
	switch n % 10 {
	case 2, 4, 5, 7, 9:
		fmt.Fprintln(out, "hon")
	case 3:
		fmt.Fprintln(out, "bon")
	default:
		fmt.Fprintln(out, "pon")
	}
}


Measured memory_bytes: 1764
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    N = int(input().rstrip())
    H = int(input().rstrip())
    W = int(input().rstrip())
    
    print((H-N)*(W-N) + N - H + N - W + 1)
if __name__ == '__main__':
    solve()


Measured memory_bytes: 3944
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<bitset>
#include<tuple>
#include<time.h>
#include<list>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

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



int n, k, h[202020];
void solve(){
	cin >> n >> k;
	for(int i = 0; i < n; i++){
		cin >> h[i];
	}
	sort(h, h+n, greater<int>());
	i64 cnt = 0;
	for(int i = k; i < n; i++){
		cnt += h[i];
	}
	cout << cnt << endl;
}

int main(){
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1024
#include <climits>
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>

using namespace std;

vector<vector<long long>> g;
vector<long long> memo;

long long dp(long long i) {
  if (memo[i] != -1) return memo[i];
  long long res = 0;
  for (auto n: g[i]) {
    res = max(res, dp(n) + 1);
  }
  memo[i] = res;
  return res;
}

int main() {
  long long n, m;
  cin >> n >> m;

  g.resize(n+1);
  memo.resize(n+1, -1);

  for (int i=0; i<m; i++) {
    long long x, y;
    cin >> x >> y;
    g[x].push_back(y);
  }

  long long ans = 0;

  for (int i=1; i<=n; i++) {
    ans = max(ans, dp(i));
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main(){
  long long n,count=1;
  cin>>n;
  long int prime[1001]={0};
  bool is_prime[1005];
  for(long long i=0;i<1005;++i)
    is_prime[i]=true;
  vector <int> p_index;
  for(long long i=2;i<=1000;++i)
    for(long long j=i*i;j<=1000;j+=i)
      is_prime[j]=false;
  for(long long i=n;i>=2;--i){
    int k=i;
    for(long long j=2;j<=i;j++)
      if(is_prime[j]){
        while(k%j==0){
          prime[j]++;
          k/=j;
        }
      }
  }
  long long result=1;
  for(long long i=1;i<=1000;i++){
    result=(result*(prime[i]+1))%mod;
  }
  cout<<result<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int main(){
	int A,B,C;
	cin >> A >> B >> C;
	bool ret;
	if (A <= C && C <= B) ret = true;
	else ret = false;
	if(ret) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

const int N = 50022;
int n, m, q, MOD, eu[N], ev[N], ec[N], is4[1000233];
int fa[N * 6];
inline int F(int x) {while (x != fa[x]) x = fa[x] = fa[fa[x]]; return x;}
inline void merge(int x, int y) {fa[F(x)] = y;}
inline bool ask(int x, int y) {return F(x) == F(y);}
inline int P(int s, int p, int q) {return s * 6 + p * 3 + q;}

int main() {
  scanf("%d%d%d%d", &n, &m, &q, &MOD);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &eu[i], &ev[i], &ec[i]);
  }
  int g = MOD;
  for (int i = 2; i <= m; i++) {
    g = __gcd(g, abs(ec[i] - ec[1]));
  }
  MOD = MOD / g % 3 ? g : g * 3;
  int z = ec[1] % g;
  for (int i = 1; i <= n * 6 + 6; i++) fa[i] = i;
  for (int i = 1; i <= m; i++) {
    ec[i] = (ec[i] - z) / g % 3;
    for (int p = 0; p < 2; p++) {
      for (int q = 0; q < 3; q++) {
        merge(P(eu[i], p, q), P(ev[i], !p, (2 * q + ec[i]) % 3));
        merge(P(ev[i], p, q), P(eu[i], !p, (2 * q + ec[i]) % 3));
      }
    }
  }
  for (int i = 1, x = z; i <= MOD; i++, x = (x << 2) % MOD) {
    is4[x] = 1;
  }
  while (q--) {
    int s, t, r, ok = 0;
    scanf("%d%d%d", &s, &t, &r);
    for (int p = 0; p < 2; p++) {
      for (int q = 0; q < 3; q++) if (ask(P(t, 0, 0), P(s, p, q))) {
        int x = ((r + z - q * g) % MOD + MOD) % MOD;
        if (p) x = (x << 1) % MOD;
        if (is4[x]) ok = 1;
      }
    }
    puts(ok ? "YES" : "NO");
  }
}


Measured memory_bytes: 6016
//http://codeforces.com/blog/entry/5514
#include<queue>
#include<map>
#include <string>
#include<bits/stdc++.h>
#define pi 3.141592654
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);
//#define x real()
//#define y imag()
using namespace std;
typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//template<typename T>T gcd(T x, T y) { if(y == 0)return x; else return gcd(y, x%y); }
//typedef bitset<30> mask;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//#define var(x) ((x)<<1)
//#define nvar(x) ((x)^1)
int n,a,b,c,d;
string s;
 main()
{

//cout<<Pow((ll)1000000,(ll)110);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//    char input[15];
//    scanf("%s", &input);  array of char
//  gets(c+1);  array of char
//printf("%s, ",name[k[i]].c_str());  printf of string
input;

cin>>n>>a>>b>>c>>d;
a--;
b--;
c--;
d--;
cin>>s;
if(c>d)
{
    int i=b,ck=0;
    while(i!=d)
    {
        if(s[i-1]=='.'&&s[i+1]=='.')ck=1;
        if(s[i+1]=='.')i++;
        else if(s[i+2]=='.')i+=2;
        else
        {
            cout<<"No";
            return 0;
        }
    }
    if(s[i-1]=='.'&&s[i+1]=='.')ck=1;

    if(!ck)
    {
        cout<<"No";
        return 0;
    }
    i=a;
    while(i!=c)
    {
        if(s[i+1]=='.')i++;
        else if(s[i+2]=='.')i+=2;
        else
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}
else
{
    int i=b;
    while(i!=d)
    {
        if(s[i+1]=='.')i++;
        else if(s[i+2]=='.')i+=2;
        else
        {
            cout<<"No";
            return 0;
        }
    }
    i=a;
    while(i!=c)
    {
        if(s[i+1]=='.')i++;
        else if(s[i+2]=='.')i+=2;
        else
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";

}


return 0;
}


Measured memory_bytes: 592
N, K = [int(_) for _ in input().split()]

result = 0

if K % 2 == 1:
    c = N // K
    result = c ** 3
else:
    K2 = K // 2
    c1 = N // K
    c2 = N // K2 - c1
    result = c1 ** 3 + c2 ** 3

print(result)


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int N;
    cin >> N;
    FOR(i, 1000, N)
    {
        if (i % 111 == 0)
        {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll INF = 1LL << 60;

ll n;
vector<ll> a;

int main() {
    cin >> n;
    a.resize(n);
    rep(i, n) cin >> a[i];

    ll tmp = INF;
    int second_idx = -1;

    ll max_a = *max_element(a.begin(), a.end());

    for (int i = 0; i < n; i++) {
        if (max_a == a[i]) continue;

        ll diff = abs(max_a / 2 - a[i]);
        // cout << "i: " << i << " " << diff << " " << n / 2 << " " << a[i] << endl;
        if (diff < tmp) {
            second_idx = a[i];
            tmp = diff;
        }
    }

    cout << max_a << " " << second_idx << endl;
}

Measured memory_bytes: 4012
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a>12)
    {
        cout<<b;
    }
    else if(a>5)
    {
        cout<<b/2;
    }
    else
    {
        cout<<0;
    }
}

Measured memory_bytes: 3576
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int N, K;
  ll ans=1;
  cin >> N >> K;
  int a,b;
  vector<vector<int>> tree(N);
  rep(i,N-1){
    cin >> a >> b;
    a--; b--;
    tree[a].pb(b);
    tree[b].pb(a);
  }
  vector<int> ok(N); rep(i,N)ok[i]=-1;
  queue<int> q;
  q.push(0); ok[0]=1;
  while(!q.empty()){
    int now = q.front();
    q.pop();
    int cnt=K-1;
    if(now!=0)cnt--;
    for(int i=0;i<(int)tree[now].size();i++){
      if(ok[tree[now][i]]==1)continue;
      q.push(tree[now][i]);
      ok[tree[now][i]]=1;
      ans *= cnt;
      ans %= mod;
      cnt--;
    }
  }
  cout << (ans*K)%mod << endl;
  return 0;
}


Measured memory_bytes: 7032
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9 + 7;
const int MAX = 510000;

int main() {
    char x,y; cin >> x >> y;
    if(x>y) puts(">");
    else if(x==y) puts("=");
    else puts("<");
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var d=sc.D;
		d/=3;
		Console.WriteLine("{0}",d*d*d);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
struct node {
long long a,b,c;
} g[2000];
int n,m;
long long s[2000];
bool cmp(long long a,long long b) {
return a > b;
}
int main() {
cin >> n >> m;
memset(s,0,sizeof(s));
long long ans=-1e9;
for(int i = 1; i <= n; i++)
cin >> g[i].a >> g[i].b >> g[i].c;
for(int l=-1;l<=1;l+=2) 
for(int j=-1;j<=1;j+=2)
for(int k=-1;k<=1;k+=2)
{
for(int i = 1; i <= n; i++)
{
long long sum=0;
if(l==1) sum += g[i].a;
else sum -= g[i].a;
if(j==1) sum += g[i].b;
else sum-= g[i].b;
if(k==1) sum += g[i].c;
else sum -= g[i].c;
s[i]=sum; 
}
sort(s+1,s+n+1,cmp);
long long sum1 = 0;
for(int i = 1; i <= m; i++)
sum1 += s[i];
ans=max(ans,sum1);
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
C = [list(map(int, input().split())) for _ in range (M)]
C = list(map(list, set(map(tuple, C))))
C = sorted(C, key=lambda x: x[0])

DEB = False

def check(n, C):
    n_str = str(n)
    if DEB: print(n_str)
    for i in range(len(C)):
        if int(n_str[C[i][0]-1]) != C[i][1]:
            if DEB: print(n_str[C[i][0]-1], C[i][1])
            return False
    else:
        return True

for i in range(10**(N-1) if N>1 else 0, 10**N):
    if check(i, C) is True:
        print(i)
        break
else:
    print(-1)

Measured memory_bytes: 3064
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE NumDecimals #-}
module Main (main) where
import Data.List
-- import Debug.Trace
import qualified Data.ByteString             as S
import qualified Data.ByteString.Char8       as S
import Data.Maybe (fromJust)
getInts :: IO [Integer]
getInts = fmap readInts S.getLine

readInts :: S.ByteString -> [Integer]
readInts = map (fst . fromJust . S.readInteger). S.words

main :: IO ()
main = do
  n:_ <- getInts
  ts <- getInts
  as <- getInts
  print $ solve n ts as
  return ()

solve :: Integer -> [Integer] -> [Integer] -> Integer
solve n ts as = prod' $ zipWith f ts' as'
  where
    ts' = determine ts
    as' = reverse $ determine $ reverse as
    f (t,False) (a,False)        = min t a
    f (t,True) (a,True)
      | t /= a = 0
    f (t,True) (b,_)             = if t <= b then 1 else 0
    f (t,_) (b,True)            = if t >= b then 1 else 0

prod' :: [Integer] -> Integer
prod' = foldl f 1
  where
    f a b = (a * b) `mod` (1e9 + 7)

determine :: [Integer] -> [(Integer,Bool)]
determine xs = zip xs $ zipWith (/=) (0:xs) xs



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

int a, b, c, x, y, ans;

int main() {
	cin >> a >> b >> c >> x >> y;

	if (a + b > c * 2) {
		int m = min(x, y);
		ans = 2 * m * c;
		x -= m;
		y -= m;
		if ((x > y ? a : b) >= c * 2) {
			ans += 2 * max(x, y) * c;
		}
		else {
			ans += max(x, y) * (x > y ? a : b);
		}
	}
	else {
		ans = a*x + b*y;
	}

	cout << ans << endl;
}

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

using namespace::std;

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

	// freopen("milkvisits.in","r",stdin);
	// freopen("milkvisits.out","w",stdout);


	set<int> S;

	for(int i = 0;i < 3;i++){
		int ent;
		cin >> ent;

		S.insert(ent);
	}

	if(S.size() == 2){
		cout << "Yes\n";
	}
	else{
		cout << "No\n";
	}

	return 0;
}

//g++ -std=c++11 -Wall DS.cpp -o main

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

#define N 2000000
 
void maxHeapify(int );
void insert(int );
int extractMax();
void fuelKey(int, int);

int cnt,A[N+1];

int main()
{
 int k;
 char order[10];

 while(1)
 {
  scanf("%s",order);
  if(strcmp(order,"end") == 0) break;

  if(order[0] == 'i')
  {
   scanf("%d",&k);
   insert(k);
  }
  else  printf("%d\n",extractMax());
 }
  
 return 0;
}

void insert(int n)
{
  cnt++;
  A[cnt] = -N;
  fuelKey(cnt,n);
}

void fuelKey(int m, int n)
{
  int swap;
  if(n < A[m]) return;
   A[m] = n;
   while(m > 1 && A[m / 2] < A[m])
   {
    swap = A[m];
    A[m] = A[m/2];
    A[m/2] = swap;
    m = m / 2;
   }
}

int extractMax()
{
 int max;
 
 if(cnt < 1) return -N;

 max = A[1];
 A[1] = A[cnt--];
 maxHeapify(1); 
 return max;
}
 
 
void maxHeapify(int i)
{
  int l = 2*i, r = 2*i + 1;
  int largest,swap;
 
  if(l <= cnt && A[l] > A[i])
    largest = l;
  else
    largest = i;
 
  if(r <= cnt && A[r] > A[largest])
    largest = r;
 
  if(largest != i)
    {
      swap = A[i];
      A[i] = A[largest];
      A[largest] = swap;
      maxHeapify(largest);
    }
   
}
 


Measured memory_bytes: 5680
s = input()
at = 0
to = 0
res = 0

for i in s:
    if i == "g":
        to += 1
        if at > 0:
            at -= 1
            res += 1
        else:
            at += 1
    elif i == "p":
        to -= 1
        if at > 0:
            at -= 1
        else:
            at += 1
            res -= 1
else:
    print(res)


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

//-----------------------------------------------------------------------------

int f(int d) {
	return d*d;
}

bool compare_y(P a,P b) {
	return a.second<b.second;
}

int closest_pair(P *p,int n) {
	if(n<=1) return INF;
	int m=n/2;
	int x=p[m].first;
	int d=min(closest_pair(p,m),closest_pair(p+m,n-m));
	inplace_merge(p,p+m,p+n,compare_y);

	vector<P> b;
	REP(i,n) {
		if(f(p[i].first-x)>=d) continue;
		for(int j=(int)b.size()-1;j>=0;j--) {
			int X=abs(p[i].fi-b[j].fi);
			int Y=abs(p[i].se-b[j].se);
			if(f(Y)>=d) break;
			d=min(d,f(X)+f(Y));
		}
		b.pb(p[i]);
	}
	return d;
}

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

	int n;
	cin>>n;
	P p[n];
	REP(i,n) cin>>p[i].fi>>p[i].se;
	sort(p,p+n);
	cout<<closest_pair(p,n)<<endl;

	return 0;
}



Measured memory_bytes: 12380
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,n) for(int i = (a); i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define debug_v(v,N) for(int i=0;i<N;i++) { cout << v[i] << " "; } cout << endl;
#define debug_vv(v,H,W) for(int i=0;i<H;i++) { for(int j=0;j<W;j++) { cout << v[i][j] << " "; } cout << endl; }

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

ll dp[1005][5000];

void Main()
{
	ll INF = 1000000000000000000;
	int N, M; cin >> N >> M;
	vector<pair<int, ll>> KEY(M);
	rep(i,M) {
		int a, b; cin >> a >> b;
		ll bit = 0;
		rep(j, b) {
			int tmp;
			cin >> tmp;
			bit += (1 << tmp - 1);
		}
		KEY[i] = make_pair(a, bit);
	}
	rep(i, M) rep(j,(1 << N) + 1) dp[i][j] = INF;
	dp[0][0] = 0;
	rep(i,M) {
		rep(j,(1 << N)) {
			ll bit = 0;
			rep(k, N) {
				if ((j >> k & 1) && !(KEY[i].second >> k & 1)) {
					bit += (1 << k);
				}
			}
			dp[i + 1][j] = min(dp[i][j], dp[i][bit] + KEY[i].first);
		}
	}
	if (dp[M][(1 << N) - 1] == INF) {
		cout << -1 << endl;
	} else {
		cout << dp[M][(1 << N) - 1] << endl;
	}
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 39168