akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,L;
    cin >> N >> L;
    vector<ld> T(N);
    rep(i,N){
        cin >> T[i];
    }
    ld resx=0,resy=0;
    rep(i,N){
        rep(j,i){
            resx+=(N-2+2*(j-i+1))*cos((PI*(T[i]+T[j])/L));resy+=(N-2+2*(j-i+1))*sin(PI*(T[i]+T[j])/L);
        }
    }
    cout << fixed << setprecision(10) << resx*6/(N*(N-1)*(N-2)) << ' ' << resy*6/(N*(N-1)*(N-2)) << endl;
}
/*
overflow checked?
corner case checked?
boundary checked?
not TLE in worst case checked?
*/


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

using lli = long long int;
using ll = long long;

lli n, m, h, a, b;

std::vector<lli> vec;
std::vector<lli> viewpoints;

int main() {
    std::cin >> n >> m;
    vec.assign(n+1, 0);
    viewpoints.assign(n+1, -1);
    for (int i = 1; i <= n; i++) {
        std::cin >> vec[i];
    }
    for (int i = 0; i < m; i++) {
        std::cin >> a >> b;
        if (vec[a] <= vec[b]) {
            viewpoints[a] = 0;
        }
        if (vec[b] <= vec[a]) {
            viewpoints[b] = 0;
        }
    }
    lli ans = std::count(viewpoints.begin()+1, viewpoints.end(), -1);
    std::cout << ans << std::endl;
}


Measured memory_bytes: 4816
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
    string s;
    cin >> s;
    rep(i,s.size()){
        if(s[i]=='?')
            s[i] = 'D';
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3720
import re
s=input()
t=input()
regex = '([?'+'][?'.join(t[::-1])+'])'
m=re.split(regex,s[::-1])
if len(m)==1:
    print('UNRESTORABLE')
else:
    m[1] = t[::-1]
    print(''.join(m).replace('?','a')[::-1])

Measured memory_bytes: 3188
#include <stdio.h>


int main() {
	char S[256] = { '\0' };
	int len,i;
	int N;
	int count = 0;

	scanf("%d", &N);

	for (i = N; i >= 1; i--) {
		sprintf(S, "%d", i);
		len = strlen(S);
		if (len % 2 == 1) {
			count++;
			
		}

	}
	printf("%d\n", count);

	return 0;

	}

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

int main(){
  int D;
  cin >> D;
  vector<int> c(27);
  for(int i=1;i<27;i++){
    cin >> c.at(i);
  }
  
  vector<vector<int>> s(D+1,vector<int>(27));
  for(int i=1;i<D+1;i++){
    for(int j=1;j<27;j++){
      cin >> s.at(i).at(j);
    }
  }
  
  vector<int> t(D+1);
  for(int i=1;i<D+1;i++){
    cin >> t.at(i);
  }
  
  vector<int> last(27,0);
  
  ll ans=0;
  
  for(int i=1;i<D+1;i++){
    ans += s.at(i).at(t.at(i));
    last.at(t.at(i)) = i;
    for(int j=1;j<27;j++){
      ans -= c.at(j) * (i - last.at(j));
    }
    cout << ans << endl;
  }
  
  return(0);
}

Measured memory_bytes: 3680
from collections import defaultdict
N = int(input())
d = defaultdict(int)
for _ in range(N):
    s = str(input())
    d[s] += 1
print('AC x {}'.format(d['AC']))
print('WA x {}'.format(d['WA']))
print('TLE x {}'.format(d['TLE']))
print('RE x {}'.format(d['RE']))

Measured memory_bytes: 9468
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main() {
	int n;
	cin >> n;
	int* x = new int[n];
	int* y = new int[n];
	for (int i = 0; i < n; i++)
		cin >> x[i];
	for (int i = 0; i < n; i++)
		cin >> y[i];
	double norm;
	for (int p = 1; p <= 3; p++) {
		norm = 0;
		for (int i = 0; i < n; i++)
			norm += pow(fabs(x[i] - y[i]), p);
		norm = pow(norm, 1.0 / p);
		cout << setprecision(5) << fixed << norm << endl;
	}
	norm = 0;
	int max = fabs(x[0] - y[0]);
	for (int i = 1; i < n; i++)
		if (max < fabs(x[i] - y[i]))
			max = fabs(x[i] - y[i]);
	norm = max;
	cout << setprecision(5) << fixed << norm << endl;
	return 0;
}


Measured memory_bytes: 3476
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
long long int fun(vector<long long int>v, vector<long long int>p, long long int w, long long int n)
{
    long long int k[n+1][w+1],i,j;
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=w;j++)
        {
            if(i==0||j==0)
            {
                k[i][j]=0;
            }
            else if(v[i-1]<=j)
            {
                k[i][j]=max(p[i-1]+k[i-1][j-v[i-1]],k[i-1][j]);
            }
            else
            {
                k[i][j]=k[i-1][j];
            }
        }
    }
    return(k[n][w]);
}
int main()
{
    long long int n,i,w;
    cin>>n>>w;
    vector<long long int>v(n);
    vector<long long int>p(n);
    for(i=0;i<n;i++)
    {
        cin>>v[i]>>p[i];
    }
    cout<<fun(v,p,w,n);
}


