akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int n,k;
	string s;
	cin >> n >> s >> k;
	char ch = s[k-1];
	for(int i = 0;i < s.length();i++)
	{
		if(s[i] != ch)
			cout << '*';
		else
			cout << s[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""
# 最大公約数 と 最小公倍数
"""def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def lcm(a,b):
  g = gcd(a,b)
  return (a * b) // g"""
# 二分探索
"""import bisect # 二分探索
print(A,bisect.bisect_left(A,4))
print(C,n - bisect.bisect_right(C,4))
print(sum(bisect.bisect_left(A,b) * (n-bisect.bisect_right(C,b)) for b in B))"""

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7

def main():
  n = int(input())
  F = [readInts() for _ in range(n)]
  P = [readInts() for _ in range(n)]
  
  max_score = -float('inf')
  
  for i in range(1, 2**10):
    op_num = [0] * n
    for j in range(10):
      if i & 1 << j:
        for n_i in range(n):
          op_num[n_i] += F[n_i][j]
    max_score = max(max_score, sum([p_i[op_num_i] for p_i, op_num_i in zip(P,op_num)]))
  print(max_score)
if __name__ == '__main__':
  main()

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int counter[26];
int temp_counter[26];

int main()
{
    int n;cin >> n;
    vector<string> ss(n);
    rep(i,n)
    {
        cin >> ss[i];
    }
    rep(i,n)
    {
        for (int i = 0; i < 26; i++)
        {
            temp_counter[i] = 0;
        }
        for (auto &&j : ss[i])
        {
            if(i==0)counter[j-'a']++;
            temp_counter[j-'a']++;
        }
        for (int  i = 0; i < 26; i++)
        {
            chmin(counter[i], temp_counter[i]);
        }
        
        
    }
    vector<char> ans;
    for(int i = 0; i< 26; i++)
    {
        int num = counter[i];
        while(num >0)
        {
            ans.push_back('a'+i);
            num--;
        }
    }
    for (auto &&i : ans)
    {
        cout << i ;
    }
    cout << endl;
}

Measured memory_bytes: 3636
# coding:utf-8

def insertionSort(A, N):
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j -= 1
        A[j + 1] = v
        for i in A:
            print i,
        else:
            print

N = input()
A = map(int, raw_input().split())
for i in A:
    print i,
else:
    print
insertionSort(A,N)

Measured memory_bytes: 4664
/*  In the name of ALLAH */

#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and Constants    *******/

#define int long long
#define ull unsigned long long 
#define ld long double
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i < k ; ++i)
#define rrep(i, j, k) for (int i = j; i > k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define debug(a) cout << #a << ": " << a << endl
#define Flag(n) cout << "here " << n << endl
#define w(x) int x;cin>>x;while(t--)
#define mp make_pair
#define pb push_back

#define endl '\n';
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int POSITIVE_INFINITY = 9223372036854775807;
const int NEGATIVE_INFINITY = -9223372036854775807;
const int MOD = 1000000007;
const ld PI = acos(-1.0);
 

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif



int32_t main() {
    io;
    // freopen("input.txt","r",stdin); 
    // freopen("output.txt","w",stdout);
  

 
    char x;
    cin>>x;
    if (x<='Z')cout<<'A';
    else cout<<'a';
 
    
 
    return 0;
}


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



Measured memory_bytes: 3108
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String args[]) throws IOException {
		Scanner scan = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		StringBuilder sb2 = new StringBuilder();
		String str = "";
		int num, number;
		num = 0;// ?????°
		char c;

		// ??????????????\???????????????????????????
		// List<String> list = new ArrayList<String>();

		// ???????????????????????§??????
		while (true) {
			// StringBuilder?????\??????
			sb.append(scan.next());
			// System.out.println("??????????§?");
			if (new String(sb).equals("-")) {
				break;
			}

			// ?????°???input
			num = scan.nextInt();
			// ?????°??????????????????
			for (int count2 = 0; count2 < num; count2++) {
				// ?????£??????????????°
				number = scan.nextInt();
				// ?????£??????????????? c = sb.charAt(0);

				for (int count3 = 0; count3 < number; count3++) {
					// ?????£??????????????°???????????????????????????????°?????????£?????????
					// sb?????????????¶???????????????????????????£?????????
					// ??????????????????c?????£??\
					c = sb.charAt(0);
					// ????????????????????????
					sb.delete(0, 1);
					// c??????????°??????????
					sb.append(String.valueOf(c));
				}

			}

			sb2.append(new String(sb));
			sb2.append("\n");
			// sb?????????
			sb.setLength(0);

		}
		sb2.deleteCharAt(sb2.length() - 1);
		System.out.println(new String(sb2));
	}
}

Measured memory_bytes: 26216
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <map>
#include <algorithm>
#include <math.h>
#include <iostream>     // std::cout, std::fixed
#include <iomanip>
#include<queue>
#include <cmath>
#include <queue>
#include <set>
#include <iostream>


using namespace std;
typedef long long ll;


