akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

vector< vector<long long> > dp( 3001 , vector<long long>(3000,-1) );
vector< vector<long long> > dp1( 3001 , vector<long long>(3000,-1) );


long long doWork(vector<long long> &a,long long l,long long r,long long turn){
	if(l>r)
		return 0;
	if(dp[l][r]!=-1 && turn==1)
		return dp[l][r];

	if(dp1[l][r]!=-1 && turn==0)
		return dp1[l][r];

	if(turn==1){
		return (dp[l][r] = max(doWork(a,l+1,r,0)+a[l],doWork(a,l,r-1,0)+a[r]));
	}else{
		return (dp1[l][r]=min(doWork(a,l+1,r,1),doWork(a,l,r-1,1)));
	}
}

int main(){

	long long n;
	cin >> n;

	long long sum = 0;

	vector<long long> a(n+1);

	for(long long i=0;i<n;i++){
		cin >> a[i];
		sum+=a[i];
	}

	cout << 2*doWork(a,0,n-1,1)-sum << "\n";


	return 0;
}

Measured memory_bytes: 141312
#include<iostream>
#include<string>
#include<cstdlib>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
	long long int n,a,b;
	cin >> n >> a >> b;
	
	if(a > b || a != b && n <= 1){
		cout << 0 << endl;
	}
	else{
		if(a == b)
			cout << 1 << endl;
		else{
			cout << (b-a)*(n-2) + 1 << endl;
		}
	}
	
 	return 0;
}

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

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    if (A < B)
    {
        int temp = A;
        A = B;
        B = temp;
    }
    int r = A % B;
    while (r != 0)
    {
        A = B;
        B = r;
        r = A % B;
    }
    stack<int> fgc;
    for (int i = 1; i <= B; i++)
    {
        if (B % i == 0) fgc.push(i);
    }
    for (int i = 0; i < K - 1; i++) fgc.pop();
    cout << fgc.top();
}

Measured memory_bytes: 3604
#define dbg(...) fprintf(stderr,__VA_ARGS__)
#define dpr(x) cerr<<#x<<": "<<x<<endl;
#define dprc(c) do{cerr<<#c<<":";for(auto&_i:(c)){cerr<<" "<<_i;}cerr<<endl;}while(0)
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int INF = 1e9+7;
#define all(c) begin(c), end(c)
#define tr(i,c) for(auto i=begin(c);i!=end(c);i++)
#define rtr(i,c) for(auto i=(c).rbegin();i!=(c).rend();i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

int cnt, m;
vi G;

void insertionSort(vi& A, int n, int g) {
  for (int i = g; i < n; i++) {
    int v = A[i];
    int j = i - g;
    while (j >= 0 && A[j] > v) {
      A[j+g] = A[j];
      j = j - g;
      cnt++;
    }
    A[j+g] = v;
  }
}

void shellSort(vi& A, int n) {
  cnt = 0;
  G = vi(0);
  int g = 1;
  do {
    G.pb(g);
    g = g*3 + 1;
  } while (g <= n);
  reverse(all(G));
  m = sz(G);
  for (auto& g:G) {
    insertionSort(A, n, g);
  }
}

void dump(vi& A, const string& sep) {
  string sp = "";
  for (auto& a:A) {
    cout << sp << a;
    sp = sep;
  }
  cout << endl;
}

int main(int argc, char **argv)
{
  vi A;
  int n;
  cin >> n;
  A = vi(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  shellSort(A, n);

  cout << m << endl;
  dump(G, " ");
  cout << cnt << endl;
  dump(A, "\n");
  return 0;
}

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

int main() {
    int m, f, r;
    while (1) {
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) break;

        if (m == -1 || f == -1) {
            cout << "F" << "\n";
            continue;
        }
        if (m + f >= 80) cout << "A" << "\n";
        if (m + f < 80 && m + f >= 65) cout << "B" << "\n";
        if (m + f < 65 && m + f >= 50) cout << "C" << "\n";
        if (m + f < 50 && m + f >= 30 ){
            if (r >= 50) cout << "C" << "\n";
            else cout << "D" << "\n";
        }
        if (m + f < 30) cout << "F" << "\n";
    }

    return 0;
}

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

#define MAXN 3007

int n , m ;
vector < int > v[ MAXN ][ MAXN ] ;

long long dp[ MAXN ][ MAXN ][ 4 ] ;

void add ( int x , int y , int z ) {
    v[ x ][ y ].push_back ( z ) ;
    sort ( v[ x ][ y ].begin ( ) , v[ x ][ y ].end ( ) , greater < int > ( ) ) ;
    while ( v[ x ][ y ].size ( ) > 3 ) {
        v[ x ][ y ].pop_back ( ) ;
    }
}

void input ( ) {
    int k ;
    cin >> n >> m >> k ;
    for ( int i = 1 ; i <= k ; ++ i ) {
        int x , y , z ;
        cin >> x >> y >> z ;
        add ( x , y , z ) ;
    }
}

