akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
    int n, k;
    cin >> n >> k;
    ll cnt = (ll(n) * (n+1) - (ll)(n-k) * (n-k+1) - ll(k) * (k-1)) / 2 + 1;
    mint ans = cnt;
    for (int i=k; i<=n; ++i) {
        cnt = cnt + (n-i) - i;
        ans += cnt;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3652
from math import log,ceil
def solve():
    N,K = map(int, input().split())

    
    ans = 0
    for x in range(1, N+1): # xは初期値
        kaisuu = ceil( log( K / x, 2))
        if x >= K:
            kaisuu = 0
        # print(kaisuu)
        # tmp = pow(0.5, kaisuu)
        tmp = 1/N
        for i in range(kaisuu):
            tmp *= 0.5
        ans += tmp 
    # ans /= N
    print(ans)
        

    
if __name__ == "__main__":
    solve()


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

int main(void) {
  int H, W;
  cin >> H >> W;
  char map[H][W];
  int dx[] = {-1, 0, 1, 1, 1, 0, -1, -1};
  int dy[] = {1, 1, 1, 0, -1, -1, -1, 0};
  for (int h = 0; h < H; h++) {
    cin >> map[h];
  }

  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      if (map[h][w] != '#') {
        int cnt = 0;
        for (int i = 0; i < 8; i++) {
          int nx = w + dx[i];
          int ny = h + dy[i];
          if (nx < 0 || nx >= W || ny < 0 || ny >= H) continue;
          if (map[ny][nx] == '#') {
            cnt++;
          }
        }
        cout << cnt;
      } else {
        cout << "#";
      }
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long q = n / (a + b);
        long r = n % (a + b);
        System.out.println(a * q + Math.min(r, a));
    }

}