Measured memory_bytes: 79104
// Problem : C - Reconciled?
// Contest : AtCoder Regular Contest 076
// URL : https://atcoder.jp/contests/arc076/tasks/arc076_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define size(x) (int)x.size()

const int N = 1e6 + 1, mod = 1e9 + 7, inf = 2e9;

#define temptts template <class T, class... Ts>
temptts int add(T f) { return f; } temptts int add(T f, Ts... ts) { return (f + add(ts...)) % mod; }
temptts int sub(T f) { return f; } temptts int sub(T f, Ts... ts) { return (f - sub(ts...) + mod * 2) % mod; }
temptts int mul(T f) { return f; } temptts int mul(T f, Ts... ts) { return (1ll * f * mul(ts...)) % mod; }
int binpow(ll n, ll k) { int ans = 1; while (k) { if (k & 1) ans = mul(ans, n); n = mul(n, n), k >>= 1; } return ans; }
int inv(int n) { return binpow(n, mod - 2); }
struct precompute { int f[N]; precompute() { f[0] = 1; for (int i = 1; i < N; i++) f[i] = mul(f[i - 1], i); } int operator() (int n) { return f[n]; } } fact;
int C(int n, int k) { return mul(fact(n), inv(mul(fact(k), fact(n - k)))); }

int n, m;

int main() { cin.tie(0)->sync_with_stdio(0);
	cin >> n >> m;
	if (n < m) swap(n, m);
	if (n - m > 1) cout << 0;
	else if (n == m) cout << mul(2, fact(n), fact(m));
	else cout << mul(fact(n), fact(m));
}


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

int main() {
    double d;
    cin >> d;
    double ans = d * sqrt(2);
    cout << fixed << setprecision(10);
    cout << max(ans, (double)((int)d + 1)) << endl;
    return 0;
}


Measured memory_bytes: 3268
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
using namespace std;

typedef long long ll;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)

int N,M;


int main() {
  cin >> N>>M; 
  vector<pair<ll,ll>> shop(N,pair<ll,ll>(0,0));
  rep(i,N) cin >> shop.at(i).first >> shop.at(i).second;
  sort(shop.begin(),shop.end());
  
  ll ans = 0;
  rep(i,N){
    if(M > shop.at(i).second){
	  M -= shop.at(i).second;
	  ans += shop.at(i).second*shop.at(i).first;
	  continue;
	}
    ans += M*shop.at(i).first;
	break;
  }
  
  cout << ans << endl;
	
}



Measured memory_bytes: 1792
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  vector<int> a(n), count(32);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = 0; 1 << j <= a[i]; j++) {
      if (a[i] >> j & 1) {
        count[j] = 1 - count[j];
      }
    }
  }
  for (int i = 0; i < n; i++) {
    int ans = 0;
    for (int j = 0; j < 32; j++) {
      if (count[j] != (a[i] >> j & 1)) {
        ans += 1 << j;
      }
    }
    cout << ans << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3984
#include <iostream>
#include <cmath>
using namespace std;
 
int main(void){
  int n,t,a;
  double top = 1000000;
  int flag = 0;
  double h[1002];
  cin >> n;
  cin >> t >> a;
  for(int i = 0; i < n; i++){
    cin >> h[i];
    double th = t - h[i] * 0.006;
    double sa = abs(a - th);
    if(top > (sa)){
      top = sa;
      flag = i + 1;
    }
  }
  cout << flag << endl;
  
  return 0;
}

Measured memory_bytes: 256
import itertools
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
for _ in range(K):
    cumsum = [0] * (N + 2)
    for i, a in enumerate(A):
        i += 1
        cumsum[max(0, i - a)] += 1
        cumsum[min(i + a + 1, N + 1)] -= 1
    A = list(itertools.accumulate(cumsum))[1:N + 1]
    if min(A) == N:
        break
print(' '.join(map(str, A)))


Measured memory_bytes: 205224
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;
        Solver s = new Solver();
        for (int i = 1; i <= t; i++) {
            s.solve(i, in, out);
        }
        out.close();
    }

}

class Solver {

    void solve(int test, InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        int a = in.nextInt();
        int rem = n - (500 * (n / 500));
//        out.println(rem);
        out.println(rem <= a ? "Yes" : "No");
    }
}

class InputReader {
    BufferedReader br;
    StringTokenizer st;

    public InputReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
        st = null;
    }

    public String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }

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

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

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

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 21460
#include<iostream>
using namespace std;
int main()
{
	int a,b,k;
	cin>>a>>b>>k;
	if(b-a>k)
	{
		int flag;
		for(int i=a;i<a+k;i++)
		{
			cout<<i<<endl;
			flag=i;
		}
		for(int i=b-k+1;i<=b;i++)
		{
			if(flag!=i)
			cout<<i<<endl;
		}
	}
	else
	{
		for(int i=a;i<=b;i++)
		{
			cout<<i<<endl;
		}
	}
	return 0;
}

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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

