akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair <ll , int> pll;
typedef vector <ll> vll;
typedef pair <pll,ll> p3l;
#define pb push_back
#define X first
#define Y second
#define mkp make_pair
#define smax(a,b) a=max(a,b)
#define ER(x) cout<<#x<<" "<<x<<"\n";
#define smin(a,b) a=min(a,b)
#define SZ(s) (ll)((s).size())
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define RET(x) {cout<<x<<'\n';} //return 0;}
#define RETD(x) {cout << fixed << setprecision(15) << x <<'\n';}
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
const ll maxn=2e5+10,M=4e3+10,SQ=360,bghs=1e9+7,inf=1e18+15,LG=22,I=2e3+5;
ll n,dp[M][M],fac[4*M];
pll ab[maxn];
ll pw(ll x,ll n=bghs-2)
{
    if (n==0) return 1;
    ll res=pw(x,n/2);
    res*=res; res%=bghs;
    if (n%2) res*=x,res%=bghs;
    return res;
}
ll C(ll i,ll j)
{
    return (((fac[i]*pw(fac[j]))%bghs)*pw(fac[i-j]))%bghs;
}
int main()
{
    IOS; cin>>n;
    For(i,0,n) {cin>>ab[i].X>>ab[i].Y;dp[I-ab[i].X][I-ab[i].Y]++;}
    For(i,1,M) For(j,1,M) dp[i][j]+=(dp[i-1][j]+dp[i][j-1]),dp[i][j]%=bghs;
    ll ans=0;
    fac[0]=1;
    For(i,1,4*M) fac[i]=(i*fac[i-1])%bghs;
    For(i,0,n)
    {
        ans=(ans+dp[I+ab[i].X][I+ab[i].Y])%bghs;
        //ER(dp[I-ab[i].X][I-ab[i].Y]);
        ans=(ans-C(2*(ab[i].X+ab[i].Y),2*ab[i].X))%bghs;
    }
    cout<<(((ans+bghs)%bghs)*(ll)(5e8 + 4))%bghs<<'\n';
}


Measured memory_bytes: 129152
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>
#define rep(i,n) for(int i=0; i<n; i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