void solve ( ) {
    for ( int i = 1 ; i <= n ; ++ i ) {
        for ( int j = 1 ; j <= m ; ++ j ) {
            int sz = v[ i ][ j ].size ( ) ;
            for ( int z = 0 ; z < sz ; ++ z ) {
                for ( int t = 0 ; t < 3 ; ++ t ) {
                    dp[ i ][ j ][ t ] = max ( dp[ i ][ j ][ t ] , dp[ i ][ j ][ t + 1 ] + v[ i ][ j ][ z ] ) ;
                }
            }
            for ( int t = 0 ; t <= 3 ; ++ t ) {
                dp[ i ][ j + 1 ][ t ] = max ( dp[ i ][ j + 1 ][ t ] , dp[ i ][ j ][ t ] ) ;
                dp[ i + 1 ][ j ][ 3 ] = max ( dp[ i + 1 ][ j ][ 3 ] , dp[ i ][ j ][ t ] ) ;
            }
        }
    }
    long long ans = 0 ;
    for ( int i = 0 ; i <= 3 ; ++ i ) {
        ans = max ( dp[ n ][ m ][ i ] , ans ) ;
    }
    cout << ans << "\n" ;
}


int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    input ( ) ;
    solve ( ) ;
    return 0 ;
}


Measured memory_bytes: 503588
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <unordered_set>
#include <ctime>
#include <numeric>

typedef long long int llint;

int main(void){
  llint n, k;
  std::cin >> n >> k;
  std::vector<int> A(n+1);
  for(int i=1; i<=n; i++){
    std::cin >> A[i];
  }
  std::vector<int> last(n+1,-1);
  last[1]=0;

  int now = 1;
  for(int i=0; i<std::min(k, n+1); i++){
    if(last[A[now]] != -1){
      // find a loop!
      int diff = last[now]+1 - last[A[now]];

      llint nokori = k - last[A[now]];
      now = A[now];
      nokori = nokori % diff;
      for(int j=0; j<nokori; j++){
	now = A[now];
      }
      std::cout << now << std::endl;
      return 0;
      
    }else{
      last[A[now]] = last[now]+1;
      now = A[now];
    }
  }
  std::cout << now << std::endl;
  return 0;
}


Measured memory_bytes: 4844
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long;
// #define int ll
using PII = pair<int, int>;
 
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
 
template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) { 
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }
 
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}
 
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<40;
const ll MOD = 1000000007;

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

  ll n;
  cin >> n;
  n = 2*n-1;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];

  auto check = [&](ll mid) -> bool {
    vector<ll> v(n);
    REP(i, n) v[i] = a[i] >= mid;

    ll prev = 0;
    FOR(i, 1, n) {
      if(v[i] == v[i-1]) {
        if(prev < i-1) {
          ll x = ceil(prev+i-1, 2LL);
          FOR(j, prev, x) v[j] = v[prev];
          FOR(j, x, i) v[j] = v[i-1];
        }
        prev = i;
      }
    }
    if(prev < n-1) {
      ll x = ceil(prev+n-1, 2LL);
      FOR(j, prev, x) v[j] = v[prev];
      FOR(j, x, n) v[j] = v[n-1];
    }
    return v[n/2];
  };

  ll lb = 1, ub = n+1;
  while(ub-lb > 1) {
    ll mid = (lb+ub)/2;
    if(check(mid)) lb = mid;
    else ub = mid;
  }

  cout << lb << endl;

  return 0;
}


Measured memory_bytes: 3436
//Half and Half
#include <iostream>
using namespace std;

int main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int t;
    int T;
    if((a+b)<=c*2){
        cout << a*x+b*y << endl;
    }
    else{
        if(x>=y){
            t= y*c*2+(x-y)*a;
            T= x*c*2;
        }
        else if(x<y){
            t= x*c*2+(y-x)*b;
            T= y*c*2;
        }
        cout << min(t,T) << endl;

    }

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#define INT long long
using namespace std;
INT a, b, c, d, cnt[110], ans;

int main()
{
    cin>>a>>b>>c>>d;
    for(int i = a ; i < b ; i++ ) cnt[i]++;
    for(int i = c ; i < d ; i++ ) cnt[i]++;
    for(int i = 0 ; i <= 100 ; i++ )
        if( cnt[i] == 2 ) ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int n;
	cin >> n;
	int s = 0;
	for(int i = 1; ;i++){
		if(1000 * i >= n){
			cout << 1000*i -n;
			return 0;
		}
	}
}

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

const int Nmax=200010;

int main() {
	int N,K;
	int ans = 1;
  	cin >> N >> K;
	for(int i=0;i < N;i++){
		ans = min(ans*2, ans+K);
	}
	cout << ans << endl;
	
	return 0;
}

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

long long int dp[3000][3000] = {};
vector<int> A(3000);

string s;


