akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
int main(){
	int n, m;
	while(cin >> n >> m, (n || m)) {
		int x[100][100], y[50][50];
		rep(i,n) {
			rep(j,n) {
				cin >> x[i][j];
			}
		}
		rep(i,m) {
			rep(j,m) {
				cin >> y[i][j];
			}
		}
		int rx = n+1, ry = n+1;
		rep(i,4) {
			int sx = 0, sy = 0;
			rep(j,m) {
				rep(k,m) {	
					if(y[j][k] != -1) {
						sx = k+1, sy = j+1;
						break;
					}					
				}
				if(sx) break;
			}
			bool f = 1;
			rep(j,n-m+1) {
				rep(k,n-m+1) {
					f = 1;
					rep(p,m) {
						rep(q,m) {
							if(y[p][q] != -1 && x[j+p][k+q]!=y[p][q]) {
								f = 0;
								break;
							}
						}
						if(!f) break;
					}
					if(f) {
						sx += k, sy += j;
						break;
					}
				}
				if(f) break;
			}
			if(f && (sy<ry || sy==ry && sx<rx)) {
				rx = sx, ry = sy;
			}
			int n[50][50];
			rep(i,m) {
				rep(j,m) {
					n[i][j] = y[j][m-i-1];
				}
			}
			rep(i,m) {
				rep(j,m) {
					y[i][j] = n[i][j];
				}
			}
		}
		if(rx==n+1&&ry==n+1) cout << "NA" << endl;
		else cout << rx << " " << ry << endl;
	}
}

Measured memory_bytes: 1220
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int a, b;
  cin >> a >> b;
  int ans = max( a + b, max( a - b, a * b));
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k,c=0,c1=0;
    cin>>n;
    if(n<105)
        cout<<0<<endl;
    else if(n==105)
        cout<<1<<endl;
    else
    {
        c1=1;
        for(i=106;i<=n;i++)
        {
            k=i;

            for(j=1;j<=k;j++)
            {

                if(k%j==0)

                   {
                       c++;
                   }
            }

          if(i%2!=0 && c==8)
            c1++;
          c=0;
        }
        cout<<c1<<endl;
    }

}


Measured memory_bytes: 256
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, Y] = string_to_int(inputs[0])
    Y = Y // 1000

    for n10 in reversed(range(N+1)):
        for n5 in reversed(range(N - n10 + 1)):
            n1 = N - (n10 + n5)
            if n1 >= 0:
                money = 10 * n10 + 5 * n5 + 1 * n1
                if money == Y:
                    return "{} {} {}".format(n10, n5, n1)
    return '-1 -1 -1'


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3812
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int N;
int W[100];
int S1=0, S2=0;

int main(){
    cin>>N;
    rep(i,N){
        cin>>W[i];
        S2+=W[i];
    }

    int ans=100100;
    rep(i,N){
        S1+=W[i];
        S2-=W[i];
        if(abs(S1-S2)<ans) ans=abs(S1-S2);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
c = [list(map(int, input().split())) for i in range(3)]
vert1 = [c[1][i] - c[0][i] for i in range(3)]
vert2 = [c[2][i] - c[1][i] for i in range(3)]
horiz1 = [c[i][1]-c[i][0] for i in range(3)]
horiz2 = [c[i][2]-c[i][1] for i in range(3)]

if len(set(vert1)) == len(set(vert2)) == len(set(horiz1)) == len(set(horiz2)) == 1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
n = int(input())
AC, WA, TLE, RE = 0, 0, 0, 0
for i in range(n):
    s = input()
    if s == 'AC':
        AC += 1
    elif s == 'WA':
        WA += 1
    elif s == 'TLE':
        TLE += 1
    else:
        RE += 1

print('AC x', AC)
print('WA x', WA)
print('TLE x', TLE)
print('RE x', RE)

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

int main() {
    map<string, int> cnt;
    string s;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s;
        cnt[s]++;
    }
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s;
        cnt[s]--;
    }
    int max = 0;
    map<string, int>::iterator it;
    for (it = cnt.begin(); it != cnt.end(); it++) {
        if (max < it->second) {
            max = it->second;
        }
    }
    cout << max << endl;
    return 0;
}



Measured memory_bytes: 380
using System;
using System.Linq;
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string[] str=Console.ReadLine().Split(' ');
      int A=int.Parse(str[0]);
      int B=int.Parse(str[1]);
      if((A==2)||(B==2)){
        Console.WriteLine("No");
      }else{
        Console.WriteLine("Yes");
      }
    }
    
  }

}


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

#define N 500000
int count=0;

void Merge(int A[], int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;
  int L[n1+1], R[n2+1];
  int i, j, k;

  for(i=0; i<n1; i++) L[i] = A[left + i];
  for(i=0; i<n2; i++) R[i] = A[mid + i];
  L[n1] = R[n2] = 1000000000;
  i = j = 0;
  for(k=left; k<right; k++){
    count++;
    if (L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }
    else{
      A[k] = R[j];
      j++;
    }
  }
}

void MergeSort(int A[], int left, int right){
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    MergeSort(A, left, mid);
    MergeSort(A, mid, right);
    Merge(A, left, mid, right);
  }
}