int main(){
	ll N,M;
	cin >> N >> M;
	vll A(M);
	ll sum=0;
	rep(i,M){
		cin >> A[i];
		sum+=A[i];
	}

	ll ans = N-sum;
	if(ans<0) ans = -1;

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

Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

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

    int ans = 0;
    int temp = 0;
    for (auto c : S) {
        if (c == 'A' || c == 'C' || c == 'G' || c == 'T') {
            ++temp;
        }
        else {
            temp = 0;
        }

        if (ans < temp) {
            ans = temp;
        }
    }

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


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

using Int = __int128_t;
Int abs128(Int val){return val<0?-val:val;}

ostream &operator<<(ostream &os,Int val){
  if(ostream::sentry(os)){
    __uint128_t tmp=abs128(val);
    char buf[64];
    char *d=end(buf);
    do{
      --d;
      *d=char(tmp%10+'0');
      tmp/=10;
    }while(tmp);
    if(val<0) *--d='-';
    Int len=end(buf)-d;
    if(os.rdbuf()->sputn(d,len)!=len){
      os.setstate(ios_base::badbit);
    }
  }
  return os;
}

istream &operator>>(istream &is,Int &val){
  string s;
  is>>s;
  val=0;
  for(Int i=0;i<(Int)s.size();i++)
    if(isdigit(s[i])) val=val*10+s[i]-'0';
  if(s[0]=='-') val*=-1;
  return is;
}



template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,a;
  cin>>n>>a;
 
  
  Int ans=n;
  for(Int i=1;i<100;i++){
    auto calc2=[&](Int x){
      vector<Int> v(i,x/i);
      for(Int j=0;j<x%i;j++) v[j]++;
      Int s=1;
      for(Int j=0;j<i;j++){
	if(s<(n+v[j]-1)/v[j]) s*=v[j];
	else s=n;
	if(s>=n) break;
      }
      return (n+s-1)/s;
    };
    
    auto calc=[&](Int x){
      if(x<0) return ans;
      return i*a+x+calc2(x);
    };
    
    auto best=[&](Int x){
      if(x<0) return x;
      Int l=0,r=x-2*i+1;
      Int v=calc2(x);
      while(l+1<r){
	Int m=(l+r)>>1;
	if(v==calc2(x-m)) l=m;
	else r=m;
      }
      return x-l;
    };
    
    auto next=[&](Int x)->Int{
      if(x<0) return x;
      Int l=0,r=1e18;
      Int v=calc2(x);
      if(v==calc2(x+r)) return -1;
      while(l+1<r){
	Int m=(l+r)>>1;
	if(v==calc2(x+m)) l=m;
	else r=m;
      }
      //assert(best(x+r)==x+r);
      return x+r;
    };
    
    Int l=i*2,r=1e18;    
    while((l+1<r)&&(calc2(r)+1<calc2(l))){
      //cout<<l<<" "<<calc(l)<<endl;
      //cout<<r<<" "<<calc(r)<<endl;
      l=best(l);
      r=best(r);
      chmin(ans,calc(l));
      chmin(ans,calc(r));
      Int m=best((l+r)>>1);
      Int t=next(m);
      chmin(ans,calc(m));
      chmin(ans,calc(t));
      if(calc2(t)+(t-m)==calc2(m))
	for(Int j=m+1;calc2(j)<calc2(j-1);j++) chmin(ans,calc(j));
      
      //cout<<i<<":"<<m<<" "<<t<<":";
      //cout<<calc2(t)<<" "<<calc2(m)<<":"<<calc(m)<<" "<<calc(t)<<endl;    
      if(calc2(t)+(t-m)<calc2(m)) l=m;
      else r=m;
    }
    l=best(l);
    r=best(r);
    chmin(ans,calc(l));
    chmin(ans,calc(r));
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);

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


//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}


////////////////////////////////////////////////////////////////////

int main() {
char kk;
cin>>kk;
char kt=(char)(kk+1);
cout<<kt<<endl;
return 0;


}




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

#define rep(i, e) for( int i = 0; i < e; i++ )
#define eps 1e-10
typedef vector<int> vec;

int main(){
    int N, M = 256;
    while( cin >> N, N){
        vec I(N);
        rep(i, N) cin >> I[i];
        int S, A, C;
        double H = 1000000;
        rep(s, 16){
            rep(a, 16){
                rep(c, 16){
                    int R = s, O, x[256] = {0};
                    //O[0] = ( I[0] + R[0] ) % M;
                    double h = 0;//-( O[0] / N ) * log(O[0] / N);
                    rep(i, N){
                        R = (a*R+c) % M;
                        O = (I[i] + R) % M;
                        x[O]++;
                    }
                    rep(i, M){
                        if( !x[i] ) continue;
                        double t = 1.0 * x[i] / N;
                        h -= (t * log(t));
                    }
                    if( h+eps < H ){
                        H = h;
                        S = s;
                        A = a;
                        C = c;
                        //cout << H << ' ' << s << ' ' << a << ' ' << c << endl;
                    }
                }
            }
        }
        cout << S << ' ' << A << ' ' << C << endl;
    }
}

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

int main() {
    int a, b;
    cin >> a >> b;

    if (a < b) {
        cout << "a < b" << endl;
    } else if (a > b) {
        cout << "a > b" << endl;
    } else if (a == b) {
        cout << "a == b" << endl;
    }
    return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#define N 10000
using namespace std;
int n,m;
string s;
char p[N];

int main()
{
    int l=0,r=0;
    cin>>n;
    cin>>s;
    int tmp=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]==')')tmp++;
        else tmp--;
        l=max(l,tmp);
    }
    tmp=0;
    for(int i=n-1;i>=0;i--)
    {
        if(s[i]=='(')tmp++;
        else tmp--;
        r=max(r,tmp);
    }
    for(int i=1;i<=l;i++)cout<<"(";
    cout<<s;
    for(int i=1;i<=r;i++)cout<<")";
}
/*
 5
 1 1 1
 111
 3 1 8
 1
 2
 4
 1 2
 2 3
 3 2 10
 4 7
 8 9
 2 3
 1 2
 2 3
 4 2 99
 0 1
 0 1
 0 1
 0 0
 4 1
 2 4
 4 3
 4 3 99
 0 1 0
 0 1 0
 0 1 0
 0 0 0
 4 1
 2 4
 4 3
 */


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define lli long long int
#include<vector>
int main(){
  lli n,t,a,x,j=0;
  cin>>n;
  cin>>t>>a;
  lli k=1<<30,z;
  for(lli i=0;i<n;i++){
    cin>>x;
    z=(1000*t)-(6*x)-(1000*a);
    if(abs(z)<k){
      j=i;
      k=abs(z);
    }
  }
  cout<<j+1;
  return 0;
}

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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> time;
  string ans = "Yes";

  REP(i,n){
    int a,b;
    cin >> a >> b;
    time.pb(make_pair(b,a));
  } 

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

  int now = 0;
  REP(i,n){
    now += time[i].second;
    int due = time[i].first;
    if(due < now) ans = "No";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}


