akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define mp(a,b) make_pair(a,b)
#define vi vector<int>
#define mii map<int,int>
#define mpi map<pair<int,int>,int>
#define vp vector<pair<int,int> >
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define F first
#define S second
#define endl "\n"
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define dom 998244353
#define pi 3.14159265
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
#define pii pair<int,int> 
#define mini 2000000000000000000
#define time_taken 1.0 * clock() / CLOCKS_PER_SEC
//mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
struct Query 
{ 
    int l, r, idx; 
};
bool cmp(Query x, Query y) 
{ 
    return x.r < y.r; 
} 
void update(int idx, int val, int bit[], int n) 
{ 
    for (; idx <= n; idx += idx&-idx) 
        bit[idx] += val; 
} 
int query(int idx, int bit[], int n) 
{ 
    int sum = 0; 
    for (; idx>0; idx-=idx&-idx) 
        sum += bit[idx]; 
    return sum; 
} 
void shikhar7s(int cas)
{
    int n,i,q;
    cin>>n>>q;
    int arr[n];
    fr(i,n)
    {
        cin>>arr[i];
    }
    Query queries[q];
    int x,y;
    fr(i,q)
    {
        cin>>x>>y;
        x--;
        y--;
        queries[i].l=x;
        queries[i].r=y;
        queries[i].idx=i;
    }
    sort(queries, queries+q, cmp); 
    int bit[n+1]; 
    memset(bit, 0, sizeof(bit)); 
    int last_visit[500005]; 
    memset(last_visit, -1, sizeof(last_visit)); 
    int ans[q]; 
    int query_counter = 0; 
    for (int i=0; i<n; i++) 
    { 
        if (last_visit[arr[i]] !=-1) 
            update (last_visit[arr[i]] + 1, -1, bit, n); 
        last_visit[arr[i]] = i; 
        update(i + 1, 1, bit, n); 
        while (query_counter < q && queries[query_counter].r == i) 
        { 
            ans[queries[query_counter].idx] = query(queries[query_counter].r + 1, bit, n)- query(queries[query_counter].l, bit, n); 
            query_counter++; 
        } 
    } 
    for (int i=0; i<q; i++) 
        cout << ans[i] << endl; 
}
signed main()
{
    fast;
    int t=1;
    //cin>>t;
    int cas=1;
    while(cas<=t)
    {
    shikhar7s(cas);
    cas++;
    }
    return 0;
}

Measured memory_bytes: 31092
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
//#define X first
#define Y second
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const LL INF = 1e9;
const LL LINF = INF * INF;
const LL MAXN = 507;

int x, A[MAXN * MAXN];
bool F[MAXN * MAXN], flag = true;

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	int n;
	cin >> n;
	FOR(i, 1, n + 1)
	{
		cin >> x;
		A[x] = i;
		F[x] = true;
	}
	int p = 1;
	FOR(i, 1, n * n + 1)
	{
		if (F[i])
		{
			REP(j, A[i] - 1)
			{
				while (A[p] && p < i) ++p;
				if (p == i) flag = false;
				A[p] = A[i];
			}
		}
	}
	p = n * n;
	RFOR(i, n * n + 1, 1)
	{
		if (F[i])
		{
			REP(j, n - A[i])
			{
				while (A[p] && p > i) --p;
				if (p == i) flag = false;
				A[p] = A[i];
			}
		}
	}
	if (flag)
	{
		cout << "Yes\n";
		FOR(i, 1, n * n + 1) cout << A[i] << ' ';
	}
	else cout << "No\n";
	//cout << endl; system("pause");
	return 0;
}

