akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
//#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}


char s[maxn];
int main(void) {
    FAST_IO;
    
    scanf("%s", s);
    int n = strlen(s);
    deque<char> q;
    for (int i = 0; i < n; i++) {
        q.push_back(s[i]);
    }
    int Q;
    int cnt = 0;
    scanf("%d", &Q);
    while (Q--) {
        int t, f;
        char c[3];
        scanf("%d", &t);
        if (t == 1) {
            cnt++;
        } else {
            scanf("%d %s", &f, c);

            if (f == 1 && (cnt & 1) == 0) q.push_front(c[0]);
            else if (f == 1) q.push_back(c[0]);
            if (f == 2 && (cnt & 1) == 0) q.push_back(c[0]);
            else if (f == 2) q.push_front(c[0]);
        }
    }
    if (cnt % 2) {
        reverse(q.begin(), q.end());
    }
    for (auto & x: q) {
        printf("%c", x);
    }
    puts("");
    
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
            #define ll long long
            #define f   first
            #define s   second
            #define pb          push_back
            #define mod        1000000007
            #define mod1       1000000009
            #define hell        998244353
            #define inf         1000000000000000000LL
            #define pi          3.14159265358979323
            //#define N           100005 
            const int N=200005;
            using namespace std;
            ll n,k,sum,q,res,m,val,ans;
            ll x,y;
            double p;
            ll xx[]={1,0,-1,0};
            ll yy[]={0,1,0,-1};
            void solve()    
            {   
                cin>>n;
                map<pair<ll,ll>,ll> hm;
                for(int i=0;i<n;i++)
                {
                    string s1;
                    cin>>s1;
                    int m=s1.size();
                    ll x=0,cnt=1,y=1;
                    ll c=1;;
                    for(int j=m-1;j>=0;j--)
                    {
                        if(s1[j]=='.') {c=cnt;continue;}
                        x=(s1[j]-'0')*y+x;
                        cnt*=10;
                        y*=10;
                    }
                    ll a=x/(__gcd(x,c));
                    ll b=c/(__gcd(x,c));
                    ll c1=0,c2=0,c3=0,c4=0;
                    while(a%2==0){a/=2;c1++;}
                    while(a%5==0) {a/=5;c2++;}
                    while(b%2==0){b/=2;c3++;}
                    while(b%5==0) {b/=5;c4++;}
                    hm[{c1-c3,c2-c4}]++;
                }
                ll ans=0;
                for(auto x:hm)
                {   ll x1=x.f.f;
                    ll x2=x.f.s;
                    for(auto y:hm)
                    {
                        ll y1=y.f.f;
                        ll y2=y.f.s;
                        if(x1==y1 and x2==y2)
                        {   if(x1+y1>=0 and x2+y2>=0)
                            ans+=(x.s*(x.s-1));
                        }
                        else if(x1+y1>=0 and x2+y2>=0) ans+=(x.s*y.s);       
                    }
                }
                cout<<ans/2;
                


            }
            int main()  
            {   ios_base::sync_with_stdio(false);
                cin.tie(0);cout.tie(0);
                ll t=1;  
                //cin>>t;
                 for(ll i=1;i<=t;i++)
                    solve();
                

            }            


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;cin>>a>>b;a=a-1;b=b-1;
  double n = 1.0;
  n= (n*b)/a;//cout<<n<<endl;
  int n1=b/a;
  if(n1==n){cout<<n1;return 0;}
  cout<<n1+1;
}


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

long l[100][100], r[100][100];
long v[100], s[100];