int main()
{
	cin >> s;
	int N = s.length();

	vector<int> M(N), A(N), S(N + 1);

	M[0] = 1;
	for (int i = 1; i < N; ++i)
		M[i] = M[i - 1] * 10 % 2019;

	std::reverse(s.begin(), s.end());

	S[0] = 0;
	for (int i = 0; i < N; ++i)
	{
		A[i] = M[i] * (s[i] - '0') % 2019;
		S[i + 1] = (S[i] + A[i]) % 2019;
	}

	int ans = 0;
	int cnt[2019] = {};
	for (int i = 0; i <= N; ++i)
	{
		ans += cnt[S[i]];
		cnt[S[i]]++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 5928
#include<bits/stdc++.h>
#define int long long int
#define ldouble long double
#define vin vector<int>
#define pqueue priority_queue
#define rep(a,n) for(int i=(a);i<(n);i++)
#define INF (int)1000000007

//setprecision()<<

using namespace std;

void fin(int n,vin &a){
    rep(0,n){
        cin>>a.at(i);
    }
}

signed main(){
    typedef pair<int,int> P;
    int N;
    cin>>N;
    vin A(N);
    fin(N,A);
    vin B(N);
    rep(0,N){
        B.at(i)=A.at(i);
    }
    sort(B.begin(),B.end());

    //cout<<"OK2"<<endl;

    vector<P> cnt(0);
    int head=0;
    cnt.push_back(make_pair(B.at(0),1));
    rep(0,N-1){
        if(B.at(i)!=B.at(i+1)){
            cnt.push_back(make_pair(B.at(i+1),1));
            head++;
        }
        else{
            cnt.at(head).second++;
        }
    }
    //cout<<"OK"<<endl;

    // rep(0,cnt.size()){
    //     cout<<cnt.at(i).first<<" "<<cnt.at(i).second<<endl;
    // }

    vector<vector<int> > comb(N+1,vector<int>(2));
    int sum=0;
    rep(0,cnt.size()){
        int n=cnt.at(i).second;
        if(n>=2) comb.at(cnt.at(i).first).at(0)=(n*(n-1))/2;
        else comb.at(cnt.at(i).first).at(0)=0;
        if(n>2)  comb.at(cnt.at(i).first).at(1)=((n-1)*(n-2))/2;
        else comb.at(cnt.at(i).first).at(1)=0;
        sum+=comb.at(cnt.at(i).first).at(0);
    }

    rep(0,N){
        cout<<sum-comb.at(A.at(i)).at(0)+comb.at(A.at(i)).at(1)<<endl;

    }

    return 0;
}

Measured memory_bytes: 19312
import sys

N = int(input())
A = list(map(int, input().split()))
A = sorted([A[k]-(k+1) for k in range(N)])

if N == 1:
  print(0)
  sys.exit()

for k in range((N-2)//2 + 1, N-1):
  if A[k] < A[k+1]:
    b = k
    break
  if k == N-2:
    print(0)
    sys.exit()
print(sum([abs(A[k]-A[b]) for k in range(N)]))

Measured memory_bytes: 26836
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N;
	cin >> N;
	int p = 0;
	rep(i,N){
		int x;
		cin >> x;
		if(p <= x-1) x--;
		if(p > x){
			cout << "No" << endl;
			return 0;
		}
		p = x;
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 892
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int L,i;cin>>L;
	int hen=36;
	for(int h=0;h<19;h++){
		if(L&(1<<h)){hen++;}
	}
	if(L&(1<<19)){hen+=2;}
	cout<<20<<" "<<hen<<endl;
	for(int i=0;i<18;i++){
		cout<<i+1<<" "<<i+2<<" 0\n";
		cout<<i+1<<" "<<i+2<<" "<<(1<<i)<<endl;
		if(L&(1<<i)){cout<<i+1<<" 20 "<<(L&((1<<i)-1))<<endl;}
	}
	if(L/(1<<18)>=1){cout<<19<<" 20 "<<(L&((1<<18)-1))<<endl;}
	if(L/(1<<18)>=2){cout<<19<<" 20 "<<(L&((1<<18)-1))+(1<<18)<<endl;}
	if(L/(1<<18)>=3){cout<<19<<" 20 "<<(L&((1<<18)-1))+(2<<18)<<endl;}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int n;
  long long int ans;
  ans=1;
  scanf("%d",&n);
  long long int a[100005];
  for(int i=0;i<n;i++)
  {
      scanf("%lld",&a[i]);
      if(!a[i])
      {
          printf("0");
          return 0;
      }
  }
    
 for(int i=0;i<n;i++)  {
    long long int temp;
    temp=ans*a[i];
    if(ans>temp||temp>1000000000000000000){
        printf("-1");
        return 0;
    }
    ans=temp;
  }
  printf("%lld",ans);
  return 0;
}

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

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

    string s;
    cin>>s;
    if(s[0]!=s[1]||s[1]!=s[2]||s[0]!=s[2]){
        cout<<"Yes"<<endl;
        return 0;
    }
    else{
        cout<<"No"<<endl;
        return 0;
    }
}

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

#define int long long int
#define MOD 1000000007

double get(pair<double, double> p, pair<double, double> q)
{
    double dist = 0 ;
    
    dist = (double)sqrt((p.first - q.first) * (p.first - q.first) + (p.second - q.second) * (p.second - q.second)) ;
    return dist ;
}

void solve()
{
    int n ;
    cin >> n ;
    int ind[n] ;
    pair<double, double> a[n] ;
    double x, y ;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> x >> y ;
        a[i] = {x, y} ;
        ind[i] = i ;
    }
    double sum = 0 ;
    double avgSum = 0 ;
    do
    {
        sum = 0 ;
        for(int i = 1 ; i < n ; i++)
        {
            sum += get(a[ind[i-1]], a[ind[i]]) ;
        }
        avgSum += sum ;
    }while(next_permutation(ind, ind + n)) ;
    
    cout << fixed << setprecision(10) ;
    
    int divd = 1 ;
    for(int i = 2 ; i <= n ; i++)
        divd *= i ;
    
    avgSum /= divd ;
    cout << avgSum << endl ;
}

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

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

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

int main(){
  int n, b, f , r, v;
  int building[4][3][10]={};
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> b >> f >> r >> v;
    building[b-1][f-1][r-1] += v;
  }
  for(int b_i =0; b_i<4; b_i++){
    for(int f_i=0; f_i < 3; f_i++){
      for(int r_i=0; r_i < 10; r_i++){
          cout << " " << building[b_i][f_i][r_i];
      }
    cout << endl;
    }
  if(b_i < 3)
    cout << "####################" << endl;
  }
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    ll n,m;
    cin>>n>>m;
    unordered_map<ll,ll> mpa,mpb;
    rep(i,m){
        ll ta,tb;
        cin>>ta>>tb;
        if(ta==1)mpa[tb]=1;
        if(tb==n)mpb[ta]=1;
    }
    bool flg=false;
    for(auto x:mpa){
        if(mpb[x.first]==1)flg=true;
    }
    if(flg)cout<<"POSSIBLE"<<endl;
    else cout << "IMPOSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 12652
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define int long long

signed main(){
	int ans;
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if(a >= k)ans = k;
	else if(a + b >= k)ans = a;
	else ans = a - (k - a - b);
	cout << ans << endl;
	return 0;
}

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

int main() {
  vector<int> A(5);
  int k;
  for (int i = 0; i < 5; i++) {
  	cin >> A.at(i);
  }
  cin >> k;
  
  bool found = false;
  for (int i = 0; i < 5; i++) {
    if (found) break;
  	for (int j = i; j < 5; j++) {
      if (found) break;
      if (A.at(j) - A.at(i) > k) {
        found = true;
      }
    }
  }
  if (found) cout << ":(" << endl;
  else cout << "Yay!" << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
N, M = map(int, input().split())
MOD = 10 ** 9 + 7
prime = defaultdict(int)

for i in range(2, M + 1):
    if i * i > M:
        break
        
    while M % i == 0:
        prime[i] += 1
        M //= i
        
if M != 1:
    prime[M] = 1
    
def comb(n, k):
    ret = 1
    for i in range(1, k + 1):
        ret = ret * (n - i + 1) % MOD
        ret = ret * pow(i, MOD - 2, MOD) % MOD
        
    return ret

ans = 1
for v in prime.values():
    ans = ans * comb(N + v - 1, N - 1) % MOD
    
print(ans)


Measured memory_bytes: 39408
# -*- coding: utf-8 -*-
# 08-Computation-Simple_Calculator.py

# ?¨???????
# ???????????´??° a, b ??¨?????????????????? op ?????????????????§???a op b ????¨??????????????????°?????????????????????????????????
# ????????????????????? op ??????"+"(???)???"-"(???)???"*"(???)???"/"(???)???????????¨?????????????????§????????????????????´??????????°???°?????\??????????????¨????????????????¨????????????¨????????????

# Input
# ??\???????????°????????????????????????????§???????????????????????????????????????????????????¢????????\????????¨????????§??????
# a op b
# op ??? '?' ?????¨??? ??\?????????????????????????????????????????±???????????????????????£????????????????????????
# Output
# ?????????????????????????????????????¨??????????????????????????????????????????????

# Constraints
# 0 ??? a, b ??? 20000
# 0 ?????????????????????????????????????????¨?????????????????????
# Sample Input
# 1 + 2
# 56 - 18
# 13 * 2
# 100 / 10
# 27 + 81
# 0 ? 0
# Sample Output
# 3
# 38
# 26
# 10
# 108

import sys

output = []


while 1:
	a,op,b = input().split()
	a= int(a)
	b= int(b)

	if op=="+":
		output.append(a+b)
	elif op =="-":
		output.append(a-b)
	elif op =="*":
		output.append(a*b)
	elif op =="/":
		output.append( int(a/b) )
	elif op =="?":
		break;
	else:
		sys.exit()

for i in range( len(output)):
	print(output[i])

Measured memory_bytes: 7664
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e9+7;
int main(){
	ll n,k;
	cin >> n >> k;
	ll m=(((k+1)*k)/2)%N;
	ll p =((k*(k-1))/2)%N;
	ll a[n];
	for(int i=0;i<n;i++)scanf("%lld",&a[i]);
	ll cnt = 0;
	for(int i=0;i<n;i++){
		ll sum=0;
		ll ans=0;
		for(int j=i+1;j<n;j++){
			if(a[i]>a[j])sum++;
		} 
		sum%=N;
		cnt+=(sum*(m%N))%N;
		for(int j=i-1;j>=0;j--){
			if(a[i]>a[j])ans++;
		}
		ans%=N;
		cnt+=(ans*(p%N))%N;
	}
	cout << cnt%N << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			String s = scanner.next();
			StringBuilder sb = new StringBuilder();
			s.chars().forEach(c -> {
				switch (c) {
				case '0':
				case '1':
					sb.append((char) c);
					break;
				case 'B':
					if (sb.length() > 0) {
						sb.deleteCharAt(sb.length() - 1);
					}
					break;
				default:
					break;
				}
			});
			System.out.println(sb.toString());
		}
	}
}


