akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
 
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define len(x) int((x).size())
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define randint(n) uniform_int_distribution<int>(1, (n))(rng)

ll dp[2][2][1000001];

const int p = 1000000007LL;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 
	#ifdef ARTHUR_LOCAL
		ifstream cin("input.txt");
	#endif

	int n;
	cin>>n;

	dp[0][0][0]=1LL;

	for(int i=1; i<=n; i++)
	{
		dp[0][0][i] = 8LL * dp[0][0][i-1];
		dp[0][0][i] %= p;

		dp[0][1][i] = 9LL * dp[0][1][i-1] + dp[0][0][i-1];
		dp[0][1][i] %= p;

		dp[1][0][i] = 9LL * dp[1][0][i-1] + dp[0][0][i-1];
		dp[1][0][i] %= p;

		dp[1][1][i] = dp[1][0][i-1] + dp[0][1][i-1] + 10LL * dp[1][1][i-1];
		dp[1][1][i] %= p;
 	}

 	cout << dp[1][1][n] << "\n";
}

Measured memory_bytes: 34736
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin>>s;
    if((s.at(0)==s.at(1)&&s.at(2)==s.at(3)&&s.at(0)!=s.at(2))||(s.at(0)==s.at(2)&&s.at(1)==s.at(3)&&s.at(0)!=s.at(1))||(s.at(0)==s.at(3)&&s.at(2)==s.at(1)&&s.at(0)!=s.at(2))) cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rbf(a, x) for (auto& a : x)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    template<typename Num>
        constexpr Num mypow(Num a, long long b) {
            if(b==0)return 1;
            if (a==0)return 0;
            Num x = 1;
              while (b > 0) {
                if(b & 1)x*=a;
                a*=a;
                b >>= 1;
              }
              return x;
        }

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo
//mint,dijkstra,gyakugen

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        string s;
        cin>>s;
        ll r=Size(s)-1;
        ll l=0;
        ll res=0;
        while(r-l>0){
            if(s[l]==s[r]){
                l++;
                r--;
            }
            else if(s[l]=='x'){
                res++;
                l++;
            }
            else if(s[r]=='x'){
                res++;
                r--;
            }
            else{
                cout<<-1<<endl;
                return 0;
            }
        }
        cout<<res<<endl;
    }

Measured memory_bytes: 3716
#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 5e2+5;
int n, m, w, h, f, ans[N][N];
int main()
{
    n = read(), m = read(), w = read(), h = read();
    if(n%w == 0&&m%h == 0) return puts("No"), 0;
    else if(n%w == 0) swap(n, m), swap(w, h), f = 1;
    for(int i = 1; i <= n; i += w) ans[i][(m/h)*h] = (n/w)*(m/h)+1;
    for(int i = w; i <= n; i += w) ans[i][(m/h)*h] = -(n/w)*(m/h)-2;
    for(int i = w; i <= n; i += w)
        for(int j = h; j+h <= m; j += h)
            ans[i][j] = -1;
    puts("Yes");
    if(!f)
        for(int i = 1; i <= n; ++i, puts(""))
            for(int j = 1; j <= m; ++j)
                printf("%d ", ans[i][j]);
    else 
        for(int i = 1; i <= m; ++i, puts(""))
            for(int j = 1; j <= n; ++j)
                printf("%d ", ans[j][i]);
    return 0;
}
/*
4 3 2 2
*/

Measured memory_bytes: 1792
// A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<string>
using namespace std;
int main()
{
    string s;

    cin >> s;
    bool ok = true;

    for (int i = 0; i < 3; i++) {
        if (s[i] == s[i + 1]) {
            ok = false;
        }
    }

    if (ok)cout << "Good" << endl;
    else cout << "Bad" << endl;

}



Measured memory_bytes: 3624
//Twenty Questions
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define BMAX 177157
#define bmax (2<<11)+10
using namespace std;


#define INF 100

int dp[BMAX]={0};
int youso[BMAX]={0};
int obj[130][20];
int m,n;

int checkyouso(int);

int checkdp(int S){
//	printf("%d dp\n",S);
	if(dp[S]!=100)
		return dp[S];
	if(checkyouso(S)==1)
		return 0;
	if(checkyouso(S)==0)
		return 100;
	int a[20];
	int temp = S;
//	printf("%d \n",temp);
	rep(i,m){
		a[i]=temp%3;
		temp/=3;
//		printf("%d ",a[i]);
	}
//	printf("| %d \n",checkyouso(S));
	rep(i,m){
		int temp = 0;
		if(a[i]!=2)
			continue;
		rep(bit,2){temp=max(temp,checkdp(S+pow(3,i)*(bit-2))+1);
		}
		dp[S]=min(dp[S],temp);
//		printf("dp[S]=%d,i=%d,S=%d\n",dp[S],i,S);
//		printf("%d \n",temp);

	}
	return dp[S];
}


int checkyouso(int S){
//	printf("%d youso\n",S);
	if(youso[S]!=100)
		return youso[S];
	int a[20];
	int temp = S;
	rep(i,m){
		a[i]=temp%3;
		temp/=3;
	}
	int num = 0;
	rep(i,n){
		temp = 0;
		rep(j,m){
			if(a[j]==2)
				continue;
			else if(a[j]!=obj[i][j]){
				temp = 1;
				break;
			}
		}
		if(temp == 1){
			continue;
		}
		num++;
	}
	youso[S]=num;
	return num;
}

