akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {

  int n, q;

  cin >> n;
  vector<int> S(n);
  for (int i = 0; i < n; i++) {
    cin >> S[i];
  }

  cin >> q;
  vector<int> T(q);
  for (int i = 0; i < q; i++) {
    cin >> T[i];
  }

  int answer = 0;

  for (int i = 0; i < q; i++) {
    for (int j = 0; j < n; j++) {
      if (T[i] == S[j]) {
        answer++;
        break;
      }
    }
  }

  cout << answer << endl;

  return 0;

}


Measured memory_bytes: 3116
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int bubble(vector<int>::iterator, vector<int>::iterator);

int main() {
  int n;
  cin >> n;
  vector<int> nums;
  for(int i = 0; i < n; ++i) {
    int num;
    cin >> num;
    nums.push_back(num);
  }
  int count = 0;
  for(int i = 0; i < n - 1; ++i) {
    count += bubble(nums.begin(), nums.end() - i);
  }
  for(auto j = nums.begin(); j != nums.end() - 1; ++j) cout << *j << " ";
  cout << *(nums.end() - 1) << endl << count << endl;
  return 0;
}

int bubble(vector<int>::iterator begin, vector<int>::iterator end) {
  int count = 0;
  for(auto i = begin; i != (end - 1); ++i) {
    if(*i > *(i + 1)) {
      iter_swap(i, i + 1);
      ++count;
    }
  }
  return count;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int,int> PII;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) REP(i,0,n)
#define MAX(a,b) a>b? a:b
#define MIN(a,b) a>b? b:a

int main(){
int a,b;
cin>>a>>b;
a*b%2==1? cout<<"Odd":cout<<"Even";
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,t,x,y,nt,nx,ny;cin>>n;
  bool b=true,travel;
  x=0,y=0;t=0;
  for(int i=0;i<n;i++){
    cin>>nt>>nx>>ny;
    if(nt-t<abs(nx-x)+abs(ny-y)||(nt-t+abs(nx-x)+abs(ny-y))%2==1){b=false;break;}
    t=nt,x=nx,y=ny;
  }
  cout<<(b?"Yes":"No");
}


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

