akhauriyash/Code-Regression huggingface dataset:
#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;
typedef double D;
typedef long double LD;
typedef long long LL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> opset;
#define SZ(X) ((int)X.size())
#define ALL(I) I.begin(), I.end()
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define eps 1e-12
#define INF 1000000007
#define MXN 200005
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
const LL mod = INF;

char s[MXN];
int n;
LL cnt[30], ans;

int main(){
	scanf("%d%s", &n, s);
	for(int i = 0; i < 26; i ++) cnt[i] = 1;
	for(int i = 0; i < n; i ++){
		LL c = 1;
		for(int j = 0; j < 26; j ++){
			if(j == s[i] - 'a') continue;
			c = c * cnt[j] % mod;
		}
		ans = (ans + c) % mod;
		cnt[s[i] - 'a'] ++;
	}
	printf("%lld\n", ans);
}



Measured memory_bytes: 384
import math

n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

##xのbit数
bit_num = math.floor(math.log2(max(max(a),k)))+1

###num_oneはAの２進数の各桁の1の数
num_one = []
for i in range(bit_num):
  ###各Aの各桁が1かどうか
  num_one_tmp = 0
  for j in a:
    num_one_tmp += (j >> i) & 1
  num_one.append(num_one_tmp)
#print(num_one)
  
if k == 0:
  bit_k = 1
else:
  bit_k = math.floor(math.log2(k))+1

###下からbit_k番目のbitを0にしたとき、下からbit_k-1番目のbitの0,1に関係なくk以下になる
###下からbit_k番目のbitを1にしたとき、
###下からbit_k-1番目のbitの0しか取れない場合は0を、１が取れる場合はbit_k番目と同じ
###以上より、kの最上位bitから順に探索し、0,1ともに取れる場合は、
###0にした場合はそれ以下の桁でansの最大化を
###１にした場合はそれ以下の桁で0,1ともに取れる桁まで進み、同様の議論を行う

###まずbit_kより上の処理
constant_ans = 0
for i in range(bit_k,bit_num):
  constant_ans += num_one[i] * 2**i

ans = 0

###bit_k以下の処理
for i in range(bit_k)[::-1]:
  
  ###0しか取れない場合
  if 2**i > k:
    constant_ans += num_one[i] * 2**i
  
  ###0,1取れる場合
  else:
    ###0を取る場合
    variant_ans = num_one[i] * 2**i
    ###i-1桁のbitは自由だから最大化する
    for j in range(i):
      ###１の数が半分より多いなら、xは0をとり、xorのあとの1の数はnum_oneに等しい
      if num_one[j] >= (n+1)//2:
        variant_ans += num_one[j] * 2**j
      ###0の数が半分より多いなら、xは1をとり、xorのあとの1の数はn-num_oneに等しい
      else:
        variant_ans += (n-num_one[j]) * 2**j
    ans = max(ans,constant_ans+variant_ans)

    ###1をとる場合
    constant_ans += (n-num_one[i]) * 2**i
    k -= 2**i
  #print(k)
  #print(constant_ans)
  
ans = max(ans,constant_ans)
print(ans)

Measured memory_bytes: 14748
n,m = map(int,input().split())
if n == 1 and m == 1:
  print('1')
elif n == 1 and 2 <= m:
  print(m-2)
elif m == 1 and 2 <= n:
  print(n-2)
elif n == 2 or m == 2:
  print('0')
else:
  print((n-2)*(m-2))

Measured memory_bytes: 3060
N = int(input())
S = input()
s1 = list()
s2 = list()
if N % 2 == 1:
    print("No")
else:
    for i in range(N//2):
        s1.append(S[i])
    for i in range(N//2,N):
        s2.append(S[i])
    if s1 == s2:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main()
{
	int n=0;cin>>n;
	int a=0,b=0,A=0,B=0;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		if(a>A){A=a,B=b;}
	}
	cout<<A+B<<endl;
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
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;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  int N; cin >> N;
  cout << ceil(N / 2.0) - 1 << endl;
}

Measured memory_bytes: 3748
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int dp[110][110], A[110], B[110];
 
signed main() {
    int N; cin >> N;
    fill(dp[0], dp[N+1], INF);
    for(int i=0; i<N; i++) {
        cin >> A[i] >> B[i];
        dp[i][i+1] = 0;
    }

    for(int d=1; d<=N; d++) {
        for(int l=0; l<N-d+1; l++) {
            int r = l + d;
            for(int k=l+1; k<r; k++) {
                int cost = A[l] * B[k-1] * A[k] * B[r-1];
                chmin(dp[l][r], dp[l][k] + dp[k][r] + cost);
            }
        }
    }
    cout << dp[0][N] << endl;
    return 0;
}


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

int main(){
ll n, w; cin>>n>>w;
ll wt[n], val[n];
ll i,j;
ll V=0;
for(i=0;i<n;i++){
    cin>>wt[i]>>val[i];
    V+=val[i];
}
vector<ll>dp(100005, INT_MAX);
dp[0]=0;
for(i=0;i<n;i++){
    for(j=V;j>=0;j--){
        if(j-val[i]>=0){
            dp[j]=min(dp[j], dp[j-val[i]]+wt[i]);
        }
    }
}
for(i=V;i>=0;i--){
    if(dp[i]<=w){
        cout<<i<<endl;
        break;
    }
}

    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int x = a + b;
        int y = a - b;
        int z = a * b;
        int out = 0;
        if(x >= y && x >= z){
            out = x;
        }else if(y >= z && y >= x){
            out = y;
        }else if(z >= x && z >= y){
            out = z;
        }
        System.out.println(out);
    }
}

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

