akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h> 
using namespace std;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define INF 1e18L+5
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef vector<int> vi;
typedef pair<int,int>ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<long long > vl;
/*template<typename T>
void show(vector<T> v){
for(auto it:v){
    cout<<it<<" ";
}
cout<<"\n";
}/*
inline int nxt() {
	int x;
	scanf("%d", &x);
	return x;
}
/*struct LCA{
    vi euleur,height,first,st;
    vector<bool> visited;
    LCA(vvi adj,int root=0){
        int n=adj.size();
        height.resize(n);visited.assign(n,false);euleur.reserve(2*n);
        first.resize(n);
        dfs(adj,root);
        int m=euleur.size();
        st.resize(4*m);
        build(1,0,m-1);
    }
    void dfs(vvi adj,int root=0,int h=0){
        visited[root]=true;
        height[root]=h;
        first[root]=(int)euleur.size();
        euleur.pb(root);
        for(int child:adj[root]){
            if(!visited[child]){
                dfs(adj,child,h+1);
                euleur.pb(root);
            }
        }
    }
    void build(int p,int l,int r){
        if(l==r)st[p]=euleur[l];
        else{
            int mid=(l+r)>>1;
            build(p<<1,l,mid);build(p<<1|1,mid+1,r);
            int l=st[p<<1],r=st[p<<1|1];
            st[p]=height[l]<height[r]?l:r;
        }
    }
    int query(int p,int l,int r,int i,int j){
        if (l> j || r < i)
            return -1;
        if(i<=l&&r<=j)return st[p];
        int mid=(l+r)>>1;
        int p1=query(p<<1,l,mid,i,j),p2=query(p<<1|1,mid+1,r,i,j);
        if(p1==-1)return p2;if(p2==-1)return p1;
        return height[p1]<height[p2]?p1:p2;
        
    }
    int lca(int u,int v){
        int l=first[u],r=first[v],m=euleur.size();
        if(l>r)swap(l,r);
        return query(1,0,m-1,l,r);
    }
};
*/
const int N=3000;

 int main() { ios_base::sync_with_stdio(false); cin.tie(NULL);
 int n;scanf("%d",&n);
 vector<double>dp(n+1);dp[0]=1;
 //dp[i] proba of having i heads 

for(int coin=0;coin<n;++coin){
    double p;
  scanf("%lf",&p);
    for(int i=coin+1;i>=0;--i){
        dp[i]=(i==0?0:dp[i-1]*p)+dp[i]*(1-p);
    }
}
double ans=0;
for(int i=0;i<=n;++i){
  int reste=n-i;
  if(reste<i){
      ans+=dp[i];
  }
}
printf("%.10lf\n",ans);
       return 0;
    }

Measured memory_bytes: 3852
# p (0..6).to_a.map{|j| [6 ** j, 9 ** j] }.flatten.uniq
a = [1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 59049, 46656, 531441]

m, dp = gets.to_s.to_i, [0]
(1..m).each {|i|
  cans = a.select {|j| i - j >= 0 }.map{|j| i - j }.uniq
  t = 10**18
  cans.each{|c| t = dp[c] if t > dp[c] }
  dp.push(t + 1)
}
p dp.last

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

int main() {

	int r = 0;
	string s,t;
    
    cin >> s >> t;
    
    for(int i=0;i < s.size();i++){
    	if(s.at(i) != t.at(i)){
        r = 1;
        }
    }

	if(r == 1){
      	cout << "No" <<endl;
	}
    else{
   		cout << "Yes" <<endl;
    }
}


Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
typedef double db;
ll a[4],k;
int main()
{
	scanf("%d%d%d%lld",&a[1],&a[2],&a[3],&k);
	if(k&1) printf("%d\n",a[2]-a[1]);
	else printf("%d\n",a[1]-a[2]);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // ver2.2.2
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ

int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
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;}



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n,m;
  cin >> n >> m;
  Vi a(26);
  char c;
  rep(i,0,n*m){
    cin >> c;
    a[c-'a']++;
  }
  //Vout(a);
  
  int rT=0,rO=0;
  Vi b(0);
  if(n%2==0 && m%2==0){
    //rep(i,0,n*m/4) b.pb(4);
  }
  if(n%2==1 && m%2==0){
    //rep(i,0,(n-1)*m/4) b.pb(4);
    //rep(i,0,m/2) b.pb(2);
    rT = m/2;
  }
  if(n%2==0 && m%2==1){
    //rep(i,0,(m-1)*n/4) b.pb(4);
    //rep(i,0,n/2) b.pb(2);
    rT = n/2;
  }
  if(n%2==1 && m%2==1){
    //rep(i,0,(m-1)*(n-1)/4) b.pb(4);
    //rep(i,0,n/2) b.pb(2);
    //rep(i,0,m/2) b.pb(2);
    //b.pb(1);
    rO = 1;
    rT = n/2+m/2;
  }
  //Vout(b);
  
  int F,T=0,O=0;
  rep(i,0,a.size()){
    if(a[i]%4==1) O++;
    else if(a[i]%4==2) T++;
    else if(a[i]%4==3) {
      O++;
      T++;
    }
  }
  
  if(rO >= O && rT >= T) cYes; 
  else cNo;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  int M;
  cin >>N>>M;
  vector<int> a(M);
  vector<int> b(M);
  rep(i,M) {
cin >>a.at(i)>>b.at(i);
  }
  
  
  vector<int> vec(N);
  
  rep(k,M) {
   vec.at(a.at(k)-1)++;
    vec.at(b.at(k)-1)++;
  }
