akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

bool checkBreak(int T,int L){
    if(T <= 0 || T > L) return 1;
    return 0;
}

int main(){
    int N,T,H,L;
    cin >> N >> T >> H >> L;
    vector<int> t(N),h(N);
    for(int i = 0 ; i < N ; i++){
        cin >> t[i] >> h[i];
    }
    int p = 0,coin = 0;
    vector<bool> flg(N,0);
    while(1){
        if(t[p] > 0){
            t[p]--; T++;
            coin += 10;
        }else{
            h[p]--; H++;
            coin += 100;
        }
        if(coin >= 90){
            coin -= 90;
            t[p] += coin/10;
            T -= coin/10;
            coin = 0;
        }
        if(checkBreak(T,L) || flg[p]) break;
        if(t[p] == 0 && h[p] == 0){
            flg[p] = 1;
        }
        p = (p + 1) % N;
    }
    cout << p+1 << endl;
    return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
   FAST/**/
   
   string s;
   cin>>s;
   
   if(s[2] == s[3] && s[4] == s[5])
        cout<<"Yes\n";
   else cout<<"No\n";        
   
   
   return 0;        
}  
   

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

int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    int hl, hr = 1;
    int i;
    int ans = 0;
    for (i=2; i<=999; i++)
    {
        hl = hr;
        hr += i;
        if (hr - hl == b - a) ans = hl - a;
    }
    printf("%d\n", ans);
    return 0;
}


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

char *shuffle(char *s, int h){
  char t[201];
  strcpy(t, s);

  for(int i = 0; i < strlen(s) - 1; i++){
	s[i] = t[i + h];
  }

  for(int j = 0; j < h; j++){
	s[(strlen(t) - h) + j] = t[j];
  }

  return s;
}


int main(){

  char cards[201];
  int m, h;
  while(1){
	scanf("%s", cards);
	if(cards[0] == '-'){
	  break;
	}

	scanf("%d", &m);

	for(int i = 0; i < m; i++){
	  scanf("%d", &h);
	  shuffle(cards, h);
	}
	printf("%s\n", cards);
  }

  return 0;
}


Measured memory_bytes: 2040
#include<iostream>
#include<algorithm>
#include<sstream>
#include<stack>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 1; i <= n;i++)
#define ALL(a)  (a).begin(),(a).end()
#define fix  fixed << setprecision(10)
const int MOD = 1000000007;
const ll INF = (1LL << 60);
string s; ll n, m, k, q = 0, ans, sum =INF; 
int main() {
    cin >> n;
    rep(i, n) {
        if (i % 3 == 0 || i % 5 == 0) continue;
        q += i;
    }
    cout << q << endl;
}


Measured memory_bytes: 3636
from math import *

n = int(input())
l = []
s = []

for x in range(n):
    a, b = map(int, input().split())
    l.append([a, b])

for x in range(n):
    for y in range(x + 1, n):
        s.append(sqrt((l[x][0] - l[y][0]) ** 2 + (l[x][1] - l[y][1]) ** 2))
        
print(sum(s) * 2 / n)

Measured memory_bytes: 3064
# 文字列 s の連続した一部分(部分文字列という)を取り出して
# 先頭が A であり末尾が Z であるような文字列を作ることにしました。

# s には先頭が A であり末尾が Z であるような
# 部分文字列が必ず存在することが保証されます。

# 作ることのできる文字列の最大の長さを求めてください。
a_s = gets.chomp.split("")
# p a_s

idx_b = -1
idx_e = a_s.size

last_idx = a_s.size-1
mid_idx = last_idx/2

0.upto(last_idx) do |idx|
  #if a_s[idx] == "A" && idx_b == -1
  if a_s[idx] == "A"
	#p idx
    idx_b = idx
    break
  end
end

last_idx.downto(0) do |idx|
  #if a_s[idx] == "Z" && idx_e == a_s.size
  if a_s[idx] == "Z"
    #p idx
    idx_e = idx
    break
  end
end


puts "#{(idx_e-idx_b)+1}"

Measured memory_bytes: 16764
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,W=MI()
    WV=LLIN(N)
    W0 = WV[0][0]
    for i,(w,v) in enumerate(WV):
        WV[i][0] = w-W0
    WV.sort(key=lambda x: x[1], reverse=True)
    cumsum = [0]*N
    for i,(w,v) in enumerate(WV):
        cumsum[i]=cumsum[i-1]+v

    dp = [[0]*(N*3+1) for _ in range(N+1)]
    for i in range(N):
        for k in range(1,N+1)[::-1]:
            for w in range(N*3+1):
                if w>=WV[i][0]:
                    dp[k][w] = max(dp[k][w], dp[k-1][w-WV[i][0]] + WV[i][1])

    ans = 0 
    for k in range(1,N+1):
        W_k = W-W0*k
        if W_k>=N*3:
            ans = max(ans, cumsum[k-1])
            continue
        if W_k<0:
            break   
        ans = max(ans, dp[k][W_k])
    print(ans)



