akhauriyash/Code-Regression huggingface dataset:
def main():
    s = input()
    f = s[0]
    n = len(s) - 1
    ans = 0
    
    for i in range(2 ** (n)):
        res = [0] * (n)
        for j in range(n):
            if (i >> j) & 1:
                res[j] = 1
                f += '+'
            f += s[j+1]
        ans += sum(map(int, f.split("+")))
        # print(f)
        # print('b', res)
        f = s[0]
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,d,a = LI()
xh = [LI() for _ in range(n)]
xh.sort()
X = [x for x,h in xh]
que = deque()
for i,[x,h] in enumerate(xh):
    r = br(X,x+2*d)
    que.append((h,i,r))

ans = 0
lst = [0]*(n+1)
while que:
    h,l,r = que.popleft()
    tmp = max(0,math.ceil((h - lst[l])/a))
    ans += tmp
    lst[l] += tmp*a
    lst[r] -= tmp*a
    lst[l+1] += lst[l]
print(ans)


Measured memory_bytes: 119900
#include "bits/stdc++.h"
using namespace std;
 
using ll = long long;
 
const ll inf = 1e18;
const int N = 2 * 1e6 + 10;

ll res;
ll a[N];
ll prime[N];
ll spf[N];

vector<ll> p;

void siev(ll maxN){
    prime[0] = prime[1] = 1;
    spf[0] = spf[1] = 1;
    for(int i = 2; i < maxN; ++i){
        if(!prime[i]){
            spf[i] = i;
            for(int j = 2 * i; j < maxN; j += i){
                prime[j] = 1;
                if(!spf[j]) spf[j] = i;
            }
            p.push_back(i);
        }
    }
}

std::map<ll, ll> mp;
ll primefactorization(ll x){
    while(x != 1){
        mp[spf[x]]++;
        x = x / spf[x];
    }

    ll ans = 1;
    for(auto i : mp){
        ans = ans * (i.second + 1);
    }
    mp.clear();
    return ans;
}

void solve(){
    ll n;
    cin >> n;
    res = 0;
    for (int i = 1; i < n; ++i){
        res += primefactorization(n - i);
    }
    cout << res;
}
 
int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    siev(N);
    //cin >> t;
    while(t--){
        solve();
    }
}
// Radhe Radhe

Measured memory_bytes: 36536
#include <iostream>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	int i;
	int num4=0;
	int num2=0;
	int num1=0;
	LL A;
	for (i=0;i<N;i++){
		cin>>A;
		if (A%4==0){
			num4++;
		}else if (A%2==0){
			num2++;
		}else{
			num1++;
		}
	}
	if (num1==0 && N>1){
		cout<<"Yes"<<endl;
		return 0;
	}
	if (num1<num4){
		cout<<"Yes"<<endl;
		return 0;
	}
	int N4=N-(2*num4+1);
	if (N4==0){
		cout<<"Yes"<<endl;
		return 0;
	}
	
	if (num2>N4 && num2>1){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		String n = scan.next();
		
		for(int i=0;i<3;i++) {
			if(n.charAt(i) == '7') {
				System.out.println("Yes");
				System.exit(0);
			}
		}
		
		System.out.println("No");
		
		
		
		
	}	
}


Measured memory_bytes: 35772
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <list>


int* find(
    std::unordered_map<std::string, std::unordered_map<std::string, int> > *map,
    const std::string &s1, const std::string &s2)
{
    auto it1 = map->find(s1);
    if (it1 == map->end()) return NULL;

    auto it2 = it1->second.find(s2);
    return (it2 == it1->second.end()) ? NULL : &it2->second;
}


bool walk(
    std::unordered_map<std::string, std::unordered_map<std::string, int> > *map,
    const std::tuple<std::string, std::string, int> &t)
{
    const std::string &s0 = std::get<0>(t);
    const std::string &s1 = std::get<1>(t);
    int mag1 = std::get<2>(t);

    int *old = find(map, s0, s1);
    if (old == NULL)
    {
        (*map)[s0][s1] = mag1;
        (*map)[s1][s0] = -mag1;
    }
    else return (*old == mag1);

    std::list<std::tuple<std::string, std::string, int> > next;
        
    for (auto x : map->at(s0))
    {
        const std::string &s2 = x.first;
        int mag2 = x.second;
        
        if (s1 != s2)
        if (find(map, s1, s2) == NULL)
            next.push_back(std::make_tuple(s1, s2, -mag1 + mag2));
    }
    
    for (auto x : map->at(s1))
    {
        const std::string &s2 = x.first;
        int mag2 = x.second;
        
        if (s0 != s2)
        if (find(map, s0, s2) == NULL)
            next.push_back(std::make_tuple(s0, s2, mag1 + mag2));
    }

    for (auto t : next)
        if (!walk(map, t))
            return false;

    return true;
}