int main(){
	string s;
	cin>>s;
	while(s!="ABC"){
		if(s.substr(0,3)=="ABC" && s.substr(s.size()-3,3)=="ABC"){
			cout<<"No"<<endl;
			return 0;
		}
		int a=count(all(s),'A');
		int b=count(all(s),'B');
		if(a==0 or b==0 or a+b==s.size()){
			cout<<"No"<<endl;
			return 0;
		}
		string re="B";
		if(s.substr(0,3)=="ABC"){
			re="A";
		}else if(s.substr(s.size()-3,3)=="ABC"){
			re="C";
		}
		if(s==regex_replace(regex_replace(s,regex("ABC"),re),regex(re),"ABC")){
			s=regex_replace(s,regex("ABC"),re);
		}else{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}



Measured memory_bytes: 3352
from itertools import permutations
from math import factorial

n = int(input())
xys = [tuple(map(int, input().split())) for _ in range(n)]

k = factorial(n)

ret = 0
for perm in permutations(xys):
    a, b = perm[0]
    for x, y in perm:
        ret += (((x - a) ** 2 + (y - b) ** 2) ** 0.5)
        a, b = x, y
print(ret / k)


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

int main(){
  int N;
  cin>>N;
  set<int> A;
  int k=0;
  for(int i=0;i<N;i++){
    int j;
    cin>>j;
    if(j<3200)
      A.insert(j/400);
    else
      k++;
  }
  cout<<max(1,(int)A.size())<<' '<<(int)A.size()+k<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
#include <functional>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define MAX 1000001

void _main(){
    vector<ll> out;
    ll a,b,c,x,y; cin >> a>> b>> c>> x>> y;
    c*=2;
    out.push_back(a*x+b*y);
    if(x>y) {
        out.push_back(c*y+a*(x-y));
        out.push_back(c*x);
    }
    else {
        out.push_back(c*x+b*(y-x));
        out.push_back(c*y);
    }
    cout << *min_element(ALL(out)) << endl;
    return;
}
int main() {
    cout << fixed << setprecision(10);
    _main();
    return 0;
}
    

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
  for (T &x : vec)
    is >> x;
  return is;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  int n;
  cin >> n;

  vector<pair<int, int>> v(n);
  REP(i, n) cin >> v[i].fst >> v[i].snd;

  map<pair<int, int>, int> m;
  REP(i, n) FOR(j, i + 1, n) {
    m[make_pair(v[j].fst - v[i].fst, v[j].snd - v[i].snd)]++;
    m[make_pair(v[i].fst - v[j].fst, v[i].snd - v[j].snd)]++;
  }

  int mm = 0;
  for (auto a : m) {
    mm = max(mm, a.snd);
    //    cout << a.fst.fst << " " << a.fst.snd << " : " << a.snd << endl;
  }

  cout << n - mm << endl;

  return 0;
}


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

int main()
{
  string s;
  string t;
  cin >> s >> t;
  int cnt = 0;
  for (int i = 0; i < 3; i++) {
    if (s.at(i) == t.at(i)) {
      cnt++;
    }
  }
  cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 256
def solve():
    A_yen, B_yen, AB_yen, A_mai, B_mai = list(map(int, input().split()))
    AB_average = (A_yen + B_yen)/2
    if (AB_average > AB_yen):
        if(2*AB_yen >= A_yen and 2*AB_yen >= B_yen):
            kakaku = AB_yen*2*min(A_mai, B_mai)
            if(A_mai > B_mai):
                kakaku += A_yen * (A_mai - min(A_mai, B_mai))
            else:
                kakaku += B_yen * (B_mai - min(A_mai, B_mai))
            print(kakaku)
        elif(2*AB_yen < A_yen and 2*AB_yen >= B_yen):
            kakaku = AB_yen*2*min(A_mai, B_mai)
            if(A_mai > B_mai):
                kakaku += 2*AB_yen * (A_mai - min(A_mai, B_mai))
            else:
                kakaku += B_yen * (B_mai - min(A_mai, B_mai))
            print(kakaku)
        elif(2*AB_yen >= A_yen and 2*AB_yen < B_yen):
            kakaku = AB_yen*2*min(A_mai, B_mai)
            if(A_mai > B_mai):
                kakaku += A_yen * (A_mai - min(A_mai, B_mai))
            else:
                kakaku += 2*AB_yen * (B_mai - min(A_mai, B_mai))
            print(kakaku)
        elif(2*AB_yen < A_yen and 2*AB_yen < B_yen):
            kakaku = AB_yen*2*min(A_mai, B_mai)
            if(A_mai > B_mai):
                kakaku += 2*AB_yen * (A_mai - min(A_mai, B_mai))
            else:
                kakaku += 2*AB_yen * (B_mai - min(A_mai, B_mai))
            print(kakaku)
    else:
        kakaku = A_yen * A_mai + B_yen * B_mai
        print(kakaku)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 62116
cnt=0
b=1
N=int(input())
A=input().split()

A=[int(A[j]) for j in range(N)]

while b==1:
  for i in range(N):
    if A[i]%2==0:
      A[i]=A[i]/2
    else:
      b=0
      break
  if b==1:
    cnt+=1     
  else:
    break
print(cnt)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int N; cin >> N;
  string s;
  unordered_map<string, int> cnt;
  rep(i,N){
    cin >> s;
    sort(all(s));
    cnt[s]++;
  }

  ll retval = 0;
  for (auto p:cnt){
    ll n = p.second;
    retval += n*(n-1)/2;
  }

  cout << retval << endl;


  // cout << fixed << setprecision(10);
  
  return 0;
}



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

int w,h,a[20][20];
int dp[2][1<<20];

void solve(){
  fill(dp[0],dp[2],0);
  
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      for(int k=0;k<(1<<w);k++){
	int newbit = (k<<1)&((1<<w)-1);

	if((j == 0 || (k & 1) == 0) && (i == 0 || (k & (1 << (w-1))) == 0)){
	  dp[1][newbit|1] = max(dp[1][newbit|1], dp[0][k] + a[i][j]);
	}

	dp[1][newbit] = max(dp[1][newbit], dp[0][k]);
      }

      for(int k=0;k<(1<<w);k++){
	dp[0][k] = dp[1][k];
	dp[1][k] = 0;
      }
    }
  }

  int ans = 0;
  for(int i=0;i<(1<<w);i++) ans = max(ans, dp[0][i]);
  cout << ans << endl;	
}

