akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int N,M;
  int k[11];
  int s[11][11];
  int p[11];
  int res=0;
  cin >> N >> M;
  rep(i,M){
    cin >> k[i];
    rep(j,k[i]){
      cin >> s[i][j];
      s[i][j]--;
    }
  }
  rep(i,M) cin >> p[i];

  rep(n,1<<N){//pattern                                                                  
    bool allLightsOn=true;
    rep(j,M){//lights                                                                    
      int nOnSwitches=0;
      rep(kk,k[j]){//switches                                                            
        if((1<<s[j][kk]) & n) nOnSwitches++;
      }
      if (nOnSwitches%2!=p[j]) {
        allLightsOn=false;
        break; // to next lights                                                         
      }
    }
    if(allLightsOn) res++;
  }

  cout << res << endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define rer(i, a, b) for (int i = (int)a; i <= (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int inf = 1000000000;
const int mod = 1000000007;
const double EPS = 1e-9;
const int dx[] = { -1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};

int n, r;
int p, c;

int main() {
	while (cin >> n >> r, n && r) {
		if (n == 1) {
			cout << 1 << endl;
			continue;
		}

		vector<int> card;
		for (int i = n; i > 0; --i) card.push_back(i);
		rep(i, r) {
			cin >> p >> c;
			vector<int> tmp;
			rep(j, c) tmp.push_back(card[p - 1 + j]);
			rep(j, p - 1) tmp.push_back(card[j]);
			REP(j, p + c - 1, n) tmp.push_back(card[j]);
			card = tmp;
		}
		cout << card[0] << endl;
	}
}

Measured memory_bytes: 1220
a, b, k = map(int, input().split())
for i in range(k):
    if i % 2 == 0:
        if a % 2 == 1:
            a -= 1
        b += a // 2
        a //= 2
    else:
        if b % 2 == 1:
            b -= 1
        a += b // 2
        b //= 2
print(a, b)


Measured memory_bytes: 38384
N, Y = map(int, input().split())

for x in range(N + 1):
    for y in range(N - x + 1):
        z = N - x - y
        if 10000 * x + 5000 * y + 1000 * z == Y:
            print(x, y, z)
            exit()
else:
    print(-1, -1, -1)


Measured memory_bytes: 2940
import sys
import math
import collections
import itertools
import array
import inspect
import bisect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(list(map(int, input())))
    return li

# --------------------------------------------

dp = None

def main():
    N = int(input())
    A = sorted(list(map(int, input().split())))
    B = sorted(list(map(int, input().split())))
    C = sorted(list(map(int, input().split())))

    ans = 0

    for b in B:
        a_idx = bisect.bisect_left(A, b)
        c_idx = bisect.bisect_right(C, b)

        ans += a_idx * (N - c_idx)

    print(ans)




main()


Measured memory_bytes: 24700
primes = []
boo = [True] * (int(1e6) + 1)
boo[0] = False; boo[1] = False
for i in range(2, len(boo)):
    if boo[i]:
        for j in range(i*i, len(boo), i):
            boo[j] = False
        primes.append(i)
        
# Finds the prime factors of a number
def findPF(num):
    ans = []
    PF_idx = 0
    PF = primes[PF_idx]
    while PF * PF <= num:
        while num % PF == 0:
            num //= PF
            ans.append(PF)
        PF_idx += 1
        PF = primes[PF_idx]
    if num != 1:
        ans.append(num)
    return ans

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

a, b = map(int, input().split())
temp = gcd(a, b)
print(len(set(findPF(temp)))+1)


Measured memory_bytes: 19792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{
	int to,cap,cost,rev;
};
typedef vector<edge> ve;
typedef vector<ve> vve;
class MCF{	//Minimum Cost Flow
	public:
	int n;
	vve G;
	vi h,dist,prev,pree;
	MCF(int size){
		n=size;
		G=vve(n);
		h=dist=prev=pree=vi(n);
	}
	void add_edge(int s,int t,int ca,int co){
		edge e={t,ca,co,G[t].size()};
		G[s].pb(e);
		edge ee={s,0,-co,G[s].size()-1};
		G[t].pb(ee);
	}
	int mcf(int s,int t,int f){
		int out=0;
		h=vi(n);
		while(f>0){			
			priority_queue<pii,vector<pii> >q;
			dist=vi(n,inf);
			dist[s]=0;
			q.push(pii(0,s));
			while(!q.empty()){
				pii p=q.top();q.pop();
				int v=p.second;
				if(dist[v]<-p.first)continue;
				rep(i,G[v].size()){
					edge &e=G[v][i];
					if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
						dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
						prev[e.to]=v;
						pree[e.to]=i;
						q.push(pii(-dist[e.to],e.to));
					}
				}
			}
			if(dist[t]==inf)return -1;
			rep(i,n)h[i]+=dist[i];
			int d=f;
			for(int v=t;v!=s;v=prev[v])d=min(d,G[prev[v]][pree[v]].cap);
			f-=d;
			out+=d*h[t];
			for(int v=t;v!=s;v=prev[v]){
				edge &e=G[prev[v]][pree[v]];
				e.cap-=d;
				G[v][e.rev].cap+=d;
			}
		}
		return out;	
	}
};
int main(){
	int n;
	cin>>n;
	map<int,int>ma;
	int co=0;
	int sum=0;
	vp in;
	rep(i,n){
		int a,b;
		cin>>a>>b;
		sum+=a+b;
		in.pb({a,b});
		if(ma[a]==0)ma[a]=++co;
		if(ma[b]==0)ma[b]=++co;
	}
	MCF mcf(2+n+co);
	int s=n+co,t=s+1;
	rep(i,n)mcf.add_edge(s,i,1,0);
	rep(i,co)mcf.add_edge(n+i,t,1,0);
	rep(i,n){
		mcf.add_edge(i,n+ma[in[i].first]-1,1,in[i].first);
		mcf.add_edge(i,n+ma[in[i].second]-1,1,in[i].second);
		mcf.add_edge(i,t,1,in[i].first+in[i].second);
	}
	int flow=mcf.mcf(s,t,n);
	cout<<sum-flow<<endl;
}

Measured memory_bytes: 3476
#include<stdio.h>
#define MAX 10000
#define NIL -1

typedef struct N {
  int p, l ,r;
} Node;

Node T[MAX];
int n;

void preParse(int u){
  if( u == NIL ) return;
  printf(" %d", u);
  preParse(T[u].l);
  preParse(T[u].r);
}

void inParse(int u){
  if( u == NIL ) return;
  inParse(T[u].l);
  printf(" %d", u);
  inParse(T[u].r);
}

void postParse(int u){
  if( u == NIL ) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d", u);
}

int main(){
  int i, v, l, r, root;

  scanf("%d", &n);

  for( i = 0 ; i < n ; i++ ){
    T[i].p = NIL;
  }

  for( i = 0 ; i < n ; i++ ){
    scanf("%d %d %d", &v, &l, &r);
    T[v].l = l;
    T[v].r = r;
    if( l != NIL ) T[l].p = v;
    if( r != NIL ) T[r].p = v;
  }

  for( i = 0 ; i < n ; i++ ) if( T[i].p == NIL ) root = i;

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2048
#include <stdio.h>          // printf(), scanf()

int
main(int argc, char** argv)
{
	int i, x;

	for (i = 1;; ++i)
	{
		scanf("%d", &x);
		if (x == 0)
			break;

		printf("Case %d: %d\n", i, x);
	}

	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long int;using ld = long double;using P = pair<ll,ll>;const int MOD = (int)1e9+7;const string rt = "\n";const string sp = " ";/* 最大公約数 */template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}/* UnionFind */template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};/* コンビネーション */template<typename T> ll combpm(T N_, T C_) {const int NUM_=400001;static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];if (fact[0]==0) {inv[1]=fact[0]=factr[0]=1;for (int i=2;i<=NUM_;++i) inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%MOD, factr[i]=factr[i-1]*inv[i]%MOD;}if(C_<0 || C_>N_) return 0;return factr[C_]*fact[N_]%MOD*factr[N_-C_]%MOD;}/* 多次元ベクター */template<class T>vector<T> multi_vector(size_t a){return vector<T>(a);}template<class T, class... Ts>auto multi_vector(size_t a, Ts... ts){return vector<decltype(multi_vector<T>(ts...))>(a, multi_vector<T>(ts...));}/* テスト関数 */void test(ll n){cout << "test" << n << endl;}/* 小数点以下 */void fixsp(ll n){cout << fixed << setprecision(n);}void defsp(ll n){cout << defaultfloat << setprecision(n);}/* 重み付きUnionFind */struct WUnionFind {vector<int> par;vector<int> rank;WUnionFind(int n = 1) {init(n);}void init(int n = 1) {par.resize(n); rank.resize(n);for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;}int root(int x) {if (par[x] == x) {return x;}else {int r = root(par[x]);return par[x] = r;}}bool issame(int x, int y) {return root(x) == root(y);}bool merge(int x, int y) {x = root(x); y = root(y);if (x == y) return false;if (rank[x] < rank[y]) swap(x, y);if (rank[x] == rank[y]) ++rank[x];par[y] = x;return true;}};/* IO高速化 */void fastio(){ios::sync_with_stdio(false);cin.tie(NULL);}