void solve() {
  int h, w; cin >> h >> w;
  int ch, cw, dh, dw;
  cin >> ch >> cw >> dh >> dw;
  ch--; cw--; dh--; dw--;
  vector<vector<char>> s(h, vector<char> (w));
  vector<vector<int>> dist(h, vector<int> (w, 1e9));
  for(int i=0; i<h; ++i) {
    for(int j=0; j<w; ++j) {
      cin >> s[i][j];
    }
  }

  int dy[] = {0,1,0,-1}; 
  int dx[] = {1,0,-1,0};
  deque<pair<int,int>> q;
  q.push_back(make_pair(ch,cw));
  dist[ch][cw] = 0;
  while(!q.empty()) {
    int cy, cx;
    tie(cy, cx) = q.front(); q.pop_front();
    for(int i=0; i<4; ++i) {
      int ny = cy + dy[i], nx = cx + dx[i];
      if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
      if(s[ny][nx] == '#') continue;
      if(dist[ny][nx] > dist[cy][cx]) {
        dist[ny][nx] = dist[cy][cx];
        q.push_front(make_pair(ny,nx));
      }
    }
    for(int i=-2; i<=2; ++i) {
      for(int j=-2; j<=2; ++j) {
        int ny = cy + i, nx = cx + j;
        if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
        if(s[ny][nx] == '#') continue;
        if(dist[ny][nx] > dist[cy][cx]+1) {
          dist[ny][nx] = dist[cy][cx]+1;
          q.push_back(make_pair(ny,nx));
        }
      }
    }
  }
  cout << (dist[dh][dw] == 1e9 ? -1 : dist[dh][dw]) << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


Measured memory_bytes: 8668
#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  int n;
  cin >> n;
  string hoge="ldmbmpncndngntnwpsqucwts";
  map<string, int> mp;
  REP(i, 12) {
    mp[hoge.substr(2*i, 2)] = i+26;
  }
  int num[38][38];
  memset(num,0,sizeof(num));
  cin.ignore();
  while(n--) {
    string line;
    getline(cin, line);
    stringstream ss(line);
    string s;
    while(ss>>s) {
      int pre = -1;
      REP(i, s.size()) {
        int k;
        if (i<s.size()-1 && mp.count(s.substr(i, 2))) {
          k = mp[s.substr(i, 2)];
          i++;
        } else {
          k = s[i]-'a';
        }
        if (pre != -1)
          num[pre][k]++;
        pre = k;
      }
    }
  }
  string kan[38];
  REP(i, 38) {
    if (i<26) kan[i] = string(1, 'a' + i);
    else kan[i] = hoge.substr((i-26)*2, 2);
  }
  REP(i, 38) {
    int ma = max_element(num[i], num[i]+38) - num[i];
    cout << kan[i] << " " << kan[ma] << " " << num[i][ma] << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll w, h, x, y;
    cin >> w >> h >> x >> y;

    ll d = 0;
    if(x * 2 == w && y * 2 == h) d = 1;

    double res = (w * h) / 2.0;
    cout << res << " " << d << endl;
    return 0;
}

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

using namespace std;

using ll= long long;

#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

const int N = 2e5+2;
int length;
int a[N],vis[N];
vector<int> cycle;

void dfs(int node){
	cycle.push_back(node);
	vis[node]=1;
	if(!vis[a[node]]){
		dfs(a[node]);
	}
}
void solve(){
	ll n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]--;
	}
	dfs(0);
	int length=sz(cycle);
	int i=0;
	for(i=0;i<sz(cycle);i++){
		if(a[cycle.back()]==cycle[i]){
			break;
		}
		if(k==0){
			cout<<cycle[i]+1<<"\n";
			return ;
		}
		k--;
		length--;
	}
	k%= length;
	cout<<cycle[i+(int)k]+1<<"\n";
}

int32_t main(){
	IOS

	int t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

/*
   check for overflows int long long
   correct size of array
*/

Measured memory_bytes: 11760
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val words = Array(N) { readLine()!! }
    for (i in 1 until N) {
        val w = words[i]
        if (w[0] != words[i-1][words[i-1].length-1]) {
            println("No")
            return
        }
        for (j in 0 until i) {
            if (w == words[j]) {
                println("No")
                return
            }
        }
    }
    println("Yes")
}

Measured memory_bytes: 33592
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
const int INF = 1001001001;
const ll MOD = 1e9+7;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill((T*)array, (T*)(array+N),val);}

class CompareDist
{
public:
    bool operator()(PLL n1,PLL n2) {
				if(n1.first!=n2.first) return n1.first<n2.first;
				else return n1.second<n2.second;
    }
};


__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	double n; cin>>n;
  rep(i,n+1){
    if(floor(i*1.08)==n) return cout << i << endl,0;
  }
  cout << ":(" << endl;
  return 0;
}