int main () {
    ios_base::sync_with_stdio(false);
    string s;
    cin>>s;
    for(int i=0;i<s.size()-8;i++)
        cout<<s[i];
    return 0;
}


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

int main(void){
	char input[200] = {};
	int i,num;

	for(i=1; true ; i++){
		scanf("%c", &input[i]);
		
		if(input[i]=='\0'){
			num=i;
			break;
		}
    }    
       
    for(i=1;i<num - 1;i=i+2){
        if(input[i]=='L'){
            printf("No\n");
            return 0;
        }
    }
    for(i=2;i<num - 1;i=i+2){
     if(input[i]=='R'){
            printf("No\n");
            return 0;
    
        }
    } 
        printf("Yes\n");
 
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long  
#define pb push_back
#define mk make_pair
#define mod 998244353
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define all(x) x.begin(),x.end()
int main()
{
    ios::sync_with_stdio(0) ;
    cin.tie(0); 
    int n;
    cin>>n;
    int a[n],b[n];int fac[n+1]={0};
    fac[1]=1;
    fac[0]=1;
    for(int i=2;i<=n;i++)
    fac[i]=i*fac[i-1];
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
    }
    double ans=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            double u=(a[i]-a[j])*(a[i]-a[j]);
            u=u+(b[i]-b[j])*(b[i]-b[j]);
            u=sqrt(u);
            u*=fac[n-2+1];
            u*=2;
            ans+=u;
        }
    }
  
    double y=fac[n];
   
    ans/=y;
    cout<<fixed<<setprecision(9)<<ans;
    return 0;
}
//make all values ll


Measured memory_bytes: 256
/// In the name of God
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;

#define y1 def1
#define X first
#define Y second
#define endl '\n'
#define all(o) o.begin(), o.end()
#define IOS ios::sync_with_stdio(0), cin.tie(0)
const int maxn = 1e5 + 10;
int pos[maxn], cnt[maxn], tim[maxn];
void get(int h,int t,int s){
	if(s < pos[h] || s > pos[t]){
		for(int i=h; i<=t; i++)
			tim[i] = abs(s - pos[i]);
		return;
	}
	if(cnt[h] >= cnt[t]){
		cnt[h] += cnt[t];
		get(h, t-1, s);
		tim[t] = tim[h] + pos[t] - pos[h];
		return;
	}
	cnt[t] += cnt[h];
	get(h+1, t, s);
	tim[h] = tim[t] + pos[t] - pos[h];
}
int32_t main(){
    IOS;
	ll ans = 0;
	int n, s;
	cin >> n >> s;
	for(int i=0; i<n; i++)
		cin >> pos[i] >> cnt[i];
	int h = 0, t = n-1;
	get(0, n-1, s);
	int mx = 0;
	for(int i=0; i<n; i++)
		mx = max(mx, tim[i]);
	cout << mx << endl;

}


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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

using namespace std;
using P = pair<int, int>;

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

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int N;
    int coin[4];
    int value[4] = { 10, 50, 100, 500 };
    bool a = false;
    while( cin >> N, N ){
        if( a ) cout << endl;
        a = true;

        int sum = -N;
        REP( i, 4 ){
            cin >> coin[i];
            sum += coin[i] * value[i];
        }

        vector<P> ans;
        REPR( i, 3 ){
            int cnt = 0;
            while( sum >= value[i] ){
                cnt++;
                sum -= value[i];
            }
            if( coin[i] - cnt > 0 ) ans.emplace_back( value[i], coin[i] - cnt );
        }

        REPR( i, ans.size() - 1 ) cout << ans[i].first << " " << ans[i].second << endl;

    }
}



Measured memory_bytes: 3008
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int a,b;
    scanf("%d%d", &a, &b);

    int curr=1;
    int i;
    for(i=0; i<100; i++) {
        if(curr>=b) break;
        curr += (a-1);
    }
    printf("%d\n", i);



    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
using namespace std;
#define REP(i,n); for(int i = 0;i < (int)(n);i++)

