akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        String[] lines = getStdin();
        String str1 = lines[0];
        int n = Integer.parseInt(str1);
        Boolean heart[] = {false, false, false, false, false, false, false, false, false, false, false, false, false};
        Boolean club[] = {false, false, false, false, false, false, false, false, false, false, false, false, false};
        Boolean diamond[] = {false, false, false, false, false, false, false, false, false, false, false, false, false};
        Boolean spade[] = {false, false, false, false, false, false, false, false, false, false, false, false, false};
        for(int i = 1; i <= n; ++i){
            String[] cinfo = lines[i].split(" ");
            String pic = cinfo[0];
            int cnum = Integer.parseInt(cinfo[1]);
            cnum--;
            if(pic.equals("H")){
                heart[cnum] = true;
            } else if(pic.equals("S")){
                spade[cnum] = true;
            } else if(pic.equals("C")){
                club[cnum] = true;
            } else if(pic.equals("D")){
                diamond[cnum] = true;
            }
        }
        for(int i = 0; i < 13; ++i){
            if(spade[i] == false){
                System.out.printf("%s %d", "S", i + 1);
                System.out.println();
            }
        }
        for(int i = 0; i < 13; ++i){
            if(heart[i] == false){
                System.out.printf("%s %d", "H", i + 1);
                System.out.println();
            }
        }
        for(int i = 0; i < 13; ++i){
            if(club[i] == false){
                System.out.printf("%s %d", "C", i + 1);
                System.out.println();
            }
        }
        for(int i = 0; i < 13; ++i){
            if(diamond[i] == false){
                System.out.printf("%s %d", "D", i + 1);
                System.out.println();
            }
        }
    }
  private static String[] getStdin() {
    Scanner scanner = new Scanner(System.in);
    ArrayList<String> lines = new ArrayList<>();
    while (scanner.hasNext()) {
      lines.add(scanner.nextLine());
    }
    return lines.toArray(new String[lines.size()]);
  }
}


Measured memory_bytes: 26464
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

int main() {
    int N;
    set<int> exist;
    int res = 0;
    int c;
    cin >> N;
    REP(i, N){
        cin >> c;
        if(exist.find(c)!=exist.end()) res++;
        exist.insert(c);
    }

    if(res % 2 == 1) {
        cout << exist.size() - 1;
    } else {
        cout << exist.size();
    }

    return 0;
}


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

int main()
{
	int a, b;
	char t;

	cin >> a >> b;

	if (a + b == 15)
		t = '+';
	else if (a * b == 15)
		t = '*';
	else
		t = 'x';

	cout << t << endl;

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, M := sc.nextInt(), sc.nextInt()
	A := sc.nextIntSlice(N)
	B := sc.nextIntSlice(M)
	And := []int{}
	Or := []int{}
	setOr := make(map[int]bool)
	for _, a := range A {
		setOr[a] = true
	}
	for _, b := range B {
		if setOr[b] {
			And = append(And, b)
		}
		setOr[b] = true
	}
	for k, _ := range setOr {
		Or = append(Or, k)
	}
	sort.Ints(Or)
	sort.Ints(And)

	fmt.Fprintln(wtr, len(And), len(Or))
	for _, v := range And {
		fmt.Fprintln(wtr, v)
	}
	for _, v := range Or {
		fmt.Fprintln(wtr, v)
	}
	wtr.Flush()
}



Measured memory_bytes: 21920
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;

int main(){
	cin>>n;
	int B=0;
	for(int i=1;i*100<=n;i++){
		int t=n-i*100;
		if(0<=t&&t<=5*i) B=1;
	}
	cout<<B<<endl;
}

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

using namespace std;

void __start__() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef MY
    freopen("/home/ainur/CLionProjects/wow/input.txt", "r", stdin);
    freopen("/home/ainur/CLionProjects/wow/output.txt", "w", stdout);
#else
    //freopen("search.in", "r", stdin);
   // freopen("search.out", "w", stdout);
#endif
}

#define sz(x) (int)x.size()
#define yes cout<<"Yes\n"
#define  no cout << "No\n"
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define ft first
#define sd second
#define read(a) for(auto &qwqw:a)cin >> qwqw;
#define print(a) for(auto qwqw:a)cout<<qwqw<<' ';
#define print_plus(a) for(auto qwqw:a)cout<<qwqw+1<<' ';
//#define FOR(i, b, n) for(int i=b;i<n;i++) #define FOR(i, n) FOR(i, 0, n) #define FOR(n) FOR(i, 0, n)
mt19937_64 rnd(time(0));
#define int long long
using ll = long long;
using vi = vector<int>;
using ld = long double;
using vb = vector<bool>;
using pii = pair<int, int>;
using vd = vector<long double>;


int log2(int q) {
    int c = 0;
    while (q) {
        q >>= 1;
        c++;
    }
    return c;
}

void test_case() {
    int x, y;
    cin >> x >> y;
    for (int i = 0; i < 100; ++i) {
        for (int j = 0; j < 100; ++j) {
            if (4 * i + 2 * j == y && i + j == x) {
                yes;
                return;
            }
        }

    }
    no;

}

signed main() {
    __start__();
    int Q = 1;
    //cin >> Q;
    while (Q--) {
        test_case();
    }
}





