akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <tuple>
using namespace std;

#include <sys/mman.h>
static char *_in_buf = 
(char*)mmap(NULL, 1 << 26, PROT_READ, MAP_PRIVATE, fileno(stdin), 0);
inline int read() {
  int p = 0, v = 0;
  while (*_in_buf < 48) (*_in_buf ++ == 45) && (v = 1);
  while (*_in_buf > 47 && *_in_buf < 58) p = p * 10 + *_in_buf ++ - 48;
  return v ? -p : p;
}

static char out_buf[100000];
static char *outf = out_buf;
inline void flush() {
  if (outf != out_buf)
    fwrite(out_buf, outf - out_buf, 1, stdout), outf = out_buf;
}
inline void Putchar(char x) {
  *outf ++ = x;
  (outf == out_buf + 100000) && (flush(), 0);
}

int n, q, ans[100005], dis[100005];
vector <tuple <int, int, int> > g[100005];

int par[100005], sz[100005];
int son[100005], dep[100005];
int ind[100005], top[100005], indx;
void dfs1(int u, int parent, int depth) {
  dep[u] = depth, par[u] = parent, sz[u] = 1;
  for (int i = 0; i < (int)g[u].size(); ++ i) {
    int v = get <0> (g[u][i]);
    if (v == parent) continue;
    dfs1(v, u, depth + 1), sz[u] += sz[v];
    if (sz[v] > sz[son[u]]) son[u] = v;
  }
}
void dfs2(int u, int topv) {
  top[u] = topv, ind[u] = ++ indx;
  if (son[u]) dfs2(son[u], topv);
  for (int i = 0; i < (int)g[u].size(); ++ i) {
    int v = get <0> (g[u][i]);
    if (v == par[u] || v == son[u]) continue;
    dfs2(v, v);
  }
}
inline int get_lca(int u, int v) {
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]])
      swap(u, v);
    u = par[top[u]];
  }
  if (dep[u] < dep[v]) return u;
  return v;
}

int dist[100005];
void dfs3(int u, int parent) {
  for (int i = 0; i < (int)g[u].size(); ++ i) {
    int v = get <0>(g[u][i]), w = get <2>(g[u][i]);
    if (v == parent) continue;
    dist[v] = dist[u] + w, dfs3(v, u);
  }
}

vector <tuple <int, int, int> > qry[100005];
int d[100005], cnt[100005];
void dfs4(int u, int parent) {
  for (int i = 0; i < (int)g[u].size(); ++ i) {
    int v = get <0>(g[u][i]), c = get <1> (g[u][i]), w = get <2>(g[u][i]);
    if (v == parent) continue;
    d[c] += w, cnt[c] ++;
    dfs4(v, u);
    d[c] -= w, cnt[c] --;
  }
  for (int i = 0; i < (int)qry[u].size(); ++ i) {
    int id = get <0>(qry[u][i]), c = get <1>(qry[u][i]);
    int t = get <2>(qry[u][i]), nowd = dis[id];
    int x = d[c], y = nowd * cnt[c];
    ans[id] += (y - x) * t;
  }
}

int main() {
  n = read(), q = read();
  for (int i = 1; i < n; ++ i) {
    int u = read(), v = read();
    int c = read(), d = read();
    g[u].emplace_back(v, c, d);
    g[v].emplace_back(u, c, d);
  }
  dfs1(1, 0, 1);
  dfs2(1, 1);
  dfs3(1, 0);
  for (int i = 1; i <= q; ++ i) {
    int c = read(); dis[i] = read();
    int u = read(), v = read();
    int lca = get_lca(u, v);
    ans[i] = dist[u] + dist[v] - 2 * dist[lca];
    qry[u].emplace_back(i, c, 1);
    qry[v].emplace_back(i, c, 1);
    qry[lca].emplace_back(i, c, -2);
  }
  dfs4(1, 0);
  for (int i = 1; i <= q; ++ i) {
    register char stk[20], top = 0;
    while (ans[i]) stk[top ++] = ans[i] % 10, ans[i] /= 10;
    while (top --) Putchar(stk[top] + 48);
    Putchar('\n');
  }
  flush();
  return 0;
}

Measured memory_bytes: 25400
#include <iostream>

using namespace std;

int rec(int n, int k){
    if(n == 1) return 1;
    return (k-1+rec(n-1,k))%n + 1;
}

int main(){
    int n,k,m;

    while(cin >> n >> k >> m){
        if((n|k|m) == 0) break;
        if(k==1){
            if(m==1){
                cout << n << endl;
            }else{
                cout << m-1 << endl;
            }
            continue;
        }
        int bias = m-k;
        while(bias < 0){
            bias += n;
        }
        int ret = (rec(n,k)+bias)%n;
        if(ret == 0) ret = n;
        cout << ret << endl;
    }
}

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

int n;

struct P{
	int *a;

	P(){
		a = new int[n+1];
		for(int i=1;i<=n;i++) a[i]=i;
	}

	int & operator[](int i){
		return a[i];
	}

	P operator*(P x){
		P t;
		for(int i=1;i<=n;i++) t[i] = x[a[i]];
		return t;
	}
}p,q;

P T(P p){
	P q;
	for(int i=1;i<=n;i++) q[p[i]]=i;
	return q;
}

P getPow(P x, int y){
	P res;
	while(y){
		if(y&1) res=res*x;
		x=x*x;
		y>>=1;
	}
	return res;
}