/* ここからコード開始 */

int main(){
  fastio;
  ll N;
  cin >> N;
  ll R = N/2*2;
  ll sum{};
  vector<P> ans;
  rep(i, 1, R+1){
    rep(j, i+1, R+1){
      if(i + j != R+1){
        ans.push_back(P(i, j));
        sum++;
      }
    }
  }
  rep(i, 1, N*(N%2)){
    ans.push_back(P(i, N));
    sum++;
  }
  cout << sum << rt;
  for(auto&& i : ans){
    cout << i.first << sp << i.second << rt;
  }
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

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

//------------------------------------------------

int n;
int sum[100];

int f(int x, int y) {
	return x > y ? 3 : x == y ? 1 : 0;
}

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

	cin >> n;
	REP(i, n * (n - 1) / 2) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		a--, b--;
		sum[a] += f(c, d);
		sum[b] += f(d, c);
	}
	vector<P> v;
	REP(i, n) v.pb(P(sum[i], i));
	sort(ALL(v));
	reverse(ALL(v));
	int rank[n], now = 1, prv_pt = -1;
	REP(i, n) {
		if (v[i].fi == prv_pt) {
			rank[v[i].se] = now;
		}
		else {
			rank[v[i].se] = i + 1;
			prv_pt = v[i].fi;
			now = i + 1;
		}
	}
	REP(i, n) cout << rank[i] << endl;

	return 0;
}