Measured memory_bytes: 3708
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)
#define MP make_pair


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(10);

  int INF = 1000000;

  vector<int> m;
  int hei;
  while(cin >> hei){
    m.push_back(hei);
  }

  sort(m.begin(), m.end(), greater<int>());

  REP(i,3)
    cout << m[i] << endl;

  return 0;
}

Measured memory_bytes: 1216
var
a:array[0..205] of longint;
n,i,min,x,t:longint;
begin
readln(n);
for i:=1 to n do read(a[i]);
min:=maxlongint;
for i:=1 to n do
  begin
    t:=a[i];
    x:=0;
    while t mod 2=0 do
      begin
        t:=t div 2;
        inc(x);
      end;
    if x<min then min:=x;
  end;
writeln(min);
end.

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
int main(void){
  int n,i,j;
  scanf("%d",&n);
  for(i=0;i<=25;i++){
    for(j=0;j<=15;j++){
      if(i*4+j*7==n) {printf("Yes");return 0;}
    }
  }
  printf("No");
  return 0;
}

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

using namespace std;

int main(){
    long N, K;
    cin>>N>>K;
    vector<long> A(N), F(N);
    for(int i=0; i<N; ++i){
        cin>>A[i];
    }
    for(int i=0; i<N; ++i){
        cin>>F[i];
    }
    
    sort(A.begin(), A.end());
    sort(F.begin(), F.end());
    long mmax = 0;
    for(int i=0; i<N; ++i){
        mmax = max(A[i] * F[N-i-1], mmax);
    }

    long l = 0;
    long r = mmax;
    long m;
    while(l+1 < r){
        //cout<<l<<" "<<r<<endl;
        m = (l+r)/2;
        //cout<<m<<endl;
        long sum = 0;
        for(int i=0; i<N; ++i){
            sum += max(long(ceil((A[i] * F[N-i-1] - m)*1.0/F[N-i-1])), long(0));
        }
        if(sum > K){
            l = m;
        }else if(sum <= K){
            r = m;
        }else{
            //cout<<m<<endl;
            //return 0;
        }
    }
    if(l==0){
        cout<<0<<endl;
    }else{
        cout<<r<<endl;
    }

    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    vector<int> S;
    for(auto x : s) S.push_back(x == 'o');
    vector<int> ans;
    for(int a0 = 0; a0 < 2; a0++) {
        for(int a1 = 0; a1 < 2; a1++) {
            int x = a0, y = a1, z = 0;
            ans.push_back(x);
            ans.push_back(y);
            for(int i = 1; i < N - 1; i++) {
                z = x ^ y ^ S[i];
                x = y, y = z;
                ans.push_back(z);
            }
            if( (ans[0] ^ ans[N - 1] ^ ans[N - 2] ^ S[N - 1] == 0) &&
                (ans[1] ^ ans[0] ^ ans[N - 1] ^ S[0] == 0)) {
                for(auto x : ans) cout << (x ? 'S' : 'W');
                cout << endl;
                return 0;
            }
            ans.clear();
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 1528
import java.util.Scanner;
public class Main {

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

        String a=scan.next();
        String b=scan.next();
        String c=scan.next();

        int []anum=new int [a.length()];
        int []bnum=new int[b.length()];
        int []cnum=new int[c.length()];


        anum=strToint(a);
        bnum=strToint(b);
        cnum=strToint(c);
        int []cnt=new int[3];
        String ans;
        int tmp=0;
        while(true){
            if(tmp==0){
                if(cnt[0]>=a.length()){
                    ans="A";
                    break;
                }
                tmp=anum[cnt[0]];
                cnt[0]++;
            }
            else if(tmp==1){
                if(cnt[1]>=b.length()){
                    ans="B";
                    break;
                }
                tmp=bnum[cnt[1]];
                cnt[1]++;
            }
            else if(tmp==2){
                if(cnt[2]>=c.length()){
                    ans="C";
                    break;
                }
                tmp=cnum[cnt[2]];
                cnt[2]++;
            }


        }
        System.out.println(ans);
        //System.out.println(cnt[0]+" "+cnt[1]+" "+cnt[2]);


    }
     static int[] strToint(String  a){

        int []ans=new int[a.length()];
        for(int i=0;i<a.length();i++){
            ans[i]=a.charAt(i)-'a';
        }
        return ans;
    }
}


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

const int N = 3e5 + 10;

int n;
int times[N], cnt[N], times2[N];

int get(int x) {
  return times[x] + (times2[x - 1]) / x;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    ++cnt[x];
  }
  for (int i = 0; i <= n; ++i) {
    if (cnt[i] > 0) {
      ++times[cnt[i]];
      times2[cnt[i]] += cnt[i];
    }
  }
  for (int i = n; i >= 0; --i)
    times[i] += times[i + 1];
  for (int i = 1; i <= n; ++i)
    times2[i] += times2[i - 1];
  for (int k = 1; k <= n; ++k) {
    int low = 0, high = n / k + 1;
    while (low + 1 < high) {
      int mid = (low + high) / 2;
      if (get(mid) >= k)
        low = mid;
      else
        high = mid;
    }
    printf("%d\n", low);
  }
  return 0;
}

Measured memory_bytes: 4352
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::vec::Vec;
use std::{vec, cmp, num};


struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

// create Vec<char> from String
#[allow(dead_code)]
fn to_chars(s: String) -> vec::Vec<char> {
    let mut cs = s.chars();
    let mut res = vec::Vec::new();
    while let Some(c) = cs.next() {
        res.push(c);
    }
    res
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let a: i32 = sc.read();
    let b: i32 = sc.read();
    if a + b >= 10 {
        println!("error");
    } else {
        println!("{}", a + b);
    }
}

Measured memory_bytes: 4352
#和風いろはちゃんイージー
a,b,c = [int(x) for x in input().split()]
if (a==7 and b==5 and c==5) or (a==5 and b==7 and c==5) or (a==5 and b==5 and c==7): print('YES')
else: print('NO')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#ifdef CURIOUSCAT
#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)
#else
#define Pr(f,...)
#endif

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=1e6+50;

int P;
int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
void upd(int &a,int b) { a=a+b>=P?a+b-P:a+b; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
int gcd(int a,int b){ return !b?a:gcd(b,a%b); }

int C(int n,int m) { 
	if(m<0||m>n)return 0;
	if(m==0)return 1;
	if(m==1)return n;
	if(m==2)return n&1?mul(n,(n-1)/2):mul(n/2,n-1);
}

int n,dp[6005][2005],ans;
int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
#endif
	read(n); read(P); 
	dp[0][0]=1;
	rep(i,0,n*3)rep(j,0,n){
		upd(dp[i+1][j],dp[i][j]); 
		upd(dp[i+2][j+1],mul(dp[i][j],C(i+1,1))); 
		upd(dp[i+3][j+1],mul(dp[i][j],mul(C(i+2,2),2))); 
	}
	rep(j,0,n)ans=add(ans,dp[n*3][j]); 
	cout<<ans<<endl;
	return 0; 
}


Measured memory_bytes: 50652
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define rusha scanf("%d",&n);rep(i,1,n)scanf("%d",&a[i]);
#define rushb scanf("%d",&t);while(t--)
#define debug(x) cout<<" L-B-W-- "<<x<<" --N-B\n"
#define pb push_back
#define pii pair<int,int>
#define vii vector<int>
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof a)
#define all(x) (x.begin(),x.end())
#define judgef printf("%s\n",f?"Yes":"No")
#define Judgef printf("%s\n",f?"YES":"NO")
#define sz(x) ((int)(x).size())
#define sf(x) (sizeof(x))
using namespace std;
typedef long long ll;
typedef double db;
const double pai = acos(-1.0);
const double eps = 1e-8;
const int mod=998244353;
//const int mod=1e9+7;
const int inf=1e9+7;
//const ll inf=0x7f7f7f7f1234abcd;
const int maxn=2e5+10;
inline ll ksm(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;x=x*x%mod;y>>=1;}return res;}
inline ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}
inline ll lcm(ll a,ll b){return a * b / __gcd(a, b);}
int t,n,m,k;
int main() {
    int n;
    cin >> n;
    vector<tuple<bool, int, int, int>> v(n);
    for (auto &e : v) {
    string s;
    cin >> s;
    int l = 0, r = 0;
    for (auto c : s) {
      if (c == '(') {
        l++;
      } else if (l > 0) {
        l--;
      } else {
        r++;
      }
    }
    e = {l <= r, l <= r ? -l : r, l, r};
    }
    sort(v.begin(), v.end());

    bool valid = true;
    int h = 0;
    //for (auto [a, b, l, r] : v)  cerr << a << ' ' << b << ' ' << l << ' ' << r << endl;
    for (auto [a, b, l, r] : v) {
     //cerr << a << ' ' << b << ' ' << r << ' ' << l << endl;
    if (h < r) {
      valid = false;
      break;
    }
    h -= r;
    h += l;
    }
    if (h != 0) valid = false;
    cout << (valid ? "Yes" : "No") << endl;
}