P gao(int k){
	P t = p*T(q)*T(p)*q;
	t = getPow(t, k/6);
	p = T(t)*p*t;
	q = T(t)*q*t;
	k %= 6;
	while(k--){
		t = T(p)*q;
		p=q; q=t;
	}
	return p;
}

int main(){
#ifdef DEBUG
	freopen("in","r",stdin);
#endif
	int K;
	scanf("%d%d",&n,&K);
	p=P(); q=P();
	K--;
	for(int i=1;i<=n;i++)
		scanf("%d",p.a+i);
	for(int i=1;i<=n;i++)
		scanf("%d",q.a+i);
	P res = gao(K);
	for(int i=1;i<=n;i++)
		printf("%d ",res[i]);
	return 0;
}


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

double dp[3300][3300];

int main() {
    int n;
    cin >> n;
    double p[3300] = {};
    rep(i,n) cin >> p[i+1];
    dp[0][0] = 1;  
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            dp[i][j] = 0;
            if (j-1 >= 0) dp[i][j] += dp[i-1][j-1] * p[i];
            dp[i][j] += dp[i-1][j] * (1 - p[i]);
        }
    }
    double ans = 0;
    for (int i = 0; i <= n; i++) {
        if (i > n-i) ans += dp[n][i];
    }
    printf("%.10lf\n", ans);
}

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



int main(){
    //入力  
    int N,Q;
    std::cin>>N;
    int* A = new int[N];
    int dic[100001]={};
    int i;
    for(i=0;i<N;i++){
        std::cin>>A[i];
    }
    std::cin>>Q;
    int* B = new int[Q];
    int* C = new int[Q];
    for(i=0;i<Q;i++){
        std::cin>>B[i]>>C[i];
    }

    //計算
    unsigned long long int wa=0;
    for(i=0;i<N;i++){
        dic[A[i]]+=1;
        wa=wa+A[i];
    }
    int tmp;
    for(i=0;i<Q;i++){ //S回目の進行
        tmp=dic[B[i]];
        dic[C[i]]+=tmp;
        dic[B[i]]=0;
        wa+=tmp*(C[i]-B[i]);  
        std::cout<<wa<<std::endl;    
    }
    delete[] A;
    delete[] B;
    delete[] C;
    return 0;

}



Measured memory_bytes: 4736
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    cout << max({a+a-1, a+b, b+b-1}) << endl;
}


Measured memory_bytes: 256
from collections import deque

N = int(input())
S = input()

patterns = ["SS", "SW", "WS", "WW"]

for pat in patterns:
    q = deque(list(pat))
    bef = q[0]
    cur = q[1]
    for i in range(1,N+1):
        aft = ""
        if (cur == "S" and S[i%N] == "o") or (cur == "W" and S[i%N] == "x"):
            aft = "S" if bef == "S" else "W"
        else:
            aft = "S" if bef == "W" else "W"
        q.append(aft)
        bef = cur
        cur = aft

    if q[0] == q[-2] and q[1]==q[-1]:
        for i in range(N):
            print(q.popleft(), end="")
        print()
        exit()

print(-1)

Measured memory_bytes: 5744
#include<stdio.h>
#include<string.h>
char s[50][50];
int n;
int i;
int f1(int x);
int f2(int x);
int f1(int x)
{
	int res = 0;
	int d = strlen(s[x]);
	i = x + 1;
	for (; i < n; i++)
	{
		if (strlen(s[i]) != d + 1)
			break;
		if (s[i][d] >= '0' && s[i][d] <= '9')
			res += s[i][d] - '0';
		if (s[i][d] == '+')
			res += f1(i);
		if (s[i][d] == '*')
			res += f2(i);
	}
	i--;
	return res;
}
int f2(int x)
{
	int res = 1;
	int d = strlen(s[x]);
	i = x + 1;
	for (; i < n; i++)
	{
		if (strlen(s[i]) != d + 1)
			break;
		if (s[i][d] >= '0' && s[i][d] <= '9')
			res *= s[i][d] - '0';
		if (s[i][d] == '+')
			res *= f1(i);
		if (s[i][d] == '*')
			res *= f2(i);
	}
	i--;
	return res;
}
int main()
{
	int k, j;
	int ans[10002];

	for (j = 0;; j++)
	{
		scanf("%d", &n);
		if (n == 0)
			break;
		for (k = 0; k < n; k++)
			scanf("%s", s[k]);
		if (n == 1)
		{
			ans[j] = s[0][0] - '0';
			continue;
		}
		if (s[0][0] == '+')
			ans[j] = f1(0);
		else
			ans[j] = f2(0);
	}
	for (k = 0; k < j; k++)
		printf("%d\n", ans[k]);
	return 0;
}


Measured memory_bytes: 2040
#include<bits/stdc++.h>
using namespace std;
#define int long long
int h;
void maxHeapify(int *A,int i){
  int l=i*2+1;
  int r=i*2+2;
  int largest;
  if(l<h&&A[l]>A[i]) largest=l;
  else largest=i;
  if(r<h&&A[r]>A[largest]) largest=r;
  if(largest!=i){
    swap(A[i],A[largest]);
    maxHeapify(A,largest);
  }
}
void insert(int *A,int x){
  int i=h++;
  A[i]=x;
  while(i&&A[(i-1)/2]<A[i]){
    swap(A[(i-1)/2],A[i]);
    i=(i-1)/2;
  }
}
int extract(int *A){
  int res=A[0];
  A[0]=A[--h];
  maxHeapify(A,0);
  return res;
}
int A[2222222];
signed main(){
  string s;
  while(cin>>s,s!="end"){
    if(s=="insert"){
      int x;
      cin>>x;
      insert(A,x);
    }
    if(s=="extract") cout<<extract(A)<<endl;
  }
  return 0;
}