if __name__ == '__main__':
    main()

Measured memory_bytes: 70764
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int i=1;
  while(++i<=n){
    int x=i;
    if(x%3==0){
      cout << " " << i;
      continue;
    }
    while(x){
      if(x%10==3){
	cout << " " << i;
	break;
      }
      x/=10;
    }
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 3088
function Main(input) {
  input = input.split("\n");
  var A = parseInt(input[0].split(" ")[0]);
  var B = parseInt(input[0].split(" ")[1]);
  var C = parseInt(input[0].split(" ")[2]);

  if(A <= B){
    if(A <= C && C <= B){
      console.log("Yes");
    }else{
      console.log("No");
    }
  }else{
    if(B <= C && C <= A){
      console.log("Yes");
    }else{
      console.log("No");
    }
  }
}

var input=Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// var input=`3 8 5`
// Main(input);


Measured memory_bytes: 25160
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
void vout(vl V) {
	for (ll i = 0; i < (ll)V.size(); i++) cout << V[i] << " ";
	cout << endl;
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color; vll path; vl A; vl dp; vl Ans;
int main() {
	string S;
	cin >> S;
	if (S == "ABC") cout << "ARC";
	else cout << "ABC";
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
    a[i]--;
  }
  vector<bool> C(N,false);
  int p = 0;
  int count = 0;
  while (!C[p]){
    C[p] = true;
    if (p == 1) break;
    p = a[p];
    count++;
  }
  if (C[1]) cout << count;
  if (!C[1]) cout << -1;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
int main()
{
  char a,b,c;
  int d;
  cin >> a >> b >> c;
  if(a=='o')d++;
  if(b=='o')d++;
  if(c=='o')d++;
  printf("%d",700+100*d);
}

Measured memory_bytes: 256
import java.util.*;

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

    long n = sc.nextLong();
    long ans = 10;

    for(int i = 1; i <= Math.sqrt(n); i++){
      if(n % i == 0){
        long buf = String.valueOf(n / i).length();
        if(ans > buf){
          ans = buf;
        }
      }
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 23124
#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;

using ll = long long;
using ull = unsigned long long;
using vl = vector<ll>;
using vi = vector<int>;
using vchar = vector<char>;
using vstr = vector<string>;
using pll =  pair<ll,ll>;

const ll mod = 1000000007;
const ll inf = 1000000000000000;

#define pi acos(-1)
#define pb push_back
#define test int TEST;cin>>TEST;while(TEST--)
#define vsort(xx) sort(xx.begin(),xx.end())
#define vrevsort(xx) sort(xx.rbegin(),xx.rend())


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll n;
    cin>>n;
    ll a=sqrt(n);
    cout<<a*a;
   
    return 0;
}




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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;

int main() {

	IOS

	ll a, b, n;
	cin >> a >> b >> n;

	ll x = min(b-1, n);
	ll ans = (a * x) / b;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace LogicSummoner
{
    class Program
    {
        static void Main(string[] args)
        {
            var target = Console.ReadLine().Trim().ToLower();
            var count = 0;
            while (true)
            {
                var line = Console.ReadLine().Trim();
                if (line == "END_OF_TEXT")
                {
                    break;
                }

                var lines = line.ToLower().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                count += lines.Count(l => l == target);
            }
            System.Console.WriteLine(count);
        }

        //static StreamReader Console = new StreamReader("input.txt");

        static int GetNumber()
        {
            return int.Parse(Console.ReadLine().Trim());
        }

        static double GetDounble()
        {
            return double.Parse(Console.ReadLine().Trim());
        }

        static int[] GetNumbersInt(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToArray();
        }

        static long[] GetNumbersLong(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToArray();
        }

        static double[] GetNumbersDouble(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(x => double.Parse(x)).ToArray();
        }

        static string[] GetStrings(int n = 0)
        {
            return Console.ReadLine().Trim().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
        }
    }
}

Measured memory_bytes: 10084
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <string.h>
#include <math.h>

using namespace std;

#define PI 3.141592653589793
#define epsilon 0.000000001
#define INF 1000000000000000000
#define MOD 1000000007

int main(){
    //freopen("subrev.in", "r", stdin); freopen("subrev.out", "w", stdout);
    int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;
    int j = 0; int bestNumer = -1; int bestDenom = -1; int retVol = 100*a; int retSugar = 0;
    while(j*a*100 <= f){
        int k = 0; if(j == 0) k++;
        while((j*a+k*b)*100 <= f){
            int sugarSpace = min(f-(j*a+k*b)*100, e*(j*a+k*b)), bestSugar = 0;
            bool dp [sugarSpace+100]; memset(dp, false, sizeof(dp)); dp[0] = true;
            for(int i = 0; i <= sugarSpace; i++){
                if(!dp[i]) continue;
                bestSugar = i;
                dp[i+c] = true; dp[i+d] = true;
            }
            if(bestNumer == -1){ retVol = (j*a+k*b)*100; retSugar = bestSugar; bestNumer = bestSugar; bestDenom = (j*a+k*b)*100+bestSugar; }
            else if(bestSugar*bestDenom > ((j*a+k*b)*100+bestSugar)*bestNumer){
                retVol = (j*a+k*b)*100; retSugar = bestSugar; bestNumer = bestSugar; bestDenom = (j*a+k*b)*100+bestSugar;
            }
            k++;
        }
        j++;
    }
    cout << retVol+retSugar << " " << retSugar << '\n';
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
root_map = dict()
root_map[1] = set()
root_map[n] = set()

for i in range(m):
    a, b = map(int, input().split())
    if a == 1 or a == n:
        root_map[a].add(b)
    if b == 1 or b == n:
        root_map[b].add(a)

if root_map[1] & root_map[n]:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 23908
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  int n,q;
  cin>>n>>q;
  vector< queue<int> > qs(n);
  for(int i=0;i<q;i++){
    int t,x;
    cin>>t>>x;
    if(t==0){
      x--;
      cout<<qs[x].front()<<"\n";
      qs[x].pop();
    }
    if(t==1){
      int k=0;
      for(int j=0;j<n;j++)
        if(qs[j].size()<qs[k].size()) k=j;
      qs[k].emplace(x);
    }
  }
  return 0;
}



Measured memory_bytes: 3132
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int h = scanner.nextInt();
			int w = scanner.nextInt();
			int n = scanner.nextInt();
			if ((h | w | n) == 0)
				break;
			int[][] map = new int[h + 1][w + 1];
			map[0][0] = --n;
			boolean[][] b = new boolean[h][w];
			for (int i = 0; i < h; i++)
				for (int j = 0; j < w; j++) {
					int m = scanner.nextInt();
					map[i][j + 1] += (map[i][j] + (m & 1)) / 2;
					map[i + 1][j] += (map[i][j] + (m ^ 1)) / 2;
					b[i][j] = (map[i][j] + m) % 2 == 1;
				}
			int px = 0;
			int py = 0;
			while (px < w && py < h) {
				if (b[py][px])
					px++;
				else
					py++;
			}
			System.out.println((py + 1) + " " + (px + 1));
		}
	}
}