int main(){
//	printf("%d\n",(int)pow(3,11)+10);
	char str[100];
	
	while(1){
		scanf("%d %d",&m,&n);
		
		if(m==0&&n==0)
			break;
		
		rep(i,BMAX){
			dp[i]=100;
			youso[i]=100;
		}
		rep(i,n){
			scanf("%s",str);
			rep(j,m){
				obj[i][j]=(str[j]-'0');
			}
		}
		int ans = checkdp((int)pow(3,m)-1);
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 2624
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;

#define mpr make_pair


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

    string s;
    cin>>s;
    reverse(s.begin(), s.end());
    lint n = s.size();
    lint base = 1;
    lint mod = 2019;
    vl summ(n+1, 0);

    map<lint, lint> mcnt;
    mcnt[0]++;
    for (lint i=0; i<n; ++i){
        lint cur = (s[i]-'0')*base % mod;
        base = base*10 % mod;
        summ[i+1] = (summ[i] + cur)%mod;
        mcnt[summ[i+1]]++;
    }
    lint res = 0;
    for (pll p : mcnt){
        res += p.second * (p.second-1)/2;
    }
    cout<<res;
}


Measured memory_bytes: 5140
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 1145141919810ll
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(15)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

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

  int N, M, P, A, B, C; cin >> N >> M >> P;
  vector<edge> G;
  int d[2500]; fill(d, d+N, INF); d[0] = 0;
  REP(i, M){
    cin >> A >> B >> C;
    A--; B--; C-=P;
    G.push_back({A, B, -C});
  }
  sort(ALL(G), [](edge a, edge b){
    if(a.from != b.from) return a.from < b.from;
    return a.to < b.to;
  });

  bool close = 0;
  REP(cnt, N*2){
    REP(i, M){
      edge e = G[i];
      int tmp = d[N-1];
      if(d[e.to] > d[e.from] + e.cost){
        d[e.to] = d[e.from] + e.cost;
        if(cnt >= N-1 and d[N-1] < tmp){
          close = 1; break;
        }
      }
    }
  }

  if(close){
    cout << -1 << endl;
  } else {
    cout << max(0ll, -d[N-1]) << endl;
  }
}


Measured memory_bytes: 576
#include <stdio.h>
int n;
int C[10001];
void CountingSort(int A[],int B[],int k){
    int i,j;
    for(i=0;i<k;i++){
        C[i]=0;
    }
    for(j=1;j<=n;j++){
        C[A[j]]++;
    }
    for(i=1;i<=k;i++){
        C[i]=C[i]+C[i-1];
    }
    for(j=n;j>=1;j--){
        B[C[A[j]]]=A[j];
        C[A[j]]--;
    }
}
int main(){
    int i,MAX=0;
    int *A,*B;
    scanf("%d",&n);
    A = malloc(sizeof(int)*n+1);
    B = malloc(sizeof(int)*n+1);
    for(i=1;i<=n;i++){
        scanf("%d",&A[i]);
        if(MAX<A[i]){
            MAX=A[i];
        }
    }
    CountingSort(A,B,MAX);
    for(i=1;i<=n-1;i++){
        printf("%d ",B[i]);
    }
    printf("%d\n",B[i]);
}


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

