akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author HARSHAD
 */

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

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

class DIslandsWar {
public:
	void solve(std::istream& in, std::ostream& out) {
		int n, m; in >> n >> m;
		vector<vector<int>> adj(n+1);
        f(i, m){
            int a, b; in >> a >> b;
            adj[a].push_back(b);
            adj[b].push_back(a);
        }
        set<int> s;
        int res = 0;
        rep(i, 1, n) adj[i].push_back(i);
        rep(i, 1, n){
            bool ok = s.find(i)==s.end();
            if(!ok) ++res, s.clear();
            for(int x: adj[i]) s.insert(x);
        }
        out << res;
	}
};


int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	DIslandsWar solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 10616
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<string>
#include<cmath>
#include<cassert>
#include<unordered_map>
using namespace std;

typedef long long ll;
typedef ll int__;
#define rep(i,j) for(int__ (i)=0;(i)<(j);(i)++)
#define repeat(i,j,k) for(int__ i=(j);i<(k);(i)++)
#define all(v) begin(v),end(v)

const int INF = 1<<30;

struct Circle{
  int x,y,r,c;
};


bool is_intersect(const Circle &c1,const Circle &c2){
  int dist2=pow(c1.x-c2.x,2)+pow(c1.y-c2.y,2);
  if(dist2>=pow(c1.r+c2.r,2))return false;
  return true;
}

int n;
vector<Circle> C;
vector< vector<bool> > is_I;

unordered_map<unsigned int,int> MEMO;


int rec(unsigned int bits){
  if(MEMO.find(bits)!=MEMO.end())return MEMO[bits];
  
  int ret=INF;
  vector<int> tops[4];
  rep(i,n){
    if(bits & (1<<i)){
      rep(j,i){
        if(bits & (1<<j)){
          if(is_I[i][j])goto BREAK;
        }
      }
      tops[C[i].c-1].push_back(i);
   BREAK:;
    }
  }

  rep(i,4){
    rep(j,tops[i].size()){
      rep(k,j){
        ret = min(ret,rec(bits & ~((1<<tops[i][j]) | (1<<tops[i][k]))));
      }
    }
  }

  if(ret==INF){
    ret=__builtin_popcount(bits);
  }
  return MEMO[bits]=ret;
}

int main()
{
  while(true){
    C.clear();
    is_I.clear();
    MEMO.clear();
    
    cin>>n;
    if(n==0)break;
    C.resize(n);
    is_I.resize(n,vector<bool>(n,false));
    
    rep(i,n){
      int x,y,r,c;
      cin>>x>>y>>r>>c;
      C[i]=(Circle){x,y,r,c};
    }
    rep(i,n){
      rep(j,n){
        is_I[i][j]=is_intersect(C[i], C[j]);
      }
    }
    unsigned int bits=0;
    rep(i,n)bits|=1<<i;
    cout<<n-rec(bits)<<endl;
  }
  return 0;
}

Measured memory_bytes: 42108
#include <iostream>

template <typename T , unsigned N>
auto findMax (T (& a) [N]) -> T
{
    auto res = a [0];
    for (auto && elem : a)
    {
        res = std::max (res , elem);
    }
    return res;
}

auto main () -> int
{
    int a [110] = {};
    int n;
    while (std::cin >> n)
    {
        ++ a [n];
    }
    auto m = findMax (a);
    for (auto i = 1; i <= 100; ++ i)
    {
        if (a [i] == m)
        {
            std::cout << i << std::endl;
        }
    }
}

Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main(){
    char c;
    int i;
    int count=0;
    for(i=0;i<4;i++){
        scanf("%c",&c);
        if(c=='2'){
            count=count+1;
        }
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

X = INT()
print("Yes" if X >= 30 else "No")


Measured memory_bytes: 10496
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    string s; cin >> s;
    vs div(4);
    div[0]="dream";
    div[1]="dreamer";
    div[2]="erase";
    div[3]="eraser";
    rep(i,4) reverse(all(div[i]));
    reverse(all(s));
    
    int index=0;
    while(index!=SZ(s)){
        bool can=false;
        rep(i,4){
            if(s.substr(index,div[i].size())==div[i]){
                can=true;
                index+=SZ(div[i]);
                break;
            }
        }
        if(!can){
            coutN;
            return 0;
        }
    }
    coutY;
}

Measured memory_bytes: 3764
import math

a, b, x = list(map(int, input().split()))
if a**2 * b / 2 < x:
    s = math.degrees(math.atan(2*(b/a-x/a**3)))
else:
    s = 90 - math.degrees(math.atan(2*x / (a*b**2)))
print(s)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,a,n) for (register int i=a;i<=n;i++)
#define per(i,a,n) for (register int i=n;i>=a;i--)
#define FOR(i,a,n,x) for (register int i=a;i<=n;i+=x)
#define ROF(i,a,n,x) for (register int i=n;i>=a;i-=x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define VI vector<int>
#define ll long long
#define ull unsigned long long
#define lowbit(x) ((x)&(-x))
#define mem(i, a) memset(i, a, sizeof(i))
#define sqr(x) ((x)*(x))
#define ls (p << 1)
#define rs (p << 1 | 1)
using namespace std;

template <typename T>

