akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
long double dist(long double a,long double b) {
	return a*a + b*b;
}
int main()
{  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    long double x[n],y[n];
    long double X=0,Y=0;
	for (int i = 0; i < n; i++) {
		cin>>x[i]>>y[i];
		X+=x[i];Y+=y[i];
	}
	X/=n; Y/=n;
	long double P=0.1,e,d;
	for (int i = 0;i< 30000; i++) {
		ll f = 0;
		d=dist(X- x[0],Y-y[0]);
		for (int j=1;j<n;j++) {
			e = dist(X-x[j],Y-y[j]);
			if (d<e) {d= e; f = j; }
		}
		X += (x[f] - X)*P;
		Y += (y[f] - Y)*P;
		P *= 0.999;
	}
	cout<<fixed;
	cout<<setprecision(10)<<sqrt(d);
}


Measured memory_bytes: 256
#include<iostream>

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

	std::cin >> a;
	std::cin >> c;
	std::cin >> b;

	if ('+'== c) {
		std::cout << a + b << std::endl;
	}
	if ('-' == c) {
		std::cout << a - b << std::endl;
	}

	return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

vector<int> ch(string s) {
        vector<int> r;
        rep (i, s.size()) r.push_back(s[i] - 'A');
        return r;
}

string hc(vector<int> v) {
        string s = "";
        rep (i, v.size()) s += (char)(v[i] + 'A');
        return s;
}

int main() {
        int n, a, b, c;
        cin >> n >> a >> b >> c;
        
        int d[] = {a, b, c}, m = a + b + c;

        vector<string> vs(n);
        rep (i, n) cin >> vs[i];
        
        bool f = true;
        vector<int> ans;
        rep (i, n) {
                auto v = ch(vs[i]);

                if (d[v[0]] == 0 && d[v[1]] == 0) {
                        f = false;
                        break;
                }

                if (m == 2 && i != n-1 && d[v[0]] == 1 && d[v[1]] == 1) {
                        auto nv = ch(vs[i + 1]);
                        if (v != nv) {
                                if (v[0] == nv[0] || v[0] == nv[1]) {
                                        d[v[0]]++;
                                        d[v[1]]--;
                                        ans.push_back(v[0]);
                                } else {
                                        d[v[0]]--;
                                        d[v[1]]++;
                                        ans.push_back(v[1]);
                                }
                                continue; 
                        }
                } 

                if (d[v[0]] > d[v[1]]) {
                        d[v[0]]--;
                        d[v[1]]++;
                        ans.push_back(v[1]);
                } else {
                        d[v[0]]++;
                        d[v[1]]--;
                        ans.push_back(v[0]);
                }
        }

        if (f) {
                cout << "Yes" << endl;
                rep (i, n) cout << char(ans[i] + 'A') << endl;
        } else {
                cout << "No" << endl;
        }

        return 0;
}


Measured memory_bytes: 7044
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    LL N,A,B;cin >> N >> A >> B;
    vector<LL> X(N);rep(i,N)cin >> X[i];

    vector<LL> sa(N-1);
    rep(i,N-1){
        sa[i] = X[i+1]- X[i];
    }   

    LL ans = 0;
    rep(i,N-1){
        if(A * sa[i] > B)ans += B;
        else ans += A*sa[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1920
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		String str = stdIn.nextLine();
		
		String[] word;
		word = str.split(" ");
		int[] num = new int[word.length];
		String[] check = new String[word.length];
		int index = 0;
		int max = 0;
		int len = 0;
		String longword = new String();
		for(int i = 0; i < word.length; i++){
			if( word[i].length() > len ){
				len = word[i].length();
				longword = word[i];
			}
			for(int j = 0; j < index; j++){
				if( word[i].equals(check[j]) ){
					num[j]++;
					if( num[j] > max ){
						max = num[j];
					}
				}
			}
			check[index] = word[i];
			num[index]++;
			index++;
		}
		String mode = new String();
		for(int i = 0; i < index; i++){
			if( num[i] == max ){
				mode = check[i];
			}
		}
		System.out.println(mode + " " + longword);
	}
}

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        cout<<fixed;
        cout<<setprecision(10);
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#ifdef BTK
#include<dvector.h>
#define DEBUG if(1)
#else
#define DEBUG if(0)
#endif

#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}

int N;
LL r[212345];
LL c[212345];

int R,C;
inline void input(){
    int br,bc,er,ec;
    cin>>br>>bc>>er>>ec;
    cin>>N;
    REP(i,N)cin>>r[i]>>c[i];
    if(br>er){
        br=1e8-br;
        er=1e8-er;
        REP(i,N)r[i]=1e8-r[i];
    }
    if(bc>ec){
        bc=1e8-bc;
        ec=1e8-ec;
        REP(i,N)c[i]=1e8-c[i];        
    }
    if(er-br>ec-bc){
        swap(br,bc);
        swap(er,ec);
        REP(i,N)swap(r[i],c[i]);
    }
    R=er-br;
    C=ec-bc;
    REP(i,N)r[i]-=br;
    REP(i,N)c[i]-=bc;
    
}
map<LL,LL> w;

bool dead_check(){
    int prv=0;
    if(R<212345){
        REP(i,R+1){
            if(w.count(i)==0)return false;
            if(w[i]<prv)return false;
            prv=w[i];
        }
        return true;
    }
    return false;
}
constexpr double X=5*acos(-1)-20;
constexpr double Y=10*acos(-1)-20;

