akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max({a * c, a * d, b * c, b * d}) << endl;
}


Measured memory_bytes: 3648
import sys
input = sys.stdin.readline

class WarshallFloyd:
    def __init__(self,n):
        self.v = n
        self.d = [[1e100]*n for _ in range(n)]
        for i in range(n):
            self.d[i][i] = 0

    def path(self,x,y,c):
        if x == y:
            return False
        self.d[x][y] = c
        self.d[y][x] = c
        return True

    def build(self):
        for k in range(self.v):
            for i in range(self.v):
                for j in range(self.v):
                    self.d[i][j] = min(self.d[i][j], self.d[i][k] + self.d[k][j])

n,m = map(int,input().split())
ABC = [tuple() for _ in range(m)]
wf = WarshallFloyd(n)
for i in range(m):
    a,b,c = map(int,input().split())
    wf.path(a-1,b-1,c)
    ABC[i] = (a-1,b-1,c)
ans = 0
wf.build()
for a,b,c in ABC:
    ans += (c > wf.d[a][b])
print(ans)


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

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

int main() {
  ll a,n,b,h,w,k,f=0,ans=0;
  string word;
  bool flag;
  cin>>a>>b;
  cin>>n>>h;
  if(a==n)cout<<0<<endl;
  else cout<<1<<endl;
  vector<vector<int>> sss(h,vector<int>(w));
  //vector<int> a(k),b(k);
  char x;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
#define fast ios::sync_with_stdio(false), cout.tie(), cin.tie();
#define sz(s) int(s.size())

int main(){
	int n;
	cin >> n;
	ld a[n], sum = 0, min = 101, x = 0;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
	}
	sum /= n;
	for (int i = 0; i < n; i++){
		if (abs(a[i] - sum) < min){
			min = abs(a[i] - sum);
			x = i;
		}
	}
	cout << x;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>
#include<type_traits>

using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;
constexpr ll LONGINF = 1050000000000000000;


int main() {
	int n; cin >> n;
	vector<double> v(n);

	double ans = 0.0;

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

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

	for (int i = 1; i < n; i++) {
		v[i] = (v[i] + v[i - 1]) / 2;
	}

	cout << v[n - 1] << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int M1 = sc.nextInt();
		int D1 = sc.nextInt();
		int M2 = sc.nextInt();
		int D2 = sc.nextInt();
		sc.close();

		System.out.println(D2 == 1 ? 1 : 0);

	}

}

Measured memory_bytes: 22732
#include <iostream>


int countPattern(int n) {
  int count = 0;
  int ni, ij, ijk;
  for (int i = 0; i < 10; i ++) {
    ni = n - i;
    for (int j = 0; j < 10; j ++) {
      ij = ni - j;
      for (int k = 0; k < 10; k ++) {
        ijk = ij - k;
        if (0 <= ijk && ijk <= 9) {
          count ++;
        }
      }
    }
  }
  return count;
}


int main () {
  int n;
  while (std::cin >> n) {
    std::cout << countPattern(n) << std::endl;
  }
  return 0;
}

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

int		main(void)
{
	char	a, b;

	cin >> a >> b;

	if (a == 'H')
		cout << (b == 'H' ? "H" : "D") << endl;
	else
		cout << (b == 'H' ? "D" : "H") << endl;
}

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

using namespace std;

int main(){
    int n, k;
    cin>>n>>k;
    vector<int> arr(n, 0);
    for(int i = 0;i< k;i++){
        int d;
        cin>>d;
        for(int j =0;j< d;j++){
            int temp ;
            cin>>temp;
            arr[temp-1]++;
        }
    }
    int count = 0;
    for(int i= 0;i< n;i++){
        if(arr[i] == 0)count++;
    }
    cout<<count<<endl;
    return 0;
}


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

using namespace std;

int main(){
    string s;
    int cnt,res;
    bool isStart = false;
    
    cin >> s;

    cnt = 0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A' && isStart == false){
            cnt++;
            isStart = true;
            continue;
        }
        if(isStart)
            cnt++;
        if(s[i] == 'Z')
            res = cnt;
    }

    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#define MAX 31

using namespace std;