Measured memory_bytes: 10856
#include<iostream>
using namespace std;
int n, i, j, a, b, x;
int v[5005];
long long d[5005][5005], s[5005][5005];
int main(){
    cin>> n >> a >> b;
    for(i = 1; i <= n; i++){
        cin>> x;
        v[x] = i;
    }
    for(i = 1; i <= n; i++){
        for(j = 0; j <= n + 1; j++){
            if(j <= v[i]){
                d[i][j] = s[i - 1][j] + b;
            }
            else{
                d[i][j] = s[i - 1][j] + a;
            }
            if(j == v[i]){
                d[i][j] = min(d[i][j], s[i - 1][j - 1]);
            }
            s[i][j] = d[i][j];
            if(j != 0){
                s[i][j] = min(s[i][j], s[i][j - 1]);
            }
        }
    }
    cout<< s[n][n + 1];
}


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

public class Main {

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        if(b>=a){
        System.out.println(a);
        }else{
            System.out.println(a-1);
        }
    }
}

Measured memory_bytes: 24276
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct TreeNode {
	int val;
	TreeNode *left, *right;
	TreeNode(int x) :val(x), left(NULL), right(NULL) {}
};

int main()
{
	//freopen("data_in.txt", "rb", stdin);
	string s;
	cin >> s;
	int n = s.size();
	bool ok = false;
	int t = n - 7;
	for (int i = 0; i < 7; ++i) {
		string tmp = s.substr(0, i) + s.substr(n - 7 + i);
		if (tmp == "keyence") {
			ok = true;
			break;
		}
	}
	if (ok) cout << "YES";
	else cout << "NO";
	return 0;
}


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

int main()
{
  ll a,ans;
  double b;
  scanf("%lld %lf",&a,&b);
  
  ans = (a*(ll)(b*100+.5))/100;
  
  printf("%lld\n",ans);
  return 0;
  
}