int main() {
  string S;
  cin >> S;
  bool flag = false;
  for (int i = 0; i < S.size(); i += 2)
    if (S.substr(i, 2) != "hi")
      flag = true;
  if (!flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{
  unsigned long long n, sum;
  while(cin >> n, n) {
    vector<int> t(n), sub(n);
    sum = 0;
    for(int i = 0 ; i < n ; i++) {
      cin >> t[i];
    }
    sort(t.begin(), t.end());
    for(int i = 0 ; i < n ; i++) {
      sub[i+1] += (sub[i] + t[i]); 
    }
    for(int i = 0 ; i < n ; i++) {
      sum += sub[i];
    }
    cout << sum << endl;
  }
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    N %= 10; //余りをいれることで一の位が手に入る

    if (N == 2 || N == 4 || N == 5 || N == 7 || N == 9)
        cout << "hon" << endl;
    else if (N == 3)
        cout << "bon" << endl;
    else
        cout << "pon" << endl;

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define ld long double
#define vi vector<vector<ll> >
using namespace std;
const int MOD=1000000007;
const int MOD2=998244353;
const ll MAX=9187201950435737471;
const int N=100005;
const int INF=1e9+7;
const long double PI=acos(-1);



void solve(int T){
    int n;
    cin>>n;
    int x=1000-n%1000;
    cout<<x%1000;
}

int main() {
    fastio

    int T=1;
    //cin>>T;
    for(int i=1;i<=T;i++){
        solve(i);
        if(i<T)cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

int main(){

    int a;
    cin >> a;
    string s;
    cin >> s;

    if(a >= 3200) cout << s << endl;
    else cout << "red" << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int main() {
    long n,x;
    cin>>n>>x;
    vector<int> a(n);
    rep(i,n){
        cin>>a[i];
        a[i]=abs(x-a[i]);
    }
    int ans=0;
    rep(i,n){
        ans=gcd(ans,a[i]);
    }
    cout<<ans;
}

Measured memory_bytes: 3708
function main(p){
  'use strict'
  const num = parseInt(p.split('\n')[0], 10)
  for(let i=1; i<10; i++){
    if((num % i === 0) && (num / i <= 9)){
      console.log('Yes')
      return
    }
  }
  console.log('No')
    
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7372
# Problem B - バイナリックイージー
# input
s = list(input())

# initialization
result = []

# count
for c in s:
    if c=='B':
        if len(result)>0:
            result.pop(-1)
    elif c=='0':
        result.append(c)
    elif c=='1':
        result.append(c)

# output
print("".join(result))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> x(n);
    vector<vector<int>> y(3, vector<int>(n));
    int a = 0;
    int bcnt = 0;
    for (int i = 0; i < n; i++) {
        x[i] = s[i] - '0';
        if (x[i]) {
            bcnt++;
        }
    }
    vector<int> z(3);
    for (int j = bcnt - 1; j <= bcnt + 1; j++) {
        if (j <= 0) {
            continue;
        }
        y[j - bcnt + 1][n - 1] = 1 % j;
        if (x[n - 1]) {
            z[j - bcnt + 1] += y[j - bcnt + 1][n - 1];
        }
        for (int i = n - 2; i >= 0; i--) {
            y[j - bcnt + 1][i] = y[j - bcnt + 1][i + 1] * 2 % j;
            if (x[i]) {
                z[j - bcnt + 1] += y[j - bcnt + 1][i];
                z[j - bcnt + 1] %= j;
            }
        }
    }
    int st = bcnt;
    for (int i = 0; i < n; i++) {
        if (st == 1 && x[i] == 1) {
            cout << 0 << '\n';
            continue;
        }
        x[i] ^= 1;
        if (x[i]) {
            bcnt++;
        } else {
            bcnt--;
        }
        int k = z[bcnt - st + 1];
        if (x[i]) {
            k += y[bcnt - st + 1][i];
        } else {
            k -= y[bcnt - st + 1][i];
        }
        k += bcnt;
        k %= bcnt;
        int ans = 1;
        while (k) {
            k %= __builtin_popcount(k);
            ans++;
        }
        cout << ans << '\n';
        x[i] ^= 1;
        if (x[i]) {
            bcnt++;
        } else {
            bcnt--;
        }
    }
    return 0;
}

Measured memory_bytes: 7544
#include<bits/stdc++.h>
#define ll long long int
#define r0 return 0
using namespace std;

int main()
{
    int n,m,i,j,k,t,x;

     int a,b,c;

     cin>>a>>b>>c>>k;

     while(k--){

          if(b<=a){
              b*=2;
          }
          else if(c<=b){

            c*=2;
          }
     }

     if(c>b && b>a){

        cout<<"Yes"<<endl;
     }
     else{

        cout<<"No"<<endl;
     }

    return 0;
}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int main()
{
    int h,w;
    int dx[8]={0,1,1,1,0,-1,-1,-1};
    int dy[8]={1,1,0,-1,-1,-1,0,1};
    while(cin >>h >>w,h|w)
    {
        vector<string> s(h);
        rep(i,h) cin >>s[i];

        map<string,int> ct;
        //start
        rep(i,h)rep(j,w)rep(k,8)
        {
            int x=j,y=i;
            string now="";

            vector<vector<int>> vis(h,vector<int>(w,0));
            rep(a,h*w)
            {
                if(vis[y][x]) break;

                now+=s[y][x];
                vis[y][x]=1;
                y=(y+dy[k]+h)%h;
                x=(x+dx[k]+w)%w;

                if(now.size()>=2)
                {
                    if(ct.find(now)==ct.end()) ct[now]=1;
                    else ++ct[now];
                }
            }
        }

        string ans="";
        for(const auto &i:ct)
        {
            if(i.se>1)
            {
                string t=i.fi;
                if(t.size()>ans.size()) ans=t;
                else if(t.size()==ans.size() && t<ans) ans=t;
            }
        }

        if(ans=="") ans="0";
        std::cout << ans << std::endl;
    }
    return 0;
}

Measured memory_bytes: 37860
#include <bits/stdc++.h>
#define lid id<<1
#define rid id<<1|1
using namespace std;
const int maxn=1e5+5;
typedef long long ll;
int n,a[101];
int read() {
	char ch = getchar();
	int x = 0, f = 1;
	while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
	while (ch >= '0' && ch <= '9') x = x*10 + ch - 48, ch = getchar();
	return x * f;
}
int main() {
	n=read();
	for(int i=1; i<=n; i++) {
		a[i]=read();
		if(a[i]%2==0) {
			if(a[i]%3!=0&&a[i]%5!=0) {
				cout<<"DENIED";
				return 0;
			}
		}
	}
	cout<<"APPROVED";
	return 0;
}

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

int a,b,x;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>a>>b>>x;
	if(x <= a+b && x >= a)
		cout<<"YES";
	else
		cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	string s; int K;
	cin >> s >> K;
	set<string>sub;
	for (int i = 0; i < s.size();++i) {
		for (int j = 1; j <= K; ++j) {
			if (i + j > s.size())continue;
			sub.insert(s.substr(i, j));//K文字以内の部分文字列を重複なしで全列挙
		}
	}
	auto itr = sub.begin();//1番小さい部分文字列をiteratorで取得
	repp(i, 0, K-1)++itr;//K番目になるようにiterotorの位置を進める
	cout << *itr << endl;//K番目のiteratorが指す値にアクセス
	return 0;
}


Measured memory_bytes: 1664
N = int(input())
a = list(map(int, input().split()))

alice = []
bob = []
i = 2
while True:
    mx = max(a)
    if i % 2 == 0:
        alice.append(mx)
    else:
        bob.append(mx)
    a.remove(mx)
    i+=1
    if len(a) == 0:
        break

print(sum(alice)-sum(bob))

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

/*
,,,,
　　　　　　　　　　　　　　　　　　　　　　　　　　,.斗*''“i:i:{
　　　　　　　　　　　　　,.　｡. . . * : : : ''' : : : :” :”“ ''ｰ - 弋,,_
　　　　　 　 　 ,.斗*''“ : : : : : : : : : : : : : ' ' ' ' ' ' : : : : : : : : : : :”: '':* ｡ ,
　　　 ,.斗*''“ ” ＼：　　 ”・・． ' ' ' '　　　　　　　　 ' ' ' ' : : : : : : : : : : : : ”ミ*｡,,,,,,　　　　　　 　 　 　 ＿
　　く.　 ◎　 ﾞ:.ﾞ:..　ﾟ:,　:　───────────　　　--　　,,,,,,__ ' ' ' :.:.:.:.:.”≧s｡.　　＿,,,｡s*i:i:i:i:<
　　ﾏ*s｡ :,　 }　ﾟ:,　 :}　　　　　　　　　　　　　　　　　　　　　　　　　　　　”　''　-　”””：：”：：`*｡i:i:i:i:i:i:i;:’
　　　` .｡`　 ,　,ノ ／｡ ,,,_　　　　　　　　　　　　　　　　　　　　　　　　　　　　　＿＿`　　} }　　ﾉi:i:i:i:i:ﾂ
　　　　　 `　*　｡　　`*｡i:i:i::*=-　　　　　　　　　　　＿＿　　　　　　,,,....｡s*'i,:’　　　”`*｡＿,*’i:i:i:i:r’
　　　　　　　　　　　”　─ --　　　　｡｡｡｡｡　　 -　－`''''''''ヽ ─ '''”　　　｀ｰ“　　　　　　　`*｡i:i:i:i:i:i:
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*｡i:i:::
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*ﾟ:,
         fozubaoyou    no BUGs alive!
*/

typedef long long ll;
//{
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define dumo dump
#define sysp system("pause")
//}

#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 0

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cout<<endl;}
template<class...A> inline void debug_rest() {cout<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cout<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cout<<first,debug_rest(rest...);}
inline long long digitsum(long long v){long long d=0;while(v){d+=v%10;v/=10;}return d;}
inline long long digitnumbersum(long long a){long long b=0;while(a){a/=10;b++;}return b;}
inline long long mysqrt(long long a){long long i=0;for(i=1;a>0;i++){a-=i*2+1;}return i-1;}
//}

int main(){
  int a;
  cin>>a;
  int b[a];
  for(int i=0;i<a;i++){
    cin>>b[i];
  }
  dump(abs(*max_element(b,b+a)-(*min_element(b,b+a))));
}


Measured memory_bytes: 764
import sys
input = sys.stdin.readline


class Input():
    def __init__(self):
        self.line = input()

    def number(self):
        return int(self.line)

    def numbers(self):
        array = self.line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strings(self):
        return self.line.split(' ')


def main():
    ipt = Input()
    ab = ipt.numbers()
    a = ab[0]
    b = ab[1]

    if a < 10 and b < 10:
        print(a*b)
    else:
        print('-1')


main()


Measured memory_bytes: 3064
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt(),m=s.nextInt();
		long[]dp=new long[m+1];
		for(int q=0;q<n;++q) {
			int w=s.nextInt(),v=s.nextInt();
			for(int i=m;i>=w;--i)
				dp[i]=Math.max(dp[i],dp[i-w]+v);
		}
		System.out.println(dp[m]);
	}
}


Measured memory_bytes: 22996
import java.io.InputStreamReader
import java.io.BufferedReader

fun main(args: Array<String>) {
  val br = BufferedReader(InputStreamReader(System.`in`))

  val n = br.readLine().toInt()
  val seq = br.readLine().split(" ").map { it.toInt() }.toIntArray()

  // val a1 = seq.first()
  val ans = seq.drop(1).fold(Triple(1, seq.first(), 0)) { acc, i ->
    val (cnt, pre, sign) = acc
    when {
      pre == i && sign == 0 -> Triple(cnt, i, 0)
      pre < i && sign == 0 -> Triple(cnt, i, 1)
      pre > i && sign == 0 -> Triple(cnt, i, -1)
      pre <= i && sign > 0 -> Triple(cnt, i, 1)
      pre >= i && sign < 0 -> Triple(cnt, i, -1)
      else -> Triple(cnt + 1, i, 0)
    }
  }.first
  println(ans)
}

Measured memory_bytes: 57948
from collections import defaultdict, deque
import sys
input = sys.stdin.readline

N = int(input())
count = defaultdict(int)
for _ in range(N):
    S = input().rstrip()
    count[S] += 1
ans = []
for k, v in count.items():
    ans.append((v, k))
ans.sort(key=lambda x: (-x[0], x[1]))
ans = deque(ans)
m = ans[0][0]
while ans:
    v, k = ans.popleft()
    if v == m:
        print(k)
    else:
        break


Measured memory_bytes: 59484
#!/usr/bin/python
# coding: UTF-8

from math import *
import os
import sys

#import scipy.optimize
import numpy as np


##################################################################
if __name__ == "__main__":
    Input = [raw_input() for i in range(1)]
    [a,b] = list(map(int,Input[0].split()))
    if a*b % 2 == 0:
        print 'Even'
    else:
        print 'Odd'
    
    

Measured memory_bytes: 20340
#include <stdio.h>
#include <math.h>

#define POW(x) ((x) * (x))

int main(){
  int n, i, j;
  double s[1001], dev, ave, sum;
  while(scanf("%d", &n) && n){
    sum = 0;
    for(i = 0; i < n; ++i){
      scanf("%lf", &s[i]);
      sum += s[i];
    }
    ave = sum / n;
    sum = 0;
    for(i = 0; i < n; ++i) sum += POW(s[i] - ave);
    printf("%.8f\n", sqrt(sum / n));
  }
  return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define allsort(v) sort(v.begin(),v.end())
const ll mod = 1e9 + 7;
const int inf = 1e9;

int main() {
	cin.sync_with_stdio(false);
	string s;
	cin >> s;
	int gcount = 0, pcount = 0;
	for (auto x : s) {
		if (x == 'p')pcount++;
		else gcount++;
	}
	cout << (pcount + gcount)/2 - pcount << endl;
	return 0;
}

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

using ll = long long;

int a[100010];
int b[100010];

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

    int n;
    cin>>n;

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

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

    ll ans=0;

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

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 4440
N = int(input())
lis_B = list(map(int, input().split()))
lis_A = []
for i in range(N-2):
    lis_A.append(min(lis_B[i], lis_B[i+1]))
ans = sum(lis_A) + lis_B[0] + lis_B[N-2]
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
struct Point{
    double x,y;
    Point(){}
    Point(double x,double y):x(x),y(y){}
};
typedef Point Vector;
Vector operator + (Vector A,Vector B){
    return Vector(A.x+B.x,A.y+B.y);
}
Vector operator - (Vector A,Vector B){
    return Vector(A.x-B.x,A.y-B.y);
}
Vector operator * (Vector A,double p){
    return Vector(A.x*p,A.y*p);
}
Vector operator / (Vector A,double p){
    return Vector(A.x/p,A.y/p);
}
bool operator < (const Point& a,const Point& b){
    return a.x<b.x||(a.x==b.x&&a.y<b.y);
}
const double eps = 1e-10;
int dcmp(double x){
    if(fabs(x)<eps) return 0; else return (x<0?-1:1);
}
bool operator == (const Point& a,const Point& b){
    return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y)==0;
}
//点积
double Dot(Vector A,Vector B){
    return A.x*B.x+A.y*B.y;
}
double Length(Vector A){
    return sqrt(Dot(A,A));
}
double Angle(Vector A,Vector B){
    return acos(Dot(A,B)/Length(A)/Length(B));
}
 
//叉积
double Cross(Vector A,Vector B){
    return (A.x*B.y-A.y*B.x);
}
//三角形面积的二倍的叉乘公式
double Area2(Point A,Point B,Point C){
    return Cross(B-A,C-A);
}
//向量旋转,rad是弧度
Vector Rotate(Vector A,double rad){
    return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad));
}
//计算向量的单位法线,先逆时针旋转90度，然后把长度归一化
Vector Normal(Vector A){
    double Len=Length(A);
    return Vector(-A.y/Len,A.x/Len);
}
//求两直线交点
//调用前请确保P+tv和Q+tw有唯一交点，当且仅当Cross(v,w)非0
Point GetLineIntersection(Point P,Vector v,Point Q,Vector w){
    Vector u=P-Q;
    double t=Cross(w,u)/Cross(v,w);
    return P+v*t;
}
//点到直线的距离
double DistanceToLine(Point P,Point A,Point B){
    Vector v1=B-A,v2=P-A;
    return fabs(Cross(v1,v2))/Length(v1);
}
//点到线段的距离
double DistanceToSegment(Point P,Point A,Point B){
    if(A==B) return Length(P-A);
    Vector v1=B-A,v2=P-A,v3=P-B;
    if(dcmp(Dot(v1,v2))<0) return Length(v2);
    else if(dcmp(Dot(v1,v3))>0) return Length(v3);
    else return fabs(Cross(v1,v2))/Length(v1);
}
//点在直线上的投影
Point GetLineProjection(Point P,Point A,Point B){
    Vector v=B-A;
    return A+v*(Dot(v,P-A)/Dot(v,v));
}
Point GetLineReflection(Point P,Point A,Point B){
    return GetLineProjection(P,A,B)*2-P;
}
int main(){
    Point A,B;
    cin>>A.x>>A.y>>B.x>>B.y;
    int t;
    cin>>t;
    while(t--){
        Point P;
        cin>>P.x>>P.y;
        double cro=Cross(B-A,P-A);
        double dot=Dot(B-A,P-A);
        double dot2=Dot(A-B,P-B);
        if(dcmp(cro)<0){
            cout<<"CLOCKWISE";
        }else if(dcmp(cro)>0){
            cout<<"COUNTER_CLOCKWISE";
        }else{
            if(dcmp(dot)<0){
                cout<<"ONLINE_BACK";
            }else{
                if(dcmp(dot2)<0){
                    cout<<"ONLINE_FRONT";
                }else{
                    cout<<"ON_SEGMENT";
                }
            }
        }
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
/*
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
*/

#define INF 10e15
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

int main(){
  long long int dist[100][100];
  long long int V, E;
  cin >> V >> E;

  long long int s, t, d;
  long long int i, j, k;
  for(i = 0; i < V; i++){
      for(j = 0; j < V; j++){
          if(i == j){
              dist[i][j] = 0;
          }else{
              dist[i][j] = INF;
          }
       }
  }
  for(i = 0; i < E; i++){
      cin >> s >> t >> d;
      dist[s][t] = d;
  }

  for(k = 0; k < V; k++){
      for(i = 0; i < V; i++){
          for(j = 0; j < V; j++){
              if(dist[i][k] != INF && dist[k][j] != INF){
                  dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
              }
              if(i == j && dist[i][j] < 0){
                  cout << "NEGATIVE CYCLE" << endl;
                  return 0;
              }
          }
      }
  }

  for(i = 0; i < V; i++){
       for(j = 0; j < V; j++){
          if(j) cout<<" ";
          if(dist[i][j] == INF) cout<<"INF";
          else cout << dist[i][j];
       }
       cout<<endl;
   }
}







Measured memory_bytes: 3180
n = int(input())
a = list(map(int,input().split()))
num =set()
for i in range(n-2):
    if a[i]<=a[i+1] and a[i+1]<=a[i+2]:
        num.add(a[i+1])
    elif a[i]>=a[i+1] and a[i+1]>=a[i+2]:
        num.add(a[i + 1])
print(len(num))

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> sum(m, 0);
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++) {
      int a;
      cin >> a;
      sum[a - 1]++;
    }
  }

  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (sum[i] == n) ans++;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 200001

