akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

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

    int n;
    cin >> n;
    while (n--) {
        string s;
        cin >> s;
        string t;
        cin >> t;
        int m = t.size();

        reverse(all(s));
        rep(i, s.size()) {
            if (s[i] == 'J') {
                t = t[m - 1] + t.substr(0, m - 1);
            }
            if (s[i] == 'C') {
                t = t.substr(1) + t[0];
            }
            if (s[i] == 'E') {
                string u = "";
                u += t.substr((m + 1) / 2);
                if (m % 2 == 1) u += t[m / 2];
                u += t.substr(0, m / 2);
                t = u;
            }
            if (s[i] == 'A') {
                reverse(all(t));
            }
            if (s[i] == 'P') {
                rep(j, m) {
                    if (isdigit(t[j])) {
                        t[j] = (t[j] - '0' - 1 + 10) % 10 + '0';
                    }
                }
            }
            if (s[i] == 'M') {
                rep(j, m) {
                    if (isdigit(t[j])) {
                        t[j] = (t[j] - '0' + 1) % 10 + '0';
                    }
                }
            }
        }

        cout << t << endl;
    }
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
signed main(){
	int n;
	cin >> n;
	if(n<1200){
		cout << "ABC" << endl;
	}else{
		cout << "ARC" << endl;
	}
return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define vec vector
#define fi first
#define se second
#define eb emplace_back
#define ef emplace_front
#define pof pop_front()
#define pob pop_back()
#define Rep(i,n) for(li i=0,nn=(li)(n);i!=nn;++i)
#define Rep1(i,n) for(li i=1,nn=(li)(n)+1;i!=nn;++i)
#define Size(v) (li)(v.size())
#define SortA(v) sort(v.begin(),v.end())
#define SortD(v) sort(v.rbegin(),v.rend())
#define All(a) (a).begin(),(a).end()
#define Input(a) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii);}
#define Input2(a,b) for(li ii=0,nn=(li)(a.size());ii!=nn;++ii){cin>>(a).at(ii)>>(b).at(ii);}
#define mp make_pair
using li = int64_t;
using intl = int64_t;
using vi = vec<li>;
using vb = vec<bool>;
using vvi = vec<vi>;
using qi = deque<li>;
using pi = pair<li, li>;
using vpi = vec<pi>;
using si = set<li>;
using vsi = vec<si>;
using mii = map<li, li>;
using vmii = vec<mii>;
vec<li> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<li> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr li INF = LLONG_MAX;

void Yes(li b) {
	if (b)cout << "Yes";


	else cout << "No";
}
void yes(li b) {
	if (b)cout << "yes";
	else cout << "no";
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	cout.precision(16);

	li D,T,S;

	cin >>D>>T>>S;

	Yes(T*S>=D);

}

Measured memory_bytes: 3652
N, K = map(int, input().split())
num = list(range(N+1))
ans = 0
S = [0] * (N+1)
for i in range(N+1):
  S[i] = S[i-1] + num[i]
ans = 0
if K == N+1:
  print(1)
  exit()
for j in range(K-1, N):
  ans += S[-1] - S[-j-2] - S[j] + 1
print((ans+1) % (10**9+7))

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

template <typename T>
unordered_map<T,int> pfact(T m)
{
    unordered_map<T,int> ps;
    T tmp = m;
    for(T i=2;i*i<=m;++i)
    {
        while(tmp%i == 0)
        {
            if(ps.count(i) == 0)
                ps[i] = 0;
            ps[i]++;
            tmp /= i;
        }

        if(tmp == 1)
            break;
    }

    if(tmp > 1)
    {
        if(ps.count(tmp) == 0)
            ps[tmp] = 0;
        ps[tmp]++;
    }

    return move(ps);
}

int main()
{
    const i64 MOD = 1e9+7;
    i64 n;
    cin >> n;
    vector<i64> a(n);
    rep(i,n) cin >> a[i];

    unordered_map<i64,int> ps;
    rep(i,n)
    {
        auto tmp_ps = pfact<i64>(a[i]);
        for(auto& i : tmp_ps)
        {
            if(ps.count(i.first) == 0) ps[i.first] = i.second;
            else ps[i.first] = max(ps[i.first], i.second);
        }
    }

    i64 sum = 0;
    rep(i,n)
    {        
        auto tmp_ps = pfact<i64>(a[i]);
        i64 g = 1;
        for(auto i:ps)
        {
            i64 cnt = i.second;
            if(tmp_ps.count(i.first)) cnt -= tmp_ps[i.first];

            rep(j,cnt)
            {
                g *= i.first;
                g %= MOD;
            }
        }
        
        sum += g;
        sum %= MOD;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t;
    }
    return n*rep_jijo(n,x-1);
}

int main(){
    ll n,y;
    cin >> n >> y;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            int k=n-(i+j);
            if(k<0) continue;
            ll sum=10000*i+5000*j+1000*k;
            if(sum==y){
                cout << i <<" " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 <<endl;
    return 0;
}

Measured memory_bytes: 256
#python3
def main():
    n, m = map(int, input().split())
    cards = [(int(i), 1) for i in input().split()]
    for _ in range(m):
        b, c = map(int, input().split())
        cards.append((c, b))
    cards.sort(reverse=True)
    ans = 0
    sumv = 0
    for i in range(n):
        v = cards[i][1]
        cv = cards[i][0] * v
        ans += cv
        sumv += v
        if sumv >= n:
            ans -= cards[i][0] * (sumv - n)
            break
    print(ans)
main()

Measured memory_bytes: 28888
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [0]*(n)
for i in range(1, min(n, k+1)) :
    dp[i] = abs(h[0]-h[i])
for i in range(k+1, len(dp)) :
    minv = 10**9+7
    for j in range(1, k+1) :
        minv = min(minv, dp[i-j] + abs(h[i-j]-h[i]))
    dp[i] = minv

print(dp[n-1])


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

using namespace std;

using int64 = long long;

int s(int64 n) {
  int ret = 0;
  while(n > 0) {
    ret += n % 10;
    n /= 10;
  }
  return ret;
}

int main() {
  vector< int64 > candidate;
  for(int i = 0; i <= 15; i++) {
    int64 base = 1;
    for(int j = 0; j < i; j++) base *= 10;
    for(int j = 1; j < 1000; j++) {
      candidate.push_back(base * j + (base - 1));
    }
  }
  sort(begin(candidate), end(candidate));
  candidate.erase(unique(begin(candidate), end(candidate)), end(candidate));
  int K;
  vector< int64 > ret;
  for(int i = 0; i < candidate.size(); i++) {
    bool f = true;
    for(int j = i + 1; j < candidate.size(); j++) {
      int64 n = candidate[i], m = candidate[j];
      if((__int128_t) n * s(m) > (__int128_t) m * s(n)) {
        f = false;
        break;
      }
    }
    if(f) ret.push_back(candidate[i]);
  }
  cin >> K;
  for(int i = 0; i < K; i++) {
    cout << ret[i] << endl;
  }
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	int c=0;
	cin>>n;
	vector<int>a(n);
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	for(int i=0;i<n;++i){
		if(i%2==0&&a[i]%2)++c;
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int main() {
    ll N; cin >> N;
    map<string, ll> m;
    for (int i = 0; i < N; ++i) {
        string s; cin >> s;
        if(!m.count(s)) m[s] = 0;
        m[s]++;
    }
    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

using std::min;
using std::max;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

inline int nextInt()
{
    int x = 0;
    char c = getchar();
    int mi = (c == '-');
    if (c == '-') c = getchar();
    while ('0' <= c && c <= '9')
    {
        x = 10 * x + c - '0';
        c = getchar();
    }
    if (mi) return x * -1;
    return x;
}

int p[500000];
int g[500000];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); i++)
    {
        if (i > 0) p[i] = p[i - 1], g[i] = g[i - 1];
        if (s[i] == 'p') p[i]++;
        else g[i]++;
    }
    int r = g[s.size() - 1] - p[s.size() - 1];
    cout << max(0, r / 2);
}

Measured memory_bytes: 1232
def main():
    from collections import Counter
    n = int(input())
    V = map(int,input().split())
    odds = []
    evens = []
    for i,v in enumerate(V):
        if i & 1:
            evens.append(v)
        else:
            odds.append(v)
    
    odds_counter = list(Counter(odds).items())
    eves_counter = list(Counter(evens).items())
    
    odds_counter.sort(reverse=True, key= lambda x: x[1])
    eves_counter.sort(reverse=True, key= lambda x: x[1])

    if odds_counter[0][0] != eves_counter[0][0]:
        print(len(odds)- odds_counter[0][1] + len(evens) - eves_counter[0][1])
    else:
        odds_counter.append((-1,0))
        eves_counter.append((-1,0))

        print(
            min(
                len(odds)-odds_counter[0][1] + len(evens) - eves_counter[1][1],
                len(odds)-odds_counter[1][1] + len(evens) - eves_counter[0][1],
            )
        )
            
        

    

    
    
    


main()

Measured memory_bytes: 96020
"use strict";
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

var re = /\s+|$/;
reader.on('close', () => {
    var rc = []
    var line=lines.shift() 
    var x=line.trim().split(' ').map(Number)
    var r=x[0]
    var c=x[1]
    
    while (lines.length > 0) {
	line=lines.shift()
	var l = line.trim().split(' ').map(Number);
	rc.push(l)
    }

    var rc1=aux(rc);

    rc1=rc.map(x=>x.map(y=>y.toString()).join(' '))
    rc1.forEach(x=>console.log(x))

});

function dump(rc)
{
    var n=rc.length
    var m=rc[0].length
    console.log("n: "+ n+" m: "+m)
    for (var i=0;i<n; i++){
	console.log(rc[i].map(Number).join(' '))
    }
	
}
function sum(r)
{
    return r.reduce(function(s,x){return s+x},0)
}

function aux(rc)
{
    rc.forEach(r=>r.push(sum(r)))
    //dump(rc)
    const cl=rc[0].length
    const rl=rc.length

    var cs=[]
    for (var j=0; j<cl; j++){
	let s=0
	for (var i=0; i<rl; i++){
	    s += rc[i][j]
	}
	cs.push(s)
    }
    rc.push(cs)
    //dump(rc)

    return(rc)
}


Measured memory_bytes: 17864
S = list(input())
N = len(S)
hn = int((N-1)/2)
for i in range(hn):
  if S[i] != S[N-1-i]:
    print('No')
    exit()
for i in range(hn//2):
  if S[i] != S[hn-1-i]:
    print('No')
    exit()
for i in range(hn//2):
  if S[hn+1+i] != S[N-1-i]:
    print('No')
    exit()
x = hn//2
if hn % 2 == 1:
  if S[x] != S[N-1-x]:
    print('No')
    exit()
print('Yes')


Measured memory_bytes: 3064
def r;gets.split.map &:to_i;end

N,W = r
DP = [[0,0]] # weight, value

N.times do
  w,v = r
  DP.size.times do |i|
    next if DP[i][0] + w > W
    DP << [DP[i][0] + w, DP[i][1] + v]
  end

  DP.sort!

  i = 0
  while i < DP.size - 1
    unless DP[i][1] < DP[i+1][1]
      DP.delete_at(i+1)
    else
      i += 1
    end
  end
end

p DP[-1][1]

Measured memory_bytes: 3836
#include<stdio.h>

int main(){
  int i,j;
  int n,r,p,c;
  int tmp;
  int A[51],B[51],R[51];
  while(1){

    scanf("%d %d",&n,&r);
    if(n==0 && r==0) break;
    for(i=n;i>0;i--){
      A[n-i]=i; 
      B[n-i]=i;
    }
    //for(i=0;i<n;i++)printf("%d %d %d\n",A[i],B[i],i);
    //for(i=0;i<n;i++) R[i]==0;

    for(i=0;i<r;i++){
      scanf("%d %d",&p,&c);
      //if(p==0 && c==0) break;
      
      for(j=0;j<p-1;j++) B[j+c]=A[j];
      for(j=p-1;j<p-1+c;j++) B[j-(p-1)]=A[j];
      //for(j=0;j<n;j++)    printf("%d\n",B[j]);
      for(j=0;j<n;j++)A[j]=B[j];
    }
    printf("%d\n",B[0]);
  }
  return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
int n,d;
int arr[1000][100];
int main(){
	scanf("%d%d",&n,&d);
	for(int i=0;i<n;i++){
		for(int j=0;j<d;j++){
			scanf("%d",&arr[i][j]);
		}
	} 
	int sumss=0,index=0;
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			sumss=0;
			for(int k=0;k<d;k++){
				sumss+=((arr[i][k]-arr[j][k])*(arr[i][k]-arr[j][k]));
			}
			int s=sqrt(sumss);
//			printf("%d    %d   %d --> %d\n",arr[i][0],arr[j][0],s,sumss);
			if(s*s==sumss){
				index+=1;
			}
		}
	}
//	sumss=0;
//	for(int k=0;k<d;k++){
//		sumss+=((arr[n-1][k]-arr[0][k])*(arr[n-1][k]-arr[0][k]));
//	}
//	int s=sqrt(sumss);
//	if(s*s==sumss){
//		index+=1;
//	}
	printf("%d",index);
	return 0;
} 

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

int main(){
  string s;
  cin >> s;
  int ans = 0, num = 0;
  rep(i,s.size(),0){
    if(s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C') num++;
    else{
      if(num > ans) ans = num;
      num = 0;
    }
  }
  if(num > ans) ans = num;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int H, W;
  cin >> H >> W;
  char a[H][W];

  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> a[i][j];
    }
  }

  for (int i = 0; i < W + 2; i++){
    printf("#");
  }
  printf("\n");

  for (int i = 0; i < H; i++){
    printf("#");
    for (int j = 0; j < W; j++){
      printf("%c",a[i][j]);
    }
    printf("#\n");
  }
  
  for (int i = 0; i < W + 2; i++){
    printf("#");
  }
  printf("\n");
}


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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    ll ans = mod;
    ll A[N]; rep(i, N) cin >> A[i];
    ll sumA[N+1] = {}; rep(i, N) sumA[i+1] = sumA[i] + A[i];
    for(int mid = 2; mid <= N-2; mid++){
        //左側と右側それぞれ絶対値の差が少なくなるようにする
        //左側の境目lとするとabs(sumA[l] - (sumA[mid]-sumA[l]))
        //右側の境目rとするとabs((sumA[r]-sumA[mid] - (sumA[N]-sumA[r]))
        ll key_left = sumA[mid]/2, key_right = (sumA[N]+sumA[mid])/2;
        int ok_left = 0, ng_left = mid, ok_right = mid, ng_right = N;
        int m = (ok_left + ng_left)/2;
        while(abs(ok_left-ng_left) > 1){
            if(sumA[m] <= key_left) ok_left = m;
            else ng_left = m;
            m = (ok_left+ng_left)/2;
        }
        ll P, Q, R, S;
        ll eval1 = abs(sumA[ok_left] - (sumA[mid]-sumA[ok_left]));
        ll eval2 = abs(sumA[ok_left+1] - (sumA[mid]-sumA[ok_left+1]));
        if(eval1 <= eval2){
            P = sumA[ok_left];
            Q = sumA[mid]-sumA[ok_left];
        }
        else{
            P = sumA[ok_left+1];
            Q = sumA[mid]-sumA[ok_left+1];
        }

        m = (ok_right+ng_right)/2;
        while(abs(ok_right-ng_right) > 1){
            if(sumA[m] <= key_right) ok_right = m;
            else ng_right = m;
            m = (ok_right+ng_right)/2;
        }
        ll eval3 = abs(sumA[ok_right]-sumA[mid] - (sumA[N]-sumA[ok_right]));
        ll eval4 = abs(sumA[ok_right+1]-sumA[mid] - (sumA[N]-sumA[ok_right+1]));
        if(eval3 <= eval4){
            R = sumA[ok_right]-sumA[mid];
            S = sumA[N]-sumA[ok_right];
        }
        else{
            R = sumA[ok_right+1]-sumA[mid];
            S = sumA[N]-sumA[ok_right+1];
        }
        ll choose[] = {P, Q, R, S};
        sort(choose, choose+4);
        ans = min(ans, choose[3]-choose[0]);
        //if(mid == 4) cout << P << " " << Q << " " << R << " " << S << endl;
        //if(mid == 4) cout << key_right << endl;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int main() {
	int s[5];
	int a, b;
	while (cin >> a >> b, a || b) {
		s[0] = a + b;
		FOR(i, 1, 5) {
			cin >> a >> b;
			s[i] = a + b;
		}
		
		pii ma(-1, 0);
		REP(i, 5) chmax(ma, pii(s[i], i));
		
		printf("%c %d\n", ma.se + 'A', ma.fi);
	}
	return 0;
}

Measured memory_bytes: 3096
#include<cstdio>
#include<vector>
enum order{
    preorder=0,
    inorder=1,
    postorder=2,
};
class BinaryTree{
private:
    int numVertex;
    int *parent, *left, *right;
public:
    BinaryTree(int v);
    ~BinaryTree();
    void init();
    void dfs(int v,order flag);
    std::vector<int> root();
};
BinaryTree::BinaryTree(int v){
    numVertex=v;
    parent = new int[v];
    left = new int[v];
    right = new int[v];
    for(int i=0;i<v;i++){
        parent[i]=-1;
        left[i]=-1;
        right[i]=-1;
    }
}
BinaryTree::~BinaryTree(){
    delete[] parent;
    delete[] left;
    delete[] right;
}
void BinaryTree::init(){
    for(int i=0;i<numVertex;i++){
        int id,l,r;
        scanf("%d%d%d",&id,&l,&r);
        if(l>=0)parent[l]=id;
        if(r>=0)parent[r]=id;
        left[id]=l;
        right[id]=r;
    }
}
std::vector<int> BinaryTree::root(){
    std::vector<int> vec;
    for(int i=0;i<numVertex;i++){
        if(parent[i]==-1)vec.push_back(i);
    }
    return vec;
}
void BinaryTree::dfs(int v,order flag){
    if(v>=0){
        if(flag==preorder)printf(" %d",v);
        dfs(left[v],flag);
        if(flag==inorder)printf(" %d",v);
        dfs(right[v],flag);
        if(flag==postorder)printf(" %d",v);
    }
}
int main(){
    int n;
    scanf("%d",&n);
    BinaryTree t(n);
    t.init();
    std::vector<int> v=t.root();
    printf("Preorder\n");
    t.dfs(v[0],preorder);
    printf("\nInorder\n");
    t.dfs(v[0],inorder);
    printf("\nPostorder\n");
    t.dfs(v[0],postorder);
    printf("\n");
    return 0;
}


Measured memory_bytes: 2708
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    
    double a, b, c;
    double s, l, h;
    cin>>a>>b>>c;
    c=c*M_PI/180;
    s = a*b*sin(c)/2;
    l = a+b+sqrt(a*a+b*b-2*a*b*cos(c));
    h = s*2/a;
    cout<<s<<'\n'<<l<<'\n'<<h<<'\n';
    return 0;
}

Measured memory_bytes: 1296
from collections import deque
from itertools import chain

H, W = map(int, input().split())
M = [list(input()) for _ in range(H)]
inf = float('inf')


def flatten(list_of_lists):
    return chain.from_iterable(list_of_lists)


def bfs(start, end):
    distance = [[inf for i in range(W)] for j in range(H)]
    queue = deque([(end, start)])
    distance[end][start] = 0

    while queue:
        y, x = queue.pop()
        for i in range(0, 4):
            nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]
            if 0 <= nx < W and 0 <= ny < H and M[ny][nx] != '#' and distance[ny][nx] == inf:
                queue.appendleft((ny, nx))
                distance[ny][nx] = distance[y][x] + 1
    return distance