Measured memory_bytes: 35624
#include <iostream>
#include <string>
using namespace std;
int main() {
  string S;
  cin >> S;
  int f = stoi(S.substr(0, 2));
  int l = stoi(S.substr(2, 2));
  bool isFMM = 0 < f && f < 13;
  bool isLMM = 0 < l && l < 13;
  if(isFMM && isLMM) {
    cout << "AMBIGUOUS";
  } else if(isFMM) {
    cout << "MMYY";
  } else if(isLMM) {
    cout << "YYMM";
  } else {
    cout << "NA";
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int INF = 1001001001;
const ll mod = 1e+9 + 7;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    vector<vector<ll>> c(10, vector<ll>(10, 0));
    for(int i = 1; i <= n; ++i){
        int y = i % 10;
        if(y == 0)  continue;
        string s = to_string(i);
        int x = s[0] - '0';
        ++c[x][y];
    }
    ll res = 0;
    for(int i = 1; i < 10; ++i){
        for(int j = 1; j < 10; ++j){
            res += c[i][j] * c[j][i];
        }
    }
    cout << res << endl;
}

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


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,m;
  cin >> n >> m;
  if(n%2==0){
    int s =1;
    int s2 = n/2-1;
    rep(i,m){
      if(i%2==0){
        cout << s  << " "<< n-s+1 << endl;
        s++;
      }
      else{
        cout << s2 << " " << n-s2 << endl;
        s2--;
      }
    }
  }
  else{
    rep1(i,m){
      cout <<i << " "<< n-i << endl;
    }
  }

  return 0;
    

}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> bool chmax(T& a, const T& b){ if(a < b){ a = b; return 1; } return 0; }