Measured memory_bytes: 18660
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>
#include <sstream>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) x.begin(),x.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

//pairと順列全探索
int main(){
    int N;
    long double cnt=0;
    cin >> N;
    vector<pair<ll,ll>> A(N);

    for(int i = 0;i < N;i++)
        cin >> A[i].first >> A[i].second;

    vector<int> d(N);
    for(int i = 0;i < N;i++)
        d.at(i) = i;
    

    long double goukei = 0.0,ave;

    do{
        for(int i = 1;i < N;i++){
            goukei += hypot(A[d[i-1]].first - A[d[i]].first,A[d[i-1]].second - A[d[i]].second);
        }
        cnt++;    
    }while(next_permutation(d.begin(),d.end()));


   printf("%.10Lf\n",goukei/cnt); 
}


Measured memory_bytes: 3712
def solve():
    N = input()
    
    INF = 10 ** 32
    
    dp = [[INF, INF] for i in range(len(N) + 1)]
    dp[0][0] = 0
    
    for i, x in enumerate(int(n) for n in N[::-1]):
        ni = i + 1
        dp[ni][0] = min(dp[i][0] + x, dp[i][1] + x)
        dp[ni][1] = min(dp[i][0] + 11 - x, dp[i][1] + 9 - x)
    
    ans = min(dp[-1])
    
    print(ans)

solve()