m = 0
for i in range(W):
    for j in range(H):
        if M[j][i] != "#":

            for length in list(flatten(bfs(i, j))):
                if length != inf and m < length:
                    m = length

print(m)


Measured memory_bytes: 3316
#include <iostream>
using namespace std;
int main() {
	int a;
	int b;
	int c;
	cin >> a >> b >> c ;
	if ( a < b ) {
		if (b < c) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		
		cout << "No" << endl ;
		

	}
	
	
}


Measured memory_bytes: 3052
#include<stdio.h>
#define INFTY 2100000001;
void mergeSort(int *A,int left,int right);
void merge(int *A,int left,int mid,int right);

int L[500000],R[500000];
int cnt;

int main(){
  int s[500001],n;
  int i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&s[i]);
  //in

  mergeSort(s,0,n);

  for(i=0;i<n-1;i++)
    printf("%d ",s[i]);
  printf("%d\n",s[i]);
  printf("%d\n",cnt);
  
  return 0;
}
void mergeSort(int *A,int left,int right){
  int mid;
  if (left+1 < right){
    //cnt++;
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}
void merge(int *A,int left,int mid,int right){
  int n1,n2;
  int i,j,k;
  //cnt++;
  n1 = mid - left;
  n2 = right - mid;
 
  for( i = 0 ;i< n1;i++)
    L[i] = A[left + i];
  for( i = 0;i< n2;i++)
    R[i] = A[mid + i];
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
    for (k = left;k< right;k++){
      if (L[i] <= R[j]){
	A[k] = L[i];
	i = i + 1;
	cnt++;
      }
      else {
	A[k] = R[j];
	j = j + 1;
	cnt++;
      }
    }
}



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

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<int> input(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> input[i];
		}
		sort(input.begin(), input.end());
		unsigned long long int sum = 0;
		unsigned long long int ans = 0;
		for(int i = 0; i < input.size() - 1; ++i)
		{
			sum += input[i];
			ans += sum;
		}
		cout << ans << endl;
	}
}

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

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'


