akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

  bool all0 = true;
  int a[N];
  map<int, int> mp;
  for(int i = 0; i < N; i++){
    cin >> a[i];
    mp[a[i]]++;
    if(a[i] != 0) all0 = false;
  }

  if(all0){
    cout << "Yes" << endl;
    return 0;
  }

  int sz = mp.size();
  if(N % 3 == 0){
    if(sz == 3){
      int num[3];
      int cnt[3];
      int i = 0;
      for(auto it = mp.begin(); it != mp.end(); it++){
        num[i] = it->first;
        cnt[i] = it->second;
        i++;
      }
      if(cnt[0] == N / 3 && cnt[1] == N / 3 && cnt[2] == N / 3){
        if((num[0] ^ num[1]) == num[2]){
          cout << "Yes" << endl;
        }
        else{
          cout << "No" << endl;
        }
      }
      else{
        cout << "No" << endl;
      }
    }
    else if(sz == 2){
      int num[2];
      int cnt[2];
      int i = 0;
      for(auto it = mp.begin(); it != mp.end(); it++){
        num[i] = it->first;
        cnt[i] = it->second;
        i++;
      }
      if((num[0] == 0 && cnt[0] == N / 3) || (num[1] == 0 && cnt[1] == N / 3)){
        cout << "Yes" << endl;
      }
      else{
        cout << "No" << endl;
      }
    }
    else{
      cout << "No" << endl;
    }
  }
  else{
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
#define ppp pair<ll,pp >
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define sz(v) (ll)(v.size())
#define hell (ll)998244353
#define slld(x) scanf("%lld",&x)
ll t=1, tt;
const ll N=100005, inf=1e18;
void solve(){
	ll n, ans=0;
	map<ll,ll> mapa;
	cin>>n;
	vector<ll> v(n+1);
	rep(i,1,n+1)
		cin>>v[i];
	for(ll i=n;i>=1;i--){
		ans+=mapa[i+v[i]];
		mapa[i-v[i]]++;
	}
	cout<<ans;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   	//cin>>t;
   	tt=t;
    while(t--){
        solve();
        if(t)cout<<"\n";
    }
    return 0 ;
}


Measured memory_bytes: 27340
#include <stdlib.h> 
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>

using namespace std; 

int main()
{
	int n,a,b;
	string s;
	
	cin>>n>>a>>b;
	cin>>s;
	
	int ab = a + b;
	int i = 0;
	
	while( i < s.size())
	{
		if( s[i] == 'a')
		{
			if( ab != 0) 
			{
				cout<<"Yes"<<endl;
				ab--;
			}
			else cout<<"No"<<endl;
		}
		
		else if( s[i] == 'b')
		{
			if(ab != 0 && b != 0) 
			{
				cout<<"Yes"<<endl;
				ab--;
				b--;
			}
			else cout<<"No"<<endl;
		}
		
		else if( s[i] == 'c') cout<<"No"<<endl;
		
		i++;
	}
	return 0;
}


Measured memory_bytes: 3720
#include <stdio.h>

//バイナリヒープ
#define N 10000000
int heap[N];
int last;
unsigned seed=0x12121204;
void push(int n){
    int i=last,j=(i-1)>>1;
    while(i>0&&heap[j]>n){
        heap[i]=heap[j];
        i=j;
        j=(i-1)>>1;
    }
    heap[i]=n;
    last++;
}
int pop(){
    last--;
    int a=heap[0];
    int t=heap[last],i=0,j;
    j=1+(heap[1]>heap[2]);
    while(j<last&&t>heap[j]){
        heap[i]=heap[j];
        i=j;
        if(j*2+1<last&&heap[j*2+1]>heap[j*2+2]){
            j=j*2+2;
        }else{
            j=j*2+1;
        }
    }
    heap[i]=t;
    return a;
}
int main(void){
    int n,p[100],a[100];
    int i,h,sorted;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&p[i]);
        a[i]=p[i];
    }
    for(i=0;i<n;i++){
        push(p[i]);
    }
    for(i=0;i<n;i++){
        p[i]=pop(p[i]);
    }
    int cnt=0;
    for(i=0;i<n;i++){
        if(a[i]!=p[i]) cnt++;
        //printf("%d %d\n",a[i],p[i]);
    }
    //printf("%d\n",cnt);
    if(cnt<=2){
        
        puts("YES");
    }else{
        puts("NO");
    }
    return 0;
}


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

using namespace std;

typedef vector<int> row;
typedef vector<row> matrix;

matrix multi(const matrix& a, const matrix& b, const int mod)
{
  matrix c(a.size(), row(b[0].size(), 0));
  for(int i = 0; i < a.size(); i++) {
    for(int j = 0; j < b.size(); j++) {
      for(int k = 0; k < b[0].size(); k++) {
	c[i][k] = (c[i][k] + a[i][j]*b[j][k]) % mod;
      }
    }
  }
  return c;
}

matrix pow(matrix a, int n, const int mod)
{
  matrix b(a.size(), row(a.size(), 0));
  for(int i = 0; i < a.size(); i++) b[i][i] = 1;
  while(n > 0) {
    if(n & 1) b = multi(b, a, mod);
    a = multi(a, a, mod);
    n >>= 1;
  }
  return b;
}