Measured memory_bytes: 171008
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    string s;
    cin >> n >> s;
    set<string> st1;
    for(int i = 0; i < n; i++){
        set<string> st2 = st1;
        for(auto stt: st2){
            if (stt.size() == 3) continue;
            if (st2.find(stt+s[i]) == st2.end()) st1.insert(stt+s[i]);
        }
        st1.insert({s[i]});
    }
    int ans = 0;
    for(auto stt: st1){
        if (stt.size() == 3) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3800
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

ll x,y;

void run() {
	scanf("%lld%lld",&x,&y);

	ll ret=abs(abs(x)-abs(y));
	if(x>=0) {
		if(y>=x) {
			//nothing
		} else if(y>0) {
			ret+=2;
		} else {
			ret++;
		}
	} else {
		if(y<=x) {
			ret+=2;
		} else if(y<=0) {
			//nothing
		} else {
			ret++;
		}
	}
	printf("%lld\n",ret);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 764
#!/usr/bin/env python3
import sys


def solve(N: int, A: "List[int]", B: "List[int]"):
    s = 0
    for i, b in enumerate(B):
        if A[i] + A[i + 1] <= b:
            s += A[i] + A[i + 1]
            A[i] = 0
            A[i + 1] = 0
            B[i] = 0
    for i, b in enumerate(B):
        sub = min(A[i], B[i])
        A[i] -= sub
        B[i] -= sub
        s += sub
        sub = min(A[i + 1], B[i])
        A[i + 1] -= sub
        B[i] -= sub
        s += sub
    print(s)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N + 1)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 19504
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct D{int i,s;}D;
D res[40];
int N,s[30],r,i,j,c,f;
char S[1000],*p;

int cmp(const void *a,const void *b)
{
	D*x=(D*)a,*y=(D*)b;
	return x->s==y->s?x->i-y->i:y->s-x->s;
}

int main()
{
	for(;scanf("%d\n",&N),N;)
	{
		for(j=0;j<N;j++)
		{
			gets(S);
			p=strtok(S," ");
			res[j].i=atoi(p);
			for(c=0;(p=strtok(NULL," "))!=NULL;c++)
			{
				s[c]=atoi(p);
			}
			for(i=r=0,f=1;i<c;f++)
			{
				if(f==10)
				{
					for(;i<c;i++)r+=s[i];
				}
				else if(s[i]==10)
				{
					r+=s[i]+s[i+1]+s[i+2];
					i++;
				}
				else if(s[i]+s[i+1]==10)
				{
					r+=10+s[i+2];
					i+=2;
				}
				else
				{
					r+=s[i]+s[i+1];
					i+=2;
				}
			}
			res[j].s=r;
		}
		qsort(res,N,sizeof(D),cmp);
		for(j=0;j<N;j++)
			printf("%d %d\n",res[j].i,res[j].s);
	}
	return 0;
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b&&b==c) cout << 1 << endl;
  else if(a!=b&&b!=c&&c!=a) cout << 3 << endl;
  else cout << 2 << endl;
}

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

using namespace std;


int main(){

    set<int>b;

    int N;

    cin >> N;

    for(int i = 0;i < N;i++){
    	int A;
    	cin >> A;
    	if(b.count(A) !=0){
    		b.erase(A);
    	}else{
    		b.insert(A);
    	}
    }

    cout  << b.size() << endl;


	return 0;

}


Measured memory_bytes: 4864
import java.util.Scanner;

public class Main {
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextInt();
        sc.close();
        final int limit = 1000000007;
        long power = 1;
        for(int i = 1 ; i <= n;i++)
            power = (power * i) % limit;
        System.out.println(power);
    }
}


Measured memory_bytes: 21844
while True:
  r,c = map(int,input().split())
  if not r:
    break
  lst = [list(map(int,input().split())) for i in range(r)]
  dic = [0 for i in range(2 ** r)]
  for i in range(c):
    num = 0
    for j in range(r):
      num *= 2
      num += lst[j][i]
    dic[num] += 1
  ans = 0
  for i in range(2 ** r):
    ret = 0
    for j in range(2 ** r):
      num = (i ^ j)
      cnt = 0
      for k in range(r):
        cnt += num % 2
        num //= 2
      ret += max(cnt, r - cnt) * dic[j]
    ans = max(ans, ret)
  print(ans)



Measured memory_bytes: 6980
#!/usr/bin/env python3
import sys, itertools


def solve(N: int, K: int, x: "List[int]", y: "List[int]"):
    mn = 1e25
    for X in itertools.combinations(x, 2):
        for Y in itertools.combinations(y, 2):
            if len([xx for (xx, yy) in zip(x, y) if (X[0]-xx)*(X[1]-xx)<=0 and (Y[0]-yy)*(Y[1]-yy)<=0]) >= K:
                mn = min(mn, abs(X[0] - X[1]) * abs(Y[0] - Y[1]))
    print(mn)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, K, x, y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 48092
