akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using mat = vector<vector<ll>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


int main() {
  int H,W; cin >>H >>W;
  vector<string> field(H); rep(i, H) cin >>field[i];
  vector<vector<ll>> dp(H, vector<ll>(W, 0));
  dp[0][0] = 1;
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      if (i+1 < H && field[i+1][j] == '.') dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD;
      if (j+1 < W && field[i][j+1] == '.') dp[i][j+1] = (dp[i][j+1] + dp[i][j]) % MOD;
    }
  }
  int res = dp[H-1][W-1];
  cout <<res <<endl;
}

Measured memory_bytes: 9216
//#pragma GCC optimize ("O3")
//#pragma GCC target ("avx")
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	int p=0;
	for(char c:s){
		p+=c-'0';
	}
	if(p%9==0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
}

Measured memory_bytes: 3740
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] cs = sc.next().toCharArray();
		int result = 0;
		for (int i = 0; i < cs.length; i++) {
			int count = 0;
			for (int j = i; j < cs.length; j++) {
				if (cs[j] == 'A' || cs[j] == 'C' || cs[j] == 'G' || cs[j] == 'T') {
					count++;
				} else {
					break;
				}
			}
			result = Math.max(count, result);
		}
		System.out.println(result);
		sc.close();
	}
}

Measured memory_bytes: 35740
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
#include <map>
#include <fstream>
#include <array>
#include <utility>
#include <functional>
#include <stack>
#include <math.h>
#include <numeric>

using namespace std;
typedef long long Int;
#define REP(i , x) for(Int i = 0 ; i < x ; ++i)
typedef pair<int, int> P;


int main()
{
	int a[4], t[4];
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> t[0] >> t[1] >> t[2] >> t[3];

	int asum = accumulate(a, a + 4, 0);
	int tsum = accumulate(t, t + 4, 0);

	cout << max(asum, tsum) << endl;

	return 0;
}

Measured memory_bytes: 1160
/**
 * Header Files
 */
#include <stdio.h>


int main(void){

    int N,X;

    scanf("%d %d", &N, &X);

    int v[N];
    int x;
    for(int i=0;i<N;i++){
        scanf("%d",&x);
        v[i] = x;
    }

    int numOfBounce = 0;
    int dist = 0;
    for(int i=0;dist<=X;i++){
        dist = dist + v[i];

        numOfBounce++;
    }

    printf("%d", numOfBounce);

	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

ll pow_mod(ll n,ll p,ll m){
    ll res = 1;
    while(p>0){
        if(p%2==1) res = (res * n) % m;
        n = (n * n) % m;
        p /= 2;
    }
    return res;
}

ll inv_mod(ll n,ll mod){
    return pow_mod(n,mod-2,mod);
}

ll factrial_mod(ll n,ll k,ll mod){
    ll x=1,y=1;
    rep(i,k){
        x = (x*(n-i)) % mod;
        y = (y*(i+1)) % mod;
    }
    return x*inv_mod(y,mod)%mod;
}

int main(){
    int n;
    cin >> n;
    vl a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    ll N = a[n-1];
    int l = 0,r = n-1;
    ll R;
    int cnt = 0;
    while(r-l>1 && cnt <= 1000){
        int c = (r+l)/2;
        ll d = a[c];
        if(r==l) break;
        else if(2*d<N){
            l = c;
        }else if(2*d>N){
            r = c;
        }
        cnt++;
    }
    int ind = (r+l)/2;
    R = a[ind];
    if(ind+1 <= n-2 ){
        if(abs(2*R-N) > abs(2*a[ind + 1] - N)){
            R = a[ind + 1];
        }
    }
    if(ind - 1 >=0){
        if(abs(2*R-N) > abs(2*a[ind-1] - N)){
            R = a[ind -1];
        }
    }
    cout << N << " " << R << endl;
}

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

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    vector<int> v;
    vector<int> haiku = {5,5,7};
    v.push_back(A);
    v.push_back(B);
    v.push_back(C);
    sort(v.begin(),v.end());

    bool can = equal(v.begin(),v.end(), haiku.begin());
    if(can) cout << "YES" << endl;
    else cout << "NO" << endl;

}

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

int N;
int flg[111];
int P[111][11];

int calc(int x){
    int tmp = 0;
    for(int i = 0; i < N; i++){
        tmp += P[i][__builtin_popcount(x & flg[i])];
    }
    return tmp;
}

int main(){
    
    cin >> N;
    for(int i = 0; i < N; i++){
        for(int j = 0; j < 10; j++){
            int f;
            cin >> f;
            flg[i] = flg[i] * 2 + f;
        }
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j <= 10; j++)cin >> P[i][j];
    }
    int ans = calc(1);
    for(int i = 2; i < (1 << 10); i++)ans = max(ans, calc(i));
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
#include <queue>
#include <fstream>
#include <stdio.h>
#include <math.h>

using namespace std;

int main(int argc, const char * argv[]) {
   string s;
   getline(cin,s);
   cout<<s.substr(0,4)+" "+s.substr(4)<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))

def main():
    sys.setrecursionlimit(10**8)
    INF = float("inf")

    a = INT()
    print(a + a**2 + a**3)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9120