int main(void) {
    int n,q;
    cin >> n >> q;
    vector<pair<long, pair<long,long>>> v(n);

    for(int i=0; i<n; i++) {
        int s,t,x;
        cin >> s >> t >> x;
        v[i].first = x;
        v[i].second.first = s-x;
        v[i].second.second = t-x;
    }

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


    vector<pair<long,int>> qs(q);
    for(int i=0; i<q; i++) {
        cin >> qs[i].first;
        qs[i].second = i;
    }

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

    vector<long> res(q, -1);
    vector<vector<pair<long,int>>::iterator> skip(q, qs.begin());

    for(int i=0; i<n; i++) {
        long s = v[i].second.first;
        long t = v[i].second.second;

        auto lb = lower_bound(qs.begin(), qs.end(), pair<long,int>(s,-1e9));
        auto ub = lower_bound(qs.begin(), qs.end(), pair<long,int>(t,-1e9));
        for(auto it = lb; it != qs.end() && it < ub; ) {
            if(res[it->second] == -1) res[it->second] = v[i].first;
            auto t = max(it+1, skip[it->second]);
            skip[it->second] = max(skip[it->second], ub);
            it = t;
        }
    }

    for(int i=0; i<q; i++)
        cout << res[i] << endl;

}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str;
cin >> str;
int ans = 700;
if(str[0] == 'o')
{
ans += 100;
}
if(str[1] == 'o')
{
ans += 100;
}
if(str[2] == 'o')
{
ans += 100;
}
cout << ans;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char s[12345]; 
 
int main() {
  cin >> s;
  int n = strlen(s);
  long long ans = 0;
  for(int t = 0; t < (1 << (n-1)); t++){
    long long num = s[0]-'0';
    for(int i = 0; i < n-1; i++){
      if (t & (1 << i)) {
        ans = ans + num;
        num = 0;
      }
      num = num*10 + s[i+1]-'0';
    }
    ans = ans + num;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)
#define all(V) V.begin(), V.end()
using i64 = int_fast64_t;
using P = pair<int,int>;

int main(){
    int N, Q;
    cin >> N >> Q;
    priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> que;

    int s, t, x;
    rep(i,N){
        cin >> s >> t >> x;
        que.push({s-x, x, 1});
        que.push({t-x, x , 0});
    }

    int ans = -1, D;
    set<int> Xs;
    rep(i, Q){
        cin >> D;
        while(!que.empty() && que.top()[0] <= D){
            int t = que.top()[0];
            int x = que.top()[1];
            int is_push = que.top()[2];
            que.pop();

            if(is_push) Xs.insert(x);
            else Xs.erase(x);
        }
        if(Xs.size() == 0) ans = -1;
        else ans = *Xs.begin();

        cout << ans << endl;
    }
}


Measured memory_bytes: 35240
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int (i) = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int (i) = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int (i) = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int (i) = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define Pi 3.1415926535
#define MOD 1000000007;
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << endl;}
void no(){cout << "No" << endl;}

int solve(){
    int k,x; cin >> k >> x;
    if(k*500>=x) yes();
    else no();

    return 0;
}

int main(){
    cin.tie(0);
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


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

#define Mset(s, n)      memset(s, n, sizeof(s))
#define Rp0(i, m)       for(int i = 0; i < m; ++i)
#define Rpd(i, m, l)    for(int i = l; i >= m; --i)
#define Rp1(i ,m)       for(int i = 1; i <= m; i++)
#define All(a)          (a).begin(), (a).end()
#define Lwb             lower_bound
#define Upb             upper_bound
#define Sz(a)           int((a).size())
#define u_map           unordered_map
#define Exist(a, b)     (find(All(a), (b)) != (a).end())
#define Sort(x)         sort(All(x))
#define Gsort(x)        sort(All(x), greater<typeof(*((x).begin()))>())
#define Unique(v)       Sort(v); (v).resize(unique(ALL(v)) - (v).begin())
#define Max(a, b, c)    max(a, max(b, c))

#define fi              first
#define se              second
#define pb              push_back
#define pf              push_front
#define is              insert
#define ooi             INT_MAX
#define ool             LLONG_MAX
#define ll              long long
#define ull             unsigned ll
#define ld              long double
#define pii             pair<int, int>
#define vi              vector<int>
#define vpii            vector<pii>

const ll MOD = (ll) 1e9 + 7;
const ld PI = acos((ld) -1);
inline int Get_bit(int x, int k){return (x >> (k - 1)) & 1;}
inline ll Gcd(ll a, ll b) {ll r; while(b){ r = a % b; a = b; b = r;} return a;}
inline ll Lcm(ll a, ll b) {return a / Gcd(a, b) * b;}
inline ll Pow(ll n, ll k) {ll r = 1; for(; k; k >>= 1, n = n * n % MOD){if(k & 1) r = r * n % MOD;} return r;}
const int base = 311;


const int N = 5e3 + 5;
ll n, m, k, ans, q, s, t;
ll a[N];

void Solve(){
    cin >> n;
    for(int i =1 ; i <= n; i++){
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            ans += a[i] * a[j];
        }
    }
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(6);
    Solve();
}