int main(void){

  int N[MAX];
  int w,n;
  int a,b;
  char ten;

  cin >> w >> n;
  for( int i = 1 ; i <= w ; i++ )N[i] = i;

  for( int i = 1 ; i <= n ; i++ ){
    cin >> a >> ten >> b;
      swap( N[a] , N[b]); //swap関数は第一引数と第二引数を交換する関数
  }
  for( int i = 1 ; i <= w ; i++ ){
    cout << N[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define mms(x,l) memset(x,0,sizeof(x[0])*(l))
#define mmp(x,y,l) memcpy(x,y,sizeof(y[0])*(l))

using namespace std;
typedef long long ll;

const int N=20,P=998244353,M=33005,g=3;

char A[M],B[M];
int l,n,m,k,fac[M],ifac[M],inv[M],f[M],a[M],ans;
int _w[N][M];

inline int fpow(int a,int t){static int r;for(r=1;t;a=(ll)a*a%P,t>>=1)if(t&1)r=(ll)r*a%P;return r;}
inline int lset(int x){int l=1;while(l<=x)l<<=1;return l;}
void make(int n){
	n++;n=lset(n);
	int l=2,p=1,w;
	while(l<=n){
		w=fpow(g,(P-1)/l);int*f=_w[p];f[0]=1;
		for(int j=1;j<(l>>1);j++)f[j]=(ll)f[j-1]*w%P;
		l<<=1,p++;
	}
	inv[1]=1;
	for(int i=2;i<=n;i++)inv[i]=P-(ll)inv[P%i]*(P/i)%P;
}
void ntt(int*a,int n,int d){
	int i,j=n>>1,k,t=0,l,u,v,*p;
	for(i=1;i<n-1;i++){
		if(i<j)swap(a[i],a[j]);
		for(k=n>>1;(j^=k)<k;k>>=1);
	}
	for(l=2;l<=n;l<<=1){
		i=l>>1,p=_w[++t];
		for(j=0;j<n;j+=l)for(k=0;k<i;k++){
			u=a[j+k],v=(ll)a[j+k+i]*p[k]%P;
			a[j+k]=(u+v)%P,a[j+k+i]=(u-v+P)%P;
		}
	}
	if(d==-1){
		for(i=0,v=fpow(n,P-2);i<n;i++)a[i]=(ll)a[i]*v%P;
		for(i=1;i<n/2;i++)swap(a[i],a[n-i]);
	}
}

void convol(int A[],int B[],int R[],int n){
	static int x[M],y[M],z[M];
	mms(x,n),mmp(x,A,n),mms(y,n),mmp(y,B,n);
	ntt(x,n,1),ntt(y,n,1);
	for(int i=0;i<n;i++)z[i]=(ll)x[i]*y[i]%P;
	ntt(z,n,-1),mmp(R,z,n);
}

void Inv(int A[],int R[],int n){
	if(n==1){*R=fpow(*A,P-2);return;}
	static int T[M],t1[M],t2[M],t3[M];
	int d=(n+1)/2;
	Inv(A,T,d);
	int m=lset(d*2+n-3);
	mms(t1,m),mms(t2,m),mms(t3,m);
	mmp(t1,T,d),mmp(t2,A,n);
	ntt(t1,m,1);ntt(t2,m,1);
	for(int i=0;i<m;i++)t3[i]=((2*t1[i]-(ll)t1[i]*t1[i]%P*t2[i])%P+P)%P;
	ntt(t3,m,-1);
	mmp(R,t3,n);
}

void Ln(int f[],int a[],int n){
	static int g[M],t[M],b[M];
	int m=lset(2*n-2);
	mms(g,m),mms(t,m),mms(b,m);
	for(int i=1;i<n;i++)g[i-1]=(ll)f[i]*i%P;
	Inv(f,t,n);
	convol(t,g,b,m);
	a[0]=0;
	for(int i=1;i<n;i++)a[i]=(ll)b[i-1]*inv[i]%P;
}

void Exp(int c[],int f[],int n){
	if(n==1){f[0]=1;return;}
	static int f0[M],g0[M],t1[M],t2[M],t3[M];
	int d=(n+1)/2,m=lset(n+d-2);
	Exp(c,f0,d);
	Ln(f0,g0,n);
	mms(t1,m),mms(t2,m),mms(t3,m);
	mmp(t1,f0,n);
	for(int i=0;i<n;i++)t2[i]=(c[i]-g0[i]+P)%P;
	t2[0]++;
	convol(t1,t2,t3,m);
	mmp(f,t3,n);
}

int main(){
	scanf("%s%s",A+1,B+1);
	l=strlen(A+1);
	for(int i=1;i<=l;i++){
		int j=(A[i]&1)+(B[i]&1);
		if(j==2)m++;else if(j)n++;
	}
	n>>=1;k=n+m;
	fac[0]=1;
	for(int i=1;i<=k;i++)fac[i]=(ll)fac[i-1]*i%P;
	ifac[k]=fpow(fac[k],P-2);
	for(int i=k;i>=1;i--)ifac[i-1]=(ll)ifac[i]*i%P;
	make(m<<1);
	for(int i=0;i<=m;i++)f[i]=ifac[i+1];
	Ln(f,a,m+1);
	for(int i=0;i<=m;i++)a[i]=(ll)a[i]*n%P;
	Exp(a,f,m+1);
	for(int i=0;i<=m;i++)ans=(ans+f[i])%P;
	ans=(ll)ans*fac[n+m]%P*fac[n]%P*fac[m]%P;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3584
h, n = gets.chomp.split(" ").map(&:to_i)
dmg = gets.chomp.split(" ").map(&:to_i)
atk = 0

(0...n).each do |i|
  atk += dmg[i]
end

if atk >= h
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 8708
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace aizu1
{
    public class Solution
    {
        public static void Main(string[] args)
        {
            Console.ReadLine();
            int[] s = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '),int.Parse);
            int comCount = mergeSort(s, 0, s.Length);
            string res = string.Join(" ", Array.ConvertAll<int, string>(s,(i)=>i.ToString()));

            Console.WriteLine(res);
            Console.WriteLine(comCount);
        }

        public static int mergeSort(int[] list, int left, int right)
        {
            if (left == right-1) return 0;

            return mergeSort(list, left, (right+left)/2)+mergeSort(list,(right+left)/2,right)+merge(list,left,(left+right)/2,right); 
        }

        public static int merge(int[] list, int left, int mid, int right)
        {
            int[] L = new int[mid - left+1];
            int[] R = new int[right - mid + 1];
            int com = 0;

            for(int m=0;m<mid-left;m++)
            {
                L[m] = list[m+left];
            }
            
            for(int i=0;i<right-mid;i++)
            {
                R[i] = list[mid + i];
            }

            L[mid - left] = int.MaxValue;
            R[right - mid] = int.MaxValue;

            int j= 0, k = 0;
            for(int l=left;l<right;l++)
            {
                if (L[j] <= R[k]) list[l] = L[j++];
                else list[l] = R[k++];
                com++;
            }
            return com;
        }
    }
}

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

using namespace std;
int n, k;
long long a[100005], ans = (long long)2e15;
int main()
{

    cin >> n >> k;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i + k - 1 <= n; i++)
    {
        int l = i, r = i + k - 1;
        ans = min(ans, a[r] - a[l] + min(abs(a[l]), abs(a[r])));
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
long long gcd(long long a, long long b) {
    if (b==0)return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b;
}
int main() {
ll n;
cin >> n;
ll t[n];
for (ll i = 0; i < n; i++) cin >> t[i];
ll ans = 1;
for (ll i = 0; i < n; i++) ans = lcm(ans, t[i]);
cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fastio() ios::sync_with_stdio(0);cin.tie(0);
#define nl "\n"
#define wi(x) cerr << #x << " is " << x << nl
const double eps = 1e-6;
const int mod = 1e9 + 7;

void solve(){
	// since graph is DAG, think in terms of KAHN's algo
	int n,m; cin >> n >> m;
	vi graph[n+1];
	vll dp(n+1,0);
	vi indegree(n+1,0);
	while(m--){
		int u,v; cin>>u>>v;
		indegree[v]++;
		graph[u].pb(v);
	}
	
	queue<int> Q;
	rep(i,1,n){
		if(indegree[i] == 0) Q.push(i);
	}
	while(!Q.empty()){
		int from = Q.front();
		Q.pop();
		
		for(auto to : graph[from]){
			indegree[to]--;
			if(indegree[to] == 0) Q.push(to);
			dp[to] = max(dp[to], dp[from] + 1);
		}
	}
	
	ll ans = 0;
	rep(i,1,n) ans = max(ans, dp[i]);
	cout << ans;
}

int main(){
	fastio()
	
	int T=1;
	//int T; cin>>T;
	while(T--) solve();

	return 0;
}


Measured memory_bytes: 9600
#[warn(unused_imports)]
use proconio::{
   fastout, input,
   marker::{Bytes, Chars, Isize1, Usize1}
};

#[fastout]
fn main() {
   input! {
      n: usize,
      k: usize,
   }
   let mut snk = vec![0; n];
   for _ in 0..k {
      input! {
         d: usize,
         a: [Usize1; d]
      }
      for a in a {
         snk[a] += 1;
      }
   }
   let mut ans = 0;
   for s in snk {
      if s==0 {
         ans += 1;
      }
   }
   println!("{}", ans);
}


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

int main() {
  int N, T, A;
  cin >> N >> T >> A;
  
  int place;
  double delt = 5000;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    double t = T - 0.006*x;
    if (abs(t-A) < delt) {
      place = i+1;
      delt = abs(t-A);
    }
  }
  
  cout << place << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
if n % 2 == 0 and n >= 4:
  dp = [[0, 0] for i in range(n)]
  dp[0][0] = a[0]
  dp[1][1] = a[1]
  dp[2][0] = a[0] + a[2]
  for i in range(3, n):
    dp[i][0] = dp[i - 2][0] + a[i]
    dp[i][1] = max(dp[i - 3][0], dp[i - 2][1]) + a[i]
  print(max(dp[n - 2][0], dp[n - 1][1]))
elif n % 2 != 0 and n >= 5:
  dp = [[0, 0, 0] for i in range(n)]
  dp[0][0] = a[0]
  dp[1][1] = a[1]
  dp[2][0] = a[0] + a[2]
  dp[2][2] = a[2]
  dp[3][1] = a[1] + a[3]
  dp[3][2] = a[0] + a[3]
  for i in range(3, n):
    dp[i][0] = dp[i - 2][0] + a[i]
    dp[i][1] = max(dp[i - 3][0], dp[i - 2][1]) + a[i]
    dp[i][2] = max(dp[i - 4][0], dp[i - 3][1], dp[i - 2][2]) + a[i]
  print(max(dp[n - 3][0], dp[n - 2][1], dp[n - 1][2]))
elif n == 2:
  print(max(a[0], a[1]))
else:
  print(max(a[0], a[1], a[2]))

Measured memory_bytes: 68088
/* In the name of Allah */
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, m;
	cin >> n >> m;
	int arr[n+1];
	int sum =0;
	for(int i = 0; i < m; i++){
		cin >> arr[i];
		sum += arr[i];
	}
	if(sum > n){
		cout << -1;
	}else{
		cout << n- sum ;
	}
	return 0;
}

Measured memory_bytes: 3640
using System;
using System.Linq;
namespace ABC059_C{
    class Program{
        static void Main(string[] args){
            var n = long.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            var ans1 = 0L;
            var ans2 = 0L;
            var flag = true;
            var sum = 0L;

            for(var i = 0;i < n;i++){
                sum += a[i];
                if(flag){
                    if(sum <= 0){
                        ans1 += Math.Abs(sum) + 1;
                        sum += Math.Abs(sum) + 1;
                    }
                }else{
                    if(sum >= 0){
                        ans1 += Math.Abs(sum) + 1;
                        sum -= Math.Abs(sum) + 1;
                    }
                }
                flag = (flag) ? false : true;
            }
            sum = 0;
            flag = false;
            for(var i = 0;i < n;i++){
                sum += a[i];
                if(flag){
                    if(sum <= 0){
                        ans2 += Math.Abs(sum) + 1;
                        sum += Math.Abs(sum) + 1;
                    }
                }else{
                    if(sum >= 0){
                        ans2 += Math.Abs(sum) + 1;
                        sum -= Math.Abs(sum) + 1;
                    }
                }
                flag = (flag) ? false : true;
            }

            Console.WriteLine(Math.Min(ans1,ans2));
        }
    }
}


Measured memory_bytes: 31196
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string a;
  cin >> a;
  
  for (int i = 0; i < 3; i++){
    if (a[i] =='1'){
      a[i] = '9';
    }
    else if (a[i] == '9'){
      a[i] = '1';
    }
  }
  cout << a << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	static char bombs[][]=new char[8][8];
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		String s[]=new String[8];
		int x,y;
		for(int i=1;i<=n;i++){
			for(int j=0;j<8;j++){
				s[j]=sc.next();
				for(int k=0;k<8;k++){
					bombs[j][k]=s[j].charAt(k);
				}
			}
			x=sc.nextInt()-1;
			y=sc.nextInt()-1;
			dfs(y, x);
			System.out.println("Data "+i+":");
			for(int j=0;j<8;j++){
				for(int k=0;k<8;k++){
					System.out.print(bombs[j][k]);
				}
				System.out.println();
			}
		}
	}
	private static void dfs(int y, int x){
		int x_c[]={1,0,-1,0,2,0,-2,0,3,0,-3,0};
		int y_c[]={0,1,0,-1,0,2,0,-2,0,3,0,-3};
		for(int i=0;i<12;i++){
			bombs[y][x]='0';
			if(x+x_c[i]>=0&&y+y_c[i]>=0&&x+x_c[i]<8&&y+y_c[i]<8&&bombs[y+y_c[i]][x+x_c[i]]=='1'){
				dfs(y+y_c[i], x+x_c[i]);
			}
		}
	}
}

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

template <typename T> T load() { T r; cin >> r; return r; }
template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	auto n = load<int>();
	auto xs = loadMany<int>(n);
	auto s = multiset<long double>();
	for (auto x : xs)
		s.insert(1.0l / x);
	while (s.size() > 1) {
		auto x1 = *s.begin();
		s.erase(s.begin());
		auto x2 = *s.begin();
		s.erase(s.begin());
		s.insert(x1 + x2);
	}
	auto answer = 1.0l / *s.begin();
	cout << fixed << setprecision(8) << answer << '\n';
}


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

#define ll long long
#define tc(t) int t;cin >> t; while(t--)
#define pb push_back
#define fi first
#define se second
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);

void solve() {
    string s;
    cin >> s;
    int rev = 0;
    vector<char> vs, ve;
    tc(Q) {
        int op;
        cin >> op;
        if(op == 1) {
            rev = rev ^ 1;
        }
        else {
            int f;
            cin >> f;
            char ch;
            cin >> ch;
            if(f == 1) {
                if(rev == 0) {
                    vs.pb(ch);
                }
                else {
                    ve.pb(ch);
                }
            }
            else {
                if(rev == 0) {
                    ve.pb(ch);
                }
                else {
                    vs.pb(ch);
                }
            }
        }
    }
    string ans = "";
    for(int i = int(vs.size())-1; i>=0; i--) ans.pb(vs[i]);
    for(char c: s) ans.pb(c);
    for(auto it: ve) ans.pb(it);

    if(rev == 1) reverse(ans.begin(), ans.end());
    cout << ans << '\n';
}

int main() {_
    int t = 1;
    //cin >> t;
    // Please remember to uncomment for taking test cases
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 1484
#[test]
fn test_solve() {
    assert_eq!(solve("4\n1\n3\n2\n4\n"), "2\n");
    assert_eq!(solve("6\n3\n2\n5\n1\n4\n6\n"), "4\n");
    assert_eq!(solve("8\n6\n3\n1\n2\n7\n4\n8\n5\n"), "5\n");
    assert_eq!(solve("5\n1\n2\n3\n4\n5\n"), "0\n");
}
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();
    let p: Vec<_> = (0..n).map(|_| sc.read::<usize>() - 1).collect();

    let mut q = vec![0; n];
    for i in 0..n {
        q[p[i]] = i;
    }

    let lgis = q
        .iter()
        .chain(&[0])
        .scan((0, 0), |i_n, &j| {
            let (i, n) = *i_n;
            if i < j {
                *i_n = (j, n + 1);
            } else {
                *i_n = (j, 1);
            }
            Some(n)
        })
        .max()
        .unwrap();

    format!("{}\n", n - lgis)
}
fn main() {
    let mut buf = String::new();
    use std::io::{Read, Write};
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}


Measured memory_bytes: 10492
d = {}

i = int(input())

for m in range(i):
	word = input()
	d[m] = word
for n in range(1, i):
	a = d[n-1]
	b = d[n]
	if a[-1] != b[0]:
		print('No')
		exit()
for x in range (i-1):
	for j in range (x+1, i):
		if d[x] == d[j]:
			print('No')
			exit()
print('Yes')


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;

int n, d;
float calc_norm(vector<int> &x, vector<int> &y){
  float norm = 0;
  for (int i = 0; i < d; i++) {
    norm += pow(x[i] - y[i], 2);
  }
  norm = sqrt(norm);
  return norm;
}

int main() {
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) {
      cin >> x[i][j];
    }
  }

  int ans = 0;
  float norm;
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      norm = calc_norm(x[i], x[j]);
      // cout << norm << endl;
      if(ceil(norm) == floor(norm)) ans++;
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline ll read() {
    ll x=0,f=1; char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())
        if(ch=='-')f=-f;
    for(;ch>='0'&&ch<='9';ch=getchar())
        x=x*10+ch-'0';
    return x*f;
}
inline void chkmin( int &a,int b ) { if(a>b) a=b; }
inline void chkmax( int &a,int b ) { if(a<b) a=b; }
#define _ read()
int main() {
	int n=_,mx=0,ans=0;
	for( int i=1;i<=n;i++ ) {
		int x=_; chkmax(mx,x);
		ans+=(x==mx);
	}cout<<ans;
}

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