Measured memory_bytes: 256
X, Y = map(int, input().split())

M = 0

if X == 1:
    M += 300000
elif X == 2:
    M += 200000
elif X == 3:
    M += 100000
else:
    pass

if Y == 1:
    M += 300000
elif Y == 2:
    M += 200000
elif Y == 3:
    M += 100000
else:
    pass

if X == 1 and Y == 1:
    M = 1000000

print(M)


Measured memory_bytes: 3060
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

x = ni()
ans = 0
for i in range(100):
    for j in range(2,11):
        p = i**j
        if p <= x:
            ans = max(ans, p)
        else:
            continue

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

struct UnionFind {
    vector< int > data;

    UnionFind(int sz) {
        data.assign(sz, -1);
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return (false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k) {
        if(data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k) {
        return (-data[find(k)]);
    }
};

int main(void) {
    int N, K, L;
    cin >> N >> K >> L;

    UnionFind street(N), train(N);
    while(K--) {
        int p, q;
        cin >> p >> q;
        street.unite(--p, --q);
    }
    while(L--) {
        int r, s;
        cin >> r >> s;
        train.unite(--r, --s);
    }

    map< pair<int,int>, int> mp;
    for(int i=0; i<N; i++) {
        mp[make_pair(street.find(i), train.find(i))]++;
    }
    for(int i=0; i<N; i++) {
        cout << mp[make_pair(street.find(i), train.find(i))] << endl;
    }
    return 0;
}


Measured memory_bytes: 13568
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <map>
#include <algorithm>

using namespace std;

map<string, int> memo;

int parse(const vector<pair<string, int> > &dict, const string &str) {
    int mx = -1;
    if(str.size() == 0) return 0;
    if(memo.count(str) > 0) return memo[str];

    for(int i = 0; i < dict.size(); ++i) {
        const string &s = dict[i].first;
        if(str.compare(0, s.size(), s) == 0) {
            int tmp = parse(dict, str.substr(s.size()));
            if(tmp >= 0) mx = max(mx, tmp+dict[i].second);
        }
    }
    return memo[str] = mx;
}

int main() {
    for(int C = 1; ; ++C) {
        int N;
        cin >> N;
        if(!N) break;

        memo.clear();
        vector<pair<string, int> > v(N);
        for(int i = 0; i < N; ++i) {
            cin >> v[i].first >> v[i].second;
        }

        string str;
        cin >> str;
        int digits = parse(v, str);

        vector<int> dp(digits+1, INT_MAX);
        dp[0] = 0;
        for(int i = 1; i <= digits; ++i) {
            for(int j = 0; j < v.size(); ++j) {
                if(v[j].second <= i) {
                    if(dp[i-v[j].second] != INT_MAX) dp[i] = min(dp[i], (int)(dp[i-v[j].second] + v[j].first.size()));
                }
            }
        }

        cout << "Case " << C << ": " << dp[digits] << endl;
    }
    return 0;
}

Measured memory_bytes: 1008
#include<stdio.h>
#include<string.h>
 
#define LEN 100005
#define MAX 100
 
typedef struct pp{
  char name[MAX];
  int t;
}P;
 
P Q[LEN+1];
int head, tail, n;
 
void initialize(void);
 
void enqueue(P);
P dequeue(void);
 
 
int main(){
  P u;
  int elaps = 0, n;
  int i, q;
  
  scanf("%d %d", &n, &q);
 
  for ( i = 1; i <= n; i++){
    scanf("%s", u.name);
    scanf("%d", &u.t);
    enqueue(u);
  }
  
  while(head != tail){
    u=dequeue();
    if(u.t>q){
      u.t=u.t-q;
      enqueue(u);
      elaps+=q;
    }
    else{
      printf("%s %d\n",u.name,u.t+elaps);
      elaps+=u.t;
    }
  }
   
  return 0;
}
void initialize(void){
  head=0;
  tail=0;
}
  
 
void enqueue(P x){
  
    Q[tail]=x;
    if(tail+1==LEN)
      tail=0;
    else
      tail++;
 
}
P dequeue(void){
  P x;
   
    x=Q[head];
    if(head+1==LEN)
      head=0;
    else
      head++;
 
  return x;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    LL n,a,b;
    cin>>n>>a>>b;
    LL x=a+b;
    LL r=n/x;
    LL d=n%x;
    LL ans=r*a+min(d,a);
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int i;
	double a,s;
	while(scanf("%lf",&a) != EOF){
		s = a;
		for(i = 1; i <= 9;i++){
			if(i % 2) a*=2;
			else a/=3;
			s+=a;
		}
		printf("%lf\n",s);
	}
	return 0;
}

Measured memory_bytes: 648
s = list(input())
n = len(s)
strong = True
s1, s2 = s[0:int((n-1)/2)], s[int((n+3)/2):-1]
for i in range(0, (n-1)//2):
    if s[i] != s[-i-1]:
        strong = False
        break

for i in range(0, len(s1)//2):
    if s1[i] != s1[-i-1]:
        strong = False
        break

for i in range(0, len(s2)//2):
    if s2[i] != s2[-i-1]:
        strong = False
        break

if strong:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

leftGcd = [-1] * (N + 1)
leftGcd[0] = A[0]
for i, a in enumerate(A, start=1):
    leftGcd[i] = gcd(leftGcd[i - 1], a)

rightGcd = [-1] * (N + 1)
rightGcd[-1] = A[-1]
for i, a in enumerate(A[:: -1], start=2):
    rightGcd[-i] = gcd(rightGcd[-i + 1], a)

ans = max(leftGcd[-2], rightGcd[1])
for mid in range(N):
    ans = max(ans, gcd(leftGcd[mid], rightGcd[mid + 1]))

print(ans)

Measured memory_bytes: 14440
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N,D,X;
    cin >> N >> D >> X;
    vector<int> A(N);
    rep(i,N){
        cin >> A[i];
    }
    int count = X;
    rep(i,N){
        count += (D - 1)/ A[i] + 1;
    }
    cout << count << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fsp(x) fixed << setprecision(x)
#define xout cerr
const ll inf = LLONG_MAX;
const long double pi = acosl(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //const ll p = 1e9 + 7;
    //const ll p = 998244353;
    
    clock_t start = clock();
    
    ll d;
    cin >> d;
    vector<ll> c(26);
    for (ll i = 0; i < 26; i++) cin >> c[i];
    vector<vector<ll>> s(d, vector<ll>(26));
    for (ll i = 0; i < d; i++) {
        for (ll j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    
    vector<ll> w(0);
    for (ll i = 0; i < 26; i++) {
        w.push_back(i);
        for (ll j = 0; j < c[i]; j++) {
            w.push_back(i);
        }
    }
    ll m = w.size();
    
    random_device rand;
    vector<ll> ans(d);
    for (ll i = 0; i < d; i++) ans[i] = w[rand() % m];
    
    auto calc_score = [&] () {
        vector<ll> v(26, -1);
        ll ret = 0;
        for (ll i = 0; i < d; i++) {
            v[ans[i]] = i;
            ret += s[i][ans[i]];
            for (ll j = 0; j < 26; j++) {
                ret -= c[j] * (i - v[j]);
            }
        }
        return ret;
    };
    
    ll score = calc_score();
    
    ll cnt = 0;
    while (clock() - start <= 1.95 * CLOCKS_PER_SEC) {
        cnt++;
        ll change_at1 = rand() % d, into1 = w[rand() % m];
        ll memo1 = ans[change_at1];
        ll memo_score = score;
        ans[change_at1] = into1;
        score = calc_score();
        if ((double)score / memo_score < 0.9) {
            ans[change_at1] = memo1;
            score = memo_score;
        }
        else if (score < memo_score && clock() - start > CLOCKS_PER_SEC) {
            ans[change_at1] = memo1;
            score = memo_score;
        }
    }
    
    for (ll i = 0; i < d; i++) cout << ans[i] + 1 << endl;
    xout << score << endl;
}

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

int main()
{
    int X, Y, Z;
    long long K;
    std::cin >> X >> Y >> Z >> K;
    std::vector<long long> A(X);
    std::vector<long long> B(Y);
    std::vector<long long> C(Z);

    for (int i = 0; i < X; ++i)
    {
        std::cin >> A[i];
    }
    for (int i = 0; i < Y; ++i)
    {
        std::cin >> B[i];
    }
    for (int i = 0; i < Z; ++i)
    {
        std::cin >> C[i];
    }

    std::sort(A.begin(), A.end(), [](auto a, auto b) { return a > b; });
    std::sort(B.begin(), B.end(), [](auto a, auto b) { return a > b; });
    std::sort(C.begin(), C.end(), [](auto a, auto b) { return a > b; });

    std::vector<long long> Sums;
    for (int i = 0; i < X; i++)
    {
        for (int j = 0; j < Y; j++)
        {
            Sums.emplace_back(A[i] + B[j]);
        }
    }
    std::sort(Sums.begin(), Sums.end(), [](auto a, auto b) { return a > b; });
    Sums.resize(K);
    std::vector<long long> ans;
    for (int i = 0; i < Z; i++)
    {
        for (int j = 0; j < Sums.size(); j++)
        {
            ans.emplace_back(Sums[j] + C[i]);
        }
    }
    std::sort(ans.begin(), ans.end(), [](auto a, auto b) { return a > b; });
    for (int i = 0; i < K; i++)
    {
        std::cout << ans[i] << std::endl;
    }
    return 0;
}

Measured memory_bytes: 43368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(12);
    ll X;
    cin >> X;
    cout << 10 - X/200 << "\n";
}

Measured memory_bytes: 3688
#include <cstdio>
#include <string>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <utility>
using namespace std;
const int MAXN = 8;
const string& WIN = "01234567";
const int dx[4] = { 1, -1, 0, 0 };
const int dy[4] = { 0, 0, 1, -1 };
struct Status {
    string puzzle;
    int x;
    int y;
    int num;
    Status(const string& p, int x, int y, int n) :
        puzzle(p), x(x), y(y), num(n) { }
};
unordered_map<string, int> HM;
bool isExist(int x, int y) {
    return 0 <= x && x < 2 && 0 <= y && y < 4;
}
void init() {
    queue<Status> Q;
    Q.push(Status(WIN, 0, 0, 0));
    HM.insert(make_pair(WIN, 0));
    while (!Q.empty()) {
        string p = Q.front().puzzle;
        int x = Q.front().x, y = Q.front().y, num = Q.front().num + 1;
        Q.pop();
        for (int i = 0; i < 4; ++i) {
            int nx = x + dx[i], ny = y + dy[i];
            if (isExist(nx, ny)) {
                swap(p[x * 4 + y], p[nx * 4 + ny]);
                if (HM.count(p) == 0) {
                    Q.push(Status(p, nx, ny, num));
                    HM.insert(make_pair(p, num));
                }
                swap(p[x * 4 + y], p[nx * 4 + ny]);
            }
        }
    }
}
int main() {
    init();
    char temp;
    string puzzle;
    while (scanf("%c%*c", &temp) != EOF) {
        puzzle = temp;
        for (int i = 1; i < MAXN; ++i) {
            scanf("%c%*c", &temp);
            puzzle += temp;
        }
        printf("%d\n", HM[puzzle]);
    }
    return 0;
}


Measured memory_bytes: 4736
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

int main(){
    int n;
    lld k;
    scanf("%d %lld", &n, &k);
    lld a[n];
    int cnt_1[41] = {0}, cnt_0[41] = {0};
    rep(i, 0, n){
        scanf("%lld", &a[i]);
        rep(j, 0, 41){
            lld buf = 1LL << j;
            if(a[i] & buf){
                cnt_1[j]++;
            }else{
                cnt_0[j]++;
            }
        }
    }
    int id = -1;
    lld ans = 0;
    lld sum = 0;
    revrep(i, 40, -1){
        lld buf = 1LL << i;
        if(buf <= k && id == -1){
            id = i;
        }
        if(cnt_1[i] > cnt_0[i]){
            ans += buf * cnt_1[i];
        }else{
            if(sum + buf <= k){
                ans += buf * cnt_0[i];
                sum += buf;
            }else{
                ans += buf * cnt_1[i];
            }
        }
    }
    lld t = 0;
    sum = 0;
    revrep(i, id, -1){
        lld buf = 1LL << i;
        if(cnt_1[i] > cnt_0[i]){
            t += buf * cnt_1[i];
        }else{
            if(sum + buf <= k && i != id){
                t += buf * cnt_0[i];
                sum += buf;
            }else{
                t += buf * cnt_1[i];
            }
        }
    }
    if(t > ans){
        ans = t;
    }
    printf("%lld", ans);

    return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }



int main() {
    clock_t start = clock();

    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(n-1));
    vector<int> finished(n, 0);
    // 入れる
    rep(i, n) rep(j, n-1) cin >> a[i][j];


    vector<vector<bool>> mached(n, vector<bool>(1e6, false));

    bool flag = true;
    int ans = 0;
    while(flag) {
        int match_game = 0;
        bool all_finish = true;

        vector<bool> today(n, false);
        vector<bool> today_m(n, ans);
        rep(i, n) {
            if(finished[i] >= n-1) continue;
            all_finish=false;
            int rival = a[i][finished[i]]-1;

            if(a[rival][finished[rival]] == i+1) {
                if(!today[rival] && !today[i]) {
                    match_game++;
                    finished[rival]++;
                    finished[i]++;
                    today[rival] = true;
                    today[i] = true;
                }

            }
        }


        // 全てが終わったら終了
        if(all_finish) {
            cout << ans << endl;
            return 0;
        }

        // 1つもゲームが行われかったらNG
        if(match_game == 0) {
            cout << -1 << endl;
            return 0;
        }

        clock_t end = clock();
        auto t = (double)(end - start) / CLOCKS_PER_SEC;
        if(t >= 1.8) {
            cout << n*(n-1)/2 << endl;
            return 0;
        }

        // 1日終わり
        ans++;

    }
}


Measured memory_bytes: 126464
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  ll m, d;
  cin >> m >> d;
  
  ll ans = 0;
  for (int i = 1; i < m + 1; i++){
    for (int j = 1; j < d + 1; j++){
      if (i == (j / 10) * (j % 10) && j / 10 >= 2 && j % 10 >= 2)
        ans++;
    }
  }
  
  cout << ans << endl;
  
  

  return 0;
}


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

using namespace std;

typedef string s;
typedef int x;

s a,b;

x main(){
    cin>>a>>b;
    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    sort(a.begin(),a.end());
    if(b > a)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}

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

int V, E, R, S[500010], T[500010], D[500010];
int C[100010];
const int Inf = 10000*100000+100;

int main(){
 cin >> V >> E >> R;
 for(int i=0; i<E; i++){
  cin >> S[i] >> T[i] >> D[i];
 }
 for(int j=0; j<V; j++){
  C[j]=Inf;
 }
 C[R]=0;
 for(int t=0; t<V; t++){
  bool update = false;
  for(int i=0; i<E; i++){
   int s = S[i], t = T[i], d = D[i];
   if(C[s]<Inf && (C[s]+d)<C[t]){
    C[t] = C[s]+d;
    update = true;
   }
  }
  if(!update)break;
 }
 
 for(int m=0; m<V; m++){
  if(C[m]==Inf){
   cout << "INF" << endl;
  }
  else{
   cout << C[m] << endl;
  }
 }
}

Measured memory_bytes: 7372
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string start = input.Substring(0,1);
            string end = input.Substring(input.Length-1, 1);

            Console.WriteLine(start + (input.Length-2) + end);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cmath>
using namespace std;
const long double EPS = 1e-12;
int main() {
	double x1, y1, x2, y2, x3, y3, x4, y4;
	int n;
	double veku1[2];
	double veku2[2];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
		veku1[0] = x2 - x1;
		veku1[1] = y2 - y1;
		veku2[0] = x4 - x3;
		veku2[1] = y4 - y3;
		if (fabs(veku1[0]*veku2[1]-veku1[1]*veku2[0]) <= EPS) {
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include<vector>
using namespace std;
int main(void){
    int N;
    cin>>N;
    int count=0;
    vector<int>p(N);
    for(int i=0;i<N;i++){
        cin>>p[i];
        if(p[i]==i+1){
            
        }else{
            count++;
        }
    }
    if(count<=2){
        cout<<"YES";
    }else{
        cout<<"NO";
    }
}

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int>::iterator maxIter;
  size_t maxIndex;
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
  }
  
  bool turn = true;
  int diff=0;
  for(int i = 0; i < N; i++){
    maxIter = max_element(a.begin(), a.end());
    maxIndex = distance(a.begin(), maxIter);
    if(turn){
      diff += a.at(maxIndex);
      turn = false;
    }else{
      diff -= a.at(maxIndex);
      turn = true;
    }
    a.at(maxIndex) = -1;
  }
  cout << diff << endl;
  
  return 0;
}

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

string replacePQR(int p,int q,int r,string input){
  p += '0';
  q += '0';
  r += '0';
  for(int i=0;i<(int)input.size();i++){
    switch(input[i]){
    case 'P':
      input[i]=p;
      break;
    case 'Q':
      input[i]=q;
      break;
    case 'R':
      input[i]=r;
      break;
    }
  }
  return input;
}

string solve(string input){
  //  cout<<input<<endl;  
  if((int)input.size()==1) return input;
  if(input[0]=='('){
    int paren=0;
    int i;
    char op;
    for(i=1;i<(int)input.size();i++){
      if(input[i]=='(') paren++;
      else if(input[i]==')') paren--;
      else if((input[i]=='+' || input[i]=='*' )&& paren == 0){
	op=input[i];
	break;
      }
    }
    string s1,s2;
    s1=solve(input.substr(1,i-1));
    s2=solve(input.substr(i+1,(int)input.size()-2-i));
    if(op=='+'){
      if(s1[0]=='2' || s2[0]=='2') return string(1,'2');
      else if(s1[0]=='1' || s2[0]=='1') return string(1,'1');
      else return string(1,'0');
    }else{
      if(s1[0]=='0' || s2[0]=='0') return string(1,'0');
      else if(s1[0]=='1' || s2[0]=='1') return string(1,'1');
      else return string(1,'2');
    }
  }
  else{
    string s=solve(input.substr(1));
    if(s[0]=='0') s[0]+=2;
    else if(s[0]=='2') s[0]-=2;
    //cout<<" (--"<<s<<"--)"<<endl;
    return s;
  }

}

int main(){
  string input;
  while(cin>>input,input!="."){
    int cnt=0;
    for(int p=0;p<3;p++){
      for(int q=0;q<3;q++){
	for(int r=0;r<3;r++){
	  string s;
	  if((s=solve(replacePQR(p,q,r,input)))=="2") cnt++;
	  //cout<<s<<endl;
	}
      }
    }
    cout<<cnt<<endl;
    
  }
  return 0;
}

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

int main() {
  int N;
  int d[110];
  cin >> N;
  for (int i = 0; i < N; ++i) cin >> d[i];

  set<int> values;
  for (int i = 0; i < N; i++) {
    values.insert(d[i]);
  }
  cout << values.size() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    double a;
    cin >> a;
    cout << a*2.0*3.141592 << endl;

    return 0;

}


Measured memory_bytes: 3792
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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 INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
	if(!b)return 1;	if(b&1)return modpow(a,b-1,m)*a%m;
	int memo = modpow(a,b>>1,m);
	return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a;
  cin>>a;
  if(ketawa(a)==1)
    out(10);
  else
    out(ketawa(a));
}

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

int main() {
  int N, score = 0;
  cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for(int i = 0; i < N; i++) {
    if(i % 2 == 0){
      score += a.at(i);
    }else{
      score -= a.at(i);
    }
  }
  cout << score << endl;
}


Measured memory_bytes: 256
program main
  implicit none
  character(len=4) :: Ain
  integer :: A(4)
  integer :: ans(8)
  integer :: i
  read(*,*) Ain
  do i = 1,4
     read(Ain(i:i),*) A(i)
  end do
  ans(1) = A(1) + A(2) + A(3) + A(4)
  ans(2) = A(1) + A(2) + A(3) - A(4)
  ans(3) = A(1) + A(2) - A(3) + A(4)
  ans(4) = A(1) + A(2) - A(3) - A(4)
  ans(5) = A(1) - A(2) + A(3) + A(4)
  ans(6) = A(1) - A(2) + A(3) - A(4)
  ans(7) = A(1) - A(2) - A(3) + A(4)
  ans(8) = A(1) - A(2) - A(3) - A(4)

  do i = 1,8
     if (ans(i) == 7) then
        call output(i,a)
        stop
     end if
  end do
  stop

contains
  subroutine output(i,a)
    integer,intent(in) :: i
    integer,intent(in) :: a(4)
    select case(i)
    case(1)
       write(*,'(i0,"+",i0,"+",i0,"+",i0,"=7")') a
    case(2)
       write(*,'(i0,"+",i0,"+",i0,"-",i0,"=7")') a
    case(3)
       write(*,'(i0,"+",i0,"-",i0,"+",i0,"=7")') a
    case(4)
       write(*,'(i0,"+",i0,"-",i0,"-",i0,"=7")') a
    case(5)
       write(*,'(i0,"-",i0,"+",i0,"+",i0,"=7")') a
    case(6)
       write(*,'(i0,"-",i0,"+",i0,"-",i0,"=7")') a
    case(7)
       write(*,'(i0,"-",i0,"-",i0,"+",i0,"=7")') a
    case(8)
       write(*,'(i0,"-",i0,"-",i0,"-",i0,"=7")') a
    end select
  end subroutine output
end program main


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    ll H, N;
    cin >> H >> N;
    ll A[N], B[N];
    rep(i, N){
        cin >> A[i] >> B[i];
    }
    ll m[H+1];
    m[0] = 0;
    rep2(i, 1, H){
        m[i] = INF;
        rep(j, N){
            ll k = max(0ll, i-A[j]);
            m[i] = min(m[i], B[j]+m[k]);
        }
    }
    cout << m[H] << endl;
}

Measured memory_bytes: 384
N = int(input())
H = list(map(int, input().split()))

re = H[-1]
for i in range(N - 2, -1, -1):
  t = H[i]
  if t > re + 1:
    print("No")
    break
  if t < re + 1:
    re = t
else:
  print("Yes")

Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i = 0 ; i < n ; i ++){
        cin>>a[i];
        a[i]-=i+1;
    }
    sort(a.begin(),a.end());
    int v=a[n/2];
    long long int rez=0;
    for(int i = 0 ; i < n ; i ++){
        rez+=abs(a[i]-v);
    }
    cout<<rez;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
    #define int long long
    int X,Y,A,B,C,D,N,A5,K;
    string S,T;
    cin >> A >> B >> C >> K;
    int rs = 0;
    if(K<=A){
        rs = K;
    }else if(K<=(A+B)){
        rs = A;
    }else{
        rs = 2*A + B -K;
    }
    cout << rs << endl;
    
    
}

Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 200005
using namespace std;