int main(){
  int n, A[N], i;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
  MergeSort(A, 0, n);
  for(i=0; i<n-1; i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[i]);
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 4504
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    K = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    s=input()
    ls=len(s)
    tot=pow(26,ls+K,mod)

    N=ls+K
    fact=[0]*(N+1)#NはnCrの最大のn
    ifact=[0]*(N+1)
    fact[0],fact[1],ifact[0],ifact[1]=1,1,1,1
    for i in range(2,N+1):
        x=(fact[i-1]*i)%mod
        fact[i]=x
        ifact[i]=pow(x,mod-2,mod)
    pows=[1]*(N+1)
    for i in range(1,N+1):
        pows[i]=pows[i-1]*25%mod

    def comb(n,r): return (fact[n]*ifact[r]%mod)*ifact[n-r]%mod
    
    for i in range(0,ls):
        tot-=comb(ls+K,i)*pows[ls+K-i]
        tot%=mod
    print(tot)
    






if __name__ == "__main__":
    main()

Measured memory_bytes: 122592
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
    int A,B,C,D;
    cin>>A>>B>>C>>D;

    cout<<max(A*B,C*D)<<endl;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000000;
long long MOD = 1000000007;
int main(){
  int N;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++){
    cin >> T[i];
  }
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  vector<int> m(N, 1);
  vector<int> M(N, INF);
  M[0] = min(M[0], T[0]);
  m[0] = max(m[0], T[0]);
  for (int i = 1; i < N; i++){
    if (T[i - 1] < T[i]){
      M[i] = min(M[i], T[i]);
      m[i] = max(m[i], T[i]);
    } else {
      M[i] = min(M[i], T[i]);
    }
  }
  M[N - 1] = min(M[N - 1], A[N - 1]);
  m[N - 1] = max(m[N - 1], A[N - 1]);
  for (int i = N - 2; i >= 0; i--){
    if (A[i] > A[i + 1]){
      M[i] = min(M[i], A[i]);
      m[i] = max(m[i], A[i]);
    } else {
      M[i] = min(M[i], A[i]);
    }
  }
  long long ans = 1;
  for (int i = 0; i < N; i++){
    ans *= max(M[i] - m[i] + 1, 0);
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4728
#include <stdio.h>

#define BIG ((long long) 1e18)

int main(void)
{
    int n;
    long long as[100000];
    scanf("%d", &n);

    long long ans = 1;
    for (int i = 0; i < n; i++)
    {
        scanf("%lld", &as[i]);
    }

    for (int i = 0; i < n; i++)
    {
        if (as[i] == 0)
        {
            printf("0\n");
            return 0;
        }
    }

        for (int i = 0; i < n; i++)
        {
            if (as[i] > BIG / ans)
            {
                printf("-1\n");
                return 0;
            }
            ans *= as[i];
        }

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 2492
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;
static const int MAX_N = 50;

int main(void){
    int n;

    // 入力
    cin >> n;
    vector<double> v(n);
    for(int i=0; i<n; i++){
        cin >> v[i];
    }

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

    vector<double>::iterator itr = v.begin();
    double ans = 0;
    // n-1を先に
    *itr /= pow(2.0, n-1);
    ans += *itr;
    ++ itr;
    for(int i=n-2; i>=0; i--){
        *itr /= pow(2.0, i+1);
        ans += *itr;
        ++itr;
    }

    cout << ans;
    return 0;
}

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

template<typename T, typename U>
using pv=vector<pair<T,U>>;
template<typename T>
using matrix=vector<vector<T>>;
template<typename T>
using pque=priority_queue<T>;
template<typename T>
using lpque=priority_queue<T,vector<T>,greater<T>>;

using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using ilpair=pair<int,ll>;
using lipair=pair<ll,int>;
using intvec=vector<int>;
using llvec=vector<ll>;
using intq=queue<int>;
using llq=queue<ll>;
using intmat=vector<intvec>;
using llmat=vector<llvec>;

#define PI 3.141592653589793
#define INTINF ((1<<30)-1)
#define LLINF 1LL<<60
#define MPRIME 1000000007
#define MPRIME9 998244353
#define MMPRIME (1ll<<61)-1

#define len length()
#define pushb push_back
#define fi first
#define se second

#define all(name) name.begin(),name.end()
#define rall(name) name.rbegin(),name.rend()
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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>
inline void init(T& v) {
	for(auto &a: v) cin>>a;
}
template<class T, class U>
inline void init(vector<pair<T,U>>& v) {
	for(auto &a: v) cin>>a.first>>a.second;
}
template<class T, class N>
inline void init(T& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a;
}
template<class T, class U, class N>
inline void init(vector<pair<T,U>>& v, N n) {
	v.resize(n);
	for(auto &a: v) cin>>a.first>>a.second;
}

template<class T>
inline void out(T a) {
	cout<<a<<endl;
}
template<class T, class... U>
inline void out(T a, U... alist) {
	cout<<a<<" ";
	out(forward<U>(alist)...);
}

template<class N>
void resiz(N n) {
	//empty
}
template<class N, class T, class... U>
void resiz(N n, T&& hd, U&&... tl) {
	hd.resize(n);
	resiz(n,forward<U>(tl)...);
}

ll binpow(ll a, ll ex, ll p) {
	ll result=1;
	while(ex>0) {
		if(ex&1) result=result*a%p;
		ex>>=1;
		a=a*a%p;
	}
	return result;
}


int N,K,R,S,P;
string T;
int res;

void input() {
	cin>>N>>K>>R>>S>>P>>T;
}

void solve() {
	for(int i=0; i<K; i++) {
		bool but=true;
		for(int j=i; j<N; j+=K) {
			char ch=T[j];
			switch(ch) {
				case 'r': {
					if(j==i || T[j]!=T[j-K]) {
						res+=P;
						but=true;
					}
					else if(but) {
						but=false;
					}
					else {
						res+=P;
						but=true;
					}
					break;
				}
				case 's': {
					if(j==i || T[j]!=T[j-K]) {
						res+=R;
						but=true;
					}
					else if(but) {
						but=false;
					}
					else {
						res+=R;
						but=true;
					}
					break;
				}
				case 'p': {
					if(j==i || T[j]!=T[j-K]) {
						res+=S;
						but=true;
					}
					else if(but) {
						but=false;
					}
					else {
						res+=S;
						but=true;
					}
					break;
				}
			}
		}
	}

	cout<<res<<endl;
}

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(15);
	int t=1;
	while(t) {
		input();
		solve();
		t--;
	}
}


Measured memory_bytes: 3732
#include<iostream>
using namespace std;
int main()
{
    long long n,b[200005]={0},i,x,j;
    cin>>n;
    for(i=1;i<n;i++)
    {
        cin>>x;
        b[x]=b[x]+1;
    }
    for(j=1;j<=n;j++)
    {
        cout<<b[j]<<endl;
    }
    return 0;
}

Measured memory_bytes: 5200
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<cstdio>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
#define INF 1000000007
#define ARRAY_MAX 30
ll dx[4] = {1,0,0,-1};
ll dy[4] = {0,1,-1,0};

int n;
int dp[ARRAY_MAX][ARRAY_MAX];

void warshal_floyd(){
    REP(k,10){
        REP(i,10){
            REP(j,10){
                dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j]);
            }
        }
    }
}