int main(){
  int stack[100];
  int stack_s=0,judge=0;
  char rs;

  while((rs=getchar())!='\n'){
    if(isdigit(rs)){
      if(judge){
	stack[stack_s]=stack[stack_s]*10+(rs-'0');
    }else{
      stack[stack_s]=(rs-'0');
      judge++;
    }
    }
    if(isspace(rs)){
      if(judge){
	stack_s++;
	judge=0;
      }
    }
    if(rs=='+'){
      if(stack_s>1){
	stack_s--;
      }
      stack[stack_s-1]+=stack[stack_s];
      stack[stack_s]=0;
    }
    if(rs=='-'){
      if(stack_s>1){
	stack_s--;
      }
      stack[stack_s-1]-=stack[stack_s];
      stack[stack_s]=0;
    }
    if(rs=='*'){
      if(stack_s>1){
	stack_s--;
      }
      stack[stack_s-1]*=stack[stack_s];
      stack[stack_s]=0;
    }
    }
  printf("%d\n",stack[0]);
  return 0;
}



Measured memory_bytes: 2108
#include <iostream>

using namespace std;

int main()
{
    int a,b,x,i,flag;
    cin>>a>>b>>x;
    for(i=b;i>=0;i--)
        if((a+i)==x){
            flag=1;
            cout<<"YES";
            break;}
        else
            flag=0;
    if(flag==0)
        cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
dic=defaultdict(list)
while True:
    try:
        word,page=raw_input().split()
        dic[word].append(int(page))
    except EOFError:
        break;

for word in sorted(dic):
    print word
    dic[word].sort()
    for i in range(len(dic[word])-1):
        print dic[word][i],
    print dic[word][-1]

Measured memory_bytes: 8788
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
const int N = 1000000;

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

    if(n == 100)n++;
    print(n * int(pow(100,d)));
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		sc.close();

		System.out.println(Math.abs((long)(N - 2) * (M - 2)));
	}
}