#include <iostream>
#include <algorithm>
#include <string>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
	int n, p, i;
	ll r, dd, k[200003] = {}, mr[10003] = {}, ans;
	string s;

	scanf("%d%d", &n, &p);
	cin >> s;

	if (p == 2) {
		ans = 0;
		for (i = 0; i < n; i++) {
			if ((s[i] - '0') % 2 == 0) {
				ans += i + 1;
			}
		}
		printf("%lld\n", ans);
		return 0;
	}

	if (p == 5) {
		ans = 0;
		for (i = 0; i < n; i++) {
			if ((s[i] - '0') % 5 == 0) {
				ans += i + 1;
			}
		}
		printf("%lld\n", ans);
		return 0;
	}

	r = 0;
	dd = 1;
	for (i = n - 1; i >= 0; i--) {
		r = (r + (s[i] - '0') * dd % p) % p;
		dd = dd * 10 % p;
		k[i] = r;
	}

	mr[0] = 1;
	for (i = 0; i < n; i++) {
		mr[k[i]]++;
	}

	ans = 0;
	for (i = 0; i < p; i++) {
		ans += mr[i] * (mr[i] - 1) / 2;
	}

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

	return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	string s, t;
	cin >> s >> t;

	int n, m;
	n = s.length();
	m = t.length();

	int dp[n+1][m+1];
	// dp[i][j] : sのi文字目、tのj文字目のLCSの長さ
	rep(i, n+1) rep(j, m+1) dp[i][j] = 0;

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(s[i-1] == t[j-1]){
				dp[i][j] = dp[i-1][j-1] + 1;
			}else{
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}

	// dp配列を逆からたどってLCSを作成する
	// LCSの長さが更新されたときの文字を追加していく

	string ans = "";
	int x = n;
	int y = m;
	while(x > 0 && y > 0){
		if(dp[x][y] == dp[x-1][y]){
			x--;
		}else if(dp[x][y] == dp[x][y-1]){
			y--;
		}else{
			x--;
			y--;
			ans.push_back(s[x]);
		}
	}

	reverse(ans.begin(), ans.end());
	cout << ans << endl;
}


Measured memory_bytes: 35584
#include<iostream>
#include<string>
#include<stack>
#include<algorithm>
#include<queue>
#include<cmath>
#include<numeric>
#include<map>
#include<set>
#include<vector>
#include<list>
#include<iomanip>
#include<functional>
#include<bitset>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI M_PI
using namespace std;
typedef long long ll;

int main(){
    cout<<fixed<<setprecision(15);
    int a,b,h,m;
    cin>>a>>b>>h>>m;

    int time = h*60 + m;
    double radhour = 2*PI/720 *time;
    double radminute = 2*PI/60 *m;
    double rad = abs(radhour -radminute);
    if(rad>PI) rad = 2*PI - rad;
    double c = pow(a,2) + pow(b,2) - 2*a*b *cos(rad);
    cout<<sqrt(c)<<endl;


    return 0;
}

Measured memory_bytes: 4128
#!/usr/bin/env python3
#ABC124 D
from itertools import accumulate
import bisect
n,k = map(int,input().split())
s = list(map(int,list(input())))
#0→1 または 1→0 の切り替わるときに連続する数を入れるlist
L = [0] if s[0] == 1 else [0,0]
cnt = 1
for i in range(1,n):
    if s[i-1] != s[i]:
        L += [cnt]
        cnt = 0
    cnt += 1
L += [cnt,0]
L = list(accumulate(L))
ans = 0
if len(L) - 2*k - 1 < 1:
    print(L[-1])
    quit()
for i in range(0,len(L)-2*k-1,2):
    ans = max(ans,L[i+2*k+1] - L[i])
print(ans)


Measured memory_bytes: 8512
#include <stdio.h>
#define MAX 101

int main()
{
  int i, j;
  int n, u, v, k;
  int Adj[MAX][MAX];

  scanf("%d", &n);
  for(i = 1; i <= n; i++)
    {
      for(j = 1; j <= n; j++)
	{
	  Adj[i][j] = 0;
	}
    }
  for(i = 1; i <= n; i++)
    {
      scanf("%d %d", &u, &k);
      for(j = 1; j <= k; j++)
	{
	  scanf("%d", &v);
	  Adj[u][v] = 1;
	}
    }

  for(i = 1; i <= n; i++)
    {
      for(j = 1; j < n; j++)
	{
	  printf("%d ", Adj[i][j]);
	}
      printf("%d\n", Adj[i][n]);
    }

  return 0;
}

Measured memory_bytes: 632
#pragma GCC optimize ("O3")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <queue>
#include <unordered_map>
#define lld long long int
#define dbg1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define dbg2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define dbg3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
vector <int> adj[(int)2e3+5];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,x,y;
	cin >> n >> x >> y;
	for(int i=1;i<n;i++)
	{
		adj[i].push_back(i+1);
		adj[i+1].push_back(i);
	}
	adj[x].push_back(y);
	adj[y].push_back(x);
	vector <int> m(n+1,0);
	queue <int> q;
	for(int i=1;i<=n;i++)
	{
		vector <int> visited(n+1,0);
		q.push(i);
		visited[i]=1;
		vector <int> d(n+1,0);
		while(!q.empty())
		{	
			int v = q.front();
			q.pop();
			for(int u : adj[v])
			{
				if(!visited[u])
				{
					visited[u]=1;
					q.push(u);
					d[u]=d[v]+1;
					m[d[u]]++;
				}
			}
		}
	}
	for(int i=1;i<n;i++)
	{
		cout <<(m[i]/2) << "\n";
	}
}

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

int main()
{
    int n,m;
    std::cin >> n >> m;
    int min = INT_MAX;
    int max = 0;
    for (int i = 0; i < m; i++) {
        int l,r;
        std::cin >> l >> r;
        if (min > r) min = r;
        if (max < l) max = l;
    }

    std::cout << std::max(min - max + 1, 0) << std::endl;
    return 0;
}


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