Measured memory_bytes: 3200
def main():
    n = int(input())
    c = str(input())

    w_count = 0
    for i in range(n):
        if c[i] == 'W':
            w_count += 1

    w_count_ano = 0
    for i in range(w_count):
        if c[- 1 - i] == 'W':
            w_count_ano += 1

    count = w_count - w_count_ano
    print(count)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9344
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 30;
// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int B = 320, MAX_N = 100000;

int A[MAX_N], buckets[MAX_N/B];

int sum(int l, int r){
    int res = 0;
    while(l < r && l % B > 0){res += A[l++];}
    while(l < r && r % B > 0){res += A[--r];}
    while(l < r){
        res += buckets[l/B];
        l += B;
    }

    return res;
}

int main(){
    int N, K;
    while(std::cin >> N >> K, N){
        REP(i, N){
            std::cin >> A[i];
            buckets[i/B] += A[i];
        }

        int res = -INF;
        REP(i, N){
            if(i+K <= N){
                res = std::max(res, sum(i, i+K));
            }
        }

        std::cout << res << std::endl;
    }
}

Measured memory_bytes: 1552
#include <bits/stdc++.h>
#define ll         long long int 
#define pb         push_back
#define umap       unordered_map
#define mod        1000000007
#define all(x)     (x).begin(), (x).end()
#define rall(x)    (x).rbegin(), (x).rend()
#define MN(a,b,c)  min(a,min(b,c))
#define MX(a,b,c)  max(a,max(b,c))
#define pr1         pair<ll,ll>
#define F          first
#define S          second
#define mP         make_pair
#define f(i,n)     for(int i=0;i<n;i++)
#define f1(i,x,y)  for(int i=x;i<=y;i++)
#define f2(i,x,y)  for(int i=x;i>=y;i--)
#define yes        cout<<"YES"<<"\n"
#define no         cout<<"NO"<<"\n"
//__builtin_popcount(x)
//__builtin_parity(x)   =(number of set bits)%2
//__builtin_clz(x)      to count the number of leading  zeroes 
//__builtin_ctz(x)      to count the number of trailing zeroes 
//__gcd(a,b)
using namespace std;
 ll N,W;
 vector <ll> w(100),v(100);
 ll dp[100][100001];
 ll operate(ll ind,ll val)
 {ll y;
   if(ind==N || val==0)
       return 0;
   else if(dp[ind][val]==-1)
   {
    if(w[ind]<=val)
     {y= max(operate(ind+1,val),v[ind]+operate(ind+1,val-w[ind]));}
    else
      {y=operate(ind+1,val);}
      dp[ind][val]=y;
       return dp[ind][val];
   }
   else
    return dp[ind][val];
 }
int main()
{
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 cin>>N>>W;
 w.resize(N),v.resize(N);
 f(i,N){cin>>w[i]>>v[i];}
 memset(dp,-1,sizeof(dp));
 ll ans=operate(0,W);
 cout<<ans;
}
   

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

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

    int count = 0;
    for (int n = 1; n <= N; n++)
    {
        count = 0;
        for (int x = 1; x < n; x++)
        {
            if (x * x + 2 * x + 3 > n)
            {
                break;
            }
            for (int y = 1; y < n; y++)
            {
                if (x * x + y * y + 1 + x * y + y + x > n)
                {
                    break;
                }
                for (int z = 1; z < n; z++)
                {
                    if (x * x + y * y + z * z + x * y + y * z + z * x > n)
                    {
                        break;
                    }
                    if (x * x + y * y + z * z + x * y + y * z + z * x == n)
                    {
                        count++;
                    }
                }
            }
        }
        cout << count << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
N = int(input())
d = [[[[0]*4 for _ in range(4)] for _ in range(4)] for _ in range(N+1)]
d[0][0][0][0] = 1
mod = 10**9+7

# T -> 0
# A -> 1
# G -> 2
# C -> 3 とする

# 先頭の文字をi、先頭から2番めの文字をj、先頭から3番目の文字をkとなるような
# 場合の数をDPテーブルで管理する
# dp[n][i][j][k] += dp[n-1][j][k][l]

# 新しく文字を追加したとき、
# 先頭4文字が以下のようにならないようにしたい
# AGC*, ACG*, GAC*, AG*C, A*GC 

# j,k,lがこれらのときアウト
# AGC -> 123 -> 321
# ACG -> 132 -> 231
# GAC -> 213 -> 312

# j,k,l,mがこれらのときアウト
# AG*C -> 12*3 -> 3*21
# A*GC -> 1*23 -> 32*1

for i in range(1, N+1):
    for j in range(4):
        for k in range(4):
            for l in range(4):
                for m in range(4):

                    if j==3 and k==2 and l==1:continue
                    elif j==2 and k==3 and l==1:continue
                    elif j==3 and k==1 and l==2:continue
                    elif j==3 and k==2 and m==1:continue
                    elif j==3 and l==2 and m==1:continue

                    d[i][j][k][l] += d[i-1][k][l][m]
                    d[i][j][k][l] %= mod

ans = 0
for i in range(4):
    for j in range(4):
        for k in range(4):
            ans += d[N][i][j][k]
            ans %= mod

print(ans)

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

int main()
{
	int a, N, K;
	int x[100000];

	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> x[i];

	for (int i = 1;; i++)
	{
		if ((K + (K - 1)*(i - 1)) >= N)
		{
			a = i;
			break;
		}
	}

	cout << a << endl;

	return 0;
}

Measured memory_bytes: 640
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    tmp = "#" * W
    tmp2 = "#" + "."*(W-2) + "#"
    print(tmp)
    for i in range(H-2):
        print(tmp2)
    print(tmp)
    print("")


Measured memory_bytes: 5608
// Created by sz
#include <bits/stdc++.h>
using namespace std;
using ll = long long;


int mod = 1e9+7;
struct modular {
    int value;
    modular(long long v = 0) { value = v % mod; if (value < 0) value += mod;}
    modular(long long a, long long b) : value(0){ *this += a; *this /= b;}
    modular& operator+=(modular const& b) {value += b.value; if (value >= mod) value -= mod; return *this;}
    modular& operator-=(modular const& b) {value -= b.value; if (value < 0) value += mod;return *this;}
    modular& operator*=(modular const& b) {value = (long long)value * b.value % mod;return *this;}
    //其他函数调用mexp(modular(10),3);
    friend modular mexp(modular a, long long e) {
        modular res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
        return res;
    }
    friend modular inverse(modular a) { return mexp(a, mod - 2); }
    modular& operator/=(modular const& b) { return *this *= inverse(b); }
    friend modular operator+(modular a, modular const b) { return a += b; }
    friend modular operator-(modular a, modular const b) { return a -= b; }
    friend modular operator-(modular const a) { return 0 - a; }
    friend modular operator*(modular a, modular const b) { return a *= b; }
    //除法只有在mod是素数可用;
    friend modular operator/(modular a, modular const b) { return a /= b; }
    friend ostream& operator<<(ostream& os, modular const& a) {return os << a.value;}
    friend istream& operator>>(istream& is, modular & a){long long value; is >> value;a.value = 0; a += value;  return is;}
    friend bool operator==(modular const& a, modular const& b) {return a.value == b.value;}
    friend bool operator!=(modular const& a, modular const& b) {return a.value != b.value;}
};


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    
    vector<int> cnt(n, 0), les(n,0);
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            if(j>i && a[i] > a[j])cnt[i] ++;
            if(a[i] > a[j]) les[i] ++;
        }
    }
    
    
    
    modular ans = 0;
    for (int i = 0; i < n; i++){
        ans += (ll) k * cnt[i];
        ans += (ll) (k-1) * k/2%mod * les[i];
    }
    
    cout << ans.value << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