ll mod_pow(ll x, ll p, ll M = MOD) {
  ll a = 1;
  while (p) {
    if (p % 2)
      a = a*x%M;
    x = x*x%M;
    p /= 2;
  }
  return a;
}

ll mod_inverse(ll a, ll M = MOD) {
  return mod_pow(a, M - 2, M);
}



int main() {
  ll n, k;
  cin >> n >> k;
  vl a(n);
  rep (i, n) cin >> a[i];
  ll ans = 0;
  rep (i, n) {
    for (int j = i + 1; j < n; j++) {
      if (a[j] < a[i]) ans++;
    }
  }
  ans *= k;

  ll add = 0;
  ll inv2 = mod_inverse(2);
  rep (i, n) {
    ll c = 0, b = 0;
    rep (j, n) {
      if (a[j] > a[i]) c++;
      if (a[j] < a[i]) b++;
    }
    add += c * (k - 1) % MOD * k % MOD * inv2 % MOD;
    add += b * (k - 1) % MOD * k % MOD * inv2 % MOD;
    add %= MOD;
  }
  add = add * inv2 % MOD;
  ans = (ans + add) % MOD;
  cout << ans << endl;
}


Measured memory_bytes: 256
/*---------------------------------

 @Author:   Dicer
 @DateTime: 2019-01-11 19:41:55

---------------------------------*/

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define clr(s, x) memset(s, x, sizeof(s))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
inline ll readll(){ll r=0;char c=getchar();while(c<'0'||c>'9') {c=getchar();}while(c>='0'&&c<='9') {r=r*10+c-'0';c=getchar();}return r;}
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
inline ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}
const double eps = 1e-8;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int mod = 998244353;
const int MAXN = 1e5+7;
const int MAXM = 1e5+7;