#define BITTYPE int
#define BITCNT  1
#define BITSIZE 612345
namespace BIT_{
    int i=0;
    BITTYPE t[BITCNT][BITSIZE];
    inline BITTYPE* get(){
        i%=BITCNT;
        return t[i++];
    }
}
//[1,n],0は扱えない!
struct BIT{
    using T=BITTYPE;
    T* bit;
    int n;
    BIT(T* _table,int n):bit(_table),n(n){
        std::fill(bit,bit+n+1,0);
    }
    BIT(int n):BIT(BIT_::get(),n){}
    T sum(int i){
        T s=0;
        while(i>0){
            chmax(s,bit[i]);
            i-=i&-i;
        }
        return s;
    }
    void add(int i,T x){
        while(i<=n){
            chmax(bit[i],x);
            i+=i&-i;
        }
    }
};   
    


int main(){
    input();
    map<int,int> z;
    DEBUG cout<<R<<" "<<C<<endl;
    REP(i,N){
        if(r[i]>R)continue;
        if(r[i]<0)continue;
        if(c[i]>C)continue;
        if(c[i]<0)continue;
        w[r[i]]=c[i];
        z[c[i]]=0;
    }
    int cnt=0;
    for(auto &it:z)it.se=cnt++;
    for(auto &it:w)it.se=z[it.se];
    if(dead_check()){
        cout<<(R+C)*100.0+(R)*X+Y<<endl;
        return 0;
    }
    BIT bit(cnt+10);
    for(auto &it:w){
        bit.add(it.se+2,bit.sum(it.se+1)+1);
    }
    cout<<(R+C)*100.0+bit.sum(cnt+5)*X<<endl;;
    return 0;
}


Measured memory_bytes: 26496
#print('***')
N, K, Q = map(int, input().rstrip().split())
results = {}
for i in range(N):
    results[str(i + 1)] = 0
# print(results)
for i in range(Q):
    S = input().rstrip()
    results[S] += 1
for i in range(N):
    if K - (Q - results[str(i + 1)]) > 0:
        print('Yes')
    else:
        print('No')


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

flag = 0
for i in range(N-1):
  if A[i] < A[i+1]:
    pass
  else:
    flag = 1
    break
if flag == 0:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
int N;
int A[2][110];
int g[2][110];
int main() {
  cin >> N;
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < N; ++j) {
      cin >> A[i][j];
    }
  }
  for(int i = 0; i < 2; ++i) {
    for(int j = 0; j < N; ++j) {
      int p = 0;
      if (i > 0) p = max(p, g[i - 1][j]);
      if (j > 0) p = max(p, g[i][j - 1]);
      g[i][j] = max(g[i][j], p + A[i][j]);
    }
  }

  cout << g[1][N - 1];
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
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;
}

//////////////////////////


int main(){fastio
    ll x;cin>>x;
    set<ll>s;
    rep(a,0,10000){
        ll A=a*a*a*a*a;
        if(A>=1e18)break;
        s.insert(A);
    }
    
    rep(b,0,1000){
        ll B=b*b*b*b*b;
        ll sum=x+B;
        if(s.find(sum)!=s.end()){
            rep(a,0,10000){
                ll A=a*a*a*a*a;
                if(sum==A){
                    cout<<a<<" "<<b<<endl;return 0;
                }else if(sum==-A){
                    cout<<-a<<" "<<b<<endl;return 0;
                }
            }
        }
        sum=x-B;
        if(s.find(sum)!=s.end()){
            rep(a,0,10000){
                ll A=a*a*a*a*a;
                if(sum==A){
                    cout<<a<<" "<<-b<<endl;return 0;
                }else if(sum==-A){
                    cout<<-a<<" "<<-b<<endl;return 0;
                }
            }
        }
    }
    
    return 0;
}



Measured memory_bytes: 3840
#include <iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<cstdlib>
#include<cmath>

