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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

const int mod=1e9+7;

struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};

mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}

map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}

void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}

int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );

  int n;cin>>n;
  vi v(n);
  rep(i,n)cin>>v[i];
  vi c(n);
  rep(i,n)cin>>c[i];

  int ans=0;
  rep(i,n){
    if(v[i]-c[i]>0)ans+=v[i]-c[i];
  }
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 125568
#include <bits/stdc++.h>
#define fi first
#define se second
#define ii pair<int, int>
#define int long long
using namespace std;

const int mod = 998244353;
int a[1000005];
int f[3005][6005];
int n, s;

int attempt(int i, int w)
{

    if (i > n)
    {
        if (w == s)
            return 1;
        return 0;
    }

    if (f[i][w] != -1)
        return f[i][w];
    int res = 0;

    res = (res + 2 * attempt(i+1, w))%mod;

    if (w + a[i] <= s)
        res = (res + attempt(i+1, w + a[i]))%mod;

    return f[i][w] = res;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

//    freopen("depart.inp", "r", stdin);
//    freopen("depart.out", "w", stdout);

    memset(f, -1, sizeof(f));
    cin >> n >> s;
    for (int i = 1; i <= n; i++)
        cin >> a[i];

    cout << attempt(1, 0) %mod;
}


Measured memory_bytes: 144808
import std.stdio;

bool isKaibun(int i) {
    int[5] r;
    foreach (n; 0 .. 5) {
        r[n] = i % 10;
        i /= 10;
    }
    return r[0] == r[4] && r[1] == r[3];
}

void main() {
    int a, b;
    readf("%d %d\n", &a, &b);
    size_t n = 0;
    foreach (i; a..b+1) {
        if (isKaibun(i)) {
            ++n;
        }
    }
    writeln(n);
}


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

using namespace std;

int main () {
    string s, s1, s2;
    char c1='1', c2='0', tmp;
    long n1=0, n2=0;
    cin >> s;
    for (long i=0; i<s.size(); i++) {
        s1 = s1 + c1;
        s2 = s2 + c2;
        tmp = c1;
        c1 = c2;
        c2 = tmp;
    }
    for (long i=0; i<s.size(); i++) {
        if (s[i] != s1[i]) {
            n1++;
        }
        if (s[i] != s2[i]) {
            n2++;
        }
    }
    // cout << s1 << " " << s2 << endl;
    cout << min(n1, n2) << endl;
    return 0;
}

Measured memory_bytes: 872
N=int(input())

a=['3','5','7']
l=['3','5','7']
ans=0

def rec():
    for s in l:
        for i in range(3):
            if(len(s+a[i])<=len(str(N))):
                l.append(s+a[i])
            else:
                break

rec()

for s in l:
    if(('3' in s) and ('5' in s) and ('7' in s) and (int(s)<=N)):
        ans+=1

print(ans)

Measured memory_bytes: 5228
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,M;
//i->jにコストcで行けるとき、
//集合adj[i]は(j,c)を含む
vector<vector<pair<LL,LL>>> adj;

LL ans = 0;

void solve(){
	for(int i=2;i<=N;i++) adj[i].push_back(pair<LL,LL>(i-1,0));

	//ダイクストラ
	//pair<LL,LL>(最短距離、頂点番号)
	priority_queue<pair<LL,LL>,vector<pair<LL,LL>>,greater<pair<LL,LL>>> q;
	q.push(pair<LL,LL>(0,1));
	//点1から点iまでの最短距離をdist[i]とおく
	vector<LL> dist(N+1,INF);
	dist[1] = 0;
	while(!q.empty()){
		LL now_node = q.top().second;
		LL now_dist = q.top().first;
		q.pop();
		for(auto next:adj[now_node]){
			LL next_node = next.first;
			LL d = next.second;
			if(dist[next_node]>dist[now_node]+d){
				dist[next_node] = dist[now_node]+d;
				q.push(pair<LL,LL>(dist[next_node],next_node));
			}
		}
	}
	ans = dist[N];
	if(ans==INF) ans = -1;
}