template<typename T> inline void chkmin(T &a, const T &b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T &a, const T &b) { a = a > b ? a : b; }

const int MAXN = 100005;
int a[MAXN], b[MAXN], par[MAXN], lab[MAXN], n;
unordered_map<int, int> mp, id;

int find(int x) { return x == par[x] ? x : par[x] = find(par[x]); }

int main() {
	scanf("%d", &n);
	int tot = 0, x = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		++mp[a[i]];
		if (!id[a[i]]) id[a[i]] = ++tot;
		x ^= a[i];
	}
	++mp[x];
	if (!id[x]) id[x] = ++tot;
	a[n + 1] = x, x = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d", b + i);
		if (--mp[b[i]] < 0) return puts("-1"), 0;
		x ^= b[i];
	}
	if (--mp[x] < 0) return puts("-1"), 0;
	b[n + 1] = x;
	for (int i = 1; i <= tot; i++) par[i] = i;
	lab[find(id[a[n + 1]])] = 1;
	int res = 0;
	for (int i = 1; i <= n + 1; i++) {
		if (a[i] == b[i]) continue;
		int p = id[a[i]], q = id[b[i]];
		par[find(p)] = find(q);
		if (i <= n) ++res;
		lab[find(q)] = 1;
	}
	for (int i = 1; i <= tot; i++) res += lab[i] && par[i] == i;
	printf("%d\n", res - 1);
	return 0;
}

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

 
int32_t main() {
  ios_base::sync_with_stdio(false);
 int n,d;

  cin >> n;
  d= n%10;
  if(d==2||d==4 ||d==5||d==7||d==9)
  cout << "hon";
  else if(d==0||d==1||d==6||d==8)
  cout <<"pon";
  else
  cout <<"bon";
}


Measured memory_bytes: 3608
num = input().split()
hei = int(num[0])
wei = int(num[1])

photo = []

for i in range(hei):
    temp = input()
    temp = list(temp)
    photo.append(temp)
    photo.append(temp)
    
for i in range(hei*2):
    for j in range(wei):
        print(photo[i][j],end="")
    print("\n",end="")