inline void read(T &X) {
  X = 0; char ch = 0; T op = 1;
  for(; ch > '9' || ch < '0'; ch = getchar())
    if(ch == '-') op = -1;
  for(; ch >= '0' && ch <= '9'; ch = getchar())
    X = (X << 3) + (X << 1) + ch - 48;
  X *= op;
}

const int INF = 0x3f3f3f3f;
const int MAXN =  + 5;

vector<ll> v;
queue<string> q;

ll ToLL(string &s) {
  int len = s.length();
  ll ret = 0;
  rep (i, 0, len-1) {
    ret = ret * 10 + (s[i]-'0');
  }
  return ret;
}

void init() {
  rep (i, 1, 9) {
    // cout << (char)(i + '0') << endl;
    string s = "";
    s += (char)(i + '0');
    // cout << s << endl;
    q.push(s);
    v.pb(i);
  }
 

  while (!q.empty()) {
    string tmp = q.front();
    q.pop();
    int len = tmp.length();
    if (tmp.length() == 10) continue; 
    string news;
    if (tmp[len-1] > '0') {
      news = tmp + (char)(tmp[len-1] - 1);
      v.pb(ToLL(news)), q.push(news);
      // cout << news << endl;
    }
    news = tmp + (char)(tmp[len-1]);
    v.pb(ToLL(news)), q.push(news);
    // cout << news << endl;
    if (tmp[len-1] < '9') {
      news = tmp + (char)(tmp[len-1] + 1);
      v.pb(ToLL(news)), q.push(news);
      // cout << news << endl;
    }
  }
}

int k;

int main() {
#ifdef WiLe
  freopen ("input.txt", "rt", stdin);
#endif

  init();
  // cout << v.size() << endl;
  sort(all(v));

  read(k);

  printf("%lld\n", v[k-1]);

#ifdef WiLe
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}
/*
# author : WiLe
# date : 2020/04/17
*/

Measured memory_bytes: 9072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main(){
  string s;
  cin >> s;
  if (s.size() % 2) {
      cout << "No" << endl;
      return 0;
  }
  for (int i = 0; i < s.size(); i++) {
      if (i % 2) {
          if (s.at(i) != 'i') {
              cout << "No" << endl;
              return 0;
          }
      }else {
          if (s.at(i) != 'h') {
              cout << "No" << endl;
              return 0;
          }
      }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
   long long int n,i,c=0;

    scanf("%lld",&n);
  while(n!=0)
  {
      i=n%10;
      if(i==7)
        c++;
      n/=10;
  }
  if(c==0)
    printf("No\n");
  else
    printf("Yes\n");
}


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

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

int main(void){
    int n,c,k,ans=0,first=0,count=0;
    scanf("%d%d%d",&n,&c,&k);
    int t[n];
    for (int i=0; i<n; i++){
        scanf("%d",&t[i]);
    }
    qsort (t,n,sizeof(int),sort); 
    for (int i=0; i<n; i++){
        if(first==0){
            first=t[i];
        }
        count++;
        if (t[i]>first+k){
            ans++;
            first=t[i];
            count=1;
        } else if (count==c){
            ans++;
            first=0;
            count=0;
        }
    }
    if (count!=0){
        ans++;
    }
    printf ("%d\n",ans);
	return 0 ;
}

Measured memory_bytes: 892
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 3);
  (v[0], v[1], v[2])
}

const M: usize = 1_000_000_000;
fn main() {
    let (n, k, s) = read_touple::<usize>();
    let mut ans = Vec::new();

    for _ in 0..k {
      ans.push(s);
    }

    for _ in k..n {
      if s < M {
         ans.push(s+1);
      } else {
         ans.push(s-1);
      }
    }

    for i in 0..n {
      print!("{} ", ans[i]);
    }
}


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

int main () {
  vector<vector<int>>a(3,vector<int>(3));
  bool cnt =false;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>a[i][j];
    }
  }
  int n;
  cin>>n;
  vector<int>b(n);
  for(int i=0;i<n;i++){
    cin >>b[i];
  }

  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<n;k++){
        if(a[i][j] ==b[k])a[i][j] =1;
      }
    }
  }

  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
    if(a[0][0] ==1 &&a[1][1]==1 &&a[2][2]==1)cnt=true;
    if(a[2][0] ==1 &&a[1][1]==1 &&a[0][2]==1)cnt=true;
    if(a[0][0] ==1 &&a[0][1]==1 &&a[0][2]==1)cnt=true;
    if(a[1][0] ==1 &&a[1][1]==1 &&a[1][2]==1)cnt=true;
    if(a[2][0] ==1 &&a[2][1]==1 &&a[2][2]==1)cnt=true;
    if(a[0][0] ==1 &&a[1][0]==1 &&a[2][0]==1)cnt=true;
    if(a[0][1] ==1 &&a[1][1]==1 &&a[2][1]==1)cnt=true;
    if(a[0][2] ==1 &&a[1][2]==1 &&a[2][2]==1)cnt=true;
    }
  }

  if(cnt ==true){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
return 0; 
}


Measured memory_bytes: 256
import sys
import copy
R, C, K = map(int, input().split())
item = [[0] * (C + 1) for _ in range(R + 1)]  # dp配列と合わせるために, 0行目, 0列目を追加している.
for s in sys.stdin.readlines():
    r, c, v = map(int, s.split())
    r -= 1
    c -= 1
    item[r][c] = v
    
