akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10 **5)

# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

readline = sys.stdin.readline

def proc():
    k,n = map(int,readline().rstrip().split())
    #2x + 4y = n
    p,q = -1,-1
    ans = []
    #print(k,n, "**")
    for i in range(0, 101):
        for j in range(0,101):
            #print(i,j,"***")
            if 2*i + 4*j == n:
                p,q = i,j
                ans.append( (p,q))

    for pair in ans:
        p,q = pair[0],pair[1]
        if p+q == k:
            return "Yes"
    
    return "No"



#for _ in range(int(readline())):
print(proc())


Measured memory_bytes: 9140
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  int q;
  cin >> q;
  while(q--) {
    int b, e, t;
    cin >> b >> e >> t;
    swap_ranges(a.begin()+b, a.begin()+e, a.begin()+t);
  }
  for(int i = 0; i < n; ++i) cout << a[i] << " \n"[i==n-1];

  return 0;
}



Measured memory_bytes: 3096
#include <stdio.h>

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

	if (a < b) {
		printf("a < b\n");
	}

	if (a > b) {
		printf("a > b\n");
	}

	if (a == b) {
		printf("a == b\n");
	}
	
	return 0;
}

Measured memory_bytes: 1008
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long 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 long long INF = 1LL << 60;

string s;

void EraseWord(string word){
  string::size_type pos(s.find(word));
  while(pos != std::string::npos){
    s.replace(pos, word.length(), "");
    pos = s.find(word, pos);
  }
}

int main(){
  cin >> s;

  EraseWord("eraser");
  EraseWord("erase");
  EraseWord("dreamer");
  EraseWord("dream");

  cout << (s.size() == 0 ? "YES" : "NO") << endl;

  return 0;
}


Measured memory_bytes: 512
program name
    integer(4):: n,i,cnt
    real(8),allocatable:: x(:), y(:)
    real(8):: ans

    read*, n
    allocate(x(n), y(n))
    do i=1,n
        read*, x(i), y(i)
    end do
    ans=0d0
    cnt=0
    do i=1,n
        do j=1,n
            if (i==j) cycle
            ans=ans+dst(i,j)
            cnt=cnt+1
        end do
    end do
    print*, ans/cnt*dble(n-1)

contains
function dst(a,b) result(ret)
    integer(4):: a,b
    real(8):: ret

    ret = sqrt((x(a)-x(b))**2+(y(a)-y(b))**2)
end function
end program name

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;

int main() {
    string s;
    int K;
    cin >> s >> K;
    vector<string> subStrs;
    int n = s.size();
    for (int i=0; i<n; i++) {
        for (int j=1; j<=5; j++) {
            subStrs.push_back(s.substr(i, j));
        }
    }
    map<string, int> mp;
    rep(i, subStrs.size()) mp[subStrs[i]]++;
    int cnt = 1;
    for(auto p: mp) {
        if (cnt == K) {
            cout << p.first << endl;
            break;
        }
        cnt++;
    }
    return 0;
}


Measured memory_bytes: 2556
import itertools

ans = []

while True:
	n = int(input())
	k = int(input())
	if n == 0 and k == 0:
		break

	cards = []
	ans_set = []

	for i in range(n):
		cards.append(input())

	for i in itertools.permutations(cards, k):
		ans_set.append(int("".join(i)))
	
	ans.append(len(set(ans_set)))

for i in ans:
	print(i)


Measured memory_bytes: 5988
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
l = list(map(int, input().split()))
L = [None]*N

for i in range(N):
    n = l[i]
    L[i] = [n,i+1]

L.sort()
ans = [None]*N
for i in range(N):
    ans[i] = str(L[i][1])
print(' '.join(ans))

Measured memory_bytes: 28416
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;