int main(){
  string s,t;
  cin >> s >> t;
  int lens = s.size();
  int lent = t.size();

  int maxlen = 0;
  for (int i = 0; i+lent <= lens; i++)
  {
    int cnt = 0;
    for (int j = 0; j < lent; j++)
    {
      if(s[i+j]==t[j]) cnt++;
    }
    maxlen = max(maxlen, cnt);    
  }
  cout << lent-maxlen << endl;
}

Measured memory_bytes: 3572
#include <iostream>

using namespace std;
using ll = long long;

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

int main() {
  ll N, P;
  if (scanf("%lld%lld", &N, &P)<1);

  if (N == 1) {
    printf("%lld\n", P);
    return 0;
  }
  int ans = 1;
  for (ll i = 2; i * i <= P; ++i) {
    if (P % i == 0) {
      int count = 1;
      ll p = P/i;
      while (p % i == 0) {
        p /= i;
        ++count;
      }
      if (count >= N)
        ans = i;
    }
  }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
ll power(ll a,ll b)
{
    ll res =1;
    while(b)
    {
        if(b&1) res = (res%mod*a%mod)%mod;
        b/=2;
        a = (a%mod*a%mod)%mod;
    }
    return res;
}
ll sieve[1000005];
void pre()
{
    sieve[0]=1;
    sieve[1]=1;
    for(int i=2;i<1000005;i++)
    {
        if(sieve[i]==0)
        for(int j=2*i;j<1000005;j+=i)
        {
            sieve[j]=1;
        }
    }
}
signed main()
{
    
    senky_bansal
    IIIT_ALLAHABAD
      
    ll a,b,c;
  cin>>a>>b>>c;
  ll p = max(a-b,0LL);
  cout<<max(0LL,c-p)<<endl;
    
    
    
    
    
    
}








Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    long long num[300000];
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> num[i];
    }
    long long res[200000] = {};
    long long tmp = 0;
    int l=0;
    int r=0;
    while(true){
        // cout << l << " " << r <<endl;
        if(r < n && tmp + num[r] == (tmp ^ num[r])){
            tmp = (tmp ^ num[r]);
            r++;
        }else{
            if(l>n-1)break;
            tmp -= num[l];
            res[l] = r - l;
            // cout << res[l] << endl;
            l++;
        }
    }
    long long ans = 0;
    for(int i = 0; i < n; i++){
        ans += res[i];
    }
    cout << ans << endl;
    // cout << (2 ^ 5) << endl;
}

Measured memory_bytes: 4096
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    var N = parseInt(input[0][0], 10);
    var M = parseInt(input[0][1], 10);
    var K = parseInt(input[0][2], 10);
    var C = 998244353;
    var C2 = 1e+5;
    v = nCr_amari(N - 1, K, C, C2).reverse();
    tmp = fastRuijoR(M - 1, N - K - 1, C, C2);
    var ans = 0;
    for  (var x of v){
        ans += kakeruR(kakeruR(tmp, x, C, C2), M, C, C2); 
        ans %= C;
        tmp = kakeruR(tmp, M - 1, C, C2);
    }
    console.log(ans);
}

function kakeruR(a, b, C, C2){
    var tmpQ, tmpR, ans;
    tmpQ = (b / C2 | 0);
    tmpR = b - (tmpQ * C2);
    ans = (a * tmpQ % C) * C2 % C + (a * tmpR);
    ans %= C;
    return ans;
}

function nCr_amari(MAX, k, MOD, C2) { //return [maxC0, maxC1, ..., maxCk]
    // 前処理
    var v_ans = [ ];
    var fac, finv, inv;
    fac = [1,1];
    finv = [1,1];
    inv = [0,1];
    for (var i = 2; i <= MAX; i++){
        fac.push(fac[i - 1] * i % MOD);
        inv.push(MOD - kakeruR(inv[MOD%i], (MOD / i | 0), MOD, C2) % MOD);
        finv.push(kakeruR(finv[i - 1],inv[i] ,MOD, C2));
    }
    //二項係数計算
    for (var i = 0; i <= k; i++){
    v_ans.push(kakeruR(kakeruR(fac[MAX] , finv[MAX - i],MOD, C2), finv[i], MOD, C2));
    }
    return v_ans;
}