int main(){

    while(cin >> n,n){
        int maxi_town_number = -1;
        REP(i,ARRAY_MAX){
            REP(j,ARRAY_MAX){
                dp[i][j] = INF;
                if(i == j){
                    dp[i][j] = 0;
                }
            }
        }
        REP(i,n){
            int a,b,c;
            cin >> a >> b >> c;
            maxi_town_number = max(maxi_town_number,max(a,b));
            dp[a][b] = c;
            dp[b][a] = c;
        }
        warshal_floyd();
        int mini_town = INF;
        int maxi = INF;

        REP(i,maxi_town_number+1){
            int sum = 0;
            //i番目の町に住んでいる
            REP(j,maxi_town_number+1){
                if(dp[i][j] != INF){
                    sum += dp[i][j];
                }
            }
            if(sum < maxi){
                maxi = sum;
                mini_town = i;
            }
        }   
        cout << mini_town << " " << maxi << endl;
    }



    return 0;
}


Measured memory_bytes: 3000
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
    double h;
    cin >> h;

    ll ans = 1L;
    ll num = 1L;
    while (true)
    {
        h = floor(h / 2);
        if (h == 0.0) break;

        num *= 2L;
        ans += num;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
constexpr long long int MOD = 998244353LL;
long long int power(long long int base, int exp) {
	switch (exp) {
	case 0: return 1LL;
	case 1: return base % MOD;
	default: return power(base * base % MOD, exp >> 1) * power(base, exp & 1) % MOD;
	}
}
int main() {
	int n, m, k; std::cin >> n >> m >> k;
	if (m == 1) {
		if (k == n - 1) {
			std::cout << "1\n";
		}
		else {
			std::cout << "0\n";
		}
		return 0;
	}
	std::vector<long long int> fact(n + 1, 1), inv(n + 1, 1), ifact(n + 1, 1);
	for (auto i = 2; i < fact.size(); ++i) {
		fact[i] = i * fact[i - 1] % MOD;
		inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
		ifact[i] = inv[i] * ifact[i - 1] % MOD;
	}
	long long int result{ power(m - 1, n - 1) * m % MOD };
	for (auto i = 1; i <= k; ++i) {
		const auto pat = fact[n - 1] * ifact[i] % MOD * ifact[n - 1 - i] % MOD * power(m - 1, n - 1 - i) % MOD * m % MOD;
		result += pat;
		result %= MOD;
	}
	std::cout << result << '\n';
}


Measured memory_bytes: 7852
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

int main(){

    long long n;
    cin >> n;
    int s = n/1000000000 + (n/100000000) % 10 + (n/10000000)%10 + (n/1000000) %10 + (n/100000) % 10 +(n / 10000) % 10 + (n/1000) %10 + (n/100) % 10 + (n/10)%10 + n%10;

    if(n % s == 0)
        cout << "Yes" << endl;
    else    
        cout << "No" << endl;
    
    }


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<map>
#include<iomanip>
#include<limits>
#include<queue>
#include<set>
#include<cstdio>
#include<climits>
#include<cstring>

using namespace std;

int N;
int K;

bool hate[10];

bool okay(){
	int cur = N;
	while(cur){
		if(hate[cur%10]){
			return false;
		}
		cur/=10;
	}
	return true;
}

int main(){

   cin >> N >> K;

	for(int i = 0;i < K;i++){
		int x;
		cin >> x;
		hate[x] = 1;
	}

	while(!okay()){
		N++;
	}

	cout << N << endl;

	return 0;

}


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

typedef pair<int,int> P;
const int POINT = 600001;
const int MAX = 200000;
struct Edge{int to;int cost;};
bool vis[POINT];
void Dijk(vector<Edge> G[],int n,int s,long long res[POINT]){
	fill(res,res+n,0);
	fill(vis,vis+n,false);
	priority_queue<P,vector<P>,greater<P>> que;
	P p;
	vis[s]=true;
	res[s]=0;
	que.push(P(0,s));
	while(!que.empty()){
		p = que.top();
		que.pop();
		for(Edge e:G[p.second]){
			if(!vis[e.to] || res[e.to]>res[p.second]+e.cost){
				vis[e.to]=true;
				res[e.to]=res[p.second]+e.cost;
				que.push(P(res[e.to],e.to));
			}
		}
	}
}
int main(){
	int N,A[MAX];
	long long ans[POINT],res;
	vector<Edge> G[POINT];
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	for(int i=0;i<N;i++){
		for(int j=0;j<3;j++){
			for(int k=0;k<=min(j,N-i-3);k++){
				G[i+j*N].push_back({i+k+2+(j-k)*N,-A[i+k+2]});
			}
		}
	}
	if(N%2){
		for(int i=0;i<3;i++)G[3*N].push_back({2-i+i*N,-A[2-i]});
	}else{
		for(int i=0;i<2;i++)G[3*N].push_back({1-i+i*N,-A[1-i]});
	}
	Dijk(G,3*N+1,3*N,ans);
	
	for(int i=0;i<3;i++){
		for(int j=0;j<=i;j++){
			if(i==0&&j==0 || vis[N-1-j+i*N]&&res>ans[N-1-j+i*N]){
				res=ans[N-1-j+i*N];
			}
		}
	}
	cout<<-res;
	return 0;
}

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

int main() {
	int H, W;

	cin >> H >> W;

	while(!(H == 0 && W == 0)) {
		for (int h = 0; h < H; h++) {
			for (int w = 0; w < W; w++) {
				cout << '#';
			}
			cout << endl;
		}
		cout << endl;
		cin >> H >> W;
	}

	return 0;
}



Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    double n,k,u=1;
    double ans;
    cin >> n >> k;
    vector<int> s(n);
    for (int i=1;i<n+1;i++){
        while (true){
            if (i*u>k)break;
            u=u*2;
        }
        if (u==1) {ans+=u/n;continue;}
        while (i*u/2>=k) {u=u/2;}
        ans +=1/(n*u);
    }
    printf("%.16f"  , ans);
}