int main()
{
  int N, M, A, B, C, T;
  while(cin >> N >> M >> A >> B >> C >> T, N) {
    matrix a(N, row(N, 0)), b(N, row(1, 0));
    for(int i = 0; i < N; i++) {
      if(i > 0) a[i][i-1] = A;
      a[i][i] = B;
      if(i+1 < N) a[i][i+1] = C;
    }
    for(int i = 0; i < N; i++) cin >> b[i][0];
    a = multi(pow(a, T, M), b, M);
    for(int i = 0; i < N; i++) cout << a[i][0] << (i == N-1 ? '\n' : ' ');
  }
  return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define forn(i,n) for(int i=1;i<n+1;i++)
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)



void solve() {
	string s;
	cin >> s;

	int sum = 0;

	for (int i = 0; i < s.size(); i++) {
		sum += s[i] - '0';
	}

	if (sum % 9 == 0)cout << "Yes" << endl;
	else
		cout << "No" << endl;

}




int32_t main() {

	fastio;

#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif

	// int t; cin >> t;
	int t = 1;

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

	return 0;
}



Measured memory_bytes: 3740
from sys import stdin

N, K = [int(x) for x in stdin.readline().rstrip().split()]
h = [0]*N
for i in range(N):
    h[i] = int(input())
h.sort()
# print(h)
ans = 10**9
for i in range(N-(K-1)):
    if h[i+(K-1)]-h[i] < ans:
        ans = h[i+(K-1)]-h[i]
print(ans)


Measured memory_bytes: 7396
//Compiler optimization
#pragma GCC optimize("Ofast")

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

//typedef
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<vl> mat;

//macro
#define reverse(a) reverse(a.begin(),a.end())
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define each(x, v) for (auto &x : v)

//abbreviation
#define pb push_back
#define elif else if
#define mp make_pair
#define endl '\n'

//debug
#define debug(x) cerr << #x << ": " << x << endl
#define v_debug(v) cerr << #v << endl;fr(i,v.size()) cerr << i << ": " << v[i] << endl

//const
const  ll INF = 1e18;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(20);
    ll n;cin >> n;
    map<S, ll> dict;
    fr(i,n){
        S s;cin >> s;
        ++dict[s];
    }
    vs st = {"AC", "WA", "TLE", "RE"};
    each(s, st)cout << s <<" x " << dict[s] << endl;

}

Measured memory_bytes: 3540
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
#define ld long double
int main(){
    string s;
    cin>>s;
    cout<<s.substr(0,3)<<endl;
}

Measured memory_bytes: 3628
h,a,*m=open(0)
h,w,k,a,b,f,g=map(int,(h+a).split())
d=[I:=h*w]*I
m+=d,
a=~w+a*w+b
d[a]=1
q=[a]
for s in q:
 for y,x in(1,0),(-1,0),(0,1),(0,-1):
  for z in range(k):
   i,j=s//w+y*~z,s%w+x*~z;t=i*w+j;p=d[s]+1
   if'.'!=m[i][j]or d[t]<p:break
   if d[t]>p:q+=t,;d[t]=p