Measured memory_bytes: 2304
#include <iostream>
     
    using namespace std;
     
    int main(){
    int N,M,X,Y;
     
    cin>>N>>M>>X>>Y;
     
    int  x_max=-200,y_min=200;
     
    for(int i=0;i<N;i++){
    int temp;
    cin >>temp;
    if(temp>=x_max) x_max=temp;
    }
    for(int i=0;i<M;i++){
    int temp;
    cin >> temp;
    if(temp<y_min) y_min=temp;
    }
     
    int x_z=x_max+1,y_z=y_min;
    if(x_z<=y_min&&x_z>X&&x_z<=Y&&y_min>X&&y_min<=Y) cout<<"No War"<<endl;
    else cout<<"War"<<endl;
     
    return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<ll, ll> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

typedef ll Weight;
const ll INF = 1e12;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

void dijkstra(Graph &g, int s, Array &d)
{
	d.assign(g.size(), INF);
	d[s] = 0;
	typedef pair<Weight, int> P;
	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(0, s));
	while (!que.empty())
	{
		Weight dist = que.top().first;
		int v = que.top().second;
		que.pop();
		if (d[v] < dist) continue;
		REP(i, g[v].size())
		{
			Edge e = g[v][i];
			if (d[e.to] > d[v] + e.cost)
			{
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}


int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, m, c;
	cin >> n >> m >> c;
	Graph g(n);
	ll sum = 0;
	REP(i, m)
	{
		int a, b, d; cin >> a >> b >> d;
		a--; b--;
		sum += d;
		add_edge(g, a, b, d);
		add_edge(g, b, a, d);
	}
	Array dist;
	dijkstra(g, 0, dist);
	vector<pii> v;
	REP(i, n) v.emplace_back(dist[i], i);
	sort(ALL(v));
	set<int> used;
	ll ans = INF;
	REP(i, n)
	{
		int t = v[i].second;
		for (auto e : g[t])
		{
			if (!used.count(e.to)) continue;
			sum -= e.cost;
		}
		chmin(ans, c * v[i].first + sum);
		used.insert(t);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int n, m;
  cin>>n>>m;
  int edge[n][n];
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      edge[i][j] = -1;
    }
  }
  for (int i=0; i<m; i++) {
    int a, b, c;
    cin>>a>>b>>c;
    --a; --b;
    edge[a][b] = c;
    edge[b][a] = c;
  }
  int d[n][n];
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      if (edge[i][j] > 0) {
        d[i][j] = edge[i][j];
      } else {
        d[i][j] = 1e7;
      }
    }
  }
  set<pair<int, int> > s;
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      for (int k=0; k<n; k++) {
        int d1 = d[j][k];
        int d2 = d[j][i] + d[i][k];
        if (d2 < d1) {
          d[j][k] = d2;
          if (edge[j][k] > 0) {
            if (k > j) {
              s.insert(make_pair(j, k));
            } else {
              s.insert(make_pair(k, j));
            }
          }
        }
      }
    }
  }
  cout<<s.size()<<endl;
}

Measured memory_bytes: 384
n=gets.to_i
a=gets.split.map(&:to_i)
n.times do |i|
  a[i] -= i+1
end
m=1/0.0
a.sort!
v=a[n/2-1]
w=a[n/2]
c = a.each.map {|ai| (ai-v).abs}.inject(:+)
m = c if m > c
c = a.each.map {|ai| (ai-w).abs}.inject(:+)
m = c if m > c
puts m

Measured memory_bytes: 21228
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define _GLIBCXX_DEBUG
#define INF 100000010
 #define PI 3.14159265359

using namespace std;
const int64_t mod = 1000000007;
const int64_t tmpMod = 998244353;

int main() {
 
  int64_t N,ans=0;
  cin>>N;
  vector<int64_t> A(N);
  for(int i=0; i<N; i++){cin>>A[i];}
  //vector<vector<int> > A(N,vector<int>(M));
  //for(int i=0; i<N; i++){for(int j=0; j<M; j++){cin>>A[i][j];}}
  sort(A.begin(),A.end(), greater<int>());
  if(N==1){cout<<0<<endl;return 0;}
  else if(N==2){cout<<A[0]<<endl;return 0;}
  else{
    ans+=A[0];
  }
  int j =0;
  for(int i=1; i<N; i++){ans+=A[i];j++;if(j==N-2)break;ans+=A[i];j++;if(j==N-2)break;}


  //for (int i = 0; i < N; i++) { maximum = max(maximum , A[i]);}
  //for (int i = 0; i < N; i++) { minimum = min(minimum , A[i]);}
  cout << ans << endl;
}
 

Measured memory_bytes: 4764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

ll dp[310][90400];