int main(){
    cin >> N >> M;
    adj = vector<vector<pair<LL,LL>>>(N+1);
    for(int i=0;i<M;i++){
    	LL l,r,c;cin >> l >> r >> c;
    	adj[l].push_back(pair<LL,LL>(r,c));
    	adj[r].push_back(pair<LL,LL>(l,c));
    }

    solve();

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

Measured memory_bytes: 14928
#include <iostream>

using namespace std;

int main() {
    int k, kyu;
    cin >> k;
    if(k >= 400 && k <= 599)
        kyu = 8;
    else if(k >= 600 && k <= 799)
        kyu = 7;
    else if(k >= 800 && k <= 999)
        kyu = 6;
    else if(k >= 1000 && k <= 1199)
        kyu = 5;
    else if(k >= 1200 && k <= 1399)
        kyu = 4;
    else if(k >= 1400 && k <= 1599)
        kyu = 3;
    else if(k >= 1600 && k <= 1799)
        kyu = 2;
    else if(k >= 1800 && k <= 1999)
        kyu = 1;
    cout << kyu << endl;
}

Measured memory_bytes: 3620
/*input
3
1 1
1 1
2 1
*/

// with "help" from editorial

#include <iostream>
#include <cstdio>

using namespace std;

const int MOD = 1e9 + 7, MAX = 2007, MAXN = 200007;
int add(int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; }
int sub(int a, int b) { a -= b; if (a < 0) a += MOD; return a; }
int mul(int a, int b) { return (long long) a * b % MOD; }

int F[MAX << 1][MAX << 1], N, A[MAXN], B[MAXN];
long long G[MAX << 1][MAX << 1];

#define FOR(i, a, b) for (int i = a; i <= b; ++i)

int read()
{
    int ans = 0; register char ch = getchar();
    for (; 48 > ch || ch > 57; ch = getchar());
    for (; 47 < ch && ch < 58; ch = getchar()) ans = ans * 10 + ch - 48;
    return ans;
}

int main()
{
	N = read();
	FOR(i, 0, N-1) A[i] = read(), B[i] = read();

    FOR(i, 0, (MAX << 1) - 1) F[i][0] = F[0][i] = 1;
    FOR(i, 1, (MAX << 1) - 1) FOR(j, 1, (MAX << 1) - 1) {
        F[i][j] = add(F[i-1][j], F[i][j-1]);
    }

    FOR(i, 0, N-1) ++G[MAX - A[i]][MAX - B[i]];
    FOR(i, 1, (MAX << 1) - 1) FOR(j, 1, (MAX << 1) - 1) G[i][j] = add(G[i][j], add(G[i-1][j], G[i][j-1]));

    int ans = 0;
    FOR(i, 0, N-1) {
        ans = sub(ans, F[A[i] + A[i]][B[i] + B[i]]);
        ans = add(ans, G[MAX + A[i]][MAX + B[i]]);
    }

    cout << mul(ans, (MOD + 1) >> 1) << endl;
}



Measured memory_bytes: 190592
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    (1..n).map { Triple(sc.next(), sc.nextInt(), it) }
        .sortedWith(Comparator { o1, o2 ->
            if (o1.first == o2.first) o2.second - o1.second
            else o1.first.compareTo(o2.first)
        }).forEach { println(it.third) }
}

Measured memory_bytes: 33996
#include <stdio.h>

#define INF 999999999

int asumikana[512][512];

int main(void) {
	int N, M;
	int i, j, k;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 1; i <= N; i++) {
		for (j = 1; j <= N; j++) {
			asumikana[i][j] = INF;
		}
		asumikana[i][i] = 0;
	}
	for (i = 0; i < M; i++) {
		int a, b;
		if (scanf("%d%d", &a, &b) != 2) return 1;
		asumikana[a][b] = 1;
	}
	for (k = 1; k <= N; k++) {
		for (i = 1; i <= N; i++) {
			for (j = 1; j <= N; j++) {
				if (asumikana[i][j] > asumikana[i][k] + asumikana[k][j]) {
					asumikana[i][j] = asumikana[i][k] + asumikana[k][j];
				}
			}
		}
	}
	for (i = 1; i <= N; i++) {
		int isFirst = 1;
		for (j = 1; j <= N; j++) {
			if (asumikana[i][j] < INF && asumikana[j][i] < INF) {
				if (!isFirst) putchar(' ');
				printf("%d", j);
				isFirst = 0;
			}
		}
		putchar('\n');
	}
	return 0;
}



Measured memory_bytes: 2400
A, B = map(int, input().split())

ans = 0
if B - A <= 8:
  for i in range(A, B + 1):
    ans = ans ^ i
else:
  for i in range(A, A + 4 - (A % 4)):
    ans = ans ^ i
  for i in range(B - (B % 4), B + 1):
    ans = ans ^ i
print(ans)

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

int main(){
  int n; cin>>n;
  int num[n],ans[n];
  for(int i=0;i<n;i++){
    cin>>num[i];
  }int rest=n;
  while(rest!=0){
    int log=-1,c=0,rec;
    for(int i=0;i<n;i++){
      if(num[i]==-1) continue;
      if(num[i]==c+1){
        if(log<num[i] || log==-1){
          log=c+1; rec=i;
        }
      }
      c++;
    }if(log==-1){
      cout<<-1<<endl;
      return 0;
    }else{
      ans[rest-1]=log;
      num[rec]=-1;
    }rest--;
  }
  for(int i=0;i<n;i++){
    cout<<ans[i]<<endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	int angle = 0, step;
	double x = 0, y = 0, radian;
	String[] input;
	while (scan.hasNext()) {
	    input = scan.nextLine().split(",");
	    if (input[0].equals("0") && input[1].equals("0")) {
		break;
	    }
	    step = Integer.parseInt(input[0]);
	    radian = Math.toRadians(angle);
	    x += step * Math.sin(radian);
	    y += step * Math.cos(radian);
	    angle += Integer.parseInt(input[1]);
	}
	System.out.println((int)x);
	System.out.println((int)y);
    }
}

Measured memory_bytes: 25912
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = list(map(int, input().split()))
h = list(map(int, input().split()))
ans = sum(item>=k for item in h)
print(ans)