using namespace std;

ll func(ll a) // [1, a]
{
    if(a == -1) return 0;
    switch (a % 4) {
        case 1:
            return 1;
            break;
        case 2:
            return a + 1;
            break;
        case 3:
            return 0;
            break;
        case 0:
            return a;
            break;
    }
    return -1;
}

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    ll A, B; cin >> A >> B;
    auto left = func(A - 1);
    auto right = func(B);
    auto ret = left ^ right;
    cout << ret << endl;
    
    return 0;
}


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

int main()
{
    int a,b,c,sum;
    while(scanf("%d%d%d",&a,&b,&c)!=EOF)
    {
        sum = a*100+b*10+c;
        if (sum%4==0)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s1 = scn.next();
      	String s2 = scn.next();
      	String s3 = scn.next();
      	String[] a = s1.split("");
      	String[] b = s2.split("");
      	String[] c = s3.split("");
      	int aa = s1.length();
      	int bb = s2.length();
      	int cc = s3.length();
      	String next = "a";
      	while(true){
          if(next.equals("a")){
            if(aa==0){
            	System.out.println("A");
				return;
            }
            next = a[s1.length()-aa];
					aa--;
          }
          if(next.equals("b")){
            if(bb==0){
            	System.out.println("B");
				return;
            }
            next = b[s2.length()-bb];
					bb--;
          }
          if(next.equals("c")){
            if(cc==0){
            	System.out.println("C");
				return;
            }
            next = c[s3.length()-cc];
					cc--;
          }
        }
	}
}


