akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N;cin>>N;
    vector<double> x(N);
    vector<string> u(N);
    double ans=0;
    for(int i=0;i<N;i++){
        cin >> x[i] >> u[i];
        if(u[i]=="BTC"){
            ans+=(380000.0*x[i]);
        }
        else{
            ans+=x[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string.h>
#include <queue>
#include <stack>
#include <utility>
#include <queue>
#define mp make_pair
#define pii pair<int,int> 
#define ff first
#define ss second

using namespace std;

int mode[200];
int z,maxs;

int main()
{
	maxs=0;
	for(int a=0;a<199;a++)
	{
		mode[a]=0;
	}
	while(scanf("%d",&z)!=EOF)
	{
		if(z<0)
		{
			break;
		}
		mode[z]++;
		maxs=max(maxs,mode[z]);
	}
	for(int a=0;a<199;a++)
	{
		if(mode[a]==maxs)
		{
			printf("%d\n",a);
		}
	}
	return 0;
}

Measured memory_bytes: 1188
#include <stdio.h>
#define min(x, y) ((x)>(y) ? (y) : (x))
#define max(x, y) ((x)<(y) ? (y) : (x))
#define swap(type, x, y) do{ type t = x; x = y; y = t; }while(0)

void quick(long array[], int left, int right);

long lunlun[265726] = {0};

void dfs(long num, int len){
  if(len > 10)  return;
  lunlun[++lunlun[0]] = num;
  for(long i=-1; i<=1; i++)
    if(num%10+i>=0 && num%10+i<=9){
      long newnum = num*10 + num%10+i;
      dfs(newnum, len+1);
    }
  
  return;
}

int main(){
  int k;  scanf("%d", &k);

  for(long i=1; i<=9; i++)
    dfs(i, 1);

  quick(lunlun, 1, lunlun[0]);

  printf("%ld\n", lunlun[k]);
  return 0;
}

void quick(long array[], int left, int right){
  int pl = left, pr = right;
  long x = array[(left+right) / 2];
  do{
    while(array[pl] < x)  pl++;
    while(array[pr] > x)  pr--;
    if(pl <= pr){
      swap(long, array[pl], array[pr]);
      pl++, pr--;
    }
  }while(pl <= pr);
  if(pl < right)  quick(array, pl, right);
  if(pr > left)   quick(array, left, pr);
}
  


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

using namespace std;

struct UnionFind {
    vector<int> par, rank, size;

    UnionFind(int N) : par(N), rank(N), size(N) {
        for(int i = 0; i < N; i++){
            par[i] = i;
            size[i] = 1;
        }
    }

    int root(int x) {
        if (par[x] == x) return x;

        par[x] = root(par[x]);
        return par[x];
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;

        if (rank[x] < rank[y]) swap(x, y);
        par[y] = x;
        size[x] += size[y];
        if (rank[x] == rank[y]) rank[x]++;
    }

    int get_tree_size(int x){
        return size[root(x)];
    }
};


int main() {
    // Input
    int N, M, K;
    vector<int> A, B, C, D;

    cin >> N >> M >> K;
    A = vector<int>(M);
    B = vector<int>(M);
    C = vector<int>(K);
    D = vector<int>(K);
    for (int i = 0; i < M; i++) cin >> A[i] >> B[i];
    for (int i = 0; i < K; i++) cin >> C[i] >> D[i];

    // Process
    UnionFind tree(N);
    for (int i = 0; i < M; i++){
        tree.merge(A[i] - 1, B[i] - 1);
    }

    vector<int> ans = vector<int>(N);
    for (int i = 0; i < N; i++){
        ans[i] = tree.get_tree_size(i) - 1;
    }

    for (int i = 0; i < M; i++){
        ans[A[i] - 1]--;
        ans[B[i] - 1]--;
    }

    for (int i = 0; i < K; i++){
        if (tree.same(C[i] - 1, D[i] - 1)){
            ans[C[i] - 1]--;
            ans[D[i] - 1]--;
        }
    }

    // Output
    for (int i = 0; i < N; i++){
        if (i == 0) printf("%d", ans[i]);
        else printf(" %d", ans[i]);
    }
    printf("\n");

    return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
    int n;
    scanf("%d", &n);
    ll ans = 0;
    for (int i = 1; i <= n; i++) ans += i * (n - i + 1ll);
    int u, v;
    for (int i = 1; i < n; i++) {
        scanf("%d%d", &u, &v);
        if (u > v) swap(u, v);
        ans -= u * (n - v + 1ll);
    }
    printf("%lld", ans);
}


Measured memory_bytes: 3816
X = int(input())

if 400 <= X and X <= 599:
    print(8)
elif 600 <= X and X <= 799:
    print(7)
elif 800 <= X and X <= 999:
    print(6)
elif 1000 <= X and X <= 1199:
    print(5)
elif 1200 <= X and X <= 1399:
    print(4)
elif 1400 <= X and X <= 1599:
    print(3)
elif 1600 <= X and X <= 1799:
    print(2)
elif 1800 <= X and X <= 1999:
    print(1)


Measured memory_bytes: 9196
#include<stdio.h>
#include<string.h>
#define Max(x,y) ((x>y)?x:y)
#define min(x,y) ((x<y)?x:y)
int a[505][505];
char b[505];
int main(){
	int i,j,k,h,w,f,ans;
	while(1){
		scanf("%d%d",&h,&w);
		if(h==0)break;
		for(i=0;i<h;i++){
			scanf("%s",b);
			f=0;
			for(j=w-1;j>=0;j--){
				if(b[j]=='*')f=0;
				else f++;
				a[i][j]=f;
			}
		}
		//for(i=0;i<h;i++){for(j=0;j<w;j++)printf("%d ",a[i][j]);printf("\n");}
		ans=0;
		for(i=0;i<h;i++){
			for(j=i;j<h;j++){
				for(k=0;k<w;k++){
					if(i==j)a[500][k]=a[i][k];
					else a[500][k]=min(a[500][k],a[j][k]);
					ans=Max(ans,a[500][k]*(j-i+1));
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1412
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#ifdef ONLINE_JUDGE
  #define debug(x)
  #define debug2(x,y)
  #define debug3(x,y,z)
  #define assert(e) if(!(e)){stod("");}
#else
  #define debug(x) std::cerr<<#x<<": "<<x<<"\n"
  #define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
  #define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"
#endif

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

void solve() {
  int h1, m1, h2, m2, k;
  scan(h1, m1, h2, m2, k);
  int t1 = h1 * 60 + m1;
  int t2 = h2 * 60 + m2;
  int ans = t2 - t1 - k;
  print(ans);
}

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


Measured memory_bytes: 3232
import copy
n = int(input())
l=[int(input()) for x in range(n)]
ll=copy.copy(l)
ll.sort()
setl=list(set(l))
setl.sort()
m=max(l)

for i in range(n):
    if len(setl)==1:
        print(m)
    else:
        second=ll[-2]
        if l[i]==m:
            print(second)
        else:
            print(m)

Measured memory_bytes: 19768
abcde = []
abcde.append(int(input()))
abcde.append(int(input()))
abcde.append(int(input()))
abcde.append(int(input()))
abcde.append(int(input()))

minVal = 0
total = 0
for x in abcde:
    mod = x % 10
    if minVal == 0 and mod != 0:
        minVal = mod

    if minVal != 0 and mod != 0 and mod < minVal:
        minVal = mod

    if mod == 0:
        total += x - mod
    else:
        total += x + 10 - mod
if minVal != 0:
    total += minVal - 10
print(total)


Measured memory_bytes: 3064
n = int(input())
p = list(map(int,input().split()))
q = sorted(p)
if n != 2:
    med_1 = q[n//2-1]
    med_2 = q[n//2]
    
    for i in range(n):
        if p[i] == med_1:
            print(med_2)
        elif p[i] == med_2:
            print(med_1)
        elif p[i] < med_1:
            print(med_2)
        else:
            print(med_1)
else:
    print(p[1])
    print(p[0])

Measured memory_bytes: 25744
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

//---------------------------

int main(){
    int a,b; cin >> a >> b;
    if(a+b>=10) cout << "error" << endl;
    else cout << a+b << endl;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1e9;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), aba(n);
  ll tota = 0;
  int mnum = 0;
  rep(i, n) {cin >> a[i];
    aba[i] = abs(a[i]);
    if (a[i] < 0) mnum++;
  }
  sort(aba.begin(), aba.end());
  

  ll ans = 0;
  rep(i, n) ans += aba[i];
  if (mnum % 2 == 0) {
  } else {
    ans -= 2 * aba[0];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
	public static void main(String []args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		if(a<b&&b<c) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}



Measured memory_bytes: 26256
n = int(input())
c = [0] + [int(input()) for _ in range(n)]
dp = [0] * (200001)
num = 1
for i in range(n):
    if c[i]!=c[i+1]:
        num += dp[c[i+1]]
        dp[c[i+1]] = num
print(num%(10**9+7))

Measured memory_bytes: 28552
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[4],mx=0,ans=0;
	cin>>a[1]>>a[2]>>a[3];
	for(int i=1;i<=3;i++){
		mx=max(mx,a[i]);
		ans+=a[i];
	} 
	cout<<ans-mx;
	return 0;
}


Measured memory_bytes: 256
# B 
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n=ni()
s=si()
ans=''
for ss in s:
    ans+=chr((ord(ss)+n-65)%26+65)
print(ans)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
typedef long long ll;


ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

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

  vector<pair<int,int>> ids(m);
  rep(i, m) {
      cin >> ids[i].first >> ids[i].second;
  }

  int ans = 0; 
  int l = 0; int r = 1000000;
  rep(i, m) {
      l = max(ids[i].first, l);
      r = min(ids[i].second, r);
  }
  ans = (r-l<0) ? 0 : r - l + 1;
  cout << ans << endl;
}

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

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

    int R, G;
    cin >> R >> G;
    cout << G*2-R << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	A := ReadInts(N)
	m := make(map[int]int)
	for i := 0; i < N; i++ {
		m[A[i]]++
	}
	var even, odd int
	for _, c := range m {
		if c%2 == 0 {
			even++
		} else {
			odd++
		}
	}
	if even%2 == 0 {
		fmt.Println(odd + even)
	} else {
		fmt.Println(odd + even - 1)
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 8744
s = input()

def check():
  if s != s[::-1]:
    return("No")
  n = len(s)
  s1 = s[:int((n-1)/2)]
  #print(s1)
  if s1 != s1[::-1]:
    return("No")
  s2 = s[int((n+3)/2-1):]
  if s2 != s2[::-1]:
    return("No")
  #print(s2)
  return("Yes")

print(check())

Measured memory_bytes: 8988
#include<stdio.h>
#define MX 1099
int map[MX][MX], cnt, way[4][2] = { { 1, 0 }, { 0, 1 }, { -1, 0 }, {0, -1} };
char s[MX];
int bfs[MX*MX][2];
int main() {
	int h, w, c[2], d[2], i, j, z;
	scanf("%d%d", &h, &w);
	for (i = 0; i < 2; i++) {
		scanf("%d", &c[i]);
		++c[i];
	}
	for (i = 0; i < 2; i++) {
		scanf("%d", &d[i]);
		++d[i];
	}
	for (i = 0; i <= (h + 3); i++) {
		for (j = 0; j <= (w + 3); j++) {
			if (2 <= i && i <= (h + 1) && 2 <= j && j <= (w + 1)) {
				map[i][j] = 0;
			}
			else {
				map[i][j] = -1;
			}
		}
	}
	for (i = 1; i <= h; i++) {
		scanf("%s", &s[1]);
		for (j = 1; j <= w; j++) {
			if (s[j] == '#') {
				map[i + 1][j + 1] = -1;
			}
			else {
				map[i + 1][j + 1] = 0;
			}
		}
	}
	int st = 1, ed = 1;
	bfs[1][0] = c[0], bfs[1][1] = c[1];
	map[c[0]][c[1]] = 1;
	for (int numb = 1;; ++numb) {
		for (i = st; i <= ed; i++) {
			for (j = 0; j < 4; j++) {
				if (map[bfs[i][0] + way[j][0]][bfs[i][1] + way[j][1]] == 0) {
					map[bfs[i][0] + way[j][0]][bfs[i][1] + way[j][1]] = numb;
					++ed;
					bfs[ed][0] = bfs[i][0] + way[j][0];
					bfs[ed][1] = bfs[i][1] + way[j][1];
				}
			}
		}
		int md = ed;
		for (i = st; i <= md; i++) {
			for (j = -2; j <= 2; j++) {
				for (z = -2; z <= 2; z++) {
					if (map[bfs[i][0] + j][bfs[i][1] + z] == 0) {
						map[bfs[i][0] + j][bfs[i][1] + z] = numb + 1;
						++ed;
						bfs[ed][0] = bfs[i][0] + j;
						bfs[ed][1] = bfs[i][1] + z;
					}
				}
			}
		}
		if (md == ed) {
			break;
		}
		st = md + 1;
	}
	printf("%d", map[d[0]][d[1]] - 1);
}

Measured memory_bytes: 9896
#include<stdio.h>

int hist[100];
int map[10][10];
int main(){
	int i,max;
	max=0;
	while(scanf("%d",&i)!=EOF){
		hist[i-1]++;
		if(max<hist[i-1]) max=hist[i-1];
	}
	for(i=0;i<100;i++)
		if(max==hist[i]) printf("%d\n",i+1);
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

using llong = long long;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

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

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

template <class T> inline void chadd(T &a, const T &b) { a += b, a &= MOD; }

int main() {
  // Input
  std::vector<int> time(5);
  for (int i = 0; i < 5; ++i) {
    std::cin >> time[i];
  }

  // Main
  std::vector<int> loss(5);
  for (int i = 0; i < 5; ++i) {
    loss[i] = 10 - (time[i] % 10);
    if (loss[i] == 10)
      loss[i] = 0;
  }
  int iMax = -1;
  int maxLoss = -1;
  for (int i = 0; i < 5; ++i) {
    if (maxLoss < loss[i]) {
      maxLoss = loss[i];
      iMax = i;
    }
  }

  // Output
  int res = 0;
  for (int i = 0; i < 5; ++i) {
    if (i == iMax)
      continue;
    res += (time[i] + loss[i]);
  }
  res += time[iMax];
  std::cout << res << std::endl;

  return 0;
}


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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int n, ans = 0;
	cin >> n;
	while (n--) {
		int l, r;
		cin >> l >> r;
		ans += r - l + 1;
	}
	cout << ans << "\n";
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P  = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    vector<ll> cnt(200010);
    // map<int, int> B;
    rep(i, N)
    {
        cin >> A[i];
        cnt[A[i]]++;
    }
    sort(cnt.begin(), cnt.end(), ::greater<ll>());
    cnt.erase(cnt.begin(), cnt.begin()+K);
    int ans = 0;
    for(int i = 0 ; cnt[i] != 0 ; ++i)
    {
        ans += cnt[i];
    }
    // // if(S.size() < K)
    // // {
    // //     cout << 0 << endl;
    // // }
    // int l = B.size()-K;
    // sort(A.begin(), A.end(),[&](auto const& lhs, auto const& rhs) 
    //                         {
    //                             return B[lhs] < B[rhs];
    //                         } );
    // rep(i, N)
    // {
    //     cout << A[i] << "/" << B[A[i]] << ",";
    // }
    // cout << endl;
    // int ans = 0;
    // if(l > 0)
    // rep(k, l)
    // {
    //     ans += B[A[k]];
    // }
     cout << ans << endl;
        

    return 0;
}

Measured memory_bytes: 5624
#include <cstdio>
#include <cstring>
#define int long long
int read()
{
	int x=0,flag=1;char c;
	while((c=getchar())<'0' || c>'9') if(c=='-') flag=-1;
	while(c>='0' && c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return x*flag;
}
int n,k,ans,head,tail;
char s[105];
signed main()
{
	scanf("%s",s);
	k=read();
	n=strlen(s);
	for(int i=1;i<n;i++)
		if(s[0]^s[i])
			goto In;
	printf("%lld\n",n*k/2);
	return 0;
	In:;
	for(int i=0;i<n;i++)
	{
		int j=i;
		for(;s[i]==s[j];j++);
		ans+=(j-i)>>1;
		tail=j-i;
		i=j-1;
	}
	for(int i=0;i<n;i++)
		if(s[i]==s[n-1])
			head++;
		else 
			break;
	ans*=k;
	if(k>2 && tail+head>1 && tail%2 && head%2)
		ans+=k-1;
	printf("%lld\n",ans);
}

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

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

    bool x = false;
    for(int i = 1; i <= 9; i++)
    {
        if(n % i == 0)
        {
            int temp = n/i;
            if(temp <= 9)
            {
                cout<< "Yes\n";
                x = true;
                break;
            }
        }
    }
    if(!x)
        cout<< "No\n";

    return 0;
}


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

int main(){
	
	int n,k;
	cin >> n >> k;
	int a[n];
	for(int i =0;i<n;i++) cin >> a[i];
    sort(a,a+n);
    int count = 0;	
	for(int i = n-1;i>=0;i--){
		if( a[i] < k) break;
		else{
		 count++;
		}
		
	} 
	
	
	cout << count <<endl;
	
	
	
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define zmrl(x) (int)((x).size())
#define ahen(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n,x,m; cin>>n>>x>>m;
    int psum[100100]; psum[0] = 0;
    set<pii> s;
    s.insert({psum[1] = x, 1});
    for (int i=2; i<=n; i++) {
        x=x*x%m;
        if (!x) {
            cout << psum[i-1] << '\n';
            return 0;
        }
        auto it = s.lower_bound({x, 0});
        if (it->fi == x) {
            int len = i-it->se;
            int q = (n-i+1) / len, r = (n-i+1) % len;
            cout << psum[i-1] + (psum[i-1]-psum[it->se-1])*q + psum[it->se-1+r] - psum[it->se-1] << '\n';
            return 0;
        }
        psum[i] = psum[i-1] + x;
        s.insert({x, i});
    }
    cout << psum[n] << '\n';
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    for(auto &v:a) cin>>v;
    ll sum=accumulate(a.begin(),a.end(),0LL);
    ll snu=a[0];
    ll res=1e15;
    for(int i=0;i<n-1;i++){
        res=min(res,abs(snu-(sum-snu)));
        snu+=a[i+1];
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = int64_t;
using ld = long double;
using ull = uint64_t;

//#define cerr if (false) cerr


ll n;

int main() {
  ios::sync_with_stdio(0);
  cout.precision(10);

  cin >> n;

  if (n < 1000) {
    cout << "ABC" << endl;
  } else {
    cout << "ABD" << endl;
  }

}



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

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

		if( a == b )
		{
		cout << "a == b" << endl;
		}else{
			if( a > b)
			{
			cout << "a > b" << endl;
			}else{
			cout << "a < b" << endl;
			}
		}
}


Measured memory_bytes: 3084
iN = int(input())
aA = [0] + [int(_) for _ in input().split()] + [0]
iAll = sum(map(lambda i :abs(aA[i+1]-aA[i]),range(iN+1)))
print("\n".join(map(lambda i:str( iAll - abs(aA[i-1]-aA[i]) - abs(aA[i]-aA[i+1]) + abs(aA[i-1]-aA[i+1])), range(1,iN+1))))


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

typedef long long LL;

LL gcd(LL a,LL b)
{
	return b?gcd(b,a%b):a;
}

int main()
{
	LL a,b;
	cin>>a>>b;
	LL ans=a;
	a-=b;
	while(true)
	{
		if(a<b) swap(a,b);
		if(a%b)
		{
			ans+=a/b*b*2;
			a%=b;
		}
		else
		{
			ans+=(a/b*2-1)*b;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int n;cin >> n;
    string s; cin >> s;
    bool fx,fy,fz;
    int count = 0;
    set<int>set1;
    for(char x='0';x<='9';x++){
        for(char y='0';y<='9';y++){
            for(char z='0';z<='9';z++){
                fx=0;fy=0;fz=0;
                for(int str = 0;str < n;str++){
                    if(s[str]==x&&fx==0&&fy==0&&fz==0){
                        fx=1;
                        continue;
                    }
                    if(s[str]==y&&fx==1&&fy==0&&fz==0){
                        fy=1;
                        continue;
                    }
                    if(s[str]==z&&fx==1&&fy==1&&fz==0){
                        int num = (x-'0')*100+(y-'0')*10+(z-'0');
                        set1.insert(num);
                        break;
                    }
                }
            }
        }
    }
    COUT(set1.size());
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
	int i, n, m1 = -1, m2 = -1, m3 = -1;
	
	for (i = 0; i < 10; i++) {
		scanf("%d", &n);
		if (n > m1) {
			m3 = m2;
			m2 = m1;
			m1 = n;
		} else if (n > m2) {
			m3 = m2;
			m2 = n;
		} else if (n > m3) {
			m3 = n;
		}
	}
	printf("%d\n%d\n%d\n", m1, m2, m3);
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>

int main(void)
{
        int a,b;
        char s[11],t[11],u[11];

        scanf("%s%s",s,t);
        scanf("%d%d",&a,&b);
        scanf("%s",u);

        if(*u==*s) a--;
        else  b--;
        printf("%d %d\n",a,b);
        return 0;
}


Measured memory_bytes: 128
x = int(input())

num = x / 100

dp = [0] * (x + 1)
dp[0] = 1

for i in range(1, x + 1):
    if i <= 99:
        dp[i] = 0
    elif i in (100, 101, 102, 103, 104, 105):
        dp[i] = 1
    elif 1 in (dp[i - 100], dp[i - 101], dp[i - 102], dp[i - 103], dp[i - 104], dp[i - 105]):
        dp[i] = 1
    else:
        dp[i] = 0

print dp[x]


Measured memory_bytes: 6532
H,W=map(int,input().split())
s=[]
dp=[[10**9]*W for _ in range(H)]
dp[0][0]=0
for _ in range(H):
    s.append(list(input()))
for i in range(H):
    for j in range(W):
        if j!=W-1:
            if s[i][j]=="." and s[i][j+1]=="#":
                dp[i][j+1]=min(dp[i][j]+1,dp[i][j+1])
            else:
                dp[i][j+1]=min(dp[i][j],dp[i][j+1])
        if i!=H-1:
            if s[i][j]=="." and s[i+1][j]=="#":
                dp[i+1][j]=min(dp[i][j]+1,dp[i+1][j])
            else:
                dp[i+1][j]=min(dp[i][j],dp[i+1][j])
ans=dp[H-1][W-1]
if s[0][0]=="#":
    ans+=1
print(ans)

Measured memory_bytes: 9352
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) ->
      if x < y then Node (y, doit l, r)
      else Node (y, l, doit r) in
  doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> f x; doit l; doit r in
  doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> doit l; f x; doit r in
  doit t

let print t =
  inorder (fun e -> print_string " "; print_int e) t;
  Printf.printf "\n";
  preorder (fun e -> print_string " "; print_int e) t;
  Printf.printf "\n"

let find x t =
  let rec doit = function
    | Nil -> false
    | Node (y, _, _) when x = y -> true
    | Node (y, l, _) when x < y -> doit l
    | Node (_, _, r) -> doit r in
  doit t

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let m = read_int () in
  let t = ref (create ()) in
  for _ = 0 to m - 1 do
    match read_line () |> split_on_char ' ' with
    | ["insert"; n] -> t := insert (int_of_string n) !t
    | ["find"; n] -> print_endline (if find (int_of_string n) !t then "yes" else "no")
    | _ -> print !t
  done

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  
  int sum = 0, ord = 0, ordSum;
  for (int i = 1; i <= N; i++) {
    if (i % 10 == 0) {
      ord++;
    }
    
    ordSum = 0;
    int tmp = i;
    for (int j = 0; j <= ord; j++) {
      ordSum += tmp % 10;
      tmp /= 10;
    }

    if ((ordSum >= A) and (ordSum <= B)) {
      sum += i;
    }
  }

  cout << sum << endl;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

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

  int M1, D1, M2, D2;
  std::cin >> M1 >> D1 >> M2 >> D2;

  if(M1 != M2){
      std::cout << 1 << std::endl;
  }else{
      std::cout << 0 << std::endl;
  }
}


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

using namespace std;

int main(void){
//string S;
int N;
string S;
cin >> N;
cin >> S;
//vector<int> P(N);
int pos = 0, abcnum = 0;

while(pos < S.size()){
  int tmp = S.find("ABC",pos);
  if(tmp != string::npos){
    abcnum++;
    pos = tmp + 2; 
  }else if(tmp == string::npos){
    break;
  }
  
}

cout << abcnum << endl; 

return 0;
}


Measured memory_bytes: 256
from sys import exit
from math import sqrt

x = int(input())
if x == 2:
    print(2)
    exit()
elif x == 3:
    print(3)
    exit()
i = x
while i <= x * int(sqrt(x)):
    j = 2
    while j <= int(sqrt(i)):
        if not i % j:
            break
        j += 1
    if j > int(sqrt(i)):
        print(i)
        exit()
    i += 1

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 20050;

int n;
int p[MAXN], pr[MAXN];
int a[MAXN], b[MAXN];

int main() { 

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
    pr[p[i] - 1] = i + 1;
  }

  for (int i = 0; i < n; i++) {
    a[i] = 30000 * (i + 1);
  }
  for (int i = 0; i < n; i++) {
    b[i] = (n - 1 - i) * 30000 + pr[i];
  }

  for (int i = 0; i < n; i++) {
    printf("%d ", a[i]);
  }
  cout << endl;
  for (int i = 0; i < n; i++) {
    printf("%d ", b[i]);
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 896
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;
ll const MOD = 1e9 + 7;

int main() {
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  for (ll i = K; i <= N + 1; i++) {
    ll least = i * (i - 1) / 2;
    ll most = i * (2 * N - i + 1) / 2;
    ans = (ans + most - least + 1) % MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
n = int(input().strip())
s1 = input().strip()
s2 = input().strip()
mod = 1000000007
vert = False
hor1 = False
hor2 = False

if s1[0] == s2[0]:
    ans = 3
    vert = True
else:
    ans = 6
    hor1 = True
for i in range(1, n):
    if s1[i] == s2[i]:
        if vert:
            ans = (ans * 2) % mod
        vert = True
        hor1 = False
        hor2 = False
    else:
        if vert:
            ans = (ans * 2) % mod
            vert = False
            hor1 = True
            hor2 = False
        elif hor1:
            vert = False
            hor1 = False
            hor2 = True
        elif hor2:
            ans = (ans * 3) % mod
            vert = False
            hor1 = True
            hor2 = False
print(ans)


Measured memory_bytes: 38256
n = int(input())
if n%4 == 0:
  print("Yes")
elif n%7 == 0:
  print("Yes")
else:
  while n >= 4:
    if (n-4)%7 == 0:
      print("Yes")
      break
    else:
      n -= 4
  else:
    print("No")

Measured memory_bytes: 3060
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();

        System.out.println((1900 * m + 100 * (n - m)) * (int)Math.pow(2, m));
        sc.close();
    }

}


Measured memory_bytes: 23892
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(){
    int N;
    long long M;
    int ans;

    //input
    cin >> N >> M;
    ans = floor(M / N);
    while(M % ans != 0){
        ans--;
    }

    cout << ans << endl;
}


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

main(){
  ios_base::sync_with_stdio(false);
  int n,a;
  set<int>st;

  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a;
    if(st.find(a) == st.end()) st.insert(a);
    else st.erase(a);
  }

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

  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#define MAX 200005
using namespace std;

typedef long long ll;
ll N, bit[MAX] = {};

void update(ll x, ll delta) {
    for (;x <= N+1; x += x&-x) bit[x] += delta;
}

ll query(ll x) {
    ll sum = 0;
    for (;x > 0; x -= x&-x) sum += bit[x];
    return sum;
}

int main() {
    ll K, a[MAX], b[MAX], c[MAX], i;
    cin >> N >> K;
    b[0] = 0, c[0] = 0;
    for (i = 0; i < N; i++) cin >> a[i], a[i] -= K, b[i+1] = b[i]+a[i], c[i+1] = b[i+1];
    sort(c, c+N+1);

    ll res = 0;
    for (i = 0; i <= N; i++) {
        ll ind = lower_bound(c, c+N+1, b[i])-c+1;
        res += query(ind);
        update(ind, 1);
    }
    cout << res << '\n';
}

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

int main(void) {
    int q;
    bool v = false;
    string s;
    cin >> s >> q;
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if (t == 1) v = !v;
        else {
            int f;
            char c;
            bool a;
            cin >> f >> c;
            a = (f == 1);
            if (v) a = !a;
            if (a) s.insert(0, 1, c);
            else s.insert(s.end(), 1, c);
        }
    }
    if (v) {
        for (auto it = s.rbegin(); it != s.rend(); it++) {
            cout << *it;
        }
        cout << endl;
    }
    else cout << s << endl;
}


Measured memory_bytes: 1028
import java.util.*;


class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int c1, c2, c3, cnt;
		while(scan.hasNextInt()){
			c1 = scan.nextInt(); c2 = scan.nextInt(); c3 = scan.nextInt();
			cnt = 0;
			for(int i = 1;i <= 10;i++){
				if(i != c1 && i != c2 && i != c3 && 20 - c1 - c2 - i >= 0){
					cnt++;
				}
			}
			if(cnt >= 4){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}

}

Measured memory_bytes: 17196
#include<bits/stdc++.h>
using namespace std;
#define IO {ios_base::sync_with_stdio(false); cin.tie(0);}
#define ll  long long
#define pi pair<ll,ll>
ll  a[300000], b[40];

int main()
{
    IO;
    ll i, j, k, cnt=0, n, m, mod=1e18, t, mx,  p=0, l, h, x;
        cin>>n;n-=400; n/=200;
        cout<<8-n<<endl;
    return 0;
}


Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
 
public class Main {
    public static void main(String[] args){
         
        try {
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String buf = br.readLine();
            StringTokenizer st=new StringTokenizer(buf," ");
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
 
            if(a < b)
                System.out.println("a < b");
            else if(a > b)
                System.out.println("a > b");
            else if(a == b)
                System.out.println("a == b");
 
        } catch(IOException e) {
            System.err.println(e);
        }
    }
}

Measured memory_bytes: 16916
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    string ms;
    map< string,int> mail;
    for(i=1;i<=n;i++){
        cin>>ms;
        if(mail[ms]==0){
            mail[ms]=1;
        }
        else{
            mail[ms]++;
        }
    }
    cout<<mail.size()<<"\n";
    return 0;

}


Measured memory_bytes: 19204
#include<stdio.h>
main(){
  int i,j,k;
  char s[81];
  while(fgets(s,81,stdin)!=0){
    char t[3][5]={"the","this","that"};
    for(i=1;i<27;i++){
      for(j=0;j<3;j++){
	for(k=0;k<strlen(t[j]);k++)
	  t[j][k]=(t[j][k]-'a'+1)%26+'a';
	if(strstr(s,t[j])!=0){
	  for(j=0;j<strlen(s);j++)
	      if('a'<=s[j]&&s[j]<='z')
		for(k=0;k<i;k++)
		  s[j]+=26*(s[j]-'a'-1<0)-1;
	  printf("%s",s);
	  break;
	}
      }
      if(j!=3)
	break;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
ifstream f("1.in");
ofstream g("1.out");
typedef long long ll;
typedef pair<int,int> pi;
int t,T;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     ll D,T,S;
     cin>>D>>T>>S;
     double time=D/(double)S;
     if(time<=T) cout<<"Yes"<<'\n';
     else cout<<"No";

    return 0;
}


Measured memory_bytes: 3656
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int i,j,hit,blow,flg[4];
	int a[4],b[4];
	while(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])!=EOF) {
		scanf("%d %d %d %d",&b[0],&b[1],&b[2],&b[3]);
		for(i=0;i<4;i++) flg[i]=0;
		hit=0; blow=0;
		for(i=0;i<4;i++) {
			if(a[i]==b[i]) {
				hit++;
				flg[i]=1;
			}
		}
		for(i=0;i<4;i++) {
			for(j=0;j<4;j++) {
				if(a[i]==b[j] && flg[i]==0) blow++;
			}
		}
		printf("%d %d\n",hit,blow);
	}
	return 0;
}
	

Measured memory_bytes: 1024
#include <stdio.h>

#define MAX 100000
#define NIL -1
void Print(int);
void Depth(int, int);

struct Node {
        int p, l, r;
};
struct Node A[MAX];
int n,Dp[MAX];

int main(){
        int i,j,v,deg,c,l,r;
        scanf("%d",&n);


        for(i=0; i<n; i++) {
                A[i].p = NIL;
                A[i].l = NIL;
                A[i].r = NIL;
        }

        for(i=0; i<n; i++) {
                scanf("%d%d",&v, &deg);
                for(j=0; j<deg; j++) {
                        scanf("%d", &c);
                        if(j==0) {
                                A[v].l = c;
                        }else {
                                A[l].r = c;
                        }
                        l = c;
                        A[c].p = v;
                }
        }

        for(i=0; i<n; i++) {
                if(A[i].p == NIL) {
                        r = i;
                }
        }
        Depth(r, 0);

        for(i=0; i<n; i++) {
                Print(i);
        }

        return 0;
}


void Print(int node) {
        int i, c;

        printf("node %d: ",node);
        printf("parent = %d, ", A[node].p);
        printf("depth = %d, ", Dp[node]);

        if(A[node].p == NIL) {
                printf("root, ");
        }else if(A[node].l == NIL) {
                printf("leaf, ");
        }else {
                printf("internal node, ");
        }

        printf("[");
        c = A[node].l;
        while(c!=NIL) {
                if(c==A[node].l) {
                        printf("%d",c);
                }else {
                        printf(", %d", c);
                }
                c = A[c].r;
        }
        printf("]\n");
}


void Depth(int node, int dep){
        Dp[node] = dep;
        if(A[node].r!=NIL) {
                Depth(A[node].r, dep);
        }
        if(A[node].l!=NIL) {
                Depth(A[node].l, dep+1);
        }
}

Measured memory_bytes: 5300
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B
# Depth First Search
# Result:
import sys

class Graph(object):
    def __init__(self, size):
        super(Graph, self).__init__()
        self.__size = size
        self.__vertices = [None] * size

    def add_vertex(self, vertex):
        self.__vertices[vertex.id_ - 1] = vertex

    def get_vertex(self, vid):
        return self.__vertices[vid - 1]

    def depth_first_search(self):
        d = [0] * self.__size
        f = [0] * self.__size
        timer = 1
        for j in range(1, self.__size + 1):
            vtx = self.get_vertex(j)
            if not vtx.visited:
                stack = [vtx]
                d[vtx.id_ - 1] = timer
                vtx.visited = True
                timer = self.__depth_first_search(stack, timer, d, f) + 1

        for vtx in self.__vertices:
            print '%d %d %d' % (vtx.id_, d[vtx.id_ - 1], f[vtx.id_ - 1])

    def __depth_first_search(self, stack, timer, d, f):
        while len(stack) > 0:
            top = stack[-1]
            avid = top.get_next_adjacnt()
            if avid == -1:
                timer += 1
                f[top.id_ - 1] = timer
                stack.pop()
            else:
                av = self.get_vertex(avid)
                if not av.visited:
                    timer += 1
                    stack.append(av)
                    d[av.id_ - 1] = timer
                    av.visited = True
        return timer

    def __str__(self):
        str_ = ''
        for e in self.__vertices:
            str_ += '%s\n' % e
        return str_

class Vertex(object):
    def __init__(self, id_):
        super(Vertex, self).__init__()
        self.id_ = id_
        self.adjacents = []
        self.next_idx = 0
        self.visited = False

    def add_adjacent(self, avid):
        self.adjacents.append(avid)

    def get_next_adjacnt(self):
        if len(self.adjacents) == 0: return -1
        if self.next_idx < len(self.adjacents):
            val = self.adjacents[self.next_idx]
            self.next_idx += 1
            return val
        else:
            return -1

    def __str__(self):
        str_ = '%d ' % self.id_
        if len(self.adjacents) == 0:
            str_ += '0'
        else:
            str_ += '%d' % len(self.adjacents)
            for e in self.adjacents:
                str_ += ' %d' % e
        return str_



s = int(sys.stdin.readline().strip())
graph = Graph(s)
for _ in range(0, s):
    vals = [int(x) for x in sys.stdin.readline().strip().split(' ')]
    v = Vertex(vals[0])
    graph.add_vertex(v)
    if vals[1] == 0: continue
    for i in range(0, vals[1]):
        v.add_adjacent(vals[2 + i])

graph.depth_first_search()

Measured memory_bytes: 4392
N = int(input())
P = list(enumerate(list(map(int, input().split()))))
P = sorted(P, key=lambda x:x[1])

before_idx = list(range(-1, N-1)) + [-1, -1]
next_idx = list(range(1, N+1)) + [N, N]
ans = 0
for i, p in P:
  il1 = before_idx[i]
  il2 = before_idx[il1]
  ir1 = next_idx[i]
  ir2 = next_idx[ir1]
  ans += p * ((i-il1)*(ir2-ir1) + (ir1-i)*(il1 -il2))
  before_idx[ir1] = il1
  next_idx[il1] = ir1


print (ans)

Measured memory_bytes: 25760
from collections import Counter
N = int(input())
S = [''.join(sorted(input())) for _ in range(N)]
M = int(input())
T = [''.join(sorted(input())) for _ in range(M)]

s = Counter(S)
t = Counter(T)

ans = 0
for k, v in s.items():
    tmp = v
    tmp -= t[k]
    ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 9412
#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);
  
  int M;
  cin >> M;
  vector<string> t(M);
  for (int i=0;i<M;i++)
    cin >> t.at(i);
  
  int count_s = 0, count_t = 0;
  int plus_max = 0;
  string S;
  
  for (int i=0;i<N;i++) {
    S = s.at(i);
    
    count_s = 0;
    for (int j=0;j<N;j++) {
      if (s.at(j) == S) {
        count_s++;
      }
    } 
    
    count_t = 0;
    for (int k=0;k<M;k++) {
      if (t.at(k)==S)
        count_t++;
    }
    
    if (plus_max < count_s - count_t) {
      plus_max = count_s - count_t;
    }
  }
  
  cout << plus_max << endl;
  
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll n,T;cin >>n>>T;
    ll ans=n*T;
//    cout <<ans <<endl;
    ll sub=0;
    vector<ll>t(n);
    for (int i = 0; i < n; ++i) {
        cin >>t[i];
    }
    for (int i = 1; i <n; ++i) {
        sub+=max(T-(t[i]-t[i-1]),0LL);
    }
    cout <<ans-sub<<endl;
}


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

typedef long long ll;
ll n, ans;

int main() {
    scanf("%lld", &n);
    if (n % 9) printf("0\n"), exit(0);
    n /= 9;
    ll cur = 0, curpw = 1;
    for (int i = 1; i <= 17; i++) {
        cur = cur * 10 + 1;
        ll tmp = 1, m = n, pw = 1, base = cur;
        for (int j = 0; j + j <= i; j++) {
            tmp *= 10 - abs(m % (pw * 10) / pw) - !j;
            m -= base * (m % (pw * 10) / pw);
            base -= curpw / pw + pw, pw *= 10;
        }
        if (!m) ans += tmp;
        curpw *= 10;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
money = 1000
peak = []
botom = []
kabu = 0

if a[0] < a[1]:
    botom.append(0)
if a[n-1] >= a[n-2]:
    peak.append(n-1)
for i in range(1, n-1):
    if a[i] >= a[i-1] and a[i] > a[i+1]:
        peak.append(i)
    if a[i] <= a[i-1] and a[i] < a[i+1]:
        botom.append(i)

for i in range(n):
    if i in botom:
        kabu += money//a[i]
        money %= a[i]
    if i in peak:
        money += kabu*a[i]
        kabu = 0

print(money)


Measured memory_bytes: 61836
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
const ll N = 200030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;
int arr[N];
int main()
{ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int n;
cin>>n;
for(int i=1;i<=n;i++)
cin>>arr[i];
int ans=1;
int mn=arr[1];
rep(i,2,n+1)
{
	if(mn>=arr[i])
	{
		ans++;
		mn=arr[i];
	}

}
cout<<ans;



}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define mp  make_pair

ll N;
ll sol(ll d,ll c3,ll c5,ll c7,ll i,ll num){
	if(i>d){
		// cout<<num<<endl;
		if(num<=N)
			return 1;
		else 
			return 0;
	}
	if(d-i+1==1){
		ll a=0;
		if(c3==0)
			a+=sol(d,c3+1,c5,c7,i+1,num*10+3);
		else if(c5==0)
			a+=sol(d,c3,c5+1,c7,i+1,num*10+5);
		else if(c7==0)
			a+=sol(d,c3,c5,c7+1,i+1,num*10+7);
		else{
			a+=sol(d,c3+1,c5,c7,i+1,num*10+3)+sol(d,c3,c5+1,c7,i+1,num*10+5)+
		sol(d,c3,c5,c7+1,i+1,num*10+7);
		}
		return a;
	}
	else if(d-i+1==2){
		ll a=0;
		if(c3==0&&c5==0){
			a+=sol(d,c3+1,c5,c7,i+1,num*10+3)+sol(d,c3,c5+1,c7,i+1,num*10+5);
		}
		else if(c7==0&&c5==0){
			a+=sol(d,c3,c5+1,c7,i+1,num*10+5)+
		sol(d,c3,c5,c7+1,i+1,num*10+7);
		}
		else if(c3==0&&c7==0){
			a+=sol(d,c3+1,c5,c7,i+1,num*10+3)+
		sol(d,c3,c5,c7+1,i+1,num*10+7);
		}
		else{
			a+=sol(d,c3+1,c5,c7,i+1,num*10+3)+sol(d,c3,c5+1,c7,i+1,num*10+5)+
		sol(d,c3,c5,c7+1,i+1,num*10+7);
		}
		return a;
	}
	else{
		return sol(d,c3+1,c5,c7,i+1,num*10+3)+sol(d,c3,c5+1,c7,i+1,num*10+5)+
		sol(d,c3,c5,c7+1,i+1,num*10+7);
	}
}

int main(){
	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt", "r", stdin);
 //    freopen("output.txt", "w", stdout);
	// #endif
	cin>>N;
	ll t=N,d=0;
	while(t!=0){
		t=t/10;
		d++;
	}
	// cout<<d<<endl;
	ll ans=0;
	for(ll i=3;i<=d;++i){
		ans+=sol(i,(ll)0,(ll)0,(ll)0,(ll)1,(ll)0);
		// cout<<ans<<endl;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <stdio.h>

int selectionSort(int A[], int N) {
    int i, j, t, sw =0, minj;
    for(i=0;i<N-1;i++) {
        minj = i;
        for(j=i;j<N;j++) {
            if(A[j]<A[minj]) minj = j;
        }
        t=A[i]; A[i]=A[minj]; A[minj]=t;
        if(i!=minj) sw++;
    }
    return sw;
}

int main(void) {
    int A[100], N, i, sw;

    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&A[i]);

    sw = selectionSort(A,N);

    for(i=0;i<N;i++) {
        if(i>0) printf(" ");
        printf("%d",A[i]);
    }
    printf("\n");
    printf("%d\n",sw);

    return 0;
}


Measured memory_bytes: 2116