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

int main(){
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> AB(N);
    for (int i = 0; i < N; ++i) {
        int a, b;
        cin >> a >> b;
        AB[i] = make_pair(a, b);
    }

    int ans = 0;
    sort(AB.begin(), AB.end());

    int l = 0;
    priority_queue<int> q;
    for (int i = 0; i < M; ++i) {
        for (int j = l; j < N; j++) {
            if (AB[j].first > i+1) {
                l = j;
                break;
            } else {
                q.push(AB[j].second);
            }
            if (j == N-1) {
                l = N;
            }
        }
        if (!q.empty()) {
            ans += q.top();
            q.pop();
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a >= b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
class SegTree {
    int n;// 葉の数
    vector<T> data;// データを格納するvector
    T def; // 初期値かつ単位元
    function<T(T, T)> operation; // 区間クエリで使う処理
    function<T(T, T)> update;// 点更新で使う処理

    T find(int a, int b) {
        T val_left = def, val_right = def;
        for (a += (n - 1), b += (n - 1); a < b; a >>= 1, b >>= 1)
        {
            if ((a & 1) == 0){
                val_left = operation(val_left, data[a]);
            }
            if ((b & 1) == 0){
                val_right = operation(data[--b],val_right);
            }
        }
        return operation(val_left, val_right);
    }
    public:
    // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数,
    // _update:更新関数
    SegTree(size_t _n, T _def, function<T(T, T)> _operation,
        function<T(T, T)> _update=[](T a,T b){return b;})
        : def(_def), operation(_operation), update(_update) {
        n = 1;
        while (n < _n) {
            n *= 2;
        }
        data = vector<T>(2 * n - 1, def);
    }
    void set(int i, T x) { data[i + n - 1] = x; }
    void build() {
        for (int k=n-2;k>=0;k--) data[k] = operation(data[2*k+1],data[2*k+2]);
    }
    // 場所i(0-indexed)の値をxで更新
    void change(int i, T x) {
        i += n - 1;
        data[i] = update(data[i], x);
        while (i > 0) {
            i = (i - 1) / 2;
            data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
        }
    }

    // [a, b)の区間クエリを実行
    T query(int a, int b) {
        //return _query(a, b, 0, 0, n);
        return find(a,b);
    }

    // 添字でアクセス
    T operator[](int i) {
        return data[i + n - 1];
    }
};

int main(){
    ll n;cin >> n;
    vl x(n),y(n);rep(i,n)cin >> x[i] >> y[i];
    vl xx(n),yy(n);
    rep(i,n)xx[i]=x[i]+y[i],yy[i]=x[i]-y[i];
    ll l=*min_element(all(xx)),r=*max_element(all(xx));
    ll d=*min_element(all(yy)),u=*max_element(all(yy));
    ll ans=0;
    rep(i,n){
        ll ret=-1;
        chmax(ret,r-xx[i]);
        chmax(ret,xx[i]-l);
        chmax(ret,u-yy[i]);
        chmax(ret,yy[i]-d);
        chmax(ans,ret);
    }
    cout << ans <<endl;
}

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

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

int v, dp[5001];
const int m[] = {200, 300, 500, 1000, 1200, 1500};
const int p[] = {380, 550, 850, 1520, 1870, 2244};
const int INF = 10000000;

/*
  @ツ残ツづィツづ個重ツつウ
*/

int dfs(int w) {
  if (w <= 0) return 0;
  if (dp[w] >= 0) return dp[w];
  int res = INF;
  rep(i,6) {
    res = min(res, dfs(w-m[i]) + p[i]);
  }
  return dp[w] = res;
}

void solve() {
  cout<<dp[v]<<endl;
}

int main (int argc, char const* argv[]) {
  rep(i,5001) dp[i] = INF;
  
  dp[0] = 0;
  rep(z,6) for(int i=0;i+m[z]<5001;i++) {
    dp[i+m[z]] = min(dp[i+m[z]], dp[i] + p[z]);
  }

  while (cin>>v, v) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 0
## C - Energy Drink Collector
N, M = map(int, input().split())
val = []
for n in range(N):
    val.append( list(map(int, input().split())) )
val = sorted(val, reverse=False, key=lambda x: x[0])
ans = 0
for n in range(N):
    if val[n][1] >= M:
        ans += val[n][0] * M
        break
    else:
        ans += val[n][0] * val[n][1]
        M -= val[n][1]
print(ans)

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

#define za ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod %1000000007
#define moz 1000000007
#define nl "\n"
#define S second
#define F first
#define PB push_back
#define MP make_pair
#define V vector
#define P pair
#define LEN length()
#define SZ size()
#define loop(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long ll;
typedef complex<ll> C;
#define X real()
#define Y imag()

int n,a,b,c;

int main()
{
    za;
    unordered_map <long long unsigned,int> um;
    long long unsigned arr[100009];
    int n;
    cin >> n ;
    loop(i,0,n-1)
    {
        cin >> arr[i];
    }
    sort(arr,arr+n);
    int co=0;
    vector <long long unsigned> v;
    for(int i=n-1;i>=0;i--)
    {
        um[arr[i]]++;
        if(um[arr[i]]==2)
        {
            co++;
            v.PB(arr[i]);
        }
        if(um[arr[i]]==4)
        {
            co++;
            v.PB(arr[i]);
        }
        if(co==2) break;
    }
    if(co<2) cout << '0' << nl;
    else cout << v[0]*v[1] << nl;
}


Measured memory_bytes: 4644
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
c=0
d=-1
for i in range(0,n):
    c+=a[i]
    d+=1
    if c-x>0:
        print(d)
        break
    elif c-x==0:
        print(d+1)
        break
else:
    print(n-1)

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

int main() {
	int n,m,x,y,ax=-20000000,ay=20000000,bx,by;
	cin>>n>>m>>x>>y;
	
	for(int i=0;i<n;i++){
		cin>>bx;
		if(bx>ax) ax=bx;
	}
	
	for(int i=0;i<m;i++){
		cin>>by;
		if(by<=ay) ay=by;
	}
	
	if(ax>x&&ay<=y&&ax<=y&&ay>x&&ax<ay) cout<<"No War"<<endl;
	else cout<<"War"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef set<ii> sii;
typedef set<int> si;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;

const int INF = 1000000000;
const ll MOD = 1000000007;

int main() {FIN
	
	int i, c = 0;
	string s;
	cin >> s;
	for (i = 0; i < (int)s.size(); i++) {
		if (i > 0 and s[i] != s[i-1])
			c++;
	}
	cout << c << "\n";
	
	return 0;
}


Measured memory_bytes: 3784
#include <stdio.h>

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

Measured memory_bytes: 596
#include<stdio.h>
int main() {
	int arr[5] , i ;
	for(i=0;i<5;i++)
	  scanf("%d",&arr[i]) ;
	for(i=0;i<5;i++)
	  if(arr[i]==0)  {
	  	printf("%d",i+1) ;
	  	break ;
	  }
}

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


double pi = 3.1415926535897946264338;

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

  double ans1 = (180 / pi) * (atan(2*(a*a*b - x)/(a*a*a)));
  double ans2 = (180 / pi) * (atan((a*b*b)/(2*x))); 

if (x >= (a*a*b)/2) {
  printf("%.10f \n", ans1);
  } else {
  printf("%.10f \n", ans2);
  }
  return 0;
}

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

using namespace std;

vector<int> g[100005];
typedef long long ll;
ll dp[100005][2];
int n;
const ll mod = 1e9 + 7;
ll rec(int v, int prev, bool WorB) {
  if(WorB && dp[v][0] != -1) return dp[v][0];
  if(!WorB && dp[v][1] != -1) return dp[v][1];
 
  ll res = 1;

  for(int i = 0; i < g[v].size(); i++) {
    if(g[v][i] == prev) continue;
    if(WorB) {

      res = res * (rec(g[v][i],v,true) + rec(g[v][i],v,false)) % mod;
    }
    else {
    
      res = res * rec(g[v][i],v,true) % mod;
    }
  }
 
  if(WorB) return dp[v][0] = res;
  else return dp[v][1] = res;
}

int main() {

  cin >> n;

  for(int i = 0; i < n - 1; i++) {
    int x,y;
    cin >> x >> y;
    x--;y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for(int i = 0; i <= n; i++) {
    for(int j = 0; j < 2; j++) {
      dp[i][j] = -1;
    }
  }
  
  rec(0,-1,true);

   rec(0,-1,false);

   /*for(int i = 0; i < n; i++) {
    for(int j = 0; j < 2; j++) {
      cout << dp[i][j] << endl;
    }
    }*/
  
  cout << (dp[0][0] + dp[0][1]) % mod << endl;
}


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

using namespace std;

int n,k,i,j,a[200005];
long long sum[200005],res;

void msort(int l, int r){
	if(l == r) return;
	
	int mid = (l + r) / 2;
	
	msort(l, mid);
	msort(mid + 1, r);
	
	vector <long long> left, right;
	
	for(int ii = l; ii <= mid; ii++)
	left.push_back(sum[ii]);
	for(int ii = mid + 1; ii <= r; ii++)
	right.push_back(sum[ii]);
	
	int p = 0;
	
	for(int ii = 0; ii < right.size(); ii++){
		while(p < left.size() && right[ii] - left[p] >= 0)
		p++;
		
		res += p;
	}
	
	vector <long long> m;
	
	p = 0;
	int p1 = 0;
	
	while(p < left.size() && p1 < right.size()){
		if(left[p] < right[p1])
		m.push_back(left[p++]);
		else
		m.push_back(right[p1++]);
	}
	
	while(p < left.size()) m.push_back(left[p++]);
	while(p1 < right.size()) m.push_back(right[p1++]);
	
	for(int ii = 0; ii < m.size(); ii++)
	sum[ii + l] = m[ii];
}

int main(){
	scanf("%d%d", &n, &k);
	
	for(i = 1; i <= n; i++){
		scanf("%d", &a[i]);
		a[i] -= k;
	}
	
	for(i = 1; i <= n; i++){
		sum[i] = a[i];
		sum[i] += sum[i - 1];
	}

	msort(0, n);
	
	printf("%lld\n", res);
}


Measured memory_bytes: 7764
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            string s = ReadLine();
            int ans = 0;
            for (int i = 0; i < n-2; i++)
            {
                if (s.Substring(i,3) == "ABC")
                {
                    ans++;
                }
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int a[5],k,i,j;
    for (i=0;i<5;i++)
        cin>>a[i];
    cin>>k;
    bool flag=true;
    for (i=0;i<4;i++)
    {
        for (j=i+1;j<5;j++)
        {
            if (a[j]-a[i]>k)
            {
                flag=false;
                break;
            }
        }
        if (flag==false)
            break;
    }
    if (flag)
        cout<<"Yay!\n";
    else
        cout<<":(\n";
}

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


int main(){
  int N, M, X;
  cin >> N >> M >> X;
  int A[N][M] = {};
  int C[N];
  for (int i=0;i<N;i++){
    cin >> C[i];
    for (int j=0;j<M;j++){
      cin >> A[i][j];
    }
  }
  
  
  
  int retval=10000000, retval_tmp=0;
  for (int tmp = 0; tmp < (1 << N); tmp++) {
    bitset<12> s(tmp);
    int rikaido[M] = {};
    int sum_rikaido = 0;
    bool check_ok = false;
    for (int i=0;i<N;i++) { //bit全探索,理解度を計算
      if (s.test(i)){
        for (int j=0;j<M;j++) rikaido[j] += A[i][j];
      }
    }

    for (int j=0;j<M;j++){
      if (rikaido[j]<X) break; //達成できない

      if (j==M-1) {
        check_ok = true; //達成できた
      }
    } 
    


    if (check_ok){ //目標達成が可能な場合、金額の最小値を計算 
      retval_tmp=0;
      for (int i=0;i<N;i++){
        if (s.test(i)) retval_tmp += C[i];
      }

      retval = min(retval, retval_tmp);

    }
  }
  
  if (retval==10000000) cout << -1 << endl;
  else cout << retval << endl;

}
 

Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	private static final FastIn in = new FastIn();
	private static final PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		Solver sol = new Solver();
		sol.solve();
		out.close();
	}

	private static final class Solver {
		public void solve() {
			int n = in.nextInt(), k = in.nextInt();
			boolean[] availDigits = new boolean[10];
			for (int i = 0; i < k; ++i) availDigits[in.next().charAt(0) - '0'] = true;
			outer: for (int i = n; i < 100000;  ++i) {
				String change = Integer.toString(i);
				for (int j = 0; j < change.length(); ++j) {
					if (availDigits[change.charAt(j) - '0'] == true)
						continue outer;
				}
				out.println(i);
				break;
			}
		}
	}

	private static final class FastIn {
		private BufferedReader br;
		private StringTokenizer st;

		public FastIn() {
			br = new BufferedReader(new InputStreamReader(System.in), 1 << 20);
			st = null;
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


Measured memory_bytes: 39232
using System;
using System.Linq;

namespace _0149
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] A = new int[2];
            int[] B = new int[2];
            int[] C = new int[2];
            int[] D = new int[2];
            while (true)
            {
                string now = Console.ReadLine();
                if (now == null)
                {
                    break;
                }
                double[] x = now.Split().Select(double.Parse).ToArray();
                for (int i = 0; i < 2; i++)
                {
                    if (x[i] >= 1.1)
                    {
                        A[i]++;
                    }
                    else if (x[i] >= 0.6)
                    {
                        B[i]++;
                    }
                    else if (x[i] >= 0.2)
                    {
                        C[i]++;
                    }
                    else
                    {
                        D[i]++;
                    }
                }
            }
            Console.WriteLine(A[0] + " " + A[1]);
            Console.WriteLine(B[0] + " " + B[1]);
            Console.WriteLine(C[0] + " " + C[1]);
            Console.WriteLine(D[0] + " " + D[1]);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9576
// https://atcoder.jp/contests/abc169/tasks/abc169_e
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int const maxn = 2e5 + 1;
int A[maxn], B[maxn];

int main() {
  int N;
  cin >> N;
  rep(i, N) { cin >> A[i + 1] >> B[i + 1]; }
  sort(A + 1, A + N + 1);
  sort(B + 1, B + N + 1);
  if (N % 2 == 1)
    cout << B[(N + 1) / 2] - A[(N + 1) / 2] + 1 << '\n';
  else
    cout << (B[N / 2] + B[N / 2 + 1] - A[N / 2] - A[N / 2 + 1]) + 1 << '\n';
}

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

#define int long long
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if(x&1) {
            if(i&1) {
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3648
#include <stdio.h>
int main(void){
    int i,n;
    long max,min;
    long R2,R1,Rt;
    
    scanf("%d",&n);
    
    scanf("%ld",&R1);
    scanf("%ld",&R2);
    
    max=R2-R1;
    min=R1;
    Rt=R2;
    
    for(i=2; i<=n; i++){
        if(i!=2)scanf("%ld",&Rt);
        if(max < Rt-min) max=Rt-min;
        if(min > Rt) min=Rt;
    }
    
//    for(j=2; j<=n; j++){
//        for(i=1; i<j; i++){
//            max = (max>R[j]-R[i]) ? max : R[j]-R[i];
//        }
//    }
    
    printf("%ld\n",max);
    return 0;
}

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

int main() {

 long long int N;
  long long int K=26;
  cin >> N;
  long long int A;
  char m;
  string S="";
  while(N>0){
    A=N%K;
    A=A/(K/26);
    A=A+96;
    if(A>96){
      m=A;
      S.append(1, m);
      N=N -(N%K);
    }
    else{
     S.append(1, 'z');
       N=N-K;
    }
    K=K*26;
      
  }
  reverse(S.begin(), S.end());
  cout << S<<endl;
  
 return 0;
}


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

int main(){
    ll n, m, ans;
    cin >> n >> m;
    if (n*2 <= m) {
        ans = n;
        ll tmp = m - n*2;
        ans += tmp/4;
    } else {
        ans = m/2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List
import Data.Array

main :: IO ()
main = do
  n <- getl toInt
  when (n /= 0) $ do
    putStr $ solve n
    main

solve :: Int -> String
solve n = unlines . map concat . split n . map toStr $ elems msqr
  where
    (_,msqr) = foldl putnum (((n+1) `div` 2 + 1, (n+1) `div` 2),(listArray ((1,1),(n,n)) $ repeat 0)) [1..n^2]
    putnum :: ((Int,Int), Array (Int,Int) Int) -> Int -> ((Int,Int), Array (Int,Int) Int)
    putnum ((i,j),ar) k = let nar = ar // [((i,j),k)] in (next nar (i+1,j+1),nar)
    next ar (y, x)
      | y == n+1 && x == n+1 = next ar (1,1)
      | y == n+1 && x == 0 = next ar (1,n)
      | y == n+1 = next ar (1,x)
      | x == n+1 = next ar (y,1)
      | x == 0 = next ar (y,n)
      | ar ! (y,x) /= 0 = next ar (y+1,x-1)
      | otherwise = (y,x)
        
toStr :: Int -> String
toStr x
  | x >= 100 = " " ++ show x
  | x >= 10 = "  " ++ show x
  | otherwise = "   " ++ show x

split :: Int -> [a] -> [[a]]
split n xs
  | null zs = [ys]
  | otherwise = ys : split n zs
  where
    (ys,zs) = splitAt n xs

toInt :: String -> Int
toInt s = read s

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 4288
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <iomanip>

using namespace std;

const int maxn = 3002;

int n;
double p[maxn], f[maxn][maxn];

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> p[i];

	f[0][0] = 1.0 - p[0];
	f[0][1] = p[0];

	for (int i = 1; i < n; ++i) {
		double b = 1.0 - p[i];
		for (int j = 0; j <= i+1; ++j)
			f[i][j] = f[i-1][j-1] * p[i] + f[i-1][j] * b;
	}

	double ans = 0;
	for (int j = n; j > n-j; --j)
		ans += f[n-1][j];

	cout <<fixed<<setprecision(10)<< ans << endl;

	return 0;
}

Measured memory_bytes: 68992
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

ll dp[100000][13];

int modpow(int x, int y){
	int res = 1;
	while(y > 0){
		if (y & 1) res = res*x%13;
		x = x*x%13;
		y >>= 1;
	}
	return res;
}

int main(){
	string s;
	cin >> s;
	reverse(s.begin(), s.end());
	if (s[0] == '?'){
		for (int i = 0; i <= 9; i++){
			dp[0][i] = 1;
		}
	}else{
		dp[0][s[0]-'0'] = 1;
	}

	for (int i = 1; i < s.length(); i++){
		if (s[i] == '?'){
			for (int j = 0; j < 10; j++){
				for (int k = 0; k < 13; k++){
					int temp = (j*modpow(10, i)+k)%13;
					dp[i][temp] += dp[i-1][k];
					dp[i][temp] %= MOD;
				}
			}
		}else{
			for (int j = 0; j < 13; j++){
				int temp = ((s[i]-'0')*modpow(10, i)+j)%13;
				dp[i][temp] += dp[i-1][j];
				dp[i][temp] %= MOD;
			}
		}
	}
	cout << dp[s.length()-1][5] << endl;
	return 0;
}



Measured memory_bytes: 10624
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	
	int N;
	cin >> N;
	
	int a[11000], b[11000];
	for(int i = 0; i < N; i++){
		cin >> a[i];
	}
	for(int i = 0; i < N; i++){
		cin >> b[i];
	}
	
	long long int Sa = 0, Sb = 0;
	for(int i = 0; i < N; i++){
		if((a[i] - b[i]) % 2){
			b[i] += 1;
			Sb += 1;
		}
		if(a[i] < b[i]){
			Sa += (b[i] - a[i]) / 2;
		}else{
			Sb += a[i] - b[i];
		}
	}
	
	if(Sa >= Sb){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    ll n;
    cin >> n;
    
    string name = "";
    while (n > 0) {
        n--;
        name.push_back('a' + (n % 26));
        n /= 26;
    }
    reverse(all(name));
    put(name);
    return 0;
}

Measured memory_bytes: 3604
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
    }

    let mut ans = vec![];
    let mid = n / 2;
    
    let mut l = 1;
    let mut r = mid;


    while l < r {
        ans.push((l, r));
        l += 1;
        r -= 1;
    }

    l = mid + 1;
    r = n;

    if (r - l + 1) % 2 == mid % 2 {
        l += 1;
    }
    while l < r {
        ans.push((l,r));
        l += 1;
        r -= 1;
    }

    for i in 0..m {
        let (l, r) = ans[i];
        println!("{} {}", l, r);
    }
}

Measured memory_bytes: 3344
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P=pair<int,int>;

const int nm = 3e5;
int h, w, m, a[nm], b[nm], ans = 0, mx = 0, my = 0;
vector<int> xs, ys;
vector<P> c;

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

	for (int i = 0; i < m; ++i) {
		int x, y;
		cin >> x >> y;
		--x;
		--y;
		++a[x];
		++b[y];
		c.emplace_back(x, y);
	}

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

	for (int i = 0; i < h; ++i) {
		if (mx == a[i])
			xs.emplace_back(i);
		else if (a[i] > mx) {
			mx = a[i];
			xs.clear();
			xs.emplace_back(i);
		}
	}
	for (int i = 0; i < w; ++i) {
		if (my == b[i])
			ys.emplace_back(i);
		else if (b[i] > my) {
			my = b[i];
			ys.clear();
			ys.emplace_back(i);
		}
	}

	for (int i : xs)
		for (int j : ys) {
			if (!binary_search(c.begin(), c.end(), make_pair(i, j))) {
				cout << mx + my << endl;
				return 0;
			}
		}

	cout << mx + my - 1 << endl;

}


Measured memory_bytes: 12300
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def xor(a,b):
	return (a and b) or ((not a) and (not b))

def main():
	s = input()
	ca=s[0]==s[-1]
	cb=len(s)%2==0
	win_first=xor(ca, cb)
	ret = 'First' if win_first else 'Second'
	
	print(ret)
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 39152
#include <stdio.h>
#include <string.h>

main()
{
  int a;
  scanf("%d", &a);
  char s[a];
  gets(s);
  char t[a];
  gets (t);
  char b = 'Y';
  char *p = NULL;
  p = strchr(t, b);
  if(!p)
	printf("Three");
  else
	printf("Four");
}
 

Measured memory_bytes: 128
#include <stdio.h>
int main(void) {
    int num,array[100],i,j,key;
    scanf("%d",&num);
    for (i=0; i<num; i++) scanf("%d",&array[i]);
    for (i=0; i<num; i++) {
        if (i) printf(" ");
        printf("%d",array[i]);
    }
    printf("\n");
    for (i=1; i<num; i++) {
        key=array[i];
        for (j=i-1; j>=0&&array[j]>key; j--) array[j+1]=array[j];
        array[j+1]=key;
        for (j=0; j<num; j++) {
            if (j) printf(" ");
            printf("%d",array[j]);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 604
import itertools
#itertools.permutations(t)

def main():
    n = int(input())
    p = tuple(map(int, input().split(" ")))
    q = tuple(map(int, input().split(" ")))

    n_list = [i+1 for i in range(n)]
    n_perm = list(itertools.permutations(n_list))
    
    for i, one in enumerate(n_perm):
        i1 = i + 1
        if one==p:
            a = i1
        if one==q:
            b = i1

    print(abs(a-b))

if __name__=="__main__":
    main()


Measured memory_bytes: 13844
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int c[3][3];
    repi(i, 3, 0)
    {
        repi(j, 3, 0)
        {
            cin >> c[i][j];
        }
    }
    //i,j,k = a1,a2,a3
    repi(i, 101, 0)
    {
        repi(j, 101, 0)
        {
            repi(k, 101, 0)
            {
                int cnt = 0;
                repi(l, 3, 0)
                {
                    if (c[0][l] - i == c[1][l] - j && c[1][l] - j == c[2][l] - k)
                        cnt++;
                }
                if (cnt == 3)
                {
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
cout << "No" << endl;
return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args:Array<String>){
    solve()
}

fun solve(){
    val s = read()
    val t = read()
    var ans = 0
    for(i in 0 until s.length){
        if(s[i] != t[i]) ans++
    }
    println(ans)
}

fun read() = readLine()!!
fun reads() = readLine()!!.split(" ")
fun readint() = readLine()!!.toInt()
fun readints() = readLine()!!.split(" ").map{it.toInt()}
fun readlong() = readLine()!!.toLong()
fun readlongs() = readLine()!!.split(" ").map{it.toLong()}

Measured memory_bytes: 40492
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n; cin>>n; 
    map <int,int>m;
    int a[n];
    for (int j=0;j<n;j++){
        cin>>a[j];
    }
    int ans=0;
    sort(a,a+n);
    for (int i=0;i<n;i++){
        for (int j=i+1;j<n;j++){
            for (int k=j+1;k<n;k++){
                set<int> s;
                s.insert(a[i]);
                s.insert(a[j]);
                s.insert(a[k]);
                if ((sz(s)==3) and (a[k]<a[i]+a[j])) ans++;
            }
        }
    }
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3624
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define DEBUG
#ifdef DEBUG
#define debug(...) __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
#define debug(...)
#endif

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ; ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

#define FAST_IO std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define ld long double
#define sz(a) (ll)(a).size()
#define endl "\n"

// priority_queue<ll, vector<ll>, less<ll>>pq;     // Max Heap
// priority_queue<ll, vector<ll>, greater<ll>>pq;  // Min Heap

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//K-th smallest
//cout << k << "kth (1 based indexing) smallest: " << *A.find_by_order(k - 1) << endl;
//NO OF ELEMENTS < X
//cout << "No of elements less than " << X << " are " << A.order_of_key(X) << endl;

int main()
{
	FAST_IO;

    ll n;
    cin >> n;
    ll a[n], b[n];
    for(int i=0;i<n;i++) cin >> a[i] >> b[i];
    for(int i=0;i<n-2;i++)
    {
    	if(a[i] == b[i] && a[i + 1] == b[i + 1] && a[i + 2] == b[i + 2])
    	{
    		cout << "Yes" << endl;
    		return 0;
    	}
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int a[n];
    for (int i = 0; i < n; i++) scanf("%d",&a[i]);
    int p[n][18]; memset(p,-1,sizeof(p));
    int l;
    scanf("%d",&l);
    int cur = 0;
    for (int i = 0; i < n; i++){
        while (cur < n && a[cur] - a[i] <= l) cur++;
        cur--;
        p[i][0] = cur;
        //printf("%d %d\n",i,cur);
    }
    for (int i = n-1; i >= 0; i--){
        for (int j = 1; j < 18; j++){
            if (p[i][j-1] == -1) break;
            p[i][j] = p[p[i][j-1]][j-1];
            //printf("%d %d %d\n",i,j,p[i][j]);
        }
    }
    int q;
    scanf("%d",&q);
    for (int i =0;  i < q; i++){
        int a,b;
        scanf("%d%d",&a,&b);
        a--; b--;
        if (a > b) swap(a,b);
        int cur = a;
        int sum = 0;
        for (int k = 17; k >= 0; k--){
            if (p[cur][k] < b){
                cur = p[cur][k];
                sum += (1<<k);
            }
        }
        printf("%d\n",sum+1);
    }

}


Measured memory_bytes: 8192
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	int a, b, c;
	in >> a >> b >> c;

	int a_[] = { a,b,c };
	std::sort(a_, a_ + 3);
	out << a_[0] * a_[1] / 2 << std::endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static int[][] map;
    static int[][] label;

    static int M;
    static int N;
    static int T;
    static int P;
    static int MOD = 1000000007;

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

        String s = scanner.nextLine();

        int ans = 9999;
        for (int i = 0; i < 26; i++) {
            String ss = s;
            String temps = "";
            int cnt = 0;
            while(true){
                int ok = 0;
                for (int j = 0; j < ss.length(); j++) {
                    if(ss.charAt(j) != 'a' + i)break;
                    ok++;
                }

                if(ok == ss.length())break;
                cnt++;
                for (int j = 0; j < ss.length() - 1; j++) {
                    if(ss.charAt(j) == 'a' + i || ss.charAt(j + 1) == 'a' + i){
                        temps = temps + (char)('a' + i);
                    }else{
                        temps = temps + '0';
                    }
                }
//                System.out.println(temps);
                ss = temps;
                temps = "";
//                break;

            }
            ans = Math.min(ans, cnt);
        }

        System.out.println(ans);


    }



}


Measured memory_bytes: 43348
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main()
{
    //freopen("A.01.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int d;
    cin >> d;
    switch (d)
    {
    case 25:
        cout << "Christmas" << endl;
        break;
    case 24:
        cout << "Christmas Eve" << endl;
        break;
    case 23:
        cout << "Christmas Eve Eve" << endl;
        break;
    case 22:
        cout << "Christmas Eve Eve Eve" << endl;
        break;
    };
    return 0;
}

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

using namespace std;

int main () {
    int N, K;
    string S;

    while (cin >> N >> K >> S) {
        int seg = 1;
        for (int i = 0;i < N-1;i++) {
            if (S[i] != S[i+1]) {
                seg++;
            }
        }
        seg -= K*2;
        seg = max(seg, 1);
        cout << N - seg << endl;
    }

    return 0;
}


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

int main() {
	string s;
	cin >> s;

	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[2]) {
		cout << "Yes" << endl;
	}
	else if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) {
		cout << "Yes" << endl;
	}
	else if (s[0] == s[3] && s[1] == s[2] && s[0] != s[1]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
from sys import stdin

# 空白で分割しつつ数値に変換
A, B, C = [int(x) for x in stdin.readline().rstrip().split()]

def main():
    x = B + C
    ans = x - A
    if ans >= 0:
        print("{}".format(ans))
    else:
        print("{}".format(0))
if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#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>
#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
#define MOD 1000000007
using namespace std;

char str[1005];

int main(int argc, char* argv[])
{
    scanf("%s", str);
    long w;
    scanf("%ld", &w);

    vector<char> z;
    long i;
    for(i=0; i<strlen(str); i+=w) {
        z.push_back(str[i]);
    }
    z.push_back('\0');

    printf("%s\n", &(z[0]));

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using P  = pair<int, int>;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    vec<P> p, m;
    rep(i, N) {
        string s;
        cin >> s;
        ll last = 0;
        ll mn   = 0;
        for (auto e : s) {
            if (e == '(')
                ++last;
            else
                --last;
            mn = min(mn, last);
        }
        if (last >= 0)
            p.push_back({-mn, last});
        else
            m.push_back({-(mn-last), -last});
    }

    sort(all(p));
    sort(all(m));

    ll now = 0;
    for (auto [f, e] : p) {
        if (now - f < 0) {
            cout << "No" << endl;
            return 0;
        } else {
            now = now + e;
        }
    }

    ll now2 = 0; 
    for (auto [f, e] : m) {
        if (now2 - f < 0) {
            cout << "No" << endl;
            return 0;
        } else {
            now2 = now2 + e;
        }
    }
    if (now != now2) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

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

int main(){//参加者のポイントをQ減らし、正解者にポ
//イントを増やしていく実装
  int N,K,Q;
  cin >> N >> K >> Q;
  vector<int> s(N,K-Q);//あらかじめ参加者のポイント
  //を減らしておく
  vector<int> A(Q);
  for(int i=0;i<Q;i++)cin >> A.at(i);
  for(int i=0;i<Q;i++){
    s.at(A.at(i)-1)++;
  }
  for(int i=0;i<N;i++){
    if(s.at(i)<=0)cout << "No" << endl;
    else cout << "Yes" << endl;
  }
}

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

int main() {
    int64_t a, b;
    cin >> a >> b;
    if (a > b) {
        swap(a, b);
    }
    for (int64_t i = 0; i < b; i++) {
        cout << a;
    }
    cout << endl;

}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	N := nextInt()
	s := make([]string, N)
	t := make([]int, N)
	for i := 0; i < N; i++ {
		s[i] = nextString()
		t[i] = nextInt()
	}
	X := nextString()
	b := false
	ans := 0
	for i := 0; i < N; i++ {
		if b {
			ans += t[i]
		}
		if X == s[i] {
			b = true
		}
	}
	fmt.Println(ans)
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <math.h>
#include <list>

#define timemax 1260+1
using namespace std;

//文字列反転関数
string revstr(string s) {
	string ret;
	for(int i = s.length() - 1; i >= 0; i--)
		ret += s.at(i);
	return ret;
}

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);
	
	int m;
	cin >> m;
	for(int i = 0; i < m; i++) {
		string s;
		list<string> strlist;
		cin >> s;

		//文字列を分割する
		for(int j = 1; j < s.length(); j++) {
			string sub[2];
			sub[0] = s.substr(0,j);
			sub[1] = s.substr(j,string::npos);
			//cout << sub[0] << "+" << sub[1] << endl;
			//文字列を結合する
			for(int k = 0; k < 2; k++) {
				string temp[2];
				for(int l = 0; l < 4; l++) {
					temp[0] = sub[0];
					temp[1] = sub[1];
					if( l & 1 ) temp[0] = revstr(temp[0]);
					if( l & 2 ) temp[1] = revstr(temp[1]);
					string tmp = temp[k] + temp[1 - k];
					strlist.push_back(tmp);
				}
			}
		}
		strlist.sort();
		strlist.unique();
		cout << strlist.size() << endl;
	}

	//while(1){}
	return 0;
}

Measured memory_bytes: 1348
MOD = 10 ** 9 + 7


def mul_mod(x, y, mod):
    return x * y % mod


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(key=lambda x: abs(x), reverse=True)

    res = 1

    if k == 1:
        res = max(a) % MOD
    elif k == n:
        res = 1
        for e in a:
            res *= e
            res %= MOD
    elif max(a) < 0:
        if k % 2 == 1:
            for i in range(n - k, n):
                res *= a[i]
                res %= MOD
        else:
            for i in range(k):
                res *= a[i]
                res %= MOD
    else:
        plus_a = [e for e in a if e >= 0]
        minus_a = [e for e in a if e < 0]

        minus_cnt = min(k, len(minus_a))
        minus_cnt -= minus_cnt % 2
        plus_cnt = k - minus_cnt

        minus_a = minus_a[:minus_cnt]
        minus_a.reverse()

        max_change_cnt = min(minus_cnt, len(plus_a) - plus_cnt)
        max_change_cnt -= max_change_cnt % 2
        change_cnt = 0
        while change_cnt < max_change_cnt:
            if plus_a[plus_cnt + change_cnt] * plus_a[plus_cnt + change_cnt + 1]\
                    <= minus_a[change_cnt] * minus_a[change_cnt + 1]:
                break
            change_cnt += 2

        for i in range(change_cnt, minus_cnt):
            res *= minus_a[i]
            res %= MOD

        for i in range(plus_cnt + change_cnt):
            res *= plus_a[i]
            res %= MOD

    print(res)


main()


Measured memory_bytes: 31824
//------------------------------------------
// C++ templete
//------------------------------------------
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(), (a).end()
#define PRINT(V)     \
  for (auto v : (V)) \
  cout << v << " "
#define SORT(V) sort((V).begin(), (V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

//math
//------------------------------------------
int QP(int a, int b)
{
  int ans = 1;
  do
  {
    if (b & 1)
      ans = 1ll * ans * a % MOD;
    a = 1ll * a * a % MOD;
  } while (b >>= 1);
  return ans;
}
int QP(int a, int b, int MOD)
{
  int ans = 1;
  do
  {
    if (b & 1)
      ans = 1ll * ans * a % MOD;
    a = 1ll * a * a % MOD;
  } while (b >>= 1);
  return ans;
}
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

//debug
//------------------------------------------
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

//動的計画法で役に立つ関数
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;
}

//最大公約数と最小公倍数
ll gcd(ll a, ll b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

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

vector<vector<long long> > comb(int n)
{
  vector<vector<long long> > v(n + 1, vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++)
  {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++)
  {
    for (int k = 1; k < j; k++)
    {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

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

  string N;
  cin >> N;
  int n = N.size();
  if (n == 1)
    cout << N << endl;
  else
  {
    bool should_add=true;
    int ans = 0;
    char before;
    REP(i, n)
    {
      if (i != 0)
      {
        if (N[i] == '9')
        {
          ans += before - 48;
        }
        else
        {
          ans+=before-48-1;
          REP(j, n-i)
          {
            ans+=9;
          }
          should_add=false;
          break;
        }
      }
      before = N[i];
    }
    if (should_add) ans+=before-48;
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

signed main(){
	
	string s;
	cin>>s;
	if(s[s.size()-1]=='2'||s[s.size()-1]=='4'||s[s.size()-1]=='5'||s[s.size()-1]=='7'||s[s.size()-1]=='9'){
		cout<<"hon"<<endl;
	}
	else if(s[s.size()-1]=='3'){
		cout<<"bon"<<endl;
	}
	else {
		cout<<"pon"<<endl;
	}
	

}


Measured memory_bytes: 3596