int main() {
	int n,ans=0,sum;
	vector<vector<int>> a;
	a.resize(2);
	cin >> n;
	REP(i,2){
		a[i].resize(n);
		REP(j,n){
			cin >> a[i][j];
		}
	}
	REP(k,n){
		sum=0
		REP(j,n){
			if(j<k)sum += a[0][j];
			else if(j==k) sum+= a[0][j]+a[1][j];
			else sum+=a[1][j];
		}
		ans = max(ans,sum);
	}
	cout << ans;
	return(0);
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define PRINT1(table, D0) REP(d0, D0) cout<<table[d0]<<" "; cout<<"\n";
#define PRINT2(table, D0, D1) REP(d0, D0) { REP(d1, D1) cout<<table[d0][d1]<<" "; cout<<"\n"; }
#define PRINT3(table, D0, D1, D2) REP(d0, D0) { REP(d1, D1) { REP(d2, D2) cout<<table[d0][d1][d2]<<" "; cout<<"\n"; } cout<<"\n"; }
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	//ios::sync_with_stdio(false);
	ll A,B,C;
	while(cin>>A>>B>>C) {
		cout<<(A<=C&&C<=B ? "Yes":"No")<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
flg = 0
grid = [[0 for i in range(3)] for i in range(3)]
for i in range(3):
    temp = list(map(int,input().split()))
    for j in range(3):
        grid[i][j] = temp[j]
if grid[0][0] - grid[0][1] ==  grid[1][0] - grid[1][1] and  grid[1][0] - grid[1][1] ==  grid[2][0] - grid[2][1]:
    if grid[0][1] - grid[0][2] ==  grid[1][1] - grid[1][2] and  grid[1][1] - grid[1][2] ==  grid[2][1] - grid[2][2]:
        if grid[0][2] - grid[0][0] ==  grid[1][2] - grid[1][0] and  grid[1][2] - grid[1][0] ==  grid[2][2] - grid[2][0]:
            flg = 1
if flg == 1:
    print("Yes")

else:
    print("No")


Measured memory_bytes: 3064
def main():
    N = int(input())
    dp = [[[[0
            for c3 in range(4)]
            for c2 in range(4)]
            for c1 in range(4)]
            for L  in range(N+1)]
    dp[0][3][3][3] = 1
    for L in range(1, N+1):
        for c3 in range(4):
            for c2 in range(4):
                for c1 in range(4):
                    for c0 in range(4):
                        if ((c2 == 0 and c1 == 2 and c0 == 1) or
                            (c2 == 2 and c1 == 0 and c0 == 1) or
                            (c2 == 0 and c1 == 1 and c0 == 2) or
                            (c3 == 0 and c2 == 2 and c0 == 1) or
                            (c3 == 0 and c1 == 2 and c0 == 1)):
                            continue
                        dp[L][c0][c1][c2] += dp[L-1][c1][c2][c3]
                        dp[L][c0][c1][c2] %= 10**9 + 7
    ans = 0
    for c3 in range(4):
        for c2 in range(4):
            for c1 in range(4):
                ans += dp[N][c1][c2][c3]
                ans %= 10**9 + 7
    print(ans)

if __name__ == "__main__":
    main()


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

using namespace std;
typedef long long ll;
typedef long double ld;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll x,y,z;
	cin>>x>>y>>z;
	cout<<z<<' '<<x<<' '<<y;
    return 0;
}

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

int bubbleSort(int A[], int N){
  int sw = 0;
  bool flag = 1;
  for (int i = 0; flag; i++){
    flag = 0;
    for ( int j = N-1; j >= i+1; j-- ){
      if(A[j] < A[j-1]){
	swap(A[j], A[j-1]);
	flag = 1;
	sw++;
      }
    }
  }
  return sw;
}

int main(){
  int A[100], N, sw;
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  
  sw = bubbleSort(A, N);
  
  for (int i = 0; i < N; i++){
    if(i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;

  return 0;
}



Measured memory_bytes: 3096
#include<stdio.h>
#include<stdlib.h>
 
int main(int argc,char** argv)
{
	int count = 0;
	char s[4];
	scanf("%s",s);
 
	for(int i = 0; i < 3; i++){
		if(s[i]=='1') count++;
	}
 
	printf("%d\n",count );
	return(0);
 
}

Measured memory_bytes: 128
N, *LR = map(int, open(0).read().split())
L, R = LR[::2], LR[1::2]

Lp = max(L)
Rq = min(R)

A = sorted(max(0, r - Lp + 1) for r in R)
B = sorted(-max(0, Rq - l + 1) for l in L)

mi = float("inf")
ma = max(r - l + 1 for l, r in zip(L, R)) + max(0, Rq - Lp + 1)

for a, b in zip(A[1:], B):
    mi = min(mi, -b)
    ma = max(ma, mi + a)

print(ma)


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

int main(){
    int N, before=10000, count =0;
    cin >> N;
    vector<int> d(N);
    for(int i=0;i<N;i++){
        cin>>d[i];
    }
    sort(d.begin(), d.end(), greater<int>());
    for(int i=0;i<N;i++){
        if(d[i] < before){
            before = d[i];
            count++;
        }    
    }
    cout << count << endl;
}


Measured memory_bytes: 256
import sys
from bisect import bisect


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


def main():
    a, b, q = map(int, read().split())
    s = [-10**12] + [int(read()) for _ in range(a)] + [10**12]
    t = [-10**12] + [int(read()) for _ in range(b)] + [10**12]
    for _ in range(q):
        x = int(read())
        si = bisect(s, x)
        ti = bisect(t, x)
        sa, sb = s[si - 1], s[si]
        ta, tb = t[ti - 1], t[ti]
        d = 10**12
        for sx in (sa, sb):
            for tx in (ta, tb):
                d = min(abs(x - sx) + abs(sx - tx), abs(x - tx) + abs(tx - sx), d)
        print(d)


if __name__ == '__main__':
    main()


Measured memory_bytes: 17672
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

Int Ceil(Int a, Int b) {
    if (a % b == 0) {
        return a / b;
    } else {
        return Floor(a, b) + 1;
    }
}

vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

Int digits(Int n) {
    return (Int)to_string(n).size();
}

Int calc(vector<Int> &A, Int to) {
    Int ret = 0;

    Int ro = A.size();
    for (Int i = 0; i < ro; i++) {
        ret += (A[i] - to) * (A[i] - to);
    }

    return ret;
}

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

    Int n;
    cin >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }

    Int cost = INF;
    for (Int i = -100; i <= 100; i++) {
        Int ncost = calc(a, i);
        if (ncost < cost) {
            cost = ncost;
        }
    }

    cout << cost << endl;

    return 0;
}

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

using namespace std;
using ll = long long;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const string YES = "Yes";
const string NO = "No";


int main(){
  ll h, w;
  cin>>h>>w;
  vector<string> v(h);
  for(int i=0; i<h; i++) {
    cin>>v[i];
  }

  map<char, ll> dic;
  for(int i='a'; i<='z'; i++) {
    dic[(char)i]=0;
  }
  for(int i=0; i<h; i++) {
    for(auto x:v[i]) {
      dic[x]++;
    }
  }

  vector<ll> vv;
  for(auto x:dic) {
    vv.push_back(x.second);
  }
  int num=0;
  sort(vv.rbegin(), vv.rend());
  for(auto x:vv) {
    if(x==0)
      break;
    num++;
  }

  for(int i=0; i<(w/2)*(h/2); i++){
    if(vv[0] >= 4) {
      vv[0] -= 4;
      sort(vv.rbegin(), vv.rend());
    } else {
      std::cout << NO << std::endl;
      return 0;
    }
  }

  sort(vv.rbegin(), vv.rend());

  for(int i=0; i<(h-(h/2)*2)*(w/2); i++) {
    if(vv[0] >= 2) {
      vv[0]-=2;
      sort(vv.rbegin(), vv.rend());
    } else {
      std::cout << NO << std::endl;
      return 0;
    }
  }
  sort(vv.rbegin(), vv.rend());
  for(int i=0; i<(w-(w/2)*2)*(h/2); i++) {
    if(vv[0]>=2) {
      vv[0]-=2;
      sort(vv.rbegin(), vv.rend());
    } else {
      std::cout << NO << std::endl;
      return 0;
    }
  }
  std::cout << YES << std::endl;
  return 0;
}


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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, b, e) for (i64 i = (b); i <= (e); ++i)
#define repr(i, b, e) for (i64 i = (b); i >= (e); --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