Measured memory_bytes: 9308
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define _GLIBCXX_DEBUG
int main()
{
    ll h,n;
    cin>>h>>n;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    ll sum=0;
    rep(i,n)sum+=a[i];
    if(h<=sum)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

typedef long long int llint;

int main(){
	int N,X,Y;
	cin >> N >> X >> Y;

	int cnt[N];
	for(int i=0;i<N;i++){
		cnt[i]=0;
	}

	X-=1;
	Y-=1;

	for(int i=0;i<N;i++){
		int dp[N];
		for(int k=0;k<N;k++){
			dp[k]=abs(k-i);
		}
		if(dp[X]>dp[Y]+1){
			dp[X]=dp[Y]+1;
			for(int k=X+1;k<N;k++){
				if(dp[k]>dp[k-1]+1){
					dp[k]=dp[k-1]+1;
				}
			}
			for(int k=X-1;k>=0;k--){
				if(dp[k]>dp[k+1]+1){
					dp[k]=dp[k+1]+1;
				}
			}
		}else if(dp[Y]>dp[X]+1){
			dp[Y]=dp[X]+1;
			for(int k=Y+1;k<N;k++){
				if(dp[k]>dp[k-1]+1){
					dp[k]=dp[k-1]+1;
				}
			}
			for(int k=Y-1;k>=0;k--){
				if(dp[k]>dp[k+1]+1){
					dp[k]=dp[k+1]+1;
				}
			}
		}
		for(int i=0;i<N;i++){
			cnt[dp[i]]++;
		}
	}

	for(int i=1;i<=N-1;i++){
		cout << cnt[i]/2 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);

    int n = scan.nextInt();
    TreeMap<Integer,Integer> map = new TreeMap<>();
    int count = 0;
    for(int i = 0; i < n; i++) {
      map.put(scan.nextInt(),count);
      count++;
    }
    int result = 0;
    count = 0;
    for(Map.Entry entry : map.entrySet()) {
      if((int)entry.getValue()%2 != count%2) result++;
      //System.out.println(entry.getValue());
      count++;
    }

    System.out.println(result/2);
  }
}


Measured memory_bytes: 30032
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std; 
const long long mod=1000000007;

int main()
{
    int N,M,a;
    cin>>N>>M;
    vector<bool>check(N+1,true);
    for(int i=0;i<M;i++){
        cin>>a;
        check[a]=false;
    }
    vector<long long int>dp(N+1);
    dp[0]=1;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<=min(i+2,N);j++){
            if(check[j]){
                dp[j]+=dp[i];
                dp[j]%=mod;
            }
        }
    }
    cout<<dp[N]<<endl;
}

Measured memory_bytes: 1024
import java.lang.Math
import kotlin.comparisons.*

val MOD: Int = 1000000000 + 7
val MODL: Long = MOD.toLong()

fun main(args: Array<String>)
{
    val c = read().toCharArray()
    val ans = c[0] + 1
    println(ans)
}

fun read(): String = readLine()!!
fun CharSequence.split(): List<String> = this.split(" ")
fun Iterable<String>.toInt(): List<Int> = this.map{it.toInt()}
fun Iterable<String>.toLong(): List<Long> = this.map{it.toLong()}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int MOD = 1e9+7;
const long long INF = 1LL << 60;
const int inf = 1e9;
typedef long long ll;

int main(){
    int N, M; cin >> N >> M;
    int ans = 0;
    int x[100010], s[100010];
    //vector<int> x(M)
    rep(i,M) cin >> x[i];
    if(N>=M) {
        cout << 0 << endl;
        return 0;
    }
    sort(x, x+M);
    ans = x[M-1]-x[0];
    for(int i = 0; i < M-1; i++) {
        s[i] = x[i+1]-x[i]; //間の区間
        //printf("s[%d]=%d\n",i,s[i]);
    }
    sort(s,s+M-1,greater<int>());
    rep(i, N-1) {
        ans -= s[i];
        //printf("s[%d]=%d\n",i,s[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  cout << fixed << setprecision(20);
  int a, b;
  cin >> a >> b;
  int d = a / b;
  int r = a % b;
  double f = (double)a / b;
  cout << d << ' ' << r << ' ' << f << endl;
}


Measured memory_bytes: 3288
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

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

void solve() {
    LL n;
    cin >> n;
    if (n < 4) {
        cout << n - 1 << endl;
        return;
    }


    LL ans = 2;
    for (LL i = 2; i * i <= n; ++i) {
        //cerr << i << " " << n % i << endl;
        if (n % i == 1) ++ans;
        if (i != n / i && n % (n / i) == 1) ++ans;
        if (n % i == 0) {
            LL v = n;
            while (v % i == 0) v /= i;
            if (v % i == 1) {
                ++ans;
            }
        }
    }
    cout << ans << endl;
    dump(ans);
}

signed main() {
    solve();
    
    return 0;
}

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

int main(){
  int N;
  double W;
  cin >> N >> W;
  double sw = 0, sv = 0;
  priority_queue<pair<double,pair<double,double>>> pq;
  for(int i = 0; i < N; ++i){
    int w, v;
    cin >> w >> v;
    if(w < 0){
      sw += w;
      sv += v;
      w *= -1;
      v *= -1;
    }
    if(v > 0){
      if(w == 0) sv += v;
      else pq.push({(double)v/w,{w,v}});
    }
  }
  //cerr << sw << " " << sv << endl;
  while(W-sw > 1e-9 and not pq.empty()){
    auto p = pq.top();
    double w = p.second.first, v = p.second.second;
    pq.pop();
    double x;
    if(abs(w) > 1e-9) x = min(1.,(W-sw)/w);
    else x = 1.;
    sw += x*w;
    sv += x*v;
  }
  printf("%.12f\n",sv);
}



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

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

  ll n;
  cin >> n;

  ll low = 1, high = n;

  while (low < high) {
    ll mid = low + (high - low + 1) / 2;
    ll square = mid * mid;

    if (square <= n) low = mid;
    else high = mid - 1;
  }

  cout << (low * low) << "\n";
}


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