#include <iostream>
using namespace std;
struct {int x, y;} p[21], l;
struct {char a; int d;} o[30];
int main()
{
	int n, m, t, i, j, k, f[21];
	while (cin >> n && (t = n))
	{
		for (i = 0; i < n; f[i] = 1, i++)
			cin >> p[i].x >> p[i].y;
		cin >> m;
		for (i = 0; i < m; i++)
			cin >> o[i].a >> o[i].d;
		for (i = 0, l.x = l.y = 10; i < m; i++)
			switch (o[i].a)
			{
			case 'N':
				for (j = 0; j < o[i].d; j++)
				{
					l.y++;
					for (k = 0; k < n; k++)
						if (f[k] && l.x == p[k].x && l.y == p[k].y)
							f[k] = 0, t--;
				}
				break;
			case 'E':
				for (j = 0; j < o[i].d; j++)
				{
					l.x++;
					for (k = 0; k < n; k++)
						if (f[k] && l.x == p[k].x && l.y == p[k].y)
							f[k] = 0, t--;
				}
				break;
			case 'S':
				for (j = 0; j < o[i].d; j++)
				{
					l.y--;
					for (k = 0; k < n; k++)
						if (f[k] && l.x == p[k].x && l.y == p[k].y)
							f[k] = 0, t--;
				}
				break;
			case 'W':
				for (j = 0; j < o[i].d; j++)
				{
					l.x--;
					for (k = 0; k < n; k++)
						if (f[k] && l.x == p[k].x && l.y == p[k].y)
							f[k] = 0, t--;
				}
				break;
			}
		if (t <= 0)	cout << "Yes" << endl;
		else		cout << "No" << endl;
	}
}

Measured memory_bytes: 0
N = int(input())
T = [int(s) for s in input().split()]
M = int(input())
PX = []
for _ in range(M):
    p, x = map(int, input().split())
    PX.append((p - 1, x))
s = sum(T)
for p, x in PX:
    print(s - T[p] + x)


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

int main() {
  string S;
  int N;
  bool a=true;
  cin >> S;
  N=S.size();
  for(int i=0;i<N/2;i++){
    if(S.at(i)!=S.at(N-i-1)){
      a=false;
    }
  }
  for(int i=0;i<(N/2)/2;i++){
    if(S.at(i)!=S.at(N/2-i-1)){
      a=false;
    }
    if(S.at((N+3)/2-1+i)!=S.at(N-1-i)){
      a=false;
    }
  }
  if(a){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())
vx = x2 - x1
vy = y2 - y1
x3 = -vy + x2
x4 = -vy + x1
y3 = vx + y2
y4 = vx + y1
print(x3, y3, x4, y4)

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
const ll INF = 1e17;
const int MOD = 1e9 + 7;

ll a, b, c;

int main(void) {
	cin >> a >> b;
	if (a % 3 != 0 & a % 3 == b % 3)ct("Impossible");
	else ct("Possible");


	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
_ = int(input())
even = 0
odd = 0
for a in map(int, input().split()):
    if a % 2 == 0:
        even += 1
    else:
        odd += 1
ans = odd % 2 == 0 or (even == 0 and odd == 1)
print(['NO', 'YES'][ans])


Measured memory_bytes: 11104
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int n, m;
int main() {
	cin >> n >> m; int cnt = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			int B = i + j, C = i + j + n;
			if (B > m || C < m)continue;
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
char s[1111111],t[1111111];
int n,bel[1111111];
#include<queue>
std::queue<int>q;
inline int getans()
{
	register int i;
	int ans=0;
	for(i=n;i;i--)
	{
		if(i!=1)if(t[i]==t[i-1])continue;
		while(q.size())
		{if(q.front()-q.size()>=i)q.pop();else break;}
		q.push(bel[i]);
		if(bel[i]^i)if(ans<q.size())ans=q.size();
	}return printf("%d\n",ans+1),0;
}
int main()
{
	scanf("%d%s%s",&n,s+1,t+1);
	register int i,ii;
	for(i=1;i<=n;i++)if(s[i]!=t[i])goto Nxt;
	return puts("0"),0;
	Nxt:
	for(i=n,ii=n;i;i--)
	{
		while(ii>i)ii--;
		while(ii&&(s[ii]!=t[i]))ii--;
		if(!ii)goto Nxxt;
		bel[i]=ii;
	}return getans();
	Nxxt:
	return puts("-1"),0;
}

Measured memory_bytes: 10752
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
string change(int a,int b,string str){
    for(int i=0;i<str.size();i++)str[i]=((str[i]-'a')*a+b)%26+'a';
    return str;
}
string out(int a,int b,string str){
    for(int i=0;i<str.size();i++){
        if('a'<=str[i]&&str[i]<='z'){
            for(int j=0;j<26;j++){
                if((j*a+b)%26+'a'==str[i]){
                    str[i]=j+'a';
                    break;
                }
            }
        }
    }
    return str;
}
int main(){
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        string str;
        if(!i)getchar();
        getline(cin,str);
        for(int j=1;;j++){
            for(int k=0;k<26;k++){
                for(int l=0;l<str.size()-3;l++){
                    if(change(j,k,"that")==str.substr(l,4)){
                        cout<<out(j,k,str)<<endl;
                        goto exit;
                    }
                    if(change(j,k,"this")==str.substr(l,4)){
                        cout<<out(j,k,str)<<endl;
                        goto exit;
                    }
                }
            }
        }
        exit:;
    }
    return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define MAX 3005
using namespace std;
 
double dp[MAX][MAX], p[MAX];
int n, visited[MAX][MAX];

double solve(int pos, int cnt)
{
    if(pos >= n){
        if(cnt > (n / 2)){
            return 1.0;
        }
        else
            return 0;
    }
    if(visited[pos][cnt] != -1)
        return dp[pos][cnt];
    visited[pos][cnt] = 1;

    double ret1 = p[pos] * solve(pos + 1, cnt + 1);
    double ret2 = (1.0 - p[pos]) * solve(pos + 1, cnt);
    return dp[pos][cnt] = ret1 + ret2;
}

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #ifdef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    memset(visited, -1, sizeof(visited));
    
    cin>>n;

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

    double result = solve(0, 0);

    cout<<setiosflags(ios::fixed)<<setprecision(12);
    cout<<result<<endl;

    return 0;
}

Measured memory_bytes: 106112
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n;
    cin>>n;
    long long x,sum=0;
    for(int i=1;i<=n;i++)
    {
       x=n/i;
       sum+=i*(x*(x+1)/2);
    }
    cout<<sum<<endl;
}


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

int n;
vector<int> a(105, 0);

void input() {
    cin >> n;
    for(int i = 0; i< n; i++) {
        cin >> a.at(i);
    }
}

void solve() {
    double sum = 0.0;
    for(int i = 0; i < n; i++) {
        sum = sum + (1.0 / a.at(i));
    }
    cout << setprecision(10) << (1.0 / sum) << endl;

}

int main() {
    input();
    solve();

}


Measured memory_bytes: 256
#include <stdio.h>

int N;
int C;
int s[100005];
int t[100005];
int c[100005];

int T[31][100005];

int main(){

	scanf("%d %d",&N,&C);

	int i,j;

	for(i=0;i<N;i++){
	scanf("%d %d %d",&s[i],&t[i],&c[i]);
	}

	for(i=0;i<N;i++){
		for(j=s[i];j<=t[i];j++){
			if(T[c[i]][j]==0){
			T[c[i]][j]=1;
			}
		}
	}

	int ans=0;

	for(i=0;i<100005;i++){
	int cnt=0;
	for(j=1;j<=C;j++){
	cnt+=T[j][i];
	}
	if(ans<cnt){ans=cnt;}
	}


	printf("%d\n",ans);

return 0;
}

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

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

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

  int N = s.length();
  long long ans = 0;
  int count = 0;
  rep(i, N-1) {
    if (s[i] == 'A')
      ++count;
    else if (s.substr(i, 2) == "BC") {
      ans += count;
      ++i;
    } else
      count = 0;
  }
  cout<<ans<<"\n";
  return 0;
}



Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const long double pi=acos(-1);