char prime[10001];
int m[15][1121][500];

int get_sum(int num, int sum, int n){
    
	int i, j, ans;
    
    if (num == 0 && sum == 0){
        return (1);
	}
    if (num == 0 || sum <= 0 || sum < n){
        return (0);
    }
    
    if (n < 500){
        if (m[num][sum][n] == -1){
            m[num][sum][n] = (prime[n] ? get_sum(num - 1, sum - n, n + 1) : 0) + get_sum(num, sum, n + 1);
        }
        return(m[num][sum][n]);
    }
    
    return ((prime[n] ? get_sum(num - 1, sum - n, n + 1) : 0) + get_sum(num, sum, n + 1));
}

int main(void)
{
	int i, j;
	int n;
	int num, sum;
    
	for (i = 3; i <= 10000; i += 2){
		prime[i] = 1;
	}
	prime[2] = 1;
	
	for (i = 3; i <= 100; i += 2){
		if (prime[i] == 1){
			for (j = 3; j <= 10000 / i; j += 2){
				prime[i * j] = 0;
			}
		}
	}
    
    memset(m, -1, sizeof(m));
	while (1){
		scanf("%d%d", &sum, &num);
        
		if (num == 0 && sum == 0){
            break;
		}
		printf("%d\n", get_sum(num, sum, 2));
	}
	
	return (0);
}

Measured memory_bytes: 32000
S = input()
L = len(S)
flg = 0
if L % 2 == 1:
    flg = 1
for i in range(L):
    if i % 2 == 0:
        if S[i] != 'h':
            flg = 1
    else:
        if S[i] != 'i':
            flg = 1
if flg == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
# include <bits/stdc++.h>
# define rep(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
const int maxn = 100010;
int read(){
    char c=getchar(); int x=0;
    for(;c<'0'||c>'9';c=getchar());
    for(;c>='0'&&c<='9';c=getchar())x=x*10+c-'0';
    return x;
}
int a[maxn];
int n;
int main(){
    n=read();
    rep(i,0,n-1)a[i]=read();
    sort(a+0,a+n);
    reverse(a+0,a+n);
    int p=0,y=0;
    for(;p+1<n&&a[p+1]>p+1;++p);
    for(;y<n&&a[y]>p;++y);
    if ((a[p]-p)&1 && (y-p)&1) puts("Second");
    else puts("First");
    return 0;
}

Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int Max = 1000;
		int[][] intdata = new int[Max][3]; // 計算に使われる2つの整数の値と計算結果を格納するための配列
		String input = "";
		String[] inputdata = new String[3]; // 入力されたデータを半角スペースで区切って格納するための配列
		String[] opdata = new String[Max]; // 計算に使われる2つの整数の値を計算するための演算子を格納するための配列
		boolean judge = true; // 入力されたデータが条件を満たしているかを判定するための変数
		int n = 0; // データセットの数を示す変数 ex) 「2 + 3 」で1つのデータセット

		out: for (int i = 0; i <= intdata.length; i++) {
			input = sc.nextLine();
			inputdata = input.split(" ");
			intdata[i][0] = Integer.parseInt(inputdata[0]);
			opdata[i] = inputdata[1];
			intdata[i][1] = Integer.parseInt(inputdata[2]);

			if ((intdata[i][0] < 0 || intdata[i][0] > 20000)
					|| (intdata[i][1] < 0 || intdata[i][1] > 20000)) {
				judge = false;
				break out;
			}
			if ((intdata[i][1] == 0) && (opdata[i]).equals("/")) {
				judge = false;
				break out;
			}

			if ((opdata[i]).equals("+")) {
				intdata[i][2] = intdata[i][0] + intdata[i][1];
				n++;
			} else if ((opdata[i]).equals("-")) {
				intdata[i][2] = intdata[i][0] - intdata[i][1];
				n++;

			} else if ((opdata[i]).equals("*")) {
				intdata[i][2] = intdata[i][0] * intdata[i][1];
				n++;
			} else if ((opdata[i]).equals("/")) {
				intdata[i][2] = intdata[i][0] / intdata[i][1];
				n++;
			}

			else if ((opdata[i]).equals("?")) {
				break out;
			} else {
				judge = false;
				break out;
			}

		}

		if (judge == true) {
			for (int i = 0; i < n; i++) {
				System.out.println(intdata[i][2]);

			}
		}
	}
}



Measured memory_bytes: 26212
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <queue>

using namespace std;

int N;
vector<double> P;
vector<vector<double>> table;

int main() {
  //
  cin >> N;
  P.resize(N+1);
  for (int i = 0; i < N; ++i) {
    cin >> P[i];
  }

  //

  // 最初の i 枚を使って、表が j 枚となる確率
  table.resize(N+1);
  for (int i = 0; i <= N; ++i) {
    table[i] = vector<double>(N+1, 0);
  }


  table[0][0] = 1.;
  for (int i = 0; i < N; ++i) {
    table[i+1][0] = table[i][0] * (1 - P[i]);

    for (int j = 1; j <= N; ++j) {
      table[i+1][j] = table[i][j] * (1 - P[i]) + table[i][j-1] * P[i];
    }
  }

//  for (int i = 0; i <= N; ++i) {
//    for (int j = 0; j <= N; ++j) {
//      cout << table[i][j] << " ";
//    }
//    cout << endl;
//  }


  double ans = 0;
  for (int i = ceil(N/2.0); i <= N; ++i) {
    ans += table[N][i];
  }
  cout << fixed << setprecision(10);
  cout << ans << endl;

  return 0;
}