int main(int argc, char const *argv[])
{
	int n, a, b;
	cin >> n >> a >> b;
	int x, y, z, zz;
	x = y = z = 0;
	for(int i=1;i<=n;++i){
		cin >> zz;
		if(zz <= a)	x++;
		else if(zz <= b)	y++;
		else z++;
	}
	// cout << x << ' ' << y << ' ' << z << endl;
	cout << min(x, min(y, z)) << endl;
	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

template<typename t1, class t2>
void input(t1 count,t2* array) {
	for(t1 i = 0;i < count;i++) {
		cin >> array[i];
	}
}

template<typename t1, class t2>
void output(t1 count,t2 array) {
	for(t1 i = 0;i < count;i++) {
		cout << array[i];
		if(i != count - 1) cout << " ";
	}
	cout << endl;
}

int insSort(int* a,int n,int g) {
	int cnt = 0;
	for(int i = g;i < n;i++) {
		int v = a[i];
		int j = i - g;
		while(j >= 0 && a[j] > v) {
			a[j+g] = a[j];
			j -= g;
			cnt++;
		}
		a[j+g] = v;
	}
	return cnt;
}

int main(int argc,char** argv) {
	int n;
	cin >> n;
	int t = n;
	vector<int> g;
	while(t != 0) {
		g.push_back(t);
		t = t / 2;
	}
	int m = (signed)g.size();
	int* a = new int[n];
	input(n,a);
	int cnt = 0;
	for(int i = 0;i < m;i++) {
		cnt += insSort(a,n,g[i]);
	}
	cout << m << endl;
	output(m,g);
	cout << cnt << endl;
	for(int i = 0;i < n;i++) cout << a[i] << endl;
	delete a;
}



Measured memory_bytes: 6784
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(int n){
    cout << "Yes" << endl;
}

void no (int n){
    cout << "No" << endl;
}

int main() {
    string s; cin >> s;
    int n = s.size();
    string t = "";
    rep(i,n){
        if (i % 2 == 0) t += 'g';
        else t += 'p';
    }
    int ans = 0;
    rep(i,n){
        if (s[i] == 'g' && t[i] == 'p') ans++;
        else if (s[i] == 'p' && t[i] == 'g') ans--;
    }
    cout << ans << endl;
}

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

void min_self(ll &a , ll b){
	a=min(a,b);
}
const ll INF = 2e18 + 90 ;
int main(){
	
	ll  items, knapsack ;
	scanf("%lld%lld",&items,&knapsack);
	const ll nax = items * 1000 + 90 ;
	vector<ll> dp(nax+1,INF);
	dp[0] = 0;
	for(int i=0; i<items ; ++i){
		ll weight,value;
		scanf("%lld%lld",&weight,&value);
		for(ll j = nax-1; j>=value ; --j){
			min_self(dp[j], dp[j-value]+weight);
		}
	}
	
	ll ans = INF;
	for(ll i=nax-1 ; i>=0 ; i--){
		if(dp[i]<=knapsack){
			ans=i;
			break ;
		}
	}
	
	
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;


public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        int k = s.nextInt();
        String word = s.next();

        if(word.length()>k){
            String res = word.substring(0,k);
            res+="...";
            System.out.println(res);
        }
        else System.out.println(word);
    }
}