Measured memory_bytes: 298696
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int c = log(k)/log(2) + 1;
    if(c > n)
        c = n;
    int add = n - c;
    int ans = pow(2,c)+add*k;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

int n, m;
vector<vector<pii> > G;
vector<int> d;

void dfs(int v, int p) {
  for (pii P : G[v]) {
    int nv = P.F, cost = P.S;
    if (nv == p) continue;
    if (d[nv] == -1) {
      (d[nv] = d[v] + cost) %= 2;
      dfs(nv, v);
    }
    else {
      int D = (d[v] + cost) % 2;
      if (D != d[nv]) {
        cout << -1 << endl;
        exit(0);
      } else {
        d[nv] = D;
      }
    }
  }
}

// 矛盾してたら -1 を出力
void solve() {
  cin >> n >> m;
  G.resize(n);
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    G[a].eb(b, c % 2);
    G[b].eb(a, c % 2);
  }
  d = vector<int>(n, -1);
  int cnt = 0;
  rep(i, n) {
    if (d[i] == -1) {
      d[i] = 0;
      dfs(i, -1);
      cnt++;
    }
  }
  cout << cnt << endl;
}


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

int main(){
    int n;
    multiset<ll> s, status;
    //sは与えられる集合、statusはシミュレーションの状態、tmpはstatusのコピー先
    
    //入力部
    cin >> n;
    int j;
    for(int i = 0; i < (1 << n); i++){
        cin >> j;
        s.insert(j);
    }

    status.insert(*(s.rbegin()));
    s.erase(*(s.rbegin()));
    for(int i = 0; i < n; i++){
        multiset<ll> tmp(status); //状態を保存しておき、tmpを変化させていく、statusは参照するだけ
        for(auto e : status){ //現在の状態の最小の値から見ていく
            auto itr = s.lower_bound(e); //現在見ている値の中で最も左にあるものを参照
            if(itr == s.begin()){ //その位置が最左端ならシミュレーション失敗
                cout << "No" << endl;
                return 0;
            }
            tmp.insert(*prev(itr)); //見ている値よりも小さい物を取る
            s.erase(prev(itr));
        }
        status = tmp; //状態を更新する
    }

    //シミュレーションに成功したらYes
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 24832
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll n;cin>>n;
    ll m;cin>>m;
    vector<pair<int,int>> arena;
    if(n%2==1){
        for(int i=1;i<1+m;i++){
            arena.push_back(make_pair(i,n+1-i));
        }
    }
    else{
        int dist1=(n-1)/2;
        int dist2=dist1-1;
        for(int i=1;dist1>0;i++){
            arena.push_back(make_pair(i,i+dist1));
            dist1-=2;
        }
        for(int i=n;dist2>0;i--){
            arena.push_back(make_pair(i,i-dist2));
            dist2-=2;
        }
    }
    For(i,0,m){
        cout << arena[i].first << " " <<arena[i].second << endl;
    }
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 4256
#include <stdio.h>
#include <iostream>

using namespace std;

int main(){
    int N = 0,M = 0;
  cin >> N >> M;
  if(N >= M){
    for(int i = 0;i < N;i++) cout << M;
  }
  else for(int i = 0;i < M;i++) cout << N;
  return 0;
}


Measured memory_bytes: 256
N = input()
list = [i for i in str(N)]
ans = float("inf")

for i in range(len(list)-2):
    a = str(list[i])
    b = str(list[i+1])
    c = str(list[i+2])
    num = abs(753-int(a+b+c))
    ans = min(ans,num)

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;

vector<pair<int, int>> adj[MAX];
int n, u, v, w, vis[MAX], color[MAX];

int main(){
    cin >> n;
    for (int i = 0; i < n - 1; i++){
        cin >> u >> v >> w;
        adj[u].push_back(make_pair(v, w));
        adj[v].push_back(make_pair(u, w));
    }
    queue<int> queue;
    queue.emplace(1);
    vis[1] = 1;
    while(queue.size()){
        int cv = queue.front();
        queue.pop();
        for(auto p: adj[cv]){
            if (!vis[p.first]){
                if (p.second % 2 == 0)
                    color[p.first] = color[cv];
                else 
                    color[p.first] = 1 - color[cv];
                queue.emplace(p.first);
                vis[p.first] = 1;
            }
        }
    }
    for (int i = 1; i <= n; i++) cout << color[i] << "\n";
    return 0;
}

Measured memory_bytes: 10320
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author amotoma3
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();
            long y = in.nextLong();
            for (int i = 0; i <= 2000; i++) {
                for (int j = 0; j <= 2000; j++) {
                    if (n - i - j < 0) continue;

                    if (10000L * i + 5000L * j + 1000L * (n - i - j) == y) {
                        out.println(i + " " + j + " " + (n - i - j));
                        return;
                    }
                }
            }

            out.println("-1 -1 -1");
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

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

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



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

using namespace std;

#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define cl(x,v) memset((x), (v), sizeof(x))
#define db(x) cerr << #x << " == " << x << endl
#define dbs(x) cerr << x << endl
#define _ << ", " <<

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<int, pii> piii;
typedef pair<ll,ll> pll;
typedef pair<ll, pll> plll;
typedef vector<int> vi;
typedef vector <vi> vii;

const ld EPS = 1e-9, PI = acos(-1.);
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f, MOD = 1e9+7;
const int N = 1e5+5;

ll h[N], dp[N];

ll calldp(ll pos){
    if(~dp[pos]) return dp[pos];
    if(pos == 1) return dp[pos] = 0;
    if(pos < 1) return INF;
    return dp[pos] = min(calldp(pos-2) + abs(h[pos] - h[pos-2]), calldp(pos-1) + abs(h[pos] - h[pos-1]));
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(dp,-1,sizeof(dp));
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> h[i];
    }
    cout << calldp(n) << "\n";
    return 0;
}