Measured memory_bytes: 35376
#include <stdio.h>
#include <math.h>

void maxHeapify(int a[],int i,int H){
    int max=i;
    int l,r;
    l=i*2;
    r=i*2+1;
    
    if(l<=H&&a[i-1]<a[l-1])max=l;
    
    if(r<=H&&a[max-1]<a[r-1])max=r;
    
    int tmp;
    if(max!=i){
        tmp=a[i-1];
        a[i-1]=a[max-1];
        a[max-1]=tmp;
        
        maxHeapify(a,max,H);
    }
    
    return;
}
void buildMaxHeap(int a[],int H){
    int i;
    for(i=H/2;i>=0;i--)maxHeapify(a,i+1,H);
    return;
}

int main(){
    int i;
    
    int H;
    scanf("%d\n",&H);
    
    int a[H];
    for(i=0;i<H;i++)scanf("%d \n",&a[i]);
    
    buildMaxHeap(a,H);    
    
    for(i=0;i<H;i++)printf(" %d",a[i]);
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 3640
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2,
     1, 5, 1, 2, 1, 14, 1, 5, 1, 5,
     2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
n = int(input())
print(a[n-1])

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

using namespace std;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(int i=a; i<int(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto& e:c)
#define iter(it,c) for(auto it=c.begin(); it!=c.end(); ++it)

int g[9][9];
bool ok[9][9];

void solve(){
    rep(y,9)rep(x,9){
        loop(i,y+1,9){
            if(g[y][x]==g[i][x]){
                ok[i][x]=false;
                ok[y][x]=false;
            }
        }

        loop(j,x+1,9){
            if(g[y][x]==g[y][j]){
                ok[y][j]=false;
                ok[y][x]=false;
            }
        }
    }

    rep(i,3)rep(j,3){
        rep(a,9){
            int x=a%3+i*3;
            int y=a/3+j*3;
            loop(b,a+1,9){
                int xx=b%3+i*3;
                int yy=b/3+j*3;
                if(g[y][x]==g[yy][xx]){
                    ok[yy][xx]=false;
                    ok[y][x]=false;
                }
            }
        }
    }

}

int main(){
    int n;
    cin>>n;
    rep(i,n){
        rep(y,9)rep(x,9){
            ok[y][x]=true;
        }
        rep(y,9)rep(x,9)cin>>g[y][x];
        solve();
        rep(y,9)rep(x,9){
            printf("%c%d",ok[y][x]?' ':'*',g[y][x]);
            if(x+1==9)puts("");
        }
        if(i+1!=n)puts("");
    }
}

Measured memory_bytes: 1144
#include <stdio.h>

int main() {
	int h,w,n;
	scanf("%d", &h);
	scanf("%d", &w);
	scanf("%d", &n);
	int ctr = 0;
	int total = 0;
	while (n > total){
		if(w >= h){
			total += w;
			ctr++;
		}else if(h > w){
			total += h;
			ctr++;
		}
	}
	printf("%d\n",ctr);
	
	return 0;
}


Measured memory_bytes: 1672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;

int div13[6]={1,10,9,12,3,4};


int main(){
  string s;cin>>s;
  reverse(all(s));
  int ssz=s.size();
  ll dp[ssz+1][13];
  rep(i,ssz+1) rep(j,13) dp[i][j]=0;
  dp[0][0]=1;
  rep(i,ssz){
    if(s[i]=='?'){
      rep(j,10){
        int p=div13[i%6]*j%13;
        rep(k,13){
          dp[i+1][(p+k)%13]+=dp[i][k];
          dp[i+1][(p+k)%13]%=mod;
        }
      }
    }
    else{
      int q=s[i]-'0';
      int p=div13[i%6]*q%13;
      rep(k,13){
        dp[i+1][(p+k)%13]+=dp[i][k];
        dp[i+1][(p+k)%13]%=mod;
      }
    }
  }
  cout<<dp[ssz][5]%mod<<endl;
}



Measured memory_bytes: 10624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String s1 = sc.nextLine();
		String s2 = new StringBuilder(sc.next()).reverse().toString();

		System.out.println((s1.equals(s2)) ?  "YES" : "NO");

		sc.close();


	}

}