Measured memory_bytes: 640
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, K = map(int, input().split())
    if (N - 1) * (N - 2) // 2 < K:
        print(-1)
        return
    else:
        edges = set()
        for i in range(2, N + 1):
            edges.add((1, i))

        cnt = (N - 1) * (N - 2) // 2
        for i in range(1, N):
            for j in range(i, N + 1):
                if i == j:
                    continue

                if cnt == K:
                    print(len(edges))
                    for a, b in edges:
                        print(a, b)
                    return

                if (i, j) not in edges:
                    cnt -= 1
                    edges.add((i, j))

        print(len(edges))
        for a, b in edges:
            print(a, b)
        return


if __name__ == "__main__":
    main()


Measured memory_bytes: 4028
N,Q=map(int,input().split())
S=input()

c=0
s=[0]
for i in range(1,N):
    if S[i-1]=='A' and S[i]=='C':
        c+=1
    s.append(c)
    
for i in range(Q):
    l,r=map(int,input().split())
    out=s[r-1]-s[l-1]

    print(out)


Measured memory_bytes: 6100
#include <iostream>

int main() {
  unsigned long long n, a, b;

  std::cin >> n;
  std::cin >> a;
  std::cin >> b;

  if (a == 0) {
    std::cout << 0 << std::endl;
  } else {
    std::cout << (a * (n / (a + b)) + std::min(a, n % (a + b))) << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
n = int(input())
A = [int(i) for i in input().split()]
the = pow(10,18)
ans = 1

if 0 in A:
    print(0)
else:
    for i in range(n):
        ans *= A[i]
        if ans >the:
            print(-1)
            break
        else:
            continue
    if ans <= the:
        print(ans)
    



Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lson root<<1,l,midd
#define rson root<<1|1,midd+1,r
const int M=2e5+5;
const int inf=0x3f3f3f3f;
const ll INF=1e18;
struct Segtree{
    ll tr[M<<2],lz[M<<2];
    void build(int root,int l,int r){
        tr[root]=0,lz[root]=0;
        if(l==r)return ;
        int midd=(l+r)>>1;
        build(lson);
        build(rson);
    }
    void pushdown(int root){
        ll c=lz[root];
        tr[root<<1]+=c,tr[root<<1|1]+=c;
        lz[root<<1]+=c,lz[root<<1|1]+=c;
        lz[root]=0;
    }
    void update(int L,int R,ll val,int root,int l,int r){
        if(L<=l&&r<=R){
            tr[root]+=val;
            lz[root]+=val;
            return ;
        }
        if(lz[root])pushdown(root);
        int midd=(l+r)>>1;
        if(L<=midd)update(L,R,val,lson);
        if(R>midd)update(L,R,val,rson);
        tr[root]=min(tr[root<<1],tr[root<<1|1]);
    }
    ll query(int L,int R,int root,int l,int r){
        if(L<=l&&r<=R)
            return tr[root];
        if(lz[root])pushdown(root);
        ll res=INF;
        int midd=(l+r)>>1;
        if(L<=midd)res=min(res,query(L,R,lson));
        if(R>midd)res=min(res,query(L,R,rson));
        return res;
    }
}x,y;
int main(){
    int n,m;cin>>n>>m;
    x.build(1,1,m),y.build(1,1,m);
    for(int i=1;i<=m;i++)y.update(i,i,-i,1,1,m);
    for(int i=1;i<=n;i++){
        int a,b;cin>>a>>b;
        x.update(b+1,b+1,min(1ll*(b+1+y.query(1,b,1,1,m))-x.query(b+1,b+1,1,1,m),0ll),1,1,m);
        y.update(b+1,b+1,min(y.query(1,b,1,1,m)-y.query(b+1,b+1,1,1,m),0ll),1,1,m);
        x.update(a,b,1e9,1,1,m);
        y.update(a,b,1e9,1,1,m);
        x.update(1,m,1,1,1,m);
        y.update(1,m,1,1,1,m);
        ll ans=x.query(1,m,1,1,m);
        if(ans>=1e9)puts("-1");
        else printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 20168
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PA;
char p[1005][1005];
int main(){
  int c,n,d,a,b;
  scanf("%d %d",&c,&n);
  for(int i=0;i<n;i++){
    scanf("%s",p[i]);
  }
  
  int joge=0,sayu=0;
  for(int i=0;i<n/2;i++){
    for(int j=0;j<n;j++){
      if(p[i][j] != p[n-1-i][j]) joge++;
    }
  }
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n/2;j++){
      if(p[i][j] != p[i][n-1-j]) sayu++;
    }
  }
  
  int sum = 0;
  if(joge == 0 && sayu == 0) sum++;

  for(int i=0;i<c-1;i++){
    scanf("%d",&d);
    for(int j=0;j<d;j++){
      scanf("%d %d",&a,&b);
      a--;
      b--;
      if(p[a][b] == '0') p[a][b] = '1';
      else if(p[a][b] == '1') p[a][b] = '0';
      
      if(p[a][b] == p[n-1-a][b]) joge--;
      else if(p[a][b] != p[n-1-a][b]) joge++;
      
      if(p[a][b] == p[a][n-1-b]) sayu--;
      else if(p[a][b] != p[a][n-1-b]) sayu++;
      
    }
    if(joge == 0 && sayu == 0) sum++;
  }
  printf("%d\n",sum);
  return(0);
}



Measured memory_bytes: 4172
import itertools
import copy

H, W, K = map(int, input().split())

c = ['a'] * H
cnt = 0

for i in range(H):
    c[i] = input()
    cnt += c[i].count('#')

#print(cnt)
#print(c)
cnt = cnt - K
ans = 0
comH = list(range(H))
comW = list(range(W))

#print(comH, comW)

for n in range(len(comH)+1):
    for combiH in itertools.combinations(comH, n):
        #print(list(combiH))
        LcomH = list(combiH)
        tmpc = copy.deepcopy(c)
        Hchange = 0
        for i in LcomH:
            Hchange += tmpc[i].count('#')
            tmpc[i] = tmpc[i].replace('#', 'r')
        for m in range(len(comW)+1):
            for combiW in itertools.combinations(comW, m):
                #print(list(combiW))
                LcomW = list(combiW)
                Wchange = 0
                for j in LcomW:
                    for gyo in range(H):
                        if tmpc[gyo][j] == '#':
                            Wchange += 1
                #print(tmpc)
                #print(Hchange, Wchange)
                if Hchange + Wchange == cnt:
                    ans += 1

print(ans)

Measured memory_bytes: 9108
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, l;
  cin >> n >> l;
  vector<string> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n; i++) {
    cout << a[i];
  }
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N, ans = 0;
	cin >> N;
	vector<int> A(min(N+2, 10000));
	for (int i = 1; i < min(N+2, 10000); i++) {
		ans += i;
		A.at(i) = 1;
		if (ans >= N) {
			A.at(ans - N) = 0;
			break;
		}
	}
	for (size_t i = 0; i < min(N + 2, 10000); i++)
	{
		if (A.at(i) == 1)cout << i << endl;
	}
}

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