int main(){cout<<fixed<<setprecision(10);
		   int n;
           cin>>n;
           vin d(n);
           rep(i,0,n)cin>>d[i];
           map<int,int> cnt;
           rep(i,0,n)cnt[d[i]]++;
           bool zero=false;
           vin time(25,0);
           time[0]++;
           time[24]++;
           vin mi;
           int micnt=0;
           for(auto v:cnt){
                if(v.first==0)zero=true;
                else if(v.first==12){
                  if(v.second>=2)zero=true;
                  time[12]++;
                }
               else if(v.second>=3)zero=true;
               else if(v.second==2){
                time[v.first]++;
                time[24-v.first]++;
               }
               else{
                 micnt++;
                 mi.pb(v.first);
               }
           }
           if(zero){
            cout<<0<<endl;
             return 0;
           }
           int ans=0;
           //cout<<mi[0]<<mi[1]<<endl;
           for (int bit = 0; bit < (1 <<micnt ); ++bit) {
               vin ktime(25);
               ktime=time;
               for (int i = 0; i < micnt; ++i) {
                if (bit & (1 << i)){
                  ktime[mi[i]]++;
                }
                 else{
                   ktime[24-mi[i]]++;
                 }
               }
             int g=inf;
             int hu=0;
             rep(i,1,25){
               if(ktime[i]){
                chmin(g,i-hu);
                hu=i; 
               }
             }
             chmax(ans,g);
           }
           
           
           cout<<ans<<endl;
}



Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
typedef vector<pii> vpii;
#define reps(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define all(g) (g).begin(),(g).end()
#define pb push_back
const int mod = 1e9 + 7;
#define INF 1<<25
/*
input case
output case
*/