#ifdef DEBUG
#define dump(...) dump_(#__VA_ARGS__, __VA_ARGS__);
#else
#define dump(...)
#endif

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

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

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

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// input
void input() {}
template <class Head, class... Tail>
void input(Head&& head, Tail&&... tail) {
  cin >> head;
  input(forward<Tail>(tail)...);
}

// outs
void outs() {}
template <class Head, class... Tail>
void outs(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  outs(forward<Tail>(tail)...);
}

template <class T>
void outs(vector<T> &vec) { for (auto &e : vec) cout << e << " \n"[&e==&vec.back()]; }

template <class T>
void outs(vector<vector<T>> &df) { for (auto &vec : df) OUTS(vec); }

// outl
void outl() {}
template <class Head, class... Tail>
void outl(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  outl(forward<Tail>(tail)...);
}

template <class T>
void outl(vector<T> &vec) { for (auto &e : vec) cout << e << "\n"; }

// outn
void outn() {}
template <class Head, class... Tail>
void outn(Head&& head, Tail&&... tail) {
  cout << head;
  outn(forward<Tail>(tail)...);
}

template <class T>
void outn(vector<T> &vec) { for (auto &e : vec) cout << e; }

// dump
template <class T>
void dump_(const char *s, T&& x) {
  clog << '{';
  while(*s != '\0') clog << *(s++);
  clog << ": " << x << '}' << "\n";
}

template <class Head, class... Tail>
void dump_(const char *s, Head&& head, Tail&&... tail) {
  clog << '{';
  while(*s != ',') clog << *(s++);
  clog << ": " << head << "}, ";
  for (++s; !isgraph(*s); ++s);
  dump_(s, forward<Tail>(tail)...);
}
// }}} End

bool sqnumber(i64 n) {
  for (int i = 0; i * i <= n; ++i) {
    if (i * i == n) return true;
  }
  return false;
}

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

  var(int, N, D);

  vector<vector<i64>> x(N, vector<i64>(D));
  rep(i, N) {
    rep(j, D) {
      input(x[i][j]);
    }
  }

  i64 res = 0;
  for (int i = 0; i < N; ++i) {
    for (int k = i + 1; k < N; ++k) {
      i64 norm = 0;
      rep(j, D) {
        i64 tmp = abs(x[i][j] - x[k][j]);
        norm += tmp * tmp;
      }
      if (sqnumber(norm)) ++res;
    }
  }

  outl(res);

  return 0;
}


Measured memory_bytes: 256
import sys

A, B, Q = map(int, sys.stdin.readline().split())
INF = 10 ** 18
S = [-INF] + [int(sys.stdin.readline()) for _ in range(A)] + [INF]
T = [-INF] + [int(sys.stdin.readline()) for _ in range(B)] + [INF]
X = [int(sys.stdin.readline()) for _ in range(Q)]


