akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;



int main(void) {

    // int n;
    // cin>>n;
    // string s;
    // cin>>s;
    // if(n%2==1){
    //     fin("No");
    //     return 0;
    // }
    // if(s.substr(0,n/2)==s.substr(n/2)){
    //     fin("Yes");
    //     return 0;
    // } else {
    //     fin("No");
    // }
    int n;
    cin>>n;
    cout<<n*n<<endl;

}


Measured memory_bytes: 256
#coding:utf-8
from collections import deque
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = True

def index(a,b):
    return str(min(a,b)) + "," +  str(max(a, b))

def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    n, m = LMIIS()
    s = input()

    ans = []

    t = n
    while True:
        if t <= m:
            ans.append(str(t))
            break
        f = True
        for i in range(m):
            if s[t-m+i] == "0":
                ans.append(str(m-i))
                t = t-m+i
                f = False
                break
        if f:
            print(-1)
            exit()

    ans.reverse()

    print(" ".join(ans))





if __name__ == '__main__':
    main()


Measured memory_bytes: 10484
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)

using namespace std;

inline void inp( int &n ) { 
	n=0;    int ch=getcx();int sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

inline void inp1( LL &n ) { 
	n=0;    LL ch=getcx();LL sign=1;   
	while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();} 
	while(  ch >= '0' && ch <= '9' )    
	n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
	n=n*sign;
}

void solve() {
	int x, y, z;
	cin>>x>>y>>z;
	swap(x, y);
	swap(x, z);
	cout<<x<<" "<<y<<" "<<z<<endl;
	
}

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


Measured memory_bytes: 3584
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int w, h, x, y;
    long double sq;
    int way = 0;
    cin >> w >> h >> x >> y;
    if (w == x * 2 && h == y * 2) way = 1;
    sq = (double) w * h / 2;
    cout << fixed << setprecision(10) <<  sq << " " << way << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

const int MAX_EL = 100;

void printArray(int *A, int N) {
    for (int i = 0; i < N; i++) {
        if (i == N -1) 
            cout << A[i];
        else
            cout << A[i] << " ";
    }
    cout << endl;
}

// バブルソート
int bubbleSort(int *A, int N) { 
    int count = 0;
    bool flag = true;
    while (flag) {
        flag = false;
        for (int j = N - 1; j >= 1; j--) {
            if (A[j] < A[j-1]) {
                int tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                flag = true;
                count++;
            }
        }
    }
    return count;
}

// cl /EHsc /source-charset:utf-8 main.cpp
// .\main.exe < in1.txt
int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;

    // read elements
    int A[MAX_EL] = { 0 };
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    //printArray(A, N);
    int swapCount = bubbleSort(A, N);

    printArray(A, N);
    cout << swapCount << endl;

    return 0;
}


Measured memory_bytes: 3216
(defun app ()
    (let ((s (read-line)))
        (if (and (equal (subseq s 2 3) (subseq s 3 4)) (equal (subseq s 4 5) (subseq s 5 6)))
        (format t "Yes~%")
        (format t "No~%"))
    )
)
(app)

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

//dpテーブルをローカルで宣言したらセグフォになった...
ll a[100010],sa[100010];

int main(){
  ll n;
  cin >> n;
  ll res=0;
  a[0]=0;
  a[n+1]=0;
  rep(i,n+1){
    if(i>0){
      cin >> a[i];
    }
  }
  rep(i,n+1){
    sa[i]=abs(a[i+1]-a[i]);
    res+=sa[i];
  }
  rep(i,n+1){
    if(i>0){
      ll ans=0;
      ans=res+abs(a[i+1]-a[i-1])-abs(a[i]-a[i-1])-abs(a[i+1]-a[i]);
      cout << ans <<endl;
    }
    //i番目がi-1,i+1番目に対して
    //左、間、右にあるかで場合分けすれば良い。
  }
}


Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
void solve()
{
   int d,t,s;
   cin>>d>>t>>s;
   if(t*s>=d)
    cout<<"Yes"<<endl;
   else
    cout<<"No"<<endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  int ans = 1;
  for(int i = 0; i < n; i++){
    cin >> h[i];
  }
  for(int i = 1; i < n; i++){
    bool flag = true;
    for(int j = 0; j < i; j++){
      if(h[i] < h[j]){
        flag = false;
      }
    }
    if(flag){
      ans++;
    }
  }
  cout << ans << endl;
}

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

const int mod = 1000000000 + 7;

int dp[401][401];