signed main() {
  int N, K;
  cin >> N >> K;
  
  int ans = K;
  if( N == 1 ){
    cout << ans << endl;
    return 0;
  }
  for( int i = 0; i < N-1; i++ ){
    ans = ans *(K-1);
  }
  cout << ans << endl;
  
}

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

int main(void)
{
    int N, M;
    int *A, *B, *A2, *B2;
    char c;
    
    int i, j;
    int Ai, Bi;
    long long int cost;
    int cans;
    
    
    scanf("%d%c%d", &N, &c, &M);
    
    
    A = (int*)malloc(sizeof(int)*N/2);
    B = (int*)malloc(sizeof(int)*N/2);
    A2 = (int*)malloc(sizeof(int)*N/2);
    B2 = (int*)malloc(sizeof(int)*N/2);
    
    
    scanf("%d%c%d", &A[0], &c, &B[0]);
    
    if(N > 1)
        scanf("%d%c%d", &A2[0], &c, &B2[0]);
    
    
    for(i=2; i<N; i++)
    {
        scanf("%d%c%d", &Ai, &c, &Bi);
        
        if(i%2 == 0)
        {
            for(j=i/2-1; j>=0; j--)
            {
                if(A[j] < Ai)
                {
                    A[j+1] = A[j];
                    B[j+1] = B[j];
                }
                else
                    break;
            }
            A[j+1] = Ai;
            B[j+1] = Bi;
        }
        else
        {
            for(j=i/2-1; j>=0; j--)
            {
                if(A2[j] < Ai)
                {
                    A2[j+1] = A2[j];
                    B2[j+1] = B2[j];
                }
                else
                    break;
            }
            A2[j+1] = Ai;
            B2[j+1] = Bi;
        }
    }
    
    
    cost = 0;
    cans = M;
    
    i = N/2+N%2-1;
    j = N/2-1;
    
    
    while(cans > 0)
    {
        if(i >= 0 && j >= 0)
        {
            if(A[i] < A2[j])
            {
                if(B[i] < cans)
                {
                    cost += (long long int)A[i]*B[i];
                    cans -= B[i];
                }
                else
                {
                    cost += (long long int)A[i]*cans;
                  
                    break;
                }
                i--;
            }
            else
            {
                if(B2[j] < cans)
                {
                    cost += (long long int)A2[j]*B2[j];
                    cans -= B2[j];
                }
                else
                {
                    cost += (long long int)A2[j]*cans;
                  
                    break;
                }
                j--;
            }
        }
        else if(i >= 0)
        {
            if(B[i] < cans)
            {
                cost += (long long int)A[i]*B[i];
                cans -= B[i];
            }
            else
            {
                cost += (long long int)A[i]*cans;
                
                break;
            }
            i--;
        }
        else
        {
            if(B2[j] < cans)
            {
                cost += (long long int)A2[j]*B2[j];
                cans -= B2[j];
            }
            else
            {
                cost += (long long int)A2[j]*cans;
                
                break;
            }
            j--;
        }
    }
    
    
    printf("%lld\n", cost);
    
    
    free(A);
    free(B);
    free(A2);
    free(B2);
    
    
    //system("pause");
    
    
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};


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

	int n,k;
	cin >> n >> k;
	vi a(n,0);
	rep(i,k){
		int d;
		cin >> d;
		rep(j,d){
			int x;
			cin >> x;
			a[x-1]++;
		}
	}
	int ans = 0;
	rep(i,n){
		if(a[i]==0) ans ++;
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<deque>
#include<cmath>
#define INF 2147483647
using namespace std;
int n,q,N;
deque<int> seg;
void up(int a,int b){
    a += N - 1;
    seg[a] = b;
    while(a > 0){
        a = (a-1)/2;
        seg[a] = min(seg[2*a+1],seg[2*a+2]);
    }
}
int find(int a,int b,int k,int l,int r){//a以上b未満の区間の最小値を求める.現在地k(ノード番号).kの範囲はl以上r未満.
    if(r <= a || b <= l) return INF;
    if(a <= l && r <= b) return seg[k];
    else{
        int o1 = find(a,b,2*k+1,l,(l+r)/2);
        int o2 = find(a,b,2*k+2,(l+r)/2,r);
        return min(o1,o2);
    }
}
int main(void){
cin >> n >> q;
N = int(pow(2,floor(log2(2*n - 1))));//葉の数
seg.assign(2*N-1,INF);    
for(int i = 0; i < q; i++){
    int com,x,y;cin >> com >> x >> y;
    if(com) cout << find(x,y+1,0,0,N) << "\n";        
    else up(x,y);
}
       
}


Measured memory_bytes: 4356
#include <cstdio>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<fstream>

#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
using namespace std;

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
       
    ll i,j,k,p=1,q=1;
    ll n,m,tmp;
    string s[200000];
    string str;
    ll sum=0;
    ll strr[200005];
    cin>>i>>j;
    if(i==1){
        sum+=300000;
    } if(j==1){
                sum+=300000;

    } if(i==2){
                sum+=200000;

    }if(i==3){
        sum+=100000;

    } if(j==2){
                sum+=200000;

    } if(j==3){
                sum+=100000;

    }if(i==1&&j==1) sum+=400000;
    cout<<sum<<endl;

    return 0;
}

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

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int h = fs.nextInt(), a = fs.nextInt();
		int ans = (h + a - 1)/a;
		System.out.println(ans);
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

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

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

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

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll K;
  cin >> K;
  ll N = 50;
  vector<ll> A(N);
  for (int i = 0; i < N; i++)
    A[i] = 49 + K / N;
  K = K % N;
  for (int i = 0; i < K; i++) {
    A[i] += N + 1;
    for (int j = 0; j < N; j++)
      A[j]--;
  }
  cout << N << '\n';
  for (int i = 0; i < N; i++)
    cout << A[i] << (i == N - 1 ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
#define RF(x) freopen(x,"r",stdin)
#define WF(x) freopen(x,"w",stdout)
typedef long long LL;
using namespace std;
typedef pair<LL,LL> PLL;
typedef pair<int,int> PII;
const LL MOD = (LL)1e9+7;
const int SIZE = 2e5+5;
const LL INF = 1LL<<60;
const double eps = 1e-4;
const double PI=3.1415926535897932;

int v1[100009],v2[100009];
string s,t;
char tp[100009];

int main(){
	RS(tp);s=string(tp);
	RS(tp);t=string(tp);
	DRI(qn);
	int n=SZ(s),m=SZ(t);
	REP(i,n){v1[i+1]=v1[i]+1+(s[i]=='A');}
	REP(i,m){v2[i+1]=v2[i]+1+(t[i]=='A');}
	REP(qi,qn){
		DRII(a,b);DRII(c,d);
		if((((v1[b]-v1[a-1]-v2[d]+v2[c-1])%3+3)%3)==0)puts("YES");
		else puts("NO");
	}
}


Measured memory_bytes: 1664
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-9;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int p[110000];
int q[110000];
pair<int,int>z[210000];
int t[110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d%d",p+i,q+i);
	long long ret=inf;
	long long tmp=0;
	for(int i=0;i<a;i++)tmp+=p[i];
	ret=min(ret,tmp);
	tmp=0;
	for(int i=0;i<a;i++)tmp+=q[i];
	ret=min(ret,tmp);
	for(int i=0;i<a;i++){
		z[i*2]=make_pair(p[i],i*2);
		z[i*2+1]=make_pair(q[i],i*2+1);
	}
	std::sort(z,z+a*2);
	tmp=0;
	int ma=0;
	for(int i=0;i<a;i++){
		tmp+=z[i].first;
		t[z[i].second/2]++;
		ma=max(ma,t[z[i].second/2]);
	}
	if(ma==1){
		for(int i=0;i<a;i++){
			long long cur=tmp-z[i].first;
			for(int j=a;j<a*2;j++){
				if(z[j].second/2!=z[i].second/2){
					cur+=z[j].first;
					break;
				}
			}
			ret=min(ret,cur);
		}
	}else ret=min(ret,tmp);
	printf("%lld\n",ret);
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll x;cin>>x;
  vi yaku;
  for(ll i=1;i<=sqrt(x);i++){
    if(x%i == 0){
      if(x/i == i)yaku.pb(i);
      else{
	yaku.pb(x/i);
	yaku.pb(i);
      }
    }
  }
  for(auto a:yaku){
    for(ll i=-1111;i <= 1111; i++){
      ll A = i+a,B = i;
      if(A*A*A*A+B*B*B*B+A*A*A*B+A*A*B*B+A*B*B*B == x/(a)){
	cout<<A<<" "<<B<<endl;
	return 0;
      }      
    }
  }
  return 0;
}


Measured memory_bytes: 3640
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)