def binary_search(q, A):
    l, r = 0, len(A)
    while r-l>1:
        mid = (l + r) // 2
        if q > A[mid]:
            l = mid
        else:
            r = mid
    return A[l], A[r]


def main():
    for x in X:
        s1, s2 = binary_search(x, S)
        t1, t2 = binary_search(x, T)
        print(min(abs(s-t) + min(abs(s-x), abs(t-x)) for s in [s1, s2] for t in [t1, t2]))
    return

if __name__ == '__main__':
    main()


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

int main()
{  int A,X,N,ar[102],i=0,sum=0;
    cin>>N>>X;
    for(int j=0;j<N;j++) cin>>ar[j];
    for(int j=0;j<N;j++){ sum+=ar[j];if(sum>X) break ; i++; }
    cout<<i+1<<endl;


return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::cmp::max;
use std::cmp::min;


fn main() {
    input! {
        A: i64,
        B: i64,
    }

    let ans = if B * 2 >= A { 0 } else { A - 2 * B };

    println!("{}", ans);
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
int n, C;
int w[101];
long long v[101];

long long dp[101][100005];


long long solve(int i, int left){
	if(i == n) return 0;
	if(dp[i][left] != -1) return dp[i][left];
	
	dp[i][left] = solve(i+1, left);
	if(left >= w[i]){
		dp[i][left] = max(dp[i][left], solve(i+1, left-w[i]) + v[i]);
	}
	
	return dp[i][left];
}

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

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

	memset(dp, -1, sizeof dp);
	cout<<solve(0, C)<<endl;

	return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define test(t) ll t;cin>>t;while(t--)
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
#define fr(i,n) for(ll i=0;i<(n);++i)
#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 remin(a,b) (a=min((a),(b)))
#define remax(a,b) (a=max((a),(b)))
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
signed main()
{
    fast;
    ll m,d;
    cin>>m>>d;
    ll ans = 0;
    ll i,j;
    for(i=2;i<=9;i++)
    {
        for(j=2;j<=9;j++)
        {
            ll p = i*10+j;
            if(p<=d and i*j<=m)
                ans++;
        }
    }
    cout<<ans;
}

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

int main()
{
	ll N, W;
	cin >> N >> W;
	vector<vector<ll>> dp(N + 1, vector<ll>(W + 1, 0));
	for (int i = 1, v, w, m; i <= N; i++) {
		cin >> v >> w >> m;
		for (int j = 0; j < w; j++) {
			deque<int> dq;
			for (int k = 0; k * w + j <= W; k++) {
				if (k > m && dq.front() == k - m - 1)
					dq.pop_front();
				while (!dq.empty() && dp[i - 1][dq.back() * w + j] - v * dq.back() < dp[i - 1][k * w + j] - v * k) {
					dq.pop_back();
				}
				dq.push_back(k);
				dp[i][k * w + j] = dp[i - 1][dq.front() * w + j] - v * dq.front() + v * k;
			}
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}

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

using namespace std;

typedef long long	ll;

const int N = 1000;
ll cnt[N];
bool has[N][N];
string s;

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

	int n;

	cin >> n;

	cin >> s;

	for(int i = 0 ; i < s.length() ; i++){
		has[s[i]][i] = true;
	}

	ll sum = 0LL;

	for(int i = 0 ; i < s.length() ; i++){
		for(int j = i ; j < s.length() ; j++){
			if(s[i] != s[j]){
				set< char > st;

				st.insert('R');
				st.insert('G');
				st.insert('B');

				st.erase(s[i]);
				st.erase(s[j]);

				sum += cnt[*st.begin()];

				int dis = (j - i);

				if((dis & 1) == 0){
					sum -= has[*st.begin()][i + (dis / 2)];
				}
			}

			cnt[s[j]]++;
		}

		cnt['R'] = cnt['G'] = cnt['B'] = 0;
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3684
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define N 1000
#define W 1000
int dp[N+1][W+1];
int value[N+1], weight[N+1];
int main()
{
    for (int I=1; ; ++I) {
        memset(dp, 0, sizeof(dp));
        int w; scanf("%d", &w); if (!w) break;
        int n; scanf("%d", &n);
        for (int i=0; i<n; ++i) scanf("%d,%d", value+i, weight+i);

        for (int i=1; i<=n; ++i) {
            for (int j=1; j<=w; ++j) {
                if (j >= weight[i-1] )
                    dp[i][j]
                        = max(dp[i-1][j], dp[i-1][j-weight[i-1]] + value[i-1]);
                else
                    dp[i][j] = dp[i-1][j];
            }
        }
        int resv = 0, resw;
        for (int i=w; i>=1; --i)
            if (resv <= dp[n][i]) { resv = dp[n][i], resw = i; }
        printf("Case %d:\n%d\n%d\n", I, resv, resw);
    }
    return 0;
}

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

int main() {
  
  string s;
  cin >> s;
  int p = s.size() - 1;
  int x = 0;
  int total = 0;
  while(1) {
    int t = p - x;
    if(s.at(x) != s.at(t)) total++;
    x++;
    if(x == (p + 1) ) break;
  }
  
  cout << total / 2 << endl;
  
  
}



Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <fstream>
#include <queue>
#include <deque>
#include <numeric>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long LL;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< LL > vl;
typedef vector< vl > vvl;
typedef vector< bool > vb;
typedef pair <int, int> ii;
#define tr(c,it) for(decltype(c.begin()) it = c.begin(); it != c.end(); it++)
#define rep(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define repr(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define pb push_back
#define mp make_pair
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define in(a,b) ( (b).find(a) != (b).end())


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

	int n, k;
	cin >> n >> k;

	vl h(n), c(n, 10000000001);
	rep(i, n) cin >> h[i];
	c[0] = 0;

	auto valid = [n](int x) -> bool {return x < n;};
	rep(i, n-1)
		repr(j, 1, k+1)
			if (valid(i+j))
				c[i+j] = min(c[i+j], c[i] + abs(h[i] - h[i+j]));

	cout << c[n-1];
}


Measured memory_bytes: 1792
import sys

n, m, *ab = map(int, sys.stdin.read().split())
ab = list(zip(*[iter(ab)] * 2))

root = list(range(n+1)); root[0] = None
height = [0] * (n + 1); height[0] = None
size = [1] * (n + 1); size[0] = None

sys.setrecursionlimit(10 ** 9)
def find_root(v):
    u = root[v]
    if u == v:
        return u
    w = find_root(u)
    root[v] = w
    return w

def unite(v, u):
    rv = find_root(v)
    ru = find_root(u)
    if rv == ru:
        return 0
    sv = size[rv]
    su = size[ru]
    if height[v] >= height[u]:
        root[ru] = rv
        height[rv] = max(height[rv], height[ru] + 1)
        size[rv] += size[ru]
    else:
        root[rv] = ru
        size[ru] += size[rv]
    return sv * su

def main():
    res = [0] * m
    for i in range(1, m):
        res[i] = res[i-1] + unite(*ab[m-i])

    all_pairs = n * (n - 1) // 2
    for i in res[::-1]:
        yield all_pairs - i
    
if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')

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

const int mod = 1000000007;

int main(){
    ll h;
    cin >> h;
    ll ans = 0;
    ll cnt = 0;
    while (h > 0)
    {
        h /= 2;
        ans += pow(2, cnt);
        cnt++;
    }
    cout << ans << endl;
}

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

int main() {
    map<int, int> M;
    int n; cin >> n;
    vector<int> V;
    for(int i = 1, val; i <= n; ++i) {
        cin >> val; val -= i;
        V.emplace_back(val);
    }
    sort(V.begin(), V.end());
    int m = V[n>>1];
    long long sum = 0;
    for(auto x : V) sum += abs(x - m);
    cout << sum;
}

Measured memory_bytes: 1400
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for(ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for(ll i = (ll)(n - 1); i >= 0; i--)
#define repM1(i, n) for(ll i = (ll)(n - 1); i > 0; i--)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main()
{
	cout << fixed << setprecision(18);

	ll a, b, h, m;

	cin >> a >> b >> h >> m;

	ll l, s;
	if (a > b) {
		l = a;
		s = b;
	}
	else {
		l = b;
		s = a;
	}

	long double dig_h, dig_m, dig;

	dig_h = ((2 * M_PI) / 12.0) * h + ((2 * M_PI) / 12.0) * (m / 60.0);
	dig_m = (2 * M_PI) * (m / 60.0);
	dig = abs(dig_h - dig_m);


	long double x = s * sin(dig);
	long double y = s * cos(dig);
	long double ans = sqrt(pow(x, 2) + pow(l - y, 2));

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4148
#include <set>
#include <array>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <vector>
#include <tuple>
#include <string>
#include <math.h>
#include <time.h>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <limits>
#include <climits>
#include <numeric>
#include <functional>

#define lnd '\n'
// #define reverse(i, n) for(ll i = n-1; i >= 0; --i)
#define from(i, n) for (ll i = 0; i < n; ++i)
#define loop(i, n) for(ll i = 0; i < n; i++)
#define REPN(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(s) (s).begin(), (s).end()
#define rALL(s) (s).rbegin(), (s).rend()
#define sz(s) (int)(s).size()
#define mk make_pair
#define pb push_back
#define sqr(s) ((s) * (s))

using namespace std;

typedef long long ll;
typedef long long int lli;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;

template <class T>
T GCD (T a, T b) {
  if(a == 0) return b;
  return GCD(b%a, a);
}

template <class T>
T LCM(T a, T b){
  return a*b/GCM(a,b);
}

template <class T>
T modpow(T x, T p){
    T res = 1;
    while(p > 0){
        if(p&1) res *= x;
        x *= x;
        p /= 2;
    }
    return res;
}

template <class T>
T modpow(T x, T p, ll mod){
    T res = 1;
    while(p > 0){
        if(p&1) res = (res*x)%mod;
        x = (x*x)%mod;
        p /= 2;
    }
    return res%mod;
}

template <class T>
void print(T a[], ll n){
    for (ll i = 0; i < n; i++) std::cout << a[i] << ' ';
    cout << endl;
}

template<class T>
void printc(T c){
    for(auto const& v: c) std::cout << v << ' ';
    cout << endl;
}

struct HASH{
  size_t operator()(const pair<long,long>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};

bool pair_sort(const pair<int, int> &p1, const pair<int,int> &p2){
    if(p1.first != p2.first) return p1.first < p2.first;
    else return p1.second < p2.second;
}

const int INF = std::numeric_limits<int>::max();
const ll M_INF = std::numeric_limits<ll>::min();
const ll LL_INF = std::numeric_limits<ll>::max();

void solution();
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solution();
    return 0;
}

ll result[200005] = {0};
void fact(ll n) {
   if (n >= 0) {
      result[0] = 1;
      for (ll i = 1; i <= n; ++i) {
         result[i] = i * result[i - 1];
      }
   }
}

void solution(){
  int s,w;
  cin >> s >> w;
  if(w >= s){
    cout << "unsafe" << endl;
  }else{
    cout << "safe" << endl;
  }
}     



Measured memory_bytes: 3132
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
const ll fact_table = 5000000;
double Pi = 3.1415926535897932384626;
 
vector<ll> G[550010];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 

ll mod = 998244353;
//ll mod = 1000000007;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){

    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 

ll fact[fact_table + 5],rfact[fact_table + 5];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}

 
ll n,m,num,sum,a,b,c,d,e,g,h,w,i,j,q,r,l;
ll k,idx,ans;
ll x[500005],y[500005],z[500005];
char s[500005];
ll dp[5000005];
ll dpsum[5000005];
ll rui_table[5000005];

int main(){
    cin >> n;
    c3_init();
    for(int i=0;i<=n / 2;i++){
        dp[i] = c3(n / 2, i);
        dpsum[i] = dp[i];
    }
    ll ruih = rui(2ll, 100);
    rui_table[0] = 1;
    for(int i=1;i<=n/2;i++){
        rui_table[i] = 2 * rui_table[i-1];
        rui_table[i] %= mod;
    }
    for(int i=0;i<=n / 2;i++){
        dpsum[i] *= rui_table[n/2 - i];
        dpsum[i] %= mod;
    }
    for(int i=n / 2;i>=1;i--){
        dpsum[i-1] += dpsum[i]; 
        dpsum[i-1] %= mod;
    }

    for(int i=0;i<=n / 2;i++){
        num = dp[i] * dpsum[n / 2 - i + 1];
        num %= mod;
        num *= rui_table[n/2 - i];
        num %= mod;
        ans += num;
        ans %= mod;
        //p(ans);
    }
    ans *= 2;
    ans %= mod;
    ans = rui(3ll, n) - ans + mod;
    ans %= mod;
    p(ans);
    return 0;
}











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

int main() {

  while( true ) {

    long long int n, m, q;
    cin >> n >> m >> q;
    if ( n == 0 ) break;

    string k = "0";
    for ( long long int i = 0; i < q; i++ ) {
      k += "0";
    }

    vector< string > s;
    for ( long long int i = 0; i < n; i++ ) {
      s.push_back( k );
    }

    vector< string > b;
    for ( long long int i = 0; i < m; i++ ) {
      b.push_back( k );
    }

    for ( long long int i = 0; i < q; i++ ) {

      string in_s, in_b;
      cin >> in_s >> in_b;

      for ( long long int j = 0; j < n; j++ ) {
	s[j][i+1] = '0' + ( s[j][i] - '0' ) ^ ( in_s[j] - '0' );
      }

      for ( long long int j = 0; j < m; j++ ) {
	b[j][i+1] = in_b[j];
      }

    }

    for ( long long int i = 0; i < m; i++ ) {

      long long int ans = -1;

      for ( long long int j = 0; j < n; j++ ) {

	if ( s[j] == b[i] ) {
	  if ( ans == -1 ) {
	    ans = j;
	  }else {
	    ans = -1;
	    break;
	  }
	}

      }

      char c;
      if ( ans == -1 ) {
	c = '?';
      }else {
	if ( ans <= 9 ) {
	  c = ans + '0';
	}else {
	  c = ( ans - 10 ) + 'A';
	}
      }
      cout << c;

    }

    cout << endl;

  }

  return 0;

}

Measured memory_bytes: 2124
#include<iostream>
#include<set>
#include<string>

int n, k;
std::string cards[11];
std::set<std::string>s;

void makecard(int p, std::string res, bool used[11]){
	if (p == k){
		s.insert(res);
		return;
	}

	for (int i = 0; i < n; i++){
		if (!used[i]){
			used[i] = true;
			makecard(p + 1, res + cards[i], used);
			used[i] = false;
		}
	}
}

int main(){

	while (std::cin >> n >> k, n || k){
		s.clear();
		for (int i = 0; i < n; i++){
			std::cin >> cards[i];
		}
		bool used[11];
		for (int j = 0; j < 11; j++)used[j] = false;

		makecard(0, "", used);

		std::cout << s.size() << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1460
import bisect
N = int(input())
S = str(input())

S = list(S)
#print(S)

number_place_dict={}
for i in range(10):
  number_place_dict[i]=list()

#print(number_place_dict)

for i in range(len(S)):
  #print(int(S[i]))
  number_place_dict[int(S[i])].append(i)

#print(number_place_dict)

ans = 0

for i in range(0,1000):
  i = list(str(i))
  if len(i) == 1:
    i = [0] + [0] + i
  elif len(i) == 2:
    i = [0] + i
  elif len(i) == 0:
    i = [0] + [0] + [0]
  
  #print("i;",i)

  next_place_confition = -1

  for j in range(0,3):
    #print("数字:",int(i[j]),end="")
    place_list = number_place_dict[int(i[j])]
    index = bisect.bisect_right(place_list, next_place_confition)
    if index == len(place_list):
      #print("条件合致無し")
      break
    else:
      next_place_confition = place_list[index]
      #print("……次は→以上のindexが要:",next_place_confition)
  else:
    #print("OK")
    ans += 1

print(ans)

Measured memory_bytes: 4584
#include<stdio.h>
#include<string.h>
int d[15][15],e[15][15],a[15][15],f[15];
int dx[]={-1,0,0,0,1};
int dy[]={0,-1,0,1,0};
int func(){
	int i,j,k,r=0;
	for(i=2;i<=10;i++){
		for(j=1;j<=10;j++){
			if(e[i-1][j]%2==1){
				a[i][j]=1;
				//e[i-1][j]++;
				for(k=0;k<5;k++){
					e[i+dy[k]][j+dx[k]]++;
				}
			}
		}
	}
	for(i=1;i<=10;i++)if(e[10][i]%2==1)r++;
	return r;
}
int main(){
	int i,j,k,n;
	FILE *fp;
	//fp=fopen("test.txt","r");
	fp=stdin;
	fscanf(fp,"%d",&n);
	while(n--){
		for(i=1;i<=10;i++)for(j=1;j<=10;j++)fscanf(fp,"%d",&d[i][j]);
		for(i=0;i<(1<<10);i++){
			memset(a,0,sizeof(a));
			memcpy(e,d,sizeof(d));
			for(j=0;j<10;j++){
				if(!( (i>>j)&1 )){
					a[1][j+1]=1;
					for(k=0;k<5;k++){
						e[1+dy[k]][j+1+dx[k]]++;
					}
				}
			}
			if(func()==0){
				for(j=1;j<=10;j++){
					for(k=1;k<=10;k++){
						printf("%d%s",a[j][k],(k==10)?"\n":" ");
					}
				}
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <stack>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;

int n, m;
int num[30];

int main()
{
	scanf("%d%d", &n, &m);
	int tot1, tot2;
	if((n & 1) && (m & 1)) tot1 = 1, tot2 = (n - 1) / 2 + (m - 1) / 2;
	else if(!(n & 1) && !(m & 1)) tot1 = 0, tot2 = 0;
	else {
		tot1 = 0;
		if(n & 1) tot2 = m / 2;
		else tot2 = n / 2;
	}
	int nu1 = 0, nu2 = 0;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++) {
			char c;
			scanf(" %c", &c);
			num[c - 'a']++;
		}
	for(int i = 0; i < 26; i++) 
		if(num[i]) {
			if(num[i] % 4 != 0) {
				if(num[i] % 2 != 0) nu1++;
				else nu2++;
			}
		}
	if(nu1 > tot1 || nu2 > tot2) printf("No\n");
	else printf("Yes\n");
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222


ll a[MAX], b[MAX];


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


  cin >> n;
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  ll aa = 0, bb = 0;
  rep(i, n) aa += a[i];
  rep(i, n) bb += b[i];
  if (bb > aa) {
    cout << "-1" << endl;
    return 0;
  }
  vll v;
  ll cur = 0;
  rep(i, n) {
    if (a[i] > b[i]) v.pb(a[i] - b[i]);
    else if(b[i] > a[i]){
      cur += b[i] - a[i];
      ans++;
    }
  }
  sort(rall(v));
  ll idx = 0;
  while (cur > 0) {
    cur -= v[idx];
    idx++;
    ans++;
  }
  cout << ans << endl;





  return 0;
}

Measured memory_bytes: 2428
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let h = read::<i64>();
  let w = read::<i64>();
  let mut map: Vec<String> = vec![];

  let mut st = String::from("");
  for i in 0..w + 2 {
    st.push_str("#")
  }

  map.push(st);
  for _ in 0..h {
    let mut row_s = String::from("#");
    let row = read::<String>();
    row_s.push_str(&row);
    row_s.push_str("#");
    map.push(row_s);
  }

  let mut st2 = String::from("");
  for i in 0..w + 2 {
    st2.push_str("#")
  }
  map.push(st2);

  for i in map {
    println!("{}", i);
  }
}


Measured memory_bytes: 4352