akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;

    // 成功するまでの回数の期待値
    int it = 1;
    for (int i = 0; i < M; i++) it *= 2;

    int ans = (100*(N - M) + 1900*M)*it;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
 int n;
 int num[110];
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&num[i]);
    }
    int res = 1<<20;
    for(int i=-100;i<=100;i++)
    {
        int sum = 0;
        for(int j=0;j<n;j++)
        {
            sum+=(i-num[j])*(i-num[j]);
        }
        res = min(res,sum);
    }
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
print(n ** 3)

Measured memory_bytes: 74604
from collections import deque

h,w=map(int,input().split())
S=[]
pos=[]
for i in range(h):
  l=input()
  L=[]
  for j in range(w):
    if l[j]=='.':
      L.append('.')
      pos.append((i,j))
    else:
      L.append('#')
  S.append(L)
Maze=[[float('inf')]*w for i in range(h)]
def bfs(h,w,S,Maze,sy,sx):
    maze=Maze
    maze=[[float('inf')]*w for i in range(h)]
    maze[sy][sx]=0
    que=deque([[sy,sx]])
    while que: #キューの中に入っているということはまだ調べる余地有り
        y,x=que.popleft()
        for (i,j) in [(1,0),(0,1),(-1,0),(0,-1)]:
            nexty,nextx=y+i,x+j
            if 0<=nexty<=h-1 and 0<=nextx<=w-1:
              dist=maze[nexty][nextx]
              if S[nexty][nextx]!='#':
                if dist>maze[y][x]+1: #今の経路から(nexty,nextx)に進む方が距離が短くなるなら
                    maze[nexty][nextx]=maze[y][x]+1
                    que.append([nexty,nextx])
    m=0
    for i in range(h):
      for j in range(w):
        if maze[i][j]!=float('inf'):
          if m<maze[i][j]:
            m=maze[i][j]
            
    return m
        
M=0
for (sy,sx) in pos:
  if bfs(h,w,S,Maze,sy,sx)>M:
    M=bfs(h,w,S,Maze,sy,sx)

print(M)     


Measured memory_bytes: 46812
//By Ralif Rakhmatullin
#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
#include<math.h>
#include<cassert>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<map>
#include<ctime>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<valarray>
#include<iterator>
#include<list>
#define ll long long
#define ull unsigned long long
#define mp make_pair
#define S second
#define ld long double
#define F first
#define y1 LOL
#define ld long double
#define pb push_back
#define len length
#define sz size
#define beg begin
const ll INF = (ll)1e18 + 123;
const int inf=(int)2e9 + 123; 
const int mod=1e9+7;
using namespace std;
int n;
string ans = "", s = "", z[12];
void solve(){
	int l = 1, r = 10, sz = 1;
	while(l <= r){
		int tm = (l + r) / 2;
		cout << "? ";
		for(int i = 1; i <= tm; i ++){
			cout << "9";
		}
		cout << endl;
		char x;
		cin >> x;
		if(x == 'Y'){
			sz = tm;
			r = tm - 1;
		}else
			l = tm + 1;
	}
	cout << "! 1";
	for(int i = 1; i < sz; i ++)
		cout << "0";
	cout << endl;
}
int main(){
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  	srand(FOR);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int l = 1, r = 10, sz = 1;
	char f;
	cout << "? 1000000000" << endl;
	cin >> f;
	if(f == 'Y'){
		solve();
		return 0;
	}
	while(l <= r){
		int tm = (l + r) / 2;	
		s = "1";
		for(int i = 1; i < tm; i ++){
			s += '0';
		}
		cout << "? " << s << endl;
		char x;
		cin >> x;
		bool is = 1;
		if(x == 'Y'){
			sz = tm;
			l = tm + 1;
		}else
			r = tm - 1;
	}
	s = "";
	for(int i = 1; i <= sz; i ++){
		z[i] = z[i - 1] + '9';
	}
	for(int i = 0; i < sz; i ++){
		l = 0, r = 9;
		int d = 9;
		if(i == 0)
			l = 1;
		while(l <= r){
			int tm = (l + r) / 2;
			cout << "? " << s << char(tm + '0') << z[sz - i] << endl;
			char x;
			cin >> x;
			if(x == 'Y'){
				d = tm;
				r = tm - 1;
			}else
				l = tm + 1;
		}
		s += char(d + '0');
	}
	cout << "! " << s << endl;	
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;
int N;
string S;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    cin >> S;
    int lpar = 0;
    int rpar = 0;
    rep(i, N)
    {
        if (S[i] == '(') {
            ++rpar;
        } else {
            if (rpar == 0) {
                ++lpar;
            } else {
                --rpar;
            }
        }
    }
    string res = "";
    rep(i, lpar) {
        res += "(";
    }
    res += S;
    rep(i, rpar) {
        res += ")";
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
import java.util.Random;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int length1 = scanner.nextInt();
		int[] arr1 = new int[length1];
		
		for(int i=0;i<length1; i++) {
			arr1[i] = scanner.nextInt();
		}
		
		int length2 = scanner.nextInt();
		int[] arr2 = new int[length2];
		
		for(int i=0;i<length2; i++) {
			arr2[i] = scanner.nextInt();
		}
		//Binary Search
		int count = 0;
		for(int i=0; i<length2; i++) {
			int left = 0;
			int right = length1 -1;
			
			Boolean cont = true;
			while(left <= right && cont == true) {
				int mid = (left +right)/2;
				
				if(arr2[i]==arr1[mid]) {
					count++;
					cont = false;}
				if(arr2[i] > arr1[mid])
					left = mid + 1;
				if(arr2[i] < arr1[mid])
					right = mid - 1;
			}
			
		}
		System.out.println(count);
		
	}
}