int main()
{
    char line[256];
    
    while (not std::cin.eof())
    {
        int n;
        std::cin >> n;
        if (n == 0) break;

        std::list<std::tuple<std::string, std::string, int> > inputs;
        
        for (int i = 0; i < n; ++i)
        {
            int x;
            std::string s1, s2;
            
            std::cin.ignore(2);
            std::cin >> s1;
            std::cin.ignore(6);
            std::cin >> x >> s2;

            inputs.push_back(std::make_tuple(s1, s2, x));
        }

        std::unordered_map<std::string,
            std::unordered_map<std::string, int> > map;
        bool is_valid(true);
        
        for (auto x : inputs)
            if (!walk(&map, x))
            {
                is_valid = false;
                break;
            }

        std::cout << (is_valid ? "Yes" : "No") << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 7644
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <math.h>
#include <cstdio>
#include <iomanip>
typedef  long long ll;
using namespace std;

int main(void) {
	int N;
	string S;
	cin >> N >> S;
	int ans = 0;
	for (int i = 0; i < N - 2; i++)
	{
		if ( S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C' ) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
c=[0]*n

for i in range(n):
    c[a[i]-1]+=1

ans=0

for i in range(n):
    ans+=c[i]*(c[i]-1)

ans=ans//2+1
for i in range(n):
    print(ans-c[a[i]-1])

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

using namespace std;

#define int long long

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

typedef pair<int, int> PII;

//--------

int N;
int A,B,C;
int l[10];

int dist(int a){
    if(a >= 0) return a;
    else return -a;
}

int costcalc(int a, int b, int c){
    return (dist(a - A) + dist(b - B) + dist(c - C));
}

signed main(){  
    cin >> N; 
    cin >> A >> B >> C;

    REP(i, N){
        cin >> l[i];
    }

    int minv = LLONG_MAX;

    int fin = 1 << (2 * N);

    REP(cunt, fin){
        int i = cunt;
        int res[3];
        res[0] = 0;
        res[1] = 0;
        res[2] = 0;
        int cost = 0;
        REP(n, N){
            int y = i % 4;
            if(y != 3) {
                if(res[y] != 0){
                    cost += 10;
                }
                res[y] += l[n];
            }
            i /= 4;
            //cout << y << " ";
        }
        //cout << endl;
        sort(res, res + 3);
        if(res[0] == 0){
            continue;
        }
        //cout << res[2]  << " "
        //<< res[1] << " " << res[0] << endl;
        cost += costcalc(res[2], res[1], res[0]);
        //cout << costcalc(res[2], res[1], res[0]) << endl;
        minv = min(cost, minv);
        //cout << " " << cost << endl;
    }

    cout << minv << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;



int main()
{
    int h,w;
    cin>>h>>w;
    char arr[h][w];
    int temp[h][w];
    
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>arr[i][j];
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            temp[i][j] = 0;
        }
    }
    for(int i=0;i<h;){
        while(arr[i][0] == '.'){
            temp[i][0] = 1;
            i++;
        }
        break;
    }
    for(int i=0;i<w;){
        while(arr[0][i] == '.'){
            temp[0][i] = 1;
            i++;
        }
        
        break;
    }
    for(int i=1;i<h;i++){
        for(int j=1;j<w;j++){
            if(arr[i][j] =='.')
            temp[i][j] = (temp[i-1][j] + temp[i][j-1])%mod;
        }
    }
    cout<<temp[h-1][w-1];
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

void claim(int x){
	if(!x) puts("0"),exit(0);
}

const int N=300005,mod=998244353;
int a[N],b[N],c[N],l[N],r[N],vis[N];
int n,p,len,ans=1,rem;

int main(){
	read(n);
	rep(i,1,n){
		read(a[i]);
		if(!p&&a[i]==1) p=i;
	}
	if(a[n]==1){
		p=n;
		while(a[p-1]==1) p--;
	}
	claim(p);
	rep(i,1,p-1) b[i]=a[i];
	rep(i,1,n-p+1) a[i]=a[i+p-1];
	rep(i,1,p-1) a[i+n-p+1]=b[i];
	/*
	puts("===");
	rep(i,1,n) printf("%d ",a[i]);
	puts("\n---");
	*/
	rep(i,1,n){
		c[a[i]]++;
		if(!l[a[i]]) l[a[i]]=i;
		r[a[i]]=i;
	}
	rep(i,1,n) claim(!c[i]||c[i]==r[i]-l[i]+1&&c[i]<=c[1]);
	len=c[1];
	if(len==n){
		int ans=1;
		rep(i,1,n) ans=(ll)ans*i%mod;
		cout<<ans<<endl;
		return 0;
	}
	rep(i,2,n){
		if(!c[i]){
			claim(rem);
			ans=(ll)ans*(rem--)%mod;
			continue;
		}
		int L=(a[l[i]-1]<i),R=(a[r[i]+1]<i);
		if(L&&R){
			ans=(ll)ans*(len-c[i]+1)%mod;
			rem+=c[i]+len-2;
		}
		else if(L||R) rem+=c[i]-1;
		else claim(c[i]==len);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6144
MOD=10**9+7
fact=[1 for i in range(200010)]
ifact=[1 for i in range(200010)]
for i in range(2,200010):
    fact[i]=(fact[i-1]*i)%MOD
    ifact[i]=(ifact[i-1]*pow(i,MOD-2,MOD))%MOD
def nCm(n,m):
    global MOD,fact,ifact
    return (fact[n]*((ifact[m]*ifact[n-m])%MOD))%MOD
h,w,a,b=map(int,input().split())
ret=0
for i in range(h-a):
    ret+=(nCm(i+b-1,i)*nCm((h-i-1)+(w-b-1),h-i-1))%MOD
    ret%=MOD
print(ret)

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

int main(){
	int t1,t2;
	cin >> t1 >> t2;
	ll a1,a2;
	cin >> a1 >> a2;
	ll b1,b2;
	cin >> b1 >> b2;
	
	
	ll dist1 = a1*t1 - b1*t1;
	ll dist2 = a2*t2 - b2*t2;
	
	if(dist1 > 0){
		dist1 *= -1;
		dist2 *= -1;
	}
	
	if(dist1 + dist2 == 0){
		cout << "infinity" << endl;
		return 0;
	}
	if(dist1 + dist2 < 0){
		cout << 0 << endl;
		return 0;
	}
	
	
	ll s = (-dist1)/(dist1 + dist2);
	ll t = (-dist1)%(dist1 + dist2);
	
	if(t == 0){
		cout << 2*s << endl;
	}
	else{
		cout << 2*s+1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  cout << setprecision(10)<< sqrt(a*a+b*b-2*a*b*cos(M_PI/180.0*(5.5*m-30*h))) << endl;
  return 0;
}


Measured memory_bytes: 4132
// template version 1.6
// {{{ define basic macro
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
// varibable settings
#define int long long
#define INF 1000000000000000000LL
// #define INF 2147483647
#define MOD 1000000007LL
// #define MOD 998244353LL
#define infile "../test/sample-1.in"

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)
template<class T, size_t N> size_t sza(const T (&array)[N]) { return N; }
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
template<class T=int> T in() {T x; cin>>x; return (x);}
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

// dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
#define fi first
#define se second

// }}}

int solve(){
  string s;cin>>s;
  int n = sz(s);

  stack<char> S;
  rep(i, n){
    if (sz(S)==0 or s[i]==S.top()) S.push(s[i]);
    else{ S.pop(); }
  }
  cout << n-sz(S) << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


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

int main(){

  int n,m,k;

  cin>>n>>m>>k;

  bool ans=false;

  for(int i=0;i<=n;i++){

    int sum=i*m;
    if(sum==k) ans=true;
    
    for(int j=0;j<=m;j++){
      
      if(sum-i*j+(n-i)*j==k) ans=true;
      
    }
  }

  if(ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		int x, y, xs = 0, ys = 1;
		Scanner sc = new Scanner(System.in);
		x = sc.nextInt();
		y = sc.nextInt();
		switch (x) {
		case 1:
			xs = 1;
			break;
		case 2:
			xs = 3;
			break;
		case 3:
			xs = 1;
			break;
		case 4:
			xs = 2;
			break;
		case 5:
			xs = 1;
			break;
		case 6:
			xs = 2;
			break;
		case 7:
			xs = 1;
			break;
		case 8:
			xs = 1;
			break;
		case 9:
			xs = 2;
			break;
		case 10:
			xs = 1;
			break;
		case 11:
			xs = 2;
			break;
		case 12:
			xs = 1;
			break;
		}
		switch (y) {
		case 1:
			y = 1;
			break;
		case 2:
			ys = 3;
			break;
		case 3:
			ys = 1;
			break;
		case 4:
			ys = 2;
			break;
		case 5:
			ys = 1;
			break;
		case 6:
			ys = 2;
			break;
		case 7:
			ys = 1;
			break;
		case 8:
			ys = 1;
			break;
		case 9:
			ys = 2;
			break;
		case 10:
			ys = 1;
			break;
		case 11:
			ys = 2;
			break;
		case 12:
			ys = 1;
			break;
		}
		if (xs == ys) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 22100
class Dice:
    def __init__(self):
        self.u = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.d = 6
        self.dic = {"W":0, "S":1, "E":2, "N":3}

    def __init__(self, u, s, e, w, n, d):
        self.u = u
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.d = d
        self.dic = {"W":0, "S":1, "E":2, "N":3}

    def rot(self, way):
        if isinstance(way, str):
            way = self.dic[way]

        if way == 0:
            c = self.u
            self.u = self.e
            self.e = self.d
            self.d = self.w
            self.w = c

        elif way == 1:
            c = self.u
            self.u = self.n
            self.n = self.d
            self.d = self.s
            self.s = c

        elif way == 2:
            c = self.u
            self.u = self.w
            self.w = self.d
            self.d = self.e
            self.e = c

        else:
            c = self.u
            self.u = self.s
            self.s = self.d
            self.d = self.n
            self.n = c


u, s, e, w, n, d = map(int, input().split())
dice = Dice(u, s, e, w, n, d)
st = input()
for c in st:
    dice.rot(c)
print(dice.u)


Measured memory_bytes: 5608
def q(a,l,r):
    if l>=r:return
    i=l
    for j in range(l,r):
        if int(a[j][2:])<=int(a[r][2:]):
            a[i],a[j]=a[j],a[i]
            i+=1
    a[i],a[r]=a[r],a[i]
    q(a,l,i-1)
    q(a,i+1,r)

n=input()
a=[raw_input() for _ in range(n)]
b=a[:]
q(b,0,len(b)-1)
n=0
print "Stable" if b==sorted(a,key=lambda i:int(i[2:])) else "Not stable"
for i in b:print i

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

#define Max 51000
int n;
bool IsPrime[51000];

int main()
{
	for (int i = 2; i < Max; i++) IsPrime[i] = true;

	for (int i = 2; i < Max; i++)
	{
		if (!IsPrime[i]) continue;
		for (int j = i + i; j < Max; j += i) IsPrime[j] = false;
	}

	while (cin >> n)
	{
		for (int i = n - 1; true; i--)
		{
			if (IsPrime[i])
			{
				cout << i << ' ';
				break;
			}
		}

		for (int i = n + 1; true; i++)
		{
			if (IsPrime[i])
			{
				cout << i << endl;
				break;
			}
		}
	}

	return 0;
}

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

int main(void){
  int a[10];
  int k;

  cin >> a[0] >> a[1] >> a[2] >> k;
  sort(a, a+3);

  for (int i=0; i<k; i++) {
  a[2] *= 2;
  }


  cout << a[0]+a[1]+a[2]<< endl;
  return 0;
}


Measured memory_bytes: 256
//実装が重そうな問題はある程度考えてから書く
//初期化を忘れずに（特に二分探索とか）
//コーナーケースを考えて（特に場合分けとか）
//不可解すぎるバグは配列外参照（配列の長さ）を検討
#include "bits/stdc++.h"
#define YES "YES"
#define Yes "Yes"
#define NO "NO"
#define No "No"
#define YESNO(x) OUT(three(x,YES,NO))
#define YesNo(x) OUT(three(x,Yes,No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define rep REP
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b-1,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB emplace_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int long long
#define zero 0LL
#define all ALL
#define pb PB
using namespace std;
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long LL;
typedef LL ll;
typedef double ld;
typedef LL ut;
const LL INF = 1LL << 60;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<ppr, Vppr ,greater<ppr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
int dx[] = { 0,1,0,-1,1,1,-1,-1,0 }, dy[] = { 1,0,-1,0,1,-1,1,-1,0 };
const int SIZE1 =2e6 + 1000;
const int SIZE2 = 2010;
const int SIZE3 = 22;
const int SIZE = SIZE1;
const LL p = 7 + 1e9;const long double EPS = 1e-7;
ut N, M, K, X, L, Y,H,W,Q,D;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL vals[SIZE], nums[SIZE], maps[SIZE2][SIZE2], answer = zero;
LL A[SIZE], B[SIZE],I[SIZE];
LL solve() {
	string s;
	cin >> s;
	FOR(i,1, s.size()) {
		if(s[i]!='9')
			return s[0] - '0' + (s.size() - 1) * 9-1;
	}
	return s[0]-'0'+(s.size()-1)*9;
}
signed main() {
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	cout << solve() << endl;
	//	cin >> N;
	return 0;
}

Measured memory_bytes: 48384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
# define INF (1 << 29)
/* ちゃんと考えて実装して問題なくACできた時嬉しいよ！！ */

int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    cout << (a*b)/2;
    return 0;
}

Measured memory_bytes: 256
N = int(input()) 
a = list(map(int, input().split()))
b = [-1, -1, -1]
x=1
for i in range(N):
  x = x*b.count(a[i]-1) % 1000000007
  if b[0]==(a[i]-1):
    b[0]+=1
  elif b[1]==(a[i]-1):
    b[1]+=1
  else:
    b[2]+=1
print(x)

Measured memory_bytes: 14004
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
#define maxn 200005
#define inf 0x3f3f3f3f

int main() {
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	if (a > 8 || b > 8)cout << ":(" << endl;
	else cout << "Yay!" << endl;
}

Measured memory_bytes: 256
# ?????????????????¢?´¢????????¨?????£??????DFS??¨????????´??????
# ?????????????£?????????????????§£??¬????????????

@m = 0
@n = 0
@cells = []

def dfs cells,y,x,cur
  cells[y][x] = false
  sur = [
    [y + 1, x],
    [y - 1, x],
    [y, x + 1],
    [y, x - 1]
  ]

  results = []
  did = false
  sur.each do |(ny, nx)|
    next if ny >= @n || nx >= @m || nx < 0 || ny < 0
    next unless cells[ny][nx]
    did = true
    results << dfs(cells,ny, nx, cur + 1)
  end
  cells[y][x] = true
  unless did
    return cur + 1
  else
    return results.max || 0
  end
end

loop do
  @m = gets.to_i
  break if @m == 0
  @n = gets.to_i
  @cells = []
  @n.times { @cells << gets.split.map { |v| v == "1" } }

  flag = []
  max = 0
  @cells.each_with_index do |line, y|
    flag[y] = []
    line.each_with_index do |val, x|
      max = [dfs(@cells,y,x,0), max].max if val
    end
  end

  puts max

end

Measured memory_bytes: 8888
import sys
n = int(input())
A = [int(e)for e in sys.stdin]
cnt = 0
G = [int((2.25**i-1)/1.25)for i in range(17,0,-1)]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
for g in G:
    insertionSort(A, n, g)
print(len(G))
print(' '.join(map(str,G)))
print(cnt)
print('\n'.join(map(str,A)))


Measured memory_bytes: 126040
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;
	if (s1[s1.size() - 1] == s2[0] && s2[s2.size() - 1] == s3[0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import deque
INF = float("inf")


def runlength(S):
    ans = [0]
    newS = [S[0]]
    pos = [0]
    for i, (pre, curr) in enumerate(zip(S[0]+S, S)):
        if pre == curr:
            ans[-1] += 1
        else:
            ans.append(1)
            newS.append(curr)
            pos.append(i)
    return [(n, a, i) for (n, a, i) in zip(ans, newS, pos)]


def solve(S: str):
    N = len(S)
    RL = deque(sorted(runlength(S)))
    ans = [-1]*(N+1)
    while RL:
        n, a, i = RL.popleft()
        # print((n, a, i))
        if a == ">":
            for j in range(n+1):
                ans[i+j] = n-j
        else:
            for j in range(n+1):
                ans[i+j] = j
        # print(ans)
    print(sum(ans))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<=n;++i)
int main(){
  int n;
  cin>>n;
  int ans=0;
  for(int i=1;i<10;i++){
    if(n%i==0){
      if(n/i<=9)
      ans++;
    }
  }
  if(ans==0){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
  return 0;
}


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

const int MAXV = 100005;

int f[MAXV];

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

    std::fill(f + 1, f + MAXV, INT_MAX >> 1);

    for (int i = 0, w, v; i < n; i++) {
        scanf("%d %d", &w, &v);
        for (int j = MAXV - 1; j >= v; j--) f[j] = std::min(f[j], f[j - v] + w);
    }

    for (int i = MAXV - 1; ~i; i--) if (f[i] <= W) {
        printf("%d\n", i);
        break;
    }
    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

template <class T>
inline void read(T &x) {
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

int a[60], b[60], c[60], d[60], x[20];
int n, m, q, ans;

void dfs(int now, int last) {
    if (now > n) {
        int s = 0;
        for (int i = 1; i <= q; ++i) {
            if (x[b[i]] - x[a[i]] == c[i]) {
                s += d[i];
            }
        }
        ans = std::max(ans, s);
        return ;
    }
    for (int i = last; i <= m; ++i) {
        x[now] = i;
        dfs(now + 1, i);
    }
}

int main() {
    read(n), read(m), read(q);
    for (int i = 1; i <= q; ++i)    read(a[i]), read(b[i]), read(c[i]), read(d[i]);
    dfs(1, 1);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3752
n = int(input())
a = []
for i in range(n):
    value = int(input())
    a.append(value)
temp = sorted(a)
max_a = temp[-1]
if len(a)>=2:
    second_a = temp[-2]
for i in range(n):
    if a[i] == max_a:
        check = i
        break
for i in range(n):
    if i == check:
        print(second_a)
    else:
        print(max_a)


Measured memory_bytes: 14064
s = input()
n = len(s)
s1 = s[:(n-1)//2]
s2 = s[((n+3)//2-1):]
is_kaibun = lambda x: x==x[::-1]
if is_kaibun(s) and is_kaibun(s1) and is_kaibun(s2):
    print("Yes")
else:
    print("No")

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

#define Mset(s, n)      memset(s, n, sizeof(s))
#define Rp0(i, m)       for(int i = 0; i < m; ++i)
#define Rpd(i, m, l)    for(int i = l; i >= m; --i)
#define Rp1(i ,m)       for(int i = 1; i <= m; i++)
#define All(a)          (a).begin(), (a).end()
#define Lwb             lower_bound
#define Upb             upper_bound
#define Sz(a)           int((a).size())
#define u_map           unordered_map
#define Exist(a, b)     (find(All(a), (b)) != (a).end())
#define Sort(x)         sort(All(x))
#define Gsort(x)        sort(All(x), greater<typeof(*((x).begin()))>())
#define Unique(v)       Sort(v); (v).resize(unique(ALL(v)) - (v).begin())

#define fi              first
#define se              second
#define pb              push_back
#define pf              push_front
#define is              insert
#define ooi             INT_MAX
#define ool             LLONG_MAX
#define ll              long long
#define ull             unsigned ll
#define ld              long double
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define vll             vector<ll>
#define vpll            vector<pll>
#define vpii            vector<pii>

const ll MOD = (ll) 1e9 + 7;
const ld PI = acos((ld) -1);
inline int Get_bit(int x, int k){return (x >> (k - 1)) & 1;}
inline ll Gcd(ll a, ll b) {ll r; while(b){ r = a % b; a = b; b = r;} return a;}
inline ll Lcm(ll a, ll b) {return a / Gcd(a, b) * b;}
inline ll Pow(ll n, ll k) {ll r = 1; for(; k; k >>= 1, n = n * n % MOD){if(k & 1) r = r * n % MOD;} return r;}
const int base = 311;


const int N = 1e6 + 10;

int n, k, m, query;

ll ans;
pii a[N];

void Solve(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i].fi;
        a[i].se = i;
    }
    sort(a + 1, a + n + 1);
    for(int i = 1; i <= n ;i++) cout << a[i].se << " ";
}

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

















Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		int x = sc.nextInt();
		
		int count = 0;
		
		for(int i = 0 ;i <= a; i++){
			for(int j = 0 ;j <= b; j++){
				if( i*500 + j*100 <= x && i*500 + j*100 + c*50 >= x){
//					System.out.println(i +" "+ j);
					count ++;
				}
			}
		}
		
		System.out.println(count);
		
	}
}


Measured memory_bytes: 23636
/*
                                             ::                     ::
                                             ':                     :
                                              :.                    :
                                           ;' ::                   ::  '
                                          .'  ';                   ;'  '.
                                         ::    :;                 ;:    ::
                                         ;      :;.             ,;:     ::
                                         :;      :;:           ,;"      ::
                                         ::.      ':;  ..,.;  ;:'     ,.;:
                                          "'"...   '::,::::: ;:   .;.;""'
                                              '"""....;:::::;,;.;"""
                                          .:::.....'"':::::::'",...;::::;.
                                         ;:' '""'"";.,;:::::;.'""""""  ':;
                                        ::'         ;::;:::;::..         :;
                                       ::         ,;:::::::::::;:..       ::
                                       ;'     ,;;:;::::::::::::::;";..    ':.
                                      ::     ;:"  ::::::"""'::::::  ":     ::
                                       :.    ::   ::::::;  :::::::   :     ;
                                        ;    ::   :::::::  :::::::   :    ;
                                         '   ::   ::::::....:::::'  ,:   '
                                          '  ::    :::::::::::::"   ::
                                             ::     ':::::::::"'    ::
                                             ':       """""""'      ::
                                              ::                   ;:
                                              ':;                 ;:"


                                                     P_r_A_d_Y
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
#define mod 1000000007
#define inf 1e18
const int N = 300005;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
void cs(int &x)
{
    cout << "Case #" << x << ": ";
}
bool cmp(string a, string b)
{
    return a + b < b + a;
}

int32_t main()
{
    fastIO;
    // int t; cin >> t;
    // int x = 1;
    // while (t--)
    // {

    int n;cin>>n;
    vector<int>h(n);

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

    map<int,vector<int>>m;

    for(int i=0;i<n;i++)
    {
        m[h[i]+i].push_back(i);
    }

    int c=0;

    for(int i=n-1;i>=0;i--)
    {
        int r=i-h[i];
        if(r<=0)
            continue;

        c+= upper_bound(m[r].begin(),m[r].end(),i-1)-m[r].begin();

    }

    cout<<c<<endl;



    //}
    return 0;
}

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

typedef long long ll;

int main() {
  int N; cin >> N;
  vector<string> W(N);
  map<string,int> m;
  for(int i=0; i<N; i++){
    cin >> W[i];
    m[W[i]]++;
  }

  for(int i=0; i<N-1; i++){
    if(W[i][W[i].length()-1] != W[i+1][0]){
      cout << "No" << endl;
      return 0;
    }
  }

  for(auto itr=m.begin(); itr!=m.end(); itr++){
    if(itr->second!=1){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}

Measured memory_bytes: 256
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int w, h;
	string s;
	cin >> w >> h;
	rep(i, w) {
		rep(j, h) {
			cin >> s;
			if (s == "snuke") {
				cout << (char)('A' + j) << i+1 << endl;
			}
		}
	}

	return 0;
	
}





Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> seq;
    for(int i = 0; i< n; i++){
        cin >> a[i];
        seq[a[i]]++;
    }
    int ans = 0;
    for(int i = 0; i< n; i++){
        if(seq[a[i]] > a[i]){
            ans += seq[a[i]] - a[i];
            seq[a[i]] = a[i];
        }else if(seq[a[i]] < a[i]){
            ans += seq[a[i]];
            seq[a[i]] = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    string s;
    cin >> s;

    s[3] = '8';
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 3564
uses Math;
var
	N,K,i,j:Longint;
	x,y,c:Array[1..60]of Longint;
	rr:Array[1..60]of double;
	L,R,M,a,t,d,ri,rj,yy:double;
	flag:Boolean;
function count(tx,ty:double):Boolean;
var i,cnt:Longint;
begin
	cnt:=0;
	for i:=1 to N do if sqr(X[i]-tx)+sqr(Y[i]-ty)<sqr(rr[i])+0.000000001 then inc(cnt);
	count:=cnt>=K;
end;
begin
	read(N,K);
	for i:=1 to N do read(x[i],y[i],c[i]);
	L:=0;
	R:=200000;
	while R-L>0.000001 do begin
		M:=(L+R)/2;
		for i:=1 to N do rr[i]:=M/c[i];
		flag:=False;
		for i:=1 to N do begin
			if count(X[i],Y[i])then begin
				flag:=True;
				break;
			end;
		end;
		if not flag then begin
			for i:=2 to N do begin
				for j:=1 to i-1 do begin
					d:=sqr(X[i]-X[j])+sqr(Y[i]-Y[j]);
					ri:=rr[i];
					rj:=rr[j];
					yy:=4*sqr(ri)*d-sqr(sqr(ri)+d-sqr(rj));
					if yy<0 then continue;
					a:=arctan2(sqrt(yy),sqr(ri)+d-sqr(rj));
					t:=arctan2(Y[j]-Y[i],X[j]-X[i]);
					if count(X[i]+ri*cos(t+a),Y[i]+ri*sin(t+a)) then flag:=True
					else if count(X[i]+ri*cos(t-a),Y[i]+ri*sin(t-a))then flag:=True;
					if flag then break;
				end;
				if flag then break;
			end;
		end;
		if flag then R:=M else L:=M;
	end;
	writeln(R:0:9);
end.


Measured memory_bytes: 128
#import<cstdio>
int main(){int a,c=1,r=0,t;for(char d[]="123546",s[9];t=scanf("%s",s),*s>60;r+=*d%8)*s%6-4?a=*s%5+*s%2*2+c&3,t=*d,*d=d[++a],d[a]=d[5],d[5]=d[a=++a%4+1],d[a]=t:c+=*s+3;r&&printf("%d\n",r+1);~t&&main();}

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

double dp[2][2][101];
int main(){
    for(;;){
        int N,T,L,B;
        cin>>N>>T>>L>>B;
        if(N==0&&T==0&&L==0&&B==0) break;
        set<int> lose,back;
        int n;
        for(int i=0;i<L;i++){
            cin>>n;
            lose.insert(n);
        }
        for(int i=0;i<B;i++){
            cin>>n;
            back.insert(n);
        }
        for(int i=0;i<2;i++){
            fill(dp[0][i],dp[0][i]+N+1,0);
        }
        dp[0][0][0]=1;
        for(int i=0;i<T;i++){
            int now=i%2,nex=(i+1)%2;
            for(int j=0;j<2;j++){
                fill(dp[nex][j],dp[nex][j]+N+1,0);
            }
            for(int j=0;j<N;j++){
                double p=dp[now][0][j]/6;
                for(int k=1;k<=6;k++){
                    int at=j+k<=N ? j+k : N-(j+k-N);
                    if(lose.count(at)) dp[nex][1][at]+=p;
                    else if(back.count(at)) dp[nex][0][0]+=p;
                    else dp[nex][0][at]+=p;
                }
            }
            dp[nex][0][N]+=dp[now][0][N];
            for(int j=0;j<=N;j++){
                dp[nex][0][j]+=dp[now][1][j];
            }
        }
        printf("%.8f\n",dp[T%2][0][N]);
    }
}

Measured memory_bytes: 1212
#include <iostream>
#include <string>
#include <cstdlib>
#include <list>
#include <algorithm>
using namespace std;

int main()
{
    int n, x;
    string c;
    list<int> L;

    cin >> n;

    for (int i = 0; i != n; ++i)
    {
        cin >> c;

        if (c[0] == 'i')
        {
            cin >> x;
            L.push_front(x);
        }
        else if (c[6] == 'F')
        {
            L.pop_front();
        }
        else if (c[6] == 'L')
        {
            L.pop_back();
        }
        else if (c[0] == 'd')
        {
            cin >> x;
            for (list<int>::iterator it = L.begin(); it != L.end(); ++it)
            {
                if (*it == x)
                {
                    L.erase(it);
                    break;
                }
            }
        }
    }

    for (list<int>::iterator it = L.begin(); it != L.end(); ++it)
    {
        if (it != L.begin())
        {
            cout << " ";
        }

        cout << *it;
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 34400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProblemD
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray();
            var A = read[0];
            var B = read[1];
            var N = read[2];

            int res;
            if(N < B)
            {
                res = (int)(Math.Floor(A * N / B) - A * Math.Floor(N / B));
                Console.WriteLine(res);

            }
            else
            {
                res = (int)(Math.Floor(A * (B - 1) / B) - A * Math.Floor((B - 1) / B));
                Console.WriteLine(res);
            }

        }
    }
}


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

typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007

void solve(){
    ll n,k;cin>>n>>k;
    ll arr[n+1];
    rep(i,1,n+1)cin>>arr[i];
    vector<ll> v;
    ll tmp=1;v.push_back(1);
    bool flag=1;ll i,j=0;
    bool brr[n+1];
    rep(i,1,n+1)brr[i]=0;
    while(1){
        tmp=arr[tmp];//cout<<tmp<<"@ ";
        if(brr[tmp]==1){
            flag=0;
            break;
        }
        // for(auto x:v){
            
        //     if(tmp==x){
        //         flag=0;
        //         break;
        //     }
            //i++;        
        //}
        if(flag==1){ v.push_back(tmp);j++;brr[tmp]=1;}
        else break;
    }
    i=0;
    for(auto x: v){
        if(x==tmp){
            break;
        }
        i++;
    }
    //for (auto x: v)cout<<x<<" ";

    if(k<i)cout<<v[k];
    else {
        cout<<v[i+(k-i)%(j+1-i)];
    }
    


return ;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
   int t=1;
   //cin>>t;
   rep(i,0,t){
     solve();
  }
return 0;
}

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

int main(void){

    int N,M; cin>>N>>M;
    pair<long, int> a[N];
    for (int i = 0; i < N; ++i) {
        cin>>a[i].first>>a[i].second;
    }
    sort(a, a+N);
    long honsum=0, kanesum=0;
    for (int i = 0; i < N; ++i) {
        if(honsum+a[i].second>=M){
            kanesum += (M-honsum)*a[i].first;
            cout<<kanesum<<endl;
            return 0;
        }else{
            honsum += a[i].second;
            kanesum += (a[i].second)*(a[i].first);
        }
    }
    cout<<a<<endl;
    cout<<kanesum<<endl;
    return 0;
}

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

ll calc(string s, int flag)
{
	vector<string> sub;
	int off = 0;
	for (int p = 1; p < s.size(); ++p) {
		if (flag & 1) {
			sub.push_back(s.substr(off, p - off));
			off = p;
		}
		flag = flag >> 1;
	}
	sub.push_back(s.substr(off, s.size() - off));

	ll sum = 0;
	for (int i = 0; i < sub.size(); ++i) {
		sum += stoi(sub[i]);
	}
	return sum;
}

int main()
{
	string S; cin >> S;
	int flag = 0;
	for (int i = 0; i < S.size() - 1; ++i) {
		flag = (flag << 1) + 1;
	}
	ll sum = stold(S);
	while (flag) {
		sum += calc(S, flag);
		--flag;
	}
	cout << sum << endl;
}


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	int n; cin >> n;
	vi t(n);
	rep(i, n) cin >> t[i];
	int m; cin >> m;
	vi p(m), x(m);
	rep(i, m) cin >> p[i] >> x[i];

	vi tmp;
	rep(i, m){
		int ans = 0;
		tmp = t;
		tmp[p[i]-1] = x[i];
		rep(j, n){
			ans += tmp[j];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scan.nextInt();
        }
        long sum, min, max;
        sum = 0;
        max = -1000000;
        min = 1000000;
        for(int i = 0; i < n; i++){
            sum += a[i];
            if(max <= a[i]){
                max = a[i];
            }
            if(min >= a[i]){
                min = a[i];
            }
        }
        System.out.println(min + " " + max + " " + sum);
    }
}

Measured memory_bytes: 41460
using System;

namespace Sample1
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int alice = int.Parse(input.Split(' ')[0]);
            int bob = int.Parse(input.Split(' ')[1]);
            if (bob == alice)
            {
                Console.WriteLine("Draw");
            }
            else if (bob == 1 & alice != 1)
            {
                Console.WriteLine("Bob");
            }
            else if(alice == 1 & bob != 1)
            {
                Console.WriteLine("Alice");
            }
            else if(bob > alice & alice != 1)
            {
                Console.WriteLine("Bob");
            }
            else if(alice > bob & bob != 1)
            {
                Console.WriteLine("Alice");
            }
        }
    }
}

Measured memory_bytes: 11092
n, m = map(int, input().split())
dt = 0#一回回す時間
dt += (n - m) * 100#ms
dt += m * 1900#ms

'''
a / (1 - r)
'''
#p = 1 / (2 ** m)#一回でACの確率
#q1 = (dt * p) / (1 - (1 - p)) = dt
#q2 = q1 / (1 - (1 - p)) = q1 / p
q = dt * (2 ** m)
print(q)

Measured memory_bytes: 2940
import heapq
n=int(input())
a=list(map(int,input().split()))
q=a[0:n]
sums=[0]*(n+1)
sums[0]=sum(q)
heapq.heapify(q)
am=a[n:2*n]
for i in range(0,n):
    heapq.heappush(q,am[i])
    sums[i+1]=sums[i]+am[i]-heapq.heappop(q)
p=a[2*n:3*n]
p=list(map(lambda x: x*(-1),p))
sump=sum(p)
sums[n]+=sump
heapq.heapify(p)
for i in range(n-1,-1,-1):
    heapq.heappush(p,(-1)*am[i])
    sump=sump-am[i]-heapq.heappop(p)
    sums[i]+=sump
print(max(sums))

Measured memory_bytes: 120080
while True:
    try:
        a = float(raw_input())
        ans = 0
        for i in range(10):
            n = i+1
            if i == 0:
                ans += a
            elif n % 2 == 0:
                a *= 2
                ans += a
            else:
                a /= 3
                ans += a
        else:
            print ans
    except EOFError:
        break

Measured memory_bytes: 4224
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <vector>
#include <map>
#include <ctime>
#include <cmath>
#include <string.h>
#define inf 0x7fffffff
using namespace std;
struct P
{
    int x,y;
    bool operator<(const P &a)const{
        if(y!=a.y)
        return y>a.y;
        return x>a.x;
    }
};
vector<int> v[200456];
int a,b,c,n,m,i,k,o[4513],d,e,dy[5]={0,0,-1,1,0},dx[5]={0,1,1,1,2};
int l[300];
long long x,y,z[1111][33];
P u1[100100],u2[100100];
int j[200][10200];
priority_queue<P> q;
//long long x=0,y=0,z[99];

//deque<int> d;
//'1'==49;
map<int,int > p;
string r,r1;
//char r[1000];
bool asd(P a,P b)
{
   if(a.x-a.y!=b.x-b.y)
    return a.y-a.x<b.y-b.x;
   return a.x<b.x;
}

int f(int t,int w)
{
    if(w<0) return -1087654321;
    if(t==a) return 0;
    if(j[t][w]) return j[t][w];
    return j[t][w]=max(f(t+1,w-l[t+1])+o[t+1],f(t+1,w));

}

int main()
{
    scanf("%d %d",&a,&b);
    for(int t=0;t<a;t++)
    {
        cin>>r;
        for(int y=0;y<r.size();y++)
            l[r[y]]++;
    }
    n=((a-a%2)*(b-b%2));
    m=(b*(a%2)+a*(b%2)-(a%2)*(b%2)*2);
    i=(a%2)*(b%2);
    //printf("%d %d %d\n",n,m,i);
    for(int t='a';t<='z'&&n>0;t++)
        n-=(l[t]/4*4),l[t]-=(l[t]/4*4);
   // printf("%d %d %d\n",n,m,i);
    for(int t='a';t<='z'&&m>0;t++)
        m-=(l[t]/2*2),l[t]-=(l[t]/2*2);
    //printf("%d %d %d\n",n,m,i);
    for(int t='a';t<='z'&&i>0;t++)
        i-=(l[t]),l[t]-=(l[t]);
    //printf("%d %d %d",n,m,i);
    if(n==m&&m==i&&i==0)
        puts("Yes");
    else puts("No");
}


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

int main() {

  int n;
  cin >> n;

  if(n % 2 == 0) {
    cout << n / 2 << endl;
  } else {
    int ans = n / 2 + 1;
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/**
 *    author:  dattrinh
 *    created:    Codeforces Round #635
**/
#define pb push_back
#define fi first
#define ss second
#define tp(x) fixed<<setprecision(x)
using namespace std;
using ll = int64_t;
const int N = 1000003;
ll t;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    int t=0;
    int a[n];
    for(auto &i:a)cin>>i,t+=i;
    int k=0;
    for(int i=0;i<n;++i){
        if( ((t*1.0)/(4*m))<=(a[i]*1.0) ){
            k++;
        }
    }
    if(k>=m)cout<<"Yes";
    else cout<<"No";
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n;
cin >> n;
int p;
int ans=0;
int p_max=0;
REP(i,n) {
  cin >> p;
  ans+=p;
  p_max=max(p_max,p);
}
ans-=p_max/2;
cout << ans <<endl;
return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
long long x[200002],d[200002],c[200002];

int lis(int n){
	int i,j,I;
/*
	for(i=-1;I=0,++i<n;d[i]=I+1)
		for(j=i-1;~j;j--)
			if(x[j]<x[i]&&I<d[j])I=d[j];
*/
	// http://stackoverflow.com/questions/6129682/longest-increasing-subsequenceonlogn
	int sz = 1;
	c[1] = x[0];
	d[0] = 1;
	for(i=0;++i<n;){
		if(x[i] < c[1]){
			c[1] = x[i];
			d[i] = 1;
		}else if(x[i] > c[sz]){
			c[sz+1] = x[i];
			d[i] = sz+1;
			sz++;
		}else{
			int k = lower_bound(c,c+sz,x[i])-c;
			c[k] = x[i];
			d[i] = k;
		}
	}
	for(i=j=0;i<n;i++)
		if(d[i]>d[j])j=i;
	return d[j];
}

int main(){
	int x1,y1,x2,y2,n,xf=1,yf=1;
	scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&n);
	if(x1>x2)swap(x1,x2),xf=-1;
	if(y1>y2)swap(y1,y2),yf=-1;
	vector<pair<int,int>>v;
	for(int i=0;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		if(x1<=x&&x<=x2 && y1<=y&&y<=y2)v.emplace_back(x*xf,y*yf);
	}
	sort(v.begin(),v.end());
	n=0;
	for(auto &e:v)x[n++]=e.second;
	n=n?lis(n):0;
	printf("%.15f\n",100.0*(x2-x1+y2-y1)-20*n+5*(n+(n>=min(x2-x1,y2-y1)+1))*3.14159265358979323846);
}

Measured memory_bytes: 6640