function fastRuijoR(a, b, C, C2){
    var ans = 1;
    var binary = b.toString(2);
    var l = binary.length;
    var tmp = a;
    for (var i = 0; i < l; i++){
        if (binary.substr((i + 1) * -1, 1) === '1') ans = kakeruR(ans, tmp, C, C2);
    tmp = kakeruR(tmp, tmp, C, C2);
    }
    return ans;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8")); 

Measured memory_bytes: 55232
#include <stdio.h>
int main(void){
  int n,m;
  int i,j;
  int acc=0;
  int sum=0;
  double pum;
  int num[99];
  scanf("%d", &n);
  scanf("%d", &m);
  for (i=0; i<n; i++){
    scanf("%d", &num[i]);
    sum=sum+num[i];
  }
  pum=(double)sum/(m*4);
  for (j=0;j<n;j++){
    if(num[j]>=pum){
      acc++;
    }
  }
  if (acc<m){
    printf("No");
  }
  else
    printf("Yes");
  return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N, L; cin >> N >> L;
    int sum = 0;
    for (int i = 1; i <= N; ++i){
        sum += L + i - 1;
    }

    int r = 1LL << 29;

    for (int i = 1; i <= N; ++i){
        int tmp = 0;
        for (int j = 1; j <= N; ++j) {
            if (i == j) continue;
            tmp +=  L + j - 1;
        }
        if (abs(sum - tmp) < abs(sum - r)) r = tmp;
    }
    cout << r << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int M,D;cin >> M >> D;
  int count = 0;
  repp(m,1,M+1){
    repp(d,1,D+1){
      int d1 = d%10;
      int d10 = d/10;
      if(d1>=2 && d10 >= 2 && m == d1*d10) ++count;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdio>
#include <cmath>

using namespace std;

int main(){
	int a,b; cin>>a>>b;
	if(0<a && 0<b){
		cout<<"Positive"<<endl;
	}
	else if(a<=0 && 0<=b){
		cout<<"Zero"<<endl;
	}
	else{
		if(abs(a-b)%2==0){
			cout<<"Negative"<<endl;
		}
		else{
			cout<<"Positive"<<endl;
		}
	}
	return 0;
}

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

using namespace std;

int main() {
	int D, N;
	cin >> D >> N;
	if (N == 100) {
		N++;
	}

	for (int i = 1; i <= D; i++) {
		N *= 100;
	}

	cout << N << endl;

	return 0;
}

Measured memory_bytes: 256
a,b = map( int, input().split() )

ret = 0;

if a > b:
  if a % b == 0:
    ret = a + b
  else:
    ret = a - b
else:
  if b % a == 0:
    ret = b + a
  else:
    ret = b - a
    
    
print(ret )

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define M 1000000007  // 10^9+7

ld coins(ld arr[], int n, int heads, int i, vector<vector<ld>> &dp){
    if(i == n)
        return heads > n/2;
    if(dp[i][heads] != -1)
        return dp[i][heads];
    ld op1 = coins(arr, n, heads+1, i+1, dp)*arr[i];
    ld op2 = coins(arr, n, heads, i+1, dp)*(1-arr[i]);
    ld ans = op1 + op2;
    dp[i][heads] = ans;
    return ans;
}

int main()
{
 int n;
 cin>>n;
 ld arr[n];
 for(int i=0; i<n; i++)
    cin>>arr[i];
 vector<vector<ld>> dp(n, vector<ld>(n+1, -1));
 ld ans = coins(arr, n, 0, 0, dp);
 cout<<fixed<<setprecision(9)<<ans;
 return 0;
}



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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題
int main() {
    string o, e;
    cin >> o >> e;
    if (o.size() == e.size()) {
        rep(i, o.size()) {
            cout << o[i] << e[i];
        }
    } else {
        rep(i, e.size()) {

            cout << o[i] << e[i];
        }
        cout<<o[o.size()-1];
    }

    return 0;
}


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

int main()
{
	int M, N, K;
	cin >> M >> N >> K;
	vector<vector<vector<int>>> x(3, vector<vector<int>>(M + 1, vector<int>(N + 1)));
	for (int i = 1; i <= M; i++) {
		for (int j = 1; j <= N; j++) {
			char c;
			cin >> c;
			if (c == 'J') {
				x[0][i][j] += 1;
			}
			else if (c == 'O') {
				x[1][i][j] += 1;
			}
			else {
				x[2][i][j] += 1;
			}
		}
	}
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j <= M; j++) {
			for (int k = 1; k <= N; k++) {
				x[i][j][k] += x[i][j][k - 1];
			}
		}
		for (int k = 0; k <= N; k++) {
			for (int j = 1; j <= M; j++) {
				x[i][j][k] += x[i][j - 1][k];
			}
		}
	}
	while (K--) {
		int a, b, c, d;
		cin >> a >> b >> c >> d; a--, b--;
		for (int i = 0; i < 3; i++) {
			cout << (x[i][c][d] - x[i][a][d] - x[i][c][b] + x[i][a][b]) << " \n"[i + 1 == 3];
		}
	}
	return 0;
}



Measured memory_bytes: 18428
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
 
constexpr ll MOD = 1000000007;
 
#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " (" << x.first << " : " << x.second << ")" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "["; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "(" << obj.first << ", " << obj.second << ")"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print_sim_py(void) {cout << endl;}
template <class Head> void print_sim_py(Head&& head) {cout << head;print_sim_py();}
template <class Head, class... Tail> void print_sim_py(Head&& head, Tail&&... tail) {cout << head << " ";print_sim_py(forward<Tail>(tail)...);}
 
#define print(...) print_sim_py(__VA_ARGS__);
#else
#define print(...);
#endif


int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    ll n;
    ll ans;
    ll n10,n9,n8;
    n10=10;
    n9 = 9;
    n8 = 8;

    cin >> n;

    if(n<=1){
        cout << 0 << endl;
        return 0;
    }

    for(ll i=0; i<n-1; i++){
        n10 = n10 * 10 % MOD;
        n9 = n9 * 9 % MOD;
        n8 = n8 * 8 % MOD;
    }

    ans = (n10 - (n9 * 2 % MOD))%MOD;
    if(ans < 0) ans += MOD;
    ans = (ans + n8)%MOD;
    
    cout << ans << endl;
 
    return 0;
}



Measured memory_bytes: 3652
use std::io;
use std::io::Read;

fn main() {
    let mut stdin = io::stdin();
    let mut lines = String::new();
    let _ = stdin.read_to_string(&mut lines);
    let vec = lines.lines().collect::<Vec<&str>>();
    let firstline = vec[0].split(' ').collect::<Vec<&str>>();
    let n :usize = firstline[0].trim().parse().unwrap();
    let m :usize = firstline[1].trim().parse().unwrap();
    let mkono1 :u64 = (1 << m) - 1;
    let mut a :Vec<u64> = Vec::new();
    for i in 0..n {
        let mut thisline :u64 = 0;
        for (j, c) in vec[i+1].trim().chars().enumerate() {
            match c {
                '#' => {thisline = thisline + (1 << j);},
                _ => {},
            }
        }
        a.push(thisline);
    }
    let a = a;
    let mut b :Vec<u64> = Vec::new();
    for i in 0..m {
        let mut thisline :u64 = 0;
        for (j, c) in vec[i+n+1].trim().chars().enumerate() {
            match c {
                '#' => {thisline = thisline + (1 << j);},
                _ => {},
            }
        }
        b.push(thisline);
    }
    let b = b;
    'tate: for i in 0..(n-m+1) {
        'yoko: for j in 0..(n-m+1) {
            'chekku: for k in 0..m {
                let bline = b[k];
                let aline = (a[k+i] >> j) & mkono1;
                if aline ^ bline != 0 {continue 'yoko;}
            }
            println!("Yes");
            return;
        }
    }
    println!("No");
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std; 
using ll = long long;
#define int ll
#define MOD ll(1e9+7)
vector<vector<ll>> memo(1e5+5, vector<ll> (2, -1));
ll sol = 1;
ll dp(vector<vector<int>> &g, int v, int p, int b){

	if(memo[v][b] != -1)
		return memo[v][b];
	memo[v][b] = 1;

	int f = true;
	for(int e : g[v]){  
		
		if(e != p){
			ll tmp = 1;
			f = false;
			tmp = (dp(g, e, v, 0)) % MOD;
			if(!b)
				tmp = (tmp + dp(g, e, v, 1)) % MOD;
			memo[v][b] = (memo[v][b] * tmp) % MOD;
		}
	}
	if(f)
		return memo[v][b] = 1;
	return memo[v][b];
}