int main()
{
   
    
    int a, b, c, N, M;

    int Ma, Mb;

    cin>>N>>Ma>>Mb;

    for(int i = 0; i < N; i++)
    {
        cin>>a>>b>>c;

        for(int j = 400 - a; j >= 0; j--)
        {
            for(int k = 400 - b; k >= 0; k--)
            {
                if(dp[j][k])
                {
                    if(!dp[j + a][k + b])
                    {
                        dp[j + a][k + b] = dp[j][k] + c;
                    }
                    else
                    {
                        dp[j + a][k + b] = min(dp[j + a][k + b], dp[j][k] + c);
                    }
                }
            }
        }
        if(!dp[a][b])
        {
            dp[a][b] = c;
        }
        else
        {
            dp[a][b] = min(dp[a][b], c);
        }
    }

    int ans = -1;
    
    for(int i = 1; max(i * Ma, i * Mb) <= 400; i++)
    {
        if(dp[i * Ma][i * Mb])
        {
            if(ans > -1)
            {
                ans = min(ans, dp[i * Ma][i * Mb]);
            }
            else
            {
                ans = dp[i * Ma][i * Mb];
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int maxn=100000+100;
int A[maxn];
map<int,int> mp;
int main()
{
    int n,ans=0,maxx=0;
    scanf("%d",&n);
    for (register int i=1;i<=n;++i)
    {
        int a;
        scanf("%d",&a);
        if (!mp.count(a))A[i]=a;
        mp[a]++;
        maxx=max(maxx,a);
    }
    for (int a=1;a<=n;++a)
    {
            int x=mp[A[a]];
            if (x<A[a]) ans+=x;
            else ans+=x-A[a];
    }
    printf("%d",ans);
}


Measured memory_bytes: 5120
/*================================================================
*   Copyright (C) 2019 Sangfor Ltd. All rights reserved.
*   
*   文件名称：B.cpp
*   创 建 者：YaliKiWi
*   创建日期：2019年07月20日
*   描    述：
*
================================================================*/


#include<bits/stdc++.h>
using namespace std; 
long long n,m;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m;
	int ans=floor(n/(m*2+1));
	if(n%(m*2+1)!=0)ans++;
	cout<<ans;
	return 0;
}

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

#define readv(v) for(auto& pepito : v) cin >> pepito;
#define printv(v) for (int pepo = 0; pepo < v.size(); pepo++) cout << (pepo==0?: ) << v[pepo]; cout << endl;
#define queries(maria) int maria; cin >> maria; while (maria--) 
//for (int i = 0; i < n; i++) 

using ll = long long int;
using vi = vector<ll>;
using vvi = vector<vi>;

int main(){
    int n, k, s;
    cin >> n >> k >> s;
    for (int i = 1; i <= k; i++)
        cout << (i == 1 ? "" : " ") << s;
    if (s < 1e9) {
        for (int i = k+1; i <= n; i++)
            cout << ' ' << s+1;
    } else {
        for (int i = k+1; i <= n; i++)
            cout << ' ' << 1;
    }
    cout << endl;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<int>west(n);
    vector<int>east(n);
    west.at(0) = (s.at(0)=='W' ? 1 : 0);
    east.at(0) = 1 - west.at(0);
    for ( int i = 1; i < n; i++){
        west.at(i) = west.at(i-1) + (s.at(i)=='W' ? 1:0);
        east.at(i) = i - west.at(i) + 1;
    }
    int ans = east.at(n-1) - east.at(0);
    for (int i = 0; i <= n-2; i++){
        ans = min(ans,west.at(i) + east.at(n-1) - east.at(i + 1));
    }
    cout << ans <<endl;
}


    

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define LL long long
#define int long long
#define N 300100
inline LL read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	LL k=0,kk=1;if (c=='-')c=getchar(),kk=-1;
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();return kk*k;
}using namespace std;
void write(LL x){if (x<0)x=-x,putchar('-');if (x/10)write(x/10);putchar(x%10+'0');}
void writeln(LL x){write(x);puts("");}
int x,y,q;
int findth(int x,int y){return y>=x?y+1:y;}
bool check(int sum){
	int d=sum/2;
	for (int i=d-200;i<=d+200;i++)if ((i>0&&i<=sum))if ((findth(x,i)*findth(y,sum-i+1)>=x*y))return 0;
	return 1;
}signed main(){
	q=read();while (q--){
		x=read(),y=read();
		int l=0,r=2e9,ans=0;
		while (l<r){
			int m=(l+r+1)>>1;
			if (check(m))l=m;else r=m-1;
		}writeln(l);
	}
}

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

using namespace std;

#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000000
#define INFL (1LL << 60)
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int d = a%2, e = b%2, f = c%2;
  if(d == e && d == f){
    int k = max(a, max(b, c));
    cout << (k-a)/2 + (k-b)/2 + (k-c)/2 << endl;
  }
  else{
    if(d == e){
      a++;
      b++;
    }
    else if(d == f){
      a++;
      c++;
    }
    else{
      b++;
      c++;
    }
    int k = max(a, max(b, c));
    cout << 1+(k-a)/2 + (k-b)/2 + (k-c)/2 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int cs[3][1002][1002];
int main()
{
    int h, w, k;
    cin >> h >> w >> k;

    map<char, int> tb;
    tb['J'] = 0;
    tb['O'] = 1;
    tb['I'] = 2;

    rep(y, h)
    {
        string s;
        cin >> s;
        rep(x, w)
        {
            int i = tb[s[x]];
            rep(j, 3) cs[j][y + 1][x + 1] = cs[j][y + 1][x] + cs[j][y][x + 1] - cs[j][y][x];
            cs[i][y + 1][x + 1]++;
        }
    }

    vint ans(3);
    rep(i, k)
    {
        int y1, x1, y2, x2;
        cin >> y1 >> x1 >> y2 >> x2;
        y1--;
        x1--;
        rep(j, 3)
        {
            auto c = cs[j];
            ans[j] = c[y2][x2] - c[y2][x1] - c[y1][x2] + c[y1][x1];
        }
        printf("%d %d %d\n", ans[0], ans[1], ans[2]);
    }

    return 0;
}


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

int main(){
int N;
  cin>>N;
  int p[N];
  for(int yy=0;yy<N;yy++) cin>>p[yy];
  
  int xmax=0;
  int sum=0;
  for(int i=0;i<N;i++){
  sum+=p[i];
    xmax=max(xmax,p[i]);
  }
    cout<<sum-xmax/2<<endl;

return 0;}

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

int main(void){
  int a, b, c;
  cin >> a >> b >> c;
  if(a < c && c < b){
    cout << "Yes" << endl;
    return 0;
  }else if(a > c && c > b){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n;
	cin >> n;
	string s;
	cin >> s;
	stack<char> st;
	for(int i = 0; i < n; i++) {
		if(st.empty()) {
			st.push(s[i]);
			continue;
		}
		if(st.top() == '(') {
			if(s[i] == ')') {
				st.pop();
			}
			else {
				st.push(s[i]);
			}
			continue;
		}
		if(st.top() == ')') {
			st.push(s[i]);
		}
	}
	while(!st.empty()) {
		char tmp = st.top();
		st.pop();
		if(tmp == '(') {
			s.push_back(')');
		}
		else {
			s.insert(s.begin(), '(');
		}
	}
	cout << s << endl;
	return 0;	
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;

int main(){
    int N;
    LL C,K;
    cin >> N >> C >> K;
    LL T[N];
    LL count=0,p=0,c=0;
    for(int i=0;i<N;i++){
        cin >> T[i];
    }
    sort(T,T+N);
    p=T[0];
    for(int i=0;i<N;i++){
       if(T[i]<=p+K&&c<C){
           c++;
           continue;
       }
       if(c==C||p+K<T[i]){
            count++;
            c=1;
            p=T[i];
            continue;
       }
    }
    cout << count+1 << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fast_I_O ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int mod = 1e9+7 , INF = 1e9 ,  mx = 100005 ;
main()
{
    fast_I_O;
    int i,j,n,m,x=0,y,sum=0,p=0,l,k;
    cin>>n;
    int a[n],b[n+1];
    for(i=0;i<n;i++) cin>>a[i] , sum+=a[i];
    b[n]=0;
    for(i=n-1;i>=0;i--)
    {
        b[i]=b[i+1]+a[i];
    }
    //for(i=0;i<n;i++) cout<<b[i]<<' ';
    for(i=1;i<n;i++)
    {
        x+=((a[i-1]%mod)*(b[i]%mod))%mod;
    }
    cout<<x%mod;
    return 0;
}

Measured memory_bytes: 6712
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    int n;
    cin>>n;
    bool f=true;
    for(int i=1;i<10;i++)
        if(n/i<10&&i*(n/i)==n) f=false;
    if(f)cout<<"No";
    else cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
n = int(input())
inning = 0

while inning != n:
    score = 0
    info = [0, 0, 0]
    out_count = 0
    while True:
        event = input()
        if event == "OUT":
            out_count += 1
        if out_count == 3:
            inning += 1
            print(score)
            break

        if event == "HIT":
            score += info[-1]
            info = [1] + info[:2]
        elif event == "HOMERUN":
            score += sum(info) + 1
            info = [0, 0, 0]


Measured memory_bytes: 5592
#include <stdio.h>
#include <algorithm>

using namespace std;

int partition(int A[],int p,int r){
	int x = A[r];
	int i = p-1;
	for(int j = p; j < r; j++){
		if(A[j] <= x){
			i++;
			swap(A[i],A[j]);
		}
	}
	swap(A[i+1],A[r]);
	return i+1;
}

int main(){
	int n,partition_point;
	scanf("%d",&n);
	int A[n];
	for(int i = 0; i < n; i++) scanf("%d",&A[i]);

	partition_point = partition(A,0,n-1);

	for(int i = 0; i < n-1; i++){
		if(i == partition_point){
			printf("[%d] ",A[i]);
		}else{
			printf("%d ",A[i]);
		}
	}
	if(partition_point == n-1){
		printf("[%d]\n",A[n-1]);
	}else{
		printf("%d\n",A[n-1]);
	}
}

Measured memory_bytes: 1420
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    map<int,int> m;
    rep(i,N){
        int a; cin >> a;
        m[a]++;
    }
    int x=0,y=0;
    for(auto p:m){
        if(p.se>=4){
            if(x<=p.fi) {
                x=p.fi;
                y=p.fi;
            }
            else if(y<p.fi){
                y=p.fi;
            }
        }
        else if(p.se>=2){
            if(x<=p.fi){
                y=x;
                x=p.fi;
            }
            else if(y<p.fi){
                y=p.fi;
            }
        }
    }
    cout << x*y << endl;
}

Measured memory_bytes: 6528
#input
N = int(input())
S = [""] * N
P = [0] * N

for i in range(N):
    S[i], P[i] = input().split()

#output
for i in range(N):
    P[i] = int(P[i])

num_list = [i+1 for i in range(N)]
my_list = [(i, j, k) for i, j, k in  zip(S, P, num_list)]
my_list = sorted(my_list, key = lambda x:(x[0], -x[1]))

for k in range(N):
    print(my_list[k][2])

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, k;
long long ans, fac[400009];

long long quickpow(long long b, int e)
{
	return e ? ((e & 1 ? b : 1)*quickpow(((b%MOD)*(b%MOD)) % MOD, e >> 1)) % MOD : 1;
}

long long fun(int a, int b)
{
	long long ret = fac[a];
	ret *= quickpow(fac[b], MOD - 2);
	ret %= MOD;
	ret *= quickpow(fac[a - b], MOD - 2);
	ret %= MOD;
	return ret;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	fac[0] = 1;
	for (int i = 1; i <= n + n; i++) {
		fac[i] = fac[i - 1] * i;
		fac[i] %= MOD;
	}
	if (k >= n - 1) {
		ans = fun(n + n - 1, n - 1);
	}
	else {
		ans++;
		for (int i = 1; i <= k; i++) {
			int m = n - i;
			int u = n - m;
			long long tmp = fun(u + m - 1, m - 1);
			tmp *= fun(n, i);
			tmp %= MOD;
			ans += tmp;
			ans %= MOD;
		}
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

int main() {
  string s;
  cin >> s;
  string t;
  cin >> t;

  sort(all(s));
  sort(all(t), greater<int>());

  if (s < t)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
h,w = map(int, input().split())
al = [list(input()) for _ in range(h)]
cnts = {}
for row in al:
    for a in row:
        cnts.setdefault(a,0)
        cnts[a] += 1
        cnts[a]%= 4

c4 = [0]*5
for i,v in cnts.items():
    c4[v] += 1
c4[4] = c4[0]


if w%2 == 0 and h%2 == 0:
    if c4[1] == 0 and c4[2] == 0 and c4[3] == 0:
        print('Yes')
    else:
        print('No')

elif w%2 == 1 and h%2 == 1:
    if c4[1] + c4[3] == 1 and c4[3] + c4[2] <= (h-1)//2 + (w-1)//2:
        print('Yes')
    else:
        print('No')

elif w%2 == 1 and h%2 == 0:
    if c4[1] + c4[3] == 0 and c4[2] <= h//2:
        print('Yes')
    else:
        print('No')

elif w%2 == 0 and h%2 == 1:
    if c4[1] + c4[3] == 0 and c4[2] <= w//2:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 65912
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,ans=0;
  bool is_s;
  char tmp;
  cin >> n;
  string s[n];
  for(int i=0;i<n;i++){
    cin >> s[i];
  }
  for(int k=0;k<n;k++){
    is_s=true;
    for(int i=0;i<n;i++){
      for(int j=i;j<n;j++){
        if(s[i][j]!=s[j][i]){
          is_s=false;
          break;
        }
      }
      if(!is_s){
        break;
      }
    }
    if(is_s){
      ans+=n;
    }
    for(int i=0;i<n;i++){
      tmp = s[i][0];
      for(int j=0;j<n-1;j++){
        s[i][j]=s[i][j+1];
      }
      s[i][n-1]=tmp;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<climits>

const int INF = 1001001001;

/*
個数制限無しのナップザック問題. dpを使うという考え方は正解. 
ただしdpの設計次第では制限時間内に答えが出ないのでそこの注意が必要.
*/

int main(){
    int H, N;
    scanf("%d %d%*c", &H, &N);
    std::vector<int> A(N), B(N);
    for(int i = 0; i < N; i++){
        scanf("%d %d%*c", &A[i], &B[i]);
    }

    // dp[i + 1][j] : i番目までの魔法を使用してjダメージ以上与えるときの最小コスト
    /*
    j + A[i] <= Hのとき : i - 1番目までのときと, i番目までのjダメージのとき
    dp[i + 1][j + A[i]] = min(dp[i][j + A[i]], dp[i + 1][j] + B[i])
    j + A[i] > Hのとき : i - 1番目までのときと, i番目までのjダメージのとき
    dp[i + 1][H] = min(dp[i + 1][H], dp[i + 1][j] + B[i])
    */
    std::vector<std::vector<int>> dp(N + 1, std::vector<int>(H + 1, INF));
    // 初期化
    dp[0][0] = 0;
    for(int i = 0; i < N; i++){
        for(int h = 0; h <= H; h++){
            dp[i + 1][h] = std::min(dp[i][h], dp[i + 1][h]); // これまでの結果を考慮
            if(h + A[i] <= H){
                dp[i + 1][h + A[i]] = std::min(dp[i][h + A[i]], dp[i + 1][h] + B[i]);
            }else{
                dp[i + 1][H] = std::min(dp[i + 1][H], dp[i + 1][h] + B[i]);
            }
        }
    }

    std::cout << dp[N][H] << std::endl;

    return 0;
}

Measured memory_bytes: 39424
/*
  ミンコフスキー距離(２つの n 次元ベクトルが与えられるので
  　　　　　　　　　 pがそれぞれ 1,2,3,∞のミンコフスキー距離を求めるプログラム)
  2018/03/09
*/

#include<stdio.h>
#include<math.h>

void action(int x[],int y[],int n,int p)
{
  int i;
  double sum=0,ans;/*ans:ミンコフスキー距離*/
  for(i=0;i<n;i++)
    sum += pow((double)fabs(x[i]-y[i]),(double)p);
  ans = pow(sum,(1/(double)p));
  printf("%f\n",ans);
}
  
int main(void)
{
  int n,p;
  int x[100],y[100];
  int i;
  double max=0;/*max:チェビシェフ距離*/
  
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&x[i]);
  for(i=0;i<n;i++)
    scanf("%d",&y[i]);
  
  for(p=1;p<=3;p++)
    action(x,y,n,p);

  for(i=0;i<n;i++)
    max = ((double)fabs(x[i] - y[i]) > max)?(double)fabs(x[i]-y[i]):max;
  printf("%f\n",max);
  return 0;
}


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

#if ((_WIN32 || __WIN32__) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif

//{{{
using namespace std;
typedef long long LL;
typedef vector<int> VI;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define clr(a, b) memset(a, b, sizeof(a))
// clang-format off
#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); cerr<<endl;}
vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while
(getline(ss, x, c)) v.push_back(x); return v;} void err(vector<string>::iterator) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args)
{cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}
// clang-format on
//}}}

const int N = 1e5 + 10;
int T;
int n;

int dp[N][3];

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
// freopen("out", "w", stdout);
#endif

    while (cin >> n)
    {
        int a, b, c;
        cin >> a >> b >> c;
        dp[1][0] = a;
        dp[1][1] = b;
        dp[1][2] = c;
        for (int i = 2; i <= n; i++)
        {
            cin >> a >> b >> c;
            dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a;
            dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b;
            dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c;
        }
        int ans = max(dp[n][0], dp[n][1]);
        ans = max(ans, dp[n][2]);
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 4692
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cstring>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll MOD = 1e9 + 7;

int main()
{
    int n, m, le[310], ri[310], x[310];

    ll dp[310][310][310];

    vector<P> v[310];

    cin >> n >> m;
    REP(i, m)
    {
        cin >> le[i] >> ri[i] >> x[i];
        v[ri[i]].push_back({le[i], x[i]});
    }

    memset(dp, 0, sizeof(dp));

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

    ll res = 0;

    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
            for (int k = 0; k <= n; k++)
            {
                int ma = max(i, max(j, k));

                int a[3];
                a[0] = i;
                a[1] = j;
                a[2] = k;

                sort(a, a + 3);

                bool check = true;

                for (P l : v[ma])
                {
                    switch (l.second)
                    {
                    case 1:
                        if (l.first <= a[1])
                            check = false;
                        break;
                    case 2:
                        if (a[1] < l.first || a[0] >= l.first)
                            check = false;
                        break;
                    case 3:
                        if (a[0] < l.first)
                            check = false;
                        break;
                    default:
                        break;
                    }
                }

                if (!check)
                    dp[i][j][k] = 0;

                if (ma == n)
                {
                    res += dp[i][j][k];
                    res %= MOD;
                }

                (dp[ma + 1][j][k] += dp[i][j][k]) %= MOD;
                (dp[i][ma + 1][k] += dp[i][j][k]) %= MOD;
                (dp[i][j][ma + 1] += dp[i][j][k]) %= MOD;
            }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 232960
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
  int n;
  map<string, int> blood;
  string str;
  char c;

  blood.insert(map<string,int>::value_type("A", 0));
  blood.insert(map<string,int>::value_type("B", 0));
  blood.insert(map<string,int>::value_type("AB", 0));
  blood.insert(map<string,int>::value_type("O", 0));

  while(cin >> n >> c >> str) {
    blood[str]++;
  }
  cout << blood["A"] << endl;
  cout << blood["B"] << endl;
  cout << blood["AB"] << endl;
  cout << blood["O"] << endl;
}

Measured memory_bytes: 1216
s = input()

strs = set(s)


if len(set(s)) == 1:
  print(0)
  exit()

ans = 1000
tmp = 0
for moji in strs:
  s1 = s
  s2 = [""] * (len(s)-1)
  tmp = 0
  flag = True
  while flag == True:
    for i in range(len(s2)):
      if s1[i] == moji or s1[i+1] == moji:
        s2[i] = moji
      else:
        s2[i] = s1[i]
      
    tmp += 1
    s1 = s2
    s2 = [""] * (len(s1)-1)

    if len(set(s1)) == 1:
      flag = False
  ans = min(ans, tmp)   
 
print(ans)
  

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <limits>
using namespace std;
using LL = unsigned long long;
int main()
{
	int N, X;
	LL a[200001] = {};
	__int128 sum[200001] = {};

	scanf("%d%d", &N, &X);
	for (int n = 1; n <= N; n++)
		scanf("%llu", &a[n]), sum[n]+=sum[n-1]+a[n];

	__int128 ans = LLONG_MAX;
	for (int r = 1; r <= N; r++)
	{
		__int128 c = (sum[N]-sum[N-r])*2;
		int i;
		for (i = 1; i*r <= N; i++)
			c += (sum[N-i*r+r] - sum[N-i*r]) * (2*i+1);
		c += sum[N-i*r+r] * (2*i+1);
		ans = min(ans, c+(__int128)X*(N+r));
	}
	printf("%llu", (LL)ans);
}

Measured memory_bytes: 4992
using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading;
using System.IO;
using System.Text;

//============================================================================
namespace Sweet
{
    class Program
    {
        static StreamWriter writer = null;
        //============================================================================
        static void setstdio(string[] args)
        {
            if (0 < args.Length)
            {
                // Redirect standard input from the console to the input file.
                Console.SetIn(new StreamReader(args[0]));
                if (args.Length == 2)
                {
                    // Attempt to open output file.
                    writer = new StreamWriter(args[1]);
                    // Redirect standard output from the console to the output file.
                    Console.SetOut(writer);
                }
            }
        }
        //============================================================================
        static int Swing()
        {
            int alpha = 26;
            int[] sum=new int[alpha];

            while (true)
            {
                StringBuilder builder = new StringBuilder(Console.ReadLine());
                if (builder.Length == 0)
                    break;
                for (int i = 0; i < builder.Length; i++)
                    if (isalpha(builder[i]))
                        sum[(builder[i] & 0x1f) - 1]++;
            }
            for (int i=0; i<alpha; i++)
                Console.WriteLine("{0} : {1}", (char)('a'+i), sum[i]);
            return 0;
        }

        private static bool isalpha(char v)
        {
            if ('a' <= v && v <= 'z' || 'A' <= v && v <= 'Z')
                return true;
            return false;
        }

        //============================================================================
        static void Main(string[] args)
        {
            setstdio(args);

            while(Swing()!=0);
            if (writer != null)
                writer.Close();
            //Console.ReadLine();
        }
        //============================================================================
    }
}
//============================================================================

Measured memory_bytes: 9040
//MISHON69
//DATE:6/22/2020
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  cin>>n;
  int a[n];
  FOR(i,n){
    cin>>a[i];
  }
  map<int,int>m;
  FOR(i,n){
    int temp=a[i];
    m[temp]=i+1;
  }
  FOR(i,n){
    cout<<m[i+1]<<" ";
  }
}  


Measured memory_bytes: 8628
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las
    

main = do
    (a,b) <- readTuple2
    print $ maximum [a + b, a - b , a* b]


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

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int):
    tmp = 0
    n = N
    while n > 0:
        tmp += n % 10
        n //= 10
    if N % tmp == 0:
        ret = YES
    else:
        ret = NO
    print(ret)
    return


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
    solve(N)

if __name__ == '__main__':
    main()


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

int main(){
    int ans,n,m;
    cin >> n >> m;
    int money[m];
    rep(i,m)cin >> money[i];
    int sheet[n+1];
    rep(i,n+1)sheet[i] = INT_MAX;
    sheet[0] = 0;
    typedef pair<int,int> P;
    queue<P> que;
    que.push(P(0,0));
    while(que.size() != 0){
        P now = que.front();
        int nowmoney = now.first;
        int count = now.second+1;
        que.pop();
        rep(i,m){
            int nextmoney = nowmoney + money[i];
            if(nextmoney == n){
                cout << count << endl;
                return 0;
            }
            else if(nextmoney < n &&sheet[nextmoney] > count){
                sheet[nextmoney] = count;
                que.push(P(nextmoney,count));
            }
        }
    }
}



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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(a) "(" << #a << ": " << (a) << ")"

template<typename T>
void chmin(T &x, T y) { x = min(x, y); }

template<typename T>
void chmax(T &x, T y) { x = max(x, y); }

typedef long long int lli;
typedef long double ld;
typedef tuple<int,int> P;
typedef bitset<64> switches;
typedef bitset<1024> bulbs;

const int INF = INT_MAX/2 - 1;
const double EPS = 1e-14;
const int dx[4] = {0, 1, 0, -1}; // {-1,  0,  1, -1, 1, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0}; // {-1, -1, -1,  0, 0,  1, 1, 1};
const string base36 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

string solve(int n, int m, const vector<tuple<switches,bulbs>> &crs) {
  string ans(m, '?');
  REP (i, m) {
    switches accs;
    REP(j, n) accs.set(j);
    for (auto cr : crs) {
      switches ss; bulbs bs; tie(ss, bs) = cr;
      accs &= bs[i] ? ss:~ss;
    }
    if (accs.count() != 1) { continue; }
    REP (j, n) {
      if (accs[j]) { ans[i] = base36[j]; }
    }
  }
  return ans;
}

int main() {
  cout << fixed << setprecision(10);
  int N, M, Q;
  while (cin >> N >> M >> Q and N) {
    vector<tuple<switches,bulbs>> correspondence;
    switches current(0);
    REP (q, Q) {
      string S, B;
      cin >> S >> B;
      switches ss(0);
      REP (i, N) { ss[i] = S[i] == '1'; }
      bulbs bs(0);
      REP (i, M) { bs[i] = B[i] == '1'; }
      current ^= ss;
      correspondence.emplace_back(current, bs);
    }
    cout << solve(N, M, correspondence) << endl;
  }
  return 0;
}

Measured memory_bytes: 3248
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    A = list(map(int, readline().split()))
    A.sort()
    if N % 2 == 0:
        for i in range(0, N, 2):
            if A[i] == A[i + 1] == i + 1:
                continue
            else:
                print(0)
                sys.exit()
    else:
        for i in range(1, N, 2):
            if A[i] == A[i + 1] == i + 1:
                continue
            else:
                print(0)
                sys.exit()
        if A[0] != 0:
            print(0)
            sys.exit()
    print(pow(2, N // 2, MOD))


if __name__ == '__main__':
    main()


Measured memory_bytes: 19724
#include<bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define SZ(a) (int)(a).size()
#define FOR(i, a, b) for(int i=(a); i<=(b); ++i)
#define iFOR(i, a, b) for(int i=(a); i>=(b); --i)
#define make_unique(a) sort(all((a))), (a).resize(unique(all((a)))-(a).begin())

using namespace std;

typedef pair<int,int> PII;
typedef long long LL;
typedef double DD;
typedef long double LD;
typedef pair<LL,LL> PLL;
typedef pair<DD,DD> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;

const int N = 3004;
const int mod = 998244353;
int mul(int a, int b){
    return a * 1ll * b % mod;
}
int add(int a, int b){
    int c = a+b;
    if(c >= mod) c-=mod;
    return c;
}
int dp[N][N];
int main(){
    int A,B,C,D;
    scanf("%d %d %d %d",&A,&B,&C,&D);
    dp[A][B] = 1;
    FOR(i, A, C){
        FOR(j, B, D){
            if(PII(i, j) == PII(A, B)) continue;
            dp[i][j] = add(dp[i][j], mul(dp[i-1][j], j));
            dp[i][j] = add(dp[i][j], mul(dp[i][j-1], i));
            dp[i][j] = add(dp[i][j], mod-mul(dp[i-1][j-1], mul(i-1,j-1)));
        }
    }
    printf("%d",dp[C][D]);
	return 0;
}
/*
 *
 *
 *
 *
 *
 *
 *
 *
 *
 *
 */


Measured memory_bytes: 38920
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define INF 1 << 30
#define MAX 1000000000

ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }

int main() {
	int N, M, x, y;
	scanf("%d%d", &N, &M);
	vector<int> c(N, 1), f(N, 0);
	f[0] = 1;
	rep(i, 0, M) {
		scanf("%d%d", &x, &y);
		x--, y--;
		f[y] |= f[x];
		c[y]++, c[x]--;
		if (c[x] == 0)f[x] = 0;
	}
	int ans = 0;
	rep(i, 0, N) {
		if (f[i])ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define H ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
using namespace std;
const ll  mod = 3e7;

string bin(int x){
    string s = "00000";
    int i = 4;
    while (x){
        s[i--] = (x % 2) + '0';
        x /= 2;
    }
    return s;
}

string s, str;
int f[1000006], arr[1000006];
int getNxt(int len, char c){
    while (len && s[len] != c){
        len = f[len - 1];
    }
    if (s[len] == c)
        len++;
    return len;
}

void computeF(){
    f[0] = 0;
    for (int i = 1; i < s.size(); i++){
        f[i] = getNxt(f[i - 1], s[i]);
    }
}

void KMP(){
    computeF();
    int k = 0, ans = 0;
    for (int i = 0; i < str.size(); i++){
        k = getNxt(k, str[i]);
        arr[k]++;
    }

}

int main()
{
    H
    int n, k;
    cin >> n;
    ll arr[n + 1], b[n];
    for (int i = 0; i < n + 1; i++) cin >> arr[i];
    for (int i = 0; i < n; i++){
        cin >> b[i];
    }
    ll ans = 0;
    for (int i = 0; i < n; i++){
        ans += min(b[i], arr[i]);
        b[i] = max(0LL, b[i] - arr[i]);
        ans += min(b[i], arr[i + 1]);
        arr[i + 1] = max(0LL, arr[i + 1] - b[i]);
    }
    cout << ans;
    return 0 ;
}

Measured memory_bytes: 1792
# 数列生成
from itertools import combinations
N, M, Q = map(int, input().split())
ls = []
for i in range(Q):
    ls.append([int(j) for j in input().split()])
V = [[] for i in range(N+1)]
for i in range(1, M+1):
    V[1].append([i])

for i in range(1, N):
    for v in V[i]:
        b = v[-1]
        for x in range(b, M+1):
            V[i+1].append(v + [x])
ans = 0
for x in V[-1]:
    cur = 0
    for z in ls:
        if x[z[1]-1] - x[z[0]-1] == z[2]:
            cur += z[3]
    ans = max(ans, cur)
print(ans)

Measured memory_bytes: 36076
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}



signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int h1,m1,h2,m2,k;cin>>h1>>m1>>h2>>m2>>k;
    ll m=0;
    if(m1<=m2) m+=m2-m1+(h2-h1)*60;
    else m+=(h2-h1-1)*60+60-(m1-m2);
    cout<<m-k<<endl;
    return 0;
}


Measured memory_bytes: 3652
fn main() {
    proconio::input! {
        n: usize,
    }
    let mut count2 = 0usize;
    let mut count5 = 0usize;
    if n % 2 != 0 {
        println!("0");
        return;
    }
    for d in 1.. {
        let div = 2usize.checked_pow(d).unwrap();
        let c = n / div;
        if c == 0 {
            break;
        } else {
            count2 += c;
        }
    }
    for d in 1.. {
        let div = 5usize.checked_pow(d).unwrap() * 2;
        let c = n / div;
        if c == 0 {
            break;
        } else {
            count5 += c;
        }
    }
    let ans = std::cmp::min(count2, count5);
    println!("{}", ans);
}


Measured memory_bytes: 2156
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int D=sc.nextInt();
		int N=sc.nextInt();
		if(N==100) {
			System.out.println((int)Math.pow(100, D)*(N+1));
		}else {
			System.out.println((int)Math.pow(100, D)*N);
		}
	}
}

Measured memory_bytes: 22868
n, k = map(int, input().split())
li = list(map(int, input().split()))
 
check = [0] * (n)
res = []
next = 0
 
for i in range(k):
    if check[next] == 0:
        check[next] = 1
        next = li[next]-1
    elif check[next] == 1:
        check[next] += 1
        res.append(next+1)
        next = li[next]-1
    else:
        cnt = len(res)
        k -= check.count(1)
        amari = k%cnt
        print(res[amari])
        break
else:
    print(next+1)


Measured memory_bytes: 32236
#include <bits/stdc++.h>
using namespace std;
 int main() {
   char x;
   cin >>x;
   if (x =='A') {
     cout << 'T' << endl;
   }
   else if (x =='T') {
     cout << 'A' << endl;
   }
  else  if (x =='G') {
     cout << 'C' << endl;
   }
   if (x =='C') {
     cout << 'G' << endl;
   }
 }

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var input string
	fmt.Scan(&input)
	if input == "A" {
		fmt.Println("T")
	}
	if input == "T" {
		fmt.Println("A")
	}
	if input == "C" {
		fmt.Println("G")
	}
	if input == "G" {
		fmt.Println("C")
	}
}


Measured memory_bytes: 512