int main(){
  int T;
  cin >> T;
  for(int t=1;t<=T;t++){
    cin >> w >> h;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	cin >> a[i][j];

    cout << "Case " << t << ": " << flush;
    solve();
  }
}

Measured memory_bytes: 9352
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 基本はdouble
//map<キー,値> p は辞書。p[キー] = 値
#include <bits/stdc++.h>
#define ALL(a) (a).begin(),(a).end()
#define rep(i,N) for(int i = 0; i < N;i++)
#define ll long long int
using namespace std;

// Nの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}   // 


int main() {
	ll N, K; cin >> N >> K;

	ll d = dig(N, K);

	cout << d << endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused_macros, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap};

// Main
fn main(){
    input!{
        a: u32,
        b: u32,
        c: u32,
        d: u32,
    }
    println!("{}", max(a*b,c*d));
}




Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <cmath>

struct  Vector {
    double x = 0, y = 0;
    Vector(int _x, int _y) : x(_x), y(_y) {}
    Vector(double _x, double _y) : x(_x), y(_y) {}

    double dot(const Vector &r) const {
        return x * r.x + y * r.y;
    }
    
    double cross(const Vector &r) const {
        return x * r.y - y * r.x;
    }

    double length() const {
        return sqrt(x * x + y * y);
    }

    Vector  operator +  (const Vector &r) const {
        return Vector(x + r.x, y + r.y);
    }
    Vector& operator += (const Vector &r) {
        x += r.x, y += r.y;
        return *this;
    }

    Vector  operator -  () const {
        return Vector(-x, -y);
    }

    Vector  operator -  (const Vector &r) const {
        return *this + -r;
    }
    Vector& operator -= (const Vector &r) {
        x -= r.x, y -= r.y;
        return *this;
    }

    Vector  operator *  (double k) const {
        Vector tmp = *this;
        tmp.x *= k, tmp.y *= k;
        return tmp;
    }

    Vector& operator *= (double k) {
        x *= k, y *= k;
        return *this;
    }

    void unitise() {
        double len = length();
        x /= len, y /= len;
    }
};
typedef Vector Point;

Vector operator * (double k, const Vector & r) {
    return r * k;
}
using namespace std;


int main() {
    // freopen("in", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int xp1, yp1, xp2, yp2, q, xp, yp;
    cin >> xp1 >> yp1 >> xp2 >> yp2 >> q;
    Vector p12(xp2 - xp1, yp2 - yp1);
    p12.unitise();
    while (q--) {
        cin >> xp >> yp;
        Vector p1p(xp - xp1, yp - yp1);
        double d = p1p.dot(p12);
        Vector ans = Vector(xp1, yp1) + d * p12;
        cout << fixed << setprecision(8) << ans.x << ' ' << ans.y << '\n';
    }
    return 0;
}


Measured memory_bytes: 3300
N = int(input())
P = list(map(int,input().split()))
P_max = []
P_min = []

for i in range(N):
  if not P_max:
    P_max.append(P[0])
    P_min.append(P[0])
  else:
    P_max.append(max(P_max[-1], P[i]))
    P_min.append(min(P_min[-1], P[i]))
    
ans = 0
for i in range(N):
  if P[i] <= P_max[i] and P[i] <= P_min[i]:
    ans += 1
    
print(ans)

Measured memory_bytes: 24744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n), cnt(n, 0);
  REP(i, n) {
    cin >> a[i];
    a[i]--;
    cnt[a[i]]++;
  }
  ll sum = 0;
  REP(i, n) { sum += cnt[i] * (cnt[i] - 1) / 2; }
  REP(i, n) {
    ll t = cnt[a[i]];
    cout << sum - (t * (t - 1) / 2 - (t - 1) * (t - 2) / 2) << endl;
  }
}

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

#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) \
  for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int;  // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9) + 7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