int ds(int n){
	int sum=0;
	while(n){
		sum+=n%10;
		n/=10;
		}
	return sum;	
	}

signed main(){
	int n;cin>>n;
	if(n%ds(n))puts("No");
	else puts("Yes");
	}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    A, B, C = input().split()
    if A[-1] == B[0] and B[-1] == C[0]:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define INF 1e5 + 1
using namespace std ;
vector<int>in_degree(1e5+1,0) ;
vector<vector<int> >v(1e5+1) ;
bool arr[(int)1e5+1] ;
vector<int>dp(1e5+1,0) ;
int max(int a, int b)
{
	if(a>b)
	{
		return(a) ;
	}
	return(b) ;
}
void dfs(int j)
{
	arr[j] = true ;
	//cout<<j<<" " ;
	for(int i=0 ; i<v[j].size() ; i=i+1)
	{
		int a = v[j][i] ;
		dp[a] = max(dp[a],1+dp[j]) ;
		--in_degree[a];
		if(in_degree[a]==0)
		{
			dfs(a) ;
		}
	}
}
int main()
{
	int a,b,c,d,i,n,j,m ;
	cin>>n>>m ;
	
	for(i=0 ; i<m ; i=i+1)
	{
		cin>>a>>b;
		++in_degree[b] ;
		v[a].push_back(b) ;
	}
	for(i=1 ; i<=n ; i=i+1)
	{
		arr[i] = false ;
	}
	arr[0] = true ;
	
	for(i=1 ; i<n+1 ; i=i+1)
	{
		if(arr[i]==false && in_degree[i]==0)
		{
			//cout<<i<<" " ;
			dfs(i) ;
		}
	}
	dp[0] = 0 ;
	cout<<*max_element(dp.begin(),dp.begin()+n+2) ;
}

Measured memory_bytes: 9728
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
int digcount(int n)
{
    int count=0;
    while (n>0)
    {
        count++;
        n=n/10;
    }
    return count;
}
int main()
{
    fastio;
    int n,i,k=0;
    cin>>n;
    for (i=1;i<=n;i++)
    {
        if (digcount(i)%2!=0)
            k++;
    }
    cout<<k<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
long long longpow(long long n, long long a, long long mod) {
  if (a == 0) return 1;
  if (a == 1) return n % mod;
  if (a % 2 == 1) return (n * longpow(n, a - 1, mod)) % mod;
  ll t = longpow(n, a / 2, mod) % mod;
  return (t * t) % mod;
}
int main() {
  ll N;
  int a, b;
  /*while (true) {
    cin >> a >> b;
    cout << a % b;
  }*/
  cin >> N;
  vector<char> A(0);
  while (0 < N) {
    ll a = N % 26;
    if (a == 0) {
      a = 26;
    }
    A.push_back(a + 'a' - 1);
    N = (N-1) / 26;
  }
  reverse(A.begin(), A.end());
  REP(i, A.size()) cout << A[i];
  cout << endl;
}

Measured memory_bytes: 3628
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
-- end of templete

ioi [] = []
ioi ('O':s) = ioi s
ioi ('I':s) = ioisub 0 s
ioisub 0 [] = []
ioisub n [] = [n]
ioisub n ('O':'I':s) = ioisub (n+1) s
ioisub 0 s = ioi s
ioisub n s = n : ioi s


main = do
    n <- getInt
    when (n/=0) $ do
        m <- getInt
        s <- getLine
        print $ sum $ filter (>=1) $ map (subtract (n-1)) $ ioi s
        main

Measured memory_bytes: 51736
import Control.Monad
import Control.Monad.ST
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Array
import Data.Array.ST

main = do
    [n,w]<-map read.words<$>getLine::IO [Int]
    wvs<-replicateM n $ unfoldr (B.readInt.B.dropWhile(<'!'))<$>B.getLine::IO[[Int]]
    print $ f n w wvs

f n w wvs = runST $ do
    dp <- newArray ((0,0),(n,100000)) maxBound :: ST s (STUArray s (Int,Int) Int)
    writeArray dp (0,0) 0
    forM_ [(i,wi,vi,j)|(i,[wi,vi])<-zip [1..] wvs,j<-[0..100000]] $ \(i,wi,vi,j) ->
        writeArray dp (i,j) =<< if j-vi < 0 then readArray dp (i-1,j)
        else min.(+wi).min (maxBound-wi) <$> readArray dp (i-1,j-vi) <*> readArray dp (i-1,j)
    maximum.map fst.filter ((<=w).snd) <$> mapM (liftM2 fmap (,) (readArray dp.(,) n)) [0..100000]


Measured memory_bytes: 95996
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}
int main()
{
    int n,x;
    cin >> n >> x;
    vector<int> M(n);
    int sum = 0;
    rep(i,n){
        cin >> M[i];
        sum += M[i];
    }
    int MIN = *min_element(M.begin(), M.end());
    x -= sum;
    int ans = n;
    for (int i = 0;;i++){
        if(x>=MIN){
            x -= MIN;
            ans++;
        }else{
            break;
        }
    }
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int m, n;
double d[20][20];
double dp[1<<16][20];

// 集合maskの猫が生き残っていて、idx番目の敵とやってる
double dfs(int mask, int idx) {
  if(dp[mask][idx] >= 0) return dp[mask][idx];
  if(mask == 0) return 0.0;
  if(idx == n) return 1.0;

  double ret = 0;
  REP(i, m) if(mask & 1<<i) {
    double tmp = 0, prob = 1;
    FOR(j, idx, n) {
      // 猫iが敵jまで行った
      tmp += dfs(mask^(1<<i),j)*prob*(1.0-d[i][j]);
      prob *= d[i][j];
    }
    tmp += prob;
    chmax(ret, tmp);
  }

  return dp[mask][idx] = ret;
}

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

  // m匹, n部屋
  cin >> m >> n;
  REP(i, m) REP(j, n) cin >> d[i][j];

  REP(i, 1<<m) REP(j, n) dp[i][j] = -1;

  cout << fixed << setprecision(15) << dfs((1LL<<m)-1, 0) << endl;

  return 0;
}