Measured memory_bytes: 256
#include<stdio.h>

long long int s=1000000007;

long long int factorial(long long int A){
    long long int fact=1,i;
    for(i=1;i<=A;i++){
        fact=(fact*i)%s;
    }
    return fact;
}

int main(){
    long long int N,M,fact_N,fact_M;
    scanf("%lld %lld",&N,&M);
    fact_N=factorial(N);
    fact_M=factorial(M);
    
    if(N-M>1 || N-M<-1){
        printf("0\n");
    }else if(N-M==1 ||N-M==-1){
        printf("%lld\n",(fact_N*fact_M)%s);
    }else{
        printf("%lld\n",(fact_N*fact_M*2)%s);        
    }
    return 0;
}


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


// ローリングハッシュ
// 二分探索で LCP を求める機能つき
struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;

    // construct
    RollingHash(const string &S) {
        int n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }
    
    // get hash of S[left:right]
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }

    // get lcp of S[a:] and T[b:]
    inline int getLCP(int a, int b) const {
        int len = min((int)hash1.size()-a, (int)hash1.size()-b);
        int low = 0, high = len;
        while (high - low > 1) {
            int mid = (low + high) >> 1;
            if (get(a, a+mid) != get(b, b+mid)) high = mid;
            else low = mid;
        }
        return low;
    }
};

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

    // ロリハ
    RollingHash rh(S);

    // 求める
    int res = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            int lcp = rh.getLCP(i, j);
            lcp = min(lcp, j-i);
            res = max(res, lcp);
        }
    }   
        
    cout << res << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_set>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  if(N % 1000 == 0){
    cout << 0 << endl;
  } else {
    cout << 1000 - N % 1000 << endl;
  }
  return 0;
}


Measured memory_bytes: 3636
h1,h2=map(int,input().split())
k1,k2=map(int,input().split())
a,b,c,d=map(int,input().split())

ha, hb,ka,kb = h1*a, h2*b, k1*a, k2*b
h10, h20, k10, k20 = h1//10*c, h2//20*d, k1//10*c, k2//20*d
H, K = ha + hb + h10 + h20, ka + kb + k10 + k20
if H > K:
    print("hiroshi")
elif K > H:
    print("kenjiro")
else:
    print("even")


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    int N; cin >> N;
    int flg = 0;
    for(int i = 1; i <= 9; ++i) {
        for(int j = 1; j <= 9; ++j) {
            if(i*j==N){
                flg = 1;
            }
        }
    }
    Yn(flg);



    return 0;
}


Measured memory_bytes: 256
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