Measured memory_bytes: 21332
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=(b-1);i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll d[510][200000];

int main() {
	ll n;
	cin>>n;
	vector<ll> vc;
	vector<ll> vs;
	vector<ll> vf;
	rep(i,0,n-1){
		ll c,s,f;
		cin>>c>>s>>f;
		vc.pb(c);
		vs.pb(s);
		vf.pb(f);
	}
	rep(i,0,n-1){
		ll t = 0;
		rep(j,i,vs.sz){
			if(t<vs[j]){
				t = vs[j] + vc[j];
			}
			else{
				t += (vf[j]-(t%vf[j]))%vf[j] + vc[j];
			}
		}
		cout << t << endl;
	}
	cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
#include <set>
#include <bitset>
#include <cstring>
typedef long long ll;
typedef long double ld;


#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
using Graph = vector<vector<ll>>;
using P = pair<ll, ll>;

/* 4 方向への隣接頂点への移動を表すベクトル */
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int MAX_A = 100000;
const int MAX_B = 0;
ll H, W;
ll sX, sY, gX, gY;
ll N, M, L;
vector<int> graph;
string S, T;
int vector_finder(std::vector<int> vec, int number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
int main() {
	cin >> S >> T;
	N = S.size();
	ll ans = 0;
	rep(i,N) {
		if (S[i] != T[i])ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3840
# AOJ 0176: What Color?
# Python3 2018.6.19 bal4u

color = [ \
	[ "black",      0,    0,    0 ], \
	[ "blue",       0,    0, 0xff ], \
	[ "lime",       0, 0xff,    0 ], \
	[ "aqua",       0, 0xff, 0xff ], \
	[ "red",	 0xff,    0,    0 ], \
	[ "fuchsia", 0xff,    0, 0xff ], \
	[ "yellow",  0xff, 0xff,    0 ], \
	[ "white",   0xff, 0xff, 0xff ]]

while True:
	a = list(input())
	if a[0] == '0': break
	r, g, b = int(a[1]+a[2], 16), int(a[3]+a[4], 16), int(a[5]+a[6], 16)
	vmin = 3* 0xff**2
	for i in color:
		d = (r-i[1])**2 + (g-i[2])**2 + (b-i[3])**2
		if d < vmin: j, vmin = i, d
	print(j[0])



Measured memory_bytes: 5568
N,Y = gets.split.map(&:to_i)

isBreak = false
result = "-1 -1 -1"
(0..N).each do |i|
  (0..N).each do |j|
    if(i*10000)+(j*5000)+((N-i-j)*1000) == Y && i+j+(N-i-j) == N && (N-i-j) >= 0
      result = "#{i} #{j} #{N-i-j}"
      isBreak = true
      break
    end
  end
  break if isBreak
end

puts result

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     ll n=0;
     cin>>n;
     ll sum=0;
     for(int x=1;x<=n;x++){
        if(x%3==0&&x%5==0)
            sum+=0;
        else if(x%3==0)
            sum+=0;
        else if(x%5==0)
            sum+=0;
        else sum+=x;


     }
     cout<<sum<<"\n";
    return 0;
}



Measured memory_bytes: 3696
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int solve(vector<vector<int> > v, int d)
{
  int cnt = 0;
  for(vector<int> local : v)
  {
    if(sqrt(pow(local[0],2) + pow(local[1],2)) <= d)
    {
      cnt++;
    }
  }
  return cnt;
}
int main()
{
  int n = 0, d = 0;
  cin >> n >> d;
  vector<vector<int> > points(n);
  for(int i = 0; i < n; i++)
  {
    vector<int> local(2);
    cin >> local[0] >> local[1];
    points[i] = local;
  }
  int ans = solve(points, d);
  cout << ans;
}


Measured memory_bytes: 25256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {

    long long H;
    cin >> H;

    long long ans = 0;
    long long n = 1;
    while ( H > 1 ) {
        ans += n;
        n *= 2;
        H /= 2;
    }
    ans += n;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main { 
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String o="";
        int x=sc.nextInt();
        String y=sc.next();
        if(y.length()<=x)o=y;
      	else o=y.substring(0,x)+"...";
      System.out.println(o);
    }
    
}

Measured memory_bytes: 38588
#include<stdio.h>

int main(void){
	int a,b,c;
	char op;
	
	while(1){
scanf("%d %c %d",&a,&op,&b);
		if ( op =='+'){
			c = a + b;
					printf("%d\n",c);
		}else if( op == '-'){
			c = a - b;
					printf("%d\n",c);
		}else if( op == '*'){
			
			 c = a * b;
			 		printf("%d\n",c);
		}else if( op =='/'){
			c = a/b;
					printf("%d\n",c);
		}
		if( op =='?') break;
	}
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
int max(int x, int y){return x<y?y:x;}
int main(void){
	int N,K,i;
	long long ans=0;
	scanf("%d%d",&N,&K);
	for(i=1;i<=N;i++){
		int p = N/i,r=N%i;
		ans += p*max(0,i-K)+max(0,r-K+1);
	}
	if(K==0)ans -= N;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(){
 
  int n,i,j,k,c[4][13],y;
  char x;
 
  for (i = 0; i < 4; i++){
 
    for (j = 0; j < 13; j++){
 
      c[i][j]=0;
 
    }
 
  }
 
  scanf("%d",&n);
 
  for (k = 0; k < n*2; k++){
 
    scanf("%c %d",&x,&y);
 
    if (x == 'S'){
 
      c[0][y-1]=1;
 
    } else if (x == 'H'){
 
      c[1][y-1]=1;
 
    } else if (x == 'C'){
 
      c[2][y-1]=1;
 
    } else if (x == 'D'){
 
      c[3][y-1]=1;
 
    }
 
  }
 
    for (i = 0; i < 4; i++){
 
      for (j = 0; j < 13; j++){
 
    if (c[i][j] == 0){
 
      if (i == 0){
 
        printf("S %d",j+1);
 
      } else if (i == 1){
           
          printf("H %d",j+1);
           
      } else if (i == 2){
          
          printf("C %d",j+1);
           
          } else if (i == 3){
           
          printf("D %d",j+1);
 
        }
 
      printf("\n");
 
    }
 
      }
 
    }
     
    return 0;         
 
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

ll a[200010];

int main() {
    int n;cin>>n;
    rep(i,n) {
        cin>>a[i];
        a[i]-=i+1;
    }
    ll b;
    sort(a,a+n);
    if(n%2==0) {
        b = (a[n/2]+a[n/2-1])/2;
    } else {
        b = a[n/2];
    }

    ll ans = 0;
    rep(i,n) ans+=abs(a[i]-b);
    cout<<ans<<endl;
}

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

using ll=__int128;
const ll INF=1e15;
int main(){
    vector<vector<ll>> comb(300,vector<ll>(300,0));
    for(int i=0;i<300;i++){
        comb[i][0]=1;
        comb[i][i]=1;
    }
    for(int i=1;i<300;i++){
        for(int j=1;j<i;j++){
            comb[i][j]=min(comb[i-1][j]+comb[i-1][j-1],INF);
        }
    }
    long long bufn;
    cin>>bufn;
    ll n=bufn;
    vector<int> ans;

    auto calcPatSingle=[&](int len){
        ll sum=0;
        for(int k=2;k<=len;k+=2){
            sum+=comb[len][k];
        }
        return sum;
    };
    auto calcPatCross=[&](int li,int lk,int lj,int lp){
        ll sum=0;
        for(int i=1;i<=min(li,lk);i++){
            sum+=comb[li][i]*comb[lk][i];
        }
        ll sum2=0;
        for(int i=1;i<=min(lj,lp);i++){
            sum2+=comb[lj][i]*comb[lp][i];
        }
        return sum*sum2;
    };
    int num=1;
    while(n){
        int besti=-1;
        int bestj=-1;
        int bestk=-1;
        int bestp=-1;
        ll bestSum=0;
        for(int i=1;i<=20;i++){
            for(int k=0;i+k<=40;k++){
                for(int j=0;j<=20;j++){
                    for(int p=0;p+j<=i+k;p++){
                        ll sum=calcPatSingle(i+k)+calcPatSingle(j+p)+calcPatCross(i,k,j,p);
                        if(sum<=n && double(bestSum)/(besti+bestj+bestk+bestp)<double(sum)/(i+j+k+p)){
                            besti=i,bestj=j,bestk=k,bestp=p;
                            bestSum=sum;
                        }
                    }
                    
                }
            }
        }
        n-=bestSum;
        
        for(int i=0;i<besti;i++){
            ans.push_back(num);
        }
        for(int j=0;j<bestj;j++){
            ans.push_back(num+1);                
        }
        for(int i=0;i<bestk;i++){
            ans.push_back(num);
        }
        for(int j=0;j<bestp;j++){
            ans.push_back(num+1);                
        }

        num+=2;
    }

    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++){
        cout<<ans[i]<<(i+1==ans.size() ? "\n" : " ");
    }
    return 0;
}

Measured memory_bytes: 1664
import qualified Data.ByteString.Char8 as C
import           Data.Maybe ( fromJust )
import           Data.List ( sortBy )
import qualified Data.Vector.Unboxed as U

getParm :: IO [Int]
getParm = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  n <- readLn :: IO Int
  ass <- getParm
  print $ f' n ass

sort' :: [Int] -> [Int]
sort' = sortBy (flip compare)

f' n ass = sum [vs U.! i | i<- [1,3 .. 2*n-1]
                         , let vs = U.fromList (sort' ass)]

Measured memory_bytes: 61820
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[3] = {1,0,-1};
int dy[3] = {1,0,-1};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  string S;
  cin >> S;
  stack<char> que;
  REP(i,S.size()){
    if(S[i] == 'B'){
      if(!que.empty())
        que.pop();
    }else
      que.push(S[i]);
  }
  string T="";
  while(!que.empty()){
    T =  T + que.top();
    que.pop();
  }
  reverse(T.begin(),T.end());
  cout << T << endl;
  return 0;  
}



Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;
#define mo 1000000007
#define ull unsigned long long 
int main(){
  int n;
  string s;
  cin>>n>>s;
  int ans=0;
  for(int i=0;i<n-2;i++)
  {
    if(s.at(i)=='A'&&s.at(i+1)=='B'&&s.at(i+2)=='C')
      ans++;
  }
  cout<<ans;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long


int n,k;

int32_t main()
{
	IOS;
	cin>>n>>k;
	if(n>k){
		int diff= n/k;
		n= n- diff*k;
	}
	if(n<=(k/2))
		cout<<n<<endl;
		
	
	else if(n<=k)
		cout<<k-n<<endl;
		
	
	
	return 0;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif

int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    int A, B; cin >> A >> B;

    string ans = (A<=8 && B<=8) ? "Yay!" : ":(";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  for(int i = 0; i < N; i++){
    cin >> S.at(i);
  }
  sort(S.begin(), S.end());
  S.erase(unique(S.begin(), S.end()), S.end());
  cout << S.size() << endl;
}

Measured memory_bytes: 9596
#include <iostream>

using namespace std;
const int MOD = 1e9+7;
int n,dp[101][4][4][4],A=1,G=2,C=3,T=0,res=0;
bool notok(int i,int j,int k)
{
    if (i==A&&j==G&&k==C) return true;
    if (i==A&&j==C&&k==G) return true;
    if (i==G&&j==A&&k==C) return true;
    return false;
}
int main()
{
    //freopen("D.INP","r",stdin);
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin >> n;
    for (int a=0;a<4;a++)
        for (int b=0;b<4;b++)
            for (int c=0;c<4;c++)
                if (notok(a,b,c)) continue;
                else dp[3][a][b][c]=1;
    for (int i=3;i<n;i++)
        for (int a=0;a<4;a++)
            for (int b=0;b<4;b++)
                for (int c=0;c<4;c++)
                {
                    if (notok(a,b,c)) continue;
                    for (int d=0;d<4;d++)
                    {
                        if (a==A&&c==G&&d==C) continue;
                        if (a==A&&b==G&&d==C) continue;
                        dp[i+1][b][c][d]+=dp[i][a][b][c],dp[i+1][b][c][d]%=MOD;
                    }

                }
    for (int a=0;a<4;a++)
            for (int b=0;b<4;b++)
                for (int c=0;c<4;c++)
                {
                    if (notok(a,b,c)) continue;
                    res+=dp[n][a][b][c];
                    res%=MOD;
                }
    cout << res;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;

int main(){
  int n;
  cin>>n;
  int ans=0;
  for(int i=1;i<=n;i+=2){
    int count=0;
    for(int j=1;j<=i;j++){
      if(i%j==0)count++;
    }
    if(count==8)ans++;
  }
  cout<<ans<<endl;
}
    

Measured memory_bytes: 256
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

N, K = list(map(int, input().split()))

ans = Base_10_to_n(N, K)
print(len(str(ans)))


Measured memory_bytes: 2940
#include <iostream>
#include <string>

using namespace std;

int main()
{
	long long N, K;
	cin >> N >> K;

	double ans = 0;

	for (long long x = 1; x <= N; ++x) {
		double p = 1.0 / N;
		for (long long y = x; y < K; y *= 2) {
			p /= 2;
		}
		ans += p;
	}
	printf("%.12f\n", ans);
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

typedef pair<int,int> par;

const int N=200010,P=1e9+7,inv2=P+1>>1;

int n,cnt,G[N],dpt[N];
struct edge{
  int t,nx;
}E[N];
struct tp{
  int x,y,z;
  tp(){}
  tp(int a,int b,int c):x(a),y(b),z(c){}
};

inline void addedge(int x,int y){
  E[++cnt].t=y; E[cnt].nx=G[x]; G[x]=cnt;
}

inline int Pow(int x,int y){
  int ret=1;
  for(;y;y>>=1,x=1LL*x*x%P) if(y&1) ret=1LL*ret*x%P;
  return ret;
}

deque<tp> f[N];

void dfs(int x){
  int mx=0,smx=0;
  for(int i=G[x];i;i=E[i].nx){
    dfs(E[i].t); int v=E[i].t;
    if(f[v].size()>mx) smx=mx,mx=f[v].size();
    else smx=max(smx,(int)f[v].size());
    if(f[v].size()>f[x].size()) swap(f[x],f[v]);
    for(int j=0;j<f[v].size();j++){
      tp cur;
      cur.x=(1LL*f[x][j].x*f[v][j].y+1LL*f[v][j].x*f[x][j].y)%P;
      cur.y=1LL*f[x][j].y*f[v][j].y%P;
      cur.z=(1LL*f[x][j].x*f[v][j].x+1LL*f[x][j].x*f[v][j].z+1LL*f[x][j].y*f[v][j].z+1LL*f[x][j].z*f[v][j].x+1LL*f[x][j].z*f[v][j].y+1LL*f[x][j].z*f[v][j].z)%P;
      f[x][j]=cur;
    }
  }
  for(int i=0;i<smx;i++){
    f[x][i].y=(f[x][i].y+f[x][i].z)%P;
    f[x][i].z=0;
  }
  f[x].push_front(tp(inv2,inv2,0));
}

int main(){
  scanf("%d",&n);
  for(int i=1,x;i<=n;i++)
    scanf("%d",&x),addedge(x,i);
  dfs(0); int ans=0;
  for(int i=0;i<f[0].size();i++)
    ans=(ans+f[0][i].x)%P;
  ans=1LL*ans*Pow(2,n+1)%P;
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 234240
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a) for(int i = 0; i < a; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int a,b,x; cin>>a>>b>>x;
    if(a>x||a+b<x)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}

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

int main() {
	long long N;
	cin >>N;
	long long ans=0;
	for (size_t i = 1; i <= N; i++)
	{
		if (i % 3 != 0 && i % 5 != 0)ans += i;
	}
	cout << ans;
}

Measured memory_bytes: 3632
#include<stdio.h>

int A[100000],n;

int binarySearch(int key){
	int left=0;
	int right=n;
	int mid;
	
	while(left<right){
		mid=(left+right)/2;
		if(key==A[mid]) return 1;
		if(key>A[mid]) left=mid+1;
		else if(key<A[mid]) right=mid;
	}
	return 0;
}

int main(){
	int i,q,k,sum=0;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	
	scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&k);
		if(binarySearch(k)) sum++;
	}
	printf("%d\n",sum);
	
	return 0;
}

Measured memory_bytes: 976
<?php
$s = str();
$n = strlen($s);
$sum = 0;
for($i = 0; $i < 2**($n-1);$i++){
    $flags = sprintf("%0".($n-1)."b", $i);
    $num = 0;
    for($j = 0; $j < $n; $j++){
        $num = $num*10+$s[$j];
        if($j == $n-1 || $flags[$j]==1){
            $sum+=$num;
            $num = 0;
        }
    }
    $sum+=$num;
}
echo $sum;

function str(){return trim(fgets(STDIN));}
function ints(){return array_map('intval',explode(' ',trim(fgets(STDIN))));}
function int(){return intval(trim(fgets(STDIN)));}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}
function popcount($x){$c=0;while($x){$x&=$x-1;++$c;}return$c;}
function o(...$val){
    if(count($val)==1)$val=array_shift($val);
    echo debug_backtrace()[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0)echo "empty array";
        elseif(!is_array(current($val)))echo "array: ",implode(" ", addIndex($val)),"\n";
        else{
            echo "array:array\n";
            if(isCleanArray($val))foreach($val as $row)echo implode(" ", addIndex($row)),"\n";
            else foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row)),"\n";
        }
    }else echo $val."\n";
}
function addIndex($val){if(!isCleanArray($val)){$val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);}return $val;}
function isCleanArray($array){$clean=true;$i = 0;foreach($array as $k=>$v){if($k != $i++)$clean = false;}return $clean;}
// 座圧対象の配列 -> [圧縮された配列,復元用のMap,圧縮用のMap]
function atsu($array){$a = array_flip($array);$fuku=array_flip($a);sort($fuku);$atsu = array_flip($fuku);foreach($array as $i=>$val)$array[$i]=$atsu[$val];return [$array, $fuku, $atsu];}
function gcdAll($array){$gcd=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$gcd=gcd($gcd,$array[$i]);}return $gcd;}
function gcd($m, $n){if(!$n)return $m;return gcd($n, $m % $n);}
function lcmAll($array){$lcm=$array[0];for($i=1,$I=count($array);$i<$I;++$i){$lcm=lcm($lcm,$array[$i]);}return $lcm;}
function lcm($a, $b) {return $a / gcd($a, $b) * $b;}