int main() {
    int n, t[100005] = { 0 }, x[100005] = { 0 }, y[100005] = { 0 };
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> t[i] >> x[i] >> y[i];
    bool check = true;
    for (int i = 1; i <= n; i++) {
        int dis = x[i] - x[i - 1] + y[i] - y[i - 1], tdis = t[i] - t[i - 1];
        if ((tdis<dis)||((tdis - dis) % 2 != 0)) {
            check = false;
            break;
        }
    }
    if (check) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 1408
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n);
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); ++i)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)          (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)          (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define mp                  make_pair
#define pb                  push_back

typedef long long ll;
typedef unsigned long long ull;

#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)

#ifdef _DEBUG
#define pf printf
#define pr(n) do { cout << #n " = " << (n) << endl; } while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#endif

inline D inprd(const P &a, const P &b){ return (conj(a) * b).X; }

void solve(P p1, P p2, P pq){
    D n = inprd(p2-p1, pq-p1) / abs(p2-p1);
    P p3 = p1 + polar(n, arg(p2-p1));
    P p4 = p3 + (p3-pq);
    printf("%f %f\n", p4.X, p4.Y);
}

int main(){
    string s;
    while(cin >> s){
        double x1,y1,x2,y2,xq,yq;
        sscanf(s.c_str(), "%lf,%lf,%lf,%lf,%lf,%lf", &x1,&y1,&x2,&y2,&xq,&yq);
        P p1(x1,y1), p2(x2,y2), pq(xq,yq);
        solve(p1, p2, pq);
    }
    return 0;
}

Measured memory_bytes: 1352
#include <stdio.h>

int main(void)
{
	char inp[256];
	char buf[256];
	int i;
	int sl;
	int s;
	int len;
	int ret;
	do {
		ret = scanf("%s", inp);
		len = strlen(inp);
		if (len == 1 && inp[0] == '-')
			break;
		scanf("%d", &sl);
		for (i = 0; i < sl; i++)
		{
			buf[0] = '\0';
			scanf("%d", &s);
			strncat(buf, inp + s, len - s);
			strncat(buf, inp,  s);
			strcpy(inp, buf);
		}
		printf("%s\n", inp);
	} while (ret != EOF);

	return 0;
}


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

int main() {
	int n,cnt=-1;cin>>n;
  	int t,a;cin>>t>>a;
  	vector<int> h(n);for(int i=0;i<n;i++) cin>>h[i];
  	double absmin=10000;
  	for(int i=0;i<n;i++){
    	if(absmin>abs(t-h[i]*0.006-a)){
        	absmin=abs(t-h[i]*0.006-a);
          	cnt=i;
        }   	
    }
  	cout<<cnt+1<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

typedef long long ll;

constexpr int INF = 1e8;
constexpr int MOD = 1e9+7;

string field[100];
bool used[100][100];
int dxy[] = {0,1,0,-1};
int h, w;

void dfs(int y, int x) {
    if (used[y][x]) return;
    used[y][x] = true;
    int i;
    REP (i,4) {
        int ny = y + dxy[i];
        int nx = x + dxy[(i+1)%4];
        if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
        if (field[ny][nx] == field[y][x]) dfs(ny,nx);
    }
}

int main(void) {
    while (true) {
        int i, j;
        cin >> h >> w;
        if (h == 0 && w == 0) break;
        REP (i,h) cin >> field[i];

        REP (i,h) REP (j,w) used[i][j] = false;
        int ans = 0;
        REP (i,h) REP (j,w) if (!used[i][j]) {
            dfs(i,j);
            ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4348
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const ll MOD=1e9+7;



int main() {
    ios_base::sync_with_stdio(false);

    ll x;
    cin >> x;
    vector<ll> a(3765);
    a[0]=100;
    rep(i,3760) {
        a[i+1]=a[i]+a[i]/100;
    }
    ll ans=0;
    rep(i,a.size()) {
        if (a[i]>=x) {
            ans=i;
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3684
n=int(input())
s=set()
w=input()
s.add(w)
for _ in range(n-1):
  x=input()
  if x in s:
    print('No')
    exit()
  if w[-1]!=x[0]:
    print('No')
    exit()
  s.add(x)
  w=x
print('Yes')

Measured memory_bytes: 38384
n=int(input())
w=[]
for i in range(n):
  w.append(input())
ans=True
for i in range(n-1):
  if w[i][-1]!=w[i+1][0]:
    ans=False
if len(set(w))!=n:
  ans=False
if ans:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9124
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { println ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }

fn main() {
    let (n, s) = get!(usize, u64);
    let seq = util::gets::<u64>();

    let mut ans = n + 1;
    let mut l = n;
    let mut sum = 0;

    for r in (0..n).rev() {
        while sum < s && l > 0 {
            l -= 1;
            sum += seq[l];
        }
        if sum >= s {
            ans = min(ans, r - l + 1);
        }
        sum -= seq[r];
    }

    if ans > n {
        println!("{}", 0);
    } else {
        println!("{}", ans);
    }
}



Measured memory_bytes: 5036
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


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

  vi a(3);
  rep(i,3){
    cin>>a[i];
  }
  sort(all(a));

  cout<<a[0]*a[1]/2<<endl;


}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    if (n%2 == 1){
      System.out.println((n+1)/2);
    }
    else{
      System.out.println(n/2);
    }
  }
}


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

int main(){
    vector<int> a(3);
    rep(i,3){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    cout << abs(a.at(0)-a.at(1))+abs(a.at(1)-a.at(2));
}

Measured memory_bytes: 256
/*
 * :(
 * You taught me so much, I'm not scared anymore
 * 	I have to left go your hands that are holding me
 * 	 Even if I'm alone, I'll go on, even if it hurts
 * 	  I'll never forget the dream, I shared with you
 * 	   I'm glad to be with everyone, I'm glad to have been with everyone
 * 	    But on the morning when I wake up, no one is there
 */
//#define opti
#ifdef opti
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#endif
#ifndef opti
#pragma GCC optimize("O3")
#endif
#include <bits/stdc++.h>
using namespace std;
#ifndef rd
//#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
#define double long double
#define pii pair<int,int>
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define all(con) con.begin(),con.end()
#define shuffle(a,b) random_shuffle(a,b,rng)
#define deb cout<<"Line: "<<__LINE__<<" pls "
typedef long long ll;
const ll mod=1000000007;
const ll inf=1e18;
//const ll mod=998244353;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll powm(ll a, ll b, ll m);

int a[1001],prefa[1001];
void solve()
{
	int n,k;
	cin>>n>>k;
	for(int i=1; i<=n; i++) {
		cin>>a[i];
		prefa[i]=prefa[i-1]+a[i];
	}
	int ans=0;
	for(int bit=50; bit>=0; bit--)
	{
		ans=ans+powm(2,bit,inf);
		int hol=0;
		for(int i=1; i<=n; i++)
			for(int j=i; j<=n; j++)
			{
				if(((prefa[j]-prefa[i-1])&ans)==ans)
					hol++;
//				cout<<((prefa[j]-prefa[i-1])&ans)<<" "<<ans<<endl;
			}
		if(hol<k)
			ans-=(powm(2,bit,inf));
	}
	cout<<ans<<endl;
}
signed main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	#ifdef rd
		clock_t clk = clock();
	#endif
	int t=1;
//	cin>>t;
	while(t--)
		solve();
	#ifdef rd
		clk = clock() - clk;
		cout<<endl<<endl<< "Time Elapsed: " << fixed << setprecision(10) << ((double)clk)/CLOCKS_PER_SEC <<endl;
	#endif
	return 0;
}
ll powm(ll a,ll b, ll m)
{
	ll te=1;
	while(b)
	{
		if(b&1)
			te=(te*a)%m;
		a=(a*a)%m;
		b>>=1;
	}
	return te;
}


Measured memory_bytes: 384
#include<bits/stdc++.h> 
using namespace std; 
// Binary indexed tree supporting binary search.
 
 
#define x first
#define y second
 
#define forn(i, n) for(int i = 0; i < int(n); ++i)
 
typedef pair<int, int> pii;
//#define forn(i, a,b) for (int i = (int) a; i <= (int) b; ++i)

int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int K,A,B;
    cin>>K>>A>>B;
    int p = B/K;
    int q = (A-1)/K;
    if(p-q){
    	cout<<"OK"<<endl;
	}
	else{
		cout<<"NG"<<endl;
	}
	return 0;	
}

Measured memory_bytes: 3652
#include <stdio.h>

int binarySearch(int,int);

int T[100000],S[500000];

int main() {

  int n,q,i,x,key,count=0;
    
  scanf("%d",&n);
  for(i = 0; i < n; i++) {
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i = 0; i < q; i++) {
    scanf("%d",&T[i]);
  }
  for(i = 0; i < q; i++) {
    x = binarySearch(n,T[i]);
   
    if(x != -1) count++;
  }
  
  printf("%d\n",count);
  return 0;
}

int binarySearch(int n,int key)
{
  int left,right,mid;
  left = 0;
  right = n;
  
  while(left < right) {
    mid = (left + right)/2;
    if(key == S[mid])
      return mid;
    
    else if(key > S[mid])
      left = mid + 1;
    
    else if(key < S[mid])
      right = mid;
  }
    return -1;   
}



Measured memory_bytes: 2384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C;
  cin >> A >> B >> C;
  
  if (A+B>C) {
    cout << B+C <<endl;
  }
  else if (A+B==C) {
    cout << A+2*B <<endl;
  }
  else if (A+B<C) {
    cout << A+2*B+1 <<endl;
  }
}

Measured memory_bytes: 256
S = input()

P = 10**9+7
LENGTH = len(S)

"""dp[i][j] -> あり得る全ての上からi+1桁目までの数を13で割った余りが j となる状態数"""
dp = [[0 for i in range(13)] for j in range(LENGTH)]

if S[0]=='?':
    for j in range(10):
        dp[0][j]+=1
else:
    dp[0][int(S[0])]+=1

for i in range(LENGTH-1):
    for j in range(13):
        if S[i+1]=='?':
            for k in range(10):
                dp[i+1][(10*j+k)%13]+=dp[i][j]%P
        else:
            dp[i+1][(10*j+int(S[i+1]))%13]+=dp[i][j]%P

print(dp[LENGTH-1][5]%P)

Measured memory_bytes: 65756
open System

let INF = 1000000007L
let N,W =stdin.ReadLine().Split()|>fun c -> int c.[0],int64 c.[1]
let w = Array.create N 0L
let v = Array.create N 0
[<EntryPoint>]
let main argv =
    for i in [0..N-1] do
        let input = stdin.ReadLine().Split()|>Array.map int64
        w.[i] <- input.[0]
        v.[i] <- (input.[1]|>int)
    let dp = Array2D.create (N+1) (1000*N+1) INF
    for i in [0..N] do dp.[i,0] <- 0L
    for i in[1..N] do
        for j in [0..(1000*N)] do
            dp.[i,j] <- if (j-v.[i-1])<0 then dp.[i-1,j] else min dp.[i-1,j] (dp.[(i-1),(j-v.[i-1])]+w.[i-1])
    let ans = Array.create (1000*N+1) 0
    for i in [0..(1000*N)] do
        ans.[i] <- if dp.[N,i]<=W then i else 0
    Array.max ans
    |>stdout.WriteLine
    0

Measured memory_bytes: 143072
#素数でない数
#   1
#   ２以外の２の倍数
#   二乗してもnumberを超えない奇数で割り切れる数
def checkPrime(number)
  if number == 2
    return true
  elsif number % 2 == 0
    return false
  else
    i = 3
    while (i * i < number + 1)
      if number % i == 0
        return false
      end
      i += 2
    end
  end
  return true;
end

#入力バッファ
numPrime = Array.new(1000000)
input = ""
counter = 0

#あらかじめ素数の数を求めておく
numPrime[0] = 0
numPrime[1] = 0
for i in 2...numPrime.size
  numPrime[i] = numPrime[i - 1]
  if checkPrime(i)
    numPrime[i] += 1
  end
end

#メインルーチン
while input = gets
  p numPrime[input.to_i]
end

Measured memory_bytes: 13904
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

template<class T>
bool chmax(T &a, const T &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T>
bool chmin(T &a, const T &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}


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

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

int main(){
    int A, B; cin >> A >> B;
    cout << lcm(A, B) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    int n, sum = 0;
    scanf("%d", &n);
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        scanf("%d", &vec[i]);
        sum += vec[i];
    }
    if(sum%10 == 0){
        sort(vec.begin(), vec.end());
        for(int i=0;i<n;i++){
            if(vec[i] % 10 != 0){
                sum -= vec[i];
                break;
            }
        }
        sum = sum%10 != 0 ? sum : 0;
    }
    printf("%d", sum);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int M, D, d1, d2;
    int ans = 0;

    scanf("%d %d", &M, &D);
    d1 = D%10;
    d2 = D/10;
    
    for(int i=2; i<=d2; i++){
        for(int j=2; j<10; j++){
            if(i==d2 && j>d1){
                break;
            }
            for(int k=1; k<=M; k++){
                if(k == i*j){
                    ans++;
                }
            }
        }
    }

    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

using namespace std;

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    if (a < b) {
        printf("a < b\n");
    } else if(a > b) {
        printf("a > b\n");
    } else {
        printf("a == b\n");
    }
    return 0;
}


Measured memory_bytes: 2588
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <fstream>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <stack>
#include <map>
#include <set>
#if __cplusplus > 199711L
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//	tree<key, mapped = null_type, cmp = less<key>, rb_tree_tag, tree_order_statistics_node_update> name;
//	order_of_key
//	find_by_order
#endif

using namespace std;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fs first
#define sc second
#define abs(a) ((a) < 0 ? -(a) : (a))
#define sqr(a) ((a) * (a))

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

inline pair<pair<bool, bool>, pair<string, bool> > useinout();

void initialization() {
#ifdef SOL
	if (useinout().fs.fs)
		freopen("input.txt", "r", stdin);
	if (useinout().fs.sc)
		freopen("output.txt", "w", stdout);
#else
	srand(time(0));
	const string file = useinout().sc.fs;
	if (!file.empty()) {
		freopen((file + ".in").c_str(), "r", stdin);
		freopen((file + ".out").c_str(), "w", stdout);
	}
	if(useinout().sc.sc) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
#endif
}

int solve();

void finish(int exitval) {
	fflush(stdout);
#ifdef SOL
	fprintf(stderr, "\nexit value: %d\ntime: %.3lf ms\n", exitval, 1000. * clock() / CLOCKS_PER_SEC);
#endif
}

int main() {
	initialization();
	int exitval = solve();
	finish(exitval);
	return (0);
}

const double eps = 1e-9;
const int mod = (int) 1e+9 + 7;
const double pi = acos(-1.);
const int maxn = 100100;



int solve() {

	string s;
	bool ok1 = 0, ok2 = 0;
	getline(cin, s);
	for (int i = 0; i < (int) s.length(); i++) {
		if (s[i] == 'C') {
			ok1 = 1;
		}
		if (s[i] == 'F' && ok1) {
			ok2 = 1;
		}
	}
	if (ok2) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	return (0);
}

inline pair<pair<bool, bool>, pair<string, bool> > useinout() {
	return (mp(mp(0, 0), mp("", 0)));
}

// by Andrey Kim


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

using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using D = double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define rep(i, x)  for(int i = 0; i < (x); i++)
#define rrep(i, x) for(int i = (x - 1); i >= 0; i--)
#define sqrt(x) sqrt(abs(x))
#define y1 y1_1234413
#define j1 j1_235
#define y0 y0_235
#define j0 j0_256
#define fi first
#define se second
#define re return
#define prev PREV
#define next NEXT
#define sz(x) ((int)x.size())

template<typename T> T sqr(T a) { re a * a; }
template<typename T> T gcd(T a, T b) { re b ? gcd(b, a % b) : a; }
template<typename T> T sgn(T a) { re a > 0 ? 1 : (a < 0 ? -1 : 0); }
template<typename T> T abs(T a) { re a > 0 ? a : -a; }

const int inf = 2e9;
const ld st = 0.000001;
const ld pi = acos((ld)-1);
const int MAXN = 100000;

#define FILENAME ""


int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    //  freopen(FILENAME ".in", "r", stdin);
    //  freopen(FILENAME ".out", "w", stdout);
    ll n;
    cin >> n;
    vector <ll> a;
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        a.pb(x);
    }
    vector <ll> b = a;
    sort(b.begin(), b.end());
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] != b[i]) ans++;
    }
    if (ans == 2 || ans == 0) {
        cout << "YES";
    }
    else {
        cout << "NO";
    }
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N, Q = map(int, input().split())
V = {i: [] for i in range(1,N+1)}
for _ in range(N-1):
    a, b = map(int, input().split())
    V[a].append(b)
    V[b].append(a)