Measured memory_bytes: 68064
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 101000
using namespace std;
inline void read(int &x)
{
	x=0;
	int p=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
	while(isdigit(c)) {x=(x<<1)+(x<<3)+(c^'0');c=getchar();}
	x*=p;
}
int n;
int a[N];
int flag;
int ans;
int main()
{
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	read(n);
	for(int i=1;i<=n;i++)
		read(a[i]);
	for(int i=1;i<=n;i++)
	{
		if(a[i]==i)
		{
			if(i==1)swap(a[i],a[i+1]),ans++;
			else 
			{
				if(a[i+1]==i+1)swap(a[i+1],a[i]),ans++;
				else swap(a[i-1],a[i]),ans++;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include<vector>
using namespace std;
void reverse(string &s)
{
    int n=s.length();
    for (int i=0;i<n/2;i++)
    {
        swap(s[i],s[n-i-1]);
    }
    return;
    
}
int main() {
    string s1,s2;
    cin>>s1>>s2;
    int n1=s1.length(),n2=s2.length();
    vector<vector<int>> dp(s1.length()+1);
    for (int i=0;i<n1+1;i++)
    {
        vector<int> v1(n2+1);
        dp[i]=v1;
    }
    
    for (int i=1;i<n1+1;i++)
    {
        for (int j=1;j<n2+1;j++)
        {
            if(s1[i-1]==s2[j-1])
            {
              dp[i][j]=dp[i-1][j-1]+1 ; 
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    string ans;
    while (n1>0 and n2>0)
    {
        if (dp[n1][n2]==dp[n1-1][n2])
        {
            n1--;
        }
        else if (dp[n1][n2]==dp[n1][n2-1])n2--;
        else {
            ans=ans+s1[n1-1];
            n1--;
            n2--;
        }
    }
    reverse(ans);
    cout<<ans;
    
}

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

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

    string subs,a="a",b="b";
    int i=1;

    while(a!=b){
        subs=s.substr(0,s.size()-2*i);
        a=subs.substr(0,(s.size()-2*i)/2);
        b=subs.substr((s.size()-2*i)/2,(s.size()-2*i)/2);
        i++;
    }

    cout<<subs.size()<<endl;
}

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



int main() {
    string S;
    cin >> S;
    reverse(S.begin(), S.end());
    vector<int> F(10);
    for(int i=0; i<10; ++i) {
        F[i] = S[i] - '0';
    }
    int b2[10];
    b2[0] = 1;
    b2[1] = 1;
    for(int i=2; i<10; ++i) {
        b2[i] = b2[i-1]*2;
    }

    long long int sum=0;
    for(int i = 0; i < S.size(); ++i) {
        for(int j=i; j<S.size(); ++j) {
            long int a=0;
            long int x=1;
            for(int k=0; k<j-i+1; ++k) {
                a += F[i+k]*x;
                x *= 10;
            }
            sum += a*b2[i]*b2[S.size()-j-1];
        }
    }
    cout << sum << endl;

}

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

const int N = 3e5 + 9;

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long long a, va, b, vb, t; cin >> a >> va >> b >> vb >> t;
	if (a < b) {
		if (b + vb * t <= a + va * t) cout << "YES\n";
		else cout << "NO\n";
	}	
	else {
		if (b - vb * t >= a - va * t) cout << "YES\n";
		else cout << "NO\n";
	}
    return 0;
}

Measured memory_bytes: 3652
X, Y = map(int, input().split())
n = 0
t_leg = 2
k_leg = 4

for i in range(101):
    for s in range(101):
        if X - i - s == 0 and Y - 2 * i - 4 * s == 0:
            n += 1

if n > 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9132
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<ll> A(n);
    for(int i = 0; i < n; i++) cin >> A[i];
    sort(A.begin(), A.end());
    vector<pair<ll, ll>> v;
    for(int i = 0; i < m; i++)
    {
        ll b, c; cin >> b >> c;
        v.push_back(make_pair(c, b));
    }
    sort(v.begin(), v.end(), greater<pair<ll, ll>>());
    ll ans = 0, p = 0;
    for(int i = 0; i < m; i++)
    {
        auto itr = upper_bound(A.begin() + p, A.end(), v[i].first);
        if(itr - A.begin() == p) continue;
        ll d = min(v[i].second, ll(itr - A.begin() - p));
        ans += v[i].first * d;
        p += d;
    }
    for(int i = p; i < n; i++) ans += A[i];
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
ll LINF = numeric_limits<ll>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i = 0; i < n; i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'

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

    int x;
    cin >> x;
    vector<int> a;
    a.push_back(1);
    for(int i = 2; i <= x; i++){
        int p = 2;
        while(pow(i,p) <= x){
            a.push_back(pow(i,p));
            p++;
        }
    }
    sort(a.begin(), a.end());
    int ans = 0;
    for(int i = 0; i < a.size(); i++){
        if(a[i] <= x) ans = a[i];
        else break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int N, K;
	scanf("%d %d", &N, &K);
	int ujian[N+1];
	for(int i =0; i<N; i++){
		scanf("%d", &ujian[i+1]);
	}
	for(int i= K+1; i<= N; i++)	{
		if(ujian[i] > ujian[i-K]){
			printf("Yes\n");
		}
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 2396
#include<bits/stdc++.h>
using namespace std;
 map<string,int>m;
main()
{
  
  string s;
  long long int n,i,j,k;
  cin>>n;
  for(i=0;i<n;i++)
  {
      cin>>s;
      m[s]++;
  }
  cout<<m.size()<<endl;
}

Measured memory_bytes: 19176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		if(B.substring(0,A.length()). equals (A)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35680
#include <bits/stdc++.h>
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main() {
  string N;
  cin >> N;
  cout << (N[0] == N[2] ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bn begin()
#define en end()
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define mod 1000000007
#define pi 3.141592653589
using namespace std;

int power(int x, int y) ;
int gcd(int a, int b) ;


signed main() {
    quickie
    char a ;
    cin >> a ;
    if(a >= 'a' && a <= 'z') cout << "a\n" ;
    else cout << "A\n" ;
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}

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


Measured memory_bytes: 3632
#include "bits/stdc++.h"

using namespace std;
using uint = unsigned int;
using int64 = long long;
using i64 = int64;
using uint64 = unsigned long long;
using vint = vector<int>;
using vint64 = vector<int64>;
template<typename T>
using p_que = priority_queue<T>;
#define rep(i,N) for(int i=0;i<(int)(N);++i)
#define rep1(i,N) for(int i=1;i<=(int)(N);++i)
#define fs first
#define sc second
#define eb emplace_back
#define all(x) x.begin(),x.end()

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...));
}

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "[";
	for (auto& e : v) os << e << ", ";
	return os << "]";
}

template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U> p) {
	return os << "P(" << p.first << ", " << p.second << ")";
}

template<class T, class U> ostream& operator<<(ostream& os, const map<T, U>& mp) {
	os << "{";
	for (auto& e : mp) os << e << " ";
	return os << "}";
}

void Main();
signed main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	Main();
}

/* Cut from here! */

template <uint mod> struct ModInt {
	uint x;
	ModInt(int64_t y = 0) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
	ModInt& operator+=(const ModInt& p) {
		if ((x += p.x) >= mod) x -= mod;
		return *this;
	}
	ModInt& operator-=(const ModInt& p) {
		x = (int)(1ll * x * p.x % mod);
		return *this;
	}
	ModInt& operator/=(const ModInt& p) {
		*this *= p.inverse();
		return *this;
	}
	ModInt operator-() const {
		return ModInt(-x);
	}
	ModInt operator+(const ModInt& p) const {
		return ModInt(*this) += p;
	}
	ModInt operator-(const ModInt& p) const {
		return ModInt(*this) -= p;
	}
	ModInt operator*(const ModInt& p) const {
		return ModInt(*this) *= p;
	}
	ModInt operator/(const ModInt& p) const {
		return ModInt(*this) /= p;
	}
	bool operator==(const ModInt& p) const {
		return x == p.x;
	}
	bool operator!=(const ModInt& p) const {
		return x != p.x;
	}
	ModInt inverse() const {
		int a = x, b = mod, u = 1, v = 0, t;
		while (b > 0) {
			t = a / b;
			swap(a -= t * b, b);
			swap(u -= t * v, v);
		}
		return ModInt(u);
	}
	ModInt pow(int64_t n) const {
		ModInt ret(1), mul(x);
		while (n > 0) {
			if (n & 1) ret *= mul;
			mul *= mul;
			n >>= 1;
		}return ret;
	}
	friend ostream& operator<<(ostream& os, const ModInt& p) {
		return os << p.x;
	}
};


//#define int long long
const uint MOD = 1e9 + 7;

template<typename T>
void swaper(T& a, T& b) {
	a = a ^ b;
	b = a ^ b;
	a = a ^ b;
}

void print(const multiset<int>& s) {
	for (auto& e : s) cout << e << endl;
}

void Main() {
	int N; cin >> N;
	auto c = make_v(N, 0, 0);
	rep(i, N) {
		int M; cin >> M;
		c[i].assign(M, 0);
		rep(j, M) cin >> c[i][j];
	}

	i64 ans = 0;
	p_que<i64> que;
	for (int i = N - 1; i >= 0; --i) {
		rep(j, c[i].size()) {
			que.emplace(c[i][j]);
		}
		ans += que.top();
		que.pop();
	}

	cout << ans << endl;
}


Measured memory_bytes: 19120
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main() {
	int N, A, B;
	cin >> N; cin >> A; cin >> B;
	if ((B - A) % 2 == 1) {
		cout << "Borys" << endl;
	}
	else {
		cout << "Alice" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define p push
#define ll long long
#define f first
#define s second
#define vi vector<int>
#define vll vector<long long>
#define all(vec) begin(vec), end(vec)
#define pii pair<int,int>
#define plli pair<ll,int>
#define pill pair<ill>
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
using namespace std;
ll dp[2010];
int s;
int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s;
    dp[0] = 1;
    for(int i = 3; i <= s; i++){
        for(int j = 0; j <= i-3; j++){
            dp[i] = (dp[i]+dp[j])%(ll)1000000007;
        }
    }
    cout << dp[s] << '\n';
    return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N,0);
  for (int i = 0; i < N; i++){
    int d;
    cin >> d;
    vec.at(i) = d;
  }
  sort(vec.begin(), vec.end());
  
  int h = 1;
  for (int i = 0; i < N - 1; i++){
    if (vec.at(i+1) != vec.at(i)){
      h++;
    }
  }
  cout << h << endl;
}

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  string s,t;cin>>s>>t;
  cout<<t<<s<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
  int n,r[200000],i,j,max,min;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&r[i]);
  }
  max=-1000000000;
  min=r[0];
  for(i=1;i<n;i++){
    max=max>r[i]-min ? max:r[i]-min;
    min=min<r[i] ? min:r[i];
  }
  printf("%d\n",max);
  return(0);
}

Measured memory_bytes: 1376
#include<bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define ins insert
typedef std::pair<int,int> pii;
typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int f[210],x,y,ans;

int main(){
	f[1]=3e5;f[2]=2e5;f[3]=1e5;
	scanf("%d%d",&x,&y);
	ans=f[x]+f[y];
	if(x==y&&x==1){
		ans+=(int)4e5;
	}
	printf("%d\n",ans);
	return 0;
} 

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

int main(){
  int n, m;
  cin >> n >> m;
  vi vec(n);
  rep(i,m){
    int a, b;
    cin >> a >> b;
    if (a == 1){
       vec.at(b)++;
    }
    if (b == n){
      vec.at(a)++;
    }
  }
  rep(i,n){
    if (vec.at(i) > 1){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 4060
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"
ll a[3002],dp[3002][3002][2];
ll n;
ll fx(ll i, ll j, ll turn)
{
	if(i>j)
		return dp[i][j][turn]=0;
	if(i==j)
	{
		if(turn == 0)
			return dp[i][j][turn] = a[i];
		else
			return dp[i][j][turn] = -a[i];
	}
	if(dp[i][j][turn] != -1)
		return dp[i][j][turn];
	if(turn == 0)
		return dp[i][j][turn] = max(fx(i+1, j, turn^1) + a[i], fx(i, j-1, turn^1) + a[j]);
	else
		return dp[i][j][turn] = min(fx(i+1, j, turn^1) - a[i], fx(i, j-1, turn^1) - a[j]);
}	
int main()
{
	ios_base::sync_with_stdio(false);
	ll i,j;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=0;i<3002;i++)
		for(j=0;j<3002;j++)
			dp[i][j][0] = dp[i][j][1] = -1;
	cout<<fx(0, n-1, 0)<<nl;
	return 0;
}

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

int main(){
  while(1){
    int data[101],i,j,k,result;
    int N,K; cin >> N >> K;
    if( N == 0 && K == 0 ) break;

    for( i = 0; i < N; i++ ) cin >> data[i];
  
    int max = -1;
    for( i = 0; i <= N-K; i++ ) {
      result = 1;
      for( j = i; j < i+K; j++ ){
	result *= data[j];
	if( max < result ) max = result;
      }
    }
    
    int max2 = -1;
    int result2;
    for( i = 0; i < N; i++ ){
      for( j = 0; j < N; j++ ){
	if( i != j ){
	  swap( data[i],data[j] );
	  for( k = 0; k <= N-K; k++ ) {
	    result2 = 1;
	    for( int l = k; l < k+K; l++ ){
	      result2 *= data[l];
	      if( max2 < result2 ) max2 = result2;
	    }
	  }
	  swap( data[i],data[j] );
	}
      }
    }

    int ans = max2 - max;

    if( ans >= 0 ) cout << ans << endl;
    else cout << "NO GAME" << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
package main

import (
    "bufio"
    "os"
    "strconv"
    "fmt"
    "container/heap"

)

/*********** PriorityQueue ***********/
type PriorityQueue struct {
    arr []interface{}
    comps []CompFunc
}

/*
p < q ... -1
p == q ... 0
p > q ... 1
*/
type CompFunc func(p, q interface{}) int

func NewPriorityQueue() *PriorityQueue {
    return new(PriorityQueue)
}

func (pq PriorityQueue) Len() int {
    return len(pq.arr)
}

func (pq PriorityQueue) Swap(i, j int) {
    pq.arr[i], pq.arr[j] = pq.arr[j], pq.arr[i]
}

func (pq PriorityQueue) Less(i, j int) bool{
    for _, comp := range pq.comps {
        result := comp(pq.arr[i], pq.arr[j])
        switch result {
            case -1: return true
            case 1:  return false
            case 0:  continue
        }
    }
    return true
}

func (pq *PriorityQueue) Push(x interface{}) {
    pq.arr = append(pq.arr, x)
}

func (pq *PriorityQueue) Pop() interface{} {
    n := pq.Len()
    item := pq.arr[n - 1]
    pq.arr = pq.arr[:n - 1]
    return item
}

func (pq *PriorityQueue) IsEmpty() bool {
    return pq.Len() == 0
}

/* input */
var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
    sc.Scan()
    n, _ := strconv.Atoi(sc.Text())
    return n
}

func main() {
    sc.Split(bufio.ScanWords)
    comp := func(p, q interface{}) int {
        if p.(int) < q.(int) {
            return -1
        } else if p.(int) == q.(int) {
            return 0
        } else {
            return 1
        }
    }
    n := readInt()
    preQue := new(PriorityQueue)
    preQue.comps = append(preQue.comps, comp)
    sufQue := new(PriorityQueue)
    sufQue.comps = append(sufQue.comps, comp)
    mid := make([]int, n)
    var preScore, sufScore int
    preScores := make([]int, n + 1)
    sufScores := make([]int, n + 1)
    for i := 0; i < n; i++ {
        v := readInt()
        preScore += v
        heap.Push(preQue, v)
    }
    for i := 0; i < n; i++ {
        mid[i] = readInt()
    }
    for i := 0; i < n; i++ {
        v := -readInt()
        sufScore += v
        heap.Push(sufQue, v)
    }
    
    preScores[0] = preScore
    for i, m := range mid {
        v := heap.Pop(preQue).(int)
        if v < m {
            preScore += (m - v)
            heap.Push(preQue, m)
        } else {
            heap.Push(preQue, v)
        }
        preScores[i + 1] = preScore
    }

    sufScores[0] = sufScore
    for i := n - 1; i >= 0; i-- {
        m := mid[i]
        v := heap.Pop(sufQue).(int)
        if -v > m {
            sufScore += -v - m
            heap.Push(sufQue, -m)
        } else {
            heap.Push(sufQue, v)
        }
        sufScores[n - i] = sufScore
    }
    ans := -10000000000000000
    for i := 0; i <= n; i++ {
        score := preScores[i] + sufScores[n - i]
        if ans < score {
            ans = score
        }
    }
    fmt.Println(ans)
}

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

long long a, b, g, m = 1;

long long gcd(long long x, long long y) {
	long long c = x, d = y, r = x % y;

	while (r > 0) {
		c = d;
		d = r;
		r = c % d;
	}

	return d;
}

int main()
{
	cin >> a >> b;

	g = gcd(a, b);

	for (long long i = 2; i * i <= g; i++) {
		if (g % i == 0) {
			m++;

			while (g % i == 0)
				g /= i;
		}
	}

	if (g > 1)
		m++;

	cout << m << endl;

	return 0;
}


Measured memory_bytes: 256
N, K, Q = list(map(int, input().split()))
A = [0] * Q
P = [-Q] * N

for i in range(Q):
    A[i] = int(input())

# N, K, Q = (10**5, 10*4, 10**5)
# A = [0] * Q
# P = [K] * N

# for i in range(Q):
#     A[i] = int(1)

for i in range(Q):
    P[A[i]-1] += 1

# print(P)

for i in range(N):
    if P[i] > -K:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 51032
sx,sy,tx,ty=map(int,input().split())
print("R"*(tx-sx)+"U"*(ty-sy)+"L"*(tx-sx)+"D"*(ty-sy)+
      "D"+"R"*(tx-sx+1)+"U"*(ty-sy+1)+"L"+
      "U"+"L"*(tx-sx+1)+"D"*(ty-sy+1)+"R")


Measured memory_bytes: 3060
#-swank
(unless (member :child-sbcl *features*)
  (quit
	:unix-status
	(process-exit-code
	  (run-program *runtime-pathname*
				   `("--control-stack-size" "128MB"
					 "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
					 "--eval" "(push :child-sbcl *features*)"
					 "--script" ,(namestring *load-pathname*))
				   :output t :error t :input t))))

(defun f (x)
  (if (= x 1)
	1
	(+ 1 (* 2 (f (ash x -1))))))

(princ (f (read)))


Measured memory_bytes: 14520
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,ans=1e9,num;
    string s;
    cin>>n>>s;
    int a[n+1];
    a[0]=0;
    for(int i=0;i<n;i++){
        if(s[i]=='#'){
            a[i+1]=a[i]+1;
        }
        else{
            a[i+1]=a[i];
        }
    }
    for(int i=0;i<=n;i++){
        num=a[i];
        num+=(n-i)-(a[n]-a[i]);
        ans=min(ans,num);
    }
    cout << ans<<endl;
    return 0;
}


Measured memory_bytes: 1300
from collections import Counter
n = int(input())
l = []
for i in range(n):
   l.append(int(input()))
lcnt = Counter(l)
l_value = list(lcnt.values())
for i in range(len(l_value)):
  if l_value[i]%2 == 0:
    l_value[i] = 0
  else:
    l_value[i] = 1    
print(sum(l_value))


Measured memory_bytes: 20652
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main(void){
   int N;
   cin>>N;
   vector<int> a(N);
   for(int i=0;i<N;i++){
      cin>>a[i];
   }
   int ans=1000000;
   for(int i=-100;i<=100;i++){
      int result=0;
      for(int j=0;j<N;j++){
         result+=(a[j]-i)*(a[j]-i);
      }
      ans=min(result,ans);
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    vector<vector<int>> A(3, vector<int>(3)), ok(3, vector<int>(3, 0));
    rep(i, 3) rep(j, 3) cin >> A[i][j];
    int N;
    cin >> N;
    rep(i, N) {
        int b;
        cin >> b;
        rep(j, 3) {
            rep(k, 3) {
                if(A[j][k] == b) {
                    ok[j][k] = 1;
                }
            }
        }
    }
    rep(i, 3) {
        int f = 1;
        rep(j, 3) if(ok[i][j] == 0) f = 0;
        if(f) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    rep(i, 3) {
        int f = 1;
        rep(j, 3) if(ok[j][i] == 0) f = 0;
        if(f) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    if(ok[0][0] && ok[1][1] && ok[2][2]) {
        cout << "Yes" << endl;
        return 0;
    }
    if(ok[0][2] && ok[1][1] && ok[2][0]) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 55555;
bitset<N + 1> is_prime;
vector<int> ans(1, 2);

void gen() {
    is_prime.set();
    is_prime[0] = is_prime[1] = false;
    for(int i = 2; i <= N; ++i) {
        if(is_prime[i]) {
            for(int j = 2 * i; j <= N; j += i) {
                is_prime[j] = false;
            }
            if(i % 5 == 1) ans.emplace_back(i);
        }
        ;
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    gen();
    int n;
    cin >> n;
    for(int i = 0; i < n; ++i) cout << ans[i] << " "; 
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

#define INF 2e9

int N,i;

int main(){

    scanf("%d", &N);

    ll H[N];

    int c = 0;

    REP(i,N) scanf("%lld", &H[i]);

    int max = 0;

    REP(i,N){
        if(i != (N -1) && H[i] >= H[i+1]){
            c++;
        }else{
            if(max < c){
                max = c;
            }
            c = 0;
        }
    }
    

    printf("%d", max);
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
template<class T, class Func = function<T(T, T)>>
class segtree {
    vector<T> obj;
    int offset;
    Func updater;
    T e;
    int bufsize(int num) {
        int i = 1;
        for (; num >i; i <<= 1);
        offset = i - 1;
        return (i << 1) - 1;
    }
    T query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l)return e;
        if (a <= l && r <= b)return obj[k];
        else return updater(query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r));
    }
public:
    T query(int a, int b) {//[a,b)
        return query(a, b, 0, 0, offset + 1);
    }
    void updateall(int l = 0, int r = -1) {
        if (r < 0)r = offset + 1;
        l += offset, r += offset;
        do {
            l = (l - 1) >> 1, r = (r - 1) >> 1;
            for (int i = l; i < r; i++)obj[i] = updater(obj[i * 2 + 1], obj[i * 2 + 2]);
        } while (l);
    }
    void update(int k, T a) {
        k += offset;
        obj[k] += a;
        while (k) {
            k = (k - 1) >> 1;
            obj[k] = updater(obj[k * 2 + 1], obj[k * 2 + 2]);
        }
    }
    segtree(int n, T e, const Func &updater = Func()) :obj(bufsize(n), e), e(e), updater(updater) {}
    segtree(vector<T> &vec, T e, const Func &updater = Func()) :obj(bufsize(vec.size()), e), e(e), updater(updater) {
        copy(vec.begin(), vec.end(), obj.begin() + offset);
        updateall();
    }
    typename vector<T>::reference operator[](int n) {
        return obj[n + offset];
    }
};
signed main(){
    int n,q; cin >> n >> q;
    segtree<int>sgt(n,0LL,[](auto a,auto b){
        return a + b;
    });
    rep(_,q){
        int a,b,c; cin >> c >> a >> b;
        if(c == 0){
            sgt.update(a-1,b);
            //sgt.updateall();
        } else {
            cout << sgt.query(a-1, b) << endl;
        }
    }
}





Measured memory_bytes: 4948
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
int N;
int dp[2][100010];
int a[110];

int dfs(int stone, int turn) {
    if (dp[turn][stone] != -1) return dp[turn][stone];
    rep(i, N) {
        if (stone - a[i] >= 0 && dfs(stone - a[i], !turn ) == turn) {
            return dp[turn][stone] = turn;
        }
    }
    return dp[turn][stone] = !turn;
}


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K;
    cin >> N >> K;
    rep(i, N) cin >> a[i];
    rep(i, 2) rep(j, 100010) dp[i][j] = -1;
    if (dfs(K, 1)) cout << "First" << endl;
    else cout << "Second" << endl;

    return 0;
}


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

int main(){
    int n, q; cin >> n >> q;
    string s; cin >> s;
    vector<int> sum(n+1, 0);
    for(int i = 1; i < n; ++i){
        sum[i+1] = sum[i];
        if(s[i - 1] == 'A' && s[i] == 'C') sum[i+1]++;
    }
    rep(i,q){
        int l, r; cin >> l >> r;
        int ans = sum[r] - sum[l];
        cout << ans << endl;
    }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl


int main() {
    int N, M;  cin >> N >> M;
    vector<ll> A(N);  rep(i, N) cin >> A[i];
    vector<int> B(M);
    vector<ll> C(M);
    rep(i, M) cin >> B[i] >> C[i];

    ll lim = 0;
    rep(i, M) lim += B[i];

    vector<pair<int, int>> v;
    rep(i, M) {
        v.push_back(make_pair(C[i], B[i]));
    }

    sort(v.begin(), v.end());
    reverse(all(v));

    sort(all(A));

    ll ans = 0;
    int csr = 0;
    rep(i, N) {
        if (i > lim-1) ans += A[i];
        else if (v[csr].first > A[i]) {
            ans += v[csr].first;
        }
        else ans += A[i];

        v[csr].second--;
        if (v[csr].second == 0) csr++;
    }

    print(ans);

}


Measured memory_bytes: 3320
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <vector>

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

int n;
int ans = 0;
int pos[3333][2];
bool xy[5200][5200] = {};

int main() {

	for (;;) {
		scanf("%d", &n);
		if (!n) break;
		memset(xy, false, sizeof(xy));
		ans = 0;

		rep(i, n) {
			scanf("%d %d", &pos[i][0], &pos[i][1]);
			xy[pos[i][0]][pos[i][1]] = true;
		}

		for (int i = 0; i < n - 1; i++) {
			for (int j = i + 1; j < n; j++) {
				int vec[2] = { pos[i][0] - pos[j][0], pos[i][1] - pos[j][1] };
				if ((pos[i][0] + vec[1] >= 0 && pos[i][1] - vec[0] >= 0 && pos[j][0] + vec[1] >= 0 && pos[j][1] - vec[0] >= 0 &&
					pos[i][0] + vec[1] < 5200 && pos[i][1] - vec[0] < 5200 && pos[j][0] + vec[1] < 5200 && pos[j][1] - vec[0] < 5200 &&
					xy[pos[i][0] + vec[1]][pos[i][1] - vec[0]] && xy[pos[j][0] + vec[1]][pos[j][1] - vec[0]]) ||
					(pos[i][0] - vec[1] >= 0 && pos[i][1] + vec[0] >= 0 && pos[j][0] - vec[1] >= 0 && pos[j][1] + vec[0] >= 0 &&
						pos[i][0] - vec[1] < 5200 && pos[i][1] + vec[0] < 5200 && pos[j][0] - vec[1] < 5200 && pos[j][1] + vec[0] < 5200 &&
						xy[pos[i][0] - vec[1]][pos[i][1] + vec[0]] && xy[pos[j][0] - vec[1]][pos[j][1] + vec[0]])) ans = max(ans, vec[0] * vec[0] + vec[1] * vec[1]);
			}
		}

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

	return 0;
}

Measured memory_bytes: 29036
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a = 0, i;
    for(i = 0; i < 5; i++){
        cin >> a;
        if(a == 0){
            break;
        }
    }
    cout << i + 1 << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"

const int N = 1e5 + 5;

int a[5][N];
int dp[5][N];
int n;

int solve(int idx, int prev){

    if(idx == n + 1){
        return 0;
    }

    int &ans = dp[prev][idx];

    if(ans != -1){
        return ans;
    }

    ans = 0;
    for(int i = 1;i <= 3;i ++){
        if(i == prev){
            continue;
        }
        ans=max(ans, a[i][idx] + solve(idx + 1, i));
    }
    return ans;
}

int32_t main(){

    memset(dp, -1, sizeof(dp));

    cin >> n;

    for(int i = 1;i <= n;i ++){
        for(int j = 1;j <= 3;j ++){
            cin >> a[j][i];
        }
    }


    int ans = solve(1, 0);
    cout << ans << "\n";
    return 0;

}


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

int ans[11000];

int kansu( long long int a, long long int b ) {

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

    ans[i] += a / b;
    a = a % b * 10;

  }

  for ( int i = 11000 - 1; i > 0; i-- ) {

    ans[ i-1 ] += ans[i] / 10;
    ans[i] = ans[i] % 10;

  }

  return a;

}

int main() {

  while( true ) {

    long long int n,k,m,r,a,b;

    cin >> n >> k >> m >> r;

    if ( n == 0 ) break;

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

      ans[i] = 0;

    }

    if ( m == 0 ) {

      kansu( 1, n );

    }else {

      kansu( 1, n );

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

	kansu( 1, n * i );

      }

    }

    for ( int i = 0; i < r + 1; i++ ) {

      cout << ans[i];
      if ( i == 0 ) cout << ".";

    }

    cout << endl;

  }

  return 0;

}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000009
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

map<string, vector<string>> graph;
queue<string> str;

int main(){
  ll N;
  cin >> N;
  str.push("a");
  graph["a"] = {};
  set<string> ans;
  while(!str.empty()){
    if(sz(str.front()) == N){
      ans.insert(str.front());
      str.pop();
      continue;
    }
    if(sz(str.front()) > N){
      break;
    }
    string t = str.front();
    char d = 'a';
    rep(i, sz(t)){
      chmax(d, t.at(i));
    }
    rep(i, d-'a'+2){
      char c = 'a' + i;
      string s = t + c;
      graph.at(t).push_back(s);
      graph[s] = {};
      str.push(s);
    }
    str.pop();
  }
  for(auto st : ans){
    cout << st << endl;
  }
}

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

int main() {
  const int MOD = 1000000007;
  int N; cin >> N;
  vector<int> C;
  int tmp = -1;
  // 同じ数字が連続している箇所をなくす
  for (int i = 0; i < N; i++) {
    int c; cin >> c;
    if (c == tmp) continue;
    C.push_back(c);
    tmp = c;
  }
  int L = C.size();
  vector<int> dp(L+1), acc(200010, 0);
  dp.at(0) = 1;
  for (int i = 0; i < L; i++) {
    dp.at(i+1) = (dp.at(i+1) + dp.at(i)) % MOD;
    dp.at(i+1) = (dp.at(i+1) + acc.at(C.at(i))) % MOD;
    acc.at(C.at(i)) = (acc.at(C.at(i)) + dp.at(i)) % MOD;
  }
  cout << dp.at(L) << endl;
}

Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    ll H[N], P[N];
    pli p[N];
    rep(i, N){
        cin >> H[i] >> P[i];
        p[i] = pli(H[i]+P[i], i);
    }
    sort(p, p+N);
    ll dp[N+1];
    fill(dp, dp+N+1, INF);
    dp[0] = 0;
    rep(i, N){
        int k = p[i].second;
        rep3(j, N, 0){
            if(dp[j] > H[k]) continue;
            chmin(dp[j+1], dp[j]+P[k]);
        }
    }
    cout << lower_bound(dp, dp+N+1, INF)-dp-1 << endl;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  sort(all(v));
  double ans = (double)(v[0] + v[1]) / 2;
  REP(i, 2, n) { ans = (ans + v[i]) / 2; }

  printf("%.10f\n", ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const int N=200005,M=1000000007;
using namespace std;
int n,m,l=1,k=N,ls,f[N],s[N];
char S[N],fi;
int main(){
	scanf("%d%d%s",&n,&m,S);
	fi=S[0];
	for(int i=1;i<m;i++)
	if(S[i]!=S[i-1])
	if(S[i]^fi){
		if(ls==0||i-ls&1)
		k=min(k,i-ls);
	}else ls=i;
	if(k<N){
		if(n&1)return puts("0"),0;
		k=k+2>>1,n>>=1;
	}else l++;
	for(int i=l;i<=n;i++)
	f[i]=(s[i-l]+(i>k?-s[i-k-1]:(3ll-l)*i))%M,s[i]=(s[i-1]+f[i])%M;
	printf("%d",(f[n]+l-1+M)%M);
}

Measured memory_bytes: 2048
#include <iostream>

using namespace std;

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    int i = max(a, b);
    int j = 0;
    while (true) {
        if (a % i == 0 && b % i == 0) {
            j++;
            if (j == k) {
                cout << i << "\n";
                return 0;
            }
        }
        i--;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    static int mod = 1000000007;

    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        String S  = sc.next();
        String T = sc.next();

        if(T.substring(0,T.length()-1).equals(S)){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }


    }

}









Measured memory_bytes: 35688
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define MAX 5002

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll a,b,c,n;cin>>a>>b>>c>>n;
	ll ans=0;
	For(i,0,n+1) For(j,0,n+1){
		ll t = n-i*a-j*b;
		if((t>=0) && (t%c)==0)ans++;
	}
	cout<<ans<<endl;










	
}

Measured memory_bytes: 256
/**
 *      ABC 69 C
 *      author  : kyomukyomupurin
 *      created : 2018-09-08 08:09:34
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    int a[N] = {};
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

    int count4 = 0; int count2 = 0;
    for (int i = 0; i < N; ++i) {
        if (a[i] % 4 == 0){
            ++count4;
        }
        else if (a[i] % 2 == 0){
            ++count2;
        }
    }
    if (N % 2 == 1 && count4 >= N / 2){
        cout << "Yes" << endl; return 0;        
    }
    
    (count4 * 2 + count2 >= N) ? cout << "Yes" << endl : cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 640