int main()
{
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for(int i = 0; i < 1000; i++){
        string t = "";
        if(i < 10){
            t += "00";
        }else if(i < 100){
            t += '0';
        }
        t += to_string(i);
        int cnt = 0;
        for(int j = 0; j < n; j++){
            if(s[j] == t[cnt]){
                cnt++;
            }
            if(cnt == 3){
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
  
  int N, K; cin >> N >> K; int dif = pow(10, 9) + 1;
  
  vector<int> vec(N);
  
  for (int i = 0; i < N; i++) cin >> vec[i];
  
  sort(vec.begin(), vec.end());
  
  for (int i = 0; i + K - 1 < N; i++) {
    
    int tmp = vec[i + K - 1] - vec[i];
    
    dif = min(dif, tmp);
    
  }
  
  cout << dif << endl;
  
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
const int MAX = 1e5;
int dp[MAX+1];
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n, k; cin >> n >> k;
   vector<int>h(n+1);
   rep(i,n)cin>>h[i+1];
   dp[1]=0;
   for (int i = 2; i <= n; i++){
      dp[i] = dp[i-1]+abs(h[i]-h[i-1]);
      for (int j = 2; j <= min(k,i-1); j++){
         dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
      }
   }
   cout << dp[n] << endl;
}

Measured memory_bytes: 4024
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Libraries --------------------------------//

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int q;
    cin >> q;
    bitset<64> akarin;
    while (q--)
    {
        int x, i;
        cin >> x;
        switch (x)
        {
        case 0:
            cin >> i;
            cout << akarin.test(i) << '\n';
            break;
        case 1:
            cin >> i;
            akarin.set(i);
            break;
        case 2:
            cin >> i;
            akarin.set(i, 0);
            break;
        case 3:
            cin >> i;
            akarin.flip(i);
            break;
        case 4:
            cout << akarin.all() << '\n';
            break;
        case 5:
            cout << akarin.any() << '\n';
            break;
        case 6:
            cout << akarin.none() << '\n';
            break;
        case 7:
            cout << akarin.count() << '\n';
            break;
        case 8:
            cout << akarin.to_ullong() << '\n';
            break;
        default:
            break;
        }
    }
}

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



Measured memory_bytes: 3100
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		int[][] den=new int[11][11];
		int[] sw=new int[11];
		Arrays.fill(sw,0);
		for(int i=0; i<M; i++) {
			int k=sc.nextInt();
			sw[i+1]=k;
			for(int j=0; j<k; j++) {
				den[i+1][j]=sc.nextInt();
			}
		}
		int zenre=1;
		for(int i=0; i<N; i++) {
			zenre*=2;
		}
		int[] amari=new int[M+1];
		amari[0]=0;
		for(int i=1; i<=M; i++) {
			amari[i]=sc.nextInt();
		}
		int ans=0;
		int[] onoff=new int[N+1];
		for(int i=0; i<zenre; i++) {
			int tento=0;
			int tmp=i;
			for(int j=0; j<N; j++) {
				onoff[j+1]=tmp%2;
				tmp/=2;
			}

			for(int j=1; j<=M; j++) {
				int tuki=0;
				for(int k=0; k<sw[j]; k++) {
					tuki+=onoff[den[j][k]];
				}
				if(tuki%2==amari[j]) {
					tento++;
				}
			}
			if(tento==M) {
				ans++;
			}
		}
		pl(ans);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

Measured memory_bytes: 23636
#include<iostream>
#include<vector>

#define MOD 1e9+7

int main()
{
    long long k;
    int n;
    std::cin>>n>>k;
    std::vector<long long> a(n);
    int i,j;
    for(i=0;i<n;i++)std::cin>>a.at(i);
    long long k1=k+1;
    std::vector<int> kk(40,0);
    std::vector<int> count(40,0);
    for(i=0;i<40;i++)
    {
        kk.at(i)=k1%2;
        k1/=2;
        for(j=0;j<n;j++)
        {
            count.at(i)+=a.at(j)%2;
            a.at(j)/=2;
        }
    }
    long long ansmid;
    long long ansfinal;
    long long num;
    bool out;
    for(i=0;i<40;i++)
    {
        ansmid=0;
        num=1;
        out = false;
        if(kk.at(i)!=1)continue;
        for(j=0;j<40;j++)
        {
            if(j<i)
            {
                ansmid += num*std::max(count.at(j),n-count.at(j));
            }
            else if(j>i)
            {
                ansmid += num*(count.at(j)*(1-kk.at(j))+kk.at(j)*(n-count.at(j)));
            }
            else
            {
                if(kk.at(j)!=1)
                {
                    out = true;
                    break;
                }
                ansmid+=num*count.at(j);
            }
            num*=2;
        }
        if(!out&&ansmid>ansfinal)ansfinal=ansmid;
    }
    std::cout<<ansfinal<<std::endl;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 100005

int n , h;
int a[MAXX];

int main()
{
    _FastIO;
    cin >> h >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        h -= a[i];
    }
    if(h > 0){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 4012
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int x;
    cin >> x;
    switch(x){
        case 7:
        case 5:
        case 3:
            cout << "YES" << endl;
            break;
        default:
            cout << "NO" << endl;
            break;
    }
    return 0;
}

Measured memory_bytes: 256
import heapq

n, k = map(int, input().split())
a = [0] * (n + 1)
typecnt = 0
h = []
heapq.heapify(h)
for _ in range(n):
    t, d = map(int, input().split())
    if a[t] == 0:
        typecnt += 1
        a[t] = 1
    heapq.heappush(h, [-d, t])
ans = 0
mintype = 0
m = []
heapq.heapify(m)
for _ in range(k):
    d, t = heapq.heappop(h)
    if a[t] == 1:
        mintype += 1
        a[t] = 0
    else:
        heapq.heappush(m, -d)
    ans -= d
cnt = ans
ans += mintype * mintype
for j in range(mintype, typecnt):
    if not m:
        break
    bonus = (j + 1) * (j + 1)
    while h:
        d, t = heapq.heappop(h)
        if not m:
            break
        if a[t] == 1:
            a[t] = 0
            l = heapq.heappop(m)
            cnt -= (d + l)
            ans = max(ans, cnt + bonus)
            break
print(ans)

Measured memory_bytes: 93376
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        int x,y,z;

        if(a>=b && a>=c){
            x=a;
            if(b>c){
                y=b;
                z=c;
            } else {
                y=c;
                z=b;
            }
        } else if(b>=a && b>=c){
            x=b;
            if(a>c){
                y=a;
                z=c;
            } else {
                y=c;
                z=a;
            }
        } else {
            x=c;
            if(a>b){
                y=a;
                z=b;
            } else {
                y=b;
                z=a;
            }
        }
        System.out.printf("%d %d %d\n",z,y,x);
        sc.close();
    }   
}


Measured memory_bytes: 26252
lines = $stdin.read
array = lines.split("\n")

N = array[0].to_i
d = array[1].split(" ").map(&:to_i)
M = array[2].to_i
t = array[3].split(" ").map(&:to_i)

# p N
# p d
# p M
# p t

# M - N, and if there are something it's not sufficient
# scores.delete_if {|key, val| val < 50 }
having = Hash.new(0).tap do |h|
  d.each do |elem|
    #p elem
    h[elem] += 1 # unless elem.nil?
  end
end

ideal  = Hash.new(0).tap do |h|
  t.each do |elem|
    #p elem
    h[elem] += 1 # unless elem.nil?
  end
end

if ideal.any?{|k,v| not having.has_key?(k) or (having.has_key?(k) and having[k] < ideal[k]) }
  puts "NO"
else
  puts "YES"
end

Measured memory_bytes: 58876
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {

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

	sort(p.begin(), p.end());
	double x = p[0] + p[1];
	x /= 2;
	for (int i = 2; i < n; i++) {
		x += p[i];
		x /= 2;
	}
	cout << setprecision(20);
	cout << x << endl;
	return 0;


}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7
def add(a, b):
  return (a + b) % MOD
def sub(a, b):
  return (a - b) % MOD
def mul(a, b):
  return ((a % MOD) * (b % MOD)) % MOD
def div(a, b):
  return ( (a % MOD) * (power(b, MOD)) ) % MOD
def power(a, b):
  return pow(a, b, MOD)


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
  
N = 2001001
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % MOD )
    inverse.append( ( -inverse[MOD % i] * (MOD//i) ) % MOD )
    g2.append( (g2[-1] * inverse[-1]) % MOD )

k = int(input())
s = input()
n = len(s)
total = 0
for i in range(k+1):
  ans = cmb(n+i-1, n-1, MOD) * power(25, i) * power(26, k-i)
  total = (total + ans) % MOD
print(total)



Measured memory_bytes: 223004
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>

using namespace std;
using ll = long long;
using pint = pair<int, int>;

ll INF = 1LL << 60;

int main() {
	int n;
	cin >> n;
	vector<int> A(n);
	for (int i = 0; i < n; i++) cin >> A[i];
	int q;
	cin >> q;
	vector<int> m(q);
	for (int i = 0; i < q; i++) cin >> m[i];

	vector<string> ans(q, "no");
	for (int bit = 0; bit < (1 << n); bit++) {
		int sum = 0;
		for (int i = 0; i < n; i++) {
			if (bit & (1 << i)) sum += A[i];
		}
		for (int i = 0; i < q; i++) {
			if (sum == m[i]) ans[i] = "yes";
		}
	}
	for (int i = 0; i < q; i++) cout << ans[i] << endl;
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    map<ll, ll> mp;
    vector<ll> vec;
    rep(i, n){
        ll num;
        cin >> num;
        vec.push_back(num);
        mp[num]++;
    }
    ll sum;
    for(int i=1; i<=n; i++){
        sum += mp[i]*(mp[i]-1)/2;
    }
    rep(i, n){
        cout << sum-((mp[vec[i]])*((mp[vec[i]])-1)/2)+(((mp[vec[i]])-1)*((mp[vec[i]])-2)/2) << endl;
    }
    return 0;
}

Measured memory_bytes: 16624
import java.util.*;
import java.io.*;
 
public class Main {
    public static long ans(long[] A){
        int N = A.length;
        long ans = 0;
        
        if(A[N-1]>=N)return -1;
        ans += A[N-1];
        long next = A[N-1]-1;
        for(int n=N-2;n>=0;n--){
        	if(A[n]>n || A[n]<next) return -1;
        	if(A[n]>next) ans += A[n];
        	next = A[n]-1;
        }
        return ans;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A = new long[N];
        for(int n=0;n<N;n++) A[n]=sc.nextLong();
        System.out.println(ans(A));
    }
}

Measured memory_bytes: 82840
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")

// Begin {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

template <class A, class B> inline bool chmax(A &a, const B &b) noexcept {
    return b > a && (a = b, true);
}

template <class A, class B> inline bool chmin(A &a, const B &b) noexcept {
    return b < a && (a = b, true);
}

template <class T>
inline vector<T> make_v(const T &initializeValue, size_t sz) {
    return vector<T>(sz, initializeValue);
}

template <class T, class... Args>
inline auto make_v(const T &initializeValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initializeValue, args...))>(sz, make_v<T>(initializeValue, args...));
}

constexpr int INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}} End

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    size_t N; cin >> N;

    vector<intmax_t> a(N), b(N), c(N);
    for (auto &ai: a) cin >> ai;
    for (auto &bi: b) cin >> bi;
    for (auto &ci: c) cin >> ci;

    sort(a.begin(), a.end());
    sort(c.begin(), c.end());

    intmax_t res = 0;
    for (const auto bi: b) {
        intmax_t cntA = prev(lower_bound(a.begin(), a.end(), bi)) - a.begin() + 1;
        intmax_t cntC = c.end() - upper_bound(c.begin(), c.end(), bi);
        res += cntA * cntC;
    }

    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 2560