class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

Measured memory_bytes: 25168
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine().Split().Select(int.Parse).ToArray();
            if (N.Contains(1)&&N.Contains(7)&&N.Contains(9)&&N.Contains(4)) {
            Console.WriteLine("YES");
            } else {
               Console.WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 13396
n = int(input())
dishes = list(map(int, input().split()))
points = list(map(int, input().split()))
bonuses = list(map(int, input().split()))

score = 0
prev = 0
for i in dishes:
  score += points[i-1]
  if prev > 0:
    if i == prev + 1: score += bonuses[i-2]
  prev = i

print(score)


Measured memory_bytes: 9192
import java.util.*;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static int n, s, res;
    public static void main(String[] args) {
        while(read()){
            solve();
        }
    }
 
    static boolean read(){
        n = sc.nextInt();
        s = sc.nextInt();
        if( n == 0 && s == 0)return false;
        return true;
    }
     
    static void solve(){
        res = 0;
        dfs(0, n, 0);
        System.out.println(res);
    }
	
// dfs(検索する最小の数、足し合わせる数、合計)

    static void dfs(int i, int n, int sum){ 
        if(n == 0){
            if(sum == s)res++;
            return;
        }
         
        if(i > 9)return;
        for(int k = i; k <10; k++){
            dfs(k+1, n-1, sum+k);
        }
    }
}