rep(i,N) {
cout<<vec.at(i)<<endl;
}
}
    


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <cstdlib>
using namespace std;
 
int main(){
   int a,b,c;
   cin>>a>>b>>c;
   int temp= max(a,max(b,c));
   if(a+b+c-temp==temp){
       cout<<"Yes";
   }else{
       cout<<"No";
   }

    return 0;
}

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

#define EPS 1e-7

int main(void) {
	double d;
	double answer = 0;
	int i;
	if (scanf("%lf", &d) != 1) return 1;
	answer = d * sqrt(2);
	for (i = 1; i < d + EPS; i++) {
		double y = sqrt(d * d - i * i);
		double candidate;
		if (y < 1) candidate = i + y + (1.0 - y) /* / 2 * 2 */;
		else candidate = i + y;
		if (candidate > answer) answer = candidate;
	}
	printf("%.15f\n", answer);
	return 0;
}



Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string S;
    cin >> S;

    int ans = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == '+')
        {
            ++ans;
        }
        else
        {
            --ans;
        }
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

int main()
{
  set<int> s;
  s.insert(1);
  s.insert(2);
  s.insert(3);
  
  int a,b;
  
  cin>>a>>b;
  s.erase(a);
  s.erase(b);
  
  cout<<*s.begin()<<endl;
  
  return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define ll long long 
using namespace std;
const ll N = 2e5 + 10, mod = 1e9 + 7;
int s[N], c[N];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= m; i++)cin >> s[i] >> c[i];
    for(int i = 0; i <= 9999; i++){
        int x = i, dig = 0; 
        bool ok = true; 
        string S = "";
        while(x){
            S += char(x % 10 + '0');
            x /= 10;
        }
        if(i == 0)S = "0"; 
        if(S.size() != n)continue;
        reverse(S.begin(), S.end());
        for(int j = 1; j <= m; j++){
            if(S[s[j] - 1] != c[j] + '0'){
                ok = false;
                break;
            }
        }
        if(ok == false)continue;
        cout << i << endl;
        return 0;
    }
    cout << "-1\n";
}

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

int main(void){

int A,B,C;
cin >> A >> B >> C;

if ( A+B<C ) {
  cout << A+B+1+B << endl;
}else if( A+B==C ){
  cout << C+B << endl;
}else if( B<C ){
  cout << C+B << endl;
}else if ( B==C ){
  cout << C+B << endl;
}else if ( B>C ){
  cout << B+C << endl;
}
  
return 0;
}

Measured memory_bytes: 256
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 998244353;
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[400006],R[400006];
void make(){
	F[0] = 1;
	for(int i=1;i<400006;i++) F[i] = F[i-1]*i%mod;
	for(int i=0;i<400006;i++) R[i] = modpow(F[i],mod-2);
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}
int n, m, k;
int main(){
ios::sync_with_stdio(false);
	make();
	cin>>n>>m>>k;
	ll ans = 0;
	rep(i, k+1){
		ans += C(n-1, i) * modpow(m-1, n-1-i) % mod * m % mod;
	}
	cout<<(ans%mod+mod)%mod<<endl;
}

Measured memory_bytes: 9940
#include<math.h>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include <array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
//AtCoderC++.cpp

using namespace std;