dp0 = [[0] * (C+1) for r in range(R+1)]
dp1 = [[0] * (C+1) for r in range(R+1)]
dp2 = [[0] * (C+1) for r in range(R+1)]
dp3 = [[0] * (C+1) for r in range(R+1)]
 
for r in range(R):
   for c in range(C):
      dp3[r][c] = max(dp3[r][c], dp2[r][c] + item[r][c])
      dp2[r][c] = max(dp2[r][c], dp1[r][c] + item[r][c])
      dp1[r][c] = max(dp1[r][c], dp0[r][c] + item[r][c])
      dp1[r][c+1] = max(dp1[r][c], dp1[r][c+1])
      dp2[r][c+1] = max(dp2[r][c], dp2[r][c+1])
      dp3[r][c+1] = max(dp3[r][c], dp3[r][c+1])
      dp0[r+1][c] = max(dp0[r+1][c], dp1[r][c])
      dp0[r+1][c] = max(dp0[r+1][c], dp2[r][c])
      dp0[r+1][c] = max(dp0[r+1][c], dp3[r][c])
ans = max(dp0[R-1][C-1], dp1[R-1][C-1])
ans = max(ans, dp3[R-1][C-1])
ans = max(ans, dp2[R-1][C-1])
print(ans)

Measured memory_bytes: 432404
#include <iostream>
#include <string>
using namespace std;
int main( void )
{
  ios::sync_with_stdio(false);
  string S;
  string T = "CODEFESTIVAL2016";
  cin >> S;
  int ret = 0;
  for( int i=0; i<S.size(); i++ ){
    if( S[i] != T[i] ) ret++;
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

ll mod(ll a){
  return (a % 1000000007);
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll nCr(ll n,ll r){
  if(r == 1) return n;
  else if(r == 0) return 1;
  else return nCr(n-1,r-1)*n/r;
}

int main(){
  ll n; cin >> n; string ans ="";
  
  if(n == 0){
    cout << 0 << endl;
    return 0;
  }
  else{
    
    while(n != 0){
      if(n % 2 == 0){
        ans += "0";
        n /= -2;
      }
      else{
        ans += "1";
        n = (n-1) / -2;
      }
    }
    
    for(ll i = ans.size()-1; i >= 0; i--){
      cout << ans[i];
    }
    
    cout << endl;
  }
  
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long LL;
#define F(i) for(int i=0;i<n;i++)
int main(){
	int n;
	cin>>n;
	int r=0;
	for(int i=1;i<=n;i++){
		int c=0;
		for(int j=1;j<=i;j++)if(i%j==0)c++;
		if(i%2==1&&c==8)r++;
	}
	cout<<r;
	return 0;
}


Measured memory_bytes: 504
a,b,k=map(int,input().split())
temp=0
for i in reversed(range(1,(min(a,b))+1)):#a,bそれ自身も一番目に大きいa,bを割り切る生整数になりうる点に注意
    if a%i==0 and b%i==0:
        temp=temp+1
        if temp==k:
            print(i)
            exit()

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

int digit(int a)
{
  int cnt = 0;
  
  while(1)
    { 
      a /= 10;
      cnt++;
      if(!a) break;
    }
  return cnt;
}
int main(){
  int a,b;

  while(scanf("%d%d",&a,&b) != EOF)
    {
      int n;
      int sum = a + b;
      
      n = digit(sum);
      
      cout << n << endl;
    }
  return 0;
}



Measured memory_bytes: 3144
// import chie template :) {{{
import std.stdio,
       std.algorithm,
       std.array,
       std.string,
       std.math,
       std.conv,
       std.range,
       std.container,
       std.bigint,
       std.ascii,
       std.typecons;
// }}}
// tbh.scanner {{{
class Scanner {
  import std.stdio;
  import std.conv : to;
  import std.array : split;
  import std.string : chomp;

  private File file;
  private dchar[][] str;
  private uint idx;

  this(File file = stdin) {
    this.file = file;
    this.idx = 0;
  }

  private dchar[] next() {
    if (idx < str.length) {
      return str[idx++];
    }

    dchar[] s;
    while (s.length == 0) {
      s = file.readln.chomp.to!(dchar[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)() {
    return next.to!(T);
  }

  T[] nextArray(T)(uint len) {
    T[] ret = new T[len];

    foreach (ref c; ret) {
      c = next!(T);
    }

    return ret;
  }
}
// }}}

void main() {
  auto cin = new Scanner;
  long n = cin.next!long, m = cin.next!long;
  if (n == 1 && m == 1) {
    writeln(1);
  } else if (min(n, m) == 1) {
    writeln(n * m - 2);
  } else {
    writeln(n * m - n * 2 - m * 2 + 4);
  }
}


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

typedef long long int ll;

int main()
{
    ll n;
    cin >> n;
    vector<string> s(n);
    for(ll i = 0;i < n;i++){
        cin >> s[i];
    }
    ll ac, wa, tle, re;

    ac = wa = tle = re = 0;
    for(ll i = 0;i < n;i++){
        if(s[i] == "AC"){
            ac++;
        }
        else if(s[i] == "WA"){
            wa++;
        }
        else if(s[i] == "TLE"){
            tle++;
        }
        else{
            re++;
        }
    }

    cout << "AC x " << ac << "\n";
    cout << "WA x " << wa << "\n";
    cout << "TLE x " << tle << "\n";
    cout << "RE x " << re << "\n";

    return 0;
}

Measured memory_bytes: 6424
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

long long calc(long long money, vector<pair<int, int>> AB){
    if((int)AB.size() == 0){
        return money;
    }
    else if((int)AB.size() == 1){
        auto temp = AB[0];
        long long plus = (money / temp.first) * temp.second;
        return money + plus;
    }
    else if((int)AB.size() == 2){
        long long ret = 0;
        auto temp = AB[0];
        long long tempSum = 0;
        long long tempPlus = 0;
        for(int i = 0; i <= money; i++){
            if(tempSum > money){
                break;
            }
            auto temp2 = AB[1];
            long long rest = money - tempSum;
            long long plus = tempPlus + (rest / temp2.first) * temp2.second;

            ret = max(ret, plus);
            tempSum += temp.first;
            tempPlus += temp.second;
        }

        return money + ret;
    }
    else{
        long long ret = 0;
        auto temp = AB[0];
        long long tempSum = 0;
        long long tempPlus = 0;
        for(int i = 0; i <= money; i++){
            if(tempSum > money){
                break;
            }
            auto temp2 = AB[1];
            long long tempSum2 = tempSum;
            long long tempPlus2 = tempPlus;

            for(int j = 0; j <= money; j++){
                if(tempSum2 > money){
                    break;
                }
                auto temp3 = AB[2];
                long long rest = money - tempSum2;
                long long plus = tempPlus2 + (rest / temp3.first) * temp3.second;

                ret = max(ret, plus);

                tempSum2 += temp2.first;
                tempPlus2 += temp2.second;
            }
            tempSum += temp.first;
            tempPlus += temp.second;
        }

        return money + ret;
    }
}

int main(){

    int N;
    cin >> N;
    vector<int> A(3);
    vector<int> B(3);

    for(int i = 0; i < 3; i++){
        cin >> A[i];
    }

    for(int i = 0; i < 3; i++){
        cin >> B[i];
    }

    vector<pair<int, int>> AB;
    vector<pair<int, int>> BA;

    for(int i = 0; i < 3; i++){
        if(A[i] > B[i]){
            BA.push_back(make_pair(B[i], A[i] - B[i]));
        }
        else if(B[i] > A[i]){
            AB.push_back(make_pair(A[i], B[i] - A[i]));
        }
    }

    long long temp = calc(N, AB);
    long long ans = calc(temp, BA);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define cs const 
#define int long long
#define low(i) (i&(-i))
#define mid ((l+r)>>1)
#define ls (now<<1)
#define rs (now<<1|1)
#define par pair<int,int>
#define mp make_pair
#define fr first 
#define se second
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define drep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])
cs int base = 233;
cs int ff = 2e6+1;
cs int mod = 1e9+7;
cs int inf = 1e9+1;
int n, x, y, ans[ff];
int fir[ff], nex[ff], to[ff], tot;
void add(int x, int y)
{
	nex[++tot] = fir[x];
	fir[x] = tot;
	to[tot] = y;
}
int ksm(int a, int b, int ha = 1) 
{
    while (b) 
	{
        if (b & 1)
            ha = ha * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return ha;
}
int inv(int x) { return ksm(x, mod-2) % mod; }
int siz[ff], f[ff], u, v;
void dfs1(int now, int las)
{
	siz[now] = 1;
	fore(i, now)
		if( to[i] != las )
			dfs1(to[i], now), siz[now] += siz[to[i]];
	f[1] = ( f[1] * siz[now] ) % mod;
}
void dfs2(int now, int las)
{
	if( now != 1 ) 
		f[now] = f[las] * ( n - siz[now] ) % mod * inv(siz[now]) % mod;
	fore(i, now)
		if( to[i] != las )
			dfs2(to[i], now);
}
void init()
{
	cin >> n;
	int ps = 1;
	rep(i, 1, n-1)
		scanf("%lld %lld", &u, &v), add(u, v), add(v, u), ps = ps * i % mod;
	ps = ps * n % mod;
	f[1] = 1; dfs1(1, 0); dfs2(1, 0);
	rep(i, 1, n)
		cout << ( inv(f[i]) * ps ) % mod << endl;
}
signed main()
{
	int T = 1;
	while(T--) 
		init();
} 

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

int n, a, b, ca, cb;

int main()
{
	while (cin >> n && n > 0) {
		a = b = 0;
		for (int i = 0; i < n; i++) {
			cin >> ca >> cb;
			if (ca > cb)
				a += ca + cb;
			else if (ca < cb)
				b += ca + cb;
			else {
				a += ca;
				b += cb;
			}
		}
		cout << a << " " << b << endl;
	}
	return 0;
}

Measured memory_bytes: 3000
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

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


#define    boost        ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define    nl           "\n"
#define    ll           long long
#define    pb           push_back
#define    mpr          make_pair
#define    fr(i,a,n)   for(ll i=a;i<n;++i)
#define    fr0(i,n)     for(ll i=0;i<n;++i)
#define    pii          pair<ll, ll>
#define    mem(a)       memset(a,0,sizeof(a))
const ll mod = 1000000007;

void fio()
{
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
}

template<typename T> void TIME(T start, T end)
{
#ifndef ONLINE_JUDGE
    double time_taken =  chrono::duration_cast<chrono::nanoseconds>(end - start).count();
    time_taken *= 1e-9;
    cout << "\nExecuted in: " << fixed
         << time_taken << setprecision(9);
    cout << " sec";
#endif
}



void solve(){

    // std::vector<int> v;
    // for(int i=0;i<1;i++)
    // {
    //     int x;
    //     cin>>x;
    //     v.push_back(x);

    // }

    ll n;
    cin>>n;
    ll m = pow(10,9)+7;
    ll a[n], pre[n], sum=0,ans=0;
    pre[n-1]=0;

    for(int i=0;i<n;i++)
            cin>>a[i];

    for(int i=n-2;i>=0;i--){
        pre[i]= (pre[i+1]+a[i+1]+m)%m;
        // cout<<pre[i]<<' ';
    }
    // cout<<'\n';

    for(ll i=0;i<n-1;i++){
        ll temp = ( (a[i]*pre[i]) +m )%m;
        ans= (ans+temp+m)%m;
    }

    cout<<ans;







}

int main()
{
    //auto start = chrono::high_resolution_clock::now();
    boost;
    fio();
    ll t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    //auto end = chrono::high_resolution_clock::now();
    //TIME(start, end);
    return 0;
}

Measured memory_bytes: 6744
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
#define MOD 1000000007

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

    ll ng=0,ok=1e10,mid;
    ll cnt;
    while(abs(ok-ng)>1){
        mid=(ok+ng)/2;
        cnt=0;
        for(int i=0;i<n;i++){
            cnt+=(a[i]+mid-1)/mid;
            cnt--;
        }
        if(cnt<=k) ok=mid;
        else ng=mid;
    }
    cout << ok  << endl;

    return 0;
}

Measured memory_bytes: 4756
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;
const int mod = 1000000007;


int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  ll ans=0;
  for(int i=0; i<60; i++){
    ll count_1=0;
    for(int j=0; j<N; j++){
      if(A[j] & (1LL<<i)){
        count_1++;
      }
    }
    ll count_0=(N-count_1);
    ll sum;
    sum = (count_1*count_0);
    for(int j=i; j>0; j--){
      sum = (sum*2)%mod;
    }
    ans = (ans+sum)%mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

void findPrime(int N, vector<bool>& isPrime)
{
    isPrime.assign(N+1, true);
    isPrime[0] = isPrime[1] = false;
    for(int i=2; i*i<=N; i++){
        if(isPrime[i]){
            for(int j=i; i*j<=N; j++){
                isPrime[i*j] = false;
            }
        }
    }
}

const int MAX = 100000;

int main()
{
    vector<bool> isPrime;
    findPrime(MAX, isPrime);

    vector<int> cnt(MAX+1, 0);
    for(int i=1; i<=MAX; ++i){
        cnt[i] = cnt[i-1];
        if(i % 2 != 0 && isPrime[i] && isPrime[(i+1)/2])
            ++ cnt[i];
    }

    int q;
    cin >> q;
    while(--q >= 0){
        int l, r;
        cin >> l >> r;
        int ans = cnt[r] - cnt[l-1];
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
N = int(input())
c = input()
left = 0
right = len(c)-1
ans = 0
while left < right:
    while left < len(c):
        if c[left] == "W":
            break
        left += 1
    while right > -1:
        if c[right] == "R":
            break
        right -= 1
    if left < right:
        ans += 1
    left += 1
    right -= 1
print(ans)

Measured memory_bytes: 9480
arr = readlines
a500 = arr[0].to_i
b100 = arr[1].to_i
c50 = arr[2].to_i
x = arr[3].to_i
count = 0

51.times do |a|
  51.times do |b|
    51.times do |c|
      if( a <= a500 && b <= b100 && c <= c50)
	    r = 500*a + 100*b + 50*c
        if(r == x) 
	        count += 1 
        end
      end
    end
  end
end
puts count

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

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        
        int[] arr = {a, b, c};
        Arrays.sort(arr);
        
        System.out.println(String.format("%1$s %2$s %3$s", arr[0], arr[1], arr[2]));
        
    }
}


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

int main(){
	int N,M,C;
	cin>>N>>M>>C;
	vector <int> A(M);
	int count =0;
	int a;
	int part=0;
	vector<int> B(M);
	for(int i=0;i<M;i++){
		cin >> B.at(i);
	}
	
	for (int i=0;i<N;i++){
		
		for (int i=0;i<M;i++){
			cin >> a;
			part+=B.at(i)*a;
		}
		part+=C;
		
		if(part>0){
			count++;
		}
		part=0;
	}
	
	cout <<count<<endl;
}

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

using namespace std;
struct Node {
    int k;
    Node *p, *l, *r;
};
Node *NIL, *root;
void insert(int key) {
    Node *parent = NIL;
    Node *node = root;
    Node *target = (Node *)malloc(sizeof(Node));
    target->k = key;
    target->l = NIL;
    target->r = NIL;

    while(node != NIL) {
        parent = node;
        if(target->k < node->k) {
            node = node->l;
        } else {
            node = node->r;
        }
    }
    target->p = parent;
    if(parent == NIL) {
        root = target;
    } else {
        if(target->k < parent->k) {
            parent->l = target;
        } else {
            parent->r = target;
        }
    }
}
void inorder(Node *node) {
    if(node->l != NIL) {
        inorder(node->l);
    }
    printf(" %d", node->k);
    if(node->r != NIL) {
        inorder(node->r);
    }
}
void preorder(Node *node) {
    printf(" %d", node->k);
    if(node->l != NIL) {
        preorder(node->l);
    }
    if(node->r != NIL) {
        preorder(node->r);
    }
}
bool find(int key){
	Node *node = root;
	while(node != NIL){
		if(key < node->k){
			node = node->l;
		}else if(key > node->k){
			node = node->r;
		}else{
			return true;
		}
	}
	return false;
}
int main() {
    int n, key;
    string com;
    NIL = (Node *)malloc(sizeof(Node));
    root = (Node *)malloc(sizeof(Node));
	root = NIL;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> com;
        if(com == "print") {
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
        } else {
            scanf("%d", &key);
            if(com == "find") {
				if(find(key)){
					printf("yes\n");
				}else{
					printf("no\n");
				}
            } else if(com == "insert") {
                insert(key);
            }
        }
    }
}


Measured memory_bytes: 22020
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

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

    if(n%500 <= a) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int book[1000+100];
int main()
{
    memset(book,0,sizeof(book));
    int x,n;
    cin>>x>>n;
    for(int i=1;i<=n;++i)
    {
        int t;cin>>t;
        book[t] = 1;
    }

    for(int i=x;i<=1000000;++i)
    {
        int t=i;
        bool flag = 1;
        while(t)
        {
            if(book[t%10]==0) t/=10;
            else {flag = 0;break;}
        }
        if(flag == 1) {cout<<i<<endl;break;}
    }
}


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

using namespace std;

int main() {
  string s;
  unsigned long long K;

  cin >> s >> K;

  for(int i = 0; i < s.size(); i++) {
    if(s[i] == 'a') continue;
    int t = 'z' - s[i] + 1;
    if(t <= K) {
      s[i] = 'a';
      K -= t;
    }
  }

  if (K != 0) {
    s[s.size() - 1] += K % 26;
  }

  cout << s << endl;
}


Measured memory_bytes: 512
# -*- coding:utf-8 -*-
import numpy as np

N,K = map(int,raw_input().split())

V = map(int,raw_input().split())
V = np.array(V)
ans = 0

for l in xrange(K+1):
    for m in xrange(K+1-l):
        if (l+m) > N:
            continue
        d = K-l-m
        now = 0
        s = np.array([])
        for i in xrange(l):
            now += V[i]
            s = np.append(s,V[i])
        for i in xrange(m):
            now += V[N-i-1]
            s = np.append(s,V[N-i-1])
        s = np.sort(s)
        for i in xrange(d):
            if i>=s.size:
                break
            if s[i]>0:
                break
            now -= s[i]
        
        if ans < now:
            ans = now

print int(ans)


Measured memory_bytes: 19148
import kotlin.math.abs
import kotlin.math.ceil
import kotlin.math.floor
import kotlin.math.min

fun main() {
    nextInt()
    val values = nextLongList().mapIndexed { index, l -> l - index.plus(1) }
    val mid = values.sorted().let {
        if (it.size % 2 == 1) {
            it[it.size / 2].toDouble()
        } else {
            (it[it.size / 2] + it[it.size / 2 - 1]).toDouble() / 2
        }
    }
    println(
        min (
            values.map {
                abs(it - floor(mid).toLong())
            }.sum(),
            values.map {
                abs(it - ceil(mid).toLong())
            }.sum()
        )
    )
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }
inline fun <reified T> sized2DArray(row: Int, column: Int, default: T) = Array(row) { Array(column) { default } }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

fun gcd(x: Int, y: Int): Int {
    fun innerGcd(x: Int, y: Int): Int {
        return if (x % y == 0) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

fun gcd(x: Long, y: Long): Long {
    fun innerGcd(x: Long, y: Long): Long {
        return if (x % y == 0L) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

// classes
class UnionFindTree(val size: Int) {
    private val r = sizedArray(size, -1)
    fun root(x: Int): Int {
        if (r[x] < 0) return x
        return root(r[x])
    }

    fun unite(x: Int, y: Int) {
        var rx = root(x)
        var ry = root(y)
        if (rx == ry) return
        if (r[rx] > r[ry]) {
            rx = ry.also { ry = rx }
        }
        r[rx] += r[ry]
        r[ry] = rx
    }

    fun size(x: Int) = -r[root(x)]

    override fun toString(): String {
        return r.joinToString(separator = ", ")
    }
}

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

typedef long long ll;

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,l,n) for(int i=(l);i<(n);i++)

int main(){
    int x;
    ll happy;
    cin >> x;
    int mod = x % 500;
    happy = (x/500)*1000+5*(mod/5);
    cout << happy << endl;
    return 0;
}


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

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

bool judge(vi &a, int i, int m) {
  if (!m) return true;
  if (i == (int)a.size() - 1) return m - a[i] == 0;

  return judge(a, i + 1, m - a[i]) || judge(a, i + 1, m);
}

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

  vi a(n);
  rep(i, n) cin >> a[i];

  cin >> q;
  rep(i, q) {
    int m;
    cin >> m;

    cout << (judge(a, 0, m) ? "yes" : "no") << endl;
  } 
}



Measured memory_bytes: 3108
N = gets.to_i
a = gets.scan(/./).map{|i|i.to_i - 1}
while a.size > 1
    l = 2 ** Math.log2(a.size).floor
    s = a[0, l]
    c1 = s.count(1)
    c2 = s.count(2) % 2
    r = []
    (a.size - l + 1).times{|i|
        if c2 == 1 and c1 == 0
            r << 2
        else
            r << (c1 % 2)
        end
        case a[i]
        when 1
            c1 -= 1
        when 2
            c2 = (c2 + 1) % 2
        end
        case a[i + l]
        when 1
            c1 += 1
        when 2
            c2 = (c2 + 1) % 2
        end
    }
    a = r
end
puts a[0]


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  long long n;
  cin >> n;
  vector<long long> timetonextst(n);
  vector<long long> firsttrain(n);
  vector<long long> cycle(n);
  for(long long i = 0; i < n-1; i++){
    cin >> timetonextst[i] >> firsttrain[i] >> cycle[i];
  }

  for(long long i = 0; i < n; i++){
    if(i == n-1){
      cout << 0 <<endl;
      return 0;
    }
    long long ans = 0;
    ans += firsttrain[i] + timetonextst[i];
    for(long long j = i + 1; j < n -1; j++){
      if(ans <= firsttrain[j]){
        ans = firsttrain[j];
      } else{
        if(ans % cycle[j] != 0){
          ans += cycle[j] - ans % cycle[j];
        }
      }
      ans += timetonextst[j];
    }
    cout << ans <<endl;
  }
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long int
#define ff first
#define ss second
#define S size()
#define mod (ll)(1e9+7)
#define mset(a,k) memset(a,k,sizeof(a))
#define fr(i, x, y) for ( ll i = x; i < y;i++)
#define dr(i, x, y) for ( ll i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define pqueue priority_queue<ll>
#define piqueue priority_queue<ll,vll ,greater<ll>>
#define mapcl map<char,ll>
#define mapll map<ll,ll>
#define mapsl map<string,ll>
#define vi vector<ll>
#define vs vector<string>
#define vb vector<bool>
#define psi pair<string,ll>
#define pii pair<ll,ll>
#define piii pair<ll,pii>
#define vii vector<pii>
#define vvi vector<vi>
#define vvii vector<vii>
using namespace std;
void fast() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}
//----------------------------------------FUNCTIONS-------------------------------------
ll gcd(ll x, ll y )						{if (y == 0) return x; return gcd(y, x % y);}
ll lcm(ll a, ll b)						{return (a * b) / gcd(a, b);}
const ll MAXN = (ll)(1 * 1e6 + 5 );
void solve()
{
	string s;
	cin>>s;
	ll n = s.S;
	if(s[n-1]=='s')
	{
	   fr(i, 0, n) cout << s[i];
		cout << "es\n";
	}
	else 
	{
		cout << s;
		cout << "s\n";
	}
	
}
int main()
{
	fast();
	ll t = 1;
//	cin >> t;
	fr(i, 0, t)
    	{
		solve();
	}
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 111

int n, i, j;
int a[5][maxN], dp[5][maxN];

int main()
{
  //  freopen("test.in","r",stdin);

    cin >> n;
    for (i = 1; i <= 2; i++) {
        for (j = 1; j <= n; j++) {
            cin >> a[i][j];
            dp[i][j] += a[i][j];

            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            dp[i][j + 1] = max(dp[i][j + 1], dp[i][j]);
        }
    }

    cout << dp[2][n];


    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.PrintWriter;
public class Main {
    public static void main(String args[])throws IOException {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        in.nextToken();
        long A = (long) in.nval;
        in.nextToken();
        long B = (long) in.nval;
        in.nextToken();
        long C = (long) in.nval;
        in.nextToken();
        long K = (long) in.nval;
        if(A+B>=K)
        {
          if(A<=K)
            out.print(A);
          else
            out.print(K);
        }          
        else{
            out.print(2*A-K+B);
        }
        out.flush();
    }
}

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


int main(){
   string s;
   cin >> s;
   int temp=0;
   for(int i=0;i<s.length();i++){
   	  if((i+1)%2==0&&s[i]=='R'){temp=1;break;}
   	  if((i+1)%2==1&&s[i]=='L'){temp=1;break;}
   	
   }
  if(temp)cout << "No";
  else cout << "Yes";
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    long long h;
    cin >> h;
    long long cnt = 0;
    long long num=1;
	long long ans=1;
    while (h != 1){
        h = h/2;
        cnt++;
    }
    for (int i=0; i<cnt; i++){
        num = num*2;
        ans += num;

    }
    cout << ans;
}

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



int main(){

    int N;
    cin>>N;
    vector <int> d(N);

    for(int i=0;i<N;i++){
        cin>>d.at(i);
    }

    int sum=0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(i>=j){
                continue;
            }else{
                sum += d.at(i)*d.at(j);

            }
        }
    }

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



Measured memory_bytes: 256
/*input
3141592653589793
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

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

int main(){
	IOS;
	ll n;
	cin>>n;
	n++;

	int cnt=0;
	int ans=0;

	while(n){
		ans=max(ans,s(n-1)+cnt*9);
		n/=10;
		cnt++;
	}	
	cout<<ans<<'\n';
	return 0;
}


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

tot = sum(A)
rui = [0]*len(A)
cur = 0
for i in range(0,len(A)):
  cur += A[i]
  rui[i] = cur

ans = 0
for i in range(0,len(A)):
  if rui[i] < tot//2 and rui[i+1] > tot//2:
    ans = abs(rui[i] - (tot - rui[i]))
    ans2 = abs(2*rui[i+1]-tot)
    ans = min([ans, ans2])

print(ans)

Measured memory_bytes: 26220
#include <iostream>

using namespace std;

int main(void)
{
    int a, b, c;

    cin >> a >> b >> c;

    if(a>=b&&a>=c){
        cout << a*10+b+c << endl;
    }
    else if(b>=a&&b>=c){
        cout << b*10+a+c << endl;
    }
    else{
        cout << c*10+a+b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll a; cin >> a;
  cout << a + a*a + a*a*a << endl;
}

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

void _140() {
    int n;
    cin >> n;

    int a[20];
    int b[20];
    int c[20];
    for (int i = 0; i < n; ++i) 
        cin >> a[i];
    for (int i = 0; i < n; ++i) 
        cin >> b[i];
    for (int i = 0; i < n - 1; ++i) 
        cin >> c[i];

    int score = 0;
    for (int i = 0; i < n - 1; ++i) {
        score += b[a[i] - 1];
        if (a[i + 1] == a[i] + 1) {
            score += c[a[i] - 1];
        }
        // cout << score << endl;
    }
    score += b[a[n - 1] - 1];

    cout << score << endl;
}

#include <string>
void _141() {
    string s;
    cin >> s;
    bool judge = true;
    for (int i = 0; i < s.size(); ++i) {
        if ((i + 1) % 2 == 0 && s[i] == 'R') {
            judge = false;
            break;
        } else if ((i + 1) % 2 == 1 && s[i] == 'L') {
            judge = false;
            break;
        }
    }

    if (judge) 
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void _142() {
    int n, k;
    cin >> n >> k;
    int count = 0;
    int h;
    for (int i = 0; i < n; ++i) {
        cin >> h;
        if (h >= k)
            count++;
    }
    cout << count << endl;
}

void _143() {
    int n;
    cin >> n;
    int d[50];
    for (int i = 0; i < n; ++i) {
        cin >> d[i];
    }

    int value = 0;
    for (int i = 0; i < n - 1; ++i) {
        for (int j = i + 1; j < n; ++j) {
            value += d[i] * d[j];
        }
    }
    cout << value << endl;
}

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



Measured memory_bytes: 256
n, m = map(int, input().split())

def ark(a, b):
    return min(abs(a - b), n - abs(a - b))

a, b = n, 1
S = set()
for i in range(m):
    if 2 * ark(a, b) == n or ark(a, b) in S:
        a -= 1
    print(a, b)
    S.add(ark(a, b))
    a -= 1
    b += 1


Measured memory_bytes: 17444
def sum_all(x):
  a = 0
  while x >= 10:
    a += x%10
    x = x//10
  a += x
  return int(a)
N, A, B = map(int, input().split())
ans_list = []
for i in range(1, N+1):
  if sum_all(i) >= A and sum_all(i) <= B:
    ans_list.append(i)
print(sum(ans_list))


Measured memory_bytes: 3396
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include <iomanip>
#include<algorithm>
#include<vector>
#include <map>
#define rep(i,N) for(int (i)=0;(i) < (N); (i)++)

using namespace std;

struct restraunt{
  string s;
  int p;
  int num;
};

bool compare(restraunt a, restraunt b){
  if(a.s != b.s){
    return a.s < b.s;
  }else{
    return a.p > b.p;
  }
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  restraunt r[n];
  rep(i, n){
    string city;
    int point;
    cin >> city >> point;
    r[i].s = city;
    r[i].p = point;
    r[i].num = i + 1;
  }

  sort(r, r+n, compare);

  rep(i, n){
    cout << r[i].num << endl;
  }
  return 0;
}


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

int main()
{
  int N, M, sum = 0, count = 0;
  vector<int> A(100);

  cin >> N >> M;
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
    sum += A[i];
  }
  for (int i = 0; i < N; i++)
  {
    if (sum <= A[i] * 4 * M)
      count++;
  }
  if (count < M)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
// abc.92.c   Traveling Plan

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

int main( void ) {

    int n;
    cin >> n;
    vector<int> num( n + 2 );
    int         sum = 0;
    for( int i = 1; i <= n; i++ ) cin >> num.at( i );
    num.at( 0 ) = num.at( n + 1 ) = 0;
    for( int i = 0; i < n + 1; i++ ) {
        sum += abs( num.at( i + 1 ) - num.at( i ) );
    }
    int ans;
    for( int i = 1; i <= n; i++ ) {
        ans = sum + abs( num.at( i + 1 ) - num.at( i - 1 ) ) -
              abs( num.at( i ) - num.at( i - 1 ) ) -
              abs( num.at( i + 1 ) - num.at( i ) );
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 1664