Measured memory_bytes: 23636
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; double w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int dfs(vector<string>& a, vector<string>& b, string& c, string& d) {
	if (c == d) return 0;
	else if (c.length() >= d.length()) return INT_MAX / 2;
	int mini = INT_MAX / 2;
	for (int i = 0; i < a.size(); i++) {
		string s = c, t;
		while (!s.empty()) {
			if (s.length() >= a[i].length() && s.substr(0, a[i].length()) == a[i]) {
				t += b[i];
				s.erase(s.begin(), s.begin() + a[i].length());
			}
			else {
				t += s[0];
				s.erase(s.begin(), s.begin() + 1);
			}
		}
		if (t != c)
			mini = min(mini, dfs(a, b, t, d) + 1);
	}
	return mini;
}

int main() {
	for (;;) {
		int n; cin >> n;
		if (n == 0) break;
		vector<string> a(n), b(n);
		for (int i = 0; i < n; i++)
			cin >> a[i] >> b[i];
		string c, d; cin >> c >> d;
		int x = dfs(a, b, c, d);
		cout << (x < INT_MAX / 2 ? x : -1) << endl;
	}
}

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

int main(){
    map<char,string> m;
    cin >> m['a'] >> m['b'] >> m['c'];
    char next = 'a';
    char now;
    while(m[next].size() != 0){
        now = next;
        next = m[now][0];
        m[now] = m[now].substr(1);
    }
    if(next == 'a'){
        cout << 'A' << endl;
    }else if(next == 'b'){
        cout << 'B' << endl;
    }else if(next == 'c'){
        cout << 'C' << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define INF 1145141919
//#define int long long  
int main(){
    int N;
    bool fc=1;
    int p[114514];
    int q[114514];
    int r[114514];
    int s[114514];
    int ans1=0;
    int ans2=0;
    int ans3=0;
    int ans4=0;
    cin >> N;
    REP(i,N){cin >> p[i];q[i]=p[i];r[i]=p[i];s[i]=p[i];if(p[i]==i+1){fc=0;}}
    if(fc==1){
        cout << 0 <<endl;
    }else{
        REP(i,N-1){
            if(p[i]==i+1){
                swap(p[i],p[i+1]);
                ans1++;
            }
        }
        if(p[N-1]==N){ans1=INF;}
        
        for(int i=N-1;i>0;i--){
            if(q[i]==i+1){
                swap(q[i-1],q[i]);
                ans2++;
            }
        if(q[0]==1){ans2=INF;}
        
        }for(int i=0;i<=(N+1)/2;i++){
            if(r[i]==i+1){
                swap(r[i],r[i+1]);
                ans3++;
            }
            if(i+1>(N+1)/2)continue;
            if(r[N-1-i]==N-i){
                swap(r[N-2-i],r[N-1-i]);
                ans3++;
            }
        }
        REP(i,N){if(r[i]==i+1){ans3=INF;break;}}
        
        /*for(int i=0;i<=(N+1)/2;i++){
            if(s[N-1-i]==N-i){
                swap(s[i-1],s[i]);
                ans4++;
            }
           
            if(i+1>(N+1)/2)continue;
                if(s[i]==i+1){
                swap(s[i],s[i+1]);
                ans4++;
            }
        }
        REP(i,N){if(s[i]==i+1){ans4=INF;break;}}*/
        ans4=INF;
        
        //cout << ans1 <<  " " << ans2 << " " << ans3<<" " << ans4 <<  endl;
        ans3=min(ans3,ans4);
        if(ans1!=INF || ans2!=INF){
            cout << min({ans1,ans2,ans3}) << endl;
        }else{
            cout << min((N+1)/2,ans3) <<endl;
        }
    }
	return 0;
}

Measured memory_bytes: 1408
# DPL 1 B

def solve():
    INF = 1e+9
    n, w = map(int, input().split())
    items = [list(map(int, input().split())) for _ in range(n)]
    dp = [[0] * (w+1) for _ in range(n+1)]
    for i in range(1, n+1):
        for j in range(1, w+1):
            item = items[i-1]
            # max(dp[i-1][j], dp[i][j-item[1]] + item[0])
            if j - item[1] < 0:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-item[1]] + item[0])

    print(dp[-1][-1])