int n, ans, c, l, r, a[N], b[N], t[N];
int main()
{
	int i, j, li, ri;
	cin >> n;
	for (i = 0; i < n; i++) scanf("%d", &a[i]);
	for (i = 0; i < n; i++) scanf("%d", &b[i]);
    for (i = 0; i < 30; i++) {
		c = 0;
		for (j = 0; j < n; j++) t[j] = b[j] % (1 << i + 1);
		sort(t, t + n);
        for (j = 0; j < n; j++) {
			r = (1 << i + 1) - a[j] % (1 << i + 1);
			l = r - (1 << i);
			if (l < 0) l += 1 << i + 1;
            li = lower_bound(t, t + n, l) - t;
            ri = lower_bound(t, t + n, r) - t;
            if (l < r) c += (ri - li) % 2;
            else c += (n - li + ri) % 2;
        }
		ans += c % 2 * (1 << i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.nextLine();

		String res = "Good";
		for(int i = 1; i < S.length(); i++) {
			if(S.charAt(i) == S.charAt(i - 1)) {
				res = "Bad";
				break;
			}
		}
		
		System.out.println(res);
		scan.close();
	}

}

Measured memory_bytes: 23508
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret


def solve():
    S = getS()
    k = getN()


    li = []
    for i in range(len(S)):
        for j in range(1, k + 1):
            if i + j > len(S):
                continue
            li.append(S[i:i+j])

    li = list(set(li))
    li.sort()
    print(li[k-1])
    # print(li)


def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 68952