int main() {
	int N; cin >> N;
	using task = pair<int, int>;
	auto tasks = vector<task>(N);
	int cost, dead;
	for (size_t i = 0; i < N; i++) {
		cin >> cost >> dead;
		tasks[i] = { dead,cost };
	}
	sort(tasks.begin(), tasks.end());
	long long time = 0; bool success = true;
	for (size_t i = 0; i < N; i++) {
		time += tasks[i].second;
		if (tasks[i].first < time) {
			success = false;
			break;
		}
	}
	if (success) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    int h, w;
    cin >> h >> w;

    vector<string> img(h);
    for (int i = 0; i < h; i++) {
        cin >> img[i];
    }

    for (int i = 0; i < h; i++) {
        cout << img[i] << endl;
        cout << img[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N, ga, sa, ba, gb, sb, bb;
    cin >> N >> ga >> sa >> ba >> gb >> sb >> bb;

    vector<int> dp(N+1, 0);
    for (int i = 0; i < N; i++) {
        dp[i+1] = max(dp[i+1], dp[i] + 1);
        if (i+1-ga >= 0) dp[i+1] = max(dp[i+1], dp[i+1-ga] + gb);
        if (i+1-sa >= 0) dp[i+1] = max(dp[i+1], dp[i+1-sa] + sb);
        if (i+1-ba >= 0) dp[i+1] = max(dp[i+1], dp[i+1-ba] + bb);
    }

    int M = dp[N];
    vector<int> dp2(M+1, 0);
    for (int i = 0; i < M; i++) {
        dp2[i+1] = max(dp2[i+1], dp2[i] + 1);
        if (i+1-gb >= 0) dp2[i+1] = max(dp2[i+1], dp2[i+1-gb] + ga);
        if (i+1-sb >= 0) dp2[i+1] = max(dp2[i+1], dp2[i+1-sb] + sa);
        if (i+1-bb >= 0) dp2[i+1] = max(dp2[i+1], dp2[i+1-bb] + ba);
    }

    cout << dp2[M] << endl;
    return 0;
}

Measured memory_bytes: 195584
import random
input()
A = [int(_) for _ in input().split()]
A = [A[0]] + [j for i, j in zip(A, A[1:]) if i >= j]
N = len(A)


def cut(array, index):
    if index < 1:
        return []
    if index <= array[0][0]:
        return [(index, array[0][1])]
    for _ in range(len(array)-1, 0, -1):
        if array[_ - 1][0] < index:
            return array[:_] + [(index, array[_][1])]


def is_possible(K):
    dp = [(A[0], 0)]
    for a in A[1:]:
        if a <= dp[-1][0]:
            dp = cut(dp, a)
        else:
            dp += [(a, 0)]
        is_added = False
        for j in range(len(dp) - 1, -1, -1):
            if dp[j][1] < K - 1:
                dp = cut(dp, dp[j][0] - 1) + [(dp[j][0], dp[j][1] + 1)]
                if dp[-1][0] < a:
                    dp += [(a, 0)]
                is_added = True
                break
        if not is_added:
            return False
    return True


def bis(x, y):
    if y == x + 1:
        return y
    elif is_possible((x + y) // 2):
        return bis(x, (x + y) // 2)
    else:
        return bis((x + y) // 2, y)


print(bis(0, N))


Measured memory_bytes: 109392
function Main(input) {
    input = input.split("\n");
    tmp = input[0].split(" ");
    N = Number(tmp[0]);
    K = Number(tmp[1]);
    Students = new Array(N)
    input.shift();
    Ans = 0;
    for(i = 0; i < K; i++){
        d = Number(input[0]);
        As = input[1].split(" ");
        for(j = 0; j < As.length; j++){
            A = Number(As[j])
            Students[A-1] = d;
        }
        input.shift();
        input.shift();
    }
    for(e = 0; e < N; e++){
        if(Students[e] === undefined) Ans++
    }
    console.log(Ans)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 32644
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

int main()
{
	double a, b;
	cin >> a >> b;

	cout << (int)((a + b) / 2.0 + 0.5) << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
    int A[MAX], n;
  
     cin >> n;
     for(int i = 0; i < n; i++) cin >> A[i];

    int maxv =A[1] - A[0];
    int minv = A[0];
     for(int i = 1; i < n; i++){
        maxv = max(maxv, A[i] - minv);
        minv = min(A[i] , minv);
     }
  cout << maxv << endl;
  
  return 0;
   
}


Measured memory_bytes: 3892
h,w=map(int,input().split())

li=[]

for i in range(h):
    li.append(list(input()))

for i in range(len(li)):
    li[i].insert(0,'#')
    li[i].append('#')

li.append(['#' for i in range(w+2)])
li.insert(0,['#' for i in range(w+2)])

for i in range(len(li)):
    print("".join(li[i]))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
long long  a[100005];
long long  n,c,b;
long  pd(long long  x)
{
     long long  t=c*x;
     long long  cnt=0;
     for(int i=0;i<n;i++)
     {
         if(a[i]-t>0)
        {
             if((a[i]-t)%(b-c)==0)
                 cnt+=(a[i]-t)/(b-c);
             else
                 cnt+=(a[i]-t)/(b-c)+1;
         }
     }
    return cnt<=x;
}
int  main()
{
     cin>>n>>b>>c;
     for(int i=0;i<n;i++)
         cin>>a[i];
    long long  k=0,minn=1e9;
    long long  m;
    int t;
     while(k<minn-1)
     {
         m=(minn+k)>>1;
         if(pd(m))
         {
             minn=m;
             t=m;
         }
         else
             k=m;
    }
     cout<<minn<<endl;
     return 0;
 }

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(x,a) for(auto& (x):(a))
#define ALL(obj) (obj).begin(),(obj).end()
#define Yes(n) cout<<((n)?"Yes":"No")<<endl;
#define CO(x) cout<<(x)<<endl;
#define COSP(x) cout<<(x)<<" ";
#define DICIMAL(x) fixed<<setprecision(x)
using namespace std;
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
const int INF=1e9;
const ll LINF=1e18;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

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

  ll N; cin>>N;

  ll sum=0;
  set<ll> s;
  FOR(i,1,sqrt(N)+1){
    if(N%i==0){
      s.insert(i);
      if(N/i!=i){
        s.insert(N/i);
      }
    }
  }
  s.erase(1);
  EACH(x,s) if(N/(x-1)==N%(x-1)) sum+=(x-1);

  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define INPUT "/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.in"
#define OUTPUT "/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.out"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

const int maxn = 30 + 5;
ll d[maxn][maxn];
ll g[3][maxn];

void solve()
{
    int n, c;
    cin >> n >> c;
    for(int i = 0; i < c; i++)
    {
        g[0][i] = g[1][i] = g[2][i] = 0;
        for(int j = 0; j < c; j++)
        {
            cin >> d[i][j];
        }
    }
    
    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            int x;
            cin >> x;
            for(int k = 0; k < c; k++)
            {
                g[(i + j) % 3][k] += d[x - 1][k];
            }
        }
    }
    
    ll ans = inf;
    for(int i = 0; i < c; i++)
    {
        for(int k = 0; k < c; k++)
        {
            for(int j = 0; j < c; j++)
            {
                if(i == k || k == j || i == j)
                {
                    continue;
                }
                
                ans = min(ans, g[0][i] + g[1][k] + g[2][j]);
            }
        }
    }
    
    cout << ans;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
    //freopen(INPUT, "r", stdin);freopen(OUTPUT, "w", stdout);
    //freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    int t = 1;
    //cin >> t;
    
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[105];
bool flag[105];
int main()
{
	int x,n,i;
	cin>>x>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		flag[a[i]]=true;
	}
	for(i=0;i<=x;i++)
		if(!flag[x-i])
		{
			cout<<x-i;
			return 0;
		}
		else
			if(!flag[x+i])
			{
				cout<<x+i;
				return 0;
			}
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
typedef long long ll;
using namespace std;

int main() {
  int D, G, p[11], c[11];
  cin >> D >> G;
  rep(i,0,D) cin >> p[i] >> c[i];
  int ans = 1e9;
  for(int bit = 0; bit < (1 << D); ++bit){
    int s = 0, num = 0, rest_max = -1; 
    //sは得点の合計、numは解いた数の合計、rest_maxは解かなかった問題の中で最高点数の番号
    rep(i,0,D) {
      if(bit&1<<i) {
        s += 100 * (i+1) * p[i] + c[i];
        num += p[i];
      }
      else rest_max = i;
    }
    if(s < G) {
      int s1 = 100 * (rest_max + 1);
      int need = (G - s + (s1 - 1)) / s1; //rest_max番号の時にGを超えるために必要な試行回数を求める
      if(need >= p[rest_max]) continue; //中途半端に解く配点のためボーナス点数は考慮しない
      num += need;
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using llong = long long;
#define REP(I, N) for (std::decay_t<decltype(N)> I = 0, I##_LEN = (N); I < I##_LEN; ++I)
#define PER(I, N) for (auto I = (N) - 1; 0 <= I; --I)
#define ALLOF(c) begin(c), end(c)
#define SZ(c) static_cast<int>((c).size())
#define MEM0(x) memset((x), 0, sizeof(x))
#define MEMFF(x) memset((x), 0xFF, sizeof(x))
template<class T> const T big_number;
template<> const int big_number<int> = 1 << 30;
template<> const llong big_number<llong> = ((llong) 1) << 60;
template<class S>
S setdiff(const S& s1, const S& s2) {
    using std::begin; using std::end;
    S r;
    std::set_difference(begin(s1), end(s1), begin(s2), end(s2), std::inserter(r, end(r)));
    return r;
}

template <class It, class Func>
Func for_each_n2(
        It first, It last, int rank, Func f,
        std::vector<typename std::iterator_traits<It>::value_type>& v) {
    if (rank == 0) {
        f(v);
        return f;
    }
    const auto cfirst = first;
    for (; first != last; ++first) {
        v[rank - 1] = *first;
        for_each_n2(cfirst, last, rank - 1, f, v);
    }
    return f;
}
template <class It, class Func>
Func for_each_n(It first, It last, int rank, Func f) {
    std::vector<typename std::iterator_traits<It>::value_type> v;
    v.resize(rank);
    return for_each_n2(first, last, rank, f, v);
}



void solve() {
    int n, k;
    cin >> n >> k;  // n=品物の値段, k=嫌いな数字の数
    set<char> ds; // d[i]=嫌いな数字
    REP (i, k) {
        char d;
        cin >> d;
        ds.insert(d);
    }

    // 嫌いではない数字の重複順列を昇順に並べてn以上の最小のものを選択する
    const set<char> nums {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
    const set<char> cds = setdiff(nums, ds);  // 嫌いではない数字

    // nと同じ桁から見始める
    string sn = to_string(n);
    int i = SZ(sn);
    do {
        set<int> perm;   // 与えられた桁の重複順列
        for_each_n(ALLOF(cds), i, [&perm](const auto& v) {
                string s(ALLOF(v));
                perm.insert(stoi(s));
            });
        auto it = perm.lower_bound(n);
        if (end(perm) != it) {
            int ans = *it;
            cout << ans << endl;
            break;
        }
        ++i;
    } while (true);
}


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



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
vector<int> vis((int)1e6+5,0);
int main(){
        int n; cin>>n;
        int a[n]; for(int i=0;i<n;i++) cin>>a[i];
        for(int i=0;i<n;i++) vis[a[i]]++; int cnt=0;
        for(int i=0;i<n;i++) {
                if(vis[a[i]]>1) continue;
                if(a[i]==1){ cnt++; continue;}
                int flag=0;
                for(int j=1;j*j<=a[i];j++){
                	if(j==1) { if(vis[j]){flag=1; break;}  }
                    else if(!(a[i]%j)&&(vis[j]||vis[a[i]/j])) {flag=1; break;}
                }
                if(!flag)cnt++;
        }
        cout<<cnt<<endl;
}

Measured memory_bytes: 7944
#include <stdio.h>
#include <stdint.h>
#include <iostream>
#include <fstream>
#include <cassert>
#include <climits>
using namespace std;

#define DEBUG (0)

#if DEBUG
#define DPRINTF(...) do { \
    printf("D(L%d) %s: ", __LINE__, __func__); \
    printf(__VA_ARGS__); \
  } while (false)
#else
#define DPRINTF(...)
#endif // DEBUG


inline int getLeftChildIdx(int idx) {
  return (2 * idx + 1);
}


inline int getRightChildIdx(int idx) {
  return (2 * idx + 2);
}


void swap(int &a, int &b) {
  int c = b; b = a; a = c;
}


void maxHeapify(int array[], int maxOfIndex, int idx) {

  DPRINTF("idx %d\n", idx);

  if (idx >= maxOfIndex)
    return ;

  // check which is the most greatest number among the node, left and right childs
  const int leftChildIdx = getLeftChildIdx(idx);
  const int rightChildIdx = getRightChildIdx(idx);

  const int parent = array[idx];

  int largestIdx;
  if (leftChildIdx < maxOfIndex && array[leftChildIdx] > parent)
    largestIdx = leftChildIdx;
  else
    largestIdx = idx;

  if (rightChildIdx < maxOfIndex && array[rightChildIdx] > array[largestIdx])
    largestIdx = rightChildIdx;

  if (largestIdx != idx) {
    DPRINTF("swap array[%d] array[%d]\n", idx, largestIdx);
    swap(array[idx], array[largestIdx]);
    maxHeapify(array, maxOfIndex, largestIdx);
  }

#if DEBUG
  DPRINTF("");
  for (int i = 0; i < maxOfIndex; i++) {
    printf(" %d", array[i]);
  }
  cout << endl;
#endif

}


int main() {
  int numOfNode;
  cin >> numOfNode; cin.ignore();

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

#if DEBUG
  DPRINTF("");
  for (int i = 0; i < numOfNode; i++) {
    printf(" %d", array[i]);
  }
  cout << endl;
#endif

  for (int i = numOfNode/2; i >= 0; i--) {
    maxHeapify(array, numOfNode, i);
  }

  for (int i = 0; i < numOfNode; i++) {
    printf(" %d", array[i]);
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 5096
import java.util.Scanner;

public class Main {

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

	    int a=gi();
	    int b=gi();

        //System.out.println();
        if (a>b) {
        	System.out.print(a-1);
        }else {
        	System.out.print(a);
        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
	
	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35244
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define REP(i,j) for(int i=0;i<j;i++)
#define FORN(i,j,k) for(int i=j;i<k;i++)
#define vi vector<int>
#define vvi vector<vi >
#define pii pair<int,int>
#define vpii vector<pii >
using namespace std;
int n;
set<string>c;
int main(void){
	cin>>n;
	REP(i,n){
		string s;
		cin>>s;
		c.insert(s);
	}
	cout<<c.size();
	return 0;
}

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

using namespace std;

const int N=100005;
int n,a[N],b[N];

inline bool comp(const int&x,const int&y){return x>y;}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1,comp);
	for(int i=n;i>=1;i--)b[i]=a[i]==a[i+1]?1-b[i+1]:0;
	int p=1;
	while(p<=a[p])p++;p--;
	bool fl=(a[p]-p+b[p])&1;
	if(p==a[p+1])fl|=!b[p+1];
	if(fl)puts("First");else puts("Second");
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) throws Exception {
	    Scanner sc = new Scanner(System.in);   
	    
	    float A = sc.nextFloat();
	    float B = sc.nextFloat();
	    
	    System.out.println(Math.round((A + B) / 2));
	}    
}	

Measured memory_bytes: 22484
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void solve()
{
	string str;
	int N;
	cin >> str >> N;
	vector<string> Vec(N);
	for(int i = 0; i < N; ++i)
	{
		cin >> Vec[i];
		Vec[i] += Vec[i];
	}
	int str_size = str.size();
	int count = 0;
	for(int i = 0; i < N; ++i)
	{
		int Vec_Size = Vec[i].size();
		for(int j = 0; j < Vec_Size; ++j)
		{
			if(str[0] == Vec[i][j])
			{
				bool flag = true;
				for(int k = 1; k < str_size; ++k)
				{
					if(str[k] != Vec[i][j + k])
					{
						flag = false;
					}
				}
				if(flag)
				{
					count++;
					break;
				}
			}
		}
	}
	cout << count << endl;
}

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

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
string a;
int x,y,ans,len;
int main()
{
    cin>>a;
    len=a.size();
    for(int i=0;i<len;i++)
    {
        if (x==y)
		{
		    ++x;
			if(a[i]=='p')
			    --ans;
		}
        else
		{
		    ++y;
			if(a[i]=='g')
			    ++ans;
		}
	}
    printf("%d\n",ans);
    return 0;
}

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

int main(){
  string a,b;
  cin >> a >> b;
  int ans = b.size();
  for (int i=0;i <= (a.size()-b.size());i++){
    int dd=0;
    for(int j=0;j < b.size();j++){
      if(a.at(i+j)!=b.at(j)) dd++;
    }
    ans = min(ans,dd);
  }
  cout << ans << endl;
}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (int)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

int main()
{
    ll n,ans=1;
    cin >> n;

    vll t(n);
    rep(i,n){
        cin >> t[i];
        ans = lcm(ans,t[i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define f first
#define s second
int fun(int x,int n,int m)
{
    int ans=1;
    while(n>0)
    {
        if(1&n)
            ans=(ans*x)%m;
        n=n>>1;
        x=(x*x)%m;
    }
    return ans;
}

signed main()
{
  int n,p1=0,p2=0;


  string s;
  cin>>n>>s;
  int k=count(s.begin(),s.end(),'1');
    if(k>1)
    for(int i=0;i<n;i++)
    {
        if(s[i]=='1')
            p1+=fun(2,n-i-1,k-1);
    }
    int arr[n]={0};
    for(int i=0;i<n;i++)
    {
        if(s[i]=='1')
            p2+=fun(2,n-i-1,k+1);
    }

        for(int i=0;i<n;i++)
    {
        int p;int ans=1;
        if(s[i]=='1' && k>1)
        {
              p=(p1-fun(2,n-i-1,k-1)+(k-1))%(k-1);

              while(p>0)
              {
                  int q=0,r=p;
                  while(r>0)
                  {
                      if(1&r)
                      q++;
                      r=r>>1;
                  }
                  p=p%q;
                  ans++;
              }
              arr[i]=ans;

        }
        else if(s[i]=='0')
        {
             p=(p2+fun(2,n-i-1,k+1))%(k+1);
             while(p>0)
              {
                  int q=0,r=p;
                  while(r>0)
                  {
                      if(1&r)
                      q++;
                      r=r>>1;
                  }
                  p=p%q;
                  ans++;
              }
              arr[i]=ans;
        }

    }
    for(int i=0;i<n;i++)
        cout<<arr[i]<<endl;

}




























































































































































































































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

const int M=1e4+5;
const int MD=105;
const int MO=1e9+7;
inline int add(int x,int y)
{
	x+=y;
	if(x>=MO) x-=MO;
	return x;
}
inline void addv(int &x,int y)
{
	x+=y;
	if(x>=MO) x-=MO;
}
inline int mul(int x,int y)
{
	return 1LL*x*y%MO;
}

char s[M];
int dp[M][MD][2];
int n,d;
int getdp(int cur,int nd,int lim)
{
	if(cur==n) return nd==0;
	int &ans=dp[cur][nd][lim];
	if(ans!=-1) return ans;
	ans=0;
	int up=lim?s[cur]-'0':9;
	for(int i=0;i<=up;i++)
		addv(ans,getdp(cur+1,(nd+i)%d,lim&&i==up));
	return ans;
}

int main()
{
	scanf("%s%d",s,&d);
	n=strlen(s);
	memset(dp,-1,sizeof(dp));
	printf("%d\n",add(getdp(0,0,1),MO-1)); // 0 is not counted
	return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;

  vector<vector<int>> path(n, vector<int>(n));
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    path[a][b] = 1;
    path[b][a] = 1;
  }

  vector<int> ord;
  rep(i, n) {
    ord.push_back(i);
  }

  int ans = 0;
  do
  {
    if (ord[0] != 0) break;

    bool ok = true;
    rep(i, n - 1){
      if (path[ord[i]][ord[i + 1]] == 0) {
        ok = false;
        break;
      }
    }
    if (ok) ans++;
  } while (next_permutation(ord.begin(), ord.end()));

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector <vector<long>> act(3);
    act[0]=vector<long>(n,0);
    act[1]=vector<long>(n,0);
    act[2]=vector<long>(n,0);
    for(int i = 0; i < n; i++){
        cin >> act[0][i] >> act[1][i] >> act[2][i];
    }
    vector <vector<long>> dpvv(3);
    dpvv[0]=vector<long>(n,0);
    dpvv[1]=vector<long>(n,0);
    dpvv[2]=vector<long>(n,0);
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            if(i==0){
                dpvv[j][i]=act[j][i];
            }else{
                vector <long> oldDp;
                for(int k = 0; k < 3; k++){
                    if(j!=k){
                        oldDp.push_back(dpvv[k][i-1]);
                    }
                }
                dpvv[j][i]=act[j][i]+max(oldDp[0],oldDp[1]);
            }
        }
    }
    long ans = dpvv[0].back();
    for(int i = 0; i < 3; i++){
        ans = max(ans,dpvv[i].back());
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8012
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

ll r, D, x;

int main() {
	cin >> r >> D >> x;
	for (int i = 0; i < 10; ++i) {
		x = x*r - D;
		cout << x << endl;
	}
}


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

int main() {
	// your code goes here
	string s1,s2;
	cin>>s1>>s2;
	int n1=s1.length();
	int n2=s2.length();
	int LCS[n1+1][n2+1];
	for(int i=0;i<=n1;i++)
	{
		for(int j=0;j<=n2;j++)
			{
				if(i==0 or j==0)LCS[i][j]=0;
				if(i>0 and j>0)
				{
					if(s1[i-1]==s2[j-1])LCS[i][j]=1+LCS[i-1][j-1];
					else
					  LCS[i][j]=max(LCS[i-1][j],LCS[i][j-1]);
				}
			}
	//}
	// for(int i=0;i<=n1;i++)
	// {
	// 	for(int j=0;j<=n2;j++)
	// 	{
	// 		cout<<LCS[i][j]<<" ";
	// 	}
	// 	cout<<"\n";
	}
	int i=n1;
	int j=n2;
	vector<int>v;
	while(i>0 and j>0)
	{
		if(s1[i-1]==s2[j-1])
		{
			v.push_back(i-1);
			i-=1;
			j-=1;
		}
		if(s1[i-1]!=s2[j-1])
		{
			if(LCS[i-1][j]>=LCS[i][j-1])
			{
				i-=1;
			}
			if(LCS[i-1][j]<LCS[i][j-1])
			{
				j-=1;
			}
		}
	}
	sort(v.begin(),v.end());
	for(i=0;i<v.size();i++)
	{
		cout<<s1[v[i]];
	}
	return 0;
}

Measured memory_bytes: 35456
ABCD = input()
res = 0
for i in range(1 << 3):
    l = []
    for j in range(3):
        if i >> j & 1 == 1:
            l.append(ABCD[j])
            l.append("+")
        else:
            l.append(ABCD[j])
            l.append("-")
    l.append(ABCD[-1])
    l = ''.join(l)
    res = eval(l)
    if res == 7:
        print(l + "=7")
        exit()

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

const long mod = 1e9+7;

long power(long a,long b)
{
	return b ? power(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1;
}

long comb(long a, long b)
{
	long res = 1;
	for (long i = a; i > a - b; i--)
	{
		res = res * i % mod;
	}
	for (long i = 1; i <= b; i++)
	{
		res = (res * power(i, mod - 2)) % mod;
	}
	return res;
}

int main()
{
	long N, A, B;
	cin >> N >> A >> B;
	long ans = power(2, N);
	ans--;
	ans -= comb(N, A);
	ans -= comb(N, B);
	while (ans < 0) ans += mod;
	cout << ans << "\n";
}

Measured memory_bytes: 256
N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)

cnt = 0
N.times do |i|
  # i番目の街のモンスターを倒す
  if A[i] > B[i]
    A[i] -= B[i]
    cnt += B[i]
    B[i] -= B[i]
  else
    B[i] -= A[i]
    cnt += A[i]
    A[i] = 0
  end

  # i+1番目の街のモンスターを倒す
  if A[i+1] > B[i]
    A[i+1] -= B[i]
    cnt += B[i]
    B[i] -= B[i]
  else
    B[i] -= A[i+1]
    cnt += A[i+1]
    A[i+1] = 0
  end
end

puts cnt

Measured memory_bytes: 15396
#include <algorithm>
#include <cmath>
#include <cstdio>

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

using namespace std;

int main(){
	int n,m; scanf("%d%d",&n,&m);

	int ans=1;
	rep(g,sqrt(m)) if(g>0 && m%g==0) {
		if( g <=m/n) ans=max(ans, g );
		if(m/g<=m/n) ans=max(ans,m/g);
	}
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	int n,p,sum=0,max=0,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
	scanf("%d",&p);
	sum+=p;
	if(p>max){
		max=p;
		}
	}
	printf("%d\n",sum-max/2);
	return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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;
}

vector<int> as;

int main(void) {
    int N, M;
    cin >> N >> M;

    int sum = 0;
    as.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> as[i];
        sum += as[i];
    }

    int count = 0;
    for (int i = 0; i < N; i++) {
        if (as[i] * 4 * M >= sum) {
            count++;
        }
    }

    if (count >= M) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n;
  if (n % 2 == 0)
    Cout(-1);
  else {

    ll ans=7;
    while (1) {
      cnt++;
      if (ans % n == 0) {
        Cout(cnt);
        return 0;
      }
      
      ans %= n;
      ans=10*ans+7;
      
      if (cnt >= 1000000 * 2) break;
    }
    if (cnt == 1000000 * 2) Cout(-1);
  }
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  int cnt = 0;

  for (int i = 1; i <= n; ++i) {
    if (p[i-1] != i) cnt += 1;
  }
  
  if (cnt == 2 or cnt == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
81 58
)");
#define cin input
#endif

class SegmentTree{
	int n;
	vector<int>A,st;
	
	int left(int p)
	{
		return (p<<1);
	}
	
	int right(int p)
	{
		return (p<<1)+1;
	}
	
	void build(int p,int l,int r)
	{
		if(l==r)
		st[p]=l;
		else
		{
			build(left(p),l,(l+r)/2);
			build(right(p),((l+r)/2)+1,r);
			long long li=st[left(p)];
			long long ri=st[right(p)];
			
			if(A[li]<A[ri])
			st[p]=li;
			else
			st[p]=ri;				
		}
	}
	
	int rmq(int p,int l,int r,int i,int j)
	{
		if(i>r || j<l)
		return -1;
		else if(l>=i && r<=j)
		return st[p];
		
		int li=rmq(left(p),l,(l+r)/2,i,j);
		int ri=rmq(right(p),((l+r)/2)+1,r,i,j);
		
		if(li==-1)
		return ri;
		else if(ri==-1)
		return li;
		else
		{
			if(A[li]<A[ri])
			return li;
			else
			return ri;
		}
	}
	
	public:
		SegmentTree(const vector<int> &_A)
		{
			A=_A;
			n=(int)(A.size());
			st.assign(4*n,0);
			build(1,0,n-1);
		}
		
		int rmq(int i,int j)
		{
			return rmq(1,0,n-1,i,j);
		}
};

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

    vector<int> p[2] = {vector<int>(n/2), vector<int>(n/2)};

    REP (i, n / 2)
        cin >> p[0][i] >> p[1][i];
    
    SegmentTree st[2] = {SegmentTree(p[0]), SegmentTree(p[1])};

    map<int, array<int, 4>> q;

    const auto query = [&](int l, int r)
    {
        int lm = st[l % 2].rmq(l / 2, r / 2 - 1) * 2 + l % 2;
        int rm = st[(l + 1) % 2].rmq((lm + 1) / 2, (r - 1) / 2) * 2 + (l + 1) % 2;
        q.emplace(p[lm % 2][lm / 2], array<int, 4>{l - 1, lm, rm, r});
    };

    query(0, n);

    bool first = true;
    while (q.size())
    {
        const auto c = *q.begin();
        q.erase(q.begin());

        cout << (first ? "" : " ") << c.first << " " << p[c.second[2] % 2][c.second[2] / 2];
        first = false;

        for (int i = 0; i < 3; ++i)
            if (c.second[i] + 1 < c.second[i + 1])
                query(c.second[i] + 1, c.second[i + 1]);
    }

	cout << endl;

	return 0;
}


Measured memory_bytes: 8704
def is_575(bunsetsu_list):
    return bunsetsu_list.count(5) == 2 and bunsetsu_list.count(7) == 1
 
 
def main():
  bunsetsu_list = [int(i) for i in input().split()]
  print('YES' if is_575(bunsetsu_list) else 'NO')
  
  
main()

Measured memory_bytes: 2940
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;


public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Set<String> priseSet = new HashSet<>();
		
		for(int i = 0; i < n; i++) {
			String prise = sc.next();
			priseSet.add(prise);
		}

		System.out.println(priseSet.size());
		sc.close();
	}

}

Measured memory_bytes: 76784
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    h,w = LI()
    a = [input() for i in range(h)]
    d = defaultdict(lambda : 0)
    for i in a:
        for j in i:
            d[j] += 1
    d = list(d.values())
    n = (h>>1)*(w>>1)
    f = [i>>2 for i in d if i >= 4]
    if sum(f) < n:
        print("No")
        return
    fs = [i for i in d if i&1]
    if len(fs) > 1:
        print("No")
        return
    if (h*w)&1:
        if not fs:
            print("No")
            return
    elif fs:
        print("No")
        return
    print("Yes")
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 38640
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1, n-1):
    if (p[i] != max(p[i-1], p[i], p[i+1])) and (p[i] != min(p[i-1], p[i], p[i+1])):
        ans += 1
print(ans)


Measured memory_bytes: 9048
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<string>
#include <ios>     
#include <iomanip> 
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const llong MOD = 1000000007;

llong gcd(llong a, llong b) {
	if (a < b) swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}

llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}

//ここまで共通

int main() {
	int N, X, L[200];
	cin >> N >> X;
	int D = 0, ANS = 1;
	for (int i = 0; i < N; i++) {
		cin >> L[i];
		D += L[i];
		if (D <= X) ANS++;
		else {
			cout << ANS;
			break;
		}
	}
	if (ANS == N + 1) cout << N + 1;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int a,b,c,d;
  
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  
  d = b/a;
  
  if(d >= c)
  printf("%d",c);
  
  else
    printf("%d",d);
  
  return 0;
  
}


Measured memory_bytes: 128
$<.each do |line|
  stack = line.chomp.split
  #逆ポーランド記法
  n = []
  stack.each do |x|
    n << (x =~ /\d/ ? x.to_f : eval(n.pop(2).join(x)))
  end
  # inject =>CPU:00.02sec Memory:6164KB
  #n = stack.inject([]) do |s, x|
  #  s << (x =~ /\d/ ? x.to_f : eval(s.pop(2).join(x)))
  #end
  puts sprintf("%.6f", n.first)
end

Measured memory_bytes: 6160