#define MOD 1000000007
ll powmod(ll a,ll b,ll m=MOD){
	ll out=1;
	ll p=a%m;
	while(b){
		if(b&1)out=out*p%m;
		p=p*p%m;
		b>>=1;
	}
	return out;
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	string s;
	cin>>s;
	int t=0;
	int out=0;
	rep(i,s.size())if(s[i]=='1'){
		(out+=powmod(2,t,MOD)*powmod(3,s.size()-i-1,MOD)%MOD)%=MOD;
		t++;
	}
	(out+=powmod(2,t))%=MOD;
	cout<<out<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007 // 10^9+7
#define INF 99999999999 //10^12-1
#define dev 998244353 //tenka1
#define P pair<int,int>
#define F first
#define S second
int n,ans=0;
char s[200000][12];
vector<string>vec;
map<string,int>mp;
int memo[200000];
int tri(int x){
    if(x==1)return x;
    if(memo[x]!=0)return memo[x];
    else return memo[x]=x+tri(x-1);
}
signed main(){
    cin>>n;
    rep(i,n){
        rep(j,10){
            cin>>s[i][j];
        }
        sort(s[i],s[i]+10);
        string t="";
        rep(j,10){
            t=t+s[i][j];
        }
        mp[t]++;
        vec.push_back(t);
    }
    rep(i,n){
        if(mp[vec[i]]>1){
            ans+=tri(mp[vec[i]]-1);
            mp[vec[i]]=0;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 13172
#include <iostream>
#include <string>    
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll n, k, border, x[100008];
ll lala[100008], rara[100008];

int main() {
	cin >> n >> k;
	border = n;
	for(ll i = 1; i <= n; i++){cin >> x[i];}
	for(ll i = 1; i <= n; i++){if(x[i] > 0){border = i-1; break;}}
	
	for(ll i = 1; i <= border; i++){lala[i] = -x[border-(i-1)];}
	for(ll i = 1; i <= n-border; i++){rara[i] = x[border+i];}
	//for(ll i = 1; i <= n-border; i++)cout << rara[i];
	
	lala[0] = 0;
	rara[0] = 0;
	ll ans = 3e8;
	for(ll i = max(k-(n-border), (ll) 0); i <= min(border, k); i++){ans = min(2*lala[i]+rara[k-i], ans);}
	for(ll i = max(k-border, (ll) 0); i <= min(n-border, k); i++){ans = min(2*rara[i]+lala[k-i], ans);}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#!/usr/bin/env python

from collections import deque
import itertools as ite
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

S = raw_input()
if S.count("x") <= 7:
    print "YES"
else:
    print "NO"

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

int main(){
    long long N,M;
    cin >> N >> M;
    if(N > M) swap(N,M);
    if(N == 1 && M == 1){
        cout << 1;
    }else if(N == 1){
        cout << M - 2;
    }else{
        cout << (N - 2) * (M - 2);
    }
    return 0;
}

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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            cout<<x<<"/"<<y<<endl;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
//////////////////////////


int main(){fastio
    string s;cin>>s;
    ll c=0;
    rep(i,0,s.size()-1)if(s[i]=='2')c++;
    cout<<c;
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
    int num[5],i,j,hoge;
    for(i=0;i<5;i++)
        scanf("%d",&num[i]);
    for(i=0;i<4;i++){
        for(j=i+1;j<5;j++){
            if(num[i]<num[j]){
            hoge=num[i];
            num[i]=num[j];
            num[j]=hoge;
            }
        }
    }
    for(i=0;i<4;i++){
        printf("%d ",num[i]);
    }
    printf("%d\n",num[4]);
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
    int x, h;
 
    while(true){
        cin >> x >> h;
        if(x == 0 && h == 0) break;
 
        double S, s1, s2;
        s1 = x * x;
        s2 = x * sqrt(pow(0.5 * x, 2) + pow(h, 2)) * 0.5;
        S = s1 + s2 * 4;
 
        cout << fixed << setprecision(6) << S << endl;
    }
}


Measured memory_bytes: 3264
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long a, b;
  cin >> a >> b;
  long ans = a;
  if (a > b) ans--;
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    HashSet<Integer> set = new HashSet<Integer>();
    for(int i = 0; i < n; i++) {
      int d = sc.nextInt();
      set.add(d);
    }
    System.out.println(set.size());
  }
}

Measured memory_bytes: 21076
//#define _GLIBCXX_DEBUG//実行時、何も出なかったらこれを使う
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>
#include<climits>
#include<limits>//
#include <stdio.h>//
#include<cmath>
#include<iomanip>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

int dy[] = {1,0,-1,0}; //次に行くところ
int dx[] = {0,1,0,-1}; //s上に同じ

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  vector<string> s(n);
  map<string,int> cnt;

  for (int i = 0; i < n; i++){
    cin >> s[i];
    cnt[s[i]] ++;
  }
  
  cout << "AC" << " x " << cnt["AC"] << '\n';
  cout << "WA" << " x " << cnt["WA"] << '\n';
  cout << "TLE" << " x " << cnt["TLE"] << '\n';  
  cout << "RE" << " x " << cnt["RE"] << '\n';

  return 0;
}

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

int main() {
  int N,K;
  cin>>N>>K;
  string S;
  cin>>S;
  if(S[K-1]=='A'){
    S[K-1]='a';
  }
  if(S[K-1]=='B'){
    S[K-1]='b';
  }
  if(S[K-1]=='C'){
    S[K-1]='c';
  }
 cout<<S<<endl; 
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class AGC010A
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var N = NN;
            var AList = NNList(N);
            if (AList.Count(e => e % 2 == 1) % 2 == 1)
            {
                Console.WriteLine("NO");
            }
            else
            {
                Console.WriteLine("YES");
            }
        }
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
}


Measured memory_bytes: 26848
#![allow(unused_imports)]
use std::io::{ self, Write };
use std::str::FromStr;
use std::cmp::{ min, max };
use std::collections::{ BinaryHeap, VecDeque };

#[allow(unused_macros)]
macro_rules! trace {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stderr(), ">>> {} = {:?}", stringify!($var), $var);
    };
    ($($args:expr),*) => { trace!(($($args),*)) }
}