int main(){
    ll n, t;
    cin >> n >> t;
    vector<vector<ll>> dp(t, vector<ll>(2));
    for(ll i = 0; i < n; i++){
        ll a, b;
        cin >> a >> b;
        for(ll i = t; i --> a; ) chmax(dp[i][1], dp[i - a][1] + b);
        for(ll i = 0; i < t; i++) chmax(dp[i][1], dp[i][0] + b);
        for(ll i = t; i --> a; ) chmax(dp[i][0], dp[i - a][0] + b);
    }
    cout << max(dp[t - 1][0], dp[t - 1][1]) << endl;
}


Measured memory_bytes: 384
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

int dp[30010][5][10];
int main() {
    int N; cin >> N;
    string s; cin >> s;

    int cnt1[10] = {}, cnt2[10] = {};
    for(int i=1; i<N; i++) cnt2[ s[i] - '0' ]++;

    int exist[1010] = {};
    for(int i=0; i<N; i++) {
        int v = s[i] - '0';
        for(int a=0; a<10; a++) {
            for(int b=0; b<10; b++) {
                if(cnt1[a] > 0 and cnt2[b] > 0) {
                    int num = a * 100 + v * 10 + b;
                    exist[num] = 1;
                }
            }
        }
        cnt1[ s[i] - '0' ]++;
        if(i+1 < N) cnt2[ s[i+1] - '0' ]--;
    }
    cout << accumulate(exist, exist + 1010, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
sl = {}

for i in range(n):
    s = input()
    if not(s in sl):
        sl[s] = 0
    else:
        sl[s] += 1

ans = []
s_max = max(sl.values())
for key in sl:
    if sl[key] == s_max:
        ans.append(key)

ans.sort()
for a in ans:
    print(a)


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N;	cin>>N;
	string s;	cin>>s;
  	//cout<<s.substr(0,N/2)<<"/"<<s.substr(N/2,N/2)<<endl;
	
  	if(N%2){
		No();
	}else{
		if(s.substr(0,N/2)==s.substr(N/2,N/2))	Yes();
		else No();
	}
	
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <math.h>
using namespace std;

#define ll long long

ll xorAll(ll num){
    switch(num % 4 + 1){
        case 1:
        return num;
        case 2:
        return 1;
        case 3:
        return num + 1;
        case 4:
        return 0;
    }
}

int main(){
    ll A,B,ans = 0;
    cin >> A >> B;
    if(A){
        ans |= xorAll(B) ^ xorAll(A - 1);
    }else{
        ans |= xorAll(B);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
	ll n,a=2,b=1;
	cin >> n;
	for (int i = 0; i < n-1; i++) {
		ll c = a + b;
		a = b;
		b = c;
	}
	cout << b << endl;
	return 0;
}

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

struct edge{
  int from, to, cost;
};

bool operator<(const edge &a, const edge &b){
  return a.cost < b.cost;
}

int par[10000];
int _rank[10000];

void init(int n){
  for(int i = 0; i < n; i++){
    par[i] = i;
    _rank[i] = 0;
  }
}

int find(int x){
  if(par[x] == x) return x;
  return par[x] = find(par[x]);
}

void unite(int x, int y){
  x = find(x);
  y = find(y);
  if(x == y) return;
  if(_rank[x] < _rank[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(_rank[x] == _rank[y]) _rank[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

int main(){

  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m;
  while(cin >> n >> m, n | m){
    vector<edge> g(m);
    for(int i = 0; i < m; i++){
      cin >> g[i].from >> g[i].to >> g[i].cost;
      g[i].from--;
      g[i].to--;
    }
    sort(g.begin(), g.end());
    int ans = -1;
    for(int i = 0; i < m; i++){
      init(n);
      int min_c = g[i].cost;
      int tmp = 0;
      unite(g[i].from, g[i].to);
      for(int idx = i+1; idx < m; idx++){
        if(!same(g[idx].from, g[idx].to)){
          unite(g[idx].from, g[idx].to);
          tmp = g[idx].cost - min_c;
        }
      }
      bool flag = true;
      for(int i = 1; i < n; i++){
        if(!same(0, i)) flag = false;
      }
      if(flag){
        if(ans == -1) ans = tmp;
        else ans = min(ans, tmp);
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3140
#include <stdio.h>

int main(void)
{ 
	int a[3];
	int i,j,m;
	for(i=0;i<3;i++) scanf("%d",&a[i]);
	for(i=0;i<3;i++){
		for(j=i+1;j<3;j++){
			if(a[i]>a[j]){
				m=a[i];
				a[i]=a[j];
				a[j]=m;
			}
		}
	}
	printf("%d %d %d\n",a[0],a[1],a[2]);
	return 0;
}


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

int check (const string &s)
{
	if (s.size () % 2) return 0;
	int m = s.size () / 2;
	for (int i = 0; i < m; i++) {
		if (s[i] != s[m + i]) return 0;
	}
	return 1;
}
int main ()
{
	int ans = 0;
	string s;
	cin >> s;
	for (int i = 0; i < s.size () - 1; i++) {
		if (check (s.substr (0, i + 1))) {
			ans = i + 1;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

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

	if (N % 2 == 1) {
		printf("0\n");
	} else {
		long long M = N / 2;

		long long div = 5;
		long long cnt = 0;
		while (M / div > 0) {
			cnt += M / div;
			div *= 5;
		}

		printf("%lld\n", cnt);
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll m = 1e9 + 7;

ll powmod(ll b, ll p, ll m) {
  if (p == 0)
    return 1;
  if (p % 2 == 1)
    return b * powmod(b, p - 1, m) % m;
  else {
    ll t = powmod(b, p / 2, m);
    return t * t % m;
  }
}

ll inv(ll x) { return powmod(x, m - 2, m); }

ll fact[200005], factinv[200005];
ll ncrmod(int n, int r) {
  return fact[n] * factinv[r] % m * factinv[n - r] % m;
}

int main() {
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  ll ans = 0;
  fact[0] = 1;
  for (int i = 1; i < 200005; i++) {
    fact[i] = fact[i - 1] * i % m;
  }
  for (int i = 0; i < 200005; i++) {
    factinv[i] = inv(fact[i]);
  }
  // cout << ncrmod(3, 2);
  // cout << fact[3] << " " << factinv[3] << " " << fact[3] * factinv[3] % m;
  for (int i = 1; i <= h - a; i++) {
    ans += ncrmod(b + i - 2, i - 1) * ncrmod(w - b - 1 + h - i, h - i) % m;
  }
  cout << ans % m;
}

Measured memory_bytes: 3328
import sys


def input(): return sys.stdin.readline().strip()


def resolve():
    H, W = map(int, input().split())
    l = [list(input()) for i in range(H)]
    cl = [[0] * (W + 2) for i in range(H + 2)]
    for h in range(H):
        for w in range(W):
            if l[h][w] == '#':
                cl[h + 1][w + 1] = '#'
                if cl[h][w] != '#':
                    cl[h][w] += 1
                if cl[h][w + 1] != '#':
                    cl[h][w + 1] += 1
                if cl[h][w + 2] != '#':
                    cl[h][w + 2] += 1

                if cl[h + 1][w + 2] != '#':
                    cl[h + 1][w + 2] += 1
                if cl[h + 1][w] != '#':
                    cl[h + 1][w] += 1

                if cl[h + 2][w] != '#':
                    cl[h + 2][w] += 1
                if cl[h + 2][w] != '#':
                    cl[h + 2][w + 1] += 1
                if cl[h + 2][w + 2] != '#':
                    cl[h + 2][w + 2] += 1
    for h in range(1, H + 1):
        ans=''
        for x in cl[h][1:-1]:
            ans+=str(x)
        print(ans)

resolve()

Measured memory_bytes: 40432
//secreterror
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0;i<n;i++)
#define rev(i, n) for(ll i=n-1;i>=0;i--)
#define forr(i, x, y) for(ll i=x;i<y;i++)
#define f first
#define s second
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vpii vector<pair<int,int>>

int main()
{
    ll n,w;
    cin>>n>>w;

    vector<ll>weigh(n);
    vector<ll>val(n);
    rep(i,n) {
        cin>>weigh[i]>>val[i];
    }

    ll sum=0;
    rep(i,n) {
        sum+=val[i];
    }

    vector<ll>dp(sum+1,10000000000); //mini w for any val

    dp[0]=0;

    for(ll i=0;i<n;i++){
        for(ll alr=sum-val[i];alr>=0;alr--){
            dp[alr+val[i]]=min(dp[alr+val[i]],dp[alr]+weigh[i]);
        }
    }
    ll ans=0;
    for(ll i=0;i<=sum;i++){
        if(dp[i]<=w){
            ans=max(ans,(ll)i);
        }
    }
    cout<<ans<<endl;




}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N;
int val[10101010], f[10101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 1, N + 1) val[i] = i, f[i] = 1;
	rep(p, 2, N + 1) for (int x = p; x <= N; x += p) {
		int c = 0;
		while (val[x] % p == 0) val[x] /= p, c++;
		f[x] *= c + 1;
	}

	ll ans = 0;
	rep(i, 1, N + 1) ans += 1LL * i * f[i];
	cout << ans << endl;
}







Measured memory_bytes: 81776
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

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


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

int n, t, mi, dis = -1, cnt = 0;
vector<int> a;
map<int, int> mp;

int main() {
  cin >> n >> t;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  mi = a[0];
  for(int i = 0; i < n; ++i) {
    int now = a[i];
    if(now > mi) dis = max(dis, now - mi);
    mi = min(mi, now);
  }
  for(int i = 0; i < n; ++i) {
    int now = a[i];
    if(mp.find(now - dis) != mp.end()) ++cnt;
    ++mp[now];
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 5368
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=300000;

int main()
{
    FasterIO;

    int n, m, k;
    cin>>n;
    map<int ,int>mp;
    for(int i=0; i<n; i++)
    {
        cin>>m;
        if(mp[m])
        {
            cout<<"NO"<<endl; return 0;
        }
        mp[m]++;
    }
    cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
static const int INF (1<<30);

int main() {
  string S; cin >> S;

  int ans = 0;
  int cnt_0 = 0, cnt_1 = 0;
  rep(i, S.length()) {
    int x = S[i] - '0';
    if (x == 0 && cnt_1 > 0) {
      ans += 2;
      cnt_1--;
    } else if (x == 0) {
      cnt_0++;
    } else if (x == 1 && cnt_0 > 0) {
      ans += 2;
      cnt_0--;
    } else {
      cnt_1++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include<time.h>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
#include<unordered_map>
#include <cassert>
#include <bit>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
using Edge=pair<int,ll>;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++17
bool heiho(int x){
    if(x==1)return true;
    rep(i,x){
        if(i*i==x)return true;
    }
    return false;
}
int main(){
    int n,d;cin>>n>>d;
    vector<vector<ll>>x(n);
    rep(i,n){
        rep(j,d){
            int tmp;cin>>tmp;
            x[i].push_back(tmp);
        }
    }
    int ans=0;
    rep(i1,n)for(int i2=i1+1;i2<n;i2++){
        int sum=0;
        rep(j,d){
        sum+=(x[i1][j]-x[i2][j])*(x[i1][j]-x[i2][j]);
    }
    if(heiho(sum))ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x;
    int w,sum=1;
    cin>>w>>x;
    if(w<=10)
    {
        sum=(10-w)*100;
        sum=sum+x;
        cout<<sum<<endl;

    }
    else
        cout<<x;










}


Measured memory_bytes: 256
const input=require('fs').readFileSync('/dev/stdin', 'utf8').split(/[\s]/);const nin=()=>{const r = input[0];input.shift();return Number(r)};const nrin=(n)=>{const a:number[]=[];rep(n,()=>a.push(nin()));return a};const sin=()=>{const r = input[0];input.shift();return String(r)};const out=(...a)=>{console.log(...a)};const floor=(a)=>{return Math.floor(a)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const rep=(n, callback)=>{for(let i = 0;i < n; i++){callback()}};const strrep=(s, i, v)=>{return s.slice(0, i)+v+s.slice(i+1);};const permutation=({result=[],pre=[],post,n=post.length})=>{if(n>0){post.forEach((_,i)=>{const rest=[...post];const elem=rest.splice(i, 1);permutation({result, pre: [...pre,...elem],post:rest,n:n-1})})}else{result.push(pre)}return result};const sw=(s,a:any[])=>{for(let i=0;i<a.length;i+=2)if(s==a[i])return a[i+1]};const or=(a,...b)=>{for(let i=0;i<b.length;i++)if(a==b[i])return true;return false};const maxindex=(...a)=>{return a.indexOf(Math.max.apply(null,a))};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};
const main = ()=>{
  let [a,b]=nrin(2);
  out((a-1)*(b-1));
}
main();

Measured memory_bytes: 7500
#include <cstdio>
#define max_n 200000
using namespace std;
int a[max_n+1];
int main(){
	long long ans=0;
	int n;
	scanf("%d",&n);
	for(int i=0; ++i<=n; scanf("%d",a+i));
	for(int l=0,r=1,x=0; ++l<=n; x^=a[l],ans+=r-l)
		for(; r<=n&&!(x&a[r]); ++r){
			if(r==n){
				printf("%lld\n",ans+(long long)(n-l+1)*(n-l+2)/2);
				return 0;
			}
			x|=a[r];
		}
}

Measured memory_bytes: 2492
s = input()
n = len(s)

ans = 0
for b in reversed(range(2**(n-1))):
    sb = s
    for i in reversed(range(n-1)):
        if (b>>i)&1 == 1:
            sb = sb[:i+1] + "+" + sb[i+1:]
#     print(sb)
    ans += eval(sb)
    
print(ans)

Measured memory_bytes: 3060
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
n,a,b=map(int,stdin.readline().split())
ans=0
ans+=a*(n//(a+b))
n=n%(a+b)
if(n<=a):
    ans+=n 
else:
    ans+=a
print(ans)

Measured memory_bytes: 65332
#include<bits/stdc++.h>
using namespace std;
typedef       long long int      ll;
#define       optimize           ios::sync_with_stdio(0);cin.tie(0);
#define       RESET(a, b)        memset(a, b, sizeof(a))
#define       MX                 200005
priority_queue<ll> pq;
vector<ll> v[MX];
ll vis[MX];
void bfs(ll s)
{
   queue<ll> q;
   vis[s]=1;
   q.push(s);
   ll cnt=0;
   while(!q.empty())
   {
      ll x=q.front();
      q.pop();
      cnt++;
      for(ll i=0;i<v[x].size();i++)
      {
         if(vis[v[x][i]]==0)
         {
            vis[v[x][i]]=1;
            q.push(v[x][i]);
         }
      }
   }
   pq.push(cnt);
}
int main(void)
{
   optimize
   ll n,m,a,b;
   cin>>n>>m;
   for(ll i=0;i<m;i++)
   {
      cin>>a>>b;
      v[a].push_back(b);
      v[b].push_back(a);
   }
   RESET(vis,0);
   for(ll i=1;i<=n;i++)
   {
      if(vis[i]==0)
         bfs(i);
   }
   cout<<pq.top()<<endl;
   return 0;
}


Measured memory_bytes: 18672
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int r,d,x,ans[20];
	cin>>r>>d>>x;
	ans[0]=x;
	for(int i=1;i<=10;i++)
	{
		ans[i]=r*ans[i-1]-d;
	}
	for(int i=1;i<=10;i++)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
 } 

Measured memory_bytes: 256
#include <stdio.h>

typedef struct SCell cell;
typedef struct SCoord coord;
typedef struct SState state;

struct SCell{
	int num;
	int star;
};

struct SCoord{
	int i, j;
};

struct SState{
	int num;
	coord c[ 9 ];
};


void reset( state s[ 10 ] ){
	int i;
	for( i = 0; i < 10; i++ ){
		s[ i ].num = 0;
	}
}

int main( void ){
	cell board[ 9 ][ 9 ];
	state s[ 10 ];
	int d, n;
	int i, j, wi, wj, li, lj;
	int l, m;
	scanf( "%d", &n );
	for( d = 0; d < n; d++ ){
		//input [ツ確ツ津ィ]
		for( j = 0; j < 9; j++ ){
			for( i = 0; i < 9; i++ ){
				scanf( "%d", &board[ i ][ j ].num );
				board[ i ][ j ].star = 0;
			}
		}
		//ツ縦ツ探ツ催オ
		for( i = 0; i < 9; i++ ){
			reset( s );
			for( j = 0; j < 9; j++ ){
				s[ board[ i ][ j ].num ].c[ s[ board[ i ][ j ].num ].num ].i = i;
				s[ board[ i ][ j ].num ].c[ s[ board[ i ][ j ].num ].num ].j = j;
				s[ board[ i ][ j ].num ].num++;
			}
			for( m = 1; m <= 9; m++ ){
				if( s[ m ].num >= 2 ){
					for( l = 0; l < s[ m ].num; l++ ){
						board[ s[ m ].c[ l ].i ][ s[ m ].c[ l ].j ].star = 1;
					}
				}
			
			}
		}
		//ツ可。ツ探ツ催オ
		for( j = 0; j < 9; j++ ){
			reset( s );
			for( i = 0; i < 9; i++ ){
				s[ board[ i ][ j ].num ].c[ s[ board[ i ][ j ].num ].num ].i = i;
				s[ board[ i ][ j ].num ].c[ s[ board[ i ][ j ].num ].num ].j = j;
				s[ board[ i ][ j ].num ].num++;
			}
			for( m = 1; m <= 9; m++ ){
				if( s[ m ].num >= 2 ){
					for( l = 0; l < s[ m ].num; l++ ){
						board[ s[ m ].c[ l ].i ][ s[ m ].c[ l ].j ].star = 1;
					}
				}
			}
		}
		//ツ枠ツ探ツ催オ
		for( wj = 0; wj < 3; wj++ ){
			for( wi = 0; wi < 3; wi++ ){
				reset( s );
				for( lj = 0; lj < 3; lj++ ){
					for( li = 0; li < 3; li++ ){
						j = wj * 3 + lj;
						i = wi * 3 + li;
						s[ board[ i ][ j ].num ].c[ s[ board[ i ][ j ].num ].num ].i = i;
						s[ board[ i ][ j ].num ].c[ s[ board[ i ][ j ].num ].num ].j = j;
						s[ board[ i ][ j ].num ].num++;
					}
				}
				for( m = 1; m <= 9; m++ ){
					if( s[ m ].num >= 2 ){
						for( l = 0; l < s[ m ].num; l++ ){
							board[ s[ m ].c[ l ].i ][ s[ m ].c[ l ].j ].star = 1;
						}
					}
				}
			}
		}
		
		//output
		for( j = 0; j < 9; j++ ){
			for( i = 0; i < 9; i++ ){
				putchar( board[ i ][ j ].star ? '*' : ' ' );
				putchar( board[ i ][ j ].num + '0' );
			}
			putchar( '\n' );
		}
		if( d != n-1 ){	putchar( '\n' ); }
	}
	return 0;
}

Measured memory_bytes: 0