Measured memory_bytes: 84336
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
  string N;
  cin >> N;
  int result = 0;
  if(atoi(N.c_str()) == 0){
    cout << "Yes" << endl;
    return 0;
  }
  char num;
  for(int i=0; i < (int)N.size(); i++){
    num = N[i];
    result += num - '0';
  }
  if(result%9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3752
#include <iostream>
#include <map>
using namespace std;
	typedef long long int lli;
	const int MaxN=200005;
int main(){
	lli N,i,mon=100,time=0;
	cin>>N;
	while(mon<N){
		mon=mon+mon*.01;
		time+=1;
	}
	cout<<time;
}

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

int main(){
	string A,B,C;
	bool x,y;
	cin>>A>>B>>C;
	if(A[A.size()-1]==B[0]){
		x=true;
	}
	else{
		x=false;
	}
	if(B[B.size()-1]==C[0]){
		y=true;
	}
	else{
		y=false;
	}
	if(x&&y){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define max 1000010
#define ina(n) for(i = 0; i < n; i++) cin >> a[i]
#define oua(n) for(i = 0; i < n; i++) cout << a[i] << " "
using namespace std;

int a[max];
int i, j, k;

int main()
{
	int x, t = 0;
	cin >> x;
	t = (x / 500) * 1000;
	x %= 500;
	t += (x / 5) * 5;
	cout << t;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    string a, b, c;
    cin>>a>>b>>c;
    string turn = "a";
    while(true){
        if(turn=="a"){
            if(a.length()==0){
                cout<<"A"<<endl;
                break;
            }
            turn=a[0];
            a.erase(a.begin());
        }else if(turn=="b"){
            if(b.length()==0){
                cout<<"B"<<endl;
                break;
            }
            turn=b[0];
            b.erase(b.begin());
        }else if(turn=="c"){
            if(c.length()==0){
                cout<<"C"<<endl;
                break;
            }
            turn=c[0];
            c.erase(c.begin());
        }
    }
    
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int W,H,x,y,r;
	scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
	if(x+r>W){
		printf("No\n");
	}
	else if(x-r<0){
		printf("No\n");
	}
	else if(y+r>H){
		printf("No\n");
	}
	else if(y-r<0){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}
	return 0;
}


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

int main() {
    int w, h, x, y, r;
    cin >> w >> h >> x >> y >> r;
    if((w - (x+r) >= 0 && h - (y+r) >= 0) && (y - r >= 0 && x - r >= 0)){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
    cin>>n;
    int dp[n+1];
    int h[n+1];
    for(int i=1;i<=n;i++)
    	cin>>h[i];
    dp[1]=0;
    for(int i=2;i<=n;i++)
    {
    	 if(i==2)
    	 {
    	 	 dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
    	 	 continue;
    	 }
    	 dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n];
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            long iN = long.Parse(sS[0]);
            long iM = long.Parse(sS[1]);
            List<ClsShp> lstShp = new List<ClsShp>();
            for (int i = 0; i < iN; i++)
            {
                sS = System.Console.ReadLine().Trim().Split(' ');
                ClsShp oneUsr = new ClsShp();
                oneUsr.iA = long.Parse(sS[0]);
                oneUsr.iB = long.Parse(sS[1]);
                lstShp.Add(oneUsr);
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            lstShp.Sort(delegate (ClsShp mca1, ClsShp mca2) { return (int)(mca1.iA - mca2.iA); });        // 値段の昇順
            long iOut = 0;
            long iCnt = 0;
            for (int i = 0; i < lstShp.Count; i++)
            {
                if (iCnt + lstShp[i].iB < iM) { iOut += lstShp[i].iA * lstShp[i].iB; iCnt += lstShp[i].iB; }
                else { iOut += lstShp[i].iA * (iM - iCnt); iCnt = iM; break; }
            }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

        // 店情報
        private class ClsShp
        {
            public long iA { get; set; } = 0;       // 値段
            public long iB { get; set; } = 0;       // 制限
        }

}


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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  LL x;
  cin >> x;
  LL val = 100;
  int i = 0;
  while (val < x) {
    val = (double)val * 1.01;
    i++;
  }
  cout << i << "\n";
  return 0;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  
  cin >> a >> b;

  if (ab[a] == ab[b]) anss = "Yes";
  else anss="No";
  
  cout << anss << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll N, M, X, Y;
    ll x, y;
    ll xmax, ymin;
    ll answer;

    xmax = -100;
    ymin = 100;
    cin >> N >> M >> X >> Y;
    rep(i, N){
        cin >> x;
        xmax = max(xmax, x);
    } 
    rep(i, M){
        cin >> y;
        ymin = min(ymin, y);
    }

    For(z, X + 1, Y + 1) if (X < z && z <= Y && xmax < z && z <= ymin) {cout << "No War" << endl; return 0;}

    cout << "War" << endl;

    return 0;
}

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

string toUpper(string s){
  string t = s;
  for (int i = 0; i < s.size(); i++)
    t[i] = toupper(s[i]);

    return t;
}

int main(){
  int a = 0; //a??????????????????????????????
  string str1, str2;
  cin >> str2;
  str2 = toUpper(str2);

  while (1) {
    cin >> str1;
    if (str1 == "END_OF_TEXT") break;
    str1 = toUpper(str1);

    if (str1 == str2) a++;

  }

  cout << a << endl;

return 0;
}

Measured memory_bytes: 3200
def main():
    Q, H, S, D = map(int, input().split())
    N = int(input())
    N = 4*N
    val = [[Q, Q, 1], [H/2, H, 2], [S/4, S, 4], [D/8, D, 8]]
    val.sort(key = lambda x:x[0])
    ans = 0
    for i in range(4):
        count = N // val[i][2]
        ans += count * val[i][1]
        N = N - count * val[i][2]
    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3064
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}


int main() {
    int h,w,k;
    int x1,y1,x2,y2;

    cin>>h>>w>>k;
    cin>>y1>>x1>>y2>>x2;
    x1--;y1--;x2--;y2--;
    vector<vector<char>> v(h+1,vector<char>(w+1,0));
    vector<vector<int>> c(h+1,vector<int>(w+1,INF));

    rep(i,h){
        rep(j,w){
            cin>>v[i][j];
        }
    }

    queue<pair<int,int>> q;
    q.push({y1,x1});
    c[y1][x1] = 0;
    while(!q.empty()){
        auto p = q.front();
        int px = p.second;
        int py = p.first;
        q.pop();

        for(int i=0;i<4;i++){
            int xd = dx[i];
            int yd = dy[i];
            for(int j=1;j<=k;j++){
                int xdd = xd*j + px ;
                int ydd = yd*j + py ;
                if(xdd>=0&&ydd>=0&&xdd<w&&ydd<h){
                    if(v[ydd][xdd]=='@'){
                        break;
                    }else {
                        if(c[ydd][xdd]>c[py][px] + 1){
                            c[ydd][xdd]=c[py][px] + 1;
//                            cout<<ydd<<" "<<xdd<<endl;
//                            cout<<c[ydd][xdd]<<endl;
                            q.push({ydd,xdd});
                        }else if(c[ydd][xdd]<=c[py][px]){break;}
                    }
                }
            }
        }
    }
//    rep(i,h){
//        rep(j,w){
//            cout<<c[i][j]<<" ";
//        }
//        cout<<endl;
//    }
    if(c[y2][x2]==INF){
        c[y2][x2]=-1;
    }


    cout<<c[y2][x2]<<endl;































    return 0;


}



Measured memory_bytes: 16912
#include <iostream>
#include <map>
#include <vector>
#include <iomanip>
using namespace std;

int main() {
	int N; cin >> N;
	vector<int> t(N);
	for(int i=0; i<N; ++i){
	    cin >> t[i];
	    t[i] *= 2;
	}
	map<int, int> diag, diah, diai;
	double sum=0.0;
	for(int i=0; i<N; ++i){
	    int v; cin >> v;
	    diah[sum]=diag[sum]=min(diag[sum], v*2);
	    for(int p=1; p<=t[i]; ++p) diah[sum+p]=diag[sum+p]=v*2;
	    sum += t[i];
	}
	diag[0]=0;
	for(int d=1; d<=sum; ++d) diag[d]=min(diag[d-1]+1, diag[d]);
	diah[sum]=0;
	for(int d=sum-1; d>=0; --d) diah[d]=min(diah[d+1]+1, diah[d]);
	for(int d=0; d<=sum; ++d) diai[d]=min(diag[d], diah[d]);
	double ans=0.0;
	for(int d=1; d<=sum; ++d) ans += (double) (diai[d-1]+diai[d])/8;
	cout << setprecision(15) << ans << endl;
	return 0;
}


Measured memory_bytes: 5888
n,x = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
b = Marshal.load(Marshal.dump(a))
ans = 10**13
for i in 0..n-1
  for j in 0..n-1
    b[j] = a[(j-i)%n] if b[j] > a[(j-i)%n]
  end
  bsum = b.inject(:+)+x*i
  ans = bsum if ans > bsum
end
puts ans

Measured memory_bytes: 1916
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int count = 0;
			while(sc.hasNext()) {
				int m = sc.nextInt();
				if(m == 0) break;
				
				if(count > 0) System.out.println();
				count++;
				
				int a = sc.nextInt();
				int b = sc.nextInt();
				int c = sc.nextInt();
				int d = sc.nextInt();
				
				int min = Integer.MAX_VALUE;
				int ansa = 0;
				int ansb = 0;
				int ansc = 0;
				int ansd = 0;
				
				for(int i=0; i<=a; i++) {
					for(int j=0; j<=b; j++) {
						for(int k=0; k<=c; k++) {
							for(int l=0; l<=d; l++) {
								int M = 10*i + 50*j + 100*k + 500*l - m;
								if(M < 0) continue;
								if(i == (M % 50 / 10) && i != 0) continue;
								if(j == (M % 100 / 50) && j != 0) continue;
								if(k == (M % 500 / 100) && k != 0) continue;
								if(l == (M / 500) && l != 0) continue;
								int z = a-i + b-j + c-k + d-l + M / 500+M%500 / 100+M%100 / 50+M%50 / 10;
								
								if(min > z) {
									min = z;
									ansa = i;
									ansb = j;
									ansc = k;
									ansd = l;
								}
							}
						}
					}
				}
				if(ansa != 0) System.out.println("10 " + ansa);
				if(ansb != 0) System.out.println("50 " + ansb);
				if(ansc != 0) System.out.println("100 " + ansc);
				if(ansd != 0) System.out.println("500 " + ansd);
			}
		}
	}
}