function dfs($current, $from = -1, $d = 0){
  global $G, $distance;
  $distance[$current] = $d;
  foreach($G[$current] as $to){
    if($from != $to){
      dfs($to, $current, $d + 1);
    }
  }
}

function loadTree($N = false){
  if($N === false)$N = $GLOBALS['N'];
  return loadGraph($N, $N-1);
}
function loadGraph($N = false, $M = false, $both = true){
  if($N === false)$N = $GLOBALS['N'];
  if($M === false)$N = $GLOBALS['M'];
  $G = array_fill(1, $N, []);
  for($i = 0; $i < $M; $i++){
    $values = ints();
    if(count($values) == 2){
      list($a, $b) = $values;
      $G[$a][] = $b;
      if($both)$G[$b][] = $a;
    }else{
      list($a, $b, $d) = $values;
      $G[$a][] = [$b, $d];
      if($both)$G[$b][] = [$a, $d];
    }
  }
  return $G;
}


Measured memory_bytes: 4728
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double dist = sc.nextDouble();
        double speed = sc.nextDouble();
        double time = sc.nextDouble();
        if (dist / speed <= time) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 37168
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,double> P;
int main(){
  int n,m,p,a,b;
  while(cin>>n>>m>>p>>a>>b,n){
    a--,b--;

    double t[8],tp;
    vector<P> e[31];

    for(int i=0;i<n;i++)cin>>t[i];
    for(int j=0,x,y;j<p;j++){
      cin>>x>>y>>tp;
      x--,y--;
      e[x].push_back(P(y,tp)),e[y].push_back(P(x,tp));
    }

    double dp[9][1<<8][30];
    for(int i=0;i<=n;i++)
      for(int j=0;j<1<<n;j++)
	for(int k=0;k<m;k++)dp[i][j][k]=1e4;
    dp[0][0][a]=0;

    for(int i=0;i<n;i++)
      for(int j=0;j<1<<n;j++)
	for(int k=0;k<m;k++)
	  for(int l=0;l<n;l++)
	    if(!(j&1<<l))
	      for(int w=0;w<e[k].size();w++)
		dp[i+1][j+(1<<l)][e[k][w].first]
	   =min(dp[i+1][j+(1<<l)][e[k][w].first],dp[i][j][k]+e[k][w].second/t[l]);

    double ans=1e4;
    for(int i=0;i<=n;i++)
      for(int j=0;j<1<<n;j++)ans=min(ans,dp[i][j][b]);
    if(ans==1e4)cout<<"Impossible"<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3736
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int a[25][25] = {0};
    int H, W, h, w;
    scanf("%d %d", &H, &W);
    scanf("%d %d", &h, &w);
    for(int i = 0; i < h; ++i)
        for(int j = 0; j < W; ++j)
            a[i][j] = 1;
    for(int i = 0; i < w; ++i)
        for(int j = 0; j < H; ++j)
            a[j][i] = 1;
    int ans = 0;
    for(int i = 0; i < H; ++i)
    {
        for(int j = 0; j < W; ++j)
        {
            if(a[i][j] == 0)
                ++ans;
        }
    }
    printf("%d\n", ans);
    return 0;
}

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

int main() {
  int a;
  cin>>a;
  if(a<1200)cout<<"ABC"<<endl;
  else if(a<2800)cout<<"ARC"<<endl;
  else if(a>=2800)cout<<"AGC"<<endl;
  
}

Measured memory_bytes: 256