if __name__ == "__main__":
    solve()



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

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define int long long
using ll = long long;
int N, M, L, K, A, H;
ll dp[101][101];  // dp[i][j]=街iに、残り時間jで来るときの最短時間
bool canfri[101];
struct edge {
    int to, cost;
};
vector<edge> G[101];
void init() {
    REP(i, N) {
        REP(j, M + 1) { dp[i][j] = 1e18; }
    }
    dp[A][M] = 0;
    REP(i, N) {
        canfri[i] = false;
        G[i].clear();
    }
}

using arr3 = array<int, 3>;
bool solve() {
    cin >> N >> M >> L >> K >> A >> H;
    if (N == 0) return false;
    init();
    REP(i, L) {
        int x;
        cin >> x;
        canfri[x] = true;
    }
    REP(i, K) {
        int u, v, c;
        cin >> u >> v >> c;
        G[u].push_back({v, c});
        G[v].push_back({u, c});
    }
    priority_queue<arr3, vector<arr3>, greater<arr3>> que;
    que.push({0, A, M});
    while (!que.empty()) {
        arr3 ar = que.top();
        que.pop();
        int c = ar[0], now = ar[1], rem = ar[2];
        if (c > dp[now][rem]) continue;
        if (canfri[now] && rem < M) {
            if (dp[now][rem] + 1 < dp[now][rem + 1]) {
                dp[now][rem + 1] = dp[now][rem] + 1;
                que.push({dp[now][rem + 1], now, rem + 1});
            }
        }
        for (auto e : G[now]) {
            int nxt = e.to;
            if (rem < e.cost) continue;
            if (dp[now][rem] + e.cost < dp[nxt][rem - e.cost]) {
                dp[nxt][rem - e.cost] = dp[now][rem] + e.cost;
                que.push({dp[nxt][rem - e.cost], nxt, rem - e.cost});
            }
        }
    }
    ll ans = 1e18;
    REP(j, M + 1) { ans = min(ans, dp[H][j]); }
    if (ans < 1e18)
        cout << ans << endl;
    else
        cout << "Help!" << endl;
    return true;
}
signed main() {
    while (solve())
        ;
    return 0;
}