C = {i: 0 for i in range(1,N+1)}

for _ in range(Q):
    p, x = map(int, input().split())
    C[p] += x


def propagate(u, p):
    for v in V[u]:
        if v == p:
            continue
        C[v] += C[u]
        propagate(v, u)

propagate(1, 0)

print(' '.join(str(C[i]) for i in range(1,N+1)))


Measured memory_bytes: 267628
while True:
    n=int(input())
    if n==0:
        break
    
    s=1
    for i in range(1,n+1,1):
        s*=i
        i+=1
        
    v=0
    while True:
        if s%10==0:
            s=s//10
            v+=1
        else:
            break
    print(v)


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

  int N , M , l ;
  int ans = 0 ;
  cin >> N >> M >> l ;
  cout << l << endl;
  cout << N << endl;
  cout << M << endl;
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
typedef pair<int, int> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<int> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

const int N = 8;

void print_board(set<P> &board, set<P> &question_board) {

    for (P p : question_board) {
        if (!contain(board, p)) return;
    }

    rep(i, N) {
        rep(j, N) {
            cout << (contain(board, P(i, j)) ? 'Q' : '.');
        }
        cout << endl;
    }
}

void
recursive(int i,
          set<P> &board,
          set<P> &question_board,
          vector<bool> &row,
          vector<bool> &col,
          vector<bool> &dpos,
          vector<bool> &dneg) {
    if (i == N) {
        print_board(board, question_board);
        return;
    }
    for (int j = 0; j < N; j++) {
        if (!(col[j] && dpos[i + j] && dneg[i - j + N - 1])) continue;

        row[i] = false;
        col[j] = false;
        dpos[i + j] = false;
        dneg[i - j + N - 1] = false;

        board.insert(P(i, j));

        recursive(i + 1, board, question_board, row, col, dpos, dneg);

        board.erase(P(i, j));
        row[i] = true;
        col[j] = true;
        dpos[i + j] = true;
        dneg[i - j + N - 1] = true;


    }
}