Measured memory_bytes: 4992
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>

using namespace std; 

#define MP make_pair
typedef unsigned long long ULL;

//dp[i]...i円払う場合のコインの最小枚数
long dp[50001];

int main(){

	long n;
	int m;
	cin>>n>>m;

	vector<int> d(m);
	for(int i=0;i<m;i++){
		cin>>d[i];
		dp[d[i]]=1;
	}

	for(long i=2;i<=n;i++){
		if(dp[i]==0) dp[i]=60000; //十分大きい値
		for(int j=0;j<m;j++){
			if(i<d[j]) continue;

			//i-d[j]円払うことが可能->d[j]円の追加でi円も払える
			if(dp[i-d[j]]!=0) dp[i]=min(dp[i],dp[i-d[j]]+1);
		}
	}

	cout<<dp[n]<<endl;

	return 0;
}

Measured memory_bytes: 1580
//Δ_D
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 2222;
const int inf = 2e9;
int sq(int x){
	int i=0;
	while(i*i<x){
		i++;
	}
	return i;
}
int n,m,a[N][N],b[N][N],c[N],d[N],e[N][N],f[N][N],g[N][N];
int main()
{
	int i,j,o,u;
	scanf("%d%d",&m,&n);
	while(m--){
		scanf("%d%d",&i,&j);
		a[i%n][j%n]++;
	}
	u=0;
	for(i=0;i<n;i=i+1)
		for(j=0;j<n;j=j+1)
			u=max(u,sq(a[i][j]));
	for(i=0;i<n;i=i+1){
		for(j=0;j<n;j=j+1){
			if(a[i][j]>u*(u-1))
				b[i][j]=1;
			if(a[i][j]>(u-1)*(u-1))
				a[i][j]=1;
			else
				a[i][j]=0;
		}
	}
	for(i=0;i<n+n;i=i+1)
		for(j=0;j<n+n;j=j+1)
			a[i][j]=a[i%n][j%n],b[i][j]=b[i%n][j%n];
	for(i=0;i<n+n;i=i+1)
		for(j=0;j<n+n;j=j+1)
			if(b[i][j])
				c[i]=1,d[j]=1;
	o=0;
	for(i=0;i<n+n;i=i+1){
		if(i>=n)
			c[i-n]=o-(i-n);
		if(c[i])
			o=i;
	}
	o=0;
	for(i=0;i<n+n;i=i+1){
		if(i>=n)
			d[i-n]=o-(i-n);
		if(d[i])
			o=i;
	}
	for(i=0;i<n+n;i=i+1){
		for(j=0;j<n+n;j=j+1){
			if(a[i][j]||!j)
				e[i][j]=0;
			else
				e[i][j]=e[i][j-1]+1;
			if(a[i][j]||!i)
				f[i][j]=0;
			else
				f[i][j]=f[i-1][j]+1;
			g[i][j]=min(e[i][j],f[i][j]);
			if(i&&j)
			g[i][j]=min(g[i-1][j-1]+1,g[i][j]);
		}
	}
	o=n;
	for(i=0;i<n;i=i+1)
		for(j=0;j<n;j=j+1)
			o=min(o,max(n-1-g[i+n-1][j+n-1],max(c[i],d[j])));
	cout<<(u-1)*n+o;
	return 0;
}