const double PI = acos(-1);

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    pair<ll, ll> a = make_pair(i, 0);
    while ((n % i) == 0) {
      n /= i;
      a.second += 1;
    }
    p.push_back(a);
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
  ll b = MOD, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0) {
    u += MOD;
  }
  return u;
}
// 順列
ll permutation(const ll n, const ll m) {
  ll result = 1;
  for (ll i = n; i > n - m; i--) {
    result = (result * i) % MOD;
  }
  return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
  if (x == 0) return 1;
  ll res = repeat_square(n, x / 2);
  res = res * res % MOD;
  if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ nCm
ll combination(ll n, ll m) {
  ll p = permutation(n, m);
  ll div = 1;
  for (ll i = 2; i <= m; i++) {
    div = (div * i) % MOD;
  }
  return (p * modinv(div)) % MOD;
}

// アルファベットの取得
string get_alphabet(ll n) {
  n--;
  return string(1, 'a' + (n % 26));
}

int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;

  vector<P> n;
  rep (i, K+1) {
    P p = make_pair(K - i, i);
    n.push_back(p);
  }

  rep(i, n.size()) {
    int b = B, c = C;
    P q = n[i];
    rep (j, q.first) {
      b *= 2;
    }
    rep(j, q.second) {
      c *= 2;
    }

    if (c > b && b > A && c > A) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

int yp=0;
int main()
{
	string S;
	cin >> S;
	
	int A = 0;
	for (int i = 0;i < S.size();i++) {
		if (S[i] == 'g'&&A>0) {
			A--;
			yp++;
		}
		else if (S[i] == 'g'&&A == 0) {
			A++;
		}
		else if (S[i] == 'p'&&A > 0) {
			A--;
		}
		else if (S[i] == 'p'&&A == 0) {
			A++;
			yp--;
		}
	}
	cout << yp << endl;
}


Measured memory_bytes: 512
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	X := nextInt()
	A := nextInt()
	B := nextInt()

	fmt.Println((X - A) % B)
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(i=0; i<n; i++)

int main(void)
{
	int i;
	char a[4][10]={"Sunny", "Cloudy", "Rainy", "Sunny"};
	char b[10];
	scanf("%s", b);
	rep(i,3){
		if(strcmp(b,a[i])==0){
			printf("%s", a[i+1]);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Linq;

namespace ABC091
{
    class Program
    {
        static void Main(string[] args)
        {
            //問題1
            int[] input = new int[3];
            input = Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x)).ToArray();

            if (input[0] + input[1] >= input[2])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}


Measured memory_bytes: 13268
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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 INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(b-a+1>2*c){
  rep(i,c)
    out(a+i);
  rep(i,c)
    out(b+i-c+1);
  }
  else{
  rep(i,b-a+1)
    out(a+i);
  }
}


Measured memory_bytes: 256
def func():
    S = input()

    target = ["A", "G", "C", "T"]
    mx = 0
    count = 0
    for ch in S:
        if ch in target:
            count += 1
        else:
            mx = max(mx, count)
            count = 0
    
    mx = max(mx, count)
    print(mx)


if __name__ == '__main__':
    func()


Measured memory_bytes: 38256
n=int(input())
t,a=map(int,input().split())
li = list(map(int,input().split()))

listT=[0]*n
for i in range(n):
  listT[i]=t-0.006*li[i]
#print(listT)
min=abs(listT[0]-a)
#print(listT[0]-a)
#print(min)
ans=1
for i in range(n):
  if min>abs(a-listT[i]):
    min=abs(a-listT[i])
    ans=i+1

print(ans)

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

int main() {
	int N;
	cin >> N;
	vector<int> d(N);
	vector<int> D;
	for (int i=0; i<N; i++) {
		cin >> d.at(i);
	}
	int j=0;
	while (d.size() > 0) {
		vector<int> tmp;
		D.push_back(d.at(0));
		//cout << "d:"<< d.at(0) << endl;
			j=0;
			while (j < d.size()) {
					if (d.at(0) != d.at(j)) {
						tmp.push_back(d.at(j));
						//cout << "dpush:"<< d.at(j) << endl;
					}
				j++;
			}
		d = tmp;
		//cout << "D.size:" << D.size() << endl;
		//cout << "d.size:" << d.size() << endl;
	}
	cout << D.size() << endl;
}

Measured memory_bytes: 384
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;
 
auto solve(string s_)
{
    auto Nx = s_.split.map!(to!long)();
    immutable N=Nx[0], x=Nx[1];
    auto as = readln.split.map!(to!long).array();
    long m=sum(as);
    foreach(k;1..N)
    {
        auto dp = new long[N];
        foreach(i;0..N) dp[i]=min(as[i],as[(i-1+N)%N]);
        m=min(m,sum(dp)+x*k);
        swap(dp,as);
    }
    return m;
}

void main(){ for(string s; (s=readln.chomp()).length;) writeln(solve(s)); }

Measured memory_bytes: 4348
r, c = list(map(int, input().split()))
A = []
for i in range(r):
    A.append(list(map(int, input().split())))
    A[i].append(sum(A[i]))
A.append([])
for j in range(c):
    A[r].append(sum(A[i][j] for i in range(r)))
A[r].append(sum(A[r]))
for i in range(r + 1):
    print(" ".join(list(map(str, A[i]))))

Measured memory_bytes: 7840
#!/usr/bin/env python3
import sys

import string
digs = string.digits + string.ascii_letters


def conv(num,b):
    convStr = "0123456789"
    if num<b:
        return convStr[num]
    else:
        return conv(num//b,b) + convStr[num%b]


def solve(N: int, K: int):
    print(len(conv(N,K)))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 4084
import bisect
def main() :
    N = int(input())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
    C = list(map(int,input().split()))
    A.sort()
    B.sort()
    C.sort()
    answer = 0
    for b in B :
        i = bisect.bisect_left(A,b)
        j = bisect.bisect_right(C,b)
        if i > 0 and j != len(C) :
            answer += i * (N-j)
    print(answer)
main()


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

int main()
{
    const ll MOD = 1e9+7;
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    
    sort(a.begin(),a.end());

    if(k == 1) {
        cout << 0 << endl;
        return 0;
    }
    if(n == 2 || n == k) {
        cout << a.back()-a.front() << endl;
        return 0;
    }

    // x^y % m
    auto mpow = [](ll x, ll y, ll m)
    {
        ll ret = 1;
        while(y!=0)
        {
            if(y&1) ret = (ret*x) % m;
            x = (x*x) % m;
            y = y >> 1;
        }
        return ret;
    };
    vector<ll> fac(n, 1); // n! % MOD
    vector<ll> finv(n, 1); // 1/k! % MOD = k!^(MOD-2) % MOD
    for(int i=0;i<n-1;++i)
    {
        fac[i+1] = (fac[i]*(i+1)) % MOD;
        finv[i+1] = (finv[i]*mpow(i+1, MOD-2, MOD)) % MOD;
    }

    vector<ll> cs(n+1, 0);
    rep2(i,k-2,n-1) {
        ll kf_inv = (finv[i-k+2]*finv[k-2]) % MOD; // 1/{(n-k)!*k!} % MOD
        ll comb = (fac[i]*kf_inv) % MOD; // nCk = n!/{(n-k)!*k!}
        cs[i-k+3] = (cs[i-k+2] + comb) % MOD; // sum(jCk-2)
    }
    
    ll ans = 0;
    rep2(i,k-1,n) {        
        ans += (cs[i-k+2]*a[i]) % MOD;
        ans %= MOD;
    }
    rep2(i,0,n-k+1) {
        ans -= (cs[n-k-i+1]*a[i]) % MOD;
        if(ans < 0) ans += MOD;
        ans %= MOD;
    }

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

Measured memory_bytes: 3328
n = int(input())
s = input()
maxnum = 0
for i in range(1,n):
    num = 0
    s1 = set(s[0:i])
    s2 = set(s[i::])
    for c in s1:
        if c in s2:
            num += 1
    if maxnum < num:
        maxnum = num
print(maxnum)

Measured memory_bytes: 3060
def dfs cx, cy, lines, visited
  return 0 if visited.include? [cx, cy]
  visited << [cx, cy]

  # p [cx, cy]
  # p [lines[cy][cx + 1], lines[cy][cx - 1], lines[cy + 1][cx], lines[cy - 1][cx]]
  res = 1
  res += dfs cx + 1, cy, lines, visited if lines[cy][cx + 1] == "."
  res += dfs cx - 1, cy, lines, visited if lines[cy][cx - 1] == "."
  res += dfs cx, cy + 1, lines, visited if lines[cy + 1][cx] == "."
  res += dfs cx, cy - 1, lines, visited if lines[cy - 1][cx] == "."

  res
end

loop do
  w, h = gets.split.map(&:to_i)
  break if w == 0
  x = 0
  y = 0
  lines = [["#"] * (w + 2)] # ??????
  1.upto(h) do |i|
    line = "##{gets.chomp}#".split "" # ??????
    idx = line.index("@")
    if idx
      line[idx] = "."
      x = idx
      y = i
    end
    lines << line
  end
  lines << ["#"] * (w + 2) # ??????

  # require "pp"
  # pp lines
  # p [[x, y]]
  puts dfs x, y, lines, []
end

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

int main (){
    int n;
	while(cin>>n && n){
		vector<int> v(n);
		int ans=100000000;
		for(int i=0;i<n;i++)cin>>v[i];

		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i!=j)ans=min(ans,abs(v[i]-v[j]));
			}
		}
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 3028
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.Integer.parseInt;

/**
 * The Oldest Site
 */
public class Main {

	static final int MAX = 5000;

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == 0) break;

			int[][] points = new int[n][2];
			boolean[][] grid = new boolean[MAX + 1][MAX + 1];


			int[] pointsX = new int[MAX + 1];
			int[] pointsY = new int[MAX + 1];
			Arrays.fill(pointsX, -1);
			Arrays.fill(pointsY, -1);

			for (int i = 0; i < n; i++) {
				line = br.readLine();
				int x, y;
				x = parseInt(line.substring(0, line.indexOf(' ')));
				y = parseInt(line.substring(line.indexOf(' ') + 1));

				points[i][0] = x;
				points[i][1] = y;
				grid[y][x] = true;
			}

			//solve
			int max = 0;
			for (int i = 0; i < n; i++) {
				for (int j = i + 1; j < n; j++) {

					int p1x, p1y, p2x, p2y, dx, dy;
					p1x = points[i][0];
					p1y = points[i][1];
					p2x = points[j][0];
					p2y = points[j][1];
					dx = p1x - p2x;
					dy = p1y - p2y;

					//
					{
						int p3x, p3y, p4x, p4y;
						p3x = p1x - dy;
						p3y = p1y + dx;
						p4x = p2x - dy;
						p4y = p2y + dx;
						if (0 <= p3x && p3x <= MAX
								&& 0 <= p3y && p3y <= MAX
								&& 0 <= p4x && p4x <= MAX
								&& 0 <= p4y && p4y <= MAX
								&& grid[p3y][p3x]
								&& grid[p4y][p4x]) {
							max = Math.max(max, dx * dx + dy * dy);
						}
					}

					//
					{
						int p3x, p3y, p4x, p4y;
						p3x = p1x + dy;
						p3y = p1y - dx;
						p4x = p2x + dy;
						p4y = p2y - dx;
						if (0 <= p3x && p3x <= MAX
								&& 0 <= p3y && p3y <= MAX
								&& 0 <= p4x && p4x <= MAX
								&& 0 <= p4y && p4y <= MAX
								&& grid[p3y][p3x]
								&& grid[p4y][p4x]) {
							max = Math.max(max, dx * dx + dy * dy);
						}
					}
				}
			}
			System.out.println(max);
		}//end while
	}//end main
}

Measured memory_bytes: 127080
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer n;
  for(n=nil->next; n!=nil; n=n->next){
    if(key==n->key)return n;
  }
  return NULL;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  NodePointer n;
  if(nil->next==nil)return;
  deleteNode(nil->prev);
}

void delete(int key){
  NodePointer n;
  if(listSearch(key)==NULL)return;
  else n = listSearch(key); 
  deleteNode(n);
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  
  x->prev = nil;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;

}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



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

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S; 
    vector<int> min_max_keta(20,-1);
    for(int i=0; i<(int)S.size(); i++){
        int k = S.at(i) - '0';
        if(min_max_keta.at(2*k) == -1){
            min_max_keta.at(2*k) = 1;
        }
        else{
            min_max_keta.at(2*k+1) = i;
        }
    }
    int ans = 0;
    for (int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            for(int k=0; k<10; k++){
                /*
                if(min_max_keta.at(2*i)==-1||min_max_keta.at(2*j)==-1||min_max_keta.at(2*k)==-1){
                    continue;
                }
                if(min_max_keta.at(2*i) < min_max_keta.at(2*k+1)){
                    if(min_max_keta.at(2*j+1)<min_max_keta.at(2*i)){
                        continue;
                    }
                    if(min_max_keta.at(2*k+1)<min_max_keta.at(2*j)){
                        continue;
                    }
                    cout << i << j << k << endl;
                    ans++;
                }
                */
               int check[3] = {i, j, k};
               int f = 0;
               for(int l=0; l<N; l++){
                   if (S.at(l) == check[f] + '0') f++;
                   if (f==3) break;
               }
               if(f == 3) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            int r = sc.nextInt();
            if(n==0&&r==0)break;
            int[] x = new int[n];
            for(int i=0;i<n;i++){
                x[i] = n-i;
            }
            for(int i=0;i<r;i++){
                int p = sc.nextInt();
                int c = sc.nextInt();
                int[] a = new int[n];
                for(int j=0;j<c;j++) {
                    a[j] = x[p-1+j];
                }
                for(int j=0;j<p-1;j++){
                    x[p-2-j+c] = x[p-2-j];
                }
                for(int j=0;j<c;j++){
                    x[j] = a[j];
                }
            }
            System.out.println(x[0]);
        }
    }
}