Measured memory_bytes: 13512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	double L; cin >> L;
	double a = L / 3, b = L / 3, c = L - a - b;
	cout << a * b * c << "\n";

	return 0;
}


Measured memory_bytes: 256
<?php
define('MOD', 10 ** 9 + 7);
list($k) = ints();
list($s) = strs();
$ls = strlen($s);
init($ls + $k - 1);
$pow25[0] = $pow26[0] = 1;
for ($i = 1; $i <= $k; ++$i) {
    $pow25[$i] = modMul($pow25[$i - 1], 25);
    $pow26[$i] = modMul($pow26[$i - 1], 26);
}
$ans = 0;
for ($i = 0; $i <= $k; ++$i)
    $ans = modAdd($ans, modMul(modMul(nCr2($ls + $k - $i - 1, $ls - 1), $pow25[$k - $i]), $pow26[$i]));
echo $ans;
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
// 足し算
function modAdd($x, $y)
{
    return ($x + $y) % MOD;
}

// 引き算
function modSub($x, $y)
{
    return ($x + MOD - $y) % MOD;
}

// 掛け算
function modMul($x, $y)
{
    return ($x * $y) % MOD;
}

// 割り算
function modDiv($x, $y)
{
    return modMul($x, modPow($y, MOD - 2));
}

// 累乗（繰り返し二乗法）
function modPow($n, $x)
{
    if ($x === 0) return 1;
    $res = (modPow($n, $x >> 1) ** 2) % MOD;
    if ($x % 2 === 1) $res = modMul($res, $n);
    return $res;
}

// 階乗
function modFac($n)
{
    if ($n === 0) return 1;
    return modMul($n, modFac($n - 1));
}

// 順列
function nPr($n, $r)
{
    if ($r === 0) return 1;
    return modMul(nPr($n, $r - 1), $n - $r + 1);
}

// 組み合わせ
function nCr($n, $r)
{
    $r = min($r, $n - $r);
    if ($r === 0) return 1;
    return modDiv(nPr($n, $r), modFac($r));
}

// 階乗、逆元を前処理
function init($max)
{
    global $fac, $finv, $inv;
    $fac = $finv = [1, 1];
    $inv[1] = 1;
    for ($i = 2; $i <= $max; ++$i) {
        $fac[$i] = modMul($fac[$i - 1], $i);
        $inv[$i] = modSub(MOD, modMul($inv[MOD % $i], intdiv(MOD, $i)));
        $finv[$i] = modMul($finv[$i - 1], $inv[$i]);
    }
}

// 組み合わせ(前処理利用）
function nCr2($n, $r)
{
    global $fac, $finv;
    $r = min($r, $n - $r);
    if ($r === 0) return 1;
    return modMul($fac[$n], modMul($finv[$r], $finv[$n - $r]));
}


Measured memory_bytes: 268840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()


int main(){
    ll a, b, n;
    cin >> a >> b >> n;
    const ll x = min(b - 1, n);
    cout << (a * x) / b - a * (x / b) << endl;
    return 0;
}


Measured memory_bytes: 3620
def count_divisors(n):
    divisors = 0
    for i in range(1, int(n**0.5) +1):
        if n % i == 0:
            divisors += 1
            if i != n // i:
                divisors += 1

    return divisors

n = int(input())

print(sum(count_divisors(x) == 8 for x in range(1, n+1, 2)))



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

using namespace std;

typedef long long ll;

const int LGN = 60;
const int Z = 1e9+7;

void addm(int &a, int b) {
    a = a + b >= Z ? a + b - Z : a + b;
}

int main() {
    ios::sync_with_stdio(false);

    ll l, r;
    cin >> l >> r;

    int dp[LGN+1][2][2][2];
    fill(&dp[0][0][0][0], &dp[LGN+1][0][0][0], 0);
    fill(&dp[0][0][0][0], &dp[1][0][0][0], 1);
    for (int i = 1; i <= LGN; i++) {
        bool bl = l >> (i - 1) & 1, br = r >> (i - 1) & 1;
        for (int fl = 0; fl < 2; fl++) {
            for (int fr = 0; fr < 2; fr++) {
                for (int sb = 0; sb < 2; sb++) {
                    for (int cl = 0; cl < 2; cl++) {
                        for (int cr = 0; cr < 2; cr++) {
                            if (cl <= cr && !(sb && (cl < cr)) && !(fl && (cl < bl)) && !(fr && (cr > br))) {
                                addm(dp[i][fl][fr][sb], dp[i-1][fl&&cl==bl][fr&&cr==br][sb&&cl!=1]);
                            }
                        }
                    }
                }
            }
        }
    }

    cout << dp[LGN][1][1][1] << endl;

    return 0;
}