Measured memory_bytes: 12000
// BEGINNING WITH NAME OF ALMIGHTY GOD ALLAH
// AUTHOR:: MOHAMMAD FAISAL
// ATCODER BEGINNERS PROBLEMS
//#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.flush();
      string a,b,c;
    cin >> a >> b >> c;
      cout<<char(a[0]-32)<<char(b[0]-32)<<char(c[0]-32);
    return 0;
    // Bye Bye 2019
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 10000000000000000;
const int mod = 1000000007;
string s[123456]; int g = 1;
void G(int n) {
	for (int a = 1; a < n; a++) {
		int kari = g;
		for (int h = 0; h < kari; h++) {
			int saidai = 0;
			for (int i = 0; i < s[h].size(); i++) {
				saidai = max(saidai, (int)(s[h][i] - 97));
			}
			for (int i = 0; i <= saidai; i++) {
				s[g] = s[h] + (char)(98 + i); g++;
			}
			s[h] += "a";
		}
	}
}
int iti[12345678], cnt[12345678], cost[4321][4321];
signed main() {
	int n, m, a = 140, b = 170, cnt = 30, ans = 0;
	cin >> n; s[0] = "a"; G(n); sort(s, s + g);
	for (int h = 0; h < g; h++) {
		cout << s[h] << endl;
	}
	cin >> n; return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
const long long INF = INT64_MAX;

#define REP(i, n) for(ll i=0;i<n;i++)
#define WHOLE(v) (v).begin(), (v).end()
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).rbegin(), (v).rend())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define ACCUM(v, d0, lambda) accumulate((v).begin(), (v).end(), d0, lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define DESC(v) sort((v).rbegin(), (v).rend())
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);erase(unique(v.begin(), v.end()), v.end())
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve() {
    ll H, W, N;
    cin >> H >> W >> N;
    set<pll> S;
    set<pll> B;
    for(int i = 0; i < N; i++) {
        ll a, b;
        cin >> b >> a;
        S.insert({a-1, b-1});
        for(int j = -1; j <= 1; j++) {
            for(int k = -1; k <= 1; k++) {
                ll x,y;
                x = a-1+j;y=b-1+k;
                if(x >= 1 && x < W - 1 && y >= 1 && y < H - 1){
                    B.insert({x, y});
                }
            }
        }
    }
    vll ans(10, 0);
    ans[0] = (H - 2) * (W - 2);
    for(auto &b:B) {
        ll ctr = 0;
        for(int j = -1; j <= 1; j++) {
            for(int k = -1; k <= 1; k++) {
                ctr += S.count({b.first+j, b.second+k});
            }
        }
        ans[ctr]++;
        ans[0]--;
    }
    for_each(WHOLE(ans), [&](auto r){cout << r << endl;});
}

int main() {
    FIO;
    solve();
    return 0;
}


Measured memory_bytes: 62720
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <string>
#include <iostream>

struct Vertex {
  std::vector<int> next;
  int type;
};

class Solver {
 public:
  Solver(std::vector<Vertex> vertices) : vertices(std::move(vertices)) {
  }
  bool has_cycle() {
    was.resize(vertices.size() * bad_string.size());
    for (int i = 1; i < (int)vertices.size(); i++) {
      if (dfs(i, 0)) {
        return true;
      }
    }
    return false;
  }

 private:
  std::vector<Vertex> vertices;
  std::string bad_string = "AABB";
  std::vector<int> was;
  bool dfs(int v, int s_pos) {
    //printf("%d %d\n", v, s_pos);
    s_pos %= bad_string.size();
    if (vertices[v].type != bad_string[s_pos]) {
      return false;
    }
    int v_id = v * (int)bad_string.size() + s_pos;
    if (was[v_id] == 1) {
      return true;
    }
    if (was[v_id] == 2) {
      return false;
    }
    was[v_id] = 1;
    for (auto next_v : vertices[v].next) {
      if (dfs(next_v, s_pos + 1)) {
        return true;
      }
    }
    was[v_id] = 2;
    return false;
  }
};

int main(void) {
  int n, m;

  while (scanf("%d%d", &n, &m) == 2) {
    std::string s;
    std::cin >> s;
    std::vector<Vertex> vertices(n + 1);
    for (int i = 0; i < n; i++) {
      vertices[i + 1].type = s[i];
    }
    for (int i = 0; i < m; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      vertices[a].next.push_back(b);
      vertices[b].next.push_back(a);
    }

    if (Solver(std::move(vertices)).has_cycle()) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  }

  return 0;
}


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