#include <iostream>

int main()
{
  using namespace std;
  int N;
  double M;
  cin >> N >> M;
  int A[1000], i = 0;
  int count = 0;
  double sum = 0.0;
  while (i < N)
  {
    cin >> A[i];
    sum += A[i];
    i++;
  }
  for (i = 0; i < N; i++)
  {
    if (A[i] >= sum / (4 * M))
    {
      count++;
    }
  }
  // cout << count << endl;
  if (count >= M)
    cout << "Yes";
  else
    cout << "No";
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

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

vector<ll> a;

ll swap(ll a, ll b) {
    ll tmp;
    tmp = a;
    a = b;
    b = tmp;
}

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

ll lcm(ll a, ll b) {
    return a*b/gcd(a, b);
}

ll cnt_2(ll k) {
    ll tmp = k;
    ll ans = 0;
    while (tmp) {
        tmp /= 2;
        ans++;
    }
    return ans;
}


int main() {
    ll n, m;
    cin >> n >> m;
    ll tmp;
    bool flag = true;
    ll times_2;
    rep(i, n) {
        cin >> tmp;
        tmp /= 2;
        a.push_back(tmp);
    }

    ll lc = 1;
    rep(i, n) {
         lc = lcm(a[i], lc);
    }

    ll ans = m/lc;
    ans = (ans+1)/2;

    if (lc > m) ans = 0;

    rep(i, n) {
        if ((lc/a[i])%2 == 0) {
            cout << 0 << endl;
            return 0;
        }
    }


    cout << ans << endl;

}



Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define R register
#define ll long long
#define mp make_pair
#define pii pair<int, int>
using namespace std;
const int N = 110000, mod = 1e9 + 7;

int n, k, a[N], fac[N], inv[N], ans;

inline ll comb(int n, int m) {
    if (n < m || m < 0) return 0;
    return (ll) fac[n] * inv[m] % mod * inv[n - m] % mod;
}

template <class T>
inline void read(T &x) {
    x = 0;
    char ch = getchar(), w = 0;
    while (!isdigit(ch)) w = ch == '-', ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
    x = w ? -x : x;
    return;
}

inline ll quickpow(ll base, ll pw) {
    ll ret = 1;
    while (pw) {
        if (pw & 1) ret = ret * base % mod;
        base = base * base % mod, pw >>= 1;
    }
    return ret;
}

int main() {
    read(n), read(k);
    for (R int i = 1; i <= n; ++i) read(a[i]);
    sort(a + 1, a + 1 + n);
    fac[0] = 1;
    for (R int i = 1; i <= n; ++i) fac[i] = (ll) fac[i - 1] * i % mod;
    inv[n] = quickpow(fac[n], mod - 2);
    for (R int i = n; i; --i) inv[i - 1] = (ll) inv[i] * i % mod;
    for (R int i = 1; i <= n; ++i)
        ans = (ans + (ll) a[i] * (comb(i - 1, k - 1) - comb(n - i, k - 1) + mod)) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include <stdlib.h>



int main(){

	int A, B, K;




	scanf("%d %d", &A, &B);

		K = A + B;

		if (K % 2 != 0){
			printf("IMPOSSIBLE\n");
		}
		else{
			printf("%d\n", K / 2);
		}
	
	return 0;

}
    


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int a,b,h; cin>>a>>b>>h;
	cout<<((a+b)*h)/2;
	return 0;
}

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

int N;
int A[200];

int main(){
    cin >> N;
    for(int i =0; i < N; i++){
        cin >> A[i];
    }
    bool even = true;
    int count = 0;
    while(even){
        for(int i = 0; i < N; i++){
            if(A[i] % 2 != 0){
                even = false;
                break;
            }
             A[i] /= 2;
            }
            if(even){
                count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N, W, w[101], v[102];
long long dp[102][100003];

long long rec(int pos, int val) {
	// printf("%d %d\n", pos, val);
	if(dp[pos][val] != -1) {
		return dp[pos][val];
	}
	long long ans = 2000000000000;
	if(pos != 0) {
		ans = rec(pos - 1, val);
	}
	if(v[pos] <= val && pos!=0) {
		ans = min(ans, w[pos] + rec(pos - 1, val - v[pos]));
	} else if(pos == 0 && v[pos]==val) {
		ans = w[pos];
	} else if(pos ==0 && val == 0) {
		ans = 0;
	}
	dp[pos][val] = ans;
	// printf("%lld\n", ans);
	return ans;
}

int main() {
	scanf("%d %d",&N, &W);
	for(int i=0;i<N;++i) {
		scanf("%d %d", &w[i], &v[i]);
	}
	memset(dp, -1, sizeof(dp));
	for(int i=N*1000 + 1;i>=0;--i) {
		for(int j=N-1;j>=0;--j) {
			if(rec(j, i) <= W) {
				printf("%d", i);
				return 0;
			}
		}
	}
}

Measured memory_bytes: 80000
import qualified Data.Vector.Unboxed as V
import Data.Array.IArray (listArray, accumArray, (!))
import Data.Array.MArray
import Data.Array.ST (STUArray, runSTUArray)
import Data.Array.Unboxed (UArray)
import Data.List (sortOn, sortBy, unfoldr, partition)
import Data.Char (isSpace)
import Control.Monad.ST (ST)
import Control.Monad.Trans.State (StateT(..))
import qualified Data.ByteString.Char8 as B

-- utility functions

--   Input functions
readInt = B.readInt . B.dropWhile isSpace

readInts :: Int -> B.ByteString -> [Int]
readInts n = take n . unfoldr readInt

readIntsV :: Int -> B.ByteString -> V.Vector Int
readIntsV n = V.unfoldrN n readInt

readIntsA :: Int -> B.ByteString -> UArray Int Int
readIntsA n bs = runSTUArray $ do
  arr <- newArray_ (0,n-1)
  go arr 0 bs
  return arr
  where
    go :: STUArray s Int Int -> Int -> B.ByteString -> ST s ()
    go arr i bs
      | i==n = return ()
      | otherwise = do
        let Just (x,bs') = readInt bs
        writeArray arr i x
        go arr (i+1) bs'

readTsV :: Int -> B.ByteString -> V.Vector (Int,Int)
readTsV n = V.unfoldrN n $ runStateT ((,) <$> StateT readInt <*> StateT readInt)

readTs :: Int -> B.ByteString -> [(Int,Int)]
readTs n = take n . unfoldr readT where
  readT = runStateT ((,) <$> StateT readInt <*> StateT readInt)

-- main

zeroone = cycle "01"
onezero = cycle "10"

diff [] _ = 0
diff (x:xs) (y:ys)
  | x==y = diff xs ys
  | otherwise = 1 + diff xs ys

solv s = min z o where
  z = diff s zeroone
  o = diff s onezero

main = do
  s <- getLine
  print $ solv s


Measured memory_bytes: 7548
/*
 ▓█████▄  ▄████▄  ▓██   ██▓ ██▓███   ██░ ██ ▓█████  ██▀███
▒██▀ ██▌▒██▀ ▀█   ▒██  ██▒▓██░  ██▒▓██░ ██▒▓█   ▀ ▓██ ▒ ██▒
 ░██   █▌▒▓█    ▄   ▒██ ██░▓██░ ██▓▒▒██▀▀██░▒███   ▓██ ░▄█ ▒
 ░▓█▄   ▌▒▓▓▄ ▄██▒  ░ ▐██▓░▒██▄█▓▒ ▒░▓█ ░██ ▒▓█  ▄ ▒██▀▀█▄
 ░▒████▓ ▒ ▓███▀ ░  ░ ██▒▓░▒██▒ ░  ░░▓█▒░██▓░▒████▒░██▓ ▒██▒
  ▒▒▓  ▒ ░ ░▒ ▒  ░   ██▒▒▒ ▒▓▒░ ░  ░ ▒ ░░▒░▒░░ ▒░ ░░ ▒▓ ░▒▓░
  ░ ▒  ▒   ░  ▒    ▓██ ░▒░ ░▒ ░      ▒ ░▒░ ░ ░ ░  ░  ░▒ ░ ▒░
  ░ ░  ░ ░         ▒ ▒ ░░  ░░        ░  ░░ ░   ░     ░░   ░
    ░    ░ ░       ░ ░               ░  ░  ░   ░  ░   ░
  ░      ░         ░ ░
*/
//focus less on how much problem you should solve within a fixed time and focus more on getting the problem solved and
//learning something from it
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define per(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vii vector <pair<ll,ll> >
#define sedes set <ll, greater <ll> >
#define seasc set <ll>
#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define umap unordered_map<ll, ll>
#define map map<ll, ll>
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define mems(a, i) memset(a, i, sizeof(a))
#define endl '\n'
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define deba(a) cout << #a << " " <<a << endl;
ll dp[50000];
ll solve(ll x)
{
	if (x == 3 or x == 4 or x == 5)
		return dp[x] = 1;
	if (x < 3)
		return dp[x] = 0;
	if (dp[x] != -1)
		return dp[x];
	ll ans = 1;
	for (int i = 3; i < x; i++)
	{
		ans += solve(x - i);
	}
	return dp[x] = ans % MOD;
}
int main()
{
	fast;
#ifndef ONLINE_JUDGE
	freopen("D:\\input.txt", "r", stdin);
	freopen("D:\\output.txt", "w", stdout);
#endif
	int t = 1;
//	cin >> t;
	while (t--)
	{
		ll n;
		cin >> n;
		mems(dp, -1);

		ll x = solve(n);

		cout << dp[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 3996
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, K = sc.nextInt()
    val H = Array.fill(N)(sc.nextInt())

    val INF = Int.MaxValue
    val dp = Array.fill(N)(INF)

    dp(0) = 0
    for {
      i <- 0 until N - 1
      k <- 1 to (K min (N - i - 1))
    } dp(i+k) = dp(i+k) min (dp(i) + (H(i)-H(i+k)).abs)

    println(dp(N-1))
  }

}


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

using namespace std;

int main() {
	
	int n;
	
	while( cin >> n ) {
		
		long long sum = 0;
		int A[10000];
		
		for(int i=0;i<n;i++){
		cin >> A[i];
		sum += A[i];	
	}
		sort(A,A+n);
		
		cout << A[0] << " " << A[n-1]
			 << " " << sum << "\n"; 
		
	}
		
	return 0;
}


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

int main(){
	string number;
	int sum;

	while(1){
		cin >> number;
		
		if(number == "0"){
			break;
		}
		
		sum = 0;
		for(int i = 0; i < number.size(); i++){
			sum += number[i] - '0';
		}
		cout << sum <<endl;
	}		
	
	return 0;	
}

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

using namespace std;

const bool debug = true;
#define dbg(...) if(debug) printf(__VA_ARGS__)
#define print(var) if (debug) cout << #var << " = " << var << endl

namespace {
    using real = long double;
    struct Edge {
        int from, to, cost;
        Edge() {}
        Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
    };
    real p;
    int N;
    vector<vector<Edge>> G;
    void input() {
        cin >> p >> N;
        G.resize(N);
        for (int i = 0; i < N - 1; i++) {
            int x, y, c; cin >> x >> y >> c;
            x--; y--;
            G[x].emplace_back(x, y, c);
            G[y].emplace_back(y, x, c);
        }
    }

    void solve() {
        real e; {
            function<real(int, int)> dfs = [&](int v, int prev) {
                // returns expected value of cost.:
                real ret = 0;
                for (auto& next : G[v]) {
                    if (next.to == prev) continue;
                    ret += p * (next.cost + dfs(next.to, v));
                }
                return ret;
            };
            e = dfs(0, -1);
        }
        real ans = 0; {
            function<void(int, int, real)> dfs = [&](int v, int prev, real prob) {
                ans += prob * e;
                for (auto& next : G[v]) {
                    if (next.to == prev) continue;
                    ans += prob * p * next.cost;
                    dfs(next.to, v, prob * p);
                }
            };
            dfs(0, -1, 1.0);
        }
        cout << setprecision(12) << fixed << ans << endl;
    }
}

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




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

ll H, W, N;
int a[100010];
int b[100010];

int main()
{
	cin >> H >> W >> N;
	for (int i = 0; i < N; ++i)
		cin >> a[i] >> b[i];
	map<pair<int, int>, int> m;
	for (int i = 0; i < N; ++i) {
		for (auto dx : { -1, 0, 1 }) {
			for (auto dy : { -1, 0, 1 }) {
				auto x = b[i] + dx, y = a[i] + dy;
				if (2 <= x && x < W && 2 <= y && y < H) {
					auto k = make_pair(x, y);
					if (!m.count(k)) {
						m[k] = 1;
					}
					else {
						m[k]++;
					}
				}
			}
		}
	}
	ll ans[10] = {};
	for (auto& kv : m) {
		ans[kv.second]++;
	}
	auto s = accumulate(begin(ans), end(ans), 0ll);
	ans[0] = (H - 2) * (W - 2) - s;
	for (auto v : ans) {
		cout << v << endl;
	}
	return 0;
}

Measured memory_bytes: 57216
N = gets.to_i
arr = gets.chomp!.split(" ").map { |v|
	v.to_i
}

fir = 0
dir = ""
isfirst = true
ans = 1
0.upto(N-1) { |i|
	if (isfirst && (arr[i] == arr[fir]) ) then
		next
	end
	
	if  (isfirst && (arr[i] > arr[fir]) ) then
		isfirst = false
		dir = "up"
		next
	end
	
	if  (isfirst && (arr[i] < arr[fir]) ) then
		isfirst = false
		dir = "down"
		next
	end
	
	if (dir == "up" && arr[i] >= arr[i-1]) then
		next
	end
	if (dir == "down" && arr[i] <= arr[i-1]) then
		next
	end
	
	ans += 1
	fir = i
	isfirst = true
	
}
puts ans


Measured memory_bytes: 11020
use std::collections::HashMap;
use std::fs::File;
use std::io::{stdout, BufWriter, Read, Write};
use std::iter::FromIterator;
use std::thread;

fn main() {
    thread::Builder::new()
        .stack_size(32 * 1024 * 1024) // 32MB
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

/// ローカル環境なら _in.txt から入力を受ける
fn read_input() -> String {
    let stdin = std::io::stdin();
    let mut s = String::new();
    match option_env!("LOCAL") {
        Some(_) => File::open("src/_in.txt")
            .expect("File not found")
            .read_to_string(&mut s)
            .unwrap(),
        None => stdin.lock().read_to_string(&mut s).unwrap(),
    };
    s
}

fn run() {
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    let input = read_input();
    let mut input = input.split_whitespace();

    let _in_n: i64 = input.next().unwrap().parse().unwrap();
    let in_s: Vec<String> = input.map(|s| s.parse().unwrap()).collect();

    let mut counts: HashMap<String, i64> = HashMap::new();
    for s in in_s {
        let mut chars: Vec<char> = s.chars().collect();
        chars.sort();
        let t = String::from_iter(chars);
        let cnt: i64 = match counts.get(&t) {
            Some(&c) => c,
            None => 0,
        };
        {
            counts.insert(t, cnt + 1);
        }
    }
    let ans: i64 = counts.iter().map(|(_, cnt)| cnt * (cnt - 1) / 2).sum();
    writeln!(out, "{}", ans).ok();
}


Measured memory_bytes: 25368
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

/*** MOD CALCULATION ***/

const int MOD = 1e9+7;
const int MAX = 1'000'005;

ll addM(ll a, ll b){
	return ((a % MOD) + (b % MOD)) % MOD;
}

ll mulM(ll a, ll b){
	return ((a % MOD) * (b % MOD)) % MOD;
}

ll powM(ll a, ll b){
	if(b == 0) return 1;
  	else if(b == 1) return a % MOD;
  	else if(b%2==0) return mulM(powM(a, b/2), powM(a, b/2));
  	else return mulM(a, mulM(powM(a, (b-1)/2), powM(a, (b-1)/2)));
}

// b^{-1} = b^{p-2} (mod p)
// a/b = a*b^{p-2} (mod p)
ll divM(ll a, ll b){ 
  	return mulM(a, powM(b, MOD-2));
}

// n!, (n!)^{-1} のテーブル作成
ll fac[MAX], finv[MAX], inv[MAX];
void COMBinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    rep3(i,2,MAX-1){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COMB(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

/*** MOD CALCULATION ここまで ***/

void Main(){
    int n, k; cin >> n >> k;

    vll num(k+1);
    ll tot = 0;
    
    rep3rev(i, k, 1){
        ll tmp = k / i;
        num[i] = powM(tmp, n);
        ll j = 2;
        while(i * j <= k){
            num[i] = addM(num[i], MOD - num[i * j]);
            j++;
        }
        tot = addM(tot, mulM(i, num[i]));
        // cout << i << " " << num[i] << " " << tot << endl;
    }
    
    cout << tot << endl;
    return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 4008
import sys

def solve():
    input = sys.stdin.readline
    Num = list(map(int, list(input().strip("\n"))))
    for i in range(8): #0: +; 1: -
        ans = Num[0]
        d = i
        toPrint = str(Num[0])
        for k in range(3):
            if d % 2 == 0: 
                ans += Num[k + 1]
                toPrint += "+" + str(Num[k + 1])
            else: 
                ans -= Num[k + 1]
                toPrint += "-" + str(Num[k + 1])
            d //= 2
        if ans == 7:
            toPrint += "=7"
            print(toPrint)
            break


    return 0

if __name__ == "__main__":
    solve()

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x, y) CPP_CAT_I(x, y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x, y) x##y

#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
// }}}

constexpr i64 INF = 1'010'000'000'000'000'017LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define M5 100007
#define M9 1000000000

// util {{{
#define FOR(i, start, end) for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); i < CPP_CAT(i, xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f, c, ...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); })(c))
#define ll long long int
#define VI vector<int>
template <typename C>
i64 SIZE(const C &c)
{
    return static_cast<i64>(c.size());
}

template <typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {})
{
    if (comp(xmax, x))
    {
        xmax = x;
        return true;
    }
    return false;
}

template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {})
{
    if (comp(x, xmin))
    {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit
{
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit()
    {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if (AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

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

bool isOK(int mid, double key)
{
}

int binary_search(double key)
{
    int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = 2000000000;
    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1)
    {
        int mid = left + (right - left) / 2;

        if (isOK(mid, key))
            right = mid;
        else
            left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}

bool isKaibun(string st)
{
    bool ans = true;
    int n = st.length();
    REP(i, n / 2)
    {
        if (st[i] != st[n - i - 1])
        {
            return false;
        }
    }
    return true;
}

int toInt(char a)
{
    return a - '0';
}

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

int lcm(int a, int b)
{
    return a * b / gcd(a, b);
}

void solve()
{
    int N;
    cin >> N;
    vector<int> A(N - 1);
    vector<int> B(N);
    REP(i, N - 1)
    {
        cin >> A[i];
        B[A[i] - 1]++;
    }
    REP(i, N)
    {
        cout << B[i] << endl;
    }
}

signed main()
{

    solve();

    return 0;
}


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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int main(){
    int n;
    cin>>n;
    cout<<(180 * (n-2))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int a,b; cin >> a >> b;
    rep(i,3000){
        int x=i*0.08,y=i*0.1;
        if(a==x && b==y){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}



Measured memory_bytes: 256