#[allow(unused_macros)]
macro_rules! put {
    ($var:expr) => {
        let _ = writeln!(&mut std::io::stdout(), "{}", $var);
    };
    ($var:expr, $($args:expr),*) => {
        let _ = write!(&mut std::io::stdout(), "{} ", $var);
        put!($($args),*);
    };
}

const M: usize = 1_000_000_007;
use std::ops::Range;
struct BIT { size: usize, array: Vec<i32> }
impl BIT {
    fn new(n: usize) -> BIT {
        BIT  { size: n, array: vec![0; n + 1] }
    }
    fn add(&mut self, idx: usize, w: i32) {
        let mut x = idx + 1;
        while x <= self.size {
            self.array[x] += w;
            let xi = x as i32;
            x += (xi&-xi) as usize;
        }
    }
    fn sum_up(&self, idx: usize) -> i32 { // [0, idx)
        let mut sum = 0;
        let mut x = idx;
        while x > 0 {
            sum += self.array[x];
            let xi = x as i32;
            x -= (xi&-xi) as usize;
        }
        sum
    }
    fn sum(&self, range: Range<usize>) -> i32 {
        self.sum_up(range.end) - self.sum_up(range.start)
    }
}

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut es = BIT::new(n);
    let mut ws = BIT::new(n);
    let cs: Vec<char> = sc.cin::<String>().chars().collect();

    for i in 0..n {
        if cs[i] == 'E' {
            es.add(i, 1);
        } else {
            ws.add(i, 1);
        }
    }

    let mut ans = n as i32;
    for i in 0..n {
        let m =
            if i > 0 { ws.sum(0..i) } else { 0 }
        + if i < n - 1 { es.sum(i+1..n) } else { 0 };
        ans = min(ans, m);
    }

    put!(ans);

}

#[allow(dead_code)]
struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn reserve(&mut self) {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        self.reserve();
        match self.buffer.pop_front().unwrap().parse::<T>() {
            Ok(a) => a,
            Err(_) => panic!("parse err")
        }
    }
}


Measured memory_bytes: 8444
def solve(N, K, ABs):
    counts = {i: 0 for i in range(1, 10 ** 5 + 1)}
    for a, b in ABs:
        counts[a] += b
    s = 0
    for c, count in counts.items():
        s += count
        if K <= s:
            return c


if __name__ == "__main__":
    N, K = tuple(map(int, input().split(" ")))
    ABs = []
    for _ in range(N):
        ABs.append(tuple(map(int, input().split(" "))))
    print(solve(N, K, ABs))