signed main() { 
	cin.tie(0);
	cin.sync_with_stdio();
	int n; 
	cin>>n;
	vector<vector<int>> g(n);
	for(int i = 0; i <n-1; i++){
		int a, b;
		cin>>a>>b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	
	}
	cout<<(dp(g, 0, -1, 0)+dp(g, 0, -1, 1)) % MOD;
}


Measured memory_bytes: 20864
// https://atcoder.jp/contests/abc055/tasks/abc055_b
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, n) for (int i = 0; i < n; i++)
#define EACH(i, n) for (auto &i: n)
typedef long long ll;

int main() {
  ll n;

  cin >> n;

  ll p = 1;
  for (ll i = 1; i <= n; i++) {
    p = (p * i) % 1000000007ll;
  }
  cout << p << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,j,a,b,c,d,flg,cnt;
	flg=0;
	cnt=0;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	for(i=a;i<=b;i++){
		flg=1;
		for(j=c;j<=d;j++){
			if(i==j){
				flg=2;
				cnt++;
			}
		}
	}
	if(cnt==0){
		printf("%d\n",cnt);
	}
	else{
		printf("%d\n",cnt-1);
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

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

	int n = sc.nextInt();
	while(n!=0){
	    double[] x = new double[2];
	    double[] y = new double[2];
	    double[] r = new double[2];
	    for(int i=0; i<2; i++){
		x[i] = sc.nextDouble();
		y[i] = sc.nextDouble();
		r[i] = sc.nextDouble();
	    }

	    double dist = (x[0]-x[1])*(x[0]-x[1])+(y[0]-y[1])*(y[0]-y[1]);
	    double sr = (r[0]+r[1])*(r[0]+r[1]);
	    double dr = (r[0]-r[1])*(r[0]-r[1]);

	    int ans = 0;
	    if(dist>sr){ans = 0;}
	    else if(dist<sr && dr<dist){ans = 1;}
	    else if(dr>dist){
		if(r[0]>r[1]){ans = 2;}
		else {ans = -2;}
	    }
	    else{ans = 1;}
	    
	    System.out.println(ans);
	    n--;
	}
    }
}

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