Measured memory_bytes: 256
def x(i):
    if i==0:
        return 0
    if i==1:
        return 1
    if i==2:
        return 2
    if i==3:
        return 3
    if i==4:
        return 5
    if i==5:
        return 7
    if i==6:
        return 8
    if i==7:
        return 9

while True:
    n = int(input())
    if n==0:
        break
    n = oct(n)
    n = list(n)
    del(n[0:2])
    for i in range(len(n)):
        print(x(int(n[i])),end='')
    print()


Measured memory_bytes: 5620
n,m = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
y = 1
while y == 1 
  B = Array.new(6)
  x = n
  i = 0
  while i <= 5
    B[i] = x%10
    x = x/10
    i += 1
    if x == 0
      i = 100
    end
  end
  if (A & B).length != 0
    n = n + 1
  else
  y = 2
  end
end
puts n

Measured memory_bytes: 2172
H = 1
W = 1
while H and W:
    H, W = input().split()
    H = int(H)
    W = int(W)
    if H == 0\
    and W == 0:
        break

    for h in range(H):
        for w in range(W):
            if h % 2 and w % 2\
            or h % 2 == 0 and w % 2 == 0:
                print("#", end = "")
            else:
                print(".", end = "")

            if w == W - 1:
                print()
    print()

Measured memory_bytes: 9088
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, a = LI()
x = LI()

# dp[i][j][k] := i番目まで見たときj個使用してkを作る場合の数
dp = [[[0] * (2500+1) for _ in range(n+1)] for _ in range(n+1)]
dp[0][0][0] = 1
for i in range(n+1):
    xi = x[i-1]
    for j in range(2500+1):
        for k in range(i):
            dp[i][k][j] = dp[i-1][k][j]
    for j in range(xi, 2500+1):
        for k in range(1, i+1):
            dp[i][k][j] += dp[i-1][k-1][j-xi]
ans = 0
for i in range(1, n+1):
    ans += dp[-1][i][i*a]
print(ans)

Measured memory_bytes: 125668
#include <iostream>
using namespace std;
int main(void){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if((x + r> r && x <= W - r) && (y + r > r && y <= H - r))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

int dfs(int index,vector<int> &cnt,vector<int> &time){
    if(index==13){
        int pre=-13;
        int res=13;
        for(int i=0;i<time.size()*2;i++){
            if(time[i%24]){
                res=min(res,i-pre);
                pre=i;
            }
        }
        return res;
    }
    if(cnt[index]==0){
        return dfs(index+1,cnt,time);
    }
    if(cnt[index]==2){
        time[(12+index)%24]=true;
        time[12-index]=true;
        int res=dfs(index+1,cnt,time);
        time[(12+index)%24]=false;
        time[12-index]=false;;
        return res;
    }
    time[(12+index)%24]=true;
    int res=dfs(index+1,cnt,time);
    time[(12+index)%24]=false;
    time[12-index]=true;
    res=max(res,dfs(index+1,cnt,time));
    time[12-index]=false;
    return res;
}

int main(){
    vector<int> cnt(13,0);
    int n;
    cin>>n;
    vector<int> d(n);
    for(int i=0;i<d.size();i++){
        cin>>d[i];
        cnt[d[i]]++;
    }
    if(cnt[0]>=1 || cnt[12]>=2){
        cout<<0<<endl;
        return 0;
    }
    for(int i=1;i<cnt.size();i++){
        if(cnt[i]>=3){
            cout<<0<<endl;
            return 0;
        }
    }
    
    vector<int> time(24,0);
    time[12]=true;

    cout<<dfs(0,cnt,time)<<endl;
    return 0;
}

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

using namespace std;

typedef long long ll;


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

	int n, k, x, y;
	cin >> n >> k >> x >> y;

	cout << min(k, n) * x + max(n - k, 0) * y << endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

long long v[4][101];
int sw[4];
long long stdw,tw,ans;
long long sum0,sum1,sum2,sum3;

bool cmp(int a,int b){
	return a > b;
}

int main()
{
	long long n,w;
	scanf("%lld%lld",&n,&w);
	scanf("%lld%lld",&stdw,&v[0][++sw[0]]);
	for(int i = 2;i <= n;i++)
	{
		scanf("%lld",&tw);
		scanf("%lld",&v[tw - stdw][++sw[tw - stdw]]);
	}
	for(int i = 0;i <= 3;i++)
		sort(v[i] + 1,v[i] + sw[i] + 1,cmp);
	for(int i = 0;i <= sw[0];i++)
	{
		sum0 += v[0][i];
		for(int j = 0;j <= sw[1];j++)
		{
			sum1 += v[1][j];
			for(int k = 0;k <= sw[2];k++)
			{
				sum2 += v[2][k];
				for(int t = 0;t <= sw[3];t++)
				{
					sum3 += v[3][t];
					if(w - i * stdw - j * (stdw + 1) - k * (stdw + 2) - t * (stdw + 3) < 0)continue;
					ans = max(ans,sum3 + sum2 + sum1 + sum0);
				}
				sum3 = 0;
			}
			sum2 = 0;
		}
		sum1 = 0;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 128