Measured memory_bytes: 3532
from collections import defaultdict
n, k = map(int, input().split())
a = list(map(int, input().split()))

b = defaultdict(int)
for i in range(n):
    b[a[i]] += 1

c = list(b.values())
c.sort()

ans = 0
for i in range(len(c) - k):
    ans += c[i]

print(ans)


Measured memory_bytes: 32564
n,k = map(int,input().split())
t = [0 for i in range(10**5+1)]
count=k
for i in range(n):
    a,b = map(int,input().split())
    t[a-1]+=b
for i in range(10**5+1):
    count -= t[i]
    if count <= 0:
        print(i+1)
        exit()

Measured memory_bytes: 5920
s = input()

if s == 'SSS':
    print('0')
elif s == 'SSR':
    print('1')
elif s == 'SRS':
    print('1')
elif s == 'RSS':
    print('1')
elif s == 'SRR':
    print('2')
elif s == 'RSR':
    print('1')
elif s == 'RRS':
    print('2')
elif s == 'RRR':
    print('3')


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

int main()
{

    int max,a,b,x;

    cin >> a >> b;

    x = a+b;
    max = x;

    x = a-b;
    if(x>max)
        max = x;

    x = a*b;
    if(x>max)
        max = x;

    cout << max;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) throws Exception {
		
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String boxstr[] = new String[4];
        int ans = 0;
        
        for(int i = 0;i<4;i++){
        	
            boxstr[i] = String.valueOf(line.charAt(i));
            
            if(boxstr[i].equals("+")){
            	ans ++;
            }else{
            	ans --;
            }
        	
        }
        
        System.out.println(ans);
        
        
	}
}

Measured memory_bytes: 20820
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {
  
  int N;
  cin >> N;
  vector<string> S(N);
  rep(i,N) cin >> S[i];

  int ans = 0;
  rep(A,N) {
    bool flag = true;
    for (int i = 1; i < N; i++) {
      for (int j = 0; j < i; j++) {
        if (S[(A + i) % N][j] != S[(A + j) % N][i]) flag = false;
      }
    }
    if (flag) ans += N;
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> vec(n);
    for (int i=0; i<n; i++){
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end(), greater<int>());
    int ans = 0;
    
    for (int i=0; i<n-1; i+=2) {
        ans += vec.at(i) - vec.at(i+1);
    }
    if (vec.size() % 2 != 0) {
        ans += vec.at(n-1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;int n,m,l,x,i,a[1<<18];main(){cin>>n>>m;for(;i<2*n;i++)cin>>a[i];sort(a,a+2*n);for(i--;i>l;i--){while(a[i]+a[l]<m&&l<i-1)l++;if(a[i]+a[l]>=m){a[i]-=m;l++;}}sort(a,a+2*n);for(i=0;i<n;i++)x=max(x,a[i]+a[2*n-i-1]);cout<<x;}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;

int main()
{
	fastio;
	lli n,i;
	cin>>n;
	lli a[n];
	for(i=0;i<n;i++)
		cin>>a[i];
	lli ans=0;
	for(i=0;i<n;i++)
		if(a[i]==ans+1)
			ans++;
	if(ans==0)
		cout<<-1;
	else
		cout<<n-ans;
	return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(void){
  int num;
  cin >> num;
  vector<int> longs(num);
  for(int i = 0;i < num; i ++){
    cin >> longs[i];
  }
  sort(longs.begin(),longs.end());
  int ans = 0;
  for(int i = 0;i < num; i ++){
    for(int j = 0;j < i; j ++){
      for(int k = 0;k < j;k ++){
        if(longs[i] < longs[j] + longs[k] and longs[i] != longs[j] and longs[j] != longs[k]){
          ans ++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632