Measured memory_bytes: 36384
#include <iostream>
using namespace std;
int n;
long long t,x,y;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>t>>x>>y;
		if(t<x+y||(t-x-y)%2!=0){
			cout<<"No"<<endl;
			return 0;
		}
		else continue;
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

using namespace std;

int main(void){
    string S;
    cin>>S;
    int r_num = 0; 
    int b_num = 0;
    for(unsigned int i=0; i<S.length(); i++){
        if(S[i] == '0') r_num++;
        else if(S[i] == '1') b_num++;
        else break;
    }

    if(b_num > r_num)cout<<2*r_num<<endl;
    else cout<<2*b_num<<endl;
}

Measured memory_bytes: 512
x, n = map(int, input().split())
p_lst = list(map(int, input().split()))

ans = 0

big_x = x
sml_x = x

for i in range(100):
    
    if sml_x not in p_lst:
        ans = sml_x
        # print("0")
        break
    elif big_x not in p_lst:
        ans = big_x
        # print("1")
        break
    # else:
    #     continue
    big_x += 1
    sml_x -= 1
print(ans)

Measured memory_bytes: 9188
N, M = map(int, input().split())  # N個の県, M個の市

city_info = []
for i in range(M):  # M個の市の情報
    p, y = map(int, input().split())  # どこの県に属するかの情報p, 誕生した年y
    city_info.append([i+1, p, y, -1])  # 市のインデックス, 属する県, 誕生した年, 何番目に誕生した