Measured memory_bytes: 22228
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int h, n; cin >> h >> n;
  ll INF = 1e18;
  vll a(n), b(n), dp(20020, INF);
  rep(i,n) cin>>a[i]>>b[i];
  dp[0] = 0;
  ll ans = INF;
  rep(i,n) repc(j,20010) {
    if(a[i] <= j) {
      chmin(dp[j], dp[j-a[i]] + b[i]);
    }
    if(h <= j) chmin(ans, dp[j]);
  }
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using namespace std;
int main(){
    int n,ans=0;
    cin>>n;
    vector<vector<int>> a(n,vector<int>(n,2));
    rep(i,n){
        int m;
        cin>>m;
        rep(j,m) {
            int o,p;
            cin>>o>>p;
            o--;
            a[i][o]=p;
        }
    }
    for(int i=0;i<(1<<n);i++){
            bool flag=true;
            int p=0;
            vector<int> person(n,2);
        for(int j=0;j<n;j++){
            if((i>>j)&1){
                if(person[j]==0) {
                    flag=false;
                    break;
                }
                person[j]=1;
                p++;
                rep(k,n){
                    if(a[j][k]==1){
                        if(person[k]==0) {
                            flag=false;
                            break;
                        }
                        person[k]=1;
                    }
                    else if(a[j][k]==0){
                        if(person[k]==1) {
                            flag=false;
                            break;
                        }
                        person[k]=0;
                    }
                }
            }
            else{
                if(person[j]==1) {
                    flag=false;
                    break;
                }
                 person[j]=0;
                // rep(k,n){
                //     if(a[j][k]==1){
                //         if(person[k]==1) {
                //             flag=false;
                //             break;
                //         }
                //         person[k]=0;
                //     }
                //     else if(a[j][k]==0){
                //         if(person[k]==0) {
                //             flag=false;
                //             break;
                //         }
                //         person[k]=1;
                //     }
                // }
            }
        }
        if(flag)ans=max(ans,p);
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3592
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
LL N;
int P[15];

bool Chk(LL x) {
	int sum = 0;
	int i = 1;
	int tmp = x;
	while(tmp) {
		P[i] = tmp % 10;
		tmp /= 10;
		i++;
	}
	while(i--) sum += P[i];
	if(x % sum == 0) return true;
	else return false;
}

int main() {
	while(~scanf("%lld", &N)) {
		if(Chk(N)) puts("Yes");
		else puts("No");
	}
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int W,H,x,y,r;
  scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
  if((x+r)<=W && (x-r)>=0){
    if((y+r)<=H && (y-r)>=0){
      printf("Yes\n");
    }else{
      printf("No\n");
    }
  }else{
    printf("No\n");
  }
  return 0;
}

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

int main (){
    int a,b;
    cin>>a>>b;
    int x=0,y=0;
    for(int i=1;i<=b;i++)x+=pow(10,i-1)*a;
    for(int i=1;i<=a;i++)y+=pow(10,i-1)*b;
    cout<<max(x,y)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#define Nil -1
#define maxn 100005
using namespace std;
int n,root;
int dep[maxn]; 

struct node
{
    int parent;
    int left_son;
    int right_brother;
    node():parent(Nil),left_son(Nil),right_brother(Nil) {}
};
node t[maxn];

void build()
{
    for(int i=0; i<n; ++i)
    {
        int num,ns,l;
        scanf("%d%d",&num,&ns);
        for(int j=0; j<ns; ++j)									//?????????????????¨??????
        {
            int son;
            scanf("%d",&son);
            if(j==0) t[num].left_son=son;
            else t[l].right_brother=son;
            l=son;
            t[son].parent=num;
        }
    }
    return ;
}

int find_root()
{
    int x;
    for(int i=0; i<n; ++i)
        if(t[i].parent==Nil)
        {
            x=i;
            break;
        }
    return x;
}

void rec(int num,int d)
{
    dep[num]=d;
    if(t[num].right_brother!=Nil) rec(t[num].right_brother,d);
    if(t[num].left_son!=Nil) rec(t[num].left_son,d+1);
    return ;
}

void print(int num)
{
	printf("node %d: ",num);
	printf("parent = %d, ",t[num].parent);
	printf("depth = %d, ",dep[num]);
	if(t[num].parent==Nil) printf("root, [");
	else if(t[num].left_son==Nil) printf("leaf, [");
	else printf("internal node, [");
	for(int i=0,c=t[num].left_son;c!=Nil;i++,c=t[c].right_brother)
	{
		if(i) printf(", ");
		printf("%d",c); 
	}
	printf("]\n");
}

int main()
{
    scanf("%d",&n);
    build();
    root=find_root();
    rec(root,0);
    for(int i=0; i<n; ++i)
        print(i);
    return 0;
}

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

int main()
{
    ll n,k,s,x;
    cin>>n>>k>>s;
    if(s!=1000000000) x=s+1;
    else x=s-1;
    if(k==0)
    {
        for(ll i=0;i<n;i++)
        {
            cout<<x<<" ";
        }
    }
    else
    {
        for(ll i=0;i<k;i++)
        {
            cout<<s<<" ";
        }
        ll p=n-k;
        for(ll i=1;i<=p;i++)
        {
            cout<<x<<" ";
        }
    }
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x,y,a,b;
  scanf("%d%d%d%d",&x,&y,&a,&b);
  if(x<a){
    if(y>a)
      if(y<=b)
        cout<<y-a<<endl;
      else
        cout<<b-a<<endl;
    else
      cout<<0<<endl;
  }else if(x==a){
    cout<<min(y,b)<<endl;
  }else{
    if(b>x)
      if(b<=y)
        cout<<b-x<<endl;
      else
        cout<<y-x<<endl;
    else
      cout<<0<<endl;
  }
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N;
vector<ll> A;

int main() {
  cin >> N;
  A.resize(N);
  rep(i, N) cin >> A[i];

  vector<ll> S(N + 1, 0);
  rep(i, N) S[i + 1] = S[i] + A[i];

  ll ans = 1e18;
  rep(i, N - 1) {
    ll l = S[i + 1], r = S[N] - S[i + 1];
    ans = min(ans, abs(l - r));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using in6 = int64_t;
using ind = double;
using vi = vector<in6>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<in6,in6>;
using psi = pair<string,in6>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

void yes() {
  cout << "Yes";
}

void no() {
  cout << "No";
}

int main() {
  kyun;
  in6 a,b;
  cin >>a >> b;
  if(a > b) cout << 2 * a -1;
  else if(b > a) cout << 2 * b -1;
  else cout << a*2;
  hinata;
}

Measured memory_bytes: 256
K,N=map(int,input().split())
A=list(map(int,input().split()))

ans=float("inf")
for i in range(N):
  g=A[i-1]
  if g>A[i]:
    ans=min(ans,g-A[i])
  else:
    ans=min(ans,K-(A[i]-g))
  g=A[(i+1)%N]
  if g>A[i]:
    ans=min(ans,K-(g-A[i]))
  else:
    ans=min(ans,A[i]-g)
    
print(ans)

Measured memory_bytes: 26444
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <cassert>
#define rep(i, n) for(long long i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(long long i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
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; }
typedef long long ll;
#define pint pair<int,int>
#define pll pair<ll,ll>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, a, b; cin >> n >> a >> b;
    if(n==2) {
        cout << 0 << endl;
        return 0;
    }
    ll num = myPow(2,n,MOD) - 1;
    ll na = n, nb = n;
    ll nn = n-1;
    rep(i,a-1) {
        na *= nn;
        na %= MOD;
        nn--;
    }
    REP(i,1,a+1) {
        na *= modinv(i,MOD)%MOD;
        na %= MOD;
    }
    nn = n-1;
    rep(i,b-1) {
        nb *= nn;
        nb %= MOD;
        nn--;
    }
    REP(i,1,b+1) {
        nb *= modinv(i,MOD)%MOD;
        nb %= MOD;
    }
    ll n2 = (na+nb)%MOD;
    cout << (num+MOD-n2)%MOD << endl;


    return 0;
}

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

using namespace std;

#define ll long long
#define vi vector<int>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int N,M,K;

bool solve(){
    rep(i,M+1){
        rep(j,N+1){
            if((M*j + N*i - 2*i*j) == K){
                return true;
                break;
            }
        }
    }
    return false;
}

int main(){
    cin >> N >> M >> K;

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


Measured memory_bytes: 384
#include<iostream>
#include<cmath>

using namespace std;

int main(){
	int w, h, x, y, r;
	cin>>w>>h>>x>>y>>r;
	w = w-r;
	h = h-r;
	if(x<0||y<0)
		cout<<"No";
	else if(x<=w&&y<=h)
		cout<<"Yes";
	else
		cout<<"No";
	
	cout<<"\n";
	
	return 0;
}


Measured memory_bytes: 3088
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
} P;

P Q[LEN+1];
int head=0,tail=0,n=0;

void enqueue(P x){
  Q[tail] = x;
  if(tail == LEN){
    tail = 0;
  } else {
    tail++;
  }
}

P dequeue(){
  if(head == LEN+1){
    head = 1;
  } else {
    head++;
  }
  return Q[head-1];
}


int main(){
  int elaps=0,c=0;
  int i,q=0;
  P u;
  scanf("%d %d",&n,&q);
  head = 1;
  tail = n+1;
  P t[n+1];

  for(i=1; i <= n; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  
  while(head != tail){
    u = dequeue();
    Q[head-1].t = u.t - q;
    if(Q[head-1].t <= 0){
      c += u.t;
      Q[head-1].t = c;
      t[elaps] = Q[head-1];
      elaps++;
    } else {
      c += q;
      enqueue(Q[head-1]);
    }
  }

  for(i=0; i < n; i++){
    printf("%s %d\n",t[i].name,t[i].t);
  }
  
  return 0;
}



Measured memory_bytes: 16964
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int n, k, ans;
int a[100001];
int dist[100001];
vector<int> child[100001];
map<int, int> _vt[100001];
map<int, int> * pt[100001];

map<int, int> * merge(map<int, int> * x, map<int, int> * y) {
    if (x->size() < y->size()) return merge(y, x);
    for (pii i : *y) {
        (*x)[i.first] += i.second;
    }
    return x;
}

void dfs(int x) {
    pt[x] = _vt + x;
    for (int i : child[x]) {
        dist[i] = dist[x] + 1;
        dfs(i);
        pt[x] = merge(pt[x], pt[i]);
    }
    map<int, int>::iterator it = pt[x]->lower_bound(dist[x] + k);
    if (it != pt[x]->begin()) {
        --it;
        it->second = 1;
        pt[x]->erase(pt[x]->begin(), it);
    }
    else {
        (*pt[x])[dist[x]] = 1;
    }
}

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", a + i);
        dist[i] = -1;
    }
    dist[1] = 0;
    if (a[1] != 1) a[1] = 1, ++ans;
    for (int i = 2; i <= n; ++i) {
        child[a[i]].push_back(i);
    }
    for (int i : child[1]) {
        dist[i] = 1;
        dfs(i);
        for (pii j : (*pt[i])) {
            ans += j.second;
        }
        --ans;
    }
    printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 25984
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define iter vector<int>::iterator
#define mod 998244353



int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,W;
    cin>>n>>W;

    int v[n],w[n];

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

    int dp[n+1][W+1];

    for(int i=0;i<n+1;i++)
    {
    	for(int j=0;j<W+1;j++)
    	{
    		if(i==0 || j==0)
    		{
    			dp[i][j]=0;
    			continue;
    		}
    		if(j-w[i-1]>=0)
    		{
    			dp[i][j]=max(v[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
    		}
    		else
    		{
    			dp[i][j]=dp[i-1][j];
    		}
    	}
    }
    cout<<dp[n][W]<<"\n";

    
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
#define inf 1<<29
using namespace std;

struct edge{ int to,cap,rev; };

int V,E;
int X,Y;
vector<edge> G[202];
bool used[202];

void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,G[to].size()});
  G[to].push_back((edge){from,0,G[from].size()-1});
}

int dfs(int v,int t,int f){
  if(v==t)return f;
  used[v]=true;
  for(int i=0;i<G[v].size();i++){
    edge &e=G[v][i];
    if(!used[e.to] && e.cap>0){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
	e.cap-=d;
	G[e.to][e.rev].cap+=d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow=0;
  for(;;){
    fill(used,used+(X+Y+2),0);
    int f=dfs(s,t,inf);
    if(f==0)return flow;
    flow+=f;
  }
}

int main()
{
  int x,y;
  cin>>X>>Y>>E;
  int s=X+Y;
  int t=s+1;
  for(int i=0;i<X;i++){
    add_edge(s,i,1);
  }
  for(int i=0;i<Y;i++){
    add_edge(X+i,t,1);
  }
  for(int i=0;i<E;i++){
    cin>>x>>y;
    add_edge(x,X+y,1);
  }
  cout<<max_flow(s,t)<<endl;

  return 0;
}

Measured memory_bytes: 1536
H, W = map(int, input().split())
ans = H * W

for i in range(H+1):
  S = [0,0,0]
  S[0] = W * i
  S[1] = W // 2 * (H - i)
  S[2] = H * W - S[0] - S[1]
  ans = min(ans, max(S)-min(S))
  
  S[1] = (H-i) // 2 * W
  S[2] = H * W - S[0] - S[1]
  ans = min(ans, max(S)-min(S))

H, W = W, H
for i in range(H+1):
  S = [0,0,0]
  S[0] = W * i
  S[1] = W // 2 * (H - i)
  S[2] = H * W - S[0] - S[1]
  ans = min(ans, max(S)-min(S))
  
  S[1] = (H-i) // 2 * W
  S[2] = H * W - S[0] - S[1]
  ans = min(ans, max(S)-min(S))
  
print(ans)

Measured memory_bytes: 43356
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for (int i = 0; i < (n); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF=1LL<<60;
const int inf=(1<<30)-1;
const int mod=1e9+7;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    vector<string> a;
    queue<string> que;
    que.push("a");
    while(!que.empty()){
        string t=que.front();
        que.pop();
        int k=t.size();
        if(k==n){
            a.push_back(t);
            continue;
        }
        int m=0;
        for(int i=0;i<t.size();i++){
            chmax(m,t[i]-'a');
        }
        for(int i=0;i<=m+1;i++){
            que.push(t+char(i+'a'));
        }
    }
    sort(a.begin(),a.end());
    for(string x:a){
        cout << x << endl;
    }
}

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

int main() {
  int n, s = 0;
  scanf("%d", &n);
  vector<int> a(n);
  for(int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    s ^= a[i];
  }
  for(int i = 0; i < n; i++) { printf("%d ", s ^ a[i]); }
}

Measured memory_bytes: 4040
#include<cstdio>
#include<algorithm>
#define N_ 8192
#define M_ 210
using namespace std;


struct NTT {
	const int A = 119, B = 23, P = A << B | 1, R = 3;
	const int SZ = 14, N = 1 << SZ;

	int Pow(int x, int y) {
		int r = 1;
		while (y) {
			if (y & 1) r = (long long)r * x % P;
			x = (long long)x * x % P;
			y >>= 1;
		}
		return r;
	}

	void FFT(int *a, bool f) {
		int i, j, k, x, y, z;
		j = 0;
		for (i = 1; i < N; i++) {
			for (k = N >> 1; j >= k; k >>= 1) j -= k;
			j += k;
			if (i < j) {
				k = a[i];
				a[i] = a[j];
				a[j] = k;
			}
		}
		for (i = 1; i < N; i <<= 1) {
			x = Pow(f ? Pow(R, P - 2) : R, P / i >> 1);
			for (j = 0; j < N; j += i << 1) {
				y = 1;
				for (k = 0; k < i; k++) {
					z = (long long)a[i | j | k] * y % P;
					a[i | j | k] = a[j | k] - z;
					if (a[i | j | k] < 0) a[i | j | k] += P;
					a[j | k] += z;
					if (a[j | k] >= P) a[j | k] -= P;
					y = (long long)y * x % P;
				}
			}
		}
		if (f) {
			j = Pow(N, P - 2);
			for (i = 0; i < N; i++) a[i] = (long long)a[i] * j % P;
		}
	}
}NTT1;

int n, m, F[N_*2], InvF[N_*2], D[N_*2], C[N_ * 2], ND[N_], T[N_];
int main() {
	int i, j, k;
	scanf("%d%d", &n, &m);
	D[0] = 1;
	F[0] = 1;
	for (i = 1; i <= N_; i++)F[i] = 1ll * F[i - 1] * i%NTT1.P;
	InvF[N_] = NTT1.Pow(F[N_], NTT1.P - 2);
	for (i = N_; i >= 1; i--)InvF[i - 1] = 1ll * InvF[i] * i%NTT1.P;
	for (int i = 0; i < N_; i++)C[i] = InvF[i];
	NTT1.FFT(C, false);
	for (i = 1; i <= m; i++) {
		for (j = 0; j <= n; j++) {
			T[j] = D[j];
			D[j] = 1ll * D[j] * InvF[j] % NTT1.P;
		}
		NTT1.FFT(D, false);
		for (j = 0; j < N_+N_; j++)D[j] = 1ll * D[j] * C[j] % NTT1.P;
		NTT1.FFT(D, true);
		for (j = 0; j <= n; j++) {
			ND[j] = (1ll * NTT1.P * 3 + 1ll * D[j + 2] * F[j + 2] % NTT1.P - T[j + 2] - 1ll * T[j + 1] * (j + 2) % NTT1.P - 1ll*j*T[j]%NTT1.P) % NTT1.P;
		}
		for (j = 0; j <= n; j++)D[j] = ND[j];
		for (j = n + 1; j < N_+N_; j++)D[j] = 0;
	}

	int res = 0;
	for (i = 0; i <= n; i++) {
		res = (res + 1ll * F[n]*InvF[i]% NTT1.P*InvF[n-i]%NTT1.P * D[i]) % NTT1.P;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  int d, t, s;
  cin >> d >> t >> s;
  int tmp = d / s;
  if (d % s != 0) tmp++;
  if (tmp > t) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 3596
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Node {
	int key;
	Node prev;
	Node next;

	Node() {
		key = -1;
		prev = null;
		next = null;
	}
}

class Linked {
	Node nil;
	int N;

	Linked() {
		nil = new Node();
		nil.next = nil;
		nil.prev = nil;
		N = 0;
	}

	void InsertFirst(int val) { //最初に挿入
		Node X = new Node();
		X.key = val;
		X.next = nil.next;
		nil.next.prev = X;
		nil.next = X;
		X.prev = nil;
	}

	Node Search(int val) {
		Node ima = nil.next;
		while ((ima != nil) && (ima.key != val)) {
			ima = ima.next;
		}
		return ima;
	}

	void DeleteNode(Node X) {
		if (X == nil) {
			return;
		}
		X.prev.next = X.next;
		X.next.prev = X.prev;
	}

	void DeleteFirst() {
		DeleteNode(nil.next);
	}

	void DeleteLast() {
		DeleteNode(nil.prev);
	}

	void SearchDelete(int val) {
		DeleteNode(Search(val));
	}
	void print() {
		for(Node ima = nil.next;ima != nil; ima = ima.next) {
				if(ima != nil.next) {
					System.out.print(" ");
				}
				System.out.print(ima.key);
		}
		System.out.println();
	}
}

public class Main {

	public static void main(String[] args) throws IOException {
		Linked S = new Linked();
		BufferedReader br;
		br = new BufferedReader(new InputStreamReader(System.in));
		String a = br.readLine();
		int n = Integer.parseInt(a);
		for (int i = 0; i < n; i++) {
			a = br.readLine();
			if(a.charAt(6)== ' ') {
				if(a.charAt(0) == 'i') {
					String[] b = a.split(" ");
					//b[0] = insert
					//b[1] = 数字
					int c = Integer.parseInt(b[1]);
					S.InsertFirst(c);
				}
				else if(a.charAt(0) == 'd') {
					String[] b = a.split(" ");
					//b[0] = insert
					//b[1] = 数字
					int c = Integer.parseInt(b[1]);
					S.SearchDelete(c);
				}
			}

			else if (a.charAt(6) == 'L') {
				S.DeleteLast();
			}else if(a.charAt(6) == 'F') {
				S.DeleteFirst();
			}
		}

		S.print();

	}

}



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

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main() {
	int n, xx;
	cin >> n >> xx;
	long long x[n];
	cin >> x[0];
	long long ans = abs(x[0] - xx);
	for (int i = 1;i < n;i++) {
		cin >> x[i];
		ans = GCD(ans, abs(x[i] - xx));
	}
	cout << ans << endl;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a;
	string s;
	cin >> a;
	cin >> s;
	if (a >= 3200) cout << s << endl;
	else cout << "red" << endl;
}

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

public class Main {
	Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
	
	void run() {
		int h = sc.nextInt();
		int w = sc.nextInt();
		
		int ch[][] = new int[h+2][w+2];
		
		
		Arrays.fill(ch[0], -1);
		Arrays.fill(ch[h+1], -1);

		for(int i = 1; i <= h ; i++) {
			String str = sc.next();
			Arrays.fill(ch[i],-1);
			for(int j = 1; j <= w; j++) {
				if(str.charAt(j-1) == '#') {
					ch[i][j] = 0;
				}
			}
		}
		
	
		int u[][] = new int[h+2][w+2];
		int d[][] = new int[h+2][w+2];

		int r[][] = new int[h+2][w+2];
		int l[][] = new int[h+2][w+2];
		
		for(int i = 1; i <= h ; i++) {
			for(int j = 1 ; j <= w; j++) {				
				if(ch[i][j] == 0) {
					u[i][j] = 1;
				}else if(u[i-1][j] != 0){
					u[i][j] = u[i-1][j]+1;
				}
			}
		}

		for(int i = 1; i <= h ; i++) {
			for(int j = 1 ; j <= w; j++) {				
				if(ch[h-i+1][j] == 0) {
					d[h-i+1][j] = 1;
				}else if(d[h-i+2][j] != 0){
					d[h-i+1][j] = d[h-i+2][j]+1;
				}
			}
		}
		
		int ud[][] = new int[h+2][w+2];
		
		Arrays.fill(ud[0],Integer.MAX_VALUE/2);
		Arrays.fill(ud[h+1],Integer.MAX_VALUE/2);
		for(int i = 1 ; i <= h; i++ ) {
			ud[i][0] = Integer.MAX_VALUE/2;
			ud[i][w+1] = Integer.MAX_VALUE/2;
			for(int j = 1; j<=w;j++) {
				int min = Integer.MAX_VALUE/2;
				if(u[i][j] !=0 ) {
					min = Math.min(u[i][j], min);
				}
				if(d[i][j] != 0) {
					min = Math.min(d[i][j], min);
				}
				ud[i][j] = min -1;
			}
		}

		Arrays.fill(l[0],Integer.MAX_VALUE/2);
		Arrays.fill(l[h+1],Integer.MAX_VALUE/2);

		for(int i = 1; i <= h ; i++) {
			l[i][0] = Integer.MAX_VALUE/2;
			l[i][w+1] = Integer.MAX_VALUE/2;

			for(int j = 1 ; j <= w; j++) {
				l[i][j] = Math.min(ud[i][j], l[i][j-1]+1);
			}
		}
		
		Arrays.fill(r[0],Integer.MAX_VALUE/2);
		Arrays.fill(r[h+1],Integer.MAX_VALUE/2);
		for(int i = 1; i <= h ; i++) {
			r[i][0] = Integer.MAX_VALUE/2;
			r[i][w+1] = Integer.MAX_VALUE/2;
			for(int j = 1 ; j <= w; j++) {
				r[i][w-j+1] = Math.min(ud[i][w-j+1], r[i][w-j+2]+1);
			}
		}
		
		int lr[][] = new int[h+2][w+2];
		
		int max = 0;
		for(int i = 1; i <= h ; i++) {
			for(int j =1 ; j <= w;j++) {
				int min = Integer.MAX_VALUE/2;
				min = Math.min(min, l[i][j]);
				min = Math.min(min, r[i][j]);
				lr[i][j] = min;
				max = Math.max(min,max);
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 66512
n = int(input())

if n == 1:
    print(0)
    exit()

x = n ** 0.5
d = {}
z = 2
ans = 0
while True:
    if n % z == 0:
        n //= z
        if d.get(z) == None:
            d[z] = 1
        else:
            d[z] += 1
    else:
        z += 1
    if n == 1:
        break
    if x < z:
        ans = 1
        break
    
for dv in d.values():
    i = 1
    while True:
        dv -= i
        i += 1
        if dv < 0:
            break
        
        ans += 1

print(ans)


Measured memory_bytes: 63628
/*
  NAME : RISHABH SINGH
  INSTITUTION : DELHI TECHNOLOGICAL UNIVERSITY
*/
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pii pair<int, int>
#define bi __builtin_inf()
#define ll long long
#define mp make_pair
#define ss second
#define pb push_back
#define ff first
#define speed_cubing ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define um unordered_map
#define us unordered_set
#define bp __builtin_popcount
#define ld long double
#define rep(n) for (int i = 0; i < n; i++)
#define pll pair<ll, ll>
#define mx = 1e18;
#define lb(v, val) (lower_bound(v.begin(), v.end(), val) - v.begin())
#define ub(v, val) (upper_bound(v.begin(), v.end(), val) - v.begin())
#define PI 3.1415926535
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
#define sz(v) (int)v.size()
#define endl '\n'
const int N = 1e4;
const int mod = 998244353;
ll mul_inv(ll a,ll b = mod) {ll t1=a,t2=b,t3,v1=1,v2=0,v3;while(t2!=1){ll x=t1/t2;t3=t1-x*t2;v3=v1-x*v2;t1=t2,t2=t3;v1=v2,v2=v3;}return(v2+b)%b;}


int32_t main(){
   
   speed_cubing 
   
   int n;
   cin>>n;

   vector<int> a(n);

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

   map<int,int> m;

   int ans = 0;


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

   
   cout<<ans;

    
   return 0;
}


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

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

    ll n, m;
    cin >> n >> m;

    map<ll, ll> mp;
    rep(i, n){
        ll a;
        cin >> a;
        ++mp[a];
    }

    rep(i, m){
        ll b, c;
        cin >> b >> c;
        mp[c] += b;
    }

    ll res = 0;
    ll cnt = 0;
    for(auto itr = mp.rbegin(); itr != mp.rend(); ++itr){
        ll key = itr->first;
        ll val = itr->second;

        if(cnt+val <= n){
            res += key * val;
            cnt += val;

            if(cnt == n) break;
        }
        else{
            res += key * (n-cnt);
            break;
        }
    }

    cout << res << endl;




    

    return 0;
}

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

int a[(int)2e5+5];
int  main ()
{
    int n;
    cin>>n;
    int maxn=0,maxnn=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>maxn)
        maxn=a[i];
        else if(a[i]>maxnn)
            maxnn=a[i];

    }
    for(int i=0;i<n;i++)
        if(a[i]!=maxn)
        cout<<maxn<<endl;
    else
        cout<<maxnn<<endl;
    return 0;
}


Measured memory_bytes: 2432
#include <stdio.h>
int main(void)
{
  int tlen=0,slen=0,i,j,cnt=0,min=1001;
  char s[1001],t[1001];
  scanf("%s%s", s,t);
  while(t[tlen])tlen++;
  while(s[slen])slen++;
  for(i=0;i<slen+1-tlen;i++){
    for(j=0;j<tlen;j++){
      if(s[i+j] != t[j]) cnt++;
    }
    if(min>cnt) min=cnt;
    cnt=0;
  }
  printf("%d", min);
  return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<int, int> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };


int main() {

	int n;
	cin >> n;
	ll ans = 1;
	for (int i = 1; i < n + 1; i++) {
		ans = ans * i % mod;
	}
	cout << ans << endl;
	
	return 0;
}

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

int main(){
  int a[5];
  for(int i=0; i<5; i++){
    cin >> a[i];
  }
  int k;
  cin >> k;

  if((a[4]-a[0])<=k){
    cout << "Yay!" << endl;
  }
  else {
    cout << ":(" << endl;
  }
}

 
    


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int N, M;
    while (cin >> N >> M) {
        vector<long long> a(N*2);
        for (int i = 0; i < N*2; ++i) cin >> a[i];
        sort(a.begin(), a.end());

        // [mid, N*2) が大きいものと小さいものをペアにしていったときにすべて >= M となるような最小の mid を求める
        int low = -1, high = N*2;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            long long mi = M;
            for (int i = mid, j = N*2-1; i < j; ++i, --j) chmin(mi, a[i]+a[j]);
            if (mi >= M) high = mid;
            else low = mid;

            //cout << mid << ": " << mi << endl;
        }
        int alt = high/2*2;

        long long res = 1LL<<60;
        for (int num = max(0, alt-10); num <= min(N*2, alt+10); num += 2) {
            long long tmp = 0;
            for (int i = 0, j = num-1; i < j; ++i, --j) chmax(tmp, (a[i]+a[j])%M);
            for (int i = num, j = N*2-1; i < j; ++i, --j) chmax(tmp, (a[i]+a[j])%M);
            chmin(res, tmp);
        }
        cout << res << endl;
    }
}


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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


		int n = Integer.parseInt(br.readLine());

		int[] input = new int[n];


		for(int i = 0; i < n; i++){
			input[i] = Integer.parseInt(br.readLine());
		}


		System.out.println(n - gradLTS(input));


	}

//	static int gradLTS(int array[]){
//		int n = array.length;
//
//		int[] dp = new int[n];
//
//		int result = 0;
//		for(int i = 0; i < n ; i++){
//			dp[i] = 1;
//			for(int j = 0; j < i ; j++){
//				if(array[j]+1 == array[i] ){
//					dp[i] = Math.max(dp[i], dp[j] + 1);
//				}
//			}
//
//			result = Math.max(result, dp[i]);
////			System.out.println("dp["+i+"] = "+dp[i]);
//		}
//
//		return result;
//
//	}

	static int gradLTS(int array[]){
		int n = array.length;

		int[] dp = new int[n + 1];
		int[] index = new int[n + 1];

		Arrays.fill(dp, Integer.MAX_VALUE);
		Arrays.fill(index, -1);

		for(int i = 0; i < n; i++){

//			int tmpIndex = Arrays.binarySearch(dp, array[i] - 1);
			int tmpIndex = index[array[i] - 1];

//			System.out.println("index of "+(array[i] - 1)+ " is "+tmpIndex);
			if(tmpIndex >= 0){
				dp[tmpIndex] = array[i];
				index[array[i]] = tmpIndex;
			}
			else {
				dp[array[i]] = array[i];
				index[array[i]] = array[i];
			}

			//debug
//			for(int j = 1; j <= n; j++){
//				System.out.print(dp[j]+" ");
//			}
//			System.out.println();
		}

		int result = 0;

		for(int i = 1; i <= n; i++){
//			System.out.println("from "+i+" to "+dp[i]);
			if(dp[i] != Integer.MAX_VALUE){
				result = Math.max(result, dp[i] - i + 1);
			}
		}

		return result;
	}


}


Measured memory_bytes: 38696
#include<stdio.h>

int main(void)
{
  int w,a,b,abs;
  scanf("%d %d %d",&w,&a,&b);
  if(a < b)
    {
      abs = b - a;
      a += w;
    }
  else
    {
      abs = a - b;
      b += w;
    }
  if(abs <= w)
    {
      printf("0\n");
      return 0;
    }
  printf("%d\n",abs-w);
  return 0;
}


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

int main(){
	int N, Q, l, r, i;
	scanf("%d%d", &N, &Q);
	vector<char> S(N + 1, 'X');
	scanf("%s", S.begin() + 1);
	vector<int> sum(N + 1, 0);
	for(i = 1; i <= N; i++){
		sum[i] = sum[i - 1];
		if(S[i - 1] == 'A' && S[i] == 'C'){
			sum[i]++;
		}
	}
	for(i = 0; i < Q; i++){
		scanf("%d%d", &l, &r);
		printf("%d\n", sum[r] - sum[l]);
	}
	return 0;
}

Measured memory_bytes: 1280
#include <algorithm>
#include <array>
#include <climits>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <numeric>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#ifdef ENABLE_ASSERT
#include <cassert>
#else
#undef assert
#define assert static_cast<void>(0)
#endif

using namespace std;
using namespace std::literals;

int main() {
  int a, b;
  cin >> a>>b;
  int ans = a-2*b;

  cout << (ans < 0 ? 0 : ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 200005
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d\n", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;

int Set(int N, int pos){return N=N | (1<<pos);}
int reset(int N, int pos){return N=N & ~(1<<pos);}
bool check(int N, int pos){return (bool)(N & (1<<pos));}

int dp[22][(1<<22)+2];
int n, a[22][22];

int call(int pos, int mask)
{
    if(pos>=n)
        return 1;
    if(dp[pos][mask]!=-1)
        return dp[pos][mask];
    int& ret = dp[pos][mask] = 0;
    for(int i = 0; i < n; i++)
    {
        if(a[pos][i]==0)
            continue;
        if(check(mask,i)==0)
            ret = (ret + call(pos+1, Set(mask,i)))%MOD;
    }
    return ret;
}

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    memset(dp, -1, sizeof(dp));
    cin>>n;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin>>a[i][j];
    cout<<call(0, 0)<<endl;

    //End();
    return 0;
}


Measured memory_bytes: 360704
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node
{
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

Node* treeMinimum(Node* x) {
	while (x->left != NIL) x = x->left;
	return x;
}

Node* find(Node *u, int k) {
	while (u != NIL && k != u->key) {
		if (k < u->key) u = u->left;
		else u = u->right;
	}
	return u;
}

Node* treeSuccessor(Node* x) {
	if (x->right != NIL) return treeMinimum(x->right);
	Node* y = x->parent;
	while (y != NIL && x == y->right) {
		x = y;
		y = y->parent;
	}
	return y;
}

void treeDelete(Node* z) {
	Node *y;
	Node *x;

	if (z->left == NIL || z->right == NIL) y = z;
	else y = treeSuccessor(z);

	if (y->left != NIL) {
		x = y->left;
	}
	else
	{
		x = y->right;
	}

	if (x != NIL) {
		x->parent = y->parent;
	}

	if (y->parent == NIL) {
		root = x;
	}
	else {
		if (y == y->parent->left) {
			y->parent->left = x;
		}
		else {
			y->parent->right = x;
		}
	}

	if (y != z) {
		z->key = y->key;
	}
	free(y);
}

void insert(int k) {
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		}
		else
		{
			x = x->right;
		}
	}

	z->parent = y;
	if (y == NIL) {
		root = z;
	}
	else {
		if (z->key < y->key) {
			y->left = z;
		}
		else {
			y->right = z;
		}
	}
}

void inorder(Node *u) {
	if (u == NIL) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preorder(Node *u) {
	if (u == NIL) return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}

int main() {
	int n, i, x;
	string com;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		cin >> com;
		if (com == "insert") {
			scanf("%d", &x);
			insert(x);
		}
		else if (com == "find")
		{
			scanf("%d", &x);
			Node *t = find(root, x);
			if (t != NIL)printf("yes\n");
			else printf("no\n");
		}
		else if (com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		else if(com == "delete")
		{
			scanf("%d", &x);
			treeDelete(find(root, x));
		}
	}
	return 0;
}


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

int main(){
	int k,c,sum;
	while(cin>>k,k!=0){
		sum=0;
		for(int i=0;i<k*(k-1)/2;i++){
			cin>>c;sum+=c;
		}
		cout<<sum/(k-1)<<endl;
	}

}

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

using ll = long long;

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

    string S;
    cin >> S;

    if (S.size() == 3) {
        swap(S[0], S[2]);
    }

    cout << S << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef vector<int> vi;
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;

class UnionFind{
public:
	vector<int> ran, par;
	void init(int n){
		for(int i = 0;i < n;i++){
			par.push_back(i);
			ran.push_back(0);
		}
	}
	
	int find(int x){
		if(par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	
	void unite(int x, int y){
		x = find(par[x]);
		y = find(par[y]);
		if(x == y)return;
		if(ran[x] < ran[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(par[x] == par[y])ran[x]++;
		}
	}
	
	bool same(int x, int y){
		return find(par[x]) == find(par[y]);
	}
};

int a[100010];
signed main(){
	int n, m;
	UnionFind UF;
	UF.init(1000000);
	scanf("%lld%lld", &n, &m);
	rrep(i,n)scanf("%lld", &a[i]);
	rep(i,m){
		int x, y;
		scanf("%lld%lld", &x, &y);
		UF.unite(x, y);
	}
	
	int ans = 0;
	rrep(i,n){
		if(UF.same(i, a[i]))ans++;
	}
	printf("%lld\n", ans);
	return 0;
}




Measured memory_bytes: 16852
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my $s = <STDIN>);
my $n = length $s;

if ($s eq reverse($s)) {
  my $t = substr($s,0,int(($n-1)/2));
  my $u = substr($s, int(($n+3)/2)-1, $n);
  if ($t eq reverse($t) && $u eq reverse($u)) {
    say "Yes";
  } else {
    say "No";
  }
} else {
  say "No";
}

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

int main() {
  string S; cin >>S;
  vector<bool> flag(3);
  rep(i,0,3) {
    flag[int(S[i]-97)]=true;
  }
  int count=0;
  rep(i,0,3) {
    if (flag[i]) count++;
  }
  cout <<(count==3 ? "Yes":"No") <<endl;
  return 0;
}


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

k_5 = n // 5
k_3 = n // 3
k_15 = n // 15

sum_5 = 5 * k_5 * (k_5 + 1) / 2 
sum_3 = 3 * k_3 * (k_3 + 1) / 2 
sum_15 = 15 * k_15 * (k_15 + 1) / 2 
sum_n = n * (n+1) / 2

answer = sum_n - sum_3 - sum_5 +sum_15
print(int(answer))

Measured memory_bytes: 9200
#include<iostream>
using namespace std;
int main()
{
 int r, g, b;
  cin >> r >> g >> b;
  if ((r*100 + g*10 + b) % 4 == 0) {
  	cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

void cal_score(vector<ll> &c, vector<vector<ll>> &s, ll &score, vector<ll> v, vector<ll> &mai) {
	ll n = v.size() - 1;
	score += s[n][v.back()];
	REP(i, 26)mai[i]++;
	mai[v.back()] = 0;
	REP(i, 26)score -= c[i] * mai[i];
}

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

	ll d;cin >> d;
	vector<ll> c(26);REP(i, 26)cin >> c[i];
	vector<vector<ll>> s(d, vector<ll>(26));
	REP(i, d)REP(j, 26)cin >> s[i][j];

	vector<pair<ll, pair<vector<ll>, vector<ll>>>> lis;
	REP(i, 26){
		vector<ll> v(1, i);
		vector<ll> mai(26, 0);
		ll score = 0;
		cal_score(c, s, score, v, mai);
		lis.EB(score, MP(v, mai));
	}

	REP(i, d-1){
		sort(ALL(lis), greater<pair<ll, pair<vector<ll>, vector<ll>>>>());
		lis.resize(min((ll)lis.size(), 200LL));
		vector<pair<ll, pair<vector<ll>, vector<ll>>>> now;

		for(auto seica: lis){
			REP(i, 26){
				vector<ll> v = seica.SE.FI;v.PB(i);
				vector<ll> mai = seica.SE.SE;
				ll score = seica.FI;
				cal_score(c, s, score, v, mai);
				now.EB(score, MP(v, mai));
			}
		}

		lis = now;
	}

	sort(ALL(lis), greater<pair<ll, pair<vector<ll>, vector<ll>>>>());
	REP(i, d){
		cout << (lis[0].SE.FI[i]+1) << endl;
	}


	return 0;
}


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

int cmpstr(const void*a, const void*b){
    const char *x=a, *y=b;


    return strcmp(x,y);

}

int main(){
    int n, l, i;
    scanf("%d %d", &n, &l);
    char s[n][l+1];
    for(i=0;i<n;i++){
        scanf("%s\n", s[i]);
    }
    //ordenar str
    qsort(s, n, sizeof(s[0]), cmpstr);
    for(i=0;i<n;i++){
        printf("%s", s[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 252