using namespace std;
int main(){
    string a,b,c;
    cin>>a>>b>>c;
    if(a.back()==b.front()&&b.back()==c.front())cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque


def bfs(S):  # 幅優先探索  # キュー
    que = deque([S])
    b, w = 0, 0
    while len(que) > 0:
        p, q = que.popleft()
        b += int(s[p][q] == '#')
        w += int(s[p][q] == '.')
        for i, j in near[p][q]:  # 移動先の候補
            if (i, j) in frag:  # 処理済みか否か
                continue
            que.append((i, j)), frag.add((i, j))
    return b * w


h, w = map(int, input().split())
s = [input() for _ in range(h)]

near = [[set() for j in range(w)] for i in range(h)]
for i, si in enumerate(s):
    for j, sij in enumerate(si):
        for p, q in [(i - 1, j), (i, j - 1), (i + 1, j), (i, j + 1)]:
            if 0 <= p < h and 0 <= q < w and s[p][q] != sij:
                near[i][j].add((p, q))

ans, frag = 0,set()
for i in range(h):
    for j in range(w):
        if (i, j) not in frag:
            frag.add((i, j))
            ans += bfs((i, j))
print(ans)


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

int main(){
	/*input*/
	int n;	cin >> n;
	int* p = new int[n]; 
	for(int i = 0; i < n; i++){
		cin >> p[i];
	}
	/*calculation*/
	int ans = 0; 
	sort(p, p + n);
	for(int i = 0; i < n; i++){
		if(i == n - 1)	ans += p[i]/2;
		else			ans += p[i];
	}
	/*output*/
	cout << ans << endl;
	delete[] p;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n=0,x=0,t=0;
  cin>>n>>x>>t;
  int r=0;
  if((n%x)==0)
  {
    int d=n/x;
    r=d*t;
  }
  else
  {
    int d=n/x;
    d+=1;
    r=d*t;
  }
  cout<<r<<endl;
  return 0;
}

Measured memory_bytes: 3600
n, m = map(int,input().split())
bri_join = [[i for i in map(int,input().split())] for j in range(m)]
ans = {} 
for i in range(n):
    ans[i+1] = 0 
    for j in range(m):
        if i+1 in bri_join[j]:
            ans[i+1] += 1
    print(ans[i+1])


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

def last_value(x):
    tmp2 = x
    for a in A:
        tmp = x
        x = a - tmp
    return x-tmp2

def bsearch(l,r):
    if l > r:
        return -1
    else:
        c = (l+r)//2
        last = last_value(c)
        if last < 0:
            return bsearch(l,c-1)
        elif last> 0:
            return bsearch(c+1,r)
        elif last == 0:
            return c
    
    
        
def solver(x):
    ans = [0] * N
    ans[0] = x*2
    for i,a in enumerate(A[:-1]):
        tmp = x
        x = a - tmp
        ans[i+1] = x * 2
    return ans


Left = 0
Right = min(A[0],A[N-1])

ans = solver(bsearch(Left,Right))

print(' '.join(map(str,ans)))

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

using namespace std;

struct peo
{
	int id,num;
}p[101000];
bool cmp(peo a,peo b)
{
	return a.id<b.id;
}
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++) scanf("%d",&p[i].id),p[i].num=i;
	sort(p+1,p+n+1,cmp);
	for(int i=1;i<=n;i++) printf("%d ",p[i].num);
	return 0;
}

Measured memory_bytes: 1536
#include<iostream>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;++i)
		cin>>a[i];
	int tot=0;
	for(int i=0;i<n;++i)
		tot+=a[i]>=k;
	cout<<tot<<endl;
	return 0;
}

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