Measured memory_bytes: 43136
using System;
using static System.Console;

class Program
{
    public static void Main()
    {
        string t = ReadLine();
        int n = t.Length;

        char[] s = new char[n];
        for (int i = 0; i < n; i++)
            s[i] = t[i];

        long ans = 0;
        int foundA = -1;
        for (int i = 0; i < n-1; i++)
        {
            if (foundA < 0)
            {
                if (s[i] == 'A'){ foundA = i; }
            }
            else if (s[i] == 'A')
            {
                continue;
            }
            else if (s[i] == 'B' && s[i+1] == 'C')
            {
                s[i] = s[i+1] = 'A';
                s[foundA] = 'B'; s[foundA+1] = 'C';
                ans += i - foundA;
                foundA += 2;
                i++;
            }
            else
            {
                foundA = -1;
            }
        }

        WriteLine(ans);
    }
}

Measured memory_bytes: 13224
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
m=max(a)
c=a.count(m)
i=a.index(m)
if(c!=1):
    for j in range(n):
        print(m)
else:
    a.remove(m)
    mm=max(a)
    for j in range(n):
        if(j==i):
            print(mm)
        else:
            print(m)
    


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

namespace contest_Csharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string  S=Console.ReadLine();
            //var prop = Console.ReadLine().Split(' ')
            //  .Select(x => int.Parse(x)).ToList();
            var ans = (S[0] == '7') || (S[1] == '7') || (S[2] == '7') ? "Yes" : "No";
            Console.WriteLine(ans);



        }
    }
}


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