MOD = 1000000007  # type: int

def solve(S: str):
    N = len(S)
    dp = [[0] * 13 for _ in range(N + 1)]
    dp[0][0] = 1
    for i in range(N):
        for j in range(13):
            if S[i] == '?':
                for k in range(10):
                    nex = (j * 10 + k) % 13
                    dp[i + 1][nex] += dp[i][j]
                    dp[i + 1][nex] %= MOD
            else:
                k = int(S[i])
                nex = (j * 10 + k) % 13
                dp[i + 1][nex] += dp[i][j]
                dp[i + 1][nex] %= MOD
    ret = dp[N][5]
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61904
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int x[] = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = Integer.parseInt(sc.next());
        }
        sc.close();
        int y[] = x.clone();
        Arrays.sort(y);
        int m1 = y[n / 2 - 1];
        int m2 = y[n / 2];
        if (m1 == m2) {
            for (int i = 0; i < n; i++) {
                System.out.println(m1);
            }
            return;
        }
        for (int i = 0; i < n; i++) {
            if (x[i] <= m1) {
                System.out.println(m2);
            } else {
                System.out.println(m1);
            }
        }
    }
}

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

void solve()
{
    int n;
    cin >> n;
    int ac = 0, wa = 0, tle = 0, re = 0;

    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        if(s == "AC") ac++;
        else if(s == "WA") wa++;
        else if(s == "TLE") tle++;
        else if(s == "RE") re++;
    }

    cout << "AC" << " x " << ac << endl;
    cout << "WA" << " x " << wa << endl;
    cout << "TLE" << " x " << tle << endl;
    cout << "RE" << " x " << re << endl;
}


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


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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for(int i = 0; i < n; i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end(), greater<int>());
  int ans = 0;
  for(int i = 0; i < k; i++){
    ans += v[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
key=[]
for _ in range(m):
  a,b=map(int,input().split())
  c=list(map(int,input().split()))
  bi=0
  for i in c:
    bi+=2**(i-1)
  key.append([a,bi])
dp=[10**10]*(2**n)
dp[0]=0
for k in key:
  for b in range(2**n):
    dp[b|k[1]]=min(dp[b|k[1]],dp[b]+k[0])
if dp[-1]==10**10:
  print(-1)
else:
  print(dp[-1])

Measured memory_bytes: 9276
#include <stdio.h>

int main() {
	int count;
	int values[200000] = { 0 };
	int maxV, minV;
	int i;

	scanf("%d", &count);

	for (i = 0; i < count; i++) {
		scanf("%d", &values[i]);
	}

	maxV = -1000000000;
	minV = values[0];
	for (i = 1; i < count; i++) {
		maxV = values[i] - minV > maxV ? values[i] - minV : maxV;
		minV = values[i] < minV ? values[i] : minV;
	}

	printf("%d\n", maxV);

	return 0;
}

Measured memory_bytes: 1388
#include <iostream>
#include <cstdlib>
#include <string>
#include <typeinfo>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
static const int N = 100;

int main(){
    int n,p[N+1],m[N+1][N+1];
    cin >> n;
    for(int i = 1; i <= n; i++)cin >> p[i - 1] >> p[i];
    for(int i = 1; i <= n; i++)m[i][i] = 0;
    for(int l = 2; l <= n; l++){
        for(int i = 1; i <= n - l + 1; i++){
            int j = i + l - 1;
            m[i][j] = (1 << 21);
            for(int k = i; k <= j - 1; k++){
                m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1]* p[k] * p[j]);
            }
        }
    }
    cout << m[1][n] << endl;    
    
    return 0;
}








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