city_info = sorted(city_info, key=lambda x: (x[1], x[2]))  # 属する県でソート

# print(city_info)

now_pref = city_info[0][1]

tmp = 0
for i in range(M):
    if city_info[i][1] == now_pref:
        tmp += 1
        city_info[i][3] = tmp
    else:
        tmp = 1
        city_info[i][3] = tmp
        now_pref = city_info[i][1]

city_info = sorted(city_info, key=lambda x: x[0])

# print(city_info)


for i in range(M):
    str_p = str(city_info[i][1])
    str_zyunban = str(city_info[i][3])

    lack_p = 6-len(str_p)
    str_p = '0'*lack_p + str_p

    lack_zyunban = 6-len(str_zyunban)
    str_zyunban = '0'*lack_zyunban + str_zyunban

    print(str_p+str_zyunban)


Measured memory_bytes: 34308
import util.control.Breaks._

object Main extends App {
  val Array(h,w,n) = io.StdIn.readLine().split(' ').map(_.toInt)
  val field = Array.fill(h)(io.StdIn.readLine().toCharArray)
  var start = (0,0)
  breakable {for (j <- 0 until h; i <- 0 until w; if field(j)(i) == 'S') start = (j, i); break}
  val costs = for (g <- 1 to n) yield {
    val heap = collection.mutable.PriorityQueue.empty[((Int, Int), Int)](Ordering.by(-_._2))
    heap.enqueue((start, 0))
    val taken = Array.fill(h)(Array.fill(w)(Int.MaxValue))
    @scala.annotation.tailrec
    def loop(): Int = heap.dequeue() match {
      case ((y, x), cost) if field(y)(x) == (g+48).toChar => start = (y, x); cost
      case ((y, x), cost) =>
        val nextCost = cost + 1
        Seq((y,x-1),(y,x+1),(y-1,x),(y+1,x))
          .withFilter(p => p._1 >= 0 && p._1 < h && p._2 >= 0 && p._2 < w)
          .withFilter(p => (field(p._1)(p._2) != 'X') && nextCost < taken(p._1)(p._2))
          .foreach{p => taken(p._1)(p._2) = nextCost; heap.enqueue((p, nextCost))}
        loop()
    }
    loop()
  }
  println(costs.sum)
}