void RollN(vector<int> &a)
{
    int c = a[0];
    a[0] = a[1];
    a[1] = a[5];
    a[5] = a[4];
    a[4] = c;
}
void RollE(vector<int> &a)
{
    int c = a[0];
    a[0] = a[3];
    a[3] = a[5];
    a[5] = a[2];
    a[2] = c;
}
void Spin(vector<int> &a)
{
    int c = a[1];
    a[1] = a[2];
    a[2] = a[4];
    a[4] = a[3];
    a[3] = c;
}
bool IsSame(vector<int> &a, vector<int> &b)
{
    for (int i = 0; i < 4; i++)
    {
        if (a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3] && a[4] == b[4] && a[5] == b[5])
        {
            return true;
        }
        for (int j = 0; j < 4; j++)
        {
            if (a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3] && a[4] == b[4] && a[5] == b[5])
            {
                return true;
            }
            Spin(a);
        }
        RollN(a);
    }
    RollE(a);
    for (int i = 0; i < 2; i++)
    {
        if (a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3] && a[4] == b[4] && a[5] == b[5])
        {
            return true;
        }
        for (int j = 0; j < 4; j++)
        {
            if (a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3] && a[4] == b[4] && a[5] == b[5])
            {
                return true;
            }
            Spin(a);
        }
        RollE(a);
        RollE(a);
    }
    return false;
}

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

    for (int i = 1; i < n; i++)
    {
        if (IsSame(a[0], a[i]))
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 3172
#include<iostream>
#include<vector>
#include<queue>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;

int main()
{
    int n,a;
  string s,t; 
  // vector <long> v(n);
  cin >>s;

  vector<bool> v(26,false);
  bool ans=true;
  for (int i = 0; i < s.size(); ++i)
  {
      if(v[s[i]  -'a'] ==true)ans=false;
      v[s[i]-'a']=true;
  }
    


    cout <<  (ans?"yes":"no");
    
    return 0;
}






Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5, P = 1e9 + 7;
int n, ans;
int cnt[maxn];
char s[maxn];
int main() {
	scanf("%d%s", &n, s + 1);
	for(int i = 1; i <= n; ++i) {
		++cnt[s[i] - 'a'];
		int t = 1;
		for(int j = 0; j < 26; ++j) if(j != s[i] - 'a')
			t = 1LL * t * (cnt[j] + 1) % P;
		ans = (ans + t) % P;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>

using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;

int h, w;
char in[101];
int cnt[26];

int mat[100][100];
int cs[10001];
char ans[10001];

void dfs(int x, int y, int c) {
    if (mat[x][y]) return;
    mat[x][y] = c;
    ++cs[c];
    
    dfs(h - 1 - x, y, c);
    dfs(x, w - 1 - y, c);
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> h >> w;
	for (int i = 0; i < h; ++i) {
        cin >> in;
        for (int j = 0; j < w; ++j) {
            ++cnt[in[j] - 'a'];
            dfs(i, j, i * w + j + 1);
        }
	}
	for (int ct = 4; ct > 0; --ct) {
        for (int i = 1; i <= h * w; ++i) {
            if (cs[i] != ct) continue;
            int j;
            for (j = 0; j < 26; ++j) {
                if (ct <= cnt[j]) {
                    cnt[j] -= ct;
                    ans[i] = j + 'a';
                    break;
                }
            }
            if (j == 26) {
                printf("No\n");
                return 0;
            }
        }
	}
	printf("Yes\n");
    return 0;
}


Measured memory_bytes: 384
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val s = sc.next()
    println(problem003a(s))
}

fun problem003a(s: String): String {
    val sArray = s.toCharArray()
    val nCount = sArray.count { it == 'N' }
    val sCount = sArray.count() { it == 'S' }
    val eCount = sArray.count { it == 'E' }
    val wCount = sArray.count() { it == 'W' }
    val ns = (nCount == 0 && sCount == 0) || (nCount > 0 && sCount > 0)
    val ew = (eCount == 0 && wCount == 0) || (eCount > 0 && wCount > 0)
    return if (ns && ew) "Yes" else "No"
}

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

int main(){
  int x,n;
  cin >> x >> n;
  if(n==0){
    cout << x << endl;
    return 0;
  }
  vector<int> p(n),q(102,0);
  int i;
  for(i=0;i<n;i++){
    cin >> p.at(i);
    q.at(p.at(i))=1;
  }
  
  if(q.at(x)==0){
    cout << x << endl;
    return 0;
  }
  
  int x1=x,x2=x;
  while(q.at(x1)==1){
    x1--;
  }
  while(q.at(x2)==1){
    x2++;
  }
  
  if(x2-x<x-x1){
    cout << x2 << endl;
  }else{
    cout << x1 << endl;
  }
}

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<double> p(n+1);
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        p[i] = (p[i] + 1.0) / 2.0;
    }
    partial_sum(begin(p), end(p), begin(p));
    double ans = 0;
    for (int i = 0; i+k <= n; i++) {
        ans = max(ans, p[i+k]-p[i]);
    }
    cout << fixed << setprecision(15) << ans << endl;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cstring>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };
 
