akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

Graph G;
int color[100050];

bool dfs(int v, int c) {
  color[v] = c;
  for (auto e : G[v]) {
    if (color[e] == c) return false;
    if (color[e] == 0 && !dfs(e, -c)) return false;
  }
  return true;
}

int main(void){
  ll n,m; cin >> n >> m;
  G.assign(n,vector<int>());
  FOR(i,0,m-1){
    int a,b; cin >> a >> b;
    --a; --b;
    G[a].PB(b);
    G[b].PB(a);
  }
  ll color1 = 0;
  if(dfs(0,1)){
    FOR(i,0,n-1){
      if(color[i]==1) ++color1;
    }
    cout << color1 * (n-color1) - m << "\n";
  } else {
    cout << n*(n-1)/2 - m << "\n";
  } 
}

Measured memory_bytes: 6528
n = int(input())
word_dic = {}
for i in range(n):
    word = input()
    if word in word_dic.keys():
        word_dic[word] += 1
    else:
        word_dic[word] = 1
m = int(input())
for i in range(m):
    word = input()
    if word in word_dic.keys():
        word_dic[word] -= 1
        if word_dic[word] < 1:
            word_dic.pop(word)

if len(list(word_dic.keys())) == 0:
    print(0)
else:
    word_dic = sorted(word_dic.items(), key=lambda x: x[1])
    print(word_dic[-1][1])


Measured memory_bytes: 3064
def input_n
  gets.to_i               # 単一整数
end

def input_s
  gets.chomp              # 文字列。chompを付けないと改行文字がついてくる
end

def input_a
  gets.split.map(&:to_i)  # スペースで区切られた複数の整数
end

def input_o(num)
  num.times.map { gets.to_i }  # 縦に並んだ複数の整数。たまにある
end

def output_f(num)
  puts sprintf("%.12f", num)
end

n = input_n
num = 0
while num < n
  num += 1000
end
puts num - n


Measured memory_bytes: 14312
h,w = map(int, input().split())

src = [input() for i in range(h)]

ans = []
for row in src:
    ans.append(list(row))
    
for i in range(h):
    for j in range(w):
        if src[i][j] == '#': 
            continue
        c = 0
        if i > 0:
            if j > 0 and src[i-1][j-1] == '#': c += 1
            if src[i-1][j] == '#': c += 1
            if j < w-1 and src[i-1][j+1] == '#': c +=1
        if j > 0 and src[i][j-1] =='#' : c +=1
        if j < w-1 and src[i][j+1] == '#': c +=1
        if i < h-1:
            if j > 0 and src[i+1][j-1] == "#": c +=1
            if src[i+1][j] == '#': c += 1
            if j<w-1 and src[i+1][j+1] == '#' : c += 1
        ans[i][j] = c
        
for row in ans:
    print (''.join(list(map(str,row))))
                    
    


Measured memory_bytes: 3064
import java.util.Scanner;
public class Main{
    public static int NUM_NUMBERS = 5;
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int[] numbers = new int[NUM_NUMBERS];
	for (int i = 0; i < NUM_NUMBERS; i++) {
	    String input = scan.next();
	    numbers[i] = Integer.parseInt(input);
	}
	int width = numbers[0];
	int height = numbers[1];
	int x = numbers[2];
	int y = numbers[3];
	int r = numbers[4];
	if (r <= x && x <= width - r && r <= y && y <= height - r) {
	    System.out.println("Yes");
	} else {
	    System.out.println("No");
	}
    }
}

Measured memory_bytes: 26264
#include<cstdio>
#include<vector>
#include<cmath>
using namespace std;
struct node
{
	double x,y,z;
};
struct node x[21];
vector<double>a;
int b[25],i,n,m,j;
double d[21][21],maxx=0,ans;

double dis(int i,int j)
{
 return 
((x[i].x-x[j].x)*(x[i].x-x[j].x)+(x[i].y-x[j].y)*(x[i].y-x[j].y)+(x[i].z-x[j].z)*(x[i].z-x[j].z));
}
void dfs(int v,int k)
{
	int x,i,j,t;
 b[v]=1;
 if(k==m)
 {
	ans=0;
	for(i=0;i<a.size();i++)
	{
		x=a[i];
		for(j=0;j<a.size();j++)
			if(j!=i)
			{
				t=a[j];
				ans=ans+d[x][t];
			}
	}
	if(ans/2>maxx)maxx=ans/2;
	return;
 }
 a.push_back(v); k++;
 if(v+1<=n)dfs(v+1,k);
 a.pop_back(); k--;
 if(v+1<=n)dfs(v+1,k);
 b[v]=0;
}
int main()
{
    scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%lf%lf%lf",&x[i].x,&x[i].y,&x[i].z);
    for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			d[i][j]=dis(i,j);
	dfs(0,0);
	printf("%lf\n",maxx);
	return 0;
}