Measured memory_bytes: 3780
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
string s;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    s=s.c_str();
    bool a=false;
    bool b=false;
    if((s[0]=='0'&&s[1]!='0')||(s[0]=='1'&&(s[1]=='1'||s[1]=='2'))) a=true;
    if((s[2]=='0'&&s[3]!='0')||(s[2]=='1'&&(s[3]=='1'||s[3]=='2'))) b=true;
    if(a==true&&b==true){
        cout<<"AMBIGUOUS"<<"\n";
        return 0;
    }
    if(a==true){
        cout<<"MMYY"<<"\n";
        return 0;
    }if(b==true){
        cout<<"YYMM"<<"\n";
        return 0;
    }
    cout<<"NA"<<"\n";
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool Check(int a,int b,int c){
    
    if(a > c){
        
        if(a > b && b > c) return true;
        else return false;
    }
    else{
        if(a < b && b < c) return true;
        else return false;
    }
}
int main(void){
    
    int N,ans=0;
    cin >> N;
    int data[N];
    
    for(int i=0;i<N;i++) cin >> data[i];
    
    for(int i=0;i<N-3+1;i++) if(Check(data[i],data[i+1],data[i+2])) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cmath>
using namespace std;

int main() {
    long n, k, q;
    cin >> n >> k >> q;
    vector<long> a(q);
    for (int i = 0; i < q; i++) {
        cin >> a[i];
    }
    vector<long> ans(n);
    for (int i = 0; i < n; i++) {
        ans[i]=0;
    }
    for (int i = 0; i < q; i++) {
        ans[a[i]-1]++;
    }
    for (int i = 0; i < n; i++) {
        if (k-q+ans[i] > 0) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
}


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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(long long i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const double EPS = 1e-9;
const ll powll = 1LL<<1;

/*
while(!frag && cin >> a >>b, a|b)
*/

int main(void){
    char a; cin >> a;
    if(isupper(a)) cout << "A\n";
    else cout << "a\n";
}

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

string s;
long long ans, cnt;

int main(){
	ans=0;
	cnt=0;
	cin >> s;
	int sez=s.length();
	for (int i=0;i<sez;i++){
		if (i<sez-1 && (s[i]=='A' || s[i]=='T' || s[i]=='G' || s[i]=='C')) cnt++;
		else if (i==sez-1){
			if ((s[i]=='A' || s[i]=='T' || s[i]=='G' || s[i]=='C')) cnt++;
			ans=max(ans,cnt);
		}
		else{
			ans=max(ans,cnt);
			cnt=0;
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define LL long long
using namespace std;

int main () {
    //clock_t start = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    char a,b;
    cin >> a >> b;
    string s="",t="";
    for (int i=1;i<=b-'0';i++) s+=a;
    for (int i=1;i<=a-'0';i++) t+=b;
    cout << min(t,s) << endl;
    //cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=100010;
const ll mod=1e9+7;

int main(){
  ll a,v,b,w,t;
  cin >> a >> v >> b >> w >> t;
  ll dis = abs(a-b);
  ll V = v-w;
  if(dis>t*V){
    cout << "NO" << ln;
  } else {
    cout << "YES" << ln;
  }
  return 0;
}

Measured memory_bytes: 3636
if __name__ == '__main__':
  from itertools import permutations
  N = int(input())
  P = input()
  P = ''.join(P.split())
  Q = input()
  Q = ''.join(Q.split())
  
  base = ''
  for i in range(N):
    base += str(i+1)
  
  perm = sorted(''.join(chars) for chars in permutations(base))
  x = -1
  y = -1
  for idx, p in enumerate(perm):
    if P == p:
      x = idx
    if Q == p:
      y = idx
    if not (x == -1) and not (y == -1):
      break
  print(abs(x-y))


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

int main() {
  int H, W, N, A;
  cin >> H >> W >> N;
  vector<int> V;
  int now = 1;
  while (cin >> A) {
    while (A--) V.push_back(now);
    now++;
  }
  int v = 0;
  vector<vector<int>> ans(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      ans.at(i).at(j) = V.at(v), v++;
    }
  }
  for (int i = 0; i < H; i++) {
    if (i % 2) reverse(ans.at(i).begin(), ans.at(i).end());
  }
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (j != 0) cout << " ";
      cout << ans.at(i).at(j);
    }
    cout << "\n";
  }
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>

int main()
{
    int N=0;
    std::cin >> N;
    std::vector<std::vector<int>> D(N, std::vector<int>(2));;
    for (int i = 0; i < N; i++) {
        std::cin >> D[i][0] >> D[i][1];
    }

    int count=0;
    int flag = false;
    for (int i = 0; i < N; i++) 
    {
        if(D[i][0] == D[i][1])
        {
            count++;
            
        }
        else
        {
            count = 0;
        }
        if(count >= 3)
        {
                flag = true;
                break;
            }
    } 
    
    if(flag)
        std::cout<<"Yes"<<std::endl;
    else
        std::cout<<"No"<<std::endl;


   return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
//----
const int N=17;
const int MOD=1e9+7;
int dp[41][1<<N];
int n, x, y, z, mask, fbt;
ll ans;

int main(){
	scanf("%d%d%d%d", &n, &x, &y, &z);
	mask=(1<<N)-1;
	fbt=(1<<x-1)|(1<<x+y-1)|(1<<x+y+z-1);
	ans=1;
	rep(i, 0, n)ans=ans*10%MOD;
	dp[0][0]=1;
	rep(i, 0, n){
		rep(msk, 0, mask+1){
			if(!dp[i][msk])continue;
			rep(j, 1, 11){
				int nmsk=(msk<<j)|(1<<j-1);
				nmsk&=mask;
				if((nmsk&fbt)==fbt)continue;
				dp[i+1][nmsk]=(dp[i+1][nmsk]+dp[i][msk])%MOD;
			}
		}
	}
	rep(msk, 0, mask+1)
		ans=(ans-dp[n][msk]+MOD)%MOD;
	printf("%lld\n", ans);
	return 0;
}
/*
3 5 7 5
1
4 5 7 5
34
37 4 2 3
863912418
40 5 7 5
562805100
*/

Measured memory_bytes: 19328
#include <iostream>
#include <cmath>
using namespace std;
int main() {
	int n;
	while (cin >> n) {
		int ans = 0;
		for (int i = 0; i <= 9; i++)
			for (int j = 0; j <= 9; j++)
				for (int k = 0; k <= 9; k++)
					for (int l = 0; l <= 9; l++)
						if (i + j + k + l == n)
							ans++;
		cout << ans << endl;
	}
}


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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

bool comp(int a, int b){
    return (a<b);
}

int main(){
    int n; cin >> n;
    vector<int> a(n);
    int sum = 0;

    REP(i,0,n) cin >> a[i];
    REP(i,0,n-1){
        REP(j,i+1,n){
            sum+=a[i]*a[j];
        }
    }
    cout << sum << endl;
    return 0;
}

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

int main() {
    string m;
    string s1="s";
    string s2="es";
    cin>>m;
    int l =m.length();
    if (m[l-1]=='s')
    cout<<m.append(s2);
    else
    cout<<m.append(s1);
}

Measured memory_bytes: 3632
n, m, x = map(int, input().split())
l = list(map(int, input().split()))
left = 0
right = 0
i = 0
while i < x:
    if i in l:
        left += 1
    i += 1
j = n-1
while j > x:
    if j in l:
        right += 1
    j -= 1

print(min(left, right))

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

#define rep(i, x) for(int i=0;i<(x);i++)

int main(){
    unsigned long long N, A, B;
    cin >> N >> A >> B;
    unsigned long long sum = A + B;
    unsigned long long s = N / sum;
    unsigned long long amari = N % sum;
    unsigned long long blue = s * A;
    if(amari > A) {
        blue += A;
    } else {
        blue += amari;
    }
    cout << blue << endl;
    return 0;
}

Measured memory_bytes: 888
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {
    int N;
    float sum;
    float* money;
    char (* money_type)[4];
    const char* JPY = "JPY";
    if (scanf("%d", &N) != EOF) {
        money = malloc(sizeof(float)*N);
        money_type = malloc(sizeof(char*)*N);
        for (int i = 0; i < N; i++) {
            if (scanf("%f %s", &(money[i]), &(money_type[i])) != EOF) {
                if (!(strncmp(money_type[i], JPY, 3))) {
                    sum += money[i];
                } else {
                    sum += money[i]*380000.0;
                }
            }
        }
        printf("%g\n", sum);
    } else {
        return 1;
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define INF 1000000000000
using ll = long long;


int main(){
  int n;
  string s;
  cin >> n >> s;
  int ans = 1;
  rep1(i,n){
    if(s.at(i)!=s.at(i-1))ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
char ch[5000005];
int main(){
	scanf("%s",ch+1);
	int n=strlen(ch+1);
	int l=(n+1)/2,r=n/2+1,res=n/2,ff=l;
	if(ch[l]!=ch[r]){printf("%d",res);return 0;}
	while(ch[l]==ch[r]&&ch[l]==ch[ff]){
		++res;--l;++r;if(l==0)break;
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 384
import math

A, B, H, M = map(int, input().split())

angle1 = math.pi * 2 / 12.0 * (H + M / 60.0)
angle2 = math.pi * 2 / 60.0 * M

x1 = math.cos(angle1) * A
y1 = math.sin(angle1) * A

x2 = math.cos(angle2) * B
y2 = math.sin(angle2) * B

print(math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2))

Measured memory_bytes: 9604
from itertools import product
A,B,C,D,E,F=map(int, input().split())
ans = -float("inf")
mass = 0
sugarr = 0
for s, t in product(range(0, 31), repeat=2):
    water = 100*(A*s+B*t)
    if water > F or water == 0:
        continue
    up = min(F-water, E*(A*s+B*t))
    for u in range(0, up+1):
        if C*u > up:
            continue
        v = int((up-C*u)/D)
        if v < 0:
            continue
        sugar = C*u+D*v
        cons = sugar/(water+sugar)
        if cons > ans:
            ans = cons
            mass = water + sugar
            sugarr = sugar
print(mass, sugarr)

Measured memory_bytes: 67064
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

ll aa[100010],bb[100010],cc[300010];
int main(){
	int x,y,a,b,c;
	scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
	rep(i,0,a)scanf("%d",aa+i);
	rep(i,0,b)scanf("%d",bb+i);
	rep(i,0,c)scanf("%d",cc+i);
	sortdown(aa,a);
	sortdown(bb,b);
	rep(i,0,x)cc[c  +i]=aa[i];
	rep(i,0,y)cc[c+x+i]=bb[i];
	sortdown(cc,c+x+y);
	ll ans=0;
	rep(i,0,x+y)ans+=cc[i];
	printf("%lld",ans);
}

Measured memory_bytes: 6892
#include <iostream>

using namespace std;

int main() {

    int a, b;
    char op;
    
    while (1) {
        cin >> a >> op >> b;
        if (op == '?'){
            break;
        }else if (op == '+'){
            cout << a + b << endl;
        }else if (op == '-'){
            cout << a - b << endl;
        }else if (op == '*'){
            cout << a * b << endl;
        }else if (op == '/'){
            cout << a / b << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/
int main() {
    vector<vi> c(3);
    REP(i,3){
        ll ci1,ci2,ci3;
        cin>>ci1>>ci2>>ci3;
        c[i]=vi{ci1,ci2,ci3};
    }
    REP(i,c[0][0]+1){
        ll a1=i;
        ll b1=c[0][0]-a1;
        ll b2=c[0][1]-a1;
        ll b3=c[0][2]-a1;
        ll a2=c[1][1]-b2;
        ll a3=c[2][2]-b3;
        vi a=vi{a1,a2,a3};
        vi b=vi{b1,b2,b3};
        bool ok=true;
        REP(j,3)REP(k,3){
            if(c[j][k]!=a[j]+b[k]){
                ok=false;
                break;
            }
            if(!ok)break;
        }
        if(ok){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
  int A,B,H,M;
  double ans,a,b,x;
  scanf("%d %d %d %d",&A,&B,&H,&M);
  a=30*H+0.5*M;
  b=6*M;
  if(a>b) x=a-b;
  else x=b-a;
  ans=sqrt(A*A+B*B-2*A*B*cos(x/180*M_PI));
  printf("%.15f",ans);
  return 0;
}

Measured memory_bytes: 2600
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <numeric>
 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
string S,T;
vector<ll> so;


ll N,K,M;
ll r,s,p;
ll ans[100005][2];
ll TT[100005];

ll lmax(ll a,ll b){
    if(a>b){
        return a;
    }else{
        return b;
    }
}
int main() {
    cin >> N >> K;
    cin >> r >> s >> p;
    cin >> T;
    for(ll i=0;i<N;i++){
        if(T[i]=='r'){
            TT[i] = p;
        }
        if(T[i]=='s'){
            TT[i] = r;
        }
        if(T[i]=='p'){
            TT[i] = s;
        }
    }
    ll k=0;
    for(ll i=0;i<K;i++){
        if(i==0){
            ans[k][0] = 0;
            ans[k][1] = TT[i];
        }else{
            ans[k][0] = lmax(ans[k-1][1],ans[k-1][0]);
            ans[k][1] = lmax(ans[k-1][1],ans[k-1][0])+TT[i];
        }
        k++;
        for(ll j=i+K;j<N;j+=K){
            if(T[j]==T[j-K]){
                ans[k][1] = ans[k-1][0] + TT[j];
            }else{
                ans[k][1] = lmax(ans[k-1][1],ans[k-1][0]) + TT[j];
            }
            ans[k][0] = lmax(ans[k-1][1],ans[k-1][0]);
            k++;
        }
    }
    cout << lmax(ans[N-1][0],ans[N-1][1]) << endl;
    
}


Measured memory_bytes: 6076
//Compiler optimization
#pragma GCC optimize("Ofast")

//include
#include <bits/stdc++.h>
using namespace std;

//typedef
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<vl> mat;

//macro
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define each(x, v) for (auto &x : v)

//abbreviation
#define pb push_back
#define elif else if
#define mp make_pair
#define endl '\n'

//debug
#define debug(x) cerr << #x << ": " << x << endl

//const
const  ll INF = 1e18;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    ll n;cin >> n;
    cout << (1000-n%1000)%1000 << endl;

}

Measured memory_bytes: 3644
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<bool> ac(N, false);
    vector<int> wa(N, 0);
    for (int i = 0; i < M; i++) {
        int pi; string S;
        cin >> pi;
        pi--;
        cin >> S;
        if (S == "AC") {
            ac[pi] = true;
        }
        if (S == "WA" && !ac[pi]) {
            wa[pi]++;
        }
    }
    int correct = 0;
    int penalty = 0;
    for (int i = 0; i < N; i++) {
        if (ac[i]) {
          correct++;
          penalty += wa[i];
        }
    }
    cout << correct << " " << penalty << endl;
    return 0;
}



Measured memory_bytes: 3772
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int n;

void dfs(int k, string s, char first_unused_char) {
    if(k == n) {
        cout << s << "\n";
        return;
    }
    for(char c='a';c<first_unused_char;++c) {
        dfs(k+1, s+c, first_unused_char);
    }
    dfs(k+1, s+first_unused_char, char(first_unused_char+1));
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n;
    dfs(1, "a", 'b');
}


Measured memory_bytes: 1536
A,B=map(int, input().split())
h=w=100
ans=[['' for _ in range(w)] for __ in range(h)]
for i in range(h//2):
    for j in range(w):
        if i&1 and j&1 and A-1>0:
            ans[i][j]='.'
            A-=1
        else:
            ans[i][j]='#'
for i in range(h-1,h//2-1,-1):
    for j in range(w):
        if i&1 and j&1 and B-1>0:
            ans[i][j]='#'
            B-=1
        else:
            ans[i][j]='.'

print(h,w)
for r in ans:
    print(''.join(r))


Measured memory_bytes: 40176
#include <bits/stdc++.h>
#define int long long
#define fr first
#define sc second
using namespace std;
const int inf = 2e18 + 7;
const int mod = 1e9 + 7;
const int maxn = 3007;
signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < n; ++i) cin >> l[i];
  int ans = 0;
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j)
      for (int k = j + 1; k < n; ++k) {
        if (l[i] != l[j] && l[j] != l[k] && l[i] != l[k]
          && l[i] + l[j] > l[k] && l[i] + l[k] > l[j] && l[j] + l[k] > l[i])
          ++ans;
      }
  cout << ans;
}

Measured memory_bytes: 3616
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
typedef long long           ll;
#define REP(i, n)           for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)       for (ll i = m ; i < (ll)n ; ++i)
#define INF                 (ll)1e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef pair<ll, ll>	    P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
/* 最大公約数 */
ll gcd(ll a, ll b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}

/* 最小公倍数 */
ll lcm(ll a, ll b)
{
	ll gcdRes = gcd(a, b);
	return (a * (b / gcdRes));
}

int main()
{
	ll N, A, B, C, D;
	string S;
	cin >> N >> A >> B >> C >> D >> S;

	string ans = "No";
	A--; B--, C--, D--;

	ll endPos = max(C, D);
	for (ll i = A; i < endPos; i++) {
		if (S[i] == '#' && S[i + 1] == '#') {
			goto EXIT;
		}
	}
	
	if (C < D) {
		ans = "Yes";
		goto EXIT;
	}

	endPos = min((ll)N - 2, D);
	for (ll i = B; i <= endPos; i++) {
		if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') {
			ans = "Yes";
			goto EXIT;
		}
	}
	
EXIT:
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto __VA_ARGS__:(c))
using namespace std;
typedef long long ll;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int n;
	set<string> s;
	cin>>n;
	rep(i,0,n) {
		string t;
		cin>>t;
		s.insert(t);
	}
	cout<<sz(s)<<'\n';
}


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

int main(){
  string S,a1,a2;
  cin>>S;
  int count=2;
  for(int i=S.size()-2;i>0;i-=2){
      a1=S.substr(0,i/2);
      a2=S.substr(i/2,i/2);
      if(a1==a2){
          break;
      }
      count+=2;
  }  
  cout<<S.size()-count<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;



int main(){
    int n, cnt = 0;
    cin >> n;
    int p[n];
    for(int i = 0; i < n; i++){
         cin >> p[i];
    }   
    for(int i = 1; i<n-1; i++){
         if((p[i] > p[i-1] && p[i] < p[i+1]) || (p[i] < p[i-1] && p[i] > p[i+1])) cnt++;
    } 
    cout << cnt << endl;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int K,X;
    cin>>X>>K;
    for(int i=K-X+1;i<=K+X-1;i++){
        cout <<i<<" ";
    }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n #要素数
        self.parents = [-1] * n #親格納配列(親のときは下流の要素数のマイナスを返す)

    def find(self,x):
        if self.parents[x] < 0: #親のとき
            return x
        else:
            self.parents[x] = self.find(self.parents[x]) #再帰で親に繋ぎ変える
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y: #親が同じときスキップ
            return

        if self.parents[x] > self.parents[y]: #要素数が多いほうをxにする
            x, y = y, x

        self.parents[x] += self.parents[y] #xの要素数はyの要素数ぶん増える
        self.parents[y] = x #yをxの子にする

    def size(self, x): #xの属するグループの要素数
        return -self.parents[self.find(x)]

    def same(self, x, y): #同じグループか判定
        return self.find(x) == self.find(y)

    def members(self, x): #xの属するグループの要素一覧
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self): #根の一覧
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self): #グループ個数
        return len(self.roots())

    def all_group_members(self): #根とその要素の辞書配列
        return {r: self.members(r) for r in self.roots()}

    def __str__(self): #print用
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=map(int,input().split())
P=list(map(int,input().split()))
U=UnionFind(n)
for i in range(m):
    x,y=map(int,input().split())
    U.union(x-1,y-1)
ans=0
for i in range(n):
    if U.same(P[i]-1,i):
        ans+=1
print(ans)

Measured memory_bytes: 13940
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll MOD=1000000007;
const ll M=100005;
bool isPrime(long long x){
  if(x == 1)return 0;
  for(long long i = 2; i*i <= x; i++) if(x%i == 0) return 0;
  return 1;
}
int main(){
 ll q;cin>>q;
 vector<int> b(M);
 for(int i=1;i<=M;i+=2){
   if(isPrime(i)&&isPrime((i+1)/2))b[i]=1;
 }
 vector<ll>sum(M);
 for(int i=1;i<=M;i++)b[i+1]+=b[i];
 int l[q],r[q];
 rep(i,q){
   cin>>l[i]>>r[i];
 }
 rep(i,q){
   ll ans=0;
   ans=b[r[i]]-b[l[i]-1];
   cout << ans << endl;
 }

}

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

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

using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    sort(ALL(A),greater<>());
    vector<ll> e;
    rep(i,N){
        if(A[i]==A[i+1]&&i+1<N){
            e.push_back(A[i]);
            i++;
        }
    }
    if(e.size()>1)cout << e[0]*e[1] << endl;
    else cout << "0" << endl;
}

Measured memory_bytes: 1660
#include <iostream>
#include <vector>


int main(void){
    std::cin.tie(nullptr); std::cin.sync_with_stdio(false);
    int n; std::cin >> n; n -= 2;
    long long int a, b; std::cin >> a >> b;
    long long int B = 0; while(n--){ long long int x; std::cin >> x; B ^= x; }

    const long long int A = a + b;
    if(not ((A >= B) and (A - B) % 2 == 0)){ std::cout << "-1\n"; return 0; }

    long long int C = (A - B) / 2;
    //if(B & C){ std::cout << "-1\n"; return 0; }
    long long int res = 0;
    std::vector<long long int> wait(0);
    for(int i = 60; i >= 0; --i){
        const bool flagAnd = (C >> i) & 1;
        const bool flagXor = (B >> i) & 1;
        if(flagAnd){
            if(flagXor){ std::cout << "-1\n"; return 0; }
            res |= (1LL << i);
            if(res > a){ std::cout << "-1\n"; return 0; }
        }
        else{
            if(flagXor) wait.push_back(1LL << i);
        }
    }
    for(const long long int x : wait) if((res | x) <= a) res |= x;
    if(res == 0){ std::cout << "-1\n"; return 0; }
    std::cout << (a - res) << '\n';

    return 0;
}


Measured memory_bytes: 3664
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define L(i,u) for (int i=head[u]; i!=0; i=nxt[i])
#define rep(i,a,b) for (int i=a; i<=b; i++)
#define per(i,a,b) for (int i=a; i>=b; i--)
typedef long long ll;
using namespace std;
typedef pair<int,int> Pii;
typedef vector<int> vec;
inline void read(ll &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 30;
ll n,r;
int a[N],len;
int main() {
	read(n); r=n;
	while (n) {a[++len]=n%10; n/=10;}
	
	ll res=9*(len-1);
	
	bool flag=1;
	rep(i,1,len-1) if (a[i]!=9) flag=0;
	res+=a[len]-(flag==0);
	
	cout<<res;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    string s1, s2;
    cin >> s1 >> s1 >> s2;
    cout << "A" << s1[0] << "C" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    int a, b;
	
	if ((x - r >= 0) && (x + r <= W)) a = 1;
	else a = 0;
	
    if((y - r >= 0) && (y + r <= H)) b = 1;
    else b = 0;

    if(a && b == 1) printf("Yes\n");
    else printf("No\n");

    return 0;
}


Measured memory_bytes: 2148
#include<stdio.h>
#include<stdlib.h>

int compare_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int main(void){

    int N,X[101],i,distance_sum = 0,place,ans1=0,ans2 = 0;
 
    scanf("%d",&N);
    for(i = 0;i < N;i++){
        scanf("%d",&X[i]);
        distance_sum += X[i];
    }

    //qsort(X,N,sizeof(int),compare_int);

    place = distance_sum/N;
    //place = 20;
    for(i = 0;i < N;i++){
        ans1 += (X[i] - (place+1))*(X[i] - (place+1));
        ans2 += (X[i] - place)*(X[i] - place);
    }

    if(ans1 < ans2) printf("%d\n",ans1);
    else printf("%d\n",ans2);
    return 0;
}

Measured memory_bytes: 128
import sys

stdin = sys.stdin
inf = 1 << 60
mod = 1000000007

ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

h, w = na()
a = ncl(h)

for i in range(h):
    flag = True
    for j in range(w):
        if a[i][j] != '.':
            flag = False
    
    if flag:
        for j in range(w):
            a[i][j] = '$'

for j in range(w):
    flag = True
    for i in range(h):
        if a[i][j] != '.' and a[i][j] != '$':
            flag = False
    
    if flag:
        for i in range(h):
            a[i][j] = '$'

ans = []
for i in range(h):
    ans.append([])
    for j in range(w):
        if a[i][j] != '$':
            ans[i].append(a[i][j])

for i in range(len(ans)):
    if len(ans[i]) != 0:
        print(*ans[i], sep="")

Measured memory_bytes: 4724
#include <stdio.h> 
int main(void)
{
	int i, j, H, W;
	H = 1;
	W = 1;
	while(1)
	{
		scanf("%d %d", &H, &W);
		if ((H == 0) && (W == 0))
		{
			break;
		}
		for (i = 1;i <= H;i++)
		{
			for (j = 1;j <= W;j++)
			{
				if ((i + j) % 2 == 0)
				{
					printf("#");
				}
				if ((i + j) % 2 == 1)
				{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
N = int(input())
restaurants = []
for i in range(N):
    S, P = input().split(" ")
    restaurants.append([i+1, S, int(P)])

restaurants.sort(key=lambda x: x[2], reverse=True)
restaurants.sort(key=lambda x: x[1])

for i in restaurants:
    print(i[0])


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
long long mod = 1e9+7;
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
//////////////////////////////////

int main() {
    int a; cin >> a;
    string s; cin >> s;
    cout << (a>=3200?s:"red") << endl;
    return 0;
}




// EOF


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

using namespace std;

long long a[200000];
const long long T=1e18;

int main()
{
	int n=0;scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	sort(a+1,a+n+1);if(a[1]==0){puts("0");return 0;}
	__int128 x=1;
	for(int i=1;i<=n;i++)
	{
		x=x*a[i];if(x>T){puts("-1");return 0;}
	}
	printf("%lld",(long long)x);
}

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

int main(){
  int n, x;
  cin >> n >> x;
  vector<int> m(n);
  int M = x;
  int min = 1001;
  int a = 0;
  int i = 0;
  
  for(int i = 0; i<n; i++){
    cin >> m.at(i);
    M -= m.at(i);
    if(m.at(i) < min)
      min = m.at(i);
  }
  
  while(a <= M){
    i++;
    a = min*i;
  }
  
  cout << i - 1 + n << endl;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
a=[list(input()+'.') for _ in range(h)]
d=['.']*(w+1)
a.append(d)
x=1
i=0;j=0
a[0][0]='.'
while i!=h-1 or j!=w-1:
  if a[i+1][j]=='#':
    if a[i][j+1]=='#':
      x=0
      break
    else:
      i=i+1
      a[i][j]='.'
  else:
    if a[i][j+1]=='.':
      x=0
      break
    else:
      j=j+1
      a[i][j]='.'
if x==1:
  for k in range(h):
    if '#' in a[k]:
      x=0
      break
print('Possible' if x==1 else 'Impossible')

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    string S;
    cin >> S;

    for(int i = 1; i < S.size(); i++ ){
        if( S[i] == S[i-1] ){
            cout << "Bad" << endl;
            return 0;
        }
    }

    cout << "Good" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
		int a;
		scanf("%d",&a);
		if(a<1200)
			printf("ABC\n");
		else if(a<2800)
			printf("ARC\n");
		else
			printf("AGC");
    return 0;
}


Measured memory_bytes: 256
h, w=gets.split.map(&:to_i)
n=gets.to_i
a=gets.split.map(&:to_i)

c=Array.new(h){Array.new(w){0}}
l, r, d=0, 1, 2
nx=nil
i, j=0, 0
a.each.with_index(1) do |e, k|
  e.times do
    if nx==nil
      c[i][j]=k
      if w==1
        nx=d
      else
        nx=r
      end
    elsif nx==r
      j+=1
      c[i][j]=k
      nx=d if j+1==w
    elsif nx==d
      i+=1
      c[i][j]=k
      if w==1
        nx=d
      elsif j+1==w
        nx=l
      elsif j==0
        nx=r
      else
        raise
      end
    elsif nx==l
      j-=1
      c[i][j]=k
      nx=d if j-1<0
    else
      raise
    end
  end
end

c.each do |e|
  puts e.join(' ')
end


Measured memory_bytes: 2428
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,ll>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 2*1e5;
const int mod = 1e9+7;

vvll W;
ll w_min;
ll N, w_upper;

ll dfs(int n, int value, int sum, vint &x) {
    if (n == 3) {
        x[n] = N-sum;
        ll res = 0;
        ll weight = 0;
        rep(i,4) {
            if (x[i] > W[i].size()) return 0;
            weight += (w_min+i)*x[i];
        }
        if (weight > w_upper) return 0;
        rep(i,4)rep(j,x[i]) res += W[i][j];
        return res;
    }

    ll ans = 0;
    x[n] = value;
    for (int i = 0; i <= N-sum; i++) {
        ans = max(ans,dfs(n+1,i,sum+i,x));
    }
    return ans;

}

int main() {
    vint x(4);
    cin >> N >> w_upper;
    W.resize(4);
    rep(i,N) {
        int w, v; cin >> w >> v;
        if (i == 0) w_min = w;
        W[w-w_min].push_back(v);
    }
    rep(i,4) sort(rall(W[i]));
    ll ans = 0;
    rep(i,N+1) ans = max(ans,dfs(0,i,i,x));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;



int main(){
	ll n;
	cin >> n;
	if (n%2) cout << 2*n << endl;
	else cout << n << endl;
	return 0;
}


Measured memory_bytes: 256