int n;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    pii a[n];
    ll sum = 0;
    rep(i,n){
        cin >> a[i].first;
        a[i].second = i;
    }
    sort(a,a+n);
    rep(i,n){
        if(i%2==0 and a[i].second%2 == 1) sum++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(ll i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;


int main() {
    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    vector<ll> d(n+1);
    d[0]=0;
    rep(i,n) {
        d[i+1]=d[i]+n-(upper_bound(c.begin(),c.end(),b[i])-c.begin());
    }
    ll ans=0;
    rep(i,n) {
        int k=upper_bound(b.begin(),b.end(),a[i])-b.begin();
        ans+=d[n]-d[k];
    }
    cout << ans << endl;
}

Measured memory_bytes: 2176
N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[0]*(N+1)
for i in range(M):
    a,b=map(int,input().split())
    if H[a-1]>H[b-1]:
        L[b]=1
    elif H[a-1]<H[b-1]:
        L[a]=1
    else:
        L[a],L[b]=1,1
print(N-sum(L))


Measured memory_bytes: 19936
// ALDS1_6_B: Partition

fn scan<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn scan_vec<T: std::str::FromStr>() -> Vec<T> {
    let s: String = scan();
    s.split_whitespace().map(|a| T::from_str(a).ok().unwrap()).collect()
}

fn partition(a: &mut Vec<u32>, p: usize, r: usize) -> usize {
    let x = a[r];
    let mut i = p;
    for j in p..r {
        if a[j] <= x {
            a.swap(i, j);
            i += 1;
        }
    }
    a.swap(i, r);
    i
}

fn main() {
    let n: usize = scan();
    let mut a: Vec<u32> = scan_vec();
    let q = partition(&mut a, 0, n - 1);

    for i in 0..n {
        if i > 0 {
            print!(" ");
        }
        if i == q {
            print!("[{}]", a[i]);
        } else {
            print!("{}", a[i]);
        }
    }
    println!();
}


Measured memory_bytes: 5032
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <complex>
using namespace std;

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

#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T> void preview(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}

const int INF = 100000000;
const double PI = acos(-1.0), EPS = 1e-10;

int main() {
	string line;
	getline(cin, line);
	rep(i,line.length()) if(line[i] == '.' || line[i] == ',') line[i] = ' ';
	istringstream is(line);
	bool fst = true;
	for(string w; is >> w;) {
		if(3 <= w.length() && w.length() <= 6) {
			if(fst) {
				cout << w;
				fst = false;
			} else {
				cout << " " << w;
			}
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
 void trace(int A[], int N){
      int i;
      for(i=0; i<N; i++){
      if(i>0) printf(" ");
      printf("%d",A[i]);
      }
  printf("\n");
  }
void insertionSort(int A[],int N){
   int j,i,v;
   for (i=1; i<N; i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
    A[j+1]=A[j];
    j--;
   }
   A[j+1]=v;
   trace(A,N);
  }
}

int main(void){
   int N,i;
   int A[100];

   scanf("%d",&N);
   for(i=0;i<N;i++) scanf("%d",&A[i]);
   
	trace(A, N);
	insertionSort(A, N);
	return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;

    cin>>n>>k;
    k--;
    cin>>S;

    S[k]+=32;

    cout<<S<<"\n";

    return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> ii;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vii;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<vector<ld>> vvld;
typedef vector<bool> vbl;
typedef vector<vbl> mbl;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(s) (s).begin(), (s).end()
const ll MOD = 1e9 + 7;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    int x;
    cin >> x;
    ll ans = (x / 500) * 1000;
    x %= 500;
    cout << ans + (x / 5) * 5 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstring>
#include<vector>
#include<cmath>
#include<cstdlib>
using namespace std;

char s[100][100];
int vis[100][100],a[100][100];

int dfs(int x,int y){
	int sum = 0;
	for(int i = -1;i <= 1;i++){
		for(int j = -1;j <= 1;j++){
			if(s[x + i][y + j] == '#') sum++;
		}
	}
	return sum;
}

int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			scanf(" %c",&s[i][j]);
			if(s[i][j] == '#') vis[i][j] = 1;
		}
	}
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			if(vis[i][j] == 0)
			a[i][j] = dfs(i,j);
		}
	}
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			if(vis[i][j] == 1) printf("#");
			else printf("%d",a[i][j]);
			if(j == m) printf("\n");
		}
	}
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) cin >> vec.at(i);

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

  int ans = 0;
  for (int i = 0; i < K; i++) ans += vec.at(N - 1 - i);

  cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>

int main()
{
    int H = 0;
    int W = 0;
    
    while( 1 )
    {
        std::cin >> H;
        std::cin >> W;
        
        if( 0 == H && 0 == W )
        {
            break;
        }

        if( H < 1 || H > 300 || W < 1 || W > 300 )
        {
            std::cout << "Error : out of range!" << std::endl;
            return -1;
        }
        
        for( int i = 0; i < H; ++i )
        {
            for( int j = 0; j < W; ++j )
            {
                std::cout << "#";
            }
            std::cout << std::endl;
        }
        
        std::cout << std::endl;
    }
    
    return 0;
}


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