int MOD = 1000000007;

int main() {
	for (;;) {
		int a, b; string s; cin >> a >> s >> b;
		if (s == "+") cout << a + b << endl;
		if (s == "-") cout << a - b << endl;
		if (s == "*") cout << a * b << endl;
		if (s == "/") cout << a / b << endl;
		if (s == "?") break;
	}
}

Measured memory_bytes: 1204
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int main()
{
	int i,n;
	cin>>n;
	vi a(n);
	for0(i,n) cin>>a[i];
	for(i=n-1 ; i>=0 ; i-=2) cout<<a[i]<<" ";
	if(n%2){
		for(i=1 ; i<n ; i+=2) cout<<a[i]<<" ";
		}
	else{
		for(i=0 ; i<n ; i+=2) cout<<a[i]<<" ";
		}
	
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll dp[3002][3002];
ll a[3002];
void solve (ll i, ll j, ll c)
{
	if (dp[i][j]!=-1)
		return;
	else
	{
		if (c)
		{
			c=0;
			if (i==j)
			{
				ll ans=a[i];
				dp[i][j]=-ans;
				return;
			}
			else if (i<j)
			{
				solve(i+1,j,c);
				solve(i,j-1,c);
				dp[i][j]=min(dp[i+1][j]-a[i],dp[i][j-1]-a[j]);	
				return;
			}	
			else
			{
				dp[i][j]=0;
				return;
			}
		}
		else
		{
			c=1;
			if (i==j)
			{
				ll ans=a[i];
				dp[i][j]=ans;
				return;
			}
			else if (i<j)
			{
				solve(i+1,j,c);
				solve(i,j-1,c);
				dp[i][j]=max(dp[i+1][j]+a[i],dp[i][j-1]+a[j]);
				return;
			}	
			else
			{
				dp[i][j]=0;
				return;
			}
		}
	}
}
int main()
{
	ll n;
	cin>>n;
	for (ll i=1;i<=n;i++)
		cin>>a[i];
	for (ll i=0;i<=n;i++)
	{
		for (ll j=0;j<=n;j++)
			{
				dp[i][j]=-1;	
			}
	}
	solve(1,n,0);
	cout<<dp[1][n];
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a + b + c <= 21) cout << "win" << endl;
    else cout << "bust" << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int sum = 0;
		int [] nlist = new int[n];
		for(int i=0; i<n; i++) {
			nlist[i] = sc.nextInt();
		}
		Arrays.sort(nlist);
			for(int i=0; i<k; i++) {
				sum += nlist[i];
			}
			System.out.println(sum);
		}
	

}


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

int main() {
  char a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  string ans="NO";
  if(a==f&&b==e&&c==d)ans="YES";
  cout << ans << endl;
  return 0;  
}      

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

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr int mo2 = 998244353;
constexpr ll infl = 1ll<<60;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    vector<string> s = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string str;
    cin>>str;
    for(int i= 0;i<7;++i){
        if(s[i] == str){
            cout << 7-i << endl;
            return 0;
        }
    }
    return 0;
}



Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1);

vector<ll> sumB;

//https://qiita.com/drken/items/97e37dd6143e33a64c8c
//めぐる式二分探索法