Measured memory_bytes: 28628
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
public:
  ll *fac,*finv,*inv;
  Comb(){
    fac = new ll[1000001];
    finv = new ll[1000001];
    inv = new ll[1000001];
    fac[0] = 1;
    for(int i=1;i<1000001;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000001;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000001;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

ll powmod(ll x,ll n){
  if(n == 0) return 1;
  if(n == 1) return x%MOD;
  if(n%2 == 0){
    ll temp = powmod(x,n/2);
    return (temp*temp)%MOD;
  }
  else{
    ll temp = powmod(x,n/2);
    temp = (temp*temp)%MOD;
    return (temp*x)%MOD;
  }

}

int main(){
   int n,k,c;
   string s;
   cin >> n >> k >> c;
   cin >> s;
   int a[k+1],b[k+1];
   int now = 0;
   int lock = -1;
   int ind = 0;
   while(now != k){
     if(s[ind] == 'x'){
       ind++;
       continue;
     }
     if(lock < ind){
       now++;
       lock = ind+c;
       a[now] = ind;
     }
     ind++;
   }
   now = 0;
   lock = n+1;
   ind = n-1;
   while(now != k){
     if(s[ind] == 'x'){
       ind--;
       continue;
     }
     if(ind < lock){
       now++;
       lock = ind-c;
       b[now] = ind;
     }
     ind--;
   }

   for(int i=1;i<k+1;i++){
     if(a[i] == b[k+1-i]) cout << a[i]+1 << endl;
   }
   return 0;
}


Measured memory_bytes: 3332
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        sc.close();

        for(int i=m/n; i>0; i--){
            if(m%i == 0 && m/i >= n){
                System.out.println(i);
                return;
            }
        }
    }
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	ll N=in<ll>(),K=in<ll>();
	auto A=vecin<ll>(N);
	auto F=vecin<ll>(N);
	sort(ALL(A),greater<ll>());
	sort(ALL(F));

	ll OK=-1,NG=-1;
	REP(i,N){
		OK = max(OK,A[i]*F[i]);
	}
	OK++;
	while(abs(NG-OK)>1){
		ll mid = (OK+NG)/2LL;
		
		ll num=0;
		REP(i,N){
			num += min(A[i],max(0LL,(ll)ceil((A[i]*F[i]-mid)/(double)F[i])));
		}
		if(num<=K){
			OK = mid;
		}
		else{
			NG = mid;
		}
	}
	out(OK);
	return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h> 
#include <set>
 
using namespace std;
 
#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
using vi = vector<int>;
const int MOD = 1e9 + 7;
 
bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; }
    return true;
}
 