import static java.lang.System.in;

public class Main {
    static int n;
    static int[] A;
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        A = new int[n];
        for(int i=0;i<n;i++) A[i] = sc.nextInt();
        Arrays.sort(A);
        HashMap<Integer,Integer> map = new HashMap<>();
        int[] dic = new int[31];
        dic[0] = 1;
        for(int i=1;i<=30;i++) dic[i] = dic[i-1]*2;
        for(int w:A){
            map.put(w,map.getOrDefault(w,0)+1);
        }
        HashSet<Integer> used = new HashSet<>();
        int ans = 0;
        for(int i=n-1;i>=0;i--){
            if(!used.add(A[i])) continue;
            int idx = Arrays.binarySearch(dic,A[i]);
            if(idx>=0){
                int cur = map.get(A[i]);
                ans += cur/2;
            } else{
                idx= -(idx+1);
                int target = dic[idx];
                if(!map.containsKey(target-A[i])) continue;
                int cur = Math.min(map.get(target-A[i]),map.get(A[i]));
                ans += cur;
                map.put(target-A[i],map.get(target-A[i])-cur);
                map.put(A[i],map.get(A[i])-cur);
            }
        }
        PrintWriter out = new PrintWriter(System.out);
        out.println(ans);
        out.flush();
    }
}


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