Measured memory_bytes: 824
n=int(input())
import time
T=time.time()
data_set=[0 for i in range(n)]
for i in range(n):
    a=list(map(int,input().split()))
    a.append(-1)
    data_set[i]=a
index=[0 for i in range(n)]
ans=-1
flag=True
semi=False
now=[data_set[i][index[i]] for i in range(n)]
finished=[False for i in range(n)]
while flag:
    visited=[False for i in range(n)]
    sub=False
    for i in range(n):
        #nowリストのうち日ありからi+1番目のものについての一致条件の確認
        K=now[i]
        if now[K-1]==i+1 and not(visited[i] or visited[K-1]) and not(finished[i] or finished[K-1]):
                    visited[i]=True
                    visited[K-1]=True
                    index[i]+=1
                    index[K-1]+=1
                    sub=True
                    if index[i]==n-1:
                        finished[i]=True             
                    now[i]=data_set[i][index[i]]
                    if index[K-1]==n-1:
                        finished[K-1]=True                   
                    now[K-1]=data_set[K-1][index[K-1]]
    if not sub:
        flag=False
    if time.time()-T>1.5:
        flag=False
        semi=True
    ans+=1
judge=True
for i in range(n):
  if finished[i]==False:
    judge=False
    break
if judge:
  print(ans)
else:
  if not semi:
    print(-1)
  if semi:
    print(499500)


Measured memory_bytes: 35056
#include<stdio.h>

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

Measured memory_bytes: 2600
n,k = map(int, input().split())
H = [int(input()) for _ in range(n)]
H.sort()

dif = 10**10
for i in range(n-k+1):
    dif = H[i+k-1]-H[i] if H[i+k-1]-H[i] < dif else dif
print(dif)

Measured memory_bytes: 7384
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
	int k, n;
	cin >> k >> n;
	vector<int> a(n);
	REP(i, n) cin >> a[i];
	tmp = k- a[n-1] + a[0];
	REP(i, n-1) tmp = max(tmp, a[i+1]-a[i]);
	cout << k - tmp << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long int mod=(int)1e9+7;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int h,w;
    cin>>h>>w;
    vector<long long int> dp(w+1,0);
    char ch;
    dp[1]=1;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>ch;
            if(ch=='.'){
                dp[j]=(dp[j]+dp[j-1])%mod;
            }
            else{
                dp[j]=0;
            }
        }
    }
    cout<<dp[w]<<"\n";
}

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

int main(void)
{
    char str[1001], mei[8], p[1001];
    int a, b, i, j, q;
    int c = 0, d = 0, e;
    scanf("%s", str);
    scanf("%d", &q);
    int len = strlen(str);
    char pa[1001], pb[1001];

    for(i = 0; i < q; i++){
        scanf("%s %d %d", mei, &a, &b);
        if(!strcmp(mei, "replace")){
            scanf("%s", p);
        }
        if(!strcmp(mei, "print")){
            c = 0;
            for(j = a; j <= b; j++){
                pa[c++] = str[j];
            }
            pa[c] = '\0';
            printf("%s\n", pa);
        }else if(!strcmp(mei, "reverse")){
            strcpy(pb, str);
            e = a;
            for(j = b; j >= a; j--){
                str[j] = pb[e++];
            }
        }else if(!strcmp(mei, "replace")){
            d = 0;
            for(j =a; j <= b; j++){
                str[j] = p[d++];
            }
        }
    }

    return 0;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//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())

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

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

//main code

int main(int argc, char const* argv[])
{
	LL n;
	cin >> n;
	map<char,int> mp;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		if (s[0] == 'M' or s[0] == 'A' or s[0] == 'R' or s[0] == 'C' or s[0] == 'H') {
			mp[s[0]]++;
		}
	}
	LL ans = 0;
	VL cmb{0,0,1,1,1};
	VL sel{'M','A','R','C','H'};
	do {
		LL tmp = 1;
		for (int i = 0; i < 5; i++) {
			if (cmb[i]) {
				tmp *= mp[sel[i]];
			}
		}
		ans += tmp;
	} while (next_permutation(cmb.begin(),cmb.end()));
	cout << ans << endl;
	return 0;
}



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

char v[1000];
int fr1[26], fr2[26];