int main() {
    vector<bool>
            row(N, true),
            col(N, true),
            dpos(2 * N - 1, true),
            dneg(2 * N - 1, true);

    set<P> question_board;
    set<P> board;

    int n;
    cin >> n;

    rep(i, n) {
        int r, c;
        cin >> r >> c;
        question_board.insert(P(r, c));
    }

    recursive(0, board, question_board, row, col, dpos, dneg);


}




Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<long long> h(n);
  for(int i=0;i<n;i++)cin>>h.at(i);
  vector<int> a(m),b(m);
  vector<bool> ok(n,true);
  for(int i=0;i<m;i++)cin>>a.at(i)>>b.at(i);
  for(int i=0;i<m;i++){
    a.at(i)--;
    b.at(i)--;
    if(h.at(a.at(i))>=h.at(b.at(i)))ok.at(b.at(i))=false;
    if(h.at(b.at(i))>=h.at(a.at(i)))ok.at(a.at(i))=false;
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(ok.at(i))ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4860
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
#define X first
#define Y second
#define REP(i,n) for(int i=0;i<(int)(n);i++)
typedef pair<int, int> P;
typedef pair<int, P> Elm;

const int WMAX = 500, HMAX = 500;
const int LMAX = 100000000;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

int office[WMAX][HMAX], level[WMAX][HMAX];

void dijkstra(int w, int h, int sx, int sy) {
  REP(y, h) {
    REP(x, w) {
      level[x][y] = LMAX;
    }
  }
  priority_queue<Elm, vector<Elm>, greater<Elm> > que;
  que.push( Elm(1, P(sx, sy)) );
  level[sx][sy] = 1;

  while (!que.empty()) {
    int lev = que.top().first; P p = que.top().second;
    que.pop();

    if (level[p.X][p.Y] < lev) continue;

    REP(i, 4) {
      int x = p.X + dx[i], y = p.Y + dy[i];
      if (x < 0 or w <= x or y < 0 or h <= y) continue;
      
      int newlevel = max(office[x][y], lev);
      if (newlevel < level[x][y]) {
        level[x][y] = newlevel;
        que.push(Elm(newlevel, P(x, y)));
      }
    }
  }
}

vector<int> count_level(int w, int h) {
  vector<int> v;
  v.push_back(0);
  REP(y, h) {
    REP(x, w) {
      v.push_back(level[x][y]);
    }
  }
  sort(v.begin(), v.end());
  return v;
}

vector<int> make_level_table() {
  int w, h, sx, sy;
  cin >> w >> h >> sx >> sy;
  REP(y, h) {
    REP(x, w) {
      cin >> office[x][y];
    }
  }
  dijkstra(w, h, sx - 1, sy - 1);
  return count_level(w, h);
}

int search(int key, 
    vector<int>::iterator begin, vector<int>::iterator end) {
  if (key == 0) return 0;
  pair<vector<int>::iterator, vector<int>::iterator> eqr = 
    equal_range(begin, end, key);
  return eqr.second - eqr.first;
}

int main() {
  int r, w, h, sx, sy;
  while (cin >> r and r) {
    vector<int> ltab1 = make_level_table();
    vector<int> ltab2 = make_level_table();

    vector<int>::iterator lev1 = ltab1.end() - 1, 
      lev2 = ltab2.begin();
    int rooms = ltab1.size() - 1;
    int ans = 2 * LMAX + 1;

    while (lev1 != ltab1.begin()) {
      while (rooms < r and lev2 != ltab2.end()) {
        lev2 = upper_bound(lev2, ltab2.end(), *lev2);
        rooms += search(*lev2, lev2, ltab2.end());
      }
      
      if (rooms < r or lev2 == ltab2.end()) break;
      ans = min(ans, *lev1 + *lev2);
      
      rooms -= search(*lev1, ltab1.begin(), lev1 + 1);
      lev1 = lower_bound(ltab1.begin(), lev1, *lev1) - 1;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 5508
A,B,K = map(int, input().split())

rtn = max(A, B); 
rtn_list =[] 
while len(rtn_list) < K:
    if not(A % rtn) and not(B % rtn):
        rtn_list.append(rtn)
    rtn -= 1
print(rtn_list[-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


int main() {
    cin>>N>>K;
    ll ans = 1;
    rep(i,N){
        if(ans >= K) ans += K;
        else ans *= 2;
    }
    cout<<ans<<endl;
}

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

#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define obit __builtin_popcount
#define pof pop_front
#define mod (int)1e9 + 7
#define For(i,a,n) for(i=a;i<n;i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned short int us;
typedef short int ss;
typedef long double ld;

vector<int> pri;
void ini(){
    bool pnp[1000001];
    memset(pnp,true,sizeof(pnp));
    for(ll a = 2;a * a <= 1000000; a ++){
        if(pnp[a]){
            for(ll b = 2 * a; b<= 1000000; b += a) pnp[b] = false;
        }
    }
    for(ll a = 2;a<=1000000;a++) if(pnp[a]) pri.pb(a);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    /*
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    //*/
    ini();
    ll x;
    cin>>x;
    cout<<*lower_bound(pri.begin(),pri.end(),x);
    return 0;
}

Measured memory_bytes: 1916
def main():
    k = int(input())

    num = 1 
    n = 7
    
    if (k%2 == 0):
        print(-1)
        return
    

    for i in range(1000000):
        if (n%k == 0):
            print(num)
            return
        else:
            n = (n*10 + 7)%k
            num += 1

    print(-1)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	ll n; cin >> n;
	if(n==2){
		cout << 1 << endl;
		return 0;
	}
	int ans=2;
	for(int i=2;i<=sqrt(n);i++){
		if(n%i==0){
			ll m=n;
			while(m%i==0){
				m/=i;
				if((m-1)%i==0)
					ans++;
			}
		}
	}
	n--;
	for(int i=2;i<=sqrt(n);i++){
		if(n%i==0){
			ans+=2;
			if(i==sqrt(n))
				ans--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    int x[n];
    for(int i = 0;i < n;i++)scanf("%d",&x[i]);
    long long int sum = 0;
    for(int i = 0;i < n;i++)sum += x[i];
    double avg = (double)sum / n;
    int i_avg = (int)avg  + ((avg - (int)avg) > 0.5?1:0);
    long long ans = 0;
    for(int i = 0;i < n;i++)ans += (x[i] - i_avg) * (x[i] - i_avg);
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	
	
	
	
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		//Random sc =new Random();
		int N=sc.nextInt();
		
		Map<String, Integer> map = new HashMap<String, Integer>(N);
		
		
		
		char a[]=new char[10];
		String t;
		for(int i=0;i<N;i++) {
			a=sc.next().toCharArray();
			Arrays.sort(a);
			t=String.valueOf(a);
		//	p(t);
			if(map.containsKey(t)) {
				map.replace(t, map.get(t)+1);
			}else {
				map.put(t, 1);
			}
		}
		
		long sum=0;
		for(String h:map.keySet()) {
			//p(h);
			long v=map.get(h.toString());
			if(v!=1) {
				
					sum+=(v)*(v-1)/2;
				
					
				
			}
		}
		p(sum);
	}
	
	
	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


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

int main() {
	// your code goes here
	int n;cin>>n;
	int dp[n][3];
	for(int i=0;i<n;i++){
		cin>>dp[i][0]>>dp[i][1]>>dp[i][2];
	}
	
	for(int i=1;i<n;i++){
		dp[i][0]+=max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]+=max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]+=max(dp[i-1][1],dp[i-1][0]);
		
	}
	
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
	
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, ai, check, two, four;
    string ans;
    scanf("%d", &n);
    check = floor(n / 2);
    two = 0; four = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &ai);
        if (ai % 2 == 0 && ai % 4 != 0) two++;
        if (ai % 4 == 0) four++;
    }
    if (four >= check) ans = "Yes";
    else {
        if (four <= 0 && two >= n) ans = "Yes";
        else if (two >= (check - four) * 2) ans = "Yes";
        else ans = "No";
    }
    cout << ans << endl;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>     
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long
#define int ll
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof( i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
 
using namespace std;
 
const int maxn = (int)2e5 + 100;
const int mod = (int)1e9 + 7;
 
#define inf mod
 
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;   
typedef vector<ll> Vll;               
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;
                           
int n, h[maxn], c, dp[maxn];
       
struct line{
  int k, b;
  line(){
    k = b = 0;
  }
  line(int _k, int _b){
    k = _k, b = _b;
  }
  int get(int x){
    return k * x + b;
  }
};
vector<line> lines;
                  
ld intersect(line l1, line l2){  
  return (ld)(l2.b - l1.b) / (l1.k - l2.k);
}
 
bool bad(line l1, line l2, line l3){
  ld q1 = intersect(l1, l2);
  ld q2 = intersect(l1, l3);
  return q1 >= q2;
}
void add(int i){
  line cur = line(-2 * h[i], dp[i] + h[i] * h[i]);
  while(sz(lines) > 1 && bad(lines[sz(lines) - 1], lines[sz(lines) - 2], cur))
    lines.pop_back();
  lines.pb(cur);
}
int get(int x){
  int l = 0, r = sz(lines) - 1;
  while(l < r){
    int mid = (l + r) >> 1;
    if(lines[mid].get(x) > lines[mid + 1].get(x))
      l = mid + 1;
    else
      r = mid;
  }
  return lines[r].get(x);
}
main () {
  cin >> n >> c;
  forn(i, 1, n) cin >> h[i];
  dp[1] = 0;
  add(1);
  forn(i, 2, n){
    dp[i] = get(h[i]) + h[i] * h[i] + c;
    add(i);
  }
  cout << dp[n];

}

Measured memory_bytes: 9328
# -*- coding: utf-8 -*-

n = int(input())
s = input()

acc = [0]*(n+1)
for i in range(n):
    acc[i+1] = acc[i]
    if s[i]==".":
        acc[i+1] += 1

res = 10**6
for i in range(n+1):
    r = acc[n] - acc[i]
    r += i - acc[i]
    res = min(res, r)

print(res)


Measured memory_bytes: 11240
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    if(N <= K){
        cout << N*X << "\n";
    }else{
        cout << (K*X)+(N-K)*Y << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
 
int main()
{
	string s;
	cin >> s;
  	int n= s.size(),i;
    if(!(n%2))
    {
		printf("No");
      	return 0;
    }
  	for(i=0;i<(n-1)/2;i++)
    {
      if(s[i]!=s[n-1-i])
      {
		printf("No");
        return 0;
      }
    }
   int l=(n-1)/2;
   for(i=0;i<(l-1)/2;i++)
    {
      if(s[i]!=s[l-1-i])
      {
		printf("No");
        return 0;
      }
    }
    
  	if(!(l%2))
    {
    
      if(s[(l/2) -1 ]!=s[l/2])
      {
          
		printf("No");
        return 0;
      }
    }
  printf("Yes");
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

const int MAX_V = 11;
int d[MAX_V][MAX_V];
int V;
int x[MAX_V];

void floyd_warshall()
{
	for(int k = 0; k < V; k++){
		for(int i = 0; i < V; i++){
			for(int j = 0; j < V; j++){
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

int main()
{
	int E;
	while(cin>>E && E){
		memset(d, 0x3f, MAX_V * MAX_V *sizeof(int));
		for(int i = 0; i < MAX_V; i++){
			d[i][i] = 0;
		}
		V = 0;
		for(int i = 0; i < E; i++){
			int u, v, cost;
			cin>>u>>v>>cost;
			d[u][v] = cost;
			d[v][u] = cost;
			V = max(V, max(v, u) + 1);
		}
		floyd_warshall();
		memset(x, 0, V * sizeof(int));
		for(int i = 0; i < V; i++){
			for(int j = 0; j < V; j++){
				x[i] += d[i][j];
			}
		}
		int ans = min_element(x, x + V) - x;
		cout<<ans<<' '<<x[ans]<<endl;
	}
	return 0;
}


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

res = [0] * (M + 1)

for _ in range(N):
    A = list(map(int, input().split()))
    K = A.pop(0)
    for a in A:
        res[a] += 1

ans = 0

for r in res:
    if r == N:
        ans += 1

print(ans)

Measured memory_bytes: 9192
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const long long Maxn=100000+10,mod=1000000000000000000;
long long n,a[Maxn],ans;
inline bool check(long long x,long long y)
{
	long long a[100],c[100],tot=0;
	while(y)a[++tot]=y%10,y/=10;
	memset(c,0,sizeof(c));
	for(long long i=0;;++i)
	{
		if(!x)break;
		long long tmp=x%10;
		for(long long j=1;j<=tot;++j)
		c[i+j]+=tmp*a[j];
		x/=10;
	}
	tot=94;
	for(long long i=1;i<=tot;++i)
	c[i+1]+=c[i]/10,c[i]%=10;
	while(!c[tot])--tot;
	if(tot>19)return 1;
	long long ret=0;
	for(long long i=1;i<=tot;++i)
	ret=ret*10+c[i];
	if(ret>mod)return 1;
	return 0;
}
inline long long read()
{
	long long s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0' && ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*w;
}
int main()
{
//	freopen("in.txt","r",stdin);
	n=read();
	for(long long i=1;i<=n;++i)
	a[i]=read();
	for(long long i=1;i<=n;++i)
	if(!a[i]){puts("0");return 0;}
	ans=a[1];
	for(long long i=2;i<=n;++i)
	{
		if(check(ans,a[i])){puts("-1");return 0;}
		ans*=a[i];
	}
	printf("%lld\n",ans);
	return 0;
}

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

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

fn solve(mut n: i32) {
    if n == 0 {
        println!("0");
        return;
    }

    let mut st = Vec::<i8>::new();

    while n != 0 {
        if n % 2 != 0 {
            st.push(1);
            n -= 1;
        } else {
            st.push(0);
        }
        n /= -2;
    }

    while let Some(top) = st.pop() {
        print!("{}", top);
    }
    println!("");
}

fn main() {
    let n = read::<i32>();
    solve(n);
}


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

const int mod=1e9+7;
const int maxn=2e5+100;

int a[maxn];
double A[maxn],val[maxn];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    double sum=0,maxe=-1;
    for(int i=1;i<=1000;i++){
        sum+=i;
        val[i]=sum/i;
    }
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<n;i++)
        A[i]=val[a[i]];
        //A[i]=(a[i]+1)/2.0;
    sum=0;
    for(int i=0;i<k;i++){
        sum+=A[i];
    }
    maxe=max(maxe,sum);
    for(int i=k;i<n;i++){
        sum+=A[i];
        sum-=A[i-k];
        maxe=max(maxe,sum);
    }
    printf("%.6f\n",maxe);
    //cout<<maxe<<endl;
    return 0;
}
/*

*/


Measured memory_bytes: 2560