long long int N, T, ans = 1000000000, c, t;

int main(){
    scanf("%lld%lld", &N, &T);
    for(int i = 0; i < N; ++i){
        scanf("%lld%lld", &c, &t);
        if(t <= T) ans = min(ans, c);
    }
    if(ans < 10000)printf("%lld\n", ans);
    else puts("TLE");
    return 0;
}


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

int main() {
	int m,d,ans=0;
	cin >> m >> d;
	for(int i=1;i<=m;i++){
		for(int j=1;j<=d;j++){
			int a = j/10, b = j%10;
			if(a > 1 && b > 1 && i == a*b){
				//cout << i << '-' << j << '\n';
				ans++;
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n; cin >> n;
  vector<ll> a(n);
  vector<ll> p = {0};
  rep(i,n){
    cin >> a[i];
    p.push_back(p.back()+a[i]);
  }
  
  ll ans = 1LL << 60;
  vector<ll> diff(4);
  ll l=1, r=3;
  
  for(int i=2;i<=n;i++){
    while(l<i && abs(p[l]-(p[i]-p[l])) >= abs(p[l+1]-(p[i]-p[l+1]))) l++;
    while(r<n && abs((p[r]-p[i])-(p[n]-p[r])) >= abs((p[r+1]-p[i])-(p[n]-p[r+1]))) r++;
    
    diff[0]=p[l];
    diff[1]=p[i]-p[l];
    diff[2]=p[r]-p[i];
    diff[3]=p[n]-p[r];
    
    sort(diff.begin(),diff.end());
    ans = min(ans,diff[3]-diff[0]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3956