int main(){
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	
	for(int i=0; i<100; i++){
		C -= B;
		if(C<=0){
			cout << "Yes" << endl;
			return 0;
		}
		A -= D;
		if(A<=0){
			cout << "No" << endl;
			return 0;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3652
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from collections import Counter

mod = 10 **9 + 7


def calc(n):
    m = (n-5) // 2

    #return (1+m)*(2+m)*(3+m)*(4+m)*(5+m)*(1025024*m**10+3003*(-4+n)*(-3+n)*(-2+n)*(-1+n)*n*(1+n)*(2+n)*(3+n)*(4+n)*(5+n)-549120*m**9*(-1+10*n)+42240*m**8*(-398+45*n*(-1+7*n))-369600*m**7*(3+2*(-2+n)*n*(49+26*n))+2688*m**6*(33529+75*n*(-33-679*n+91*n**3))-336*m**5*(88065+2*n*(426107+7*n*(-6675+13*n*(-2420+9*n*(5+22*n)))))+560*m**4*(-291598+n*(216249+7*n*(95465+26*n*(-495+n*(-980+11*n*(3+5*n))))))-30*m**3*(-3080960+n*(-10447602+7*n*(854525+13*n*(93170+n*(-15295+22*n*(-714+5*n*(7+6*n)))))))+2*m**2*(28412712+25*n*(-3433650+n*(-4123841+13*n*(189882+n*(142177+22*n*(-1344+n*(-791+27*n*(2+n))))))))-m*(30149280+n*(31294296+n*(-93275400+13*n*(-3808420+n*(2988195+11*n*(111678+25*n*(-1302+n*(-456+n*(45+14*n))))))))))/1307674368000
    return (
        (1+m)*(2+m)*(3+m)*(4+m)*(5+m)%mod*(
            1025024*pow(m,10,mod)+3003*(-4+n)*(-3+n)*(-2+n)*(-1+n)*n*(1+n)*(2+n)*(3+n)*(4+n)*(5+n)%mod
            -549120*pow(m,9,mod)*(-1+10*n)%mod
            +42240*pow(m,8,mod)*(-398+45*n*(-1+7*n))%mod
            -369600*pow(m,7,mod)*(3+2*(-2+n)*n*(49+26*n))%mod
            +2688*pow(m,6,mod)*(33529+75*n*(-33-679*n+91*n**3))%mod
            -336*pow(m,5,mod)*(88065+2*n*(426107+7*n*(-6675+13*n*(-2420+9*n*(5+22*n)))))%mod
            +560*pow(m,4,mod)*(-291598+n*(216249+7*n*(95465+26*n*(-495+n*(-980+11*n*(3+5*n))))))%mod
            -30*pow(m,3,mod)*(-3080960+n*(-10447602+7*n*(854525+13*n*(93170+n*(-15295+22*n*(-714+5*n*(7+6*n)))))))%mod
            +2*pow(m,2,mod)*(28412712+25*n*(-3433650+n*(-4123841+13*n*(189882+n*(142177+22*n*(-1344+n*(-791+27*n*(2+n))))))))%mod
            -m*(30149280+n*(31294296+n*(-93275400+13*n*(-3808420+n*(2988195+11*n*(111678+25*n*(-1302+n*(-456+n*(45+14*n)))))))))%mod
        #) // 1307674368000
        )%mod*pow(1307674368000%mod, mod-2, mod)%mod
    )

def resolve():
    it = map(int, sys.stdin.read().split())
    N = next(it)

    ans = [0] * N
    for i in range(N):
        n = next(it)
        ans[i] = calc(n)

    print(*ans, sep="\n")

if __name__ == "__main__":
    resolve()


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

int main(){

	string str;

	cin>>str;
	if(str == "A")
		cout<<"T\n";
	else if(str == "T")
		cout<<"A\n";
	else if(str == "C")
		cout<<"G\n";
	else cout<<"C\n";

	return 0;
}


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

int main() {
 int N;
 int A;
 int B;
  
  cin >> N >> A >> B;
  
  int x = A*N ;
 
  if ( x < B ) {
    cout << x << endl;
  }
  
  else  {
    cout << B << endl;
  }
  
  
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<iomanip>
 
#define EPS (1e-10)
using namespace std;
#define PI (3.1415926535)
 
int main(){
    string str;

	getline(cin, str);

	for(int i = 0; i < str.size(); i++){
		if(str[i] >= 'a' && str[i] <= 'z'){
			str[i] += 'A'-'a';
		}
	}

	cout << str << endl;

	return 0;
}

Measured memory_bytes: 1172
n, m = map(int, input().split())
cnt = 0
pena = 0
L = [-1]*(n+1)
C = [0]*(n+1)
for _ in range(m):
  p, s = input().split()
  p = int(p)
  if s == "WA":
    if L[p] == -1:
      C[p] += 1
  else:
    if L[p] == -1:
      L[p] = 1
      cnt += 1
      pena += C[p]
print(cnt, pena)

Measured memory_bytes: 10396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (int) (1e9+7)
#define INF (int) 2e9

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int ans = 1;
    rep(i, n-1){
        if(s[i]!=s[i+1])ans++;
    }
    
    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef vector<int> vi;

const int MOD = 1e9 + 7;
const int INF = INT_MAX / 2;

int main() {
	ll x; cin >> x;
	int N = 50;
	int t = 0;
	for (; x % N; x++) t++;
	vector<ll> a(N, N - 1 + x / N);
	rep(i, t) {
		a[i] -= N + 1;
		rep(j, N) a[j]++;
	}
	cout << N << endl;
	rep(i, N) cout << a[i] << ' ';
	cout << endl;
	/*
	int N; cin >> N;
	vector<ll> a(N);
	rep(i, N) cin >> a[i];
	*/
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
	    int A = scanner.nextInt();
	    int B = scanner.nextInt();
	    int[] answers = {1, 2, 3};
	    
	    for (int answer : answers) {
	    	if (A == answer) {
	    		continue;
	    	} else if (B == answer) {
	    		continue;
	    	} 
            System.out.println(answer);
	    }
	}	
}	

Measured memory_bytes: 20820
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,a,b,ans=0;
  cin >> n >> a >> b;
  long long c[n];
  for(long long i=0;i<n;i++){
    cin >> c[i];
    if(i>0){
      ans+=min((c[i]-c[i-1])*a,b);
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;

int main() {

	ll h, w, n; scanf("%lld %lld %lld", &h, &w, &n);
	
	int dx[9] = { 0, 0, 0, -1, -1, -1, -2, -2, -2 };
	int dy[9] = { 0, -1, -2, 0, -1, -2, 0, -1, -2 };

	vector<ll> ans(10);
	map<pi, int> map;

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

		int a, b; scanf("%d %d", &a, &b);

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

			pi front = { a + dx[i], b + dy[i] };

			if (front.first < 1 || front.first > h - 2 || front.second < 1 || front.second > w - 2) continue;

			map[front]++;

		}

	}

	for (auto p : map) ans[p.second]++;

	ll zero = (w - 2) * (h - 2) - map.size();

	printf("%lld\n", zero);

	for(int i=1; i <= 9; i++)
		printf("%lld\n", ans[i]);
		
	return 0;

}

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

long long a,b,c,d;

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

int main(){
  cin >> a >> b >> c >> d;
  long long l = c*d/gcd(c,d);
  long long ans = b - (b/c + b/d - b/l);
  ans -= (a-1) - ((a-1)/c + (a-1)/d - (a-1)/l);

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<double> p(n);
    for(int i = 0; i < n; ++i){
        cin >> p.at(i);
    }

    vector<vector<double>> dp(n, vector<double>(n + 1, 0));
    dp.at(0).at(0) = 1 - p.at(0);
    dp.at(0).at(1) = p.at(0);
    for(int i = 1; i < n; ++i){
        for(int j = 0; j <= i + 1; ++j){
            dp.at(i).at(j) = dp.at(i - 1).at(j) * (1 - p.at(i));
            if(j > 0){
                dp.at(i).at(j) += dp.at(i - 1).at(j - 1) * p.at(i);
            }
        }
    }

    double ans = 0;
    for(int i = (n + 1) / 2; i <= n; ++i){
        ans += dp.at(n - 1).at(i);
    }
    printf("%.012lf\n", ans);
    return 0;
}

Measured memory_bytes: 70656
fun main(args:Array<String>):Unit {
    val parts = Array(readLine()!!.toInt()){
        readLine()!!.toInt()
    }
    val accumulated = Array(parts.size * 2 + 1){0L}
    for (i in 1 until accumulated.size){
        accumulated[i] = accumulated[i - 1] + parts[(i - 1) % parts.size]
    }
    val wholeSize = accumulated[parts.size]
    val maxSize = wholeSize / 3
    var maxMin:Long = 0L
    for (i in 0 until parts.size){
        val greaterPoint =
                accumulated.binarySearch(accumulated[i] + maxSize).let{ if (it >= 0) it else -it - 1}
        val firstArea =
                accumulated[greaterPoint] - accumulated[i]
        assert(firstArea >= maxSize)
        val secondPoint =
                accumulated.binarySearch(accumulated[greaterPoint] + (wholeSize - firstArea) / 2).let{if (it >= 0) it else -it - 1}
        val secondMin =
                accumulated[secondPoint - 1] - accumulated[greaterPoint]
        val thirdMax = wholeSize - firstArea - secondMin
        assert(secondMin < maxSize)
        val secondMax =
                accumulated[secondPoint] - accumulated[greaterPoint]
        val thirdMin = wholeSize - firstArea - secondMax
        assert(firstArea + secondMax <= wholeSize)
        val tempMaxMin =
                listOf(listOf(secondMin, thirdMax).min()!!, listOf(secondMax, thirdMin).min()!!).max()!!
        if (maxMin < tempMaxMin) {
            maxMin = tempMaxMin
        }
    }
    println(maxMin)
}


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

int main(){
    ll A, B, Q; cin >> A >> B >> Q;
    vector<ll> s(A), t(B), x(Q);
    for (int i = 0; i < A; i++)
    {
        cin >> s[i];
    }
    for (int i = 0; i < B; i++)
    {
        cin >> t[i];
    }
    for (int i = 0; i < Q; i++)
    {
        cin >> x[i];
    }

    for(int i = 0; i < Q; i++){
        ll ans = 1e12;
        auto its = lower_bound(s.begin(), s.end(), x[i]);
        if(its != s.end()){
            auto itt = lower_bound(t.begin(), t.end(), *its);
            if(itt != t.end()) ans = min(ans, *itt - x[i]);
            if(itt != t.begin()){
                itt--;
                if(*itt > x[i]){
                    ans = min(ans, *its - x[i]);
                }else{
                    ans = min(ans, *its - *itt + min(x[i] - *itt, *its - x[i]));
                }
            }
        }
        if(its != s.begin()){
            auto its2 = its;
            its2--;
            auto itt2 = lower_bound(t.begin(), t.end(), *its2);
            if(itt2 != t.end()){
                if(*itt2 > x[i]) ans = min(ans, *itt2 - *its2 + min(*itt2 - x[i], x[i] - *its2));
                else ans = min(ans, x[i] - *its2);
            }
            if(itt2 != t.begin()){
                itt2--;
                ans = min(ans, x[i] - *itt2);
            }
        }
        cout << ans << endl;
    }
    
    
    
}

Measured memory_bytes: 3712
s = input()
n = len(s)
ans = 0
for i in range(2**(n-1)):
  e = " "
  for j in range(n-1):
    if (i >> j) & 1 == 1:
      e += s[j] + "+"
    else:
      e += s[j]
  e += s[-1]
  ans += eval(e)
print(ans)

Measured memory_bytes: 39024
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime>
#include <algorithm>
template <typename T> inline void read(T &x) {
	x = 0; char c = getchar(); bool flag = false;
	while (!isdigit(c)) { if (c == '-')	flag = true; c = getchar(); }
	while (isdigit(c)) { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); }
	if (flag)	x = -x;
}
using namespace std;
int main() {
	char t[2][2];
	t[0][0] = 'R', t[0][1] = 'Y';
	t[1][0] = 'G', t[1][1] = 'B';
	int h, w, d; read(h), read(w), read(d);
	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j) {
			int x = (i + j) / d, y = (i - j + w) / d;
			int tx = x & 1, ty = y & 1;
			putchar(t[tx][ty]);
		}
		putchar('\n');
	}
	return 0;
}