int main() {
    ll n,m,count=0;
    cin >> n >> m;
    vector<int> h(n);
    rep(i,n) cin >> h.at(i);
    vector<vector<int>> hill(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        if(h.at(a) > h.at(b)){
            hill.at(b).push_back(a);
        }else if(h.at(a) == h.at(b)){
             hill.at(b).push_back(a);
          hill.at(a).push_back(b);
        }else{
            hill.at(a).push_back(b);
        }
    }
    rep(i,n){
        if(hill.at(i).size() == 0){
            count++;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 7744
import sys
from io import StringIO
import unittest


def resolve():
    a, b, c, k = map(int, input().split())

    if k <= a:
        print(k)        
    elif k <= (a + b):
        print(a)
    else:
        print(a - (k - a - b))



class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """2 1 1 3"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """1 2 3 4"""
        output = """0"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """2000000000 0 0 2000000000"""
        output = """2000000000"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 71000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int num1,num2;
  cin >> num1 >> num2;
  
  int num,count = 0;
  
  for (int i = 0; i <= num2 - num1; i++){
    num = num1 + i;
    if(num % 10 == num / 10000  && num / 10 % 10 == num / 1000 % 10)
      count++;
  }
    cout << count << endl;
 
}

Measured memory_bytes: 3636
from math import log10
def nsn(N):
    K = sum( list( map( int, list( str(N)))))
    return N/K

def snuke(N):
    k = int( log10(N))+1
    s = N
    now = nsn(N)
    for d in range(k+1):
        x = (10**(d+1))*(N//(10**(d+1)) + 1) - 1
        y = nsn(x)
        if y < now:
            s = x
            now = y
    return s

K = int( input())
ans = 1
print(1)
for i in range(K-1):
    ans = snuke( ans + 1)
    print(ans)



Measured memory_bytes: 3188
import std.stdio, std.math, std.conv;

void main()
{
    foreach(input; stdin.byLine)
    {
        foreach(n; 1..int.max)
        {
            if(9.8 * sqrt(5.0 / 4.9 * (n - 1)) >= input.to!double)
            {
                n.writeln;
                break;
            }
        }
    }
}

Measured memory_bytes: 1064
#include <stdio.h>
#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main()
{
  int x;
  scanf("%d", &x);
  if (x == 2 || x == 3) {
    printf("%d\n", x);
    return 0;
  }

  for(int i = x; ; i++) {
    bool flag = false;
    bool ex = false;
    if (i % 2 == 0)
       continue;
    for(int j = 3; j < i; j++) {
       if (i % j == 0)
         flag = true;
       if (flag == true) {
         break;
       }
       if (j == i - 1)
         ex = true;
    }
    if (ex == true) {
      printf("%d\n", i);
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
bool b=0;
int cnt=0;
while(n--){
	int x,y;
	cin>>x>>y;
	if(x==y)
		cnt++;
	else
		cnt=0;
	if(cnt>=3){
		b=1;
		break;
	}
}
if(b)
	cout<<"Yes\n";
else
	cout<<"No\n";
}


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

int32_t main() {
  int n;
  cin >> n;
  set<string> st;
  while (n--) {
      string s;
      cin >> s;
      st.insert(s);
  }
  cout << st.size();
  return 0;
}


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

const ll MOD = 1e9 + 7;

ll qp ( ll a , ll b )
{
    ll ans = 1;
    while ( b )
	{
        if ( b & 1 )
		   ans = ans * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    
    return ans;
    
}

const int N = 2e5 + 10;
ll fac[N];

ll C ( ll a , ll b )
{
    ll ans = fac[a] * qp ( fac[b] , MOD - 2 ) % MOD;
    ans = ans * qp ( ( fac[a-b] + MOD ) % MOD , MOD - 2 ) % MOD;
    
    return ans;
    
}

ll n,m,k,ans;

int main ()
{
    fac[0] = 1;
    for ( int i = 1 ; i < N ; ++ i )
	    fac[i] = fac[i - 1] * i % MOD;
    cin >> n >> m >> k;
    ans = C ( n * m , k ) * C ( k , 2 ) % MOD * qp ( 3 , MOD - 2 ) % MOD;
    ans = ans * ( n + m ) % MOD;
    ans %= MOD;
    
    cout << ans << '\n';
    
    return 0;
    
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;

int main() {
  ll d,t,s;
  cin >> d >> t >> s;
  if (t*s >= d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3632
n = int(input())
ll = list(map(int, input().split()))
ct = 0
step = 0
for i in range(len(ll)-1):
    if ll[i] < ll[i+1]:
        ct  = 0
    elif ll[i] >= ll[i+1]:
        ct += 1
        if ct > step:
            step = ct
print(step)


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

int main(){
    vector<bool> cup(3);
    cup.at(0) = true;
    cup.at(1) = false;
    cup.at(2) = false;

    string s;
    int x1, y1;
    bool tmp;

    while(cin >> s){
        x1 = (int)(s.at(0) - 'A');
        y1 = (int)(s.at(2) - 'A');
        tmp = cup[x1];
        cup[x1] = cup[y1];
        cup[y1] = tmp;
    }

    for(int i=0; i<3; i++){
        if(cup[i]){
            cout << (char)(i+'A') << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 0
main :: IO ()
main = do
  [n, a, b] <- (fmap (\x -> read x :: Int)) . words <$> getLine
  xs <- (fmap (\x -> read x :: Int)) . words <$> getLine
  let ds = map (\(x, y) -> abs (x - y)) (zip xs (tail xs)) in
    print $ sum $ map (\d -> min (a * d) b) ds


Measured memory_bytes: 36220
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;
#define LOCAL  1
#define UPLOAD 2
#define ll long long
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';

unsigned long long d(unsigned long long N){
  unsigned digit=0;
  while(N!=0){
      N /= 10;
      digit++;
  }
  return digit;
}

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
  int r = input();

  output((int)r*r);

  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python3

import os
import sys


def main():
    V, E = read_ints()
    G = [set() for _ in range(V)]
    for _ in range(E):
        s, t = read_ints()
        G[s].add(t)
    print(solve(V, E, G))


def solve(V, E, G):
    done = [False] * V

    def dfs(i, path):
        path.add(i)
        for j in G[i]:
            if j in path:
                return True
            if not done[j] and dfs(j, path):
                return True
        path.remove(i)
        done[i] = True
        return False

    for i in range(V):
        if not done[i] and dfs(i, set()):
            return 1

    return 0


###############################################################################
# AUXILIARY FUNCTIONS

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()



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

typedef pair<int, string> Team;

int main(void){  
  int n, firstDS=0;
  
  while (cin >> n){
    vector<Team> v;
    if (n==0) break;
    if (firstDS==0) firstDS= 1;
    else cout << endl;
    for (int i=0; i<n; i++){
      string nm;
      int w,l,d;
      Team t;
      cin >> nm >> w >> l >> d;
      t = make_pair(w*3+d, (char)('z'-i)+nm);
      v.push_back(t);
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    for (int i=0; i<n; i++){
      cout << (v[i].second.c_str()+1) << ",";
      cout << v[i].first << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3036
/*
    Mbak Sana Dong
    Mbak Chaeyoung Dong
*/
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    int n,i,j,k,x,y,ans,temp,curr,m;
    int tc;
    cin >> n;
    ll chaeng = 0;
    ll now = n / 500;
    chaeng += now * 1000;
    n %= 500;
    now = n / 5;
    chaeng += now * 5;
    cout << chaeng << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int depth[11][11];
int dx[] = {0,  0,  0,  1, -1,  1,  1, -1, -1,  0,  0,  2, -2};
int dy[] = {0,  1, -1,  0,  0, -1,  1,  1, -1,  2, -2,  0,  0};
int ans;
int total;
void draw(int x, int y, int size){
	for(int i = 0; i < size*4+1; i++){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if( nx < 0 || nx >= 10 || ny < 0 || ny >= 10) continue;
		depth[ny][nx]++;
		ans = max(ans, depth[ny][nx]);
		if(depth[ny][nx] == 1)total--;
	}
}
int main(){
	int x, y , size;
	char c;
	total = 10*10;
	while(cin >> x >> c >> y >> c >> size){
		draw(x,y,size);
	}
	cout << total << endl;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#define int long long
#define rg register
#define file(x) freopen(x".in","r",stdin);freopen(x".out","w",stdout);
using namespace std;
const int mod=1e9+7;
int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
    while(c>='0'&&c<='9') x=x*10+c-48,c=getchar();
    return f*x;
}
int f[41][262143+10];
int ksm(int a,int b){
	int ans=1;
	while(b){
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
main(){
    //file("");
	int n=read(),x=read(),y=read(),z=read(),len=(1<<(x+y+z))-1,res=1<<(x+y+z-1)|(1<<(y+z-1))|(1<<(z-1)),ans=0;
	f[0][0]=1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=len;j++)
			for(int k=1;k<=10;k++){
				int z=(j<<k)|(1<<(k-1));
				z&=len;
				if((z&res)==res) continue;
				f[i][z]=(f[i-1][j]+f[i][z])%mod;
		}
	for(int i=0;i<=len;i++)
		ans=(ans+f[n][i])%mod;
	cout<<(ksm(10,n)-ans+mod)%mod;
    return 0;
}

Measured memory_bytes: 82176
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(double x){
  printf("%.15f",x);
}
int W;
int H;
int X;
int Y;
int main(){
  double res1;
  int res2;
  rd(W);
  rd(H);
  rd(X);
  rd(Y);
  res1 = (double)W*H/2;
  if(W==2*X&&H==2*Y){
    res2 =1;
  }
  else{
    res2 =0;
  }
  wt_L(res1);
  wt_L(' ');
  wt_L(res2);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190706-1

// --- original code ---
// int W, H, X, Y;
// {
//   double res1;
//   int res2;
//   
//   rd(W,H,X,Y);
//   
//   res1 = (double)W*H/2;
//   res2 = if[W==2X&&H==2Y, 1, 0];
//   
//   wt(res1, res2);
// }


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    ll ans=0;
    rep(i,n){
        while(i+1<n && a[i]==a[i+1]) ++i;
        
        if(i+1<n && a[i]<a[i+1]) 
            while(i+1<n && a[i]<=a[i+1]) ++i;
        else if(i+1<n && a[i]>a[i+1])
            while(i+1<n && a[i]>=a[i+1]) ++i;
        
        ++ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4028
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <queue>
using namespace std;
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
 
int main() {
//	freopen("test.txt", "r", stdin);
	FASTER;
	int n; cin>>n;
	unordered_set<string> st;
	while(n--){
		string s; cin>>s;
		st.insert(s);
	}
	cout<<st.size()<<endl;
	return 0;
}

Measured memory_bytes: 13832
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=100005,mod=1e9+7;
LL read(){
	LL x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)&&ch!='-')
		ch=getchar();
	if (ch=='-')
		f=-1,ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+ch-48,ch=getchar();
	return x*f;
}
int n,a[N],Fac[N];
int Pow(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=1LL*x*x%mod)
		if (y&1)
			ans=1LL*ans*x%mod;
	return ans;
}
int Inv(int x){
	return Pow(x,mod-2);
}
int ans=0;
void add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
void del(int &x,int y){
	if ((x-=y)<0)
		x+=mod;
}
int main(){
	n=read();
	for (int i=1;i<=n;i++)
		a[i]=read();
	for (int i=Fac[0]=1;i<=n;i++)
		Fac[i]=1LL*Fac[i-1]*i%mod;
	int tot=0;
	for (int i=1;i<=n;i++)
		add(tot,Inv(i));
	add(ans,1LL*tot*a[1]%mod);
	for (int i=2;i<=n;i++){
		add(tot,Inv(i));
		del(tot,Inv(n-i+2));
		add(ans,1LL*tot*a[i]%mod);
	}
	ans=1LL*ans*Fac[n]%mod;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int md = 998244353;
inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}
inline int mul(int a, int b) {
  return (int)((long long)a * b % md);
}
inline int inv(int a) {
  a %= md;
  if(a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= a * t; swap(a, b);
    u -= v * t; swap(u, v);
  }
  assert(b == 1);
  if(u < 0) u += md;
  return u;
}
vector<int> fct, fnv;
void initFct (int n) {
  fct.resize(n, 1);
  fnv.resize(n, 1);
  for (int i = 1; i < n; i++) {
    fct[i] = mul(fct[i - 1], i);
  }
  fnv[n - 1] = inv(fct[n - 1]);
  for (int i = n - 2; i >= 0; i--) {
    fnv[i] = mul(fnv[i + 1], i + 1);
  }
}
int bnm (int n, int k) {
  assert(0 <= k && k <= n);
  return mul(fct[n], mul(fnv[k], fnv[n - k]));
}
int main() {
  int n, a, b;
  long long k;
  cin >> n >> a >> b >> k;
  initFct(n + 1);
  int ret = 0;
  for (int i = 0; i <= n; i++) {
    if (!((k - i * a) % b)) {
      int j = (k - i * a) / b;
      if (0 <= j && j <= n) {
        add(ret, mul(bnm(n, i), bnm(n, j)));
      }
    }
  }
  cout << ret << '\n';
  return 0;
}

Measured memory_bytes: 2560
fun main(args: Array<String>) {
    val n = readInt()
    val s = read()
    var ansSet = mutableSetOf<String>()
    var tempSet = mutableSetOf<String>()

    for (i in 0 until s.length - 2) {
        var x = s[i].toString()
        if (x in tempSet) continue
        tempSet.add(x)
        for (j in i+1 until s.length -1) {
            var y = x + s[j].toString()
            if (y in tempSet) continue
            tempSet.add(y)
            for (k in j+1 until s.length) {
                var z = y + s[k].toString()
                if (z in tempSet) continue
                tempSet.add(z)
                ansSet.add(z)
            }
        }
    }
    println(ansSet.size)
}

private fun read() = readLine()!!

private fun readInt() = read().toInt()

private fun readLong() = read().toLong()

private fun readDouble() = read().toDouble()

private fun readListString() = read().split(" ")

private fun readListInt() = readListString().map { it.toInt() }

private fun readListLong() = readListString().map { it.toLong() }

private fun readListDouble() = readListString().map { it.toDouble() }

private fun readMatrixString(n: Int): List<List<String>> {
    val matrix = mutableListOf<List<String>>()
    for (i in 0 until n) {
        val list = readListString()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixInt(n: Int): List<List<Int>> {
    val matrix = mutableListOf<List<Int>>()
    for (i in 0 until n) {
        val list = readListInt()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixDouble(n: Int): List<List<Double>> {
    val matrix = mutableListOf<List<Double>>()
    for (i in 0 until n) {
        val list = readListDouble()
        matrix.add(list)
    }
    return matrix
}

private fun readMatrixLong(n: Int): List<List<Long>> {
    val matrix = mutableListOf<List<Long>>()
    for (i in 0 until n) {
        val list = readListLong()
        matrix.add(list)
    }
    return matrix
}



Measured memory_bytes: 119064
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
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 (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

typedef struct houi{
    int L;
    int R;
    int U;
    int D;
}houi;

int main(){
    int H,W;cin >> H >> W;
    vector<string> s(H+10);
    rep(i,H)cin >> s[i];

    vector<vector<houi>> A(H+10,vector<houi>(W+10,{0,0,0,0}));


    rep(i,H){
        int tmp = 0;
        rep(j,W){   // L
            if(s[i][j] == '#')tmp = 0;
            else ++tmp;
            A[i][j].L = tmp;
        }
    }


    rep(i,H){
        int tmp = 0;
        for(int j = W-1;j >= 0;--j){   // R
            if(s[i][j] == '#')tmp = 0;
            else ++tmp;
            A[i][j].R = tmp;
        }
    }


    rep(j,W){
        int tmp = 0;
        rep(i,H){   // U
            if(s[i][j] == '#')tmp = 0;
            else ++tmp;
            A[i][j].U = tmp;
        }
    }


    rep(j,W){
        int tmp = 0;
        for(int i = H-1;i >= 0;--i){   // D
            if(s[i][j] == '#')tmp = 0;
            else ++tmp;
            A[i][j].D = tmp;
        }
    }


    int ans = 0;
    rep(i,H)rep(j,W){
        int t = A[i][j].L + A[i][j].R + A[i][j].U + A[i][j].D - 3;
        ans = max(ans,t);
    }

    cout << ans << endl;
}



Measured memory_bytes: 67584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
#define ls (rt << 1)
#define rs (rt << 1 | 1) 
typedef pair<int, int> pii; 
const ll mod = 1e9 + 7;
template <class T> T lowbit(T x){return ((x)&(-(x)));}
const int maxn = 1e6 + 10;
int t, n, m;
char s[maxn];
bool f(int x)
{
	for(int i = 30; ~i; --i)
		if((x & (1 << i)) && !((n - 1) & (1 << i)))
			return 0;
	return 1;
}
int main()
{
	scanf("%d", &n);
	scanf("%s", s);
	int ret = 0, tot = 0;
	for(int i = 0; i < n; ++i)
	{
		--s[i];
		if(s[i] == '1')
			++tot;
		if(!f(i)) continue;
		if(s[i] == '1') 
			ret ^= 1;
	}
	if(ret) puts("1");
	else if(tot) puts("0");
	else
	{
		ret = 0;
		for(int i = 0; i < n; ++i)
		{
			if(!f(i)) continue;
			if(s[i] == '2') 
				ret ^= 1;
		}
		if(ret) puts("2");
		else puts("0");
	}
	return 0;
}

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

int main() {
  int n, l;
  cin >> n >> l;
  int L = l;
  int R = n + l - 1;
  int eat;
  if(R <= 0){
    eat = R;
  }else if(L >= 0){
    eat = L;
  }else {
    eat = 0;
  }
  cout << (R + L) * (R - L + 1) / 2 - eat << endl;
}

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

int main(){

	int w[10], k[10];

	for (int i = 0; i < 10; i++)std::cin >> w[i];
	for (int i = 0; i < 10; i++)std::cin >> k[i];

	std::sort(w, w + 10);
	std::sort(k, k + 10);

	std::cout << w[9] + w[8] + w[7] << " " << k[9] + k[8] + k[7] << std::endl;

	return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <algorithm>
#define INF (INT32_MAX / 2)
using namespace std;

constexpr int maxn = 1e5 + 1;
int v[1001];
int w[maxn];
int dp[maxn];

int main()
{
    fill(dp + 1, dp + maxn, INF);
    int n, W, i;
    cin >> n >> W;
    for (i = 1; i <= n; i++)
        cin >> w[i] >> v[i];
    
    for ( i = 1; i <= n; i++)
    {
        for (int j = maxn - 1; j >= 0; j--)
            if (dp[j] < W)
                dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
    }

    for (i = maxn - 1; i >= 0; i--)
    {
        if (dp[i] <= W)
            break;
    }

    cout << i << "\n";
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;

const int N = 2003;

char s[N][N];
int n, m, q, sump[N][N], suml0[N][N], suml1[N][N];

int main() {
	scanf("%d%d%d", &n, &m, &q);
	for (int i = 1; i <= n; ++i)
		scanf("%s", s[i] + 1);
	
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			if (s[i][j] == '1') sump[i][j] = 1;
	for (int i = 1; i <= n; ++i)
		for (int j = 2; j <= m; ++j)
			if (s[i][j] == '1' && s[i][j - 1] == '1') suml0[i][j] = 1;
	for (int i = 2; i <= n; ++i)
		for (int j = 1; j <= m; ++j)
			if (s[i][j] == '1' && s[i - 1][j] == '1') suml1[i][j] = 1;
	
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= m; ++j) {
			sump[i][j] = sump[i][j] + sump[i - 1][j] + sump[i][j - 1] - sump[i - 1][j - 1];
			suml0[i][j] = suml0[i][j] + suml0[i - 1][j] + suml0[i][j - 1] - suml0[i - 1][j - 1];
			suml1[i][j] = suml1[i][j] + suml1[i - 1][j] + suml1[i][j - 1] - suml1[i - 1][j - 1];
		}
	
	int sp, sl, x1, y1, x2, y2;
	for (int i = 1; i <= q; ++i) {
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		sp = sl = 0;
		sp = sump[x2][y2] - sump[x1 - 1][y2] - sump[x2][y1 - 1] + sump[x1 - 1][y1 - 1];
		sl = suml0[x2][y2] - suml0[x1 - 1][y2] - suml0[x2][y1] + suml0[x1 - 1][y1];
		sl += suml1[x2][y2] - suml1[x1][y2] - suml1[x2][y1 - 1] + suml1[x1][y1 - 1];
		printf("%d\n", sp - sl);
	}
	
	return 0;
}

Measured memory_bytes: 52608