Measured memory_bytes: 70656
#include <stdio.h>
#include <algorithm>

using namespace std;
void solve();
int main() {
	solve();
#ifdef DBG
	while (true);
#endif
}

void solve() {
	int v[3], r = 0;
	scanf("%d %d %d", v, v + 1, v + 2);
	sort(v, v + 3);
	r += v[2] - v[1];
	r += (v[1] - v[0]) / 2;
	r += (v[1] - v[0]) % 2 * 2;
	printf("%d\n", r);
}

Measured memory_bytes: 128
class rightnumber():
    def __init__(self):
        self.top = [[0, 0, 0, 0], [4, 2, 3, 5], [4, 6, 3, 1], [1, 2, 6, 5], [1, 5, 6, 2], [1, 3, 6, 4], [4, 5, 3, 2]]
        self.front =[[0, 0, 0, 0], [2, 3, 5, 4], [6, 3, 1, 4], [2, 6, 5, 1], [5, 6, 2, 1], [3, 6, 4, 1], [5, 3, 2, 4]]
inp = list(map(int, input().split()))
q = int(input())
rightnumbers = rightnumber()
top= [0]*q
front = [0]*q
key1 = [0]*q
key2 = [0]*q
for n in range(q):
    top[n], front[n] = map(int, input().split())
    for k in range(6):
        if top[n] == inp[k]:
            key1[n] = k;
        if front[n] == inp[k]:
            key2[n] = k
for n in range(q):
    for i in range(1, 7):
        for j in range(0, 4):
            if rightnumbers.top[i][j] == key1[n]+1 and rightnumbers.front[i][j] == key2[n]+1:
                print(inp[i-1])


Measured memory_bytes: 5604
#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 long double ld;
typedef pair<int,int> P;
constexpr int mod = 1e9 + 7;

int main(){ 
  string s;
  cin >> s;
  int n = s.size();

  vector<ll> dp(5, 0);

  dp[0] = 1;

  for (int i = 0; i < n; i++) {
    vector<ll> ndp(5, 0);

    for (int j = 0; j < 4; j++) {
      if (s[i] == '?') (ndp[j] += dp[j] * 3 % mod) %= mod; 
      else (ndp[j] += dp[j]) %= mod;
    }
    
    if (s[i] == '?' || s[i] == 'A') (ndp[1] += dp[0]) %= mod;
    if (s[i] == '?' || s[i] == 'B') (ndp[2] += dp[1]) %= mod;
    if (s[i] == '?' || s[i] == 'C') (ndp[3] += dp[2]) %= mod;
    swap(dp, ndp);
  }

  cout << dp[3] << endl;
  return 0;
} 

Measured memory_bytes: 640
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
using namespace std;

const int width = 10;
const int dx[12] = {-1, 0, 1, -2, 2, -2, 2, -2, 2, -1, 0, 1};
const int dy[12] = {-2, -2, -2, -1, -1, 0, 0, 1, 1, 2, 2, 2};

bool check(vector<pair<int, int>> &spr, int px, int py, int k) {
    if (0 <= k) {
        if ((int)spr.size() <= k) {
            return true;
        }
        if (1 < abs(spr[k].first - px) || 1 < abs(spr[k].second - py)
            || px < 0 || 10 <= px || py < 0 || 10 <= py) {
            return false;
        }
    }
    bool ret = false;
    for (int i=0; i<12; ++i) {
        ret |= check(spr, px + dx[i], py + dy[i], k + 1);
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false);

    int px, py, n;
    vector<pair<int, int>> spr;

    while (1) {
        cin >> px >> py;
        if (px == 0 && py == 0) break;
        cin >> n;
        spr.clear();
        spr.resize(n);
        for (int i=0; i<n; ++i) {
            cin >> spr[i].first >> spr[i].second;
        }
        cout << (check(spr, px, py, -1) ? "OK" : "NA") << endl;
    }

    return 0;
}

Measured memory_bytes: 1188
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n; cin >> n;
	set<string> S;
	rep(i, 0, n) {
		string a, b; cin >> a >> b;
		if (a == "insert") {
			S.insert(b);
		}
		else {
			if (S.count(b))cout << "yes" << endl;
			else cout << "no" << endl;
		}
	}
	return 0;
}

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

#define endl '\n'

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

    int n,m; cin >> n >> m;
    if (n & 1){
        int l = 1, r = n-1;
        for (int i=0; i<m; i++) cout << l++ << " " << r-- << endl;
    } else{
        vector<pair<int, int>> ans;
        int l = 1, r = n;
        int sla = (n-1)/2;
        int resto = (sla % 2);
        sla /= 2;
        for (int i=0; i < sla + resto; i++){
            ans.push_back({l++, r--});
        }
        r--;
        for (int i=0; i < sla; i++){
            ans.push_back({l++, r--});
        }
        for (int i=0; i<m; i++) cout << ans[i].first << " " << ans[i].second << endl;
    }
}