Measured memory_bytes: 3016
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
typedef long long int Int;

int main() {
  int N; cin >>N;
  Int sum = 0;
  REP(i, N){
    Int n; cin >>n;
    sum += n;
  }
  cout <<sum / N <<endl;
  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

int main()
{ 

    fast;
string s,t;
cin>>s>>t;
cout<<t+s<<endl;
  }

Measured memory_bytes: 256
import copy
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n=INT()
    s=LIST()
    sort_s=sorted(s)
    flg=0
    if s==sort_s:
        flg=1
    for i in range(n-1):
        for k in range(i+1,n):
            temp=copy.deepcopy(s)
            temp[i],temp[k]=temp[k],temp[i]
            #print(temp)
            if temp==sort_s:
                flg=1
    if flg==1:
        print('YES')
    else:
        print('NO')
        
    
if __name__ == '__main__':
    do()

Measured memory_bytes: 3444
import Data.List
main = do
  [n,k] <- map read . words <$> getLine
  ps <- sequence $ replicate n getLine
  let f 0 xs ys = 1 + f k (reverse $ sort (xs ++ ys)) []
      f _ [] ys = 0
      f m (0:xs) ys = f m xs ys
      f m (x:xs) ys = f (m-1) xs ((x-1) : ys)
  print $ f k (reverse $ sort $ map length $ group $ map head $ sort ps) []

Measured memory_bytes: 9596
import sys
mod = 10**9+7
def bpow(x,n,m) :
  if n == 0 :
    return 1
  ans = 1
  while n > 1 :
    if n%2 != 0 :
      ans = ans*x%mod
    x = x*x%mod
    n //= 2
  return ans*x%mod
      
x,y = map(int,input().split())

for i in range(0,10**6+1) :
  xa = x - 1*i
  ya = y - 2*i
  if xa%2 == 0 and ya == 1*(xa//2) and xa >= 0 :
    n = i+xa//2
    # n!のあまりを求める
    np = 1
    for j in range(1,n+1) :
      np = (np*j)%mod
    #1/p!のあまりを求める
    pp = 1
    for j in range(1,i+1) :
      pp = pp*bpow(j,mod-2,mod)%mod
    #1/q!のあまりを求める
    qp = 1
    for j in range(1,(n-i)+1) :
      qp = qp*bpow(j,mod-2,mod)%mod
    print(np*pp*qp%mod)
    sys.exit()
print(0)

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

int main()
{
  int r,D,x[11] ;
  cin>>r>>D>>x[0] ;
  
  for(int i=1;i<11;i++){
    x[i]=r*x[i-1]-D ;
    cout<<x[i]<<endl ;
  }
  return 0 ;
}



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

const int MAX = 55; // 頂点数と辺数の最大値
int N, M;
int a[MAX], b[MAX];
bool graph[MAX][MAX]; // グラフを表す隣接行列
bool visit[MAX]; // 頂点を訪れたか否か

void dfs(int n) {
  if (visit[n]) return;

  visit[n] = true;
  for (int i = 0; i < M; i++) {
    if (graph[n][a[i]]) dfs(a[i]);
    if (graph[n][b[i]]) dfs(b[i]);
  }
}

int main() {
  // 入力
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  // グラフからある一辺を除いて、深さ優先探索でそれが連結かどうかを確かめる
  int ans = 0;
  for (int i = 0; i < M; i++) {
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
    fill(visit, visit + N, false);

    dfs(0);
    for (int j = 0; j < N; j++) {
      if (!visit[j]) {
        ans++;
        break;
      }
    }

    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
def solve(N, S):
    ans = [S.count('.')]
    for i in range(N):
        temp = ans[-1]
        temp += -1 if S[i] == '.' else 1
        ans.append(temp)
    return ans


# ... i / i+1 ####
# ####
N = int(input())
S = str(input())
print(min(solve(N, S)))


Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define maxn 100003
#define pb push_back
using namespace std;

int n,m,ans;
int dp[maxn];
vector<int>adj[maxn];

int dfs( int u ) {
	if( dp[u] != -1 )
		return dp[u];
	dp[u] = 0;
	for( int i = 0 ; i < (int) adj[u].size() ; i++ )
		dp[u] = max( dp[u] , dfs( adj[u][i] ) + 1 );
	return dp[u];
}

int main() {
	cin >> n >> m;
	for( int i = 0 , u , v ; i < m ; i++ ) {
		cin >> u >> v;
		adj[u].pb(v);
	}
	memset( dp , -1 , sizeof(dp) );
	for( int i = 1 ; i <= n ; i++ )
		ans = max( ans , dfs(i) );
	cout << ans << endl;
}


Measured memory_bytes: 8192
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Convert;
using static System.Console;
using static System.Math;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }


        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var A = cin.ReadIntArray(N);
            var ans = 0;
            while (true)
            {
                var T = (int)Pow(2, ans);
                for(int i = 0; i < N; i++)
                {
                    if(A[i] % T != 0)
                    {
                        WriteLine(ans - 1);
                        return;
                    }
                }
                ans++;
            }
        }


        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, a, b;
	for (int h = 0; h < 4; h++) {
		cin >> a >> b;
		if (a == 1) { cout << b * 6000 << endl; }
		if (a == 2) { cout << b * 4000 << endl; }
		if (a == 3) { cout << b * 3000 << endl; }
		if (a == 4) { cout << b * 2000 << endl; }
	}
	cin >> n;
}


Measured memory_bytes: 3080
fun main(args:Array<String>):Unit {
    while(true){
        val n = readLine()!!.trim().toInt()
        val m = readLine()!!.trim().toInt()
        if (n == 0 && m == 0) return
        val student = Array(n){a -> Array(n){b -> a == b}}
        repeat(m){
            val (a ,b) = readLine()!!.trim().split(' ').map(String::toInt)
            student[a - 1][b - 1] = true
            student[b - 1][a - 1] = true
        }
        val square = student.map{ line ->
            (0 until n).map{x ->
                (0 until n).any{y -> student[y][x] && line[y]}
            }.toTypedArray()
        }.toTypedArray()
        println(square[0].count{it} - 1)
    }

}




Measured memory_bytes: 73012
T = [int(n) for n in input().split()]

alice = [0] * max(T)
alice[T[0]:T[1]] = [1] * (T[1] - T[0])

bob = [0] * max(T)
bob[T[2]:T[3]] = [1] * (T[3] - T[2])

turnon = [0] * max(T)
for i in range(max(T)):
    turnon[i] = alice[i] * bob[i]

print(sum(turnon))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
# define ll long long int
#define M 1000000007
#define ff first
#define ss second
#define pb push_back
#define inf 10000000000000

							
									//nestedcode


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,k,i,ans = 0;
    cin>>n>>k;
    ll a[n+5];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(i=0;i<k;i++){
        ans+=a[i];
    }
    cout<<ans;
    
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
int ni(int a){
  int b=1;
  for(int i=0;i<a;i++){
    b*=2;
  }
  return b;
}
int main() {
  int N,M;
  cin>>N>>M;
  vector<int> p(M);
  vector<int> c(M);
  for(int i=0;i<M;i++){
    int x,y;
    cin>>x>>y;
    c.at(i)=x;
    int b=0;
    for(int i=0;i<y;i++){
      int a;
      cin>>a;
      a--;
      b+=ni(a);
    }
    p.at(i)=b;
  }
  int Q=ni(N);
  vector<vector<int>> dp(M+1,vector<int>(Q,1000000001));
  dp.at(0).at(0)=0;
  for(int i=0;i<M;i++){
    for(int j=0;j<Q;j++){
      dp.at(i+1).at(j)=dp.at(i).at(j);
    }
    for(int j=0;j<Q;j++){
      dp.at(i+1).at(j|p.at(i))=min(dp.at(i+1).at(j|p.at(i)),dp.at(i).at(j)+c.at(i));
    }
  }
  if(dp.at(M).at(Q-1)==1000000001){
    cout<<"-1"<<endl;
  }
  else{
    cout<<dp.at(M).at(Q-1)<<endl;
  }
}

Measured memory_bytes: 16384
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>

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

const int inf = 1e9 + 7;
#define EPS 1e-9


ll gcd(ll x, ll y) {
	return y ? gcd(y, x%y) : x;
}

ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll f(ll x, ll c, ll d) {
	ll res = x;
	res -= x / c;
	res -= x / d;
	res += x / lcm(c, d);
	return res;
}

int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	--a;
	ll ans = f(b, c, d) - f(a, c, d);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/*
    - Note:
    https://atcoder.jp/contests/arc076/tasks/arc076_b
*/

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
const ll MOD = 1000000007;
const double PI = 3.14159265358979323846264338327950;
inline int newline() { putchar('\n'); return 0; }

int main() {
    using P = pair<ll, ll>;

    ll n;
    cin(n);

    /*
        - Note:
        first -> x or y
        second -> index
    */
    vector<P> x(n), y(n);
    rep2(i, n) {
        ll _x, _y;
        cin(_x); cin(_y);

        x[i] = { _x, i };
        y[i] = { _y, i };
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    vector<vector<P>> relations(n);
    rep2(i, n - 1) {
        P from = x[i], to = x[i + 1];

        ll cost = abs(from.first - to.first);
        relations[from.second].push_back({ cost, to.second });
        relations[to.second].push_back({ cost, from.second });
    }
    rep2(i, n - 1) {
        P from = y[i], to = y[i + 1];

        ll cost = abs(from.first - to.first);
        relations[from.second].push_back({ cost, to.second });
        relations[to.second].push_back({ cost, from.second });
    }

    vector<bool> used(n, false);
    ll result = 0;
    priority_queue<P, vector<P>, greater<>> que;

    que.push({ 0, 0 });

    while (!que.empty()) {
        P top = que.top();
        que.pop();

        if (used[top.second]) continue;

        used[top.second] = true;
        result += top.first;

        for (auto i: relations[top.second]) {
            if (!used[i.second]) que.push(i);
        }
    }

    print(result);
    return 0;
}

Measured memory_bytes: 19824
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
#define INF 1000000000;
using namespace std;
char mas[200500];
int main() {
	int N = 0, A = 0, B = 0, C = 0, D = 0;
	cin >> N >> A >> B >> C >> D;
	for (int i = 0; i < N; i++) {
		cin >> mas[i];
		if (i+1 >= A||i+1>=B) {
			if (i + 1 < max(C, D)) {
				if (mas[i] == '#') {
					if (mas[i - 1] == '#') {
						cout << "No" << endl;
						return 0;
					}
				}
			}
		}
	}
	if (A > B && C < D) {
		if (abs(A - B) == 1) {
			if (mas[max(A, B)] == '.') {
				cout << "Yes" << endl;
				return 0;
			}
		}
		for (int i = max(A, B)-1; i < min(C, D); i++) {
			if (mas[i - 1] == '.' && mas[i] == '.' && mas[i + 1] == '.') {
				cout << "Yes" << endl;
				return 0;
			}
		}
		cout << "No" << endl;
		return 0;
	}
	if (A<B && C>D) {
		if (abs(A - B) == 1) {
			if (mas[max(A, B)] == '.') {
				cout << "Yes" << endl;
				return 0;
			}
		}
		for (int i = max(A, B)-1; i < min(C, D); i++) {
			if (mas[i - 1] == '.' && mas[i] == '.' && mas[i + 1] == '.') {
				cout << "Yes" << endl;
				return 0;
			}
		}
		cout << "No" << endl;
		return 0;
		
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 384
#include "stdio.h"
int main(void)
{
	/* code */
	int a,b,c,tmp;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	if (a>b)
	{
		tmp=a;
		a=b;
		b=tmp;
	}
	if (b>c)
	{
		tmp=b;
		b=c;
		c=tmp;
	}
	if (a>b)
	{
		tmp=a;
		a=b;
		b=tmp;
	}
	printf("%d %d %d\n",a,b,c );
	return 0;
}


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

int main() {
    int w, h, x, y;
    cin >> w >> h >> x >> y;
    cout << 1LL * w * h / 2.0 << ' ' << (x+x == w && y+y == h ? 1 : 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  vector<vector<int>> a(3,vector<int>(3)),c(3,vector<int>(3,0));
  rep(i,3){
    rep(j,3){
      cin >> a[j][i];
    }
  }
  int n;
  cin >> n;
  vector<int> b(n);
  rep(i,n) cin >> b[i];
  rep(i,n){
    rep(j,3){
      rep(k,3){
        if (a[j][k]==b[i]) c[j][k]=1;
      }
    }
  }
  bool ans=false;
  rep(i,3){
    bool t=true,tt=true;
    rep(j,3){
      if (c[i][j]==0) t=false;
      if (c[j][i]==0) tt=false;
    }
  if (tt || t) ans=true;
  }
  bool t=true,tt=true;
  rep(i,3){
    if (c[i][i]==0) t=false;
    if (c[i][2-i]==0) tt=false;
  }
  if (tt || t) ans=true;
  if (ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
/**
 *      ABC 98 B
 *      author  : kyomukyomupurin
 *      created : 2018/08/22
**/

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

int check(string X, string Y){
    int count = 0;
    for (char c = 'a'; c <= 'z'; ++c){
        if (string(X).find(c) != string::npos && string(Y).find(c) != string::npos){
            ++count;
        }
    }
    return count;
}

int main(){
    int N; string S;
    cin >> N >> S;
    int max = 0;

    for (int i = 0; i < N; ++i) {
        string X = S.substr(0, i + 1);
        string Y = S.substr(i + 1, N - i - 1);
        if (check(X, Y) > max){
            max = check(X, Y);
        }
    }

    cout << max << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
ll minthis(ll a, ll b){return a<b?a:b;}
ll maxthis(ll a, ll b){return a>b?a:b;}
bool sortbysec(const pair<int, int>& a,const pair<int, int>& b){return (a.second < b.second);} 
vector<vector<int>> v;

vector<int> vis;
    set<int> s;

void dfs(int n){
    for(auto x : v[n]){
        if(!vis[x]){
            s.insert(x);
            vis[x] = 1;
            dfs(x);
        }
    }
}

void solve(){
    int nodes, edges;
    cin >> nodes >> edges;
    v = vector<vector<int>>(nodes+1);
    vis = vector<int>(nodes+1,0);
    for(int i = 0 ; i < edges ; i++){
        int a,b;
        cin  >> a >> b;
        v[a].pb(b);
        v[b].pb(a);
    }    
    int ans = -1;
    for(int i = 1 ; i <= nodes ; i++){
        if(!vis[i]){
            dfs(i);
            s.insert(i);
            vis[i] = 1;
        }
        ans = maxthis(ans,(int)s.size());
        s.clear();
    }
    cout << ans << "\n";
}
 
 
int main(){ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
  return 0; 
}


Measured memory_bytes: 36716
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;
char f[1000],m[1000],l[1000];
int main() {
	cin>>f>>m>>l;
	cout<<f[0]<<m[0]<<l[0];
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {
    int n;
    std::cin >> n;

    for (int i = 0; i < n; i++) {
        int a;
        std::cin >> a;
        if (a % 2 == 0) {
            if (a % 3 != 0 and a % 5 != 0) {
                std::cout << "DENIED" << std::endl;
                return 0;
            }
        }
    }

    std::cout << "APPROVED" << std::endl;
    return 0;
}


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

int main(){
  std::string str;
  std::cin >> str;
  if (str == "A") std::cout << "T";
  if (str == "G") std::cout << "C";
  if (str == "C") std::cout << "G";
  if (str == "T") std::cout << "A";
  
  return 0; 
}


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

#define N 100

int cost_table[N+1][N+1];

void reset_table();
void update_table(int a, int b, int cost);
int solve_lowest_cost(int n, int a, int b);

int main()
{
	while(1) {
		int n,k;
		scanf("%d %d", &n, &k);
		if (n == 0 && k == 0) {
			break;
		}

		reset_table();

		for (; k > 0; k--) {
			int cmd;

			scanf("%d", &cmd);
			if (cmd == 0) {
				int a, b, cost;

				scanf("%d %d", &a, &b);
				cost = solve_lowest_cost(n, a, b);
				printf("%d\n", cost);

			} else if (cmd == 1) {
				int a, b, cost;

				scanf("%d %d %d", &a, &b, &cost);
				update_table(a, b, cost);
			}
		}

	}
	return 0;
}

void reset_table()
{
	memset(cost_table, 0, sizeof(cost_table));
}

void update_table(int a, int b, int cost)
{
	if (cost_table[a][b] == 0 || cost_table[a][b] > cost) {
		cost_table[a][b] = cost;
		cost_table[b][a] = cost;
	}
}

int solve_lowest_cost(int n, int a, int b)
{
	int i;
	int costs[N+1];
	int visited[N+1];

	for (i=1; i<=n; i++) {
		costs[i] = -1;
		visited[i] = 0;
	}
	costs[a] = 0;

	while (1) {
		int i;
		int min_cost, goal;
		min_cost = -1;
		goal = 0;
		for (i=1; i<=n; i++) {
			if (!visited[i] && costs[i] != -1 &&
					(min_cost == -1 || costs[i] < min_cost)) {
				min_cost = costs[i];
				goal = i;
			}
		}

		if (goal == 0) {
			break;
		}

		visited[goal] = 1;
		for (i=1; i<=n; i++) {
			int new_cost;
			if (visited[i] || cost_table[goal][i] == 0) {
				continue;
			}
			new_cost = costs[goal] + cost_table[goal][i];
			if (costs[i] == -1 || new_cost < costs[i]) {
				costs[i] = new_cost;
			}
		}
	}

	return costs[b];
}

Measured memory_bytes: 644
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    cin >> s;
    int a = 0;
    int b = 0;
    int c = 0;
    int d = 0;
    if (s[0] == s[1]) a++;
    if (s[0] == s[2]) a++;
    if (s[0] == s[3]) a++;
    if (s[1] == s[0]) b++;
    if (s[1] == s[2]) b++;
    if (s[1] == s[3]) b++;
    if (s[2] == s[0]) c++;
    if (s[2] == s[1]) c++;
    if (s[2] == s[3]) c++;
    if (s[3] == s[0]) d++;
    if (s[3] == s[1]) d++;
    if (s[3] == s[2]) d++;
    if (a == 1 && b == 1 && c == 1 && d == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
//header{{{
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <boost/hana/functional/fix.hpp>
#include <boost/sort/spreadsort/spreadsort.hpp>
//#include <boost/graph/adjacency_list.hpp>
//#include <boost/graph/dijkstra_shortest_paths.hpp>
//#include <boost/graph/graph_utility.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
  
using namespace std;
//using namespace boost::multiprecision;
//using namespace boost::math;

/*
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS,
        boost::no_property, boost::property<boost::edge_weight_t, int> > Graph;
*/

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define FixPoint boost::hana::fix
#define bsort boost::sort::spreadsort::spreadsort
#define int int_fast64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

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

struct negrightshift {
    inline int operator() (const int &x, const unsigned offset) {
        return -(x >> offset);
    }
};
//}}}


signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(10);

    int n, W;
    cin >> n >> W;

    vector w(n + 1, 0), v(n + 1, 0);

    reps(i,n){
        cin >> w[i] >> v[i];
    }

    vector dp(n + 1, vector(W + 1, -1LL));

    dp[0][0] = 0;

    const auto res = FixPoint([&](auto rec, const auto r, const auto c){
        if(c < 0 || r < 0){
            return (-LINF);
        }else if(~dp[r][c]){
            return (dp[r][c]);
        }

        dp[r][c] = max({rec(r-1, c), rec(r, c-1), rec(r-1, c - w[r]) + v[r]});

        return (dp[r][c]);
    })(n, W);

    cout << res << '\n';

    return 0;
}


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


int main() {
  int N;
  cin>>N;
  vector<long> a;
  int idx=0;
  for(int i=31;i<=55555;i+=30){
    bool flg=true;
    for(int j=2;j*j<=i;j++){
      if(i%j==0) flg=false;
    }
    if(flg) a.push_back(i);
  }
  for(int i=0;i<N;i++){
    cout<<a[i]<<" ";
  }
  cout<<endl;
  }


Measured memory_bytes: 3624
import math
from functools import lru_cache
def Frog1():
    n = int(input())
    h = list(map(int,input().split(' ')))
    @lru_cache(None)
    def Solve(i):
        if i==n-1:
            return 0
        if i==n-2:
            return abs(h[i]-h[i+1])
        return min(Solve(i+1)+abs(h[i]-h[i+1]),Solve(i+2)+abs(h[i]-h[i+2]))
    dp = [0]*n
    for i in reversed(range(n)):
        if i==n-1:
            dp[i] = 0
        elif i==n-2:
            dp[i] = abs(h[i]-h[i+1])
        else:
            dp[i] = min(dp[i+1]+abs(h[i]-h[i+1]),dp[i+2]+abs(h[i]-h[i+2]))
    print(dp[0])
Frog1()




Measured memory_bytes: 20964
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using ld = long double;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vd = vector<double>;
using Vld = vector<long double>;
using Vll = vector<vector<ll> >;
using Vldd = vector<vector<ld> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const ll LINF = LLONG_MAX / 10000;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };

int main()
{
	int n;
	cin >> n;
	Vld P(n);
	rep(i, n)  cin >> P[i];

	Vldd dp(n + 1, Vld(n + 1, 0));
	dp[0][0] = 1.0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= i; j++) {
			dp[i + 1][j + 1] += dp[i][j] * (1.0 - P[i]);
			dp[i + 1][j] += dp[i][j] * P[i];
		}
	}
	ld ans = 0.0;
	rep(i, (n / 2) + 1) ans += dp[n][i];
	cout << fixed;
	cout << setprecision(10);
	cout << ans << endl;

	//rep(i, n + 1) {
	//	rep(j, n + 1) {
	//		cout << " " << dp[i][j];
	//	}
	//	cout << endl;
	//}
}


Measured memory_bytes: 144232
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <map>
#include <deque>
#include <queue>
#include <climits>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(v) sort(v.begin(), v.end())
#define SORTFUNC(v, func) sort(v.begin(), v.end(), func)
#define PRINT(v) REP(i, v.size()) printf("%d ", v[i]); cout << endl
#define SCI(n) int (n); scanf("%d", &(n))
#define SCL(n) ll (n); scanf("%I64d", &(n))
#define IN(n) scanf("%d", &(n))

int main(){
  int a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  bool ok = true;
  REP(i, a) if(!((s[i]-'0')>=0 && (s[i]-'0')<=9)) ok = false;
  if(s[a]!='-') ok = false;
  REP(i, b) if(!((s[i+a+1]-'0')>=0 && (s[i+a+1]-'0')<=9)) ok = false;
  if(ok) puts("Yes");
  else puts("No");
  return 0;
}
























// I'd like to scroll past the end of document using Atom but I seemigly have to use these blank lines instead


Measured memory_bytes: 256
//httips://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let sum = a.iter().fold(0, |s, a| s + *a);
    let w = 8 * std::mem::size_of::<usize>();
    let mut dp = vec![0usize; (sum + 1 + w - 1) / w];
    dp[0] = 1;
    for a in a {
        let (q, r) = (a / w, a % w);
        let mut next = dp.clone();
        if r == 0 {
            for i in (q..next.len()).rev() {
                next[i] = next[i - q];
            }
        } else {
            for i in ((q + 1)..next.len()).rev() {
                let x = next[i - q];
                let y = next[i - q - 1];
                next[i] = (x << r) | (y >> (w - r));
            }
            next[q] = next[0] << r;
        }
        for i in (0..q).rev() {
            next[i] = 0;
        }
        for (dp, next) in dp.iter_mut().zip(next.iter()) {
            *dp |= *next;
        }
    }
    let mut ans = (sum + 1) / 2;
    while (dp[ans / w] >> (ans % w)) & 1 == 0 {
        ans += 1;
    }
    println!("{}", ans);
}

fn main() {
    run();
}


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

long long ans = 0;

void rec(long long s, long long p, long long sum){
  if(s%p == s){
    ans += sum + s;
    return;
  }
  rec(s/p, 10, sum + s%p);
  rec(s, p*10, sum);
  return;
}

int main(){
  long long s;
  cin >> s;
  rec(s, 10, 0);
  cout << ans << endl;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    string A=YES;
    for (int i=0; i<S.length(); ++i){
        if (i%2==0 && S[i]=='L') {
            A=NO;
            break;
        }
        if (i%2==1 && S[i]=='R') {
            A=NO;
            break;
        }
    }
    cout << A << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int start = 1;
        int goal = n;
        int m = sc.nextInt();
        Set<Integer> checkPoint1 = new HashSet<Integer>();
        Set<Integer> checkPoint2 = new HashSet<Integer>();
        
        boolean clear = false;
        while (m-- > 0) {
            int p = sc.nextInt();
            int q = sc.nextInt();
            
            if (p == start) {
                if (checkPoint2.contains(q)) {
                    clear = true;
                    break;
                }
                checkPoint1.add(q);
            } else if (q == goal) {
                if (checkPoint1.contains(p)) {
                    clear = true;
                    break;
                }
                checkPoint2.add(p);
            }
        }
        
        if (clear) {
            System.out.println("POSSIBLE");
        } else {
            System.out.println("IMPOSSIBLE");
        }
    }
}


Measured memory_bytes: 103188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int a[maxn];
int b[maxn];
int c[maxn];
int main()
{
    int m,n;
    cin>>n;

    int k=0;
    for(int i=0;i<=n;i++)
        cin>>a[i];
   for(int i=0;i<n;i++)
    cin>>b[i];
   ll ans=0;
    ll sum=0;
   for(int i=0;i<n;i++)
   {
       if(b[i]>=a[i])
       {
           sum+=a[i];
           b[i]-=a[i];
           if(b[i]>=a[i+1])
           {
             sum+=a[i+1];
             b[i]-=a[i+1];
             a[i+1]=0;
           }
           else
           {
            sum+=b[i];
            a[i+1]-=b[i];
           }
           a[i]=0;
       }
       else
       {
           sum+=b[i];
           a[i]-=b[i];
       }
   }
  cout<<sum<<endl;


    return 0;
}


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

int main() 
{
        int n;
        int i;
        int a;
        int count;
        int min;

        cin >> n;
        i = -1;
        while (++i < n)
        {
                cin >> a;
                count = 0;
                while (a % 2 == 0)
                {
                        count++;
                        a /= 2;
                }
          		if (i == 0 || min > count)
                	min = count;
        }
        cout << min << endl;
}


Measured memory_bytes: 256
/*---- enazuma11-------  */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define inc(a,n) sort(a,a+n)
#define dec(a,n) sort(a,a+n,greater<int>() )
#define F first
#define S second
#define M 1000000007
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n,mp;
	cin>>n>>mp;
	map<int,vector<int>> m;
	int x,y;
	vector<pair<int,int>> v;
	for(int i=0;i<mp;i++){
		cin>>x>>y;
		m[x].pb(y);
		v.pb({x,y});
	}
	for(auto i=m.begin();i!=m.end();i++)
	sort(all(i->second));
	for(int i=0;i<mp;i++){
		string s="";
		string pre=to_string(v[i].F);
		for(int i=0;i<6-pre.size();i++)
		s+='0';
		s+=pre;
		int b=lower_bound(all(m[v[i].F]),v[i].S)-m[v[i].F].begin();
		string suf=to_string(b+1);
		for(int i=0;i<6-suf.size();i++)
		s+='0';
		s+=suf;
		cout<<s<<'\n';
	}
	return 0;
}

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

int main(){
    int n,a=-1,b=-1,c=0;
    cin >>n;
    int arr[n];
    for (int i = 0; i < n; i++){
        cin>>arr[i];
    }

    for (int i=0; i<n-2; i++){
        if(arr[i]!=i+1){
            a=i;
            break;
        }
    } 

    for (int i = n - 1; i >= 0; i--)
    {
        if(arr[i]!=i+1){
            b=i;
            break;
        }
    }
    if(a!=-1 && b!= -1) swap(arr[a],arr[b]);

    for (int i=0; i<n-2; i++){
        if(arr[i+1]-arr[i] !=1) c++;
    }

    if(c) cout<<"NO";
    else cout<<"YES";

    return 0;
}

Measured memory_bytes: 256