int main(){
    string s, t;
    cin >> s >> t;
    for(int i=0; i < s.length(); i++){
        if(v[s[i]]==0){
            v[s[i]] = t[i];
        }else if(t[i] != v[s[i]]){
            cout << "No" << endl;
            return 0;
        }
    }
    for(int i=0; i < s.length(); i++){
        fr1[s[i] - 97]++;
        fr2[t[i] - 97]++;
    }
    sort(fr1, fr1+26);
    sort(fr2, fr2+26);
    for(int i=0; i < 26; i++){
        if(fr1[i] != fr2[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
#define INF 1001001001
using namespace std;
int main() {
	int n, a, b, c;
	cin >> n >> a >> b >> c;
	vector<int> l(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	int ans = INF;
	for (int bit = 0; bit < (1 << (n << 1)); bit++) {
		int cost = 0;
		int ta = 0, tb = 0, tc = 0;
		int ca = 0, cb = 0, cc = 0;
		for (int i = 0; i < n; i++) {
			int e = (bit >> (i * 2) & 3);
			if (e == 1) {
				ta += l[i];
				ca++;
			} else if (e == 2) {
				tb += l[i];
				cb++;
			} else if (e == 3) {
				tc += l[i];
				cc++;
			}
		}
		if (ca == 0 || cb == 0 || cc == 0)
			continue;
		cost += abs(ta - a);
		cost += abs(tb - b);
		cost += abs(tc - c);
		cost += 10 * (ca - 1);
		cost += 10 * (cb - 1);
		cost += 10 * (cc - 1);
		ans = min(ans, cost);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
r,c = map(int, input().split())
arr = []
for i in range(r):
    arr.append(list(map(int, input().split())))
#print(arr)

last_line = []
for j in range(c):
    tmp = 0
    for i in range(r):
        tmp += arr[i][j]
#        print(i,j,arr[i][j],tmp)
    last_line.append(tmp)

#print(last_line)
arr.append(last_line)    


for i in range(r+1):
    arr[i].append(sum(arr[i]))

for i in range(r+1):
    print(*arr[i],sep=" ")


Measured memory_bytes: 6232
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
const int N = 1e5+1;
int i,n,a[N],sz[N];
ll ans[N];
priority_queue<ii>pq;
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		pq.push(ii(a[i],i));
		sz[i] = 1;
	}
	while(pq.size()>1)
	{
		int t1 = pq.top().first;
		int i1 = pq.top().second;
		pq.pop();
		int t2 = pq.top().first;
		int i2 = pq.top().second;
		pq.pop();
		ans[i1] += 1ll * sz[i1] * (t1 - t2);
		pq.push(ii(t2,min(i1,i2)));
		sz[min(i1,i2)] += sz[max(i1,i2)]; 
	}
	ans[1] += 1ll * n * pq.top().first;
	for(i=1;i<=n;i++)	printf("%lld\n",ans[i]);
}

Measured memory_bytes: 5616
a,b,c = map(int,input().split())
d,e,f = map(int,input().split())
g,h,i = map(int,input().split())
N = int(input())

X = [0] * 101

for k in range(N):
    t = int(input())
    X[t] = 1

if X[a]*X[e]*X[i] == 1 or X[a]*X[b]*X[c] == 1 or X[d]*X[e]*X[f] == 1 or X[g]*X[h]*X[i] == 1 or X[a]*X[d]*X[g] == 1 or X[b]*X[e]*X[h] == 1 or X[c]*X[f]*X[i] == 1 or X[c]*X[e]*X[g] == 1:
    print("Yes")
else:
    print("No")

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

int main(){
  int a,b, max;
  cin >> a >> b;
  
  if(a+b > a-b) max = a+b;
  else max = a-b;
  if(max < a*b) max = a*b;
  
  cout << max;
  
  return 0; 
}

Measured memory_bytes: 256
/*
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>

#include<stdio.h>
#include<stdlib.h>

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

ll factor(ll x) {
	ll ret = 1;
	ll tmp = 0;
	for (ll p = 2;;p++) {
		if (x == 1) {
			ret *= tmp + 1;
			break;
		}
		if (x % p == 0) {
			tmp += 1;
			x /= p;
			p--;
			continue;
		}
		ret *= tmp + 1;
		tmp = 0;
	}
	return ret;
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start

	ll N;
	cin >> N;
	ll ans = 0;

	for (ll i = 1; i <= N; i++) {
		ll ret = factor(i);
		ll tmp = ret;
		ans += i * tmp;
	}

	cout << ans << endl;



EndPoint:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG

	return 0;
}


*/

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#include<cmath>
#include<queue>
#include<stack>

#include<stdio.h>
#include<stdlib.h>

#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}

using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//Program Start	

	int X, Y, Z;
	cin >> X >> Y >> Z;

	cout << Z << " " << X << " " << Y << endl;

EndPoint:;

	//Program End
#ifndef DEBUG
	system("pause");
#endif // !DEBUG

	return 0;
}




Measured memory_bytes: 3080
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
#include <random>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const stc& lhs, const stc& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string S; cin >> S; ll N = S.size();
    if(S[0] == '0' || S[N-1] == '1'){
        cout << -1 << endstr; return 0;
    }
    bool ok = true;
    FOR(i, 1, N){
        ll j = N-i;
        if(S[i-1] != S[j-1]) ok = false;
    }
    if(!ok){
        cout << -1 << endstr; return 0;
    }
    
    vpl res;
    ll prev = 1;
    FOR(i, 2, N+1){
        if(S[i-1] == '1'){
            for(; prev < i; prev++) res.pb({prev, i});
        }
    }
    
    res.pb({N-1, N});
    for(auto p : res){
        cout << p.ff << " " << p.ss << endstr;
    }
    
    return 0;
}


Measured memory_bytes: 3264
import sys
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if len(ps) == 0:
        return next(args)
    elif type(ps[0]) is list:
        return [input(*ps[0][0]) for _ in range(ps[0][1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]

# エントリーポイント
def main():
    N, M = input(int, int)

    ps = dd(list)
    for i in range(M):
        p, y = input(int, int)
        ps[p].append((y, i))
    ans = [None] * M
    for k, v in ps.items():
        v.sort()
        for i, c in enumerate(v, start=1):
            ans[c[1]] = (k, i)
    for v in ans:
        print("{:06d}{:06d}".format(v[0], v[1]))

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


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

string reverse(string s){
    string t;
    REP(i,s.length()){
        t += s[s.length()-1-i];
    }
    return t;
}

int main() {
    int n;
    cin >> n;
    while (n--){
        string s;
        cin >> s;
        int m = s.length();
        set<string> st;
        st.insert(s);
        REP(i,m-1){
            string s1, s2, s1r, s2r;
            s1 = s.substr(0,i+1);
            s2 = s.substr(i+1);
            s1r = reverse(s1);
            s2r = reverse(s2);
            st.insert(s1+s2r);
            st.insert(s1r+s2);
            st.insert(s1r+s2r);
            st.insert(s2+s1r);
            st.insert(s2r+s1);
            st.insert(s2+s1);
            st.insert(s2r+s1r);
        }
        cout << st.size() << endl;
    }
    return 0;
}

Measured memory_bytes: 3064
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

int main(void)
{
	int N;
	cin >> N;

	vector<int> a(N);
	for(int i=0; i<N; i++)
		cin >> a[i];

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

	int alice, bob;
	alice = bob = 0;
	for(int i=0; i<N; i++){
		if(i%2 == 0)
			alice += a[i];
		else
			bob += a[i];
	}

	cout << alice - bob << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int const INF = 1001001001;


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

int x,a;
cin >> x >> a;

cout << (x<a? "0":"10") << endl;


return 0;
}


Measured memory_bytes: 256
class UnionFindTree():
    def __init__(self, N):
        self.parent = [-1]*(N+1)
        self.rank = [1]*(N+1)
        self.size = [1]*(N+1)
        self.hubensa = N*(N-1)//2

    def find(self, i):
        if self.parent[i] == -1:
            group = i
        else:
            group = self.find(self.parent[i]) 
            self.parent[i] = group
        return group
      
    def unite(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px != py:
            if self.rank[px] == self.rank[py]: # rank is same
                self.rank[px] += 1
            elif self.rank[px] < self.rank[py]:
                px, py = py, px
                
            self.parent[py] = px
            self.hubensa -= self.size[px] * self.size[py]
            self.size[px] += self.size[py]

N, M = list(map(int, input().split()))
A = [0 for _ in range(M)]
B = [0 for _ in range(M)]

for i in range(M):
    A[i], B[i] = list(map(int, input().split()))

ans = []
UFT = UnionFindTree(N)

# 後ろから処理
for i in range(M-1, -1, -1):
    ans.append(UFT.hubensa)
    UFT.unite(A[i], B[i])

print(*ans[::-1], sep="\n")


Measured memory_bytes: 20000
#include<bits/stdc++.h>
using namespace std;
int n;
string s[10010];
int a,b,ab;
int cnt;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>s[i];
		for(int j=0;j<s[i].length()-1;j++)
		{
			if(s[i][j]=='A'&&s[i][j+1]=='B')
				cnt++;
		}
		if(s[i][0]=='B')
			b++;
		if(s[i][s[i].length()-1]=='A')
			a++;
		if(s[i][0]=='B'&&s[i][s[i].length()-1]=='A')
			ab++;
	}
	cnt+=min(a,b);
	if(a==ab&&a==b&&a>0)
		cnt--;
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 768
n = int(input())

def check_num(x):
	if x % 3 == 0:
		return True

def include3(x):
	while True:
		if x ==0:
			break
		if x%10==3:
			return True
		x //= 10

for i in range(1,n+1):
#	check_num(i)
	if include3(i) or check_num(i):
		print(f' {i}',end="")
print()
		







Measured memory_bytes: 5888
import qualified Data.Vector.Unboxed as U

main = do
  k <- readLn :: IO Int
  print $ solve k

solve :: Int -> Int
solve k = f k $ U.fromList [1..9] where
  f 1 ll = U.head ll
  f k ll
    | k <= U.length ll = ll U.! pred k
    | otherwise = f (k - U.length ll) $ U.concatMap g ll
    where
      g x = U.fromList $ case mod x 10 of
        0 -> [10*x, 10*x+1]
        9 -> [10*x+8, 10*x+9]
        r -> [10*x+r-1 .. 10*x+r+1]

  


Measured memory_bytes: 5500
import bisect
import collections


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


mod = 10**9+7  # 出力の制限
n = 10**6
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, n + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
mod = 10**9 + 7

table = collections.defaultdict(int)

for x in A:
    table[x] += 1
ans = 0
for x in table:
    # print(x)
    i = bisect.bisect_left(A, x)
    if i+table[x] >= K:
        for j in range(1, table[x] + 1):
            ans += cmb(i, K-j, mod)*x*cmb(table[x], j, mod)
            # print(ans, j)

    i = bisect.bisect_right(A, x)

    if N - (i-table[x]) >= K:
        for j in range(1, table[x] + 1):
            ans -= cmb(N-i, K-j, mod)*x*cmb(table[x], j, mod)
            # print(ans, j)
    ans %= mod
print(ans)


Measured memory_bytes: 136972
#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 ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    cout << max(max(a + b, a - b), a * b) << endl;
    
    return 0;
}


Measured memory_bytes: 256
package main

import (
        "fmt"
        "sort"
)

func solution(n int, a []int) int {
        sort.Ints(a)

        sumA, sumB := 0, 0

        for i := 0; i < n; i++ {
                if i&1 == 0 {
                        sumA += a[n-i-1]
                } else {
                        sumB += a[n-i-1]
                }
        }
        return sumA - sumB
}

func main() {
        var n int
        fmt.Scan(&n)
        a := make([]int, 0, n)
        for i := 0; i < n; i++ {
                t := 0
                fmt.Scan(&t)
                a = append(a, t)
        }
        fmt.Println(solution(n, a))
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define mod ((ll)998244353)
#define inf 0x3f3f3f3f
#define infl 0x3f3f3f3f3f3f3f3f
#define Ninf -0x3e3e3e3f
#define Ninfl -0x3e3e3e3e3e3e3e3f
#define maxx ((ll)2e5+10)
#define endl "\n"
#define time(i) cout<<"\nTime Elapsed "<<i<<" : " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expm(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
ll add(ll x, ll y) { x += y; if (x >= mod) return x-mod; return x;}
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + mod; return x;}
ll mult(ll x, ll y) { return (x * y) % mod;}
ll rev(ll x) { return expm(x, mod - 2);}

bool sv[maxx]={0};    // returns 0 if a num is prime
int sp[maxx]={0};     // gives smallest prime factor of the number
void Sieve() {for(int i= 2; i< maxx; i+= 2) sv[i]=1,sp[i] = 2;sv[2]=0;for(ll i = 3; i < maxx; i += 2){if (!sv[i]){sp[i] = i;for (ll j = i; (j*i) < maxx; j += 2){if (!sv[j*i])sv[j*i] = true, sp[j*i] = i;}}}}
ll fact[maxx]={0}; // returns factorial of that number
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<maxx;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncrm(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(expm(fact[r],mod-2)))%mod; res=(res*(expm(fact[n-r],mod-2)))%mod; return res;}
/*ll inv[maxx];   // returns the modular inverse of number
void inversify( ll m){inv[1]=1;for(int i=2;i<maxx;i++){inv[i]= m- m/i*inv[m%i]%m;}}
ll ncr(ll n,ll r,ll m){int ans=1;for (int i = 0; i < r; i++){ans=ans*(n-i)%m*inv[i+1]%m;}return ans;}
*/
signed main(){
  fast;
  //test
  {
    int n,m,k;
    cin>>n>>m>>k;
    int ans=0;
    facto();
    for(int i=0;i<=k;i++){
      ans=add( ans , mult ( mult (  m,ncrm(n-1,i) )  ,  exp(m-1,n-1-i,mod) ) );
    }
    cout<<ans<<endl;

  }
  return 0;
}

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

int main() {
    int64_t n, a;
    cin >> n >> a;
    int64_t ans = n;

    auto Solve = [&](int k) {
        if (1.0 * (k - 1) * a > ans) return n;
        int64_t res = (k - 1) * a;
        int64_t d = 2;
        while (true) {
            double f = 1.0;
            int64_t e = 1;
            for (int i = 0; i < k; ++i) {
                f *= d;
                e *= d;
            }
            if (f < n && e < n) d++;
            else break;
        }
        vector<int64_t> cd;
        for (int i = -2; i <= 2; ++i) {
            if (d + i >= 2) cd.push_back(d + i);
        }

        function<int64_t(int, int, int64_t)> Dfs = [&](int i, int c, int64_t p) {
            if (p >= n) return int64_t(0);
            if (c == k) return n;
            if (i == cd.size()) return n;
            int64_t res = n, sum = 0;
            while (p <= n + n && c <= k) {
                res = min(res, sum + Dfs(i + 1, c, p));
                if (1.0 * p * cd[i] > n + n) break;
                p *= cd[i];
                sum += cd[i];
                c++;
            }
            return res;
        };

        int64_t t = Dfs(0, 0, 1);
        cerr << "k = " << k << " res = " << res + t << "\n";
        return res + t;
    };

    for (int k = 2; (1LL << k) <= n; ++k) ans = min(ans, Solve(k));
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
using System;

class Challenge
{
  static void Main()
  {
      var s = Console.ReadLine().Split();
      var a = int.Parse(s[0]);
      var b = int.Parse(s[1]);
      var str = (a*b)%2 == 1 ? "Odd" : "Even";
      Console.WriteLine(str);

  }
}



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

int main(){
  //  freopen( "in.txt" , "r" , stdin );

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

    deque<char> a , b;
    for ( char i : s )
        a.push_back(i);
    for ( char i : t )
        b.push_back(i);

    for ( int i = 0; i < (int)s.size(); ++i ){
        if ( a == b ){
            cout << "Yes";
            return 0;
        }
        a.push_front(a.back());
        a.pop_back();
    }
    cout << "No";
    return 0;
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
using lint = long long int;

int main() {
    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    for_(i,0,N) cin >> A[i];

    vector<int> B(N);
    for_(i,0,N-1) B[i] = (A[i+1] - A[i]);
    B[N-1] = K + A[0] - A[N-1];

    int mx = *max_element(ALL(B));
    cout << K - mx << endl;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;  //名前空間の宣言
#define MAX 100000
typedef long long llong;

int n,k;

llong T[MAX];
//積載量Pのトラックk台で何個の荷物を詰めるか
int check(llong P){
    int i = 0;
    for(int j=0;j<k;j++){
        llong s = 0;
        while(s + T[i] <= P){  //Pを超えないよう重量加算
            s += T[i];
            i++;
            if(i==n)return n;  //すべての荷物を調べ終わった
        }
    }
    return i;
}

int solve(){
    llong left = 0;
    llong right = 100000 * 10000;  //荷物の数(n)×1つの荷物の最大重量(wi)
    llong mid;
    while(right-left > 1){  //二分探索
        mid =(left + right)/2;
        int v = check(mid);   //mid==p最大積載量
        if(v>=n)right = mid;
        else left = mid;
    }
    return right;
    }

int main(){
    cin >> n >> k;
    for(int i=0; i < n; i++) cin >> T[i];
    llong ans = solve();
    cout << ans << endl;
}



Measured memory_bytes: 3864
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)

int count(int N)
{

        int cnt = 0;
        while (N)
        {
                cnt++;
                N /= 10;
        }
        return cnt;
}

int main()
{
        int A, B, C;
        cin >> A >> B >> C;
        int s = A + B + C;
        int ma = max(A, max(B, C));
        if (s % 2 == ma % 2)
        {
                cout << (ma * 3 - s) / 2 << endl;
        }
        else
        {
                cout << ((ma + 1) * 3 - s) / 2 << endl;
        }

        return 0;
}


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

using namespace std;


int main()
{
    int N;
    cin >> N;

    string s = to_string(N);
    

    char s_size = s.at(s.size() - 1) ;

    if(s_size == '3'){
        cout << "bon" << endl;
    }else if(s_size == '0' || s_size == '1' || s_size ==  '6' || s_size ==  '8') {
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }

    return 0;
    

}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define eb emplace_back
#define PI 3.14159265
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vll vector<ll>
#define vpint vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define fr(it, a, b) \
    for (int it = (a); it < (b); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
typedef long long ll;
typedef long double ld;
typedef unsigned long long lu;
const ll mod = 1e9 + 7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    vint a(n + 1);
    fr(i,0,n-1)
    {
        int x;
        cin>>x;
        a[x]++;
    }
    fr(i,1,n+1)
    {
        cout<<a[i]<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3988
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
void solve();
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solve();
    return 0;
}

// Main Code
void solve() {
    int m;
    cin >> m;
    ll ans = 0, sum = 0;
    rep(i, m) {
        ll d, c;
        cin >> d >> c;
        ans += c;
        sum += d * c;
    }
    cout << ans + (sum - 1) / 9 - 1 << "\n";
    return;
}



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

int
main (
  int   argc,
  char *argv[ ]
  )
{
  int wo, ws, n;
  int i;

  scanf ( "%d%d%d", &n, &wo, &ws );
  for ( i = 1; i < n; ++i )
  {
    int o, s;

    scanf ( "%d%d", &o, &s );
    if ( s > ws
      || ( s == ws && o < wo ) )
    {
      wo = o;
      ws = s;
    }
  }

  printf ( "%d %d\n", wo, ws );

  return ( EXIT_SUCCESS );
}

Measured memory_bytes: 600
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,a,tot,ans;
vector<ll> v;
void ini(void){
    m=1;
    while(m<n)m*=2;
    v.resize(2*m-1,0);
}
void STadd(ll a,ll b){
    a+=m-1;
    v[a]=b;
    while(a){
        a=(a-1)/2;
        v[a]=max(v[2*a+1],v[2*a+2]);
    }
    return ;
}
ll STquery(ll a,ll b,ll k,ll l,ll r){
    if(r<=a||l>=b)return 0;
    if(a<=l&&r<=b)return v[k];
    ll vr=STquery(a,b,2*k+1,l,(r+l)/2);
    ll vl=STquery(a,b,2*k+2,(r+l)/2,r);
    return max(vr,vl);
}
int main(void){
    cin>>n;
    ini();
    for(int i=0;i<n;i++){
        cin>>a;
        tot+=a;
        a--;
        STadd(a,STquery(0,a+1,0,0,m)+a+1);
        ans=max(ans,v[a+m-1]);
    }
    cout<<tot-ans<<endl;
}


Measured memory_bytes: 4960
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define ld long double
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define all(c) (c).begin(),(c).end()
#define sz(x) (int)(x).size()
#define EPS 0.000000001 //1e-9
#define pii pair<int,int>
using namespace std;
int32_t main()
{
    IOS;
    double d,t,s;
    cin>>d>>t>>s;
    double k=d/s;
    if(k>t)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    
}

Measured memory_bytes: 3736
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500*i+100*j+50*k==x:
        ans+=1
print(ans)

Measured memory_bytes: 40176
/**
	*    author:  accesss_denied
	**/
	#include <bits/stdc++.h>
	using namespace std;
	#define ll long long int
	#define ff first
	#define ss second
	#define pb push_back
	#define endl "\n"
	#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	ll mod=1e9+7;			
	ll inf=1e18;

	int main() {
				fast
				// #ifndef ONLINE_JUDGE
				// freopen("input.txt","r",stdin);
				// freopen("output.txt","w",stdout);
				// #endif

				ll t;
				t=1;
				while(t--)
				{
					double d,t,s;
					cin>>d>>t>>s;

					if(d/s<=t)
					{
						cout<<"Yes";
					}
					else
					cout<<"No";
					
				}
				return 0;
			}	




Measured memory_bytes: 3728
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)

const int mod = 1000000007;

bool G[8][8];

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

  int n, m;
  cin >> n >> m;

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;b--;
    G[a][b] = true;
    G[b][a] = true;
  }

  vector<int> v(n-1);
  rep(i, n-1) {
    v[i] = i+1;
  }

  int cnt = 0;
  do {
    bool can = true;
    if(!G[0][v[0]]) can = false;
    rep(i, n-2) {
      if(!G[v[i]][v[i+1]]) can = false;
    }
    if (can) cnt++;
  } while(next_permutation(v.begin(), v.end()));

  cout << cnt << endl;
}


Measured memory_bytes: 256
s = input()
front = int(s[0]+s[1])
end = int(s[2]+s[3])
a = 1<=front<=12
b = 1<=end<=12
if a:
  if b:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if b:
    print("YYMM")
  else:
    print("NA")

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long LL;
char s[15];
int pos[15];
LL num(int l,int r)
{
    LL ans=0;
    //cout<<l<<" "<<r<<endl;
    for(int i=l;i<=r;i++)
    {
        ans=ans*10+s[i]-'0';
    }
    return ans;
}
LL solve(int n)
{
    int l=-1,r=0;
    LL ans=0;
    pos[n]=1;
    for(int i=0;i<=n;i++)
    {
        if(pos[i]==0)
            r++;
        else
        {
            ans+=num(l+1,i);
            l=i;
        }
    }
    return ans;
}
int main()
{
     while(cin>>s)
     {
         int n=strlen(s);
         long long ans=0;
         int R= (1<<(n-1))-1 ;
        // cout<<R<<endl;
        for(int i=0;i<=R;i++)
        {
            memset(pos,0,sizeof(pos));
            int tot=0;
            int temp=i;
            while(temp)
            {
                pos[tot++]=temp%2;
                temp=temp/2;
            }
            //cout<<solve(n-1)<<endl;
            ans+=solve(n-1);
            //cout<<ans<<endl;
        }
        printf("%lld\n",ans);
     }
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import copy

sys.setrecursionlimit(1000000)

input = sys.stdin.readline
from collections import defaultdict

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

A, B = map(int, input().split())

if (A + B) % 2 == 0:
    print((A + B) // 2)
else:
    print("IMPOSSIBLE")


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K,R,S,P;
  string T;
  cin >> N >> K;
  cin >> R >> S >> P;
  cin >> T;
  int times[3]={0};
  for(int i=0;i<T.size();i++){
    if(T[i]=='r') times[2] += 1;
    else if(T[i]=='s') times[0] += 1;
    else times[1] += 1;
  }

  int flag[K]={0};

  for(int i=K;i<T.size();i++){
    if(T[i]==T[i-K] && flag[i%K]==0){
      if(T[i]=='r') times[2] -= 1;
      else if(T[i]=='s') times[0] -= 1;
      else times[1] -= 1;
      flag[i%K] = 1;
    }
    else{
      flag[i%K] = 0;
    }
  }

  int score = times[0]*R + times[1]*S + times[2]*P;
  cout << score << endl;
  return 0;
}

Measured memory_bytes: 768
sx, sy, tx, ty = map(int, input().split())

len_x = tx - sx
len_y = ty - sy

ans = []
for _ in range(len_x):
    ans.append("R")
for _ in range(len_y):
    ans.append("U")
for _ in range(len_x):
    ans.append("L")
for _ in range(len_y):
    ans.append("D")
    
ans.append("D")
for _ in range(len_x + 1):
    ans.append("R")
for _ in range(len_y + 1):
    ans.append("U")
ans.append("L")
ans.append("U")
for _ in range(len_x + 1):
    ans.append("L")
for _ in range(len_y + 1):
    ans.append("D")
ans.append("R")

print("".join(ans))

Measured memory_bytes: 40176
n = int(input())
h = list(map(int, input().split()))
c = [0 for i in range(n)]
c[0] = 0
c[1] = abs(h[1] - h[0])
# c[2] = c[0] + abs(h[2]-h[0])
# c[2] = c[1] + abs(h[2]-h[1])
# c[3] = c[1] + abs(h[3]-h[1])
# c[3] = c[2] + abs(h[3]-h[1])
for i in range(2, n):
    c[i] = min(c[i-1]+abs(h[i]-h[i-1]), c[i-2]+abs(h[i]-h[i-2]))
print(c[-1])


Measured memory_bytes: 13980
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(n):
        ss = [[int(c) if i > 0 else c for c,i in zip(LS(),range(3))] for _ in range(n)]
        r = []
        a = [(0, -1)]
        ds = set()
        for s in ss:
            if s[0] == 'R':
                bi = bisect.bisect_left(a, (s[1], inf))
                t = a[bi-1][1]
                if t in ds:
                    t = -1
                r.append(t)
            elif s[0] == 'W':
                i = s[1]
                c = s[2]
                ai = 0
                al = len(a)
                while c > 0:
                    if a[ai][1] >= 0 and a[ai][1] not in ds:
                        ai += 1
                        continue
                    if ai == al - 1:
                        a[-1:] = [(a[ai][0], i), (a[ai][0]+c, -1)]
                        break
                    aic = a[ai+1][0] - a[ai][0]
                    if aic <= c:
                        a[ai] = (a[ai][0], i)
                        c -= aic
                    else:
                        a[ai:ai+1] = [(a[ai][0], i), (a[ai][0]+c, -1)]
                        break
            else: # 'D'
                ds.add(s[1])
        return r

    while True:
        n = I()
        if n == 0:
            break
        rr.extend(f(n))
        # print(rr[-1])
        rr.append('')

    return '\n'.join(map(str, rr))



print(main())



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

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();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#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)

#define en "\n"

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007; // 998244353

#define CLR(a) memset((a), 0, sizeof(a))

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    string K; cin >> K;
    int N = K.size();
    int D; cin >> D;
    ll dp[N+1][2][D]; REP(i,N+1)REP(j,2)REP(k,D) dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    REP(i,N)REP(k,D){
        REP(j,10) dp[i+1][1][(k+j)%D] = (dp[i+1][1][(k+j)%D] + dp[i][1][k])%MOD;
        REP(j,K[i]-'0') dp[i+1][1][(k+j)%D] = (dp[i+1][1][(k+j)%D] + dp[i][0][k])%MOD;
        dp[i+1][0][(k+K[i]-'0')%D] = (dp[i+1][0][(k+K[i]-'0')%D] + dp[i][0][k])%MOD;
    }
    ll ans = (dp[N][0][0] + dp[N][1][0] -1 + MOD)%MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15872