akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int N=2049;
int a[N][N],n,m;
void solve(int r1,int r2,int c1,int c2) {
	//printf("%d %d %d %d\n", r1,r2,c1,c2);
	if(r1==r2 && c1==c2) {
		a[r1][c1]=1;
		return;
	}
	int midr=(r1+r2)>>1, midc=(c1+c2)>>1;
	//printf("midr=%d,midc=%d\n", midr,midc);
	a[midr][midc]=1;
	solve(r1,midr-1,c1,midc-1);
	int d=(r2-r1)/2+1;
	for(int i=r1;i<=midr-1;i++){
		for(int j=c1;j<=midc-1;j++){
			a[i][j+d]=a[i][j];
			a[i+d][j]=a[i][j];
			a[i+d][j+d]=a[i][j];
		}
	}
}
int main() {
	scanf("%d%d",&n,&m);
	solve(0,(1<<10)-1,0,(1<<10)-1);
	for(int i=0;i<((1<<n)-1);i++){
		for(int j=0;j<((1<<m)-1);j++){
			printf("%d", a[i][j]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 9472
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
#define ld long double
#define pii pair <int,int>
#define pll pair <ll,ll>
#define pil pair <int,ll>
#define pli pair <ll,int>
#define ull unsigned long long
#define pdd pair <double,double>
#define pb push_back
#define mp make_pair
#define puu pair<ull,ull>
#define pvv pair<vector<int>, vector<int> >
#define _bp __builtin_popcount
#define ptt pair <Tree*,Tree*>
#define all(v) v.begin(),v.end()
#define en "\n"
const long double pi = acos(-1);
void boos()
{
     ios_base :: sync_with_stdio(false);
     cin.tie(0);
     cout.tie(0);
}
void file()
{
   freopen("max.in","r",stdin);
   freopen("max.out","w",stdout);
}
const ll INF = 1e9 + 7;
const ll INF1 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTmx = (int)1e9;
const ld EPS = (ld)1e-9;
const int N = 2e3 + 100;
int ans[N];
int main()
{
    //file();
    boos();
    int n,x,y;
    cin >> n >> x >> y;
    for(int i = 1;i < n;i++)
    {
    	for(int j = i + 1;j <= n;j++)
    	{
    		int rst = j - i;
    		rst = min(rst,abs(i - x) + abs(j - y) + 1);
			ans[rst]++;
		}
	}
	for(int i = 1;i < n;i++)
	{
		cout << ans[i] << en;
	}
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
last = -10
for i in range(N):
  eat = A[i] -1 
  ans += B[eat]
  if last == eat - 1:
    ans += C[eat-1]
  
  last = eat
  
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<set>

using namespace std; 

int main(){
    set<int> st;
    int N;
    cin >> N;
    for(int i=0;i<N;i++){
        int in;
        cin >> in;
        if(st.find(in)!=st.end()){
            st.erase(in);
        }else{
            st.insert(in);
        }
    }
    cout << st.size() << endl;
}

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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

#define chmax(x, y) x = max(x, y)

i64 dp[4][3005][3005];

u32 v[3000][3000];

int main() {
  u32 r, c, k;
  cin >> r >> c >> k;

  rep(i, k) {
    u32 ri, ci, vi;
    cin >> ri >> ci >> vi;
    v[ri - 1][ci - 1] = vi;
  }

  rep(i, r) rep(j, c) {
    for (u32 ki = 3; ki > 0; ki--) {
      chmax(dp[ki][i][j], dp[ki - 1][i][j] + v[i][j]);
    }
    rep(ki, 4) {
      chmax(dp[0][i + 1][j], dp[ki][i][j]);
      chmax(dp[ki][i][j + 1], dp[ki][i][j]);
    }
  }

  cout << max({dp[0][r - 1][c - 1], dp[1][r - 1][c - 1], dp[2][r - 1][c - 1],
               dp[3][r - 1][c - 1]});

  return 0;
}


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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;



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


	ll x;cin>>x;

	ll m =100LL;
	for(int i=1; i<=4000; i++){
		m *=1.01;

		if(m >=x){
			writeln(i);
			return 0;
		}
	}

}




Measured memory_bytes: 3648
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int a;cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n) 
#define ALL(x) x.begin(),x.end() 
#define P pair<ll,ll> 
#define F first
#define S second 
signed main(){
  ll A,B,C,D;cin>>A>>B>>C>>D;
  A=(A+D-1)/D;C=(C+B-1)/B;
  if(A<C)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
  int n;
  cin >> n;
  
  double result = (n+1)/2 / (1.0*n);
  cout << fixed << setprecision(6) << result << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int n;
int main()
{
    scanf("%d",&n);
    int a=n/100;
    int b=n%100/10;
    int c=n%10;
    if(a==7||b==7||c==7) printf("Yes\n");
    else printf("No\n");
    return 0;
}


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

using namespace std;

const double INF = 1e20;

typedef tuple< double, int, int > Pi;

int main()
{
  int N, A[100], B[100];

  while(cin >> N, N) {
    vector< int > height;
    for(int i = 0; i < N; i++) {
      cin >> A[i] >> B[i];
      height.push_back(B[i]);
    }

    sort(begin(height), end(height));
    height.erase(unique(begin(height), end(height)), end(height));
    vector< pair< double, int > > beet;
    for(int h : height) {
      for(int i = 0; i < N - 1; i++) {
        if(min(B[i], B[i + 1]) < h && h < max(B[i], B[i + 1])) {
          double delta = (double) (A[i + 1] - A[i]) / (B[i + 1] - B[i]);
          beet.emplace_back(A[i] + delta * (h - B[i]), h);
        }
      }
    }
    for(int i = 0; i < N; i++) {
      beet.emplace_back(A[i], B[i]);
    }
    sort(begin(beet), end(beet));

    int sz = beet.size();
    map< pair< int, int >, double > v;
    priority_queue< Pi, vector< Pi >, greater< Pi > > que;
    que.emplace(0.0, 0, sz - 1);
    v[{0, sz - 1}] = 0;

    while(!que.empty()) {
      double cost;
      int l, r;
      tie(cost, l, r) = que.top();
      que.pop();
      if(cost > v[{l, r}]) continue;
      if(l == r) {
        cout << fixed << setprecision(10) << cost << endl;
        break;
      }
      for(int i = max(l - 1, 0); i <= min(l + 1, sz - 1); i++) {
        for(int j = max(r - 1, 0); j <= min(r + 1, sz - 1); j++) {
          if(beet[i].second == beet[j].second) {
            double ncost = cost;
            ncost += sqrt(pow(beet[l].second - beet[i].second, 2) + pow(beet[l].first - beet[i].first, 2));
            ncost += sqrt(pow(beet[r].second - beet[j].second, 2) + pow(beet[r].first - beet[j].first, 2));
            if(v.count({i, j}) && v[{i, j}] <= ncost) continue;
            v[{i, j}] = ncost;
            que.emplace(ncost, i, j);
          }
        }
      }
    }
  }
}

Measured memory_bytes: 5136
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
#define MOD 1000000007
#define int long long

bool pr[(int)1e6];

signed main(){
    fill(pr,pr+(int)1e6,true);
    pr[0]=false,pr[1]=false;
    int x;cin>>x;
    for(int i=2;i*i<=2*x;i++)for(int j=i*2;j<2*x;j+=i)pr[j]=false;
    for(int i=x;;i++)
        if(pr[i]){cout<<i<<endl;return 0;}
}

Measured memory_bytes: 1280
#include <cstdio>

char bio[256];
int main(void) {
    int result = 0;
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        char c;
        scanf(" %c", &c);
        result += bio[(int)c] == 0;
        bio[(int)c] = 1;
    }

    puts(result == 3 ? "Three" : "Four");
    return 0;
}


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

num2 = 0
num4 = 0
numo = 0

for a in A:
    if a % 4 == 0:
        num4 += 1
    elif a % 2 == 0:
        num2 += 1
    else:
        numo += 1

if num2 == 0:
    if num4 + 1 >= numo:
        print("Yes")
    else:
        print("No")
else:
    if num4 >= numo:
        print("Yes")
    else:
        print("No")
        

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

// I hate
int main(){
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    a--, b--, c--, d--;
    bool valid = true;    
    if(c > d){ // snuke overtakes the other
        valid = false;
        for(int i = b-1; i+2 <= d+1; i++){
            valid |= (s[i]=='.'&&s[i+1]=='.'&&s[i+2]=='.');
        }
    }
    for(int i = a; i+1 < c; i++){
        valid &= (s[i]=='.' || s[i+1]=='.');
    }
    for(int i = b; i+1 < d; i++){
        valid &= (s[i]=='.' || s[i+1]=='.');
    }
    cout << (valid ? "Yes" : "No") << endl;
    return 0;
}

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

using namespace std;

int main(){
    long double A,B,C,D,E,F,defo=-1,answ=0,anss=0;
    cin >> A >> B >> C >> D >> E >> F;
    vector<long double> water,sugar;

    for(int i=0;i<=F/100/A;i++){
        for(int j=0;j<=(F-100*i*A)/100/B;j++){
            water.push_back(100*A*i + 100*B*j);
        }
    }

    for(int i=0;i<=F/C;i++){
        for(int j=0;j<=(F-i*C)/D;j++){
            sugar.push_back(C*i+D*j);
        }
    }


    for(int i=0;i<water.size();i++){
        for(int j=0;j<sugar.size();j++){

            if(sugar[j] <= water[i]*E/100 && (water[i]+sugar[j])<=F){

                if(defo<100*sugar[j]/(water[i]+sugar[j])){
                    defo = 100*sugar[j]/(water[i]+sugar[j]);
                    answ = i;
                    anss = j;
                }
            }
        }
    }

    cout << water[answ]+sugar[anss] << " " << sugar[anss] << endl;
}

Measured memory_bytes: 4852
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>


using namespace std;

typedef pair<int, int> PII;

int main() {
	int n, a;

	cin >> n;
	vector<int> n_card(1e5 + 1, 0);
	for (int i = 0; i < n; i++) {
		cin >> a;
		n_card[a]++;
	}

	priority_queue<PII> que;
	for (int i = 0; i < n_card.size(); i++) {
		if (n_card[i] > 0) {
			que.push(make_pair(n_card[i], i));
		}
	}


	while (!que.empty()) {
		auto p1 = que.top();
		if (p1.first == 1) {
			break;
		}

		// printf("%3d %3d\n", p1.first, p1.second);
		que.pop();
		if (p1.first >= 3) {
			p1.first -= 2;
			que.push(p1);
			continue;
		}

		if (que.empty()) {
			break;
		}

		auto p2 = que.top();
		que.pop();

		if (p1.first == 2) {
			p1.first--;
			p2.first--;
			que.push(p1);
			if (p2.first > 0) {
				que.push(p2);
			}
			continue;
		}

		if (que.empty()) {
			break;
		}

		auto p3 = que.top();
		que.pop();
	}

	cout << que.size() << endl;
	return 0;
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  int A,B,C,K; cin >>A >>B >>C >>K;
  if (K<=A) cout <<K <<endl;
  else if (K<=A+B) cout <<A <<endl;
  else cout <<A-(K-A-B) <<endl;
  return 0;
}


Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(i64 i = 0; i < N; i++)
#define all(v) v.begin(), v.end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

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

    i64 ans = 0;
    rep(i, N+1){
        if(i % 3 == 0 || i %  5 == 0) continue;
        ans += i;
    }
    Cout(ans);
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define per(i,j,n) for(int i=(int)(j);(int)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define pb push_back
#define mp make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::pair;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<int>;
using vii=vector<vi>;
using pii=pair<int,int>;
const ll MOD=1e9+7;
const int MAX=1e5+1;
const ll INF=(1ll<<62)-1;
signed main(){
    int N; cin>>N;
    vector<pii> a(2*N);
    rep(i,0,2*N){
        cin>>a[i].first;
        a[i].second=i/N;
    }
    sort(ALL(a));
    vi cnt(2);
    ll ans=1;
    rep(i,0,2*N){
        int mem=a[i].second;
        cnt[mem]++;
        if(cnt[mem]<=cnt[1-mem]){
            ans*=cnt[1-mem];
            ans%=MOD;
            cnt[0]--;
            cnt[1]--;
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var firstLine = Console.ReadLine().Split(' ').Select(value => long.Parse(value)).ToList();
			var n = firstLine[0];
			var k = firstLine[1];
			
			if(n == 0 || n % k == 0)
			{
				Console.WriteLine("0");
				return;
			}

			n -= (n / k) * k;
			n = Math.Min(n, Math.Abs(n - k)); 

			Console.WriteLine(n);
		}
	}
}


Measured memory_bytes: 11220
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    String [] g = new String[n];
    for (int i=0;i<n;i++){
      g[i] = scan.next();
    }
    HashMap<String,Integer> t = new HashMap<String,Integer>();
    ArrayList<String> tt = new ArrayList<String>();

    for (int j=0;j<n;j++){
        char[] gg = new char[10];
        for (int k=0;k<10;k++){
          gg[k] = g[j].charAt(k);
        }
        Arrays.sort(gg);
        String check = "";
        for (int p=0;p<10;p++){
          check += Character.toString(gg[p]);
        }
        if (t.get(check) == null){
          t.put(check,1);
          tt.add(check);
        }
        else{
          int y = t.get(check);
          t.put(check,y+1);
        }
    }


    long sum = 0;
    for (int i=0;i<tt.size();i++){
      int m = t.get(tt.get(i));
      sum += (long) m*(m-1)/2;
    }
    System.out.println(sum);

  }
}


Measured memory_bytes: 76932
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main() {
	int a, b; cin >> a >> b;
	string s; cin >> s;
	if(s.size() != a + b + 1) {
		printf("No\n"); return 0;
	}

	if (s[a] != '-') {
		printf("No\n"); return 0;
	}

	rep(i, s.size()) {
		if(i == a) continue;
		if(!('0' <= s[i] && s[i] <= '9')) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 256
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def main():
    n = int(input())
    ans = 0
    for i in range(n):
        ans += i + 1
    print(ans)
    return

if __name__=='__main__':
    main()


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

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W;
    cin >> H >> W;
    if (H % 3 == 0 || W % 3 == 0) {
        cout << 0 << endl;
        return 0;
    }
    int ans = INF2;
    rep(k, 2) {
        rep(i, W + 1) {
            int S1 = H * i;
            int S2 = (H + 1) / 2 * (W - i);
            int S3 = H / 2 * (W - i);
            //cout << S1 << " " << S2 << " " << S3 << endl;
            ans = min(ans, max({S1, S2, S3}) - min({S1, S2, S3}));
        }
        ans = min(ans, W);
        swap(H, W);
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int bs(int a[], int n) {
	int sw = 0;
	int i = 0;
	int flag = 1;
	while (flag) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw++;
			}
		}
		i++;
	}
	return sw;
}

int main() {
	int a[100];
	int sw = 0;
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sw = bs(a, n);
	for (int i = 0; i < n; i++) {
		if (i) {
			cout << " ";
		}
		cout << a[i];
	}
	cout << endl;
	cout << sw << endl;
	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0; return gcd(a, b, x, y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
int n, a, ans;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 0, n){
    cin >> a;
    while(a % 2 == 0){
      ans++;
      a >>= 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		long N = nextLong();
		long A = nextLong();
		long B = nextLong();

		long ans;
		long dif=B-A;
		if(dif%2==0){
			ans=dif/2;
		}else{
			long sub = Math.min(A-1, N-B);
			ans=sub+(dif-1)/2 +1;
		}
		System.out.println(ans);

	}
	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21204
#include <iostream>

using namespace std;

typedef long long ll;

ll N;

int dfs(ll x, bool b7, bool b5, bool b3, int d, int D) {
  if (d == D) {
    if (b7 && b5 && b3 && x <= N) return 1;
    else return 0;
  }
  bool b[3] = {b7, b5, b3};
  bool c[3] = {b7, b5, b3};

  int sum = 0;
  for (int i = 0; i < 3; i++){
    int k = i*2+3; // 3,5,7
    c[i] = true;
    sum += dfs(10*x+k, c[0], c[1], c[2], d+1, D);
    c[i] = b[i];
  }
  return sum;
}

int main() {
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= 9; i++) {
    ans += dfs(0, false, false, false, 0, i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque
def main():
    X = list(input().rstrip())
    past = deque()
    cnt = 0
    last = X[0]
    for i in range(1,len(X)):
        if last + X[i] == 'ST':
            if len(past) > 0:
                last = past.pop()
            else:
                last = ''
            cnt += 2
        else:
            past.append(last)
            last = X[i]
    print(len(X) - cnt)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 6556
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
int N, K, L;
map<pair<int, int>,int> mp;
int find(int x, int *w) {
    if (w[x] == x) {
        return x;
    } else {
        return w[x] = find(w[x], w);
    }
}
void solve() {
    cin >> N >> K >> L;
    int road[N], railway[N];
    for (int i = 0; i < N; i++) {
        road[i] = i;
        railway[i] = i;
    }
    for (int i = 0; i < K; i++) {
        int p,q,road_p,road_q;
        cin >> p >> q;
        road_p = find(p - 1, road);
        road_q = find(q - 1, road);
        if (road_p != road_q) road[road_p] = road_q;
    }
    for (int i = 0; i < L; i++) {
        int r,s,rail_r,rail_s;
        cin >> r >> s;
        rail_r = find(r - 1, railway); 
        rail_s = find(s - 1, railway); 
        if (rail_r != rail_s) railway[rail_r] = rail_s;
    }
    for (int i = 0; i < N; i++) {
        int u, v;
        u = find(i, road);
        v = find(i, railway);
        mp[{u, v}]++;
    }
    for (int i = 0; i < N; i++) {
        int u, v;
        u = find(i, road);
        v = find(i, railway);
        cout << mp[{u, v}] << " ";
    }
    cout << "\n";
    return;
}
//逆元を求める関数
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
      fac[i] = fac[i-1] * i % MOD;
      inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
      finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
//組み合わせ
long long COM (int n, int k) {
    if(n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}
int main(int args, char* argv[]) {
    solve();
}

Measured memory_bytes: 13568
import math

x, k, d = map(int, input().split())

nk = abs(x) // d
if k <= nk:
    if x >= 0:
        x -= d * k
    else:
        x += d * k
    print(abs(x))
    exit(0)
    
if x >= 0:
    x -= d * nk
else:
    x += d * nk
k -= nk

if k > 0 and k % 2 == 1:
    if x >= 0:
        x -= d
    else:
        x += d
print(abs(x))


Measured memory_bytes: 9212
#include <iostream>

using namespace std;

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

    int counter[N][2];
    for (int i = 0; i < N; ++i) {
        int f = (S[i] == 'W' ? 1 : 0);
        counter[i][0] = (i > 0 ? counter[i - 1][0] : 0) + f;
        counter[i][1] = (i > 0 ? counter[i - 1][1] : 0) + (1 - f);
    }

    for (int i = 0; i < N; ++i) {
        if (S[i] == 'W') {
            counter[i][0]--;
        }

        counter[i][1] = counter[N - 1][1] - counter[i][1];
    }

    int ans = 1000000000;
    for (int i = 0; i < N; ++i) {
        ans = min(ans, counter[i][0] + counter[i][1]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3076
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)                                                                             
#define seg_size 524288
int main() {
	int n;
	cin >> n;
	vector<int> wow;
	REP(i, n) {
		int tmp;
		cin >> tmp;
		wow.push_back(tmp);
	}
	sort(wow.begin(), wow.end(), greater<int>());
	wow.push_back(0);
	for (int i = 1;i < wow.size();++i) {
		if (i >= wow[i]) {
			i--;
			if ((wow[i] - i) % 2 == 0) {
				cout << "First" << endl;
				return 0;
			}
			for (int q = i;q < wow.size();++q) {
				if (wow[q] <= i) {
					if ((q - i) % 2 == 0) {
						cout << "First" << endl;
					}
					else {
						cout << "Second" << endl;
					}
					return 0;
				}
			}
			cout << "Second" << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fastcin  ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

void solve(){
	long double a, b, h, m;
	cin >> a >> b >> h >> m;
	
	if(h > 12)h-=12;
	if(h == 0)h=12;
	
	long double angle = abs(((m*M_PI)/360 + (h*M_PI)/6)- (m*M_PI)/30);
	long double ans = sqrt(a*a + b*b - 2*a*b*cosl(angle));
	
	printf("%.20Lf\n",ans);
}

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

Measured memory_bytes: 4136
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll n;
  cin>>n;
  vector<ll> v;
  rep(i,1,10){
    rep(j,1,10){
      v.pb(i*j);
    }
  }
  ll flag = 0;
  rep(i,0,v.sz){
    if(v[i]==n)flag = 1;
  }
  if(flag==1){
      cout << "Yes" << endl;
  }
  else{
      cout << "No" << endl;
  }
  return 0;
}

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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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


int main() {
    cout<<fixed<<setprecision(10);

    int n;  cin>>n;
    if(n<=999){
        puts("ABC");
    }else{
        puts("ABD");
    }

    return 0;

}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys



def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007



n, x = LI()
a, p = [1], [1]
for i in range(n):
    a += [a[i] * 2 + 3]
    p += [p[i] * 2 + 1]


def f(n, x):
    if n == 0:
        return x
    elif x == a[n]:
        return p[n]
    elif x <= 1:
        return 0
    elif 1 < x <= 1 + a[n - 1]:
        return f(n - 1, x - 1)
    else:
        return p[n - 1] + 1 + f(n - 1, x - a[n - 1] - 2)



print(f(n, x))


Measured memory_bytes: 39024
#include <iostream>
#include <limits>
#include <cfenv>
#include <cmath>
#include <algorithm>
#include <array>
#include <bitset>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <tuple>
#include <queue>
#include <vector>
#include <cmath>
#include <random>
#include <math.h>
#include <list>
#include <random>
#include <functional>


#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) for(int (i) = (n) - 1; (i) >= 0; --(i))
#define ALL(TheArray) TheArray.begin(), TheArray.end()

using lli = long long int;
using pii = std::pair<int, int>;

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


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


constexpr int N = 30000;
char str[N+10];
std::bitset<10> F;
std::bitset<100> S;
std::bitset<1000> A;


int main(void){
    int n; scanf("%d%s", &n, str);
    REP(i, n){
        int c = str[i] - '0';
        for(int p = 0; p < 100; ++p) if(S[p]) A[10 * p + c] = true;
        for(int p = 0; p < 10; ++p) if(F[p]) S[10 * p + c] = true;
        F[c] = true;
    }
    const int m = A.count();
    printf("%d\n", m);

    
    return 0;
}

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

int main()
{
  int n, m, v, p;
  cin >> n >> m >> v >> p;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  //降順
  sort(a.begin(), a.end(), greater<int>());
  
  int ans = 0;
  //二分探索
  int ok = 0, ng = n;
  while(abs(ok - ng) > 1)
  {
    int mid = (ok + ng) / 2;
    bool flag = true;
    //check関数
    [&]
    {
      //全員mid問目に投票する。その結果、上位p問に入らないならfalse
      int aa = a[mid] + m;
      if(aa < a[p - 1])
      {
        flag = false;
        return;
      }
      
      //上位p問には全員投票する（mid含む）
      int vv = v - p;
      if(vv <= 0) return;
      
      //残った票をp+1問目以降の問題に貪欲に割り振っていく
      ll sum = m;
      sum *= vv;
      for(int i = p - 1; i < n; i++)
      {
        if(i == mid) continue;
        sum -= min((aa - a[i]), m);
        if(sum <= 0) return;
      }
      
      //票が残ったならfalse
      if(sum > 0) flag = false;
    }();
    
    if(flag) ok = mid;
    else ng = mid;
    
  }
  cout << ok + 1 << endl;
  
  return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <math.h>
using namespace std;

int main(){
    long long int n;
    cin>>n;
    if(n==1){
        cout<<0<<endl;
    }
    else{
        cout<<1<<endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()

using namespace std;

void swap(int &a,int &b){
  int temp=b;
  b=a;
  a=temp;
}

int main(int argc, char const *argv[]) {
  int N;
  scanf("%d",&N);
  std::vector<int> P(N);
  std::vector<bool> same(N,false);
  for (size_t i = 0; i < N; i++) {
    std::cin >> P[i];
    if(P[i]==i+1){
      same[i]=true;
    }
  }
  int counter=0;
  for (size_t i = 0; i < N; i++) {
    if(same[i]==true){
      ++counter;
      if(same[i+1]==true && i!=N-1){
        swap(P[i],P[i+1]);
        same[i]=false;
        same[i+1]=false;
      }else if(i!=0){
        swap(P[i],P[i-1]);
        same[i]=false;
      }else{
        swap(P[i],P[i+1]);
        same[i]=false;
      }
    }
  }
  printf("%d\n",counter);
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int n;

int main() {
    cin >> n;
    int k = 1;
    while(k * (k + 1) / 2 <= n) {
        ++k;
    }
    --k;
    int dif = n - k * (k + 1) / 2;
    for(int i = 1; i <= k - dif; ++i) {
        cout << i << "\n";
    }
    for(int i = k - dif + 1; i <= k; ++i) {
        cout << i + 1 << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int N;
string S;

LL dp[1234][1234];
const LL MOD = 1000000007;

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		char c[2];
		cin >> c;
		if (c[0] != '-')S.push_back(c[0]);
	}
	N = S.size();
	dp[0][0] = 1;
	for (int i = 0; i < N; ++i) {
		for (int a = 0; a <= N; ++a) {
			if (S[i] == 'D') {
				dp[i + 1][a] += dp[i][a] * a % MOD;
				dp[i + 1][a] %= MOD;
				if (a) {
					dp[i + 1][a - 1] += dp[i][a] * a * a % MOD;
					dp[i + 1][a - 1] %= MOD;
				}
			}
			else {
				dp[i + 1][a] += dp[i][a] * a;
				dp[i + 1][a] %= MOD;
				dp[i + 1][a + 1] += dp[i][a];
				dp[i + 1][a + 1] %= MOD;
			}
		}
	}
	cout << dp[N][0] << endl;
	return 0;
}


Measured memory_bytes: 4272
// https://atcoder.jp/contests/abc164/tasks/abc164_f

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

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DEBUG 1
#if DEBUG
  #define _GLIBCXX_DEBUG
  #define DUMP(a) REP(_i, a.size()) cout << a[_i] << (_i + 1 == a.size() ? "\n" : " ")
  #define DUMP2D(b) REP(_j, b.size()) DUMP(b[_j]); cout << endl
#else
  #define DUMP(a)
  #define DUMP2D(b)
#endif

const int N_MAX = 500;
const int ALL_0 = 0;
const int ALL_1 = 1;
const int HAS_0 = 2;
const int HAS_1 = 3;

int N;
vector<int> S;
vector<int> T;
vector<ull> U;
vector<ull> V;

int line_pat(int s, ull u, int k) {
  ull f = u >> k & 1;
  if (s == 0) {
    return f ? ALL_1 : HAS_0;
  } else {
    return f ? HAS_1 : ALL_0;
  }
}

int main() {
  cin >> N;
  S = vector<int>(N);
  REP(i, N) cin >> S[i];
  T = vector<int>(N);
  REP(i, N) cin >> T[i];
  U = vector<ull>(N);
  REP(i, N) cin >> U[i];
  V = vector<ull>(N);
  REP(i, N) cin >> V[i];

  vector<vector<ull>> a = vector<vector<ull>>(N, vector<ull>(N, 0ULL));
  REP (k, 64) {
    vector<int> rp = vector<int>(N);
    REP(i, N) rp[i] = line_pat(S[i], U[i], k);
    vector<int> cp = vector<int>(N);
    REP(i, N) cp[i] = line_pat(T[i], V[i], k);

    vector<int> r1 = vector<int>(N, 0);
    vector<int> c1 = vector<int>(N, 0);

    REP(i, N) REP(j, N) {
      if (rp[i] == ALL_1 && cp[j] == ALL_0) {
        // cout << "rp[" << i << "]=ALL_1, cp[" << j << "] == ALL_0" << endl;
        cout << "-1" << endl;
        return 0;
      }
      if (rp[i] == ALL_0 && cp[j] == ALL_1) {
        // cout << "rp[" << i << "]=ALL_0, cp[" << j << "] == ALL_1" << endl;
        cout << "-1" << endl;
        return 0;
      }

      if (rp[i] == ALL_1 || cp[j] == ALL_1) {
        a[i][j] |= 1ULL << k;
        r1[i]++; c1[j]++;
      } else if (rp[i] == HAS_1 && cp[j] == HAS_1) {
        a[i][j] |= 1ULL << k;
        r1[i]++; c1[j]++;
      }
    }

    int j = 0;
    REP(i, N) {
      if (rp[i] == HAS_0 && r1[i] == N) {
        cout << "-1" << endl;
        return 0;
      }
      if (!(rp[i] == HAS_1 && r1[i] == 0)) continue;
      while(j < N && !(cp[j] == HAS_0 && N - c1[j] > 1)) j++;
      if (j >= N) {
        cout << "-1" << endl;
        return 0;
      }
      a[i][j] |= 1ULL << k;
      r1[i]++; c1[j]++;
    }

    int i = 0;
    REP(j, N) {
      if (cp[j] == HAS_0 && c1[j] == N) {
        cout << "-1" << endl;
        return 0;
      }
      if (!(cp[j] == HAS_1 && c1[j] == 0)) continue;
      while(i < N && !(rp[i] == HAS_0 && N - r1[i] > 1)) i++;
      if (i >= N) {
        cout << "-1" << endl;
        return 0;
      }
      a[i][j] |= 1ULL << k;
      r1[i]++; c1[j]++;
    }
  }

  REP(i, N) REP(j, N) {
    cout << a[i][j];
    if (j == N - 1) cout << endl;
    else cout << " ";
  }
}


Measured memory_bytes: 7696
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

const int maxn = 5005;
ll d[maxn][maxn];

signed main() {
#ifdef LOCAL
  assert(freopen("d.in", "r", stdin));
#endif
  int n;
  cin >> n;
  vector<pair<int, int>> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i].first >> v[i].second;
  }
  sort(v.begin(), v.end(), [](pair<int, int> a, pair<int, int> b) {
        return a.first + a.second < b.first + b.second;
      });
  for (int i = 0; i < maxn; ++i) {
    for (int j = 0; j < maxn; ++j) {
      d[i][j] = 1e18;
    }
  }
  d[0][0] = 0;
  for (int i = 0; i < n; ++i) {
    int h = v[i].first;
    int p = v[i].second;
    for (int k = 0; k < n; ++k) {
      d[i + 1][k] = min(d[i + 1][k], d[i][k]);
      if (d[i][k] <= h) {
        d[i + 1][k + 1] = min(d[i + 1][k + 1], d[i][k] + p);
      }
    }
  }
  for (int k = n; k >= 0; --k) {
    if (d[n][k] < 1e18) {
      cout << k << '\n';
      return 0;
    }
  }
}


Measured memory_bytes: 195968
s = input()
flag = 0
sr = s[-1::-1]
if sr == s:
    flag+=1
s1 = s[:(len(s)-1)//2]
s1r = s1[-1::-1]
if s1 == s1r:
    flag += 1
s2 = s[(len(s)+3)//2-1:]
s2r = s2[-1::-1]
if s2 == s2r:
    flag+=1
print('Yes' if flag == 3 else 'No')


Measured memory_bytes: 8868
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
int main() {
	long long n, m, l;
	cin >> n >> m >> l;
	for (long long i = n; i <= m; i++)
		if (i < n + l)
			cout << i << endl;
		else if(i > m - l)
			cout << i << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - 1e8;
const ll INFLL = numeric_limits<ll>::max() - 1e17;

int main() {
    int N;
    cin >> N;
    vector<ll> a(N + 1), idx(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
        idx[a[i]] = i;
    }
    auto calc = [&](ll left, ll now, ll right) {
        ll dif = right - left - 1, temp = 0;
        // if (dif == 1) return 1LL;
        ll maxValue = (dif + 1) / 2;
        ll minValue = min(now - left, right - now);
        if (minValue == maxValue) {
            temp += maxValue * (maxValue + 1) - (maxValue * (dif % 2 == 1));
        } else {
            temp += minValue * (minValue + 1);
            temp += (maxValue - minValue) * 2 * minValue -(minValue * (dif % 2 == 1));
        }
        return temp;
    };
    ll ans = 0;
    set<ll> explore;
    explore.insert(0);
    explore.insert(N + 1);
    for (int i = 1; i <= N; i++) {
        auto itr = explore.upper_bound(idx[i]);
        ll left = *next(itr, -1);
        ll right = *itr;
        ans += calc(left, idx[i], right) * i;
        explore.insert(idx[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 12800
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

# もしすべてaから選んだ場合
time = k
aOnly = 0
for i in range(len(a)):
    time -= a[i]
    if time < 0:
        time += a[i]
        i -= 1
        break
    aOnly += 1
a_idx = i
b_idx = -1

for i in range(len(b)):
    time -= b[i]
    if time < 0:
        time += b[i]
        i -= 1
        break
    aOnly += 1
b_idx = i
ans = aOnly

ans_kari = ans
for i in range(a_idx, -1, -1):
    time += a[i]
    ans_kari -= 1
    for j in range(b_idx+1, len(b)):
        time -= b[j]
        if time < 0:
            time += b[j]
            b_idx = j-1
            break
        ans_kari += 1
    ans = max(ans, ans_kari)
    
print(ans)

Measured memory_bytes: 41736
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
	string s; cin>>s;
	if (s == "Sunny") cout << "Cloudy" << endl;
	else if (s == "Cloudy") cout << "Rainy" << endl;
	else cout << "Sunny" << endl;
	return 0;
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int main() {
	int a, b, c, d, n, m;
	string s, t, r;
	cin >> a >> b ;
	cout << (a+b-1)/b <<endl;
	return 0;
}

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

int main() {

	ll n; cin >> n;
	const ll p = 100001;
	vector<ll> num(p, 0);
	ll sum = 0;
	for (ll i = 0; i < n; i++) {
		ll a; cin >> a;
		num[a]++;
		sum += a;
	}
	ll q; cin >> q;
	for (ll i = 0; i < q; i++) {
		ll b, c; cin >> b >> c;
		ll tmp_b_cnt = num[b];
		sum -= tmp_b_cnt * b;
		sum += tmp_b_cnt * c;
		num[b] = 0;
		num[c] += tmp_b_cnt;
		cout << sum << endl;
	}
	return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> ii;

const ll INF=2e18;
const int MOD=10000007;

int n; ll s;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n; while(n--){
        int temp; cin>>temp; s+=temp-1;
    } cout<<s;
    return 0;
}


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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))

ll fact[100010];


void solve(){
    fact[0]=fact[1]=1;
    ll n,m;cin>>n>>m;
    ll ma=max(n,m);
    rep(i,2,ma+1){
        fact[i]=(i*fact[i-1])%mod;
    }
    if(m==n){
        cout<<(fact[n]*fact[m]*2)%mod;
    }
    else if(m==n+1 || n==m+1){
        cout<<(fact[n]*fact[m])%mod;
    }
    else cout<<0;


}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long t=1;
    //cin>>t;

    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,X;
  cin>>N>>X;
  int zahyou=0,count=1;
  vector<int>vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
    zahyou+=vec.at(i);
    if(zahyou>X){
      break;
    }
    count++;
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)
#define loop(i,N,M) for(int i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

//変数
ll N,H,W;
vector<ll> vec;


//解法
void solve() {
	
	cout << (N - H + 1) * (N - W + 1);

	return;
}

int main() {
	//入力

	cin >> N>>H>>W;

	solve();
	cout << endl;
	return 0;
}

Measured memory_bytes: 256