Measured memory_bytes: 96512
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007LL
ll sum[200009];
int main()
{
    ll n,i,k,ans=0LL,mini,maxi;
    cin >> n;
    for(i=1;i<=n;i++)
        sum[i]=(sum[i-1]%mod+i%mod)%mod;
    cin >> k;
    for(i=k-1;i<=n;i++)
    {
        mini = sum[i];
        if(i==n) maxi = sum[n];
        else maxi = (sum[n]-sum[n-i-1]+mod)%mod;
        ans=(ans%mod+(maxi-mini+1LL+mod)%mod)%mod;
    }
    cout << ans << endl;
}


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


int main() {
    int N, K;
    std::cin >> N >> K;

    int max = (N - 1) * (N - 2) / 2;
    if (K > max) {
        std::cout << -1 << std::endl;
        return 0;
    }

    std::cout << (N - 1) + max - K << std::endl;;
    for (int i = 1; i < N; i++) {
        std::cout << 1 << " " << i + 1 << std::endl;
    }

    int cnt = 0;
    for (int j = 1; j < N - 1; j++) {
        for (int k = j + 1; k < N; k++) {
            if (cnt == max - K) {
                return 0;
            }
            std::cout << j + 1 << " " << k + 1 << std::endl;
            cnt++;
        }
    }
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>

template <class T>
T abs(T a) { return (a < 0 ? -a : a); }

int main() {
    long long n, k, ret = 1e14;
    std::cin >> n >> k;
    std::vector<long long> v(n);
    for (auto i = 0ll; i < n; i++) {
        std::cin >> v[i];
    }
    for (auto i = 0ll; i < n - k + 1; i++) {
        auto cost = v[i + k - 1] - v[i] + std::min(abs(v[i + k - 1]), abs(v[i]));
        ret = std::min(ret, cost);
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<climits>
#include<cstring>
using namespace std;
long long dp[101][100001];
vector<int> w(101),v(101);
int W,n;
long long sum=0;
long long int knapsack()
{  int maxvalue=n*1000;
  for(int v1=0;v1<=maxvalue;v1++)
   dp[1][v1]=INT_MAX;
dp[1][0]=0;
  dp[1][v[1]]=w[1];
  for(int i=2;i<=n;i++)
   {
   	for(int v1=0;v1<=maxvalue;v1++)
   	{
   		dp[i][v1]=dp[i-1][v1];
   		if(v[i]>v1)
   		 continue;
   		 dp[i][v1]=min(dp[i][v1],w[i]+dp[i-1][v1-v[i]]);
	  }
   }
int  ans;
for(int i=0;i<=n*1000;i++)
   if(dp[n][i]<=W)
     ans=i;
	return ans;
}
int main()
{
	 //memset(dp,INT_MAX,sizeof(dp));
	cin>>n>>W;
	for(int i=1;i<=n;i++)
     { 
       cin>>w[i];
       cin>>v[i];
}
   
  cout<<knapsack();
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pii  = pair<int,int>;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define rep2(i,x,n) for(ll i=x; i<(n); i++)
#define MOD 1000000007
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; }
const long long INF = 1LL << 60;
const double PI = 3.141593;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}    //最大公約数
ll lcm(ll a,ll b) {return a * b / gcd(a, b);}   //最小公倍数
ll combination(ll n, ll r) {
  if ( r * 2 > n ) r = n - r;
  ll dividend = 1;
  ll divisor  = 1;
  for ( ll i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

int main(){
  int m1, d1, m2, d2;
  cin >> m1 >> d1 >> m2 >> d2;
  if(m1==m2)
    cout << 0 << endl;
    else
    {
      cout << 1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
const int MOD=(int)1e9+7;
using namespace std;

int findSumOfDigits(int n) {
      int sum = 0;
    while(n>0){
     sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(){
    int n,a,b;
    int ans = 0;
       cin >> n >> a >> b;
       REP(i,n+1){
         if(findSumOfDigits(i) >= a && findSumOfDigits(i) <= b){
             ans += i;
         }
       }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main()
{
  char c;
  scanf("%c",&c);
  switch(c){
    case 'A':
      printf("T\n");
      break;
    case 'T':
      printf("A\n");
      break;
    case 'C':
      printf("G\n");
      break;
    case 'G':
      printf("C\n");
      break;
  }
}

Measured memory_bytes: 128
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pll;
#define fu(i,a,b)   for(ll i=a;i<b;i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define ms(a,x) 	memset(a, x, sizeof a)
#define prec(n) 	fixed<<setprecision(n)
#define pb(i)	    push_back(i)
#define popb()    	pop_back()
#define sc(a) 	    cin>>a
#define sc2(a,b)    cin>>a>>b
#define pr(a)	    cout<<a<<" "
#define pr2(a,b)    cout<<a<<" "<<b<<" "
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)	lower_bound(a.begin(),a.end(),x) -a.begin()
#define all(x) 		(x).begin(), (x).end()
#define sz(a) 		(ll)a.size()
#define le			length()						
#define re 			return 	
#define	mp(a,b)  	make_pair(a,b)
#define se			second
#define fi			first 
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
void inline minize(ll& a,ll b){a=(a>b?b:a);};
void inline maxize(ll& a,ll b){a=(a<b?b:a);};
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17;


ll arr[1000][1000],mark[1000000];

ll Solves(){
//	INPUT;
	ll n,k,cnt=0,ans=oo,x,l,flag,h,w,H,W,ne,po;
	// PROCESSING IN HERE
	sc2(H,W); sc2(h,w);
	po=(1e9-1)/(h*w-1);
	ne=-po*(h*w-1)-1;
	
	for(ll i=h;i<=H;i+=h)
	for(ll j=w;j<=W;j+=w)
		arr[i][j]=ne;
		
	fu(i,1,H+1) fu(j,1,W+1) if(!arr[i][j])arr[i][j]=po;
	fu(i,1,H+1) fu(j,1,W+1) cnt+=arr[i][j];
	
	if(cnt<=0)pr("No");
	else{
		cout<<"Yes"<<endl;
		fu(i,1,H+1){
			fu(j,1,W+1)cout<<arr[i][j]<<" ";
			cout<<endl;
		}
	}
		
	
	re 0;
	// Hack it if you can :)
}
int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	Solves();
}

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

class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int nine = (n/9);
		n-=nine*9;
		int six = n/6;
		n-=six*6;
		int one = n;
		int ans = 99999999;
		while(nine>=0) {
			int sum = 0;
			sum += calc(9,nine);
			sum += calc(6,six);
			sum += one;
			ans = Math.min(ans,sum);
			nine--;
			six+=1;
			one+=3;
			if(one>=6) {
				six++;
				one-=6;
			}
		}
		System.out.println(ans);
	}

	public static int calc(int num, int all) {
		int max = 1;
		int result = 0;
		while(max*num<=all) max *= num;
		while(max>0) {
			int count = all/max;
			result += count;
			all -= count*max;
			max /= num;
		}
		return result;
	}
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x -> left != NIL) {
    x = x -> left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x -> right != NIL) {
    x = x -> right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if(u == NIL && k == u -> key) {
    return u;
  }else if(k < u -> key) {
    return treeSearch(u -> left, k);
  }else{
    return treeSearch(u -> right, k);
  }
}

Node treeSuccessor(Node x){
  Node a;
  if(x -> right != NIL) {
    return treeMinimum(x -> right);
  }
  a = x -> parent;
  while(a != NIL && x == a -> right) {
    x = a;
    a = a -> parent;
  }
  return a;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z -> left == NIL || z -> right == NIL) {
    y = z;
  }else{
    y = treeSuccessor(z);
  }

  if(y -> left != NIL) {
    x = y -> left;
  }else{
    x = y -> right;
  }

  if(x != NIL) {
    x -> parent = y -> parent;
  }

  if(y -> parent == NIL) {
    root = x;
  }else if(y == y -> parent -> left) {
    y -> parent -> left = x;
  }else{
    y -> parent -> right = x;
  }

  if(y != z) {
    z -> key = y -> key;
  }
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL) {
    y = x;
    if(z -> key < x -> key) {
      x = x -> left;
    }else{
      x = x -> right;
    }
  }

  z -> parent = y;
  if(y == NIL) {
    root = z;
  }else if(z -> key < y -> key) {
    y -> left = z;
  }else{
    y -> right = z;
  }
}

void inorder(Node u){
  if(u == NIL) {
    return;
  }
  inorder(u -> left);
  printf(" %d",u -> key);
  inorder(u -> right);
}

void preorder(Node u){
  if(u == NIL) {
    return;
  }
  printf(" %d",u -> key);
  preorder(u -> left);
  preorder(u -> right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25180
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
//________
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define err(...) fprintf(stderr, __VA_ARGS__ )
#define show(x) cerr << #x << ':' << (x) << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
const int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
#define INF  0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define NIL -1
//________


signed main()
{
   FAST();
   int a , b;
   cin>> a >> b;
   a *= b;
   outl( a % 2 == 0 ? "Even" : "Odd" );
}



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

int main(){ 
  ll a, b;
  cin >> a >> b;

  auto calc = [&](ll x) {
    x++;
    ll res = 0;
    for (int d = 0; d < 55; d++) {
      ll l = (1LL << (d + 1));
      ll cnt = (x / l) * (l / 2);
      cnt += max(0LL, (x % l) - (l / 2));
      if (cnt % 2 == 1) res += (1LL << d);
    }
    return res;
  };

  ll res = calc(b) ^ calc(a-1);
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 256
MOD = 1000000007


def main():
    s = input()

    dp = [[0 for j in range(4)] for i in range(len(s)+1)]
    dp[len(s)][3] = 1

    for i in range(len(s)-1, -1, -1):
        for j in range(3, -1, -1):
            if i < j:
                continue
            if j == 3:
                dp[i][j] = dp[i+1][3]
                if s[i] == "?":
                    dp[i][j] = 3 * dp[i][j] % MOD
            else:
                m1, m2 = 1, 0
                if s[i] == "?":
                    m1 = 3
                    m2 = 1
                if s[i] == "ABC"[j]:
                    m2 = 1
                dp[i][j] = (m1*dp[i+1][j]+m2*dp[i+1][j+1]) % MOD

    print(dp[0][0] % MOD)


if __name__ == '__main__':
    main()


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

const long long SIZE = 1000000000000000000;

array<array<long long, 3>, 3> multiply(array<array<long long, 3>, 3>& a, array<array<long long, 3>, 3>& b) {
    array<array<long long, 3>, 3> result = {};
    for (int i = 0; i < 3; i++) {
        for (int k = 0; k < 3; k++) {
            for (int j = 0; j < 3; j++) {
                result[i][j] += a[i][k] * b[k][j];
            }
        }
    }
    return result;
}

array<array<long long, 3>, 3> pow(array<array<long long, 3>, 3> x, long long n) {
    array<array<long long, 3>, 3> result = {{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}};
    while (n != 0) {
        if (n % 2 == 1) {
            result = multiply(result, x);
        }
        x = multiply(x, x);
        n /= 2;
    }
    return result;
}

int main() {
    long long a, b, c, k;
    cin >> a >> b >> c >> k;
    array<array<long long, 3>, 3> m = {{{0, 1, 1}, {1, 0, 1}, {1, 1, 0}}};
    m = pow(m, k);
    cout << a * m[0][0] + b * m[0][1] + c * m[0][2] - a * m[1][0] - b * m[1][1] - c * m[1][2];
    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
u = [0]*n
for i in range(k):
    d=int(input())
    v = map(int,input().split())
    for a in v:
        u[a-1]+=1
c=0
for i in range(n):
    if u[i]==0:
        c+=1
print(c)


Measured memory_bytes: 9184
import math

N,K=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
A=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき


if N==K:
    print(1)
else:
    print(math.ceil((N-1)/(K-1)))


Measured memory_bytes: 13812
import sys
import numpy as np

I = np.array(sys.stdin.read().split(), dtype=np.int64)
a = I[1:]

def main():
    m = int(np.around(np.mean(a)))
    ans = np.sum((a - m) ** 2)
    return ans

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 12480
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)

#define debug(x) cerr<<#x<<": "<<x<<'\n'

#define fi first
#define se second

#define vi vector<int>
#define pb push_back
#define mp make_pair

#define pcnt __builtin_popcount

typedef long long ll;

const int inf = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dp[200100] = {};
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    int p[200100];
    cin >> n;
    ll sum=0;
    rep(i,n) {cin >> p[i];}
    if(p[0]!=0) {cout << -1 << endl; return 0;}
    int t = 0;
    rrep(i,n-1){
      t = max(t,p[i+1]);
      if(p[i+1] > p[i]+1){cout << -1 << endl; return 0;}
      if(p[i] >= p[i+1] ||p[i]==0){ sum+=t; t=0;}
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int p[10],c[10];
int main() {
  int n, k;
  cin >> n >> k;
  if(n%k) cout << 1 << endl;
  else cout << 0 << endl;
}



Measured memory_bytes: 256
n,W = map(int,input().split())
dp = [[0]*(W+1) for i in range(n)]
for i in range(n):
    w,v = map(int,input().split())
    if i == 0:
        for j in range(W+1):
            if w <= j:
                dp[0][j] = v
    else:
        for j in range(W+1):
            if j < w:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = max(dp[i-1][j-w]+v, dp[i-1][j])
print(dp[-1][-1])

Measured memory_bytes: 119532
#include<cstdio>
int a[110000],v[110000];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	v[1]=1;
	int t=1,flag=1,ans=0;
	while(flag)
	{
		t=a[t];
		ans++;
		if(v[t]) break;
		if(t==2) flag=0;
		v[t]=1;
	}
	printf("%d\n",flag?-1:ans);
	return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007


int main()
{
	int n, m;
	cin >> n >> m;
	long long int x[1000], y[1000], z[1000];
	for(int i = 0; i < n; i++){
		cin >> x[i] >> y[i] >> z[i];
	}
	long long int ans = (long long int)-mod * 3 * 1000;
	for(int i = 0; i < (1 << 3); i++){
		vector<long long int> v;
		for(int j = 0; j < n; j++){
			long long int sum = 0;
			if((i & (1 << 2)) > 0) sum += x[j];
			else sum -= x[j];
			if((i & (1 << 1)) > 0) sum += y[j];
			else sum -= y[j];
			if((i & (1 << 0)) > 0) sum += z[j];
			else sum -= z[j];
			v.push_back(sum);
		}
		sort(v.begin(), v.end());
		reverse(v.begin(), v.end());
		long long int res = 0;
		for(int j = 0; j < m; j++){
			res += v[j];
		}
		ans = max(ans, res);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
/* ****revpro**** */
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define endl       '\n'
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)    
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mii        map<ll,ll>
using namespace std;
 
#define N  1000005
ll a[N];
vi v;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        string s;
        cin>>s;
        ll n=sz(s);
        rep(i,0,n) {
            if((i==0)&&(s[i]=='<')) v.pb(0);
            else if((i==n-1)&&(s[i]=='>')) v.pb(n);
            else if((s[i]=='>')&&(s[i+1]=='<')) v.pb(i+1);
        }
        for(auto i:v){
            ll j=i-1;
            ll prev=0;
            while((j>=0)&&(s[j]=='>')) a[j]=max(a[j],prev+1),prev++,j--;
            j=i;
            prev=0;
            while((j<n)&&(s[j]=='<')) a[j+1]=max(a[j+1],prev+1),prev++,j++;
        }
        ll sum=0;
        rep(i,0,n+1)sum+=a[i];
        cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 6296