int main() {
    int N, M;
    cin >> N >> M;
    bool frag;
    vector<string> A(N);
    vector<string> B(M);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];
    rep(i, N - M+1) {
        rep(j, N - M+1) {
            frag = true;
            rep(k, M) {
                if (A[i + k].substr(j, M) != B[k]) {
                    frag = false;
                    break;
                }
            }
            if (frag)break;
        }
        if (frag) break;
    }
    if (frag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
package main
import (
        "fmt"
)

func main(){
        var avar, bvar,dvar,rvar int
        var fvar float64
        fmt.Scan(&avar)
        fmt.Scan(&bvar)

        fvar = float64(avar)/float64(bvar)
        rvar = avar - int(fvar)*bvar
        dvar = int(fvar)

        fmt.Printf("%d %d %.5f",dvar,rvar,fvar)
}


Measured memory_bytes: 1152
/**
 *     author: qodjf
 *     created: 05.01.2020 01:24:47
 */
#include <bits/stdc++.h>
using namespace std;

string to_string(string s) { return '"' + s + '"'; }

string to_string(const char *s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

bool solve(int N) {
  int sum = 0;
  vector<int> nums;
  for (int i = 2;; i++) {
    if (i % 2 == 0 || i % 3 == 0) {
      nums.push_back(i);
      sum += i;
      if (nums.size() == N - 1) break;
    }
  }
  if (sum % 6 == 5) {
    for (int i = N - 2; i >= 0; i--) {
      if (nums[i] % 6 == 3) {
        sum -= nums[i];
        nums.erase(nums.begin() + i);
        nums.push_back(nums.back() + 2);
        sum += nums.back();
        break;
      }
    }
  }

  for (int x : nums) {
    cout << x << ' ';
  }
  for (int x = nums.back() + 1; x <= 30000; x++) {
    if ((x + sum) % 6 == 0 && __gcd(x, sum) > 1) {
      cout << x << endl;
      return true;
    }
  }
  dbg(N, sum, sum % 6);
  return false;
}

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

  int N;
  cin >> N;
  if (N == 3) {
    cout << "2 5 63\n";
  } else if (N == 4) {
    cout << "2 5 20 63\n";
  } else if (N == 6) {
    cout << "2 3 4 6 9 12\n";
  } else {
    solve(N);
  }
}


Measured memory_bytes: 640
from typing import Set


class UnionFind:
    """Union Find (Disjoint Set): O(α(N))
    References:
        https://github.com/atcoder/ac-library/blob/master/atcoder/dsu.hpp
        https://tumoiyorozu.github.io/single-file-ac-library/document_en/dsu.html
    """

    __slots__ = ["_data_size", "_first_idx", "_roots"]

    def __init__(self, data_size: int, is_zero_origin: bool = True) -> None:
        self._data_size = data_size
        self._first_idx = 0 if is_zero_origin else 1
        self._roots = [-1] * (data_size + self._first_idx)

    # def __getitem__(self, x: int) -> int:
    #     """Find the group (root) of vertex x."""
    #     while self._roots[x] >= 0:
    #         x = self._roots[x]
    #     return x

    def __len__(self) -> int:
        """Count the number of groups (roots)."""
        return len(self.groups)

    @property
    def groups(self) -> Set[int]:
        """Return the set of groups (roots)."""
        return {
            self._find(x)
            for x in range(self._first_idx, self._data_size + self._first_idx)
        }

    def _find(self, x: int) -> int:
        while self._roots[x] >= 0:
            x = self._roots[x]

        return x

    def is_connected(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are connected or not."""
        return self._find(x) == self._find(y)

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y."""
        x, y = self._find(x), self._find(y)
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x

    def unite_all(self, *vertices: int) -> None:
        """Unite the groups of all of the given vertices."""
        x = vertices[0]
        for y in vertices[1:]:
            self.unite(x, y)

    def get_size(self, x: int) -> int:
        """Return the size of the group vertex x belongs."""
        return -self._roots[self._find(x)]


def unionfind():
    # https://judge.yosupo.jp/problem/unionfind
    # https://atcoder.jp/contests/practice2/tasks/practice2_a
    N, Q, *TUV = map(int, open(0).read().split())
    tree = UnionFind(N)
    res = []
    for t, u, v in zip(*[iter(TUV)] * 3):
        if t:
            res.append(int(tree.is_connected(u, v)))
        else:
            tree.unite(u, v)
    print("\n".join(map(str, res)))


if __name__ == "__main__":
    unionfind()


Measured memory_bytes: 144248
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  Scanner sc;

  Main() {
    sc = new Scanner(System.in);
  }

  int ni() {
    return sc.nextInt();
  }

  public static void main(String[] args) {
    new Main().run();
  }

  class Disk {
    int x;
    int y;
    int c;
    int r;

    boolean isIn(Disk disk) {
      return Math.pow(this.r + disk.r, 2) > Math.pow(this.x - disk.x, 2) + Math.pow(this.y - disk.y, 2);
    }
  }

  void run() {
    for (; ; ) {
      int n = ni();
      if (n == 0) {
        break;
      }
      Disk[] list = new Disk[n];
      for (int i = 0; i < n; ++i) {
        Disk d = new Disk();
        d.x = ni();
        d.y = ni();
        d.r = ni();
        d.c = ni();
        list[i] = d;
      }

      byte[] dp = new byte[1 << n];
      Arrays.fill(dp, (byte) -1);
      dp[0] = 0;
      for (int i = 0; i < 1 << n; ++i) {
        if (dp[i] < 0) {
          continue;
        }
        for (int j = 0; j < n; ++j) {
          if (((i >> j) & 1) == 1) {
            continue;
          }
          boolean flag = true;
          for (int a = 0; a < j; ++a) {
            if (((i >> a) & 1) == 1) {
              continue;
            }
            flag &= !list[j].isIn(list[a]);
          }
          if (!flag) {
            continue;
          }
          for (int k = j + 1; k < n; ++k) {
            if (((i >> k) & 1) == 1) {
              continue;
            }
            boolean glag = true;
            for (int a = 0; a < k; ++a) {
              if (((i >> a) & 1) == 1) {
                continue;
              }
              glag &= !list[k].isIn(list[a]);
            }
            if (!glag) {
              continue;
            }
            if (list[j].c != list[k].c) {
              continue;
            }

//            debug(j, k);

            dp[i | (1 << j) | (1 << k)] = (byte) Math.max(dp[i] + 1, dp[i | (1 << j) | (1 << k)]);
          }
        }
      }
      int max = 0;
      for (int i = 0; i < 1 << n; ++i) {
        max = Math.max(max, dp[i]);
      }

      System.out.println(max * 2);
    }
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 226612
#include <stdio.h>

int main(void)
{
    
    int T,N,i,sum=0,subsum=0;
    
    scanf("%d %d", &N, &T);
    
    int t[N];
    for(i=0;i<N;i++){
        scanf("%d",&t[i]);
    }
    
    if(N==1) sum=T;
    else{
        for(i=1;i<N;i++){
            if(t[i]-t[i-1]<T){
                subsum += t[i]-t[i-1];//差分を入れる
            }
            else{
                sum += T + subsum;
                subsum=0;
            }
            
            if(i==N-1) sum += subsum+T;
        }
    }
    
    printf("%d\n",sum);
    
    
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
// #include <boost/lexical_cast.hpp>
using namespace std;


#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pi 3.14159265358979323846
ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
vll factor(ll n){
    vll ans;
    if(n>0)ans.pb(1);if(n==2)ans.pb(2);
    for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
    return ans;
}
ll fact(ll n){
	
    ll res = 1; 
    for (ll i = 2; i <= n; i++) 
        res = res * i; 
    return res; 
} 
  
int nCr(ll n, ll r) 
{ 
    return fact(n) / (fact(r) * fact(n - r)); 
} 
  
void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
{
 
    par[k]=p;
    dis[k]=dis[p]+1;
    for(ll i=0;i<v[k].sz;i++){
        if(v[k][i]!=p){
            dfs(v,v[k][i],par,dis,k);
        }
    }
}
bool sortbysec(const pair<string,int> &a,const pair<string,int> &b){return (a.second<b.second);} 


ll ston(string s) 
{ 
    stringstream geek(s); 
    ll x = 0; 
    geek >> x; 
    
  
    return x; 
}
ll pow2(ll n,ll k){ll ans=1;
    while(k>0){
        if(k%2==1)ans=ans*n;n=n*n;k/=2;
    }return ans;}
bool prime(int n){
    int i,j;
    for(i=2;i<=sqrt(n);i++){
        if(n%i==0){
            return false;
        }
    }
    return true;
}
bool bserch(vector<string> a, string s){
	
	ll l=0,r=a.sz-1,mid;
	while(l<=r){
		mid=(l+r)/2;
		if(a[mid]==s)return true;
		if(a[mid]<s){
			l=mid+1;
		}else{
			r=mid-1;
		}
	}
	return false;
}

bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[0] < v2[0]; 
} 

void solve()
{
	ll n,k,ans=0;
	cin>>n>>k;
	ll r,p,s;
	cin>>r>>s>>p;
	string t;
	cin>>t;
	for(ll i=0;i<n;i++)
	{
		if(k<=i && t[i]== t[i-k])
			t[i]='x';
		else
		{
			if(t[i]=='r')
				ans+=p;
			if(t[i]=='s')
				ans+=r;
			if(t[i]=='p')
				ans+=s;
			
		}
	}
	cout<<ans;
}

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


Measured memory_bytes: 512
<?php

function input() {
    return trim(fgets(STDIN));
}
function input_array() {
    return explode(' ', input());
}

$n = input();
list($t, $a) = input_array();
$hs = array_map(function($key, $height) use ($t, $a) {
    return ['key' => $key, 'temperature_diff' => abs($t - $height * 0.006 - $a)];
}, range(1, $n), input_array());

usort($hs, function($a, $b) {
   return $a['temperature_diff'] <=> $b['temperature_diff'];
});
$hs = array_values($hs);

echo $hs[0]['key'] . "\n";exit;

Measured memory_bytes: 4856
#include<stdio.h>
#include<math.h>
#define N 256

int main(){
  int H[N],W[N];
  int i=0,j,k,l,m;
  while(1){
    scanf("%d %d",&H[i],&W[i]);
    if(H[i]==0 && W[i]==0){
      break;
    }
    i++;
  }
  for(m=0;m<i;m++){
    for(j=0;j<H[m];j++){
      if(j%2 == 0){
        for(k=0;k<W[m];k++){
	  if(k%2 == 0){
            printf("#");
          }
          if(k%2 == 1){
            printf(".");
          }
        }
      } 
      if(j%2 == 1){
        for(l=0;l<W[m];l++){
	  if(l%2 == 0){
            printf(".");
          }
          if(l%2 == 1){
            printf("#");
          }
        }
      } 
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1000