int main() {
  int H,W;
  cin >> H >> W;
  vector<string> s(H);
  for(int i=0; i<H; i++){
    cin >> s.at(i);
  }
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(s.at(i).at(j) == '#') continue;
      
      
      
      int num = 0;
      for(int dy=-1; dy<=1; dy++){
        for(int dx=-1; dx<=1; dx++){
          int ni = i+dy;
          int nj = j+dx;
          
          if(ni < 0 or H <= ni) continue;
          if(nj < 0 or W <= nj) continue;
          if(s.at(ni).at(nj) == '#') num++;
        }
      }
      s.at(i).at(j) = char(num + '0');
        
    }
    
  }
  for(int i=0; i<H; i++){
    cout << s.at(i) << endl;
  }
 
  
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main(){
  double n,k;
  cin >> n >> k;
  vector<int> a(n);
  int i;
  for(i=0;i<n;i++) cin >> a[i];
  if(n<=k) cout << 1 << "\n";
  else if(k==2) cout << n-1 << "\n";
  else cout << ceil((n-1)/(k-1)) << "\n";
  return 0;
}


Measured memory_bytes: 3736
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ
{
  class Program
  {
    public static void Main()
    {
      Console.WriteLine(Factorial(decimal.Parse(Console.ReadLine())));
    }

    static decimal Factorial(decimal n)
    {
      return Factorial(n, 1);
    }

    static decimal Factorial(decimal n, decimal acc)
    {
      if (n == 1)
        return acc;
      return Factorial(n - 1, n * acc);
    }
  }
}

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

#define   REP(i, n) for(int i = 0;            i <  (int)(n);        i++)
#define  CREP(i, n) for(int i = 1;            i <= (int)(n);        i++)
#define  RREP(i, n) for(int i = (int)(n) - 1; i >= 0;               i++)
#define RCREP(i, n) for(int i = (int)(n);     i >  0;               i++)
#define  BREP(i, n) for(int i = 0;            i <  (1 << (int)(n)); i++)

#define INF  std::numeric_limits<int>::max()
#define NINF std::numeric_limits<int>::min()

using namespace std;
using ll = long long;

std::string S;

ll solve() {
    ll sum = 0;

    // bit全探索
    BREP(bit, S.size() - 1) {
        int prev_assert_index = 0;
        CREP(i, S.size() - 1) {
            if(bit & (1 << (i - 1))) {
                sum += stoll(S.substr(prev_assert_index, i - prev_assert_index));
                prev_assert_index = i;
            }
        }
        sum += stoll(S.substr(prev_assert_index, S.size() - prev_assert_index));
    }

    return sum;
}

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

    std::cin >> S;

    std::cout << solve() << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define MAX  1e18
#define ss 1e15
#define pb push_back

int main() {
    lli a,b;
    cin>>a>>b;
    lli c = a + b;
    if(c%2 != 0){
        cout<<"IMPOSSIBLE\n";
    }else{
        cout<<c/2<<"\n";
    }
    return 0;
}





Measured memory_bytes: 256
N, K = map(int, input().split())
V = list(map(int, input().split()))
k = min(N, K)
v = 0
for i in range(k + 1):
    for j in range(k - i + 1):
        v_tmp = V[:i] + V[(N - j):]
        v_tmp.sort()
        for l in range(K - (i + j) + 1):
            v = max(v, sum(v_tmp[l:]))
print(v)

Measured memory_bytes: 3060
#include<stdio.h>

int H, W, N, K;
int ans_map[50][50];

void check4s(int h, int w, int num) {
	int p;
	int c = 0;
	
	printf("? %d %d %d %d\n", h, w, h, w);
	fflush(stdout);
	scanf("%d", &p);
	ans_map[h][w] = p;
	c += p;
	if(c == num) return;
	
	printf("? %d %d %d %d\n", h, w+1, h, w+1);
	fflush(stdout);
	scanf("%d", &p);
	ans_map[h][w+1] = p;
	c += p;
	if(c == num) return;
	
	printf("? %d %d %d %d\n", h+1, w, h+1, w);
	fflush(stdout);
	scanf("%d", &p);
	ans_map[h+1][w] = p;
	c += p;
	if(c == num) return;
	
	ans_map[h+1][w+1] = 1;
}

void check4h(int h, int w, int num) {
	int i;
	int p;
	int c = 0;
	
	for(i=0;i<3;i++) {
		printf("? %d %d %d %d\n", h, w+i, h, w+i);
		fflush(stdout);
		scanf("%d", &p);
		ans_map[h][w+i] = p;
		c += p;
		if(c == num) return;
	}
	
	ans_map[h][w+3] = 1;
}

void check4v(int h, int w, int num) {
	int i;
	int p;
	int c = 0;
	
	for(i=0;i<3;i++) {
		printf("? %d %d %d %d\n", h+i, w, h+i, w);
		fflush(stdout);
		scanf("%d", &p);
		ans_map[h+i][w] = p;
		c += p;
		if(c == num) return;
	}
	
	ans_map[h+3][w] = 1;
}