Measured memory_bytes: 4212
import std.stdio,std.array,std.conv;
void main(){
  string[] s=split(readln()); // splitで文字列を文字列の配列に切り分け
  int x=to!int(s[0]); // 第0要素を整数に変換
  int y=to!int(s[1]);
  int z=to!int(s[2]);
  
  int ans=to!int((x-z)/(y+z));
  writeln(ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>

int n, m;
int t[3];

int f( int a, int b, int c )
{
  	if( !a && !b ) return 0;
	
	if( c & 1 ) return f( a >> 1, b >> 1, c >> 1 );
	if( b & 1 ) return f( c >> 1, b >> 1, a >> 1 ) + 1 + f( ( a | b | c ) >> 1, 0, 0 );
	if( a & 1 ) return f( a >> 1, b >> 1, c >> 1 ) + 2 + 2 * f( ( a | b | c ) >> 1, 0, 0 );
}       

int main()
{
	while( std::cin >> n >> m, n | m ){
		memset( t, 0, sizeof( t ) );
	
		for( int i = 0; i < 3; i++ ){
			int a;
			std::cin >> a;
			
			for( int j = 0; j < a; j++ ){
				int b;
				std::cin >> b;
				
				t[i] |= 1 << ( b - 1 );
			}
		}
		
		int ans = std::min( f( t[0], t[1], t[2] ), f( t[2], t[1], t[0] ) );
		
		if( ans <= m ){
		 	std::cout << ans << std::endl;
		}
		else{
		 	std::cout << -1 << std::endl;
		}
	}

 	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define REP1(i,n) for(int i=1; i<=(int)(n); i++)
#define SORT(v) sort(v.begin(), v.end())
#define REVERSE(v)  reverse(v.begin(), v.end())
using namespace std;

int main() {
  int K; cin>>K;
  if(K%2==0) cout<<(K/2)*(K/2)<<endl;
  else cout<<(K/2)*((K/2)+1)<<endl;
}

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


class Graph:
    def __init__(self, n, directed=False, decrement=True, destroy=False, edges=[]):
        self.n = n
        self.directed = directed
        self.decrement = decrement
        self.destroy = destroy
        self.edges = [set() for _ in range(self.n)]
        self.parent = [-1]*self.n
        self.info = [-1]*self.n
        for x, y in edges:
            self.add_edge(x,y)

    def add_edge(self, x, y):
        if self.decrement:
            x -= 1
            y -= 1
        self.edges[x].add(y)
        if self.directed == False:
            self.edges[y].add(x)

    def add_adjacent_list(self, i, adjacent_list):
        if self.decrement:
            self.edges[i] = set(map(lambda x: x - 1, adjacent_list))
        else:
            self.edges[i] = set(adjacent_list)

    def bfs(self, start=1, goal=-1, time=0, save=False):
        """
        :param start: スタート地点
        :param goal: ゴール地点
        :param save: True = 前回の探索結果を保持する
        :return: （ループがあっても）最短距離。存在しなければ -1
        """
        if self.decrement:
            start -= 1
            goal -= 1
        if not save:
            self.parent = [-1] * self.n
        p, t = start, time
        self.parent[p] = -2
        next_set = deque([(p, t)])

        while next_set:
            p, t = next_set.popleft()
            for q in self.edges[p]:
                if self.parent[q] != -1:
                    continue
                if q == goal:
                    return t + 1
                self.parent[q] = p
                next_set.append((q, t + 1))
        return -1

    def connection_counter(self):
        """
        :return: 連結成分の個数。有効グラフではあまり意味がない。
        """
        cnt = 0
        self.parent = [-1] * self.n
        for start in range(self.n):
            if self.parent[start] == -1:
                cnt += 1
                self.bfs(start + self.decrement, save=True)
        return cnt



######################################################

N, M = map(int, input().split())
graph = Graph(N, directed=False, decrement=True, destroy=False)
for _ in range(M):
    x, y, z = map(int, input().split())
    graph.add_edge(x, y)

print(graph.connection_counter())

Measured memory_bytes: 112880
#include<bits/stdc++.h>
using namespace std;
int a[10005],c[105][105];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int cc;
	scanf("%d",&cc);
	for(int i=1;i<=cc;i++)scanf("%d",&a[i]);
	int x=1,y=1,k=1;
	while(x<=n)
	{
		c[x][y]=k;
		a[k]--;
		if(a[k]==0)k++;
		if(x&1&&y==m)x++;
		else if(!(x&1)&&y==1)x++;
		else if(x&1)y++;
		else y--;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			printf("%d ",c[i][j]);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, k, m;

    while (cin >> n >> k >> m && n) {
        int x = 0;
        FOR(i,2,n-1){
            int y = (k-1) % i;
            x += y+1;
            if (x >= i) x -= i;
        }
        cout << (x + m) % n + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3036
def getlist():
    return list(map(int, input().split()))

N = int(input())
a = getlist()
a = sorted(a)

if N % 3 != 0:
    if a[-1] >= 1:
        print("No")
    else:
        print("Yes")
else:
    m = int(N // 3)
    if a[0] == a[m - 1] and a[m] == a[2 * m - 1] and a[2 * m] == a[3 * m - 1]:
        if a[0] ^ a[m] == a[2 * m] and a[m] ^ a[2 * m] == a[0] and a[2 * m] ^ a[0] == a[m]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 60784