using namespace std;

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

    string s;
    cin >> s;

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

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


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define LL long long
#define maxn 200010
#define mod 1000000007
using namespace std;
int a[maxn];
LL ans=1,x,y;
int main(){
	int n,k,i,b,l,r;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	if(a[1]>=0){
		for(i=n;i>=n-k+1;i--)ans=ans*a[i]%mod;
	}else if(a[n]<0){
		if(k&1){
			for(i=n;i>=n-k+1;i--)ans=ans*a[i]%mod;
			ans=(ans%mod+mod)%mod;
		}else{
			for(i=1;i<=k;i++)ans=ans*a[i]%mod;
		}
	}else{
		int cnt1=0,cnt2=0;
		for(i=1;i<=n;i++)
			if(a[i]<0)cnt1++;
			else break;
		cnt2=n-cnt1;
		if(cnt1/2*2+cnt2<k){
			for(i=1;i<=n;i++)ans=ans*a[i]%mod;
			ans=(ans%mod+mod)%mod;
		}else{
			if(k&1)
				ans=a[n],n--,k--;
			l=1,r=n;
			while(k){
				x=(LL)a[l]*a[l+1],y=(LL)a[r]*a[r-1];
				if(x>y)x%=mod,ans=ans*x%mod,l+=2;
				else y%=mod,ans=ans*y%mod,r-=2;
				k-=2;
			}
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2508
def main():
    n, m = map(int, input().split())
    num_list = [int(input()) for _ in range(m)]

    dp = [0] * (n+1)
    dp[0] = 1
    
    for num in num_list:
        dp[num] = -1

    if dp[1] != -1:
        dp[1] = 1
    else:
        dp[1] = 0

    for i in range(2,n+1):
        if dp[i] == -1:
            dp[i] = 0
            continue
        dp[i] = dp[i - 1] + dp[i - 2]

    print(dp[n]%1000000007)

if __name__ == '__main__':
    main()

Measured memory_bytes: 471288
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

typedef pair<int, int> P;

vector<pair<int,int> > G1[100001];
vector<pair<int,int> > G2[100001];

int x=1e15;

vector<int> dist1(1e5+1,1e18);

void dijkstra1(int s){
  bool f=true;
  priority_queue<P,vector<P>,greater<P> > que;
  dist1[s]=0;
  que.push(P(0,s));
  while(!que.empty()){
    P p=que.top();
    que.pop();
    int v=p.second;
    int d=p.first;
    if(dist1[v]<d)continue;
    for(int i=0;i<G1[v].size();i++){
      int d2=d+G1[v][i].second;
      if(dist1[G1[v][i].first]>d2){
        dist1[G1[v][i].first]=d2;
        que.push(P(dist1[G1[v][i].first],G1[v][i].first));
      }
    }
  }
}


vector<int> dist2(1e5+1,1e18);

void dijkstra2(int s){
  bool f=true;
  priority_queue<P,vector<P>,greater<P> > que;
  dist2[s]=0;
  que.push(P(0,s));
  while(!que.empty()){
    P p=que.top();
    que.pop();
    int v=p.second;
    int d=p.first;
    if(dist2[v]<d)continue;
    for(int i=0;i<G2[v].size();i++){
      int d2=d+G2[v][i].second;
      if(dist2[G2[v][i].first]>d2){
        dist2[G2[v][i].first]=d2;
        que.push(P(dist2[G2[v][i].first],G2[v][i].first));
      }
    }
  }
}

signed main(){
  int n,m,s,t;
  cin>>n>>m>>s>>t;
  s--;
  t--;
  for(int i=0;i<m;i++){
    int u,v,a,b;
    cin>>u>>v>>a>>b;
    u--;
    v--;
    G1[u].push_back(make_pair(v,a));
    G1[v].push_back(make_pair(u,a));
    G2[u].push_back(make_pair(v,b));
    G2[v].push_back(make_pair(u,b));
  }
  dijkstra1(s);
  dijkstra2(t);
  vector<int> ans(n);
  ans[n-1]=dist1[n-1]+dist2[n-1];
  for(int i=n-2;i>=0;i--){
    ans[i]=min(dist1[i]+dist2[i],ans[i+1]);
  }
  for(int i=0;i<n;i++){
    cout<<x-ans[i]<<endl;
  }
}


Measured memory_bytes: 20792
n,k=map(int,input().split())
add=list(map(int,input().split()))

ans=float("inf")
for l in range(n-k+1):
    r=l+k-1
    ans=min(ans,
            abs(add[l])+abs(add[l]-add[r]),
            abs(add[r])+abs(add[r]-add[l])
            )

#探索する量が少ないので全探索により答えを求めることができる

print(ans)

Measured memory_bytes: 62576
#include<cstdio>
int main(){
	int n,x;scanf("%d%d",&n,&x);
	long long ans=0,sum,pre,w;
	scanf("%lld",&pre);
	if(pre>x)ans+=pre-x,pre=x;
	for(int i=1;i<n;i++){
		scanf("%lld",&w);
		sum=pre+w;
		if(sum>x){
			ans+=sum-x;
			pre=w-sum+x;
		}
		else pre=w;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
N, K = map(int, input().split())
A = list(map(int, input().split()))

if K == 1:
    for a, b in zip(A[:-1], A[1:]):
        if a < b:
            print("Yes")
        else:
            print("No")
else:
    for i in range(K, N):
        if A[i] > A[i-K]:
            print("Yes")
        else:
            print("No")

Measured memory_bytes: 31548
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(int n;scanf("%d",&n),n;){
		vi a(n);
		rep(i,n)
			scanf("%d",&a[i]);
		int key;
		scanf("%d",&key);
		
		int res=0;
		int left=0,right=n-1;
		while(left<=right){
			res++;
			int center=(left+right)/2;
			if(a[center]<key)
				left=center+1;
			else if(a[center]>key)
				right=center-1;
			else
				break;
		}
		printf("%d\n",res);
	}
	
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  for(int i = 0 ; i < N ; i++) {
    string a;
    cin >> a;
    if(a == "Y") {
      cout << "Four" <<endl;
      break;
    }
    else if(i == N - 1){
        cout << "Three" <<endl;
    }
  }
}

Measured memory_bytes: 3572
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0: break
    
    count = 0
    for a in range(1, n + 1):
        for b in range(a + 1, n + 1):
            if a < b:
                for c in range(b + 1, n + 1):
                    if b < c:
                        ans = a + b + c
                        if ans == x:
                            count += 1
    print(count)


Measured memory_bytes: 5596
N, M = map(int, input().split())
x=[0]*N
y=[0]*N
c=[0]*M
d=[0]*M
ans=[0]*N
for i in range(N):
  x[i],y[i]=map(int,input().split())
for i in range(M):
  c[i],d[i]=map(int, input().split())

for i in range(N):
  dmin=10**9
  for j in range(M):
    dcurr=abs(x[i]-c[j])+abs(y[i]-d[j])
    if dcurr<dmin:
      ans[i]=j+1
      dmin=dcurr

for n in ans:
  print(n)

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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(auto& e : a) cin >> e;
	int counter = -1;
	bool isDividable = true;
	while(isDividable){
		for(auto& e : a){
			if( e == 0 ) isDividable = false;
			if( e%2 == 0 ) e /= 2;
			else isDividable = false;
		}
		counter++;
	}
	cout << counter << endl;
	return 0;
}


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

int main(){
    int n; 
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    int cnt = 0;
    for(int i = 0; i < n-2; i++){
        for(int j = i+1; j < n-1; j++){
            for(int k = j+1; k < n; k++){
                ll a = l[i], b = l[j], c = l[k];
                if(a == b || b == c || c == a) continue;
                if(a+b > c && b+c > a && c+a > b) cnt++;
            }
        }
    }
    cout << cnt << endl;

    return 0; 
}

Measured memory_bytes: 3592
#include <iostream>
#include <ios>
#include <vector>
using namespace std;
#define FOR(i, s, e) for(int i = s; i < e; ++i)
typedef vector<long> vec;

int Partition(vec& vA, int p, int r)
{
	int x = vA[r];
	int i = p - 1;
	for (int j = p; j < r; ++j){
		if (vA[j] <= x){
			++i;
			swap(vA[i], vA[j]);
		}
	}
	swap(vA[i + 1], vA[r]);
	return i + 1;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, v;
	cin >> n;
	vec vA(n, 0);
	FOR(i, 0, n) cin >> vA[i];
	int x = Partition(vA, 0, n - 1);
	FOR(i, 0, n){
		if (i == x) cout << "[" << vA[i] << "]";
		else cout << vA[i];
		if (i < n - 1)
			cout << " ";
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 1796
import java.util.*;

public class Main {
	static final int MOD = 998244353;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		int sum = 0;
		for (int i = 0; i < N; i++) {
			int x = sc.nextInt();
			a[i] = x;
			sum += x;
		}

		long all_pattern = 1;
		for (int i = 0; i < N; i++) {
			all_pattern *= 3;
			all_pattern %= MOD;
		}
		long[] dp = new long[] { 1 };
		for (int i = 0; i < N; i++) {
			long[] next = new long[dp.length + a[i]];
			for (int j = 0; j < dp.length; j++) {
				next[j] += 2 * dp[j];
				next[j] %= MOD;

				next[j + a[i]] += dp[j];
				next[j + a[i]] %= MOD;
			}
			dp = next;
		}
		long[] dp2 = new long[] { 1 };
		for (int i = 0; i < N; i++) {
			long[] next = new long[dp2.length + a[i]];
			for (int j = 0; j < dp2.length; j++) {
				next[j] += dp2[j];
				next[j] %= MOD;

				next[j + a[i]] += dp2[j];
				next[j + a[i]] %= MOD;
			}
			dp2 = next;
		}
		for (int i = (sum+1)/2; i < dp.length; i++) {
			all_pattern += 3 * (MOD - dp[i]);
			all_pattern %= MOD;
		}
		if (sum % 2 == 0) {
			all_pattern += 3 * dp2[sum/2];
			all_pattern %= MOD;
		}
		System.out.println(all_pattern);
	}
}


Measured memory_bytes: 89680
#include <iostream>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
using namespace std;

int N;

int main(void) {
  cin >> N;

  if(N == 0 || N == 2) cout << 1 << endl;
  else if(N == 1) cout << 2 << endl;
  else cout << 0 << endl;

  return 0;
}

Measured memory_bytes: 3088
#include <stdio.h>

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

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

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

// @@ !! LIM()

string abc("ABC");

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  vector<ll> t(3);
  ll N; cin >> N >> t.at(0) >> t.at(1) >> t.at(2);
  vector<string> s(N);
  for (ll i = 0; i < N; i++) cin >> s.at(i);
  ll tsum = t.at(0) + t.at(1) + t.at(2);
  if (tsum == 0) {
    cout << "No\n";
    return 0;
  }
  vector<char> hand;

  auto take = [&](ll p, ll q) {
    hand.push_back(abc.at(p));
    t.at(p)++;
    t.at(q)--;
  };

  for (ll i = 0; i < N; i++) {
    string cur = s.at(i);
    ll x, y;
    if (cur == "AB") { x = 0; y = 1; }
    else if (cur == "AC") { x = 0; y = 2; }
    else if (cur == "BC") { x = 1; y = 2; }
    else assert(false);
    if (t.at(x) == 0) {
      if (t.at(y) == 0) {
	cout << "No\n";
	return 0;
      }
      take(x, y);
    }else if (t.at(y) == 0) {
      take(y, x);
    }else if (t.at(x) >= 2) {
      take(y, x);
    }else if (t.at(y) >= 2) {
      take(x, y);
    }else { // both one
      if (i+1 == N) {
	take(x, y);
      }else if (s.at(i+1) == cur) {
	take(x, y);
      }else {
	ll p, q;
	if (s.at(i+1) == "AB") { p = 0; q = 1; }
	else if (s.at(i+1) == "AC") { p = 0; q = 2; }
	else if (s.at(i+1) == "BC") { p = 1; q = 2; }
	else assert(false);
	if (x == p || x == q) {
	  take(x, y);
	}else {
	  take(y, x);
	}
      }
    }
    
  }
  cout << "Yes\n";
  for (ll i = 0; i < N; i++) {
    cout << hand.at(i) << "\n";
  }
  

  return 0;
}



Measured memory_bytes: 6676
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

int main(){
    int N,X,T;
    cin>>N>>X>>T;
    int ans;
    if(N%X==0){
        ans=(N/X)*T;
    }else{
        ans=(N/X+1)*T;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

struct Node {
    string str;
    Node *next;
    Node(const string& str, Node *next) : str(str), next(next) { }
};

const int DICT_SIZE = 1000001;
Node* dict[DICT_SIZE];

inline int tohash(const string& str) {
    int result = 0;
    for (int i = 0; i < str.size(); ++i) {
        result = result * 31 + (str[i]);
        result %= DICT_SIZE;
    }
    return result;
}

int main(void) {

    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;

    char command[7];
    string str;
    for (int i = 0; i < n; ++i) {
        cin >> command >> str;
        int hashval = tohash(str);
//        cout << "[hashval] str = " << str 
//             << ", hashval = " << hashval << "\n";
        if (command[0] == 'i') {
            if (dict[hashval]) {
                Node *node = dict[hashval];
                while (node->next) {
                    node = node->next;
                }
                node->next = new Node ( str, NULL );
            }
            else {
                dict[hashval] = new Node ( str, NULL );
            }
        }
        else {
            bool exist = false;
            for (Node *node = dict[hashval]; node != NULL;
                    node = node->next) {
                if (node->str == str) {
                    exist = true;
                    break;
                }
            }
            cout << (exist ? "yes" : "no") << '\n';
        }
    }

    return 0;
}

Measured memory_bytes: 54252
import * as fs from 'fs';

const input: string = fs.readFileSync('/dev/stdin', 'utf8');
const args: string[][] = input.split('\n').map(l => l.split(' '));

const nextNumbers: number[][] = [];
for (let i = 0; i < 10; i++) {
  const tmp: number[] =
    [i + 9, i, i + 1]
      .map(x => x % 10)
      .filter(x => Math.abs(i - x) <= 1)
      .sort((x, y) => x - y);
  nextNumbers.push(tmp);
}

function getLunlun(n: number): number {
  let tmp = n - 1;
  let a: number[][] = [];
  for (let i = 1; i <= 9; i++) a.push([i]);
  if (tmp < a.length) return getNum(a[tmp])

  while (tmp >= a.length) {
    tmp -= a.length;
    let tmpArray: number[][] = [];
    a.forEach(array => {
      const nexts: number[] = nextNumbers[array[array.length - 1]];
      nexts.forEach(x => {
        let array2: number[] = [...array];
        array2.push(x);
        tmpArray.push(array2);
      })
    });
    a = tmpArray;
  }
  return getNum(a[tmp])
}

function getNum(ns: number[]): number {
  return ns.reduce((x, y) => 10 * x + y)
}

const k = parseInt(args[0][0]);
console.log(getLunlun(k));



Measured memory_bytes: 88760
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
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;
}
using namespace std;

int n,maxv;
vector<vector<int>>g;
map<pair<int,int>,int>mp;
vector<int>color;
vector<bool>visited;

void dfs(int v){
    visited[v]=1;
    int cnt=1;
    for(auto x:g[v]){
        if(!visited[x]){
            mp[make_pair(v,x)]=(color[v]+cnt)%maxv!=0?(color[v]+cnt)%maxv:maxv;
            color[x]=mp[make_pair(v,x)];
            cnt++;
            dfs(x);
        }
    }
}

void solve(){
    cin>>n;
    g.resize(n);
    color.resize(n);
    visited.resize(n);
    vector<int>a(n-1),b(n-1);
    rep(i,n-1){
        cin>>a[i]>>b[i];
        a[i]--;b[i]--;
        g[a[i]].pb(b[i]);
        g[b[i]].pb(a[i]);
    }
    maxv=0;
    rep(i,n)chmax(maxv,(int)g[i].size());
    color[0]=0;
    dfs(0);
    cout<<maxv<<"\n";
    rep(i,n-1)cout<<mp[make_pair(a[i],b[i])]<<"\n";
}
 
signed main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
	cout<<fixed<<setprecision(15);
	solve();
	return 0;
}


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

using namespace std;

bool ganhei[100005];

char chooseToWin(char c)
{
    if (c == 'r')
        return 'p';
    if (c == 'p')
        return 's';
    return 'r';
}

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

    int r, s, p;
    cin >> r >> s >> p;

    string t; cin >> t;
    int points = 0;
    for (int i = 0; i < t.size(); i++)
    {
        if (i >= k && t[i] == t[i-k] && ganhei[i-k])
        {
            ganhei[i] = false;
            continue;
        }

        if (t[i] == 'r')
            points += p;
        else if (t[i] == 's')
            points += r;
        else if (t[i] == 'p')
            points += s;

        ganhei[i] = true;
    }

    cout << points << endl;

    return 0;
}


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

int main(){
    typedef long long ll;
    ll n, ans, count=0;
    bool checkF=false, flag=false;
    cin >> n;
    ll H[n] = {}, C[n] = {};

    for(ll i=0;i<n;i++){
        cin >> H[i];
    }

    while(!checkF){
        flag = false;
        for(int i=0;i<n;i++){
            if(flag==true){
                if(C[i]==H[i]){
                    continue;
                }else{
                    flag=false;
                }     
            }
            if(C[i]==H[i]){
                if(i==0){
                    checkF=true;
                    flag=true;
                    continue;
                }
                count++;
              	//cout << "a";
                flag=true;               
            }else{
                checkF=false;
                C[i]++;
            }
          //cout << C[i] << " ";
        }
      	//cout << endl;
      	if(!flag){
            count++;
            //cout << "b";
        }
    }
    cout << count << endl;
}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

const int MAXN = 100010;
const int MAXP = 10000000;
const u64 MOD = 1000000007;
const f80 MI = f80(1)/MOD;
const int INF = 1000000010;

ll n, p;

int main()
{
	
	cin >> n >> p;
	ll ans = 1;
	for (ll i = 2; i*i <= p; ++ i)
	{
		if (p%i == 0)
		{
			int c = 0;
			while (p%i == 0)
			{
				p /= i;
				c ++;
			}
			c /= n;
			while (c --) ans *= i;
		}
	}
	if (p > 1)
	{
		int c = 1/n;
		while (c --) ans *= p;
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import *

def bfs():
    q = deque([0])
    dist = [-1]*N
    dist[0] = 0
    
    while q:
        v = q.popleft()
        
        for nv in G[v]:
            if dist[nv]==-1:
                dist[nv] = dist[v]+1
                q.append(nv)
    
    return dist

N = int(input())
G = [[] for _ in range(N)]

for _ in range(N-1):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

c = list(map(int, input().split()))
c.sort(reverse=True)
dist = bfs()
idist = [(i, dist[i]) for i in range(N)]
idist.sort(key=lambda t: t[1])
ans = [-1]*N

for i in range(N):
    ans[idist[i][0]] = c[i]

print(sum(c[1:]))
print(*ans)

Measured memory_bytes: 76392
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm> // sort
#include <math.h>

#define DEBUG 0

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
                    //999999997000000003
                    //1000000000000000000

using namespace std;

//貪欲で良い気がする

int main(){
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    int N, M;
    cin >> N >> M;
    ll res = 0;
    string s;
    cin >> s;

    vector <ll> a;

    //dp: iに到達できるまでのルーレットを回した回数
    //辞書順で最小であるものを出力せねばならない
    // -> 後ろから貪欲に見ていけばよさそう
    ll dp[N+1];

    REP(i, N+1)dp[i] = INF;
    REP(i, N + 1)
    {
        if(s[i] == '1')
        {
            dp[i] = -1;
        }
    }
    dp[N+1] = 0;
    int pos = N;

    while(true)
    {
        if(pos - M <= 0)
        {
            a.push_back(pos);
            break;
        }
        bool ok = false;
        for(int i = M; i > 0; --i)
        {
            if(dp[pos - i] != -1)
            {
                dp[pos - i] = dp[pos] + 1;
                ok = true;
                pos = pos - i;
                a.push_back(i);
                break;
            }
        }
        if(!ok)
        {
            cout << -1 << endl;
            return 0;
        }
    }

    reverse(a.begin(), a.end());

    for(auto t:a)
    {
        cout << t << " ";
    }
    cout << endl;


    return 0;
}


Measured memory_bytes: 2296
import java.util.ArrayDeque;
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args) {
        FS fs = new FS();
        int n = fs.nextInt();
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int m = fs.nextInt();
            if (test(m)) sum++;
        }
        System.out.println(sum);
    }

    private static boolean test(int m) {
        if (m == 2) return true;
        else if (m == 3) return true;
        else {
            if (m%2==0)return false;
            if (m%3==0)return false;
            for (int i = 5; i < Math.sqrt(m)+1; i += 2) {
                if (m % i == 0) return false;
            }
            return true;
        }
    }

}


 class FS {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        return hasNextByte() ? buffer[ptr++] : -1;
    }

    private boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    private void skipUnprintable() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
    }

    public boolean hasNext() {
        skipUnprintable();
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public int nextInt() {
        return (int) nextLong();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
}




Measured memory_bytes: 25944
#include<stdio.h>
int main(void)
{
	int a,b;

	scanf("%d %d" , &a, &b);
	if(a<b){
		printf("a < b\n");
	}else if(a>b){
		printf("a > b\n");
	}else{
	printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580