void check25(int h, int w, int num) {
	int i, j;
	int p;
	int c = 0;
	
	for(i=0;i<2;i++) {
		for(j=0;j<2;j++) {
			printf("? %d %d %d %d\n", h+i*2, w+j*2, h+i*2+1, w+j*2+1);
			fflush(stdout);
			scanf("%d", &p);
			if(p > 0) {
				c += p;
				check4s(h+i*2, w+j*2, p);
				if(c == num) return;
			}
		}
	}
	
	printf("? %d %d %d %d\n", h+4, w, h+4, w+3);
	fflush(stdout);
	scanf("%d", &p);
	if(p > 0) {
		c += p;
		check4h(h+4, w, p);
		if(c == num) return;
	}
	
	printf("? %d %d %d %d\n", h, w+4, h+3, w+4);
	fflush(stdout);
	scanf("%d", &p);
	if(p > 0) {
		c += p;
		check4v(h, w+4, p);
		if(c == num) return;
	}
	
	ans_map[h+4][w+4] = 1;
}

int main() {
	int i, j;
	int p;
	int c = 0;
	long ans = 0;
	long pow = 1;
	
	scanf("%d %d %d %d", &H, &W, &N, &K);
	
	for(i=0;i<10;i++) {
		for(j=0;j<10;j++) {
			if(c == N) break;
			printf("? %d %d %d %d\n", i*5, j*5, i*5+4, j*5+4);
			fflush(stdout);
			scanf("%d", &p);
			if(p > 0) {
				c += p;
				check25(i*5, j*5, p);
			}
		}
	}
	
	for(i=0;i<H;i++) {
		for(j=0;j<W;j++) {
			if(ans_map[i][j]) ans += pow;
			pow *= 2;
			ans %= K;
			pow %= K;
		}
	}
	
	printf("! %ld\n", ans);
	
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
char a[100];
bool isP(int l,int h)
{
	while(l<h)
	{
		if(a[l] != a[h]){
			return false;
		}
		l++;
		h--;
	}
	return true;
}
int main()
{
	//char a[100];
	cin>>a;
	int n = strlen(a);
	if(isP(0,n-1) && isP(0,(n-3)/2) && isP((n+1)/2,n-1))
	{
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
}

Measured memory_bytes: 256
//in the name of god
#include <bits/stdc++.h>
using namespace std;
#define MAX_N (int)1e6+20
#define INF 1e9+20
#define pb push_back
#define F first
#define S second
typedef long long LL;
#define int LL
typedef pair<int,int> pii;
const int delta=(int)1e9+7;
int n,a,b,ans,x,y,z;
main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin>>a>>b;
	for(int i=0;;++i){
		if(a>b){
			ans=i; break;
		}
		a*=2;
	}
	cout<<ans;
	return cout<<endl,0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(float D, float T, float S){
    if(D/S <= T) cout << YES << endl;
    else cout << NO << endl;
    return;
}

int main(){
    float D;
    scanf("%fd",&D);
    float T;
    scanf("%fd",&T);
    float S;
    scanf("%fd",&S);
    solve(D, T, S);
    return 0;
}


Measured memory_bytes: 3796
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = 1e9+7;

using namespace std;
int dp[45][450][450]; // dp[i][a][b] := i番目まで見て合計がa b となる場合の最小コスト
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,Ma,Mb;
	cin >> N >> Ma >> Mb;
	vector<int> a(N),b(N),c(N);
	rep(a,45)rep(b,450)rep(c,450)dp[a][b][c] = inf;
	rep(i,N){
		cin >> a[i] >> b[i] >> c[i];
	}
	dp[0][0][0] = 0;
	for(int i=1;i<=N;i++){
		for(int ta=0;ta<450;ta++){
			for(int tb=0;tb<450;tb++){
				//i番目の薬品を使わなかった場合
				dp[i][ta][tb] = min(dp[i][ta][tb],dp[i-1][ta][tb]);
				//i番目の薬品を使った場合
				if(ta+a[i-1] < 450 && tb+b[i-1] < 450){
					dp[i][ta+a[i-1]][tb+b[i-1]] = 
					min(dp[i][ta+a[i-1]][tb+b[i-1]],dp[i-1][ta][tb] + c[i-1]);
				}
			}
		}
	}
	int ans = inf;
	for(int i=1;i<=400;i++){
		if(Ma*i>=450 || Mb*i >=450)break;
		ans = min(ans,dp[N][Ma*i][Mb*i]);
	}
	if(ans<inf)cout << ans << endl;
	else cout << -1 << endl;
}

Measured memory_bytes: 35840
#include <bits/stdc++.h>
using namespace std;
#define Maxn 200007
int n,m,k;
int posx,posy,lx,rx;
char s1[Maxn],s2[Maxn];
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    scanf("%d%d",&posx,&posy);
    scanf("%s",s1+1);
    scanf("%s",s2+1);
    bool ans=true;
    lx=1,rx=n;
    for (int i=k;i;i--)
    {
        if (s2[i]=='D')
        {
            if (lx>1) --lx;
        } else if (s2[i]=='U')
        {
            if (rx<n) ++rx;
        }
        if (s1[i]=='D')
        {
            --rx;
            if (rx<lx) ans=false;
        } else if (s1[i]=='U')
        {
            ++lx;
            if (rx<lx) ans=false;
        }
    }
    if (!(lx<=posx&&posx<=rx)) ans=false;
    lx=1,rx=m;
    for (int i=k;i;i--)
    {
        if (s2[i]=='R')
        {
            if (lx>1) --lx;
        } else if (s2[i]=='L')
        {
            if (rx<m) ++rx;
        }
        if (s1[i]=='R')
        {
            --rx;
            if (rx<lx) ans=false;
        } else if (s1[i]=='L')
        {
            ++lx;
            if (rx<lx) ans=false;
        }
    }
    if (!(lx<=posy&&posy<=rx)) ans=false;
    if (ans) printf("YES\n"); else printf("NO\n");
    return 0;
}

Measured memory_bytes: 4056