print(d[~w+f*w+g]%I-1)

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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	int n;
	cin >> n;

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

	vector<ll> b(n);
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}

	ll aSum = accumulate(a.begin(), a.end(), 0LL);
	ll bSum = accumulate(b.begin(), b.end(), 0LL);

	ll cnt = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] > b[i]) {
			cnt += a[i] - b[i];
		} else if (a[i] % 2 != b[i] % 2) {
			cnt++;
		}
	}

	cout << (cnt <= bSum - aSum ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>


int main(){
    int n, count;
    int a[210];

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

    while(true){
        bool oddEx = false;
        for(int i = 0; i < n; i++ ) {
            if(a[i]%2 != 0) oddEx = true;
        }
        if(oddEx) break;

        for(int i = 0; i < n; i++ ) a[i] /= 2;
        count++;
    }
    std::cout << count << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int A,B,C;
    cin>>A>>B>>C;
    if(A+B+C>=22){
        cout<<"bust";
    }else{
        cout<<"win";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

#define ll long long
#define pb push_back

double calc(double T, double h){
    return T - h * 0.006;
}
int main(){

    int N, T, A;
    vector<int> H;
    cin >> N >> T >> A;
    for(int i = 0; i < N; i ++){
        int h;
        cin >> h;
        H.pb(h);
    }
    int ans = 0;
    double tmp = abs(A - calc(T, H[0]));
    for(int i = 1; i < N; i ++){
        if(tmp > abs(A - calc(T, H[i]))){
            ans = i;
            tmp = abs(A - calc(T, H[i]));
        }
    }
    cout << ans + 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
typedef unsigned long ulong;

int main()
{
	int x, a;
	cin >> x >> a;
	if (x < a) {
		cout << 0;
	}
	else {
		cout << 10;
	}
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;
typedef stringstream SS;

#ifdef DEBUG
#define debug cout
#else
SS ss;
#define debug ss
#endif

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n)-1;i>=(m);--i)
#define repc(i,n) for(int i=0;i<=(n);++i)
#define repcn(i,m,n) for(int i=(m);i<=(n);++i)
#define repcd(i,n) for(int i=(n);i>=0;--i)
#define repcnd(i,m,n) for(int i=(n);i>=(m);--i)
#define repc0(i,n) for(i=0;i<=(n);++i)
#define repcn0(i,m,n) for(i=(m);i<=(n);++i)
#define repcd0(i,n) for(i=(n);i>=0;--i)
#define repcnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define X second
#define Y first
#define p_queue(n) priority_queue<n,vector<n>,greater<n> >
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

vector<int> st;

int main() {
	string str;
	cin>>str;
	if(str[0]!='m'){
		cout<<"Rabbit"<<endl;
		return 0;
	}
	rep(i,sz(str)){
		if(str[i]=='m'){
			st.PB(0);
		}else if(str[i]=='e'){
			if(st[sz(st)-1]!=0){
				cout<<"Rabbit"<<endl;
				return 0;
			}
			++st[sz(st)-1];
		}else{
			if(st[sz(st)-1]!=1){
				cout<<"Rabbit"<<endl;
				return 0;
			}
			st.pop_back();
			if(sz(st)==0&&i<sz(str)-1){
				cout<<"Rabbit"<<endl;
				return 0;
			}
		}
	}
	if(sz(st)==0)cout<<"Cat"<<endl;
	else cout<<"Rabbit"<<endl;
	return 0;
}

Measured memory_bytes: 0
h, w = map(int, input().split())
a = []

for i in range(h):
    a.append(input())

ans = []
topdown = ""

for i in range(w+2):
    topdown = topdown + "#"

for i in range(h):
    a[i] = "#" + a[i] + "#"

ans.append(topdown)
for i in range(h):
    ans.append(a[i])
ans.append(topdown)

for i in range(h+2):
    print(ans[i])


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

int main() {
    int n;
    cin>>n;
    vector<int> v1(100000,0),v2(100000,0);
    for (int i=0;i<n/2;i++) {
        int n1,n2;
        cin>>n1>>n2;
        v1[n1-1]++;
        v2[n2-1]++;
    }
    int ans11=0,ans12=0,ans21=0,ans22=0;
    int num1,num2;
    for (int i=0;i<100000;i++) {
        if (v1[i]>ans11) {
            ans12=ans11;
            ans11=v1[i];
            num1=i;
        }
        else if (v1[i]>ans12) {
            ans12=v1[i];
        }
        if (v2[i]>ans21) {
            ans22=ans21;
            ans21=v2[i];
            num2=i;
        }
        else if (v2[i]>ans22) {
            ans22=v2[i];
        }
    }
    if (num1!=num2) {
        cout<<n-ans11-ans21;
    }
    else {
        cout<<min(n-ans11-ans22,n-ans12-ans21);
    }
}

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

using namespace std;

using ll = long long;

int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i = 0; i < n; ++i){
        ll tmp, tmp1; cin >> tmp >> tmp1;
        ans += max(tmp, tmp1) - min(tmp, tmp1) + 1;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main()
{
	int N, i, nwrong=0;
	scanf("%d", &N);
	int p[N];
	for (i = 0; i < N; i++) {
		scanf("%d", &p[i]);
		if (p[i] != i+1) nwrong++;
	}
	if (nwrong > 2) puts("NO");
	else puts("YES");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;
int main(){
  string s;
  cin>>s;
  int n=s.size();
  vector<ll> val(2019,0);
  ll fac=1;
  ll cur=0;
  val[cur]++;
  for(int i=0;i<n;++i){
     long long add=s[n-1-i]-'0';
     cur=(cur+fac*add)%2019;
     fac=(fac*10)%2019;
     val[cur]++;
  }
  ll ans=0;
  for(int i=0;i<val.size();++i){
     ans+=val[i]*(val[i]-1)/2;
     }
     cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  string S,T,U;
  cin>>S>>T>>A>>B>>U;
  if(U==S){
    A--;
    cout<<A<<" "<<B<<endl;
  }
  else if(U==T){
    B--;
    cout<<A<<" "<<B<<endl;
  }
  return 0;
}


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

int main(){
    
    int N,i;
    scanf("%d",&N);
    
    char S[N];
    for(i=0;i<N;i++){
        scanf("%s",&S[i]);
    }
    
    int flag = 0;
    for(i=0;i<N;i++){
        if(S[i]=='Y'){
            printf("Four");
            flag = 1;
            break;
        }
    }
    if(flag==0){
        printf("Three");
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
      
struct P{
  int x,y;
  bool operator < (const P &a )const{
    //if(y!=a.y)
    return y<a.y;
  };
};

int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
long long o[4][4][80];
int l[100101];
int j[100101],j2[100101];

long long x,y,z,mod=1000000007;
//string r;
char r[2][66];

P u[1];
queue<int> q;
stack<int> s;
map<int,int> p[100101];
vector<int> v[100101],v1[100101];

bool as(P a,P b)
{
  return a.x<b.x;
}

long long f(int n,int m,int c)
{
  if(c>a) return 1;
  if(o[n][m][c]>=0) return o[n][m][c];
  long long x=0;
  for(int i=1;i<=3;i++)
  for(int j=1;j<=3;j++)
  {
    if((r[0][c]==r[1][c]&&i!=j)||(r[0][c]!=r[1][c]&&i==j)) continue;
    if((r[0][c-1]==r[0][c]&&i!=n)||(r[0][c-1]!=r[0][c]&&i==n)) continue;
    if((r[1][c-1]==r[1][c]&&j!=m)||(r[1][c-1]!=r[1][c]&&j==m)) continue;
    x+=f(i,j,c+1);
    x%=mod;
  }
  return o[n][m][c]=x;
}

int main()
{
  scanf("%d %s %s",&a,r[0]+1,r[1]+1);
  memset(o,-1,sizeof(o));
  printf("%lld",f(0,0,1));
}


Measured memory_bytes: 10496
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll d;
    cin >> d;
    vector<vector<ll>> s(d, vector<ll>(26));
    vector<ll> c(26);

    rep(i, 26) cin >> c[i];
    rep(i, d){
        rep(j, 26){
            cin >> s[i][j];
        }
    }

    vector<ll> t(d);
    rep(i, d){
        cin >> t[i];
        t[i]--;
    }
    ll score = 0;
    vector<ll> last(26, -1);
    rep(i, d){
        score += s[i][t[i]];
        last[t[i]] = i;
        rep(j, 26){
            score -= (i - last[j]) * c[j];
        }
        cout << score << endl;
    }

}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e6+10;
struct w
{
    int cost, v;
} w[100];
int dp[30005], sum[30005];

int main()
{
    int n;
    scanf("%d",&n);
    string s;
    cin >> s;
    if(n%2==1)
    {
        printf("No\n");
    }
    else
    {
        int i=0,j=n/2;
        while(i<n/2)
        {
            if(s[i]==s[j])
            {
                i++;
                j++;
            }
            else
                break;
        }
        if(i==n/2)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;

typedef pair<ll, ll> P;

const int MOD = 1000000007;
const ll INF = 1LL << 60;


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

vector<vector<int> > vvi;
vector<vector<vector<int> > > vvvi;

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 GCD(int a, int b) { return b ? GCD(b, a%b) : a; }

int main(int argc, char**argv){
    int n;
    string s;
    cin >> n >> s;
    int counter = 0;
    int max_val = 0;
    for (auto ch : s){
        if (ch == 'I') counter++;
        else counter--;
        chmax(max_val, counter);
    }

    cout << max_val << endl;

    return 0;
}





















Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<iterator>
#include<iostream>
#include<cctype>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<list>
#include<stack>
#include<functional>
#include<utility>
#include<numeric>
#include<bitset>
#include<iterator>
#define INF (int)1e9
#define MOD 1000000007
#define tr(c, it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz size
#define ll long long
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MEM(a, b) memset(a, (b), sizeof(a))
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define PRE(i, m, n, in) for(int (i)=(m);(i)<(n);i+=in)
#define RFOR(i, n) for(int i=n ; i>=0 ; i--)
#define RPRE(i, j, k, in) for(int i=j ; i>=k ; i-=in)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
using namespace std;
typedef pair<int, int> II;
typedef vector <int> VI;
typedef vector<string> VS;
typedef vector <II> VII;
typedef vector <VI> VVI;
typedef vector <VII> VVII;
typedef map<int,int> MPII;
typedef set<int> SETI;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    int a, b, c, x , y; cin >> a >> b >> c >> x >> y;
    // x a pizzas, y b-pizzas
    //a, b, ab - a, b, c
    ll price = 0;
    if(2*c < a + b) {
        price += min(x, y)*2*c; int t = min(x, y); x -= t; y -= t;
        //cout << x << " " << y << endl;
        //cout << price << endl;
        if(x == max(x, y)) {
            if(2*c < a) {
                //cout << price << endl;
                price += 2*c*x; x-= x;
            }
            else {
                //cout << price << endl;
                price += a*x; x-= x;
            }
        }
        if(y == max(x, y)) {
            if(2*c < b) {
                price += 2*c*y; y-= y;
            }
            else {
                price += b*y; y-= y;
            }
        }
    }
    else {
        price  = x*a + y*b;
    }
    cout << price << endl;
    return 0;
}


Measured memory_bytes: 256
n=gets.chomp.to_i
ary=Array.new
ary=gets.chomp.split(" ").map{|num| num.to_i}
k=0


for i in 0..n-1
	minj=i
	for j in i..n-1
		if ary[j] < ary[minj]
			minj=j
		end
	end
		if ary[i] > ary[minj]
			x=ary[i]
			ary[i]=ary[minj]
			ary[minj]=x
			k+=1
		end
end
puts ary.join(" ")
puts k

Measured memory_bytes: 8600
#! /usr/bin/env python
# coding: utf-8


def slove(a, b, c, x):
    ans = 0
    for i in range(a+1):
        for j in range(b+1):
            for k in range(c+1):
                tmp = x - 500*i - 100*j
                if tmp == 0:
                    ans += 1
                    break
                if tmp > 0 and tmp <= 50*k:
                    ans += 1
                    break

    return ans


if __name__ == "__main__":
    a = int(input())
    b = int(input())
    c = int(input())
    x = int(input())

    print(slove(a, b, c, x))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()

void solve(){
  ll d,t,s;
  cin >>d >> t >> s;

  cout << (s*t>=d?"Yes":"No") << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}

Measured memory_bytes: 3648
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() { return new List<int>(ReadLine().Split().Select(int.Parse)); }
        static bool[,] graph = new bool[8, 8];
        static void Main(string[] args)
        {
            var a = Sarray()[0];
            WriteLine(a+a*a+a*a*a);
        }
    }
}

Measured memory_bytes: 19052
use std::cmp::{max, min};
use std::collections::BTreeSet;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let s = sc.chars();
    let mut r = BTreeSet::new();
    let mut g = BTreeSet::new();
    let mut b = BTreeSet::new();
    for i in 0..n {
        match s[i] {
            'R' => {
                r.insert(i as i64);
            }
            'G' => {
                g.insert(i as i64);
            }
            'B' => {
                b.insert(i as i64);
            }
            _ => unreachable!(),
        }
    }

    let mut ans: usize = 0;
    for &r in r.iter() {
        for &g in g.iter() {
            let i = min(r, g);
            let j = max(r, g);
            let k1 = 2 * j - i;
            let k2 = 2 * i - j;
            ans += b.len();
            if b.contains(&k1) {
                ans -= 1;
            }
            if b.contains(&k2) {
                ans -= 1;
            }
            if (i + j) % 2 == 0 && b.contains(&((i + j) / 2)) {
                ans -= 1;
            }
        }
    }
    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 2264
#include<map>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<fstream>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
ll x;
int f(ll y,ll r){
	ll ans=y;
	if(r==0)return 1;
	if(r==1)return y;
	for(ll i=2;i<=r;i++){
		ans*=y;
	}
	return ans;
}
int xz(ll k){
	ll b,q,maxn=-0x7f;
	for(b=1;b<=sqrt(x);b++){
		for(q=2;q<=x;q++){
			ll sum=f(b,q);
			if(sum>x)break;
			maxn=max(maxn,sum);
			if(maxn==x)return maxn;
		}
	}
	return maxn;
}
int main(){
	scanf("%lld",&x);
	if(x==0||x==1){
		printf("%lld",x);
		return 0;
	}
	printf("%lld",xz(x));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
int N,ptr=0,res=0;
int A[100000];
int main(){
  cin>>N;
  for(int i=0;i<N;i++) cin>>A[i]; 
  sort(A,A+N);
  while(ptr<N){
    int cc=A[ptr],f=0;
    while(ptr<N&&A[ptr]==cc) f++,ptr++;
    res+=f%2;
  }
  cout<<res<<endl;
}

Measured memory_bytes: 640
import java.util.*; 
public class Main{
public static void main(String ... string){
  Scanner sc = new Scanner(System.in); 
  int n = sc.nextInt(); 
  int c500 = n/500; 
  int r500 = n%500; 
  int c5 = r500/5; 
  System.out.println(c500*1000+c5*5); 
  }
}


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

typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> l(n);
    for (int i = 0; i < n; i++)
        cin >> l[i];
    sort(l.begin(), l.end());
    ll ans = 0;
    for (int i = 0; i <= n - 3; i++)
        for (int k = i + 1; k <= n - 2; k++) {
            ll s = l[i] + l[k];
            ll ub = lower_bound(l.begin(), l.end(), s) - l.begin();
            ans += ub - k - 1;
        }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
import sys
from collections import deque
def input():
    return sys.stdin.readline().strip()

tozan = []
gezan = []

def check():
    s = input()
    m = 0
    res = 0
    for i in s:
        if i == "(":
            m += 1 
        else:
            m -= 1
            res = min(res,m)
    if m >= 0:
        tozan.append([res,m])
    else:
        gezan.append([res-m,-m])

N = int(input())
for _ in range(N):
    check()

tozan.sort(reverse=True)
gezan.sort(reverse=True)

t = 0
g = 0

for res,m in tozan:
    if t + res < 0:
        print("No")
        exit()
    t += m

for res,m in gezan:
    if g + res < 0:
        print("No")
        exit()
    g += m

if t == g:
    print("Yes")
else:
    print("No")

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	int N=in();
	vector<int> W(N);
	REP(i,N) W[i]=in();
	int min_W = 1e8;
	for(int i=0;i<N;i++){
		int S1 = accumulate(W.begin(),W.begin()+i,0);
		int S2 = accumulate(W.begin()+i,W.end(),0);
		min_W = min(min_W,abs(S1-S2));
	}
	
	cout << min_W << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = 0;
		if (a > b) {
			ans += a;
			a--;
		} else {
			ans += b;
			b--;
		}
		if (a > b) {
			ans += a;
		} else {
			ans += b;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22356
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int a,b,c,d,x,y;
	cin>>a>>b>>c>>d;
	x=a*b;
	y=c*d;
	if(x>=y){
		cout<<x<<endl;
	}
	else{
		cout<<y<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<vector<ll> >DP(101,vector<ll>(100001,INT_MIN));
vector<ll>wt,val;
ll dp(ll n,ll W)
{
	
	if(DP[n][W]==INT_MIN)
	{
		if(n==0||W==0)
	DP[n][W]=0;
	  else	if(wt[n-1]<=W)
	{DP[n][W]=max(dp(n-1,W),val[n-1]+dp(n-1,W-wt[n-1]));
	}
	else
	DP[n][W]=dp(n-1,W);
	}
	
	return DP[n][W];
}
int main()
{   ll n,W;
     cin>>n>>W;
     ll i,j,k;
     for(i=0;i<n;i++)
     {cin>>j>>k;
     wt.push_back(j);
     val.push_back(k);
	 }
	 cout<<dp(n,W);
    return 0;
}


Measured memory_bytes: 80256
import java.util.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    static Stack<Integer> stack = new Stack<Integer>();
    static int train_number;
    public static void main(String[] args) {
        solve();
    }

    static void solve(){
        train_number = sc.nextInt();
        stack.push(train_number);
        while(sc.hasNextInt()){
            train_number = sc.nextInt();
            if(train_number == 0){
                System.out.println(stack.pop());
            }else{
                stack.push(train_number);
            }
        }
    }

}

Measured memory_bytes: 25860
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 9999999
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans;
}
ll inv(ll a)
{
    return power(a,MOD-2,MOD);
}
//code begins

signed main()
{

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    ios_base::sync_with_stdio (false);
    ll t;
    t=1;
//    cin>>t;
    while(t--)
    {
        ll n;cin>>n;
        ll a[n+1];
        bool flag=false;
        for(ll i=1;i<=n;i++)
        {
            cin>>a[i];
            if(a[i]%2==0)
            {
                if(a[i]%3==0 or a[i]%5==0);
                else
                    flag=true;
            }
        }
        if(!flag)
            cout<<"APPROVED\n";
        else
            cout<<"DENIED\n";
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
int Min(int a, int b, int c) {
	if (a <= b) { return std::min(a, c); }
	else return std::min(b, c);
}
int Max(int a, int b, int c) {
	if (a >= b) { return std::max(a, c); }
	else return std::max(b, c);
}
int main(void) {
	int n; cin >> n;
	vector<int> v(n), vv(n);
	rep(i, n)cin >> v[i];
	rep(i, n)cin >> vv[i];
	int res = 0;
	rep(i, n)if (v[i] > vv[i])res += v[i] - vv[i];
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long ll;
const int MOD=1000000007;
int main(){
  int n,m;
  cin>>n>>m;
  vector<bool>broken(n+1);
  rep(i,m){
    int a;
    cin>>a;
    broken[a]=true;
  }
  vector<int>dp(n+2);
  dp[n]=1;
  for(int i=n-1;i>=0;i--){
    if(broken[i]){
      dp[i]=0;
      continue;
    }
    dp[i]=(dp[i+1]+dp[i+2])%MOD;
  }
  cout<<dp[0]<<endl;
  return 0;
}


Measured memory_bytes: 640
n = int(input())
series = [int(x) for x in input().split()]

odd_dict = {}
even_dict = {}

for i in range(n):
    k = series[i]
    if i % 2 == 0:
        try:
            even_dict[k] += 1
        except KeyError:
            even_dict[k] = 1 
    else:
        try:
            odd_dict[k] += 1
        except KeyError:
            odd_dict[k] = 1

odd_vals = []
even_vals = []

for key in odd_dict.keys():
    odd_vals.append([odd_dict[key], key])
for key in even_dict.keys():
    even_vals.append([even_dict[key], key])

odd_vals.sort(reverse=True)
even_vals.sort(reverse=True)

# print(odd_vals)
# print(even_vals)

if len(odd_vals) == 1 and len(even_vals) == 1:
    a = odd_vals[0][0]
    b = even_vals[0][0]

    if odd_vals[0][1] != even_vals[0][1]:
        print(n - a - b)
    else:
        print(n // 2)
elif len(odd_vals) > 1 and len(even_vals) > 1:
    if odd_vals[0][1] != even_vals[0][1]:
        print(n - odd_vals[0][0] - even_vals[0][0])
    else:
        a = odd_vals[0][0]
        b = odd_vals[1][0]
        c = even_vals[0][0]
        d = even_vals[1][0]
        print(min(n - a - d, n - b - c))
else:
    a = odd_vals[0][0]
    b = even_vals[0][0]
    c = 0
    if len(odd_vals) == 1:
        c = even_vals[1][0]
    else:
        c = odd_vals[1][0]
    
    if odd_vals[0][1] != even_vals[0][1]:
        print(n - a - b)
    else:
        print(n - a - c)

# print(even_dict)
# print(odd_dict)

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

int main() {

  int N, K, L;
  cin >> N;
  cin >> K;
  L = 1;
  
  for (int i = 0; i < N; i++) {
    if (L * 2 < L + K) {
      L *= 2;
    } else {
      L += K;
    }
  }
  
  cout << L << endl;
}

Measured memory_bytes: 256
import sys

def calcSum(N, BuyingList_bool, Books):
    Price = 0
    for Num in range(N):
        if(BuyingList_bool[Num]):
            Price += Books[Num][0]
    return Price

def search(N, M, X, Books, BuyingList_bool, Prices = [], BranchPos =0):
    if(BranchPos == N):

        Complehensives = [0] * M
        for m in range(M):
            for n in range(N):
                if(BuyingList_bool[n]):
                    Complehensives[m] += Books[n][m+1]
            if(Complehensives[m] < X):
                return None

        Prices.append( calcSum(N, BuyingList_bool, Books) )
        return Prices
    BuyingList_bool[BranchPos] = True
    search(N, M, X, Books, BuyingList_bool, Prices, BranchPos+1)
    BuyingList_bool[BranchPos] = False
    search(N, M, X, Books, BuyingList_bool, Prices, BranchPos+1)
    return Prices



if(__name__ == '__main__'):
    NMX = input().split()

    N= int(NMX[0].strip())
    M= int(NMX[1].strip())
    X= int(NMX[2].strip())

    Books = []
    AllSum = []
    for Num in range(M+1):
        AllSum.append(0) # [M] -> value
    for Num in range(N):
        List = []
        In = input().split()
        for Str in In:
            List.append(int(Str.strip()))
        Books.append(List)

    BuyingList_bool = [True] * N
    Prices = search(N, M, X, Books, BuyingList_bool)
    if(len(Prices) ==0):
        print(-1)
    else:
        print( min(Prices) )


Measured memory_bytes: 9344
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(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 sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1];}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const objvs =(a)=>{const b=[];for(const v in a){b.push(a[v])}return b};
const main=()=>{
  let [a,b]=tnn(2)
  let s=ts(),ans='Yes'
  for(let i=0;i<a;i++){
    if(!Number.isInteger(Number(s[i])))ans='No'
  }
  if(s[a]!='-')ans='No'
  for(let i=a+1;i<a+b+1;i++){
    if(!Number.isInteger(Number(s[i])))ans='No'
  }
  to(ans)
}
main()


Measured memory_bytes: 7372
#include<iostream>
#include<stdio.h>
#include<fstream>
#include<algorithm>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<set>
#include<string>
#include<queue>
#include<map>
#include<iomanip>
#include<cassert>
#include<complex>
#include<functional>
#include<list>
#include<cmath>
#include<stack>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};
int n,m,k,d[1024][1024],xs,ys,x,y,xx,yy;
char a[1024][1024];
queue<pair<int,int> > q;
bool valid(int i,int j)
{
	return i>=0 && i<n && j>=0 && j<m && a[i][j]!='#';
}
int asd(int i,int j)
{
	int r=i;
	r=min(r,j);
	r=min(r,n-1-i);
	r=min(r,m-1-j);
	return r;
}
int main()
{
	cin>>n>>m>>k;
	for (int i=0;i<n;i++)
		for (int j=0;j<m;j++)
		{
			cin>>a[i][j];
			if (a[i][j]=='S') xs=i,ys=j;
		}
	memset(d,-1,sizeof(d));
	d[xs][ys]=0;
	q.push(mp(xs,ys));
	while (!q.empty())
	{
		x=q.front().first; y=q.front().second;
		q.pop();
		for (int i=0;i<4;i++)
		{
			xx=x+dx[i]; yy=y+dy[i];
			if (valid(xx,yy) && d[xx][yy]<0)
			{
				d[xx][yy]=d[x][y]+1;
				q.push(mp(xx,yy));
			}
		}
	}
	int r=1<<20;
	for (int i=0;i<n;i++)
		for (int j=0;j<m;j++)
			if (d[i][j]>=0 && d[i][j]<=k)
				r=min(r,1+(asd(i,j)+k-1)/k);
	cout<<r;
    return 0;
}

Measured memory_bytes: 5248
N = int(input())

dish = []
for _ in range(N):
    A, B = map(int, input().split())
    dish.append((A, B))

dish = sorted(dish, key=lambda x: x[0]+x[1], reverse=True)

ans = 0
for i in range(N):
    if i % 2 == 0:
        ans += dish[i][0]
    else:
        ans -= dish[i][1]
print(ans)


Measured memory_bytes: 22148
S = list(input())
nc = S.count("N")
sc = S.count("S")
ec = S.count("E")
wc = S.count("W")

for i, j in zip([nc, ec], [sc, wc]):
    if i == 0 and j == 0:
        continue
    elif i == 0 or j == 0:
        print("No")
        break
else:
    print("Yes")


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

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

vector<ll> l;

void search(int in){
	for (ll i = 1;i < in;i++){
		for (ll j = 1;j < in-i;j++){
			ll k = in-i-j;
			if(k <= 0) continue;
			vector<ll> a(in);
			for (int m = 0;m < in;m++){
				if(m < i) a[m] = 3;
				else if(m < j+i)a[m] = 5;
				else a[m] = 7;
			}
			do{
				ll num = 0;
				ll t = 1;
				for (int b = in-1;b >= 0 ;b--){
					num += a[b]*t;
					t *= 10;
				}
				//cout << num << endl;
				l.push_back(num);
			}while(next_permutation(a.begin(),a.end()));
		}
	}
	return;
}

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

	for (int i = 3;i <= 10;i++){
		search(i);
	}

	sort(l.begin(),l.end());

	ll n; cin >> n;

	for (int i = 0;i < l.size();i++){
		//cout << l[i] << endl;
		if(n < l[i]){ cout << i << endl; break;}
	}

	return 0;

}


Measured memory_bytes: 1400
n = int(input())
a = list(map(int, input().split()))

count = 0
flag = True

while flag:
    for i in range(n):
        if a[i] % 2 != 0:
            flag = False

    if flag == False:
        break

    for i in range(n):
        a[i] //= 2
    count = count + 1
print(count)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define md 1000000007
#define mx 1e18
#define pb push_back
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pii pair<ll int,ll int>
#define ff first
#define ss second
int dp[10001][102][2];
string s;
ll int d;
ll int n;
ll int ar[10001];

ll int f(ll int i , ll int j , ll int ff)
{

	if(i==n)
	{
		if(j==0)
			return 1;
		else
			return 0;
	}

	if(dp[i][j][ff]!=-1)
		return dp[i][j][ff];

	ll int ans=0;
	if(ff)
	{
		for(ll int x=0;x<=9;x++)
		{
			ans+=f(i+1,(j-x+d)%d,1);
			ans%=md;
		}
	}
	else
	{
		for(ll int x=0;x<ar[i];x++)
		{
			ans+=f(i+1,(j-x+d)%d,1);
			ans%=md;
		}
		ans+=f(i+1,(j-ar[i]+d)%d,0);
		ans%=md;
	}
	return dp[i][j][ff] = ans;
}

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

	cin>>s;
	cin>>d;
	n=s.length();
	memset(dp,-1,sizeof(dp));

	for(ll int i=0;i<n;i++)
		ar[i]=s[i]-'0';

	ll int ans = f(0,0,0)-1;
	ans=(ans+md)%md;

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 9088
def solve(N,W,wv):
    dp=[-1]*(W+1)
    dp[0]=0
    for i in range(N):
        cur_w=wv[i][0]
        cur_v=wv[i][1]
        for j in range(W-cur_w,-1,-1):
            if dp[j]==-1:
                continue
            if dp[j+cur_w]<dp[j]+cur_v:
                dp[j+cur_w]=dp[j]+cur_v
    return max(dp)


N,W=map(int,input().split())
wv=tuple(tuple(map(int,input().split())) for _ in range(N))
print(solve(N,W,wv))


Measured memory_bytes: 7716
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int n;
VI pena;
VVI gain;
int eval(VI &order)
{
    VI last(26, -1);
    int ret = 0;
    rep(i, n)
    {
        ret += gain[i][order[i]];
        last[order[i]] = i;
        rep(j, 26)
        {
            ret -= pena[j] * (i - last[j]);
        }
    }
    return ret;
}
void print(VI &order)
{
    for (auto &&x : order)
    {
        cout << x + 1 << endl;
    }
}

void search()
{
    auto starttime = clock();
    typedef pair<int, VI> Tact;
    priority_queue<Tact> pque;
    VI base(n);
    VI last(26, -1);
    rep(i, n)
    {
        int cur = -IINF;
        int penasum = 0;
        rep(j, 26)
        {
            penasum += pena[j] * (i - last[j]);
        }
        rep(j, 26)
        {
            if (cur < gain[i][j] - penasum + pena[j] * (i - last[j]))
            {
                base[i] = j;
                cur = gain[i][j] - penasum + pena[j] * (i - last[j]);
            }
        }
        last[base[i]] = i;
    }
    auto best = base;
    int bscore = eval(base);
    //pque.push({eval(base), base});
    cerr << bscore << endl;
    int loopnum = 0;
    while (double(clock() - starttime) / CLOCKS_PER_SEC < 1.9)
    {
        base[mt() % n] = mt() % 26;
        int cscore = eval(base);
        if (cscore > bscore)
        {
            best = base;
            bscore = cscore;
        }
        else
        {
            base = best;
        }
        loopnum++;
    }
    print(best);
    cerr << bscore << endl;
    cerr << loopnum << endl;
}
int main()
{
    cin >> n;
    pena = VI(26);
    gain = VVI(n, VI(26));
    rep(i, 26)
    {
        cin >> pena[i];
    }
    rep(i, n)
    {
        rep(j, 26)
        {
            cin >> gain[i][j];
        }
    }
    search();
    return 0;
}

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

int main()
{
    int n,m,inp,sum=0;
    cin>>n>>m;

    for(int i=0;i<m;i++)
    {
        cin>>inp;
        sum = sum +inp;
    }
    if(sum<=n)
    {
        cout<<n-sum<<endl;
    }
    else
        cout<<"-1"<<endl;


    return 0;
}


Measured memory_bytes: 3632