int main() {
    long long N,K;
    cin >> N >> K;

    long long cnt0 = 0;
    long long cnt1 = 0;
    for(int i=1; i<=N; ++i) {
        if(i % K == 0) ++cnt0;
        if(i % K == K / 2) ++cnt1;
    }
    long long ans = cnt0 * cnt0 * cnt0;
    if(K % 2 == 0) {
        ans += cnt1 * cnt1 * cnt1;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int N;
    cin >> N;
    vector<double> v;
    double worse = 0;
    for (int i = 0; i < N; ++i)
    {
        double tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(v.begin(), v.end());

    for (int i = 0; i < N - 1; ++i)
    {
        worse = (v[0] + v[1]) / 2;
        v.erase(v.begin());
        v.erase(v.begin());
        v.insert(v.begin(), worse);
        sort(v.begin(), v.end());
    }
    cout << worse << endl;
}

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 30
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

int h,w;
string s[50];

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

bool ok(int i, int j){
  if(s[i][j] == '.') return true;
  REP(k,4){
    int ny = i + dy[k];
    int nx = j + dx[k];
    if(ny <0 || ny >= h || nx <0 || nx >=w) continue;
    if(s[ny][nx] == '#') return true;
  }
  return false;
}

int main(){
  cin >> h >> w;
  REP(i,h) cin >> s[i];
  REP(i,h)REP(j,w){
    if(ok(i,j)) continue;
    cout <<  "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  for(int i = 0; i < 1010; i++){
	  if(int(i*0.08)==a&&int(i*0.1)==b){
		  cout << i << endl;
		  exit(0);
	  }
  }
  cout << -1 << endl;
  return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
string S;

map <pair<string, string>, ll> cnt;


int main(){
  cin >> N >> S;


  for (int i = 0; i < (1 << N); i++){
    string T = "", U = "";
    ll num = i;
    for (int j = 2 * N - 1; j >= N; j--){
      if (num % 2 == 0) T += S[j];
      else U += S[j];
      num /= 2;
    }
    cnt[{T, U}]++;
  }


  ll ans = 0;
  for (int i = 0; i < (1 << N); i++){
    string T = "", U = "";
    ll num = i;
    for (int j = 0; j < N; j++){
      if (num % 2 == 0) T += S[j];
      else U += S[j];
      num /= 2;
    }
    ans += cnt[{T, U}];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 60892
#include<stdio.h>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=200100;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
int main(){
	int i,x,k=0,ans=0,n=read();
	for(i=1;i<=n;i++){
		x=read();
		if(x==k){k=0;ans++;}
		else k=x;
	}printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    
    int n;
    int a;
    int x=0,y=0,z=0;
    scanf("%d",&n);
    for(;~scanf("%d",&a);){
        a%2?z--:(a%4?y++:z++);
        /*
        if(a%2){
            z--;
        }else if(a%4){
            y++;
        }else{
            z++;
        }*/
    }
    //printf("%d %d\n",y,z);
    puts((!y&&z>-2||y&&z+1)?"Yes":"No");
}

Measured memory_bytes: 1640
N, X, M = map(int, input().split())

ans = 0
start = X % M
An = X % M
rList = []
repeat = 1
repeatStart = None
while True:
    ans += An
    rList.append(An)
    An = An**2 % M
    repeat += 1
    if An in rList:
        repeatStart = An
        break
# print(rList, repeatStart)

repStartIndex = rList.index(repeatStart)

extraPart = rList[0:repStartIndex]
repPart = rList[repStartIndex:]
# print(extraPart, repPart)
extraLen = len(extraPart)
repLen = len(repPart)

ans += (((N - extraLen) // repLen) - 1)* sum(repPart)


if (N - extraLen) % repLen > 0:
    rest = (N-extraLen) % repLen
    for i in range(rest):
        ans += repPart[i]
print(ans)


Measured memory_bytes: 69024
n, k = map(int,input().split())
m = n - k + 1 
def nCr(l,r,mod):
    if (r<0 or r>l):
        return 0
    r = min(r,l-r)
    return g1[l] * g2[r] * g2[l-r] % mod
mod = 10**9 + 7
N = 10**5
g1 = [1,1]
g2 = [1,1]
inverse = [0,1]
for i in range(2,N+1):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
for i in range(1,k+1):
    print(nCr(m,i,mod)*nCr(k-1,i-1,mod)%mod)

Measured memory_bytes: 15508
n = int(input())
s=[]
t=[]
for i in range(n):
    str = input().split()
    s.append(str[0])
    t.append(int(str[1]))
x=input()
total=0
if s.index(x)+1!=len(t):
    total=sum(t[s.index(x)+1:])
print(total)

Measured memory_bytes: 3064
/*
                    /\                          _--------- 
				   /  \                       _/
				  /    \                    _/
				 /      \                 _/ 
				/        \               |
		       /          \              | 
		      /------------\             | 
		     /              \            -\
		    /                \             -\
		   /                  \              -\
		  /                    \                -\________
*/
#include<iostream>
#include<cmath>
#include<algorithm>
#pragma GCC diagnostic error "-std=c++11"
#define ll long long
#define mp make_pair
using namespace std;
int n,m;
ll a[100010];
ll t[200010];
int main(){
	int i,j;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;++i) scanf("%d",a+i);
	ll sum=0;
	for(i=1;i<n;++i){
		int l=a[i-1],r=a[i];
		if(r<l) r+=m;
		++t[2+l],t[1+r]-=r-l,t[2+r]+=r-l-1;
		sum+=r-l;
	}
	ll ans=sum;
	for(j=2;j--;) for(i=1;i<=m<<1;++i) t[i]+=t[i-1];
	for(i=1;i<=m;++i) if(sum-(t[i]+=t[i+m])<ans) ans=sum-t[i];
	printf("%lld\n",ans);
}

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

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> d_index(M);
  vector<int> d_value(M);
  for (int i = 0; i < M; i++)
  {
    cin >> d_index.at(i) >> d_value.at(i);
  }
  string ans = string(N, '.');
  for (int i = 0; i < M; i++)
  {
    if (ans.at(d_index.at(i) - 1) != '.' && ans.at(d_index.at(i) - 1) != d_value.at(i) + '0')
    {
      ans = "00";
      break;
    }
    ans.at(d_index.at(i) - 1) = d_value.at(i) + '0';
  }
  if (ans.at(0) == '.' && ans.size() > 1)
  {
    ans.at(0) = '1';
  }
  for (int i = 0; i < ans.size(); i++)
  {
    if (ans.at(i) == '.')
    {
      ans.at(i) = '0';
    }
  }
  if (ans.size() > 1 && ans.at(0) == '0')
  {
    cout << -1 << endl;
  }
  else
  {
    cout << ans << endl;
  }
}


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

using namespace std;

using ll = long long;

struct Edge {
    int src, dst, w;
    Edge(int _s, int _d, int _w) : src(_s), dst(_d), w(_w) {}
    Edge() {}
};

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

    ll L;
    cin >> L;

    int d = 0;
    for (int p = 2; p <= L; p *= 2) ++d;

    const int n = d + 1;
    vector<Edge> edge;
    for (int i = 1, p = 1; i < n; ++i) {
        edge.emplace_back(Edge(i, i + 1, 0));
        edge.emplace_back(Edge(i, i + 1, p));
        p *= 2;
    }

    int sum = pow(2, d), res = L - sum;
    for (int i = d - 1; 0 <= i; --i) {
        if (res >> i & 1) {
            edge.emplace_back(Edge(i + 1, n, sum));
            sum += pow(2, i);
        }
    }

    // Output
    cout << n << ' ' << edge.size() << '\n';
    for (const auto &e : edge)
        cout << e.src << ' ' << e.dst << ' ' << e.w << '\n';

    return 0;
}


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

const int MAXN = 1e5+10;

int h[MAXN];
int m[MAXN];

int main() {
    int n,t;
    cin>>n>>t;
    for(int i=1;i<=n;i++) {
        cin>>h[i];
        m[i] = 0;
    }
    int a,b;
    while(t--) {
        cin>>a>>b;
        m[a] = max(m[a],h[b]);
        m[b] = max(m[b],h[a]);
    }
    int s = 0;
    for(int i=1;i<=n;i++) {
        if(h[i]>m[i]) {
            s++;
        }
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 4408
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

bool is_month(int x){
    return 1<=x && x<=12;
}

int main(){
    int N,K;
    cin>>N>>K;
    double kval=K;
    vi coin(18);
    vi border(18,1); //border[i]は、勝つためにサイコロi回が必要な初期得点の最小値
    // 10 5 2.5->3 1.25->2 0.625->1
    //K=10: ...10|9...5|4 3|2|1
    border[0]=K;
    int pow2[18]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072};
    for(int i=1;i<18;i++){
        kval/=2.0;
        int kfloor=floor(kval),kceil=ceil(kval);
        if(kfloor*pow2[i]>=K){
            border[i]=kfloor;
        }else{
            border[i]=kceil;
        }
    }
    // for(int i=0;i<18;i++){
    //     cout<<border[i]<<" ";
    // }
    // cout<<endl;
    double ans=0.0;
    for(int i=17;i>=0;i--){
        if(border[i-1]<=N+1){
            if(i>0){
                ans+=(border[i-1]-border[i])*1.0/pow2[i];
            }else{
                ans+=(N-border[i]+1);
            }
        }else{
            ans+=(N-border[i]+1)*1.0/pow2[i];
            break;
        }
        //cout<<i<<" "<<setprecision(13)<<ans/N<<endl;
    }
    cout<<fixed<<setprecision(15)<<ans/N<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main(){
  int T;
  while(cin>>T && T){
    vector<int> t(T);
    REP(i, T) cin>>t[i];
    int N;
    cin>>N;
    int start[100] = {};
    REP(i, 100) start[i] = 24;
    REP(i, N) {
      int D, M;
      cin>>D>>M;
      start[D-1] = min(start[D-1], M);
    }
    int dp[101][30] = {};
    REP(i, 101) fill(dp[i], dp[i] + 30, INF);
    dp[0][T - 1] = 0;
    REP(i, 100){
      REP(j, T)if(dp[i][j] < INF){
        int k = (j + 1) % T;
        dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + 1);
        if(t[k] <= start[i]) dp[i + 1][k] = min(dp[i + 1][k], dp[i][j]);
      }
    }
    int ans = INF;
    REP(i, T) ans = min(ans, dp[100][i]);
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int[][] x = new int[n][d];
		for (int i = 0; i < x.length; i++) {
			for (int j = 0; j < x[i].length; j++) {
				x[i][j] = Integer.parseInt(sc.next());
			}
		}
		int ans = 0;
		for (int i = 0; i < x.length - 1; i++) {
			for (int j = i + 1; j < x.length; j++) {
				int tmp = 0;
				double distance = 0;
				for (int j2 = 0; j2 < x[i].length; j2++) {
					tmp += Math.pow(x[i][j2] - x[j][j2], 2);
				}
				distance = Math.sqrt(tmp);
				if ((distance - (int) distance) == 0.0) {
					ans++;
				}
			}
		}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, x;
    cin >> a >> b >> x;
    if (x >= a && x <= a + b)
        cout << "YES";
    else
        cout << "NO";
}


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

void solve() {
	int num_of_animals, num_of_legs;
	bool ans = 0;
	cin >> num_of_animals >> num_of_legs;
	for (int i = 0; i < num_of_animals + 1; ++i) {
		if ((2 * i) + (4 * (num_of_animals - i)) == num_of_legs) {
			ans = 1;
			break;
		}
	}
	(ans) ? cout << "Yes" << endl : cout << "No" << endl;
}

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

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    string S;
    cin >> S;

    unordered_map<char, int> m;

    for (int i = 0; i < S.size(); ++i) {
        m[S[i]] = 1;
    }

    if (m.size() == 3) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
N = int(input())
S = list(map(int, list(input())))

ans = set()
for i in range(10):
  for j in range(10):
    for k in range(10):
      iflg = False
      jflg = False
      for s in S:
        if not iflg and s == i:
          iflg = True
        elif (not jflg) and iflg and s == j:
          jflg = True
          continue
        elif iflg and jflg and s == k:
          ans.add((i,j,k))
          break
print(len(ans))


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

double pi = 2.0 * asin(1.0);
double unit_r = 180.0 / pi;

int main() {
  double a, b, x;
  cin >> a >> b >> x;
  if ( a*a*b/2 <= x ) {
    double lim = a*a*b - x;
    printf("%.10f\n", atan(lim/a/a/a*2)*unit_r);
  } else {
    printf("%.10f\n", 90.0 - atan(x/b/b/a*2)*unit_r);
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
vector<char> Alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
vector<char> alphabet = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
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; }


int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  int r = N-1,cnt = 0;
  vector<char> c(N);
  rep(i,N) cin >> c[i];
  rep(i,N)
  {
    if(c[i]=='W')
    {
      for(int j=r;j>=i;j--)
      {
        if(c[j]=='R') 
        {
          swap(c[i],c[j]);
          r = j;
          cnt ++;
          break;
        }
        if(j==i)
        {
          cout << cnt << endl;
          return 0;
        }
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>

int main(void)
{
  int W , H , x , y , r;
  scanf("%d %d %d %d %d\n", &W, &H, &x, &y, &r);
  if(r + x > W || r + y > H || x - r < 0 || y - r < 0)
    printf("No\n");
  else
    printf("Yes\n");
  return 0;
}

Measured memory_bytes: 2688
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <utility>
#include <functional>

template <class T>
using greater_queue=std::priority_queue<T, std::deque<T>, std::greater<T>>;

template <class Weight>
struct Edge {
  size_t src, dst;
  Weight cost;
  Edge(size_t src, size_t dst, Weight cost):
    src(src), dst(dst), cost(cost)
  {}
};

template <class Weight>
using Graph=std::vector<std::vector<Edge<Weight>>>;

template <class Weight>
constexpr Weight inf=(Weight(1)<<(8*sizeof (Weight)-3));

template <class Weight>
std::vector<Weight> dijkstra(const Graph<Weight> &g, size_t s) {
  std::vector<Weight> dist(g.size(), inf<Weight>);
  greater_queue<std::pair<Weight, size_t>> q;
  dist[s] = 0;
  q.emplace(0, s);
  while (!q.empty()) {
    auto p=q.top();
    q.pop();
    Weight w=p.first;
    size_t v=p.second;
    if (w > dist[v])
      continue;

    for (const Edge<Weight> &e: g[v]) {
      if (dist[e.dst] > w + e.cost) {
        dist[e.dst] = w + e.cost;
        q.emplace(dist[e.dst], e.dst);
      }
    }
  }
  return dist;
}

int main() {
  size_t N;
  scanf("%zu", &N);

  Graph<intmax_t> g(N);
  for (size_t i=1; i<N; ++i) {
    size_t a, b;
    intmax_t c;
    scanf("%zu %zu %jd", &a, &b, &c);

    --a;
    --b;
    g[a].emplace_back(a, b, c);
    g[b].emplace_back(b, a, c);
  }

  int Q;
  size_t K;
  scanf("%d %zu", &Q, &K);
  --K;

  std::vector<intmax_t> dist=dijkstra(g, K);
  for (int i=0; i<Q; ++i) {
    size_t x, y;
    scanf("%zu %zu", &x, &y);
    --x;
    --y;

    printf("%jd\n", dist[x]+dist[y]);
  }
}


Measured memory_bytes: 11824
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    vector<long long> a(n);
    for(int i=0;i<n;++i) cin >> a[i];
    vector<long long> s(n+1);
    s[0] = 0;
    for(int i=0;i<n;++i){
        s[i+1] = s[i] + a[i];
    }
    map<long long,long long> mp;
    for(int i=0;i<=n;++i) mp[s[i]]++;
    long long ans=0;
    for(auto itr : mp){
        ans += itr.second*(itr.second-1)/2;
    }
    //ans += mp[0];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15872
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public long N, A, B, C, D;
        public long X;
        public void Run()
        {
            {
                var line = Input.ReadLongArray();
                N = line[0];
                A = line[1];
                B = line[2];
                C = line[3];
                D = line[4];
            }

            X = B - A;
            N--;

            for (int p = 0; p < N; p++)
            {
                long m = N - p;
                long mx = D * p - C * m;
                long mn = C * p - D * m;

                if (X >= mn && X <= mx)
                {
                    Console.WriteLine("YES");
                    return;
                }
            }

            Console.WriteLine("NO");

        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13396
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;

#define MOD (ll)(1e9+7)

int N;
const int MAX_N = 100;
char a[2][MAX_N];

ll dp[4][4][MAX_N];

ll solve(int lo,int hi,int x){
	if(x>=N)return 1;
	if(x>0&&a[0][x]==a[0][x-1])return solve(lo,hi,x+1);
	
	ll& ret=dp[lo][hi][x];
	if(~ret)return ret;
	ret=0;

	if(a[0][x]==a[1][x]){
		for(int i=1;i<=3;i++){
			if(i==lo)continue;
			if(i==hi)continue;
			ret+=solve(i,i,x+1);
			ret%=MOD;
		}
	}else{
		for(int i=1;i<=3;i++){
			if(i==lo)continue;
			for(int j=1;j<=3;j++){
				if(j==hi)continue;
				if(j==i)continue;
				ret+=solve(i,j,x+1);
				ret%=MOD;
			}
		}
	}
	return ret;
}

int main(){
	memset(dp,-1,sizeof(dp));

	scanf("%d",&N);
	
	for(int i=0;i<2;i++){
		scanf("%s",&a[i]);
	}
	
	printf("%lld\n",solve(0,0,0));

	return 0;
}


Measured memory_bytes: 128
N,M = [int(i) for i in input().split()]
nes = ['0'] * M
for i in range(M) :
    li = input().split()
    nes[i] = li
sum_ac = 0
sum_wa = 0
l = [0] * (N+1)
for i in range(N+1) :
    l[i] = True
r = [0] * (N+1)
rr = [0] * (N+1)
for i in range(M) :
    if nes[i][1] == "AC" :
        if l[int(nes[i][0])] :
            sum_ac+=1
            r[int(nes[i][0])]+=1
            l[int(nes[i][0])] = False
    if nes[i][1] == "WA" :
        if l[int(nes[i][0])] :
            sum_wa +=1
            rr[int(nes[i][0])] += 1
for i in range(1,N+1) :
    if r[i] == 0 :
        sum_wa -= rr[i]
print(sum_ac,sum_wa)

Measured memory_bytes: 34456
n, k, q = map(int, input().split(' '))
answers = [int(input()) for _ in range(q)]

points = [0] * n
for a in answers:
  points[a-1] += 1
for p in points:
  if k - (q - p) > 0:
    print('Yes')
  else:
    print('No')


Measured memory_bytes: 8636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=2000005,INF=1<<30;

vector<int> prime;//i番目の素数
bool is_prime[MAX+1];

void sieve(int n){
    for(int i=0;i<=n;i++){
        is_prime[i]=true;
    }
    
    is_prime[0]=is_prime[1]=false;
    
    for(int i=2;i<=n;i++){
        if(is_prime[i]){
            prime.push_back(i);
            for(int j=2*i;j<=n;j+=i){
                is_prime[j] = false;
            }
        }
    }
}

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<ll> A(N);
    for(int i=0;i<N;i++) cin>>A[i];
    sort(all(A));
    
    if(A[0]==0){
        cout<<0<<endl;
    }else{
        ll x=1;
        for(int i=0;i<N;i++){
            if(log10(x)+log10(A[i])>=18.1){
                cout<<-1<<endl;
                return 0;
            }else{
                x*=A[i];
            }
        }
        
        if(x<=1000000000000000000) cout<<x<<endl;
        else cout<<-1<<endl;
    }
}



Measured memory_bytes: 4056
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
string s;
void rec(int n , char MAX) {
    if(n==0) {
        cout << s << endl;
        return;
    }
    for(int i=0;i<=(MAX-'a')+1;i++) {
        bool ok = false;
        if(i <= (MAX-'a')) {
            s.push_back('a'+i);
        } else {
            s.push_back(MAX+1);
            ok = true;
        }
        if(ok) rec(n-1, MAX+1);
        else rec(n-1, MAX);
        s.pop_back();
    }
}
int main() {
    int n; cin >> n;
    n--; s.push_back('a');
    //cout << s.back();
    rec(n,'a');
}


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

int main() {
    int a,b;
    cin >> a >> b;
    if (a==b) cout << "Draw" << endl;
    else {
        bool flag=false;
        if (a==1) flag=true;
        else if (a>b && b!=1) flag=true;
        if (flag) cout << "Alice" << endl;
        else cout << "Bob" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include <cmath>
using namespace std;
int main(){
    int N;
    cin >> N;

    int temp = N;
    int keta = 0;
    while(temp != 0){
        temp /= 10;
        keta++;
    }

    int sum = 0;
    if(keta == 1){
        sum += N;
        keta -= 1;
    }
    else if(keta % 2 == 1){
        sum += (N - pow(10, keta-1)) + 1;
        keta -= 1;
    }
    while(keta != 0){
        if(keta ==1){
            sum += 9;
            keta -= 1;
        }
        else if(keta % 2 == 1){
            sum += pow(10, keta) - pow(10, keta-1);
            keta -= 1;
        }
        else{
            keta -= 1;
        }
    }

    cout << sum;
}

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

c = 0
l = 0
while True:
    # update l
    while l != n and hn[l] == 0:
        l += 1
    if l == n:
        break

    # update r
    r = l
    min_num = 1e3
    while r != n and hn[r] != 0:
        min_num = min(min_num, hn[r])
        r += 1
    
    # watering
    for i in range(l, r):
        hn[i] -= min_num
    c += min_num

print(c)

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

using VI = vector<long>;
struct tree {
  int node;
  tree *left;
  tree *right;
};

int p;
tree *parse(string s) {
  tree *t;
  t = (tree*)malloc(sizeof(tree));
  // left
  assert(s[p] == '(');
  if (s[p+1] == ')') {
    p += 2;
    return NULL;
  } else {
    p++;
    t->left = parse(s);
  }
  // center
  assert(s[p] == '[');
  p++;
  int l = 0;
  while(s[p+l] != ']') {
    l++;
  }
  t->node = stoi(s.substr(p, l));
  p += l+1;
  // right
  assert(s[p] == '(');
  t->right = parse(s);
  p++;
  return t;
}

string t_to_str(tree *t) {
  if (t == NULL) {
    return "";
  }
  return "(" + t_to_str(t->left) + ")[" + to_string(t->node) + "](" + t_to_str(t->right) + ")";
}

tree *get_sum(tree *t1, tree *t2) {
  tree *t;
  if (t1 == NULL || t2 == NULL) {
    return NULL;
  } else {
    t = (tree*)malloc(sizeof(tree));
    t->node = t1->node + t2->node;
    t->left = get_sum(t1->left, t2->left);
    t->right = get_sum(t1->right, t2->right);
    return t;
  }
}

int main() {
  string A, B;
  cin >> A >> B;
  if (A != "()") {
    A = "(" + A + ")";
  }
  if (B != "()") {
    B = "(" + B + ")";
  }

  tree *a, *b;
  p = 0;
  a = parse(A);
  p = 0;
  b = parse(B);
  cout << t_to_str(get_sum(a, b)) << endl;
}



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

typedef unsigned long long ULL;
const int N=2e5+50;
const ULL base=31; 

int n,k,tag; 
char ch[N];
ULL pw[N],val[2];

tr1::unordered_map <ULL,int> s;
deque <int> q;
 
inline void print() {
	for(int i=1;i<=n;i++) 
		putchar((q[i-1]^tag) ? 'B' : 'A');
}
inline void rec() {
	if(!(q[0]^tag)) {q[0]^=1; return;}  
	q.pop_front();
	tag^=1;
	q.push_back(tag);
}

int main() {
	scanf("%d%d%s",&n,&k,ch+1);
	pw[0]=1; for(int i=1;i<=n;i++) pw[i]=pw[i-1]*base;
	for(int i=1;i<=n;++i) q.push_back((ch[i]=='A') ? 0 : 1);
	
	if(k<=2*n) {
		for(int i=1;i<=k;i++) rec();
		print();
	} else {
		for(int i=0;i<n;i++) {
			val[0]+=q[i]*pw[n-i];
			val[1]+=(q[i]^1)*pw[n-i];
		}  s[val[0]]=0;
		int cir=0,i;
		for(i=1;;++i) {
			if(!(q[0]^tag)) {
				val[1]-=pw[n];
				val[0]+=pw[n];
				q[0]^=1;
			} else {
				val[0]-=(q[0]^tag)*pw[n];
				val[1]-=(q[0]^tag^1)*pw[n];
				rec();
				swap(val[0],val[1]); 
				val[0]*=base; val[1]*=base;
				val[1]+=base;
			}
			if(s.count(val[0])) {cir=i-s[val[0]]; break;}
			else s[val[0]]=i;
		}
		int t=(k-i)%cir;
		while(t--) rec();
		print();
	}
}

Measured memory_bytes: 16968
#include <iostream>

using namespace std;


int main(){
    long long a,b,c,n;
    cin >> a >> b >> c >> n;
    if(abs(a-b)>1000000000000000000){
        cout << "Unfair" << endl;
    }else{
        if(n%2==0){
            cout << a-b << endl;
        }else{
            cout << b-a << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a += b;
	if(a>MOD){
		a -= MOD;
	}
}

int bitree[123],n;

int query(int p){
	int v = 0;
	while(p){
		v += bitree[p];
		p -= (p&(-p));
	}
	return v;
}

void update(int p, int v){
	while(p<=n){
		bitree[p] += v;
		p += (p&(-p));
	}
}

int a[123];
bool f[123];

vector<int> ans;

int main(void){
	int i,j;
	cin >> n;
	for(i=1; i<=n; ++i){
		update(i,1);
		f[i] = true;
		cin >> a[i];
	}
	for(i=n; i>0; --i){
		for(j=n; j>0; --j){
			if(!f[j]){
				continue;
			}else if(a[j]>i){
				cout << "-1" << endl;
				return 0;
			}
			if(a[j]==query(j)){
				f[j] = false;
				update(j,-1);
				ans.push_back(a[j]);
				break;
			}
		}
	}
	for(i=(n-1); i>=0; --i){
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 764
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp
//ベルマンフォード法
#include<iostream>
#define MAX_V 100000
#define MAX_E 500000
#define INF 1e9
using namespace std;
struct edge {
	int from, to, cost;
};
edge es[MAX_E];
int d[MAX_V];
int V;
int E;



bool find_negative_loop(int s)
{
	d[s] = 0;
	int count = 0;
	while (true)
	{
		bool update = false;
		count++;
		for (int i = 0; i < MAX_E; i++)
		{

			if (d[es[i].from] != INF && d[es[i].to] > d[es[i].from] + es[i].cost)
			{
				if (count == V)
				{
					return true;
				}
				d[es[i].to] = d[es[i].from] + es[i].cost;
				update = true;
			}
		}
		if (update == false)
		{
			break;
		}


	}
	return false;
}

int main()
{

	int r;
	cin >> V >> E >> r;
	for (int i = 0; i < MAX_V; i++)
	{
		d[i] = INF;
	}
	for (int i = 0; i < E; i++)
	{
		cin >> es[i].from >> es[i].to >> es[i].cost;
	}
	if (find_negative_loop(r))
	{
		cout << "NEGATIVE CYCLE" << endl;
	}
	else
	{
		for (int i = 0; i < V; i++)
		{
			if (d[i] == INF)
			{
				cout << "INF" << endl;
			}
			else
			{
				cout << d[i] << endl;
			}
		}
	}

	return 0;
}



Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

  int r, g; cin >> r >> g;
  cout << (2 * g) - r << endl;

  return 0;
}

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

namespace AtCoderTest
{
    class PlacingMarbles
    {
        static int countFromString(string inStr)
        {
            int res = 0;
            for (int i=0; i<3; ++i)
                if (int.Parse(inStr.Substring(i, 1)) > 0)
                    res++;

            return res;
        }

        public static string core()
        {
            var inStr = Console.ReadLine();
            var retStr = countFromString(inStr).ToString();
            return retStr;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Console.Write(PlacingMarbles.core());
        }
    }

}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
const long long int INF = 1e18L + 5;
int main(){
    int n,W,sum=0;
    cin>>n>>W;
    int wt[n];
    int val[n];
    for(int i=0;i<n;i++){
        cin>>wt[i]>>val[i];
        sum += val[i];
    }
    int N = sum + 1;
    vector<long long int> dp(N,INF);
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j = sum;j>=val[i];j--){
            dp[j] = min(dp[j],wt[i]+dp[j-val[i]]);
        }
    }
//    for(int i=9;i<20;i++){
//        cout<<dp[i]<<" ";
//    }
//    cout<<endl;
    int ans = 0;
    for(int i=0;i<=sum;i++){
        if(dp[i]<=W){
            ans = max(ans,i);
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1024