//先に探索する配列をグローバル配列として宣言しておく必要がある。
// index が条件を満たすかどうか
bool BinaryJudgeisOK(int index, ll key) {
    if (/*a[index] >= key*//*ここに条件式*/sumB.at(index)<=key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(ll key) {
    //leftとrightのどちらがok,ngかは自分で判断する必要がある。
    int ok = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ng = (int)/*a*/sumB.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (BinaryJudgeisOK(mid, key)) ok = mid;
        else ng = mid;
    }
    //ok==-1||ok=配列変数.size()の時はその配列内に該当する値は存在しない。
    return ok;
    //配列変数内に必ず該当する値が存在すると言えるときにのみ使える。
    //使う場合はllに変えておいた方がいい
    //return 配列変数.at(ok);
}


int main() 
{
  ll N,M,K; cin>>N>>M>>K;
  vector<ll> A(N);
  vector<ll> sumA(N+1);
  vector<ll> B(M);
  sumB=vector<ll>(M+1);
  rep(i,N)
  {
    cin>>A.at(i);
    sumA.at(i+1)=A.at(i);
  }
  rep(i,M)
  {
    cin>>B.at(i);
    sumB.at(i+1)=B.at(i);
  }
  for(int i=1;i<=N;i++)
  {
    sumA.at(i)+=sumA.at(i-1);
  }
  for(int i=1;i<M;i++)
  {
    sumB.at(i)+=sumB.at(i-1);
  }
  
  ll ans=0;
  rep(i,N+1)
  {
    int j=binary_search(K-sumA.at(i));
    if(j==-1) continue;
    ans=max(ans,(ll)i+j);
    //cout<<i<<" "<<j<<" "<<i+j<<endl;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 9496
/*;

THE BEST IS YET TO COME

*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define r(i, s, l) for (int i = s; i < l; i++)
#define rr(i, s, l) for (int i = s; i >= l; i--)
#define mod 1000000007
#define INT_BITS 32
#define ld long double
#define pp pair<int, int>
#define ss second
#define ff first
#define INF 1e18
#define N 2000005
#define all(a) a.begin(), a.end()
#define pb push_back
#define vi vector<int>
#define vip vector<pair<int, int>>
#define endl "\n"
#define ln length()
#define sz size()
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

signed main()
{

    fast();
    int n;
    cin>>n;

    if(n%1000==0)
    cout<<0;
    else
    cout<<1000-n%1000;
    

    return 0;
}

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

int main(){
    int n; cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    sort(s.begin(),s.end());

    int times=0; int m=0;
    vector<int> ti(n);
    rep(i,n){
        if(i==0) ti[i] = 1;
        else if(s[i]==s[i-1]) ti[i]=ti[i-1]+1;
        else ti[i]=1;
        m=max(m,ti[i]);
    }

    rep(i,n){
        if(ti[i]==m) cout << s[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 15104
#include<cstdio>
#include<cctype>
#include<iostream>
#include<queue>
#define RI register int
#define CI const int&
using namespace std;
const int N=350,M=(N*N<<1)+(3*N);
const long long INF=1e18;
struct edge
{
	int to,nxt,v; long long c;
}e[M<<1]; char opt[N]; long long ans,v[N];
int n,m,head[N],cnt,x[N],y[N],L[N],R[N],U[N],D[N],a[N],b[N],s,t;
inline char getch(void)
{
	char ch; while (!isalpha(ch=getchar())); return ch;
}
inline void addedge(CI x,CI y,CI v,const long long& c)
{
	e[++cnt]=(edge){y,head[x],v,c}; head[x]=cnt;
	e[++cnt]=(edge){x,head[y],0,-c}; head[y]=cnt;
}
#define to e[i].to
namespace NF //Network_Flow
{
	queue <int> q; int pre[N],lst[N],cap[N]; long long dis[N]; bool vis[N];
	inline bool SPFA(CI s,CI t)
	{
		RI i; for (i=s;i<=t;++i) dis[i]=-INF,cap[i]=1e9,pre[i]=-1;
		pre[s]=0; q.push(s); dis[s]=0; vis[s]=1; while (!q.empty())
		{
			int now=q.front(); q.pop(); vis[now]=0;
			for (i=head[now];i;i=e[i].nxt)
			if (e[i].v&&dis[to]<dis[now]+e[i].c)
			{
				dis[to]=dis[now]+e[i].c; pre[to]=now; lst[to]=i;
				cap[to]=min(cap[now],e[i].v); if (!vis[to]) vis[to]=1,q.push(to);
			}
		}
		return ~pre[t];
	}
	inline long long MCMF(CI s,CI t)
	{
		long long ret=0; while (SPFA(s,t))
		{
			ret+=dis[t]*cap[t]; for (int nw=t;nw;nw=pre[nw])
			e[lst[nw]].v-=cap[t],e[lst[nw]^1].v+=cap[t];
		}
		return ret;
	}
	inline void clear(CI n)
	{
		cnt=1; for (RI i=0;i<=n;++i) head[i]=0;
	}
};
#undef to
inline long long calc(CI k)
{
	RI i,j; for (i=1;i<=k;++i) L[i]=D[i]=0,R[i]=U[i]=1e9;
	for (NF::clear(2*n+2*k+1),i=1;i<=m;++i) if (b[i]<k) 
	{
		if (opt[i]=='L') L[b[i]+1]=a[i]+1;
		if (opt[i]=='R') R[k-b[i]]=a[i]-1; 
		if (opt[i]=='D') D[b[i]+1]=a[i]+1;
		if (opt[i]=='U') U[k-b[i]]=a[i]-1; 
	}
	for (i=2;i<=k;++i) L[i]=max(L[i],L[i-1]),D[i]=max(D[i],D[i-1]);
	for (i=k-1;i;--i) R[i]=min(R[i],R[i+1]),U[i]=min(U[i],U[i+1]);
	for (s=0,t=2*n+2*k+1,i=1;i<=k;++i) addedge(s,i,1,0),addedge(k+2*n+i,t,1,0);
	for (i=1;i<=n;++i) addedge(k+i,k+n+i,1,v[i]);
	for (i=1;i<=k;++i) for (j=1;j<=n;++j)
	{
		if (L[i]<=x[j]&&x[j]<=R[i]) addedge(i,k+j,1,0);
		if (D[i]<=y[j]&&y[j]<=U[i]) addedge(k+n+j,k+2*n+i,1,0);
	}
	return NF::MCMF(s,t);
}
int main()
{
	RI i; for (scanf("%d",&n),i=1;i<=n;++i) scanf("%d%d%lld",&x[i],&y[i],&v[i]);
	for (scanf("%d",&m),i=1;i<=m;++i) opt[i]=getch(),scanf("%d%d",&a[i],&b[i]);
	for (i=1;i<=n;++i) ans=max(ans,calc(i)); return printf("%lld",ans),0;
}

Measured memory_bytes: 4244
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>


using namespace std;

bool win(char* t, char c)
{
	for (int y = 0; y < 3; ++y)
	{
		bool ok = true;
		for (int x = 0; x < 3; ++x)
		{
			if (t[y*3 + x] != c)
			{
				ok = false;
				break;
			}
		}
		if (ok)
			return true;
	}
	for (int x = 0; x < 3; ++x)
	{
		bool ok = true;
		for (int y = 0; y < 3; ++y)
		{
			if (t[y*3 + x] != c)
			{
				ok = false;
				break;
			}
		}
		if (ok)
			return true;
	}

	return t[0] == c && t[4] == c && t[8] == c
		|| t[2] == c && t[4] == c && t[6] == c;
}

int main()
{
	char buf[10];
	while (scanf("%s\n", buf) != EOF)
	{
		char c;
		if (win(buf, 'o'))
			c = 'o';
		else if (win(buf, 'x'))
			c = 'x';
		else
			c = 'd';
		printf("%c\n", c);
	}

	return 0;
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        string S; cin >> S;
        ll K; cin >> K;
        vector<ll> seq = {0};
        repeat(i, 1, S.size()) {
            seq.back()++;
            if(S[i] != S[i - 1]) seq.push_back(0);
        }
        seq.back()++;
        //debug(seq);
        if(seq.size() == 1) {
            cout << (ll)S.size() * K / 2 << endl;
            return 0;
        }
        if(S.front() == S.back()) {
            ll f = seq.front();
            ll b = seq.back();
            ll ans_a = 0;
            repeat(i, 1, seq.size() - 1) ans_a += seq[i] / 2;
            ll ans = ans_a * K + f / 2 + b / 2 + (f + b) / 2 * (K - 1);
            cout << ans << endl;
        } else {
            ll ans_a = 0;
            rep(i, seq.size()) ans_a += seq[i] / 2;
            ll ans = ans_a * K;
            cout << ans << endl;
        }
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 256
#include <string.h>
#include <string.h>
int main(){
char S[15];
char T[15];
scanf("%s %s",S,T);

int a,b;
scanf("%d %d", &a,&b);

char N[15];
scanf("%s", N);

if(strcmp(N,S)==0) printf("%d %d", a-1,b);
if(strcmp(N,T)==0) printf("%d %d", a,b-1);
return 0 ;
}

Measured memory_bytes: 1704
#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 REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int n;
    cin >> n;
    int count = 0;
    vector<int> a(n);
    REP(i,n){cin >> a[i];}
    
    int flag = 0;
    for(int i=0;i<n;i++){
        //切った次のやつと同じやつをスルー
        while(i+1<n&&a[i]==a[i+1])i++;

        if(i+1<n&&a[i]>a[i+1]){
            while(i+1<n&&a[i]>=a[i+1])i++;
        }
        else if(i+1<n&&a[i]<a[i+1]){
            while(i+1<n&&a[i]<=a[i+1])i++;
        }
        flag++;
    }
    cout << flag << endl;
    return 0;
}    


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
using namespace std;
 
int main(){
    
    double N,x,ans=0;
    string u;

    cin >> N;

    for(int i=1;i<=N;i++){
        cin >> x>>u;

        if(u == "JPY"){
            ans += x;
        }else{
            ans += x*380000.00;
        }

    }

    cout << ans;

    return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;


int n;
int a[110];
int numCount[110];

int main()
{
	int T;
	scanf("%d", &T);
	
	if (T == 1)
		printf("0\n");
	else
		printf("1\n");

	return 0;
}




Measured memory_bytes: 1664