Measured memory_bytes: 453944
#include <iostream>

int max(int a, int b){
	if(a >= b){
		return a;
	}
	return b;
}

int main()
{
	int K,N;
	std::cin >> K >> N;
	
	int A[N];
	
	std::cin >> A[0];
	int d = A[0];
	for(int i=1;i<N;i++){
		std::cin >> A[i];
		d = max (d, A[i] - A[i-1]);
	}
	
	d = max(d,K+A[0] - A[N-1]);
	
	std::cout << K-d << std::endl;
	
	return 0;
}




Measured memory_bytes: 1024
#include<vector>
#include<queue>
#include<stdio.h>
#include<map>
#include<set>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#define mp make_pair
using namespace std;
typedef long long ll;
inline ll in()
{
    ll res=0,p=1;
    char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') p=-1; c=getchar();}
    while(c>='0'&&c<='9') res=res*10+c-48,c=getchar();
    return p*res;
}
void out(ll x)
{
    if (x>9) out(x/10);
    putchar(x%10+48);
}
void outc(ll x)
{
    if (x<0){
        putchar('-');
        out(-x);
    }else out(x);
    putchar(32);
}
void outn(ll x)
{
    if (x<0){
        putchar('-');
        out(-x);
    }else out(x);
    putchar(10);
}
const int mod = 1e9 + 7, inf = 0x3f3f3f3f;
//const double pi = acos(-1.0);
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};

int gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll quickpow(ll x, int k)
{
    ll res = 1;
    while(k){
        if(k & 1) res = (res * x) % mod;
        k >>= 1, x = (x * x) % mod;
    }
    return res;
}
//ll C(int n, int m){return (fac[n] * quickpow((fac[m] * fac[n - m]) % mod, mod - 2)) % mod;}
//Unaccepted
const int maxn = 1e5 + 10;
int dp[100005];
vector<int> vi;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i){
        int x;
        cin >> x;
        vi.emplace_back(x);
    }
    reverse(vi.begin(), vi.end());
    memset(dp, 0x3f, sizeof(dp));
    for (int x : vi){
        *upper_bound(dp, dp + n, x) = x;
    }
    cout << lower_bound(dp, dp + n, 0x3f3f3f3f) - dp << endl;
	return 0;
}


Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define SZ(i) int(i.size())
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#endif

const int MAXN = 1000006;
const ll MOD = 1000000007;

string str;
bool b[MAXN];
int l[MAXN], r[MAXN], ans[MAXN];
/*********************GoodLuck***********************/
int main () {
    IOS();

    cin >> str;
    int n = SZ(str);

    int lst[2] = {-1, -1};
    REP (i, n) {
        b[i] = str[i] == 'R';
        l[i] = lst[b[i]^1];
        lst[b[i]] = i;
    }

    lst[0] = lst[1] = n;
    for (int i=n-1; i>=0; i--) {
        r[i] = lst[b[i]^1];
        lst[b[i]] = i;

        if (b[i]) {
            ans[(r[i]-i)&1 ? r[i]-1 : r[i]]++;
        } else {
            ans[(i-l[i])&1 ? l[i]+1 : l[i]]++;
        }
    }

    REP (i, n) {
        cout << ans[i] << " \n"[i==n-1];
    }

    return 0;
}


Measured memory_bytes: 11344