akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

#define int long long
#define REP(i,n) for(int i=0;(i)<(n);(i)++)
#define ll long long

int N;
int x[60];
int dp[60][2600][60];//[使える個数][使う個数][合計]で組み合わせ数を持ってdp

void makedp() {
	REP(i, N + 1) {
		REP(j, 2551) {
			REP(k, N + 1) {
				dp[i][j][k] = 0;
			}
		}
	}
	REP(i, N + 1) {
		dp[i][0][0] = 1;//合計を0にするためには使う個数が0なら使える個数に関わらず1通りの方法がある
	}

	int top, dia;
	for (int i = 1;i <= N;i++) {
		for (int j = 1;j <= 2550;j++) {
			for (int k = 1;k <= i;k++) {
				top = dp[i - 1][j][k];
				if (j - x[i] >= 0) dia = dp[i - 1][j - x[i]][k - 1];
				else dia = 0;

				dp[i][j][k] = top + dia;
			}
		}
	}

}

int calcdp(int A) {
	int ans = 0;

	for (int k = 1;k <= N;k++) {
		ans += dp[N][A*k][k];
	}

	return ans;
}

signed main() {
	int A;
	cin >> N >> A;
	REP(i, N) {
		cin >> x[i + 1];//1-indexed
	}

	makedp();

	int ans = calcdp(A);

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 63744
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    string x; cin >> x;
    ll tcnt = 0, scnt = 0;
    rep(i, x.size()){
        if(x[i] == 'S'){
            scnt++;
        }
        else{
            if(scnt >= 1) scnt--;
            else tcnt++;
        }
    }
    cout << scnt+tcnt << endl;
}

Measured memory_bytes: 3736
N,W=map(int,input().split())
w=[]
v=[]
for i in range(N):
    x,y=map(int,input().split())
    w+=[x]
    v+=[y]

V_sum=sum(v)+1
dp=[[float('inf')]*(V_sum) for i in range(N+1)]
dp[0][0]=0
for i in range(1,N+1):
    for sum_v in range(V_sum):
        #同価値の場合より軽いほうを入れる
        if sum_v-v[i-1]>=0:
            dp[i][sum_v]=min(dp[i][sum_v],dp[i-1][sum_v-v[i-1]]+w[i-1])

        dp[i][sum_v]=min(dp[i-1][sum_v],dp[i][sum_v])

ans=0
for i in range(V_sum):
    if dp[-1][i]<=W and ans<i:
        ans=i
print(ans)

Measured memory_bytes: 311632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>
#include<atcoder/all>
using namespace atcoder;

using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define debug(output) cout<<#output<<"= "<<output<<endl

using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;

long long myPow(lint x,lint n){
    lint res=1;
    lint cur=x;
    while(n>0){
        if(n&1){
            res*=cur;
        }
        n/=2;cur*=cur;
    }
    return res;
}
signed main(){
  lint n;cin>>n;
  map<lint,lint> prime;
  lint bbuf=n*2;
  for(lint i=2;i*i<=n*2;++i){
    while(bbuf%i==0){
      bbuf/=i;
      prime[i]+=1;
    }
  }
  if(bbuf>1)prime[bbuf]+=1;

  vector<pair<lint,int>> primes;
  for(auto& val:prime){
    primes.push_back({val.first,val.second});
  }
  lint num=primes.size();
  lint res=inf;
  //if(n%2==1)res=n-1;
  //else res=2*n-1;
  for(lint bit=0;bit<(1<<num);++bit){
    lint a=1;lint b=1;
    for(int i=0;i<num;++i){
      if(bit&(1<<i)){
        a*=myPow(primes[i].first,primes[i].second);
      }
      else{
        b*=myPow(primes[i].first,primes[i].second);
      }
    }
    vector<lint> r(2),m(2);
    r[0]=0;m[0]=a;
    r[1]=b-1;m[1]=b;
    auto p=crt(r,m);
    if(p.first==0)p.first=n*2;
    res=min(res,p.first);
  }
  cout<<res<<"\n";
  return 0;
}


Measured memory_bytes: 3672
#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int main()
{
	int n=read(),m=read();
	if (m*2-1<=n) cout<<"YES";else cout<<"NO";
	return 0;
}

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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

constexpr int mod = 1e9 + 7;
constexpr int32_t inf = 1001001001;
constexpr int64_t infll = 1001001001001001001ll;
constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const string YES = "YES", NO = "NO", Yes = "Yes", No = "No", yes = "yes", no = "no";

// clang-format off
// ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
// ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
// istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }

template <typename T> void sort(vector<T> &v) { sort(all(v)); }
template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  int n = in();
  string a, b, c;
  cin >> a >> b >> c;

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int f = (a[i] == b[i]) + (b[i] == c[i]) + (c[i] == a[i]);
    if (f == 1) {
      ans++;
    } else if (f == 0) {
      ans += 2;
    }
  }

  cout << ans << endl;
}


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

namespace ABC166A
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            if (input == "ABC")
            {
                Console.WriteLine("ARC");
            }
            else
            {
                Console.WriteLine("ABC");
            }
        }
    }
}


Measured memory_bytes: 25852
/**
 *      ABC 49 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-20 07:12:59
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    char c; cin >> c;
    if ((c == 'a' || c == 'e') || ((c == 'i' || c == 'o') || c == 'u')){
        cout << "vowel" << endl; return 0;
    }
    cout << "consonant" << endl;
    return 0;
}

Measured memory_bytes: 256
N, a, b = gets.chomp.split(' ').map(&:to_i)
ans = 0
1.upto(N) do |i|
  digit_sum = 0
  numbers = i.to_s.split('').map(&:to_i)
  numbers.each { |n| digit_sum += n }
  ans += i if a <= digit_sum && digit_sum  <= b
end

puts ans


Measured memory_bytes: 2172
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);

        long A = scanner.nextLong();
        double B = scanner.nextDouble();

        BigDecimal a = new BigDecimal(String.valueOf(A));
        BigDecimal b = new BigDecimal(String.valueOf(B));

        System.out.println(a.multiply(b).longValue());
    }
}


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

int x[3], y[3];

inline int od(){
	int an = 0;
	f(i, 0, 3)y[i] = x[i];
	f(i, 0, 3)if (!(y[i] & 1))--y[i], ++an;
	sort(y, y + 3);
	return (y[2] - y[0] >> 1) + (y[2] - y[1] >> 1) + an;
}

inline int ev(){
	int an = 0;
	f(i, 0, 3)y[i] = x[i];
	f(i, 0, 3)if (y[i] & 1)--y[i], ++an;
	sort(y, y + 3);
	return (y[2] - y[0] >> 1) + (y[2] - y[1] >> 1) + an;
}

int main(){
	f(i, 0, 3)scanf("%d", x + i);
	int an = min(od(), ev());
	printf("%d\n", an);
}

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

using namespace std;

int main() {
  int N, K;
  string S;
  cin >> N >> S >> K;
  char x = S[K - 1];
  for (int i = 0; i < N; ++i) {
    if (S[i] != x) {
      S[i] = '*';
    }
  }
  cout << S << endl;
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
   int a,b;
   scanf("%d %d",&a,&b);
   if(a>=b){
      for(int i = 0;i<a;i++){
         printf("%d",b);
      }
   }else{
      for(int j = 0;j<b;j++){
         printf("%d",a);
      }
   }
   return 0;
}


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()

void solve(){
    int N;
    string S;
    cin >> N >> S;

    if (N & 1) {
        cout << "No" << endl;
        return;
    }

    bool truth = false;
    for (int i = 0; i < N/2; i++) {
        if (S[i] != S[i+N/2]) {
            cout << "No" << endl;
            return;
        }
    }

    cout << "Yes" << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>

using namespace std;

void solve(string s) {
    vector<int> al(28, 0);
    int len = s.size();
    for (int i = 0; i < len; i++) {
        al[s[i]-'a'] += 1;
    }
    long long ret = (static_cast<long long>(len) * (len - 1))/2 + 1;
    for (int i = 0; i < 28; i++) {
        if (al[i] <= 1) {
            continue;
        }
        ret -= (static_cast<long long>(al[i]) * (al[i] - 1))/2;
    }
    std::cout << ret << std::endl;
}

int main() {
    struct timeval start,end;
    long long span;
    string s;

    gettimeofday(&start,NULL);

    std::cin >> s;
    solve(s);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 772
#include <stdio.h>
#include <string.h>

#define N 0
#define E 1
#define S 2
#define W 3

int dir[4][2] = { {0,1}, {1,0}, {0,-1}, {-1,0} };
int map[21][21];

int main(void)
{
    while(true) {
        int n, m;
        int px=10, py=10, s=0;

        memset(map, 0, sizeof(map));

        scanf("%d\n", &n);
        if(n==0) break;


        for(int i=0; i < n; i++)
        {
            int x,y;
            scanf("%d%d\n", &x, &y);

            map[x][y] = 1;
        }

        scanf("%d\n", &m);

        map[10][10] = 0;
        for(int i=0; i < m; i++)
        {
            char d;
            int *D, l;
            scanf("%c %d\n", &d, &l);
            switch(d) {
                case 'N':
                    D = dir[N];
                    break;
                case 'E':
                    D = dir[E];
                    break;
                case 'S':
                    D = dir[S];
                    break;
                case 'W':
                    D = dir[W];
                    break;
            }

            for(int i=0; i < l; i++)
            {
                px += *D;
                py += *(D+1);
                map[px][py] = 0;
            }
        }

        for(int i=0; i <= 20; i++)
            for(int j=0; j <= 20; j++)
                s += map[i][j];

        printf( s ? "No\n" : "Yes\n");
    }

    return 0;
}

Measured memory_bytes: 1016
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class Main {
	

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		List <Integer> N = new ArrayList<Integer>();
		List <Integer> X = new ArrayList<Integer>();
		int n;
		int x;
		do {
			n = stdIn.nextInt();
			x = stdIn.nextInt();
			N.add(n);
			X.add(x);
		} while (n != 0 || x != 0);
		
		int[] ans = new int[N.size()-1];
		for(int i = 0; i < N.size()-1; i++) {
			for(int j = 1; j <= N.get(i)-2; j++) {
				for(int k = j+1; k <= N.get(i)-1; k++) {
					if(j + k > X.get(i)) {
						break;
					}
					for(int l = k+1; l <= N.get(i); l++) {
						if(j + k + l == X.get(i)) {
							ans[i]++;
						}
						if(j + k + l > X.get(i)) {
							break;
						}
					}
				}
			}
		}
		for (int i = 0; i < N.size()-1; i++) {
			System.out.println(ans[i]);
		}
		
	
	}
}

Measured memory_bytes: 22252
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var n=arr.shift()-0;
   if(n==0)break;
   var ary=[];
   while(n--)ary.push(arr.shift().split(" ").map(Number));
   var obj={};
   ary.forEach(function(v){
      obj[v.join(",")]=true;
   });
   var max=0;
   for(var i=0;i<ary.length;i++){
      for(var j=i+1;j<ary.length;j++){
         var dx=ary[j][0]-ary[i][0];
         var dy=ary[j][1]-ary[i][1];
         var c=(ary[j][0]+dy)+","+(ary[j][1]-dx);
         var d=(ary[i][0]+dy)+","+(ary[i][1]-dx);
         if(obj.hasOwnProperty(c) && obj.hasOwnProperty(d)){
            var S=(dx*dx)+(dy*dy);
            max=Math.max(max,S);
         }
      }
   }
   console.log(max);
}

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

int main(){
    /*奇数の数が2で割り切れる場合は、OK*/
    int n;
    cin>>n;
    int a;
    int cnt=0;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a%2!=0)cnt++;
    }
    if(cnt%2==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 3580
#include <stdio.h>

#define min(a, b) ((a) > (b)) ? (b) : (a)

int main () {
    int N;
    int A;
    int B;
    scanf("%d", &N);
    scanf("%d", &A);
    scanf("%d", &B);
    int ans = min(N * A, B);

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


Measured memory_bytes: 128
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<cstdlib>
#include<list>
#include<set>
#include<numeric>

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

int dp[50][402][402];
int a[100], b[100], c[100];
int mxA,mxB;
const int INF = 1000000;

int main()
{
	int N, Ma,Mb;
	cin >> N >> Ma >> Mb;

	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i] >> c[i];
		mxA += a[i];
		mxB += b[i];
	}

	for (int i = 0; i < N+1; i++) {
		for (int j = 0; j < mxA + 1; j++) {
			for (int k = 0; k < mxB + 1; k++)
				dp[i][j][k] = INF;
		}
	}

	dp[0][0][0] = 0;
	dp[0][a[0]][b[0]] = c[0];
	for (int i = 1; i < N; i++) {
		for (int x = 0; x < mxA; x++) {
			for (int y = 0; y < mxB; y++) {
				if (x - a[i] >= 0 && y - b[i] >= 0) {
					dp[i][x][y] = min(dp[i-1][x][y],dp[i-1][x-a[i]][y-b[i]]+c[i]);
				}
				else {
					dp[i][x][y] = dp[i - 1][x][y];
				}
			}
		}
	}

	int ans = INF;
	int ma = Ma, mb = Mb;
	while (ma < mxA && mb < mxB) {
		ans = min(ans,dp[N-1][ma][mb]);
		ma += Ma;
		mb += Mb;
	}
	if (ans < INF)cout << ans << endl;
	else cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 26240
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  string s;
  cin >> s;
  int res = 0;
  for(int i = 0,j = (int)s.size()-1; i <= j; i++,j--){
    if(i == j && (s[i] == '(' || s[i] == ')')) res++; 
    if(s[i] == ')') s[i] = '(';
    else if(s[i] == '(') s[i] = ')';
    res += s[i] == s[j]?0:1;
  }
  cout << res << endl;
}

Measured memory_bytes: 1180
#include<bits/stdc++.h> 
using namespace std;
int main(){
	int a,b,max;
	cin>>a>>b;
	max=a+b;
	if(a*b>max)
		max=a*b;
	if(a-b>max)
		max=a-b;
	cout<<max;
	return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
if m == 0 and n != 1:
    print(10**(n-1))
    exit()
if m== 0 and n==1:
    print(0)
    exit()
l = [-1]*n
for i in range(m):
    s,c = map(int,input().split())
    if l[s-1] == -1:
        l[s-1] = c
    elif l[s-1] != c:
        print('-1')
        exit()
if l[0] == 0 and n==1:
    print(0)
    exit()
if l[0] == 0:
    print('-1')
    exit()
if l[0] == -1:
    l[0] = 1
for i in range(1,n):
    if l[i] == -1:
        l[i] = 0
# print(l)
ans = 0
for i in range(n):
    ans += l[n-i-1]*10**i
print(ans)

Measured memory_bytes: 61968
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    }

    private static void solve(Scanner in) {
        int N = in.nextInt();
        long T = in.nextLong();
        long[] A = new long[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextLong();
        }

        // takahashi
        long min = Long.MAX_VALUE;
        long maxgap = Long.MIN_VALUE;
        long count = 0;
        for (int i = 0; i < N; i++) {
            min = Math.min(min, A[i]);
            long gap = A[i] - min;
            if (maxgap == gap) {
                count++;
            } else if (maxgap < gap) {
                maxgap = gap;
                count = 1;
            }
        }
//        System.out.println(min + " " + maxgap);
//        long takahashi = (maxgap * T) / 2;
//        System.out.println(takahashi);
        System.out.println(count);
    }
}

Measured memory_bytes: 47172
#include <iostream>

using namespace std;
int k = -1;
char s[15], ans[15];
int main()
{
	cin >> s;
	for(int i = 0; s[i]; i++){
		if(s[i] == '0' || s[i] == '1'){
			k++;
			ans[k] = s[i];
		}else if(s[i] == 'B' && k >= 0){
			k--;
		}
	}
	for(int i = 0; i <= k; i++){
		cout << ans[i];
	}
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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

ll wa(int n){
    ll s = 0;
    while(n > 0){
        s += n%10;
        n /= 10;
    }
    ret s;
}

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

    ll s = 0;
    rep(i,1,n+1){
        ll w = wa(i);
        if( a<= w && w <= b)s += i;
    }
    P(s);
    
	return  0;
}

Measured memory_bytes: 256
import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


def main():
	h,w=map(int,input().split())
	if h==1 or w==1:
		print(1)
		exit(0)
	print((h*w+1)//2)



if __name__ == "__main__":
	main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int MAX = 100100;
int main() {
    vector<int> p(MAX, true);
    for(int i=2;i*i<MAX;i++) {
        if(p[i])
        for(int j=2*i;j<MAX;j+=i) {
            p[j] = false;
        }
    }
    vector<int> ruisekiwa(MAX, 0);
    for(int i=3;i<MAX;i+=1) {
        ruisekiwa[i] += ruisekiwa[i-1];
        if(p[i]&&p[(i+1)/2]) {
            ruisekiwa[i]++;
            //printf("i:%d\n", i);
        }
    }
    int q; cin >> q;
    vector<int> ans(q);
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        ans[i] = ruisekiwa[r] - ruisekiwa[l-1];
    }
    rep(i, q) {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;


// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int MOD = 1000000007;
using mint = Fp<MOD>;


int N, M;
vector<int> S, T;
mint dp[2100][2100];

int main() {
    cin >> N >> M;
    S.resize(N), T.resize(M);
    for (int i = 0; i < N; ++i) cin >> S[i];
    for (int i = 0; i < M; ++i) cin >> T[i];

    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j <= M; ++j) {
            if (i-1 >= 0 && j-1 >= 0 && S[i-1] == T[j-1]) dp[i][j] += dp[i-1][j-1];
            if (i-1 >= 0) dp[i][j] += dp[i-1][j];
            if (j-1 >= 0) dp[i][j] += dp[i][j-1];
            if (i-1 >= 0 && j-1 >= 0) dp[i][j] -= dp[i-1][j-1]; // ダブルカウントを除く
        }
    }
    cout << dp[N][M] << endl;
}


Measured memory_bytes: 34688
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




//0:中央 1:南 2:東 3:西 4:北 5:裏側
struct Dice{

	void roll(char dst){
		for(int i = 0; i < 6; i++) work[i] = number[i];
		switch(dst){
		case 'E':
			setNumber(work[3],work[1],work[0],work[5],work[4],work[2]);
			break;
		case 'N':
			setNumber(work[1],work[5],work[2],work[3],work[0],work[4]);
			break;
		case 'S':
			setNumber(work[4],work[0],work[2],work[3],work[5],work[1]);
			break;
		case 'W':
			setNumber(work[2],work[1],work[5],work[0],work[4],work[3]);
			break;
		}
	};

	int getBottom(){
		return number[5];
	}
	int getS(){

		return number[1];
	}
	int getE(){

		return number[2];
	}

	void copy(Dice arg_dice){

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

			number[i] = arg_dice.number[i];
		}
	}

	void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
		number[0] = n0;
		number[1] = n1;
		number[2] = n2;
		number[3] = n3;
		number[4] = n4;
		number[5] = n5;
	}

	int number[6],work[6];
};

struct Info{

	Info(int arg_row,int arg_col,Dice arg_dice){
		row = arg_row;
		col = arg_col;
		dice = arg_dice;
	}
	int row,col;
	Dice dice;
};


int H,W;
char table[105][105];
bool visited[105][105][7][7][7];

bool rangeCheck(int row,int col){

	return row >= 0 && row <= H-1 && col >= 0 && col <= W-1;
}


int main(){

	scanf("%d %d",&H,&W);

	for(int row = 0; row < H; row++){

		scanf("%s",table[row]);
	}

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			for(int a = 1; a <= 6; a++){
				for(int b = 1; b <= 6; b++){
					for(int c = 1; c <= 6; c++){

						visited[row][col][a][b][c] = false;
					}
				}
			}
		}
	}

	Dice dice;
	dice.setNumber(1,2,3,4,5,6);

	visited[0][0][dice.getBottom()][dice.getS()][dice.getE()] = true;

	queue<Info> Q;
	Q.push(Info(0,0,dice));

	int diff_row[4] = {-1,0,0,1},diff_col[4] = {0,-1,1,0};
	char DIR[4] = {'N','W','E','S'};

	while(!Q.empty()){

		if(Q.front().row == H-1 && Q.front().col == W-1){

			printf("YES\n");
			return 0;
		}else{

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

				int adj_row = Q.front().row+diff_row[i];
				int adj_col = Q.front().col+diff_col[i];

				if(!rangeCheck(adj_row,adj_col)||table[adj_row][adj_col] == '#')continue;

				dice.copy(Q.front().dice);
				dice.roll(DIR[i]);

				if(dice.getBottom() != table[adj_row][adj_col]-'0')continue;

				if(visited[adj_row][adj_col][dice.getBottom()][dice.getS()][dice.getE()])continue;
				visited[adj_row][adj_col][dice.getBottom()][dice.getS()][dice.getE()] = true;

				Q.push(Info(adj_row,adj_col,dice));
			}

			Q.pop();
		}
	}

	printf("NO\n");

	return 0;
}



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

using namespace std;
#define BUF (100005)

char s[BUF];
char str[BUF];
int main(void){
	cin >> s;
	
	int cnt = 0;
	for(int i=0;i<strlen(s);i++){
		if(s[i]!='x'){
			str[cnt] = s[i];
			cnt++;
		}
	}

	for(int i=0;i<strlen(str);i++){
		if(str[i]!=str[strlen(str)-i-1]){
			cout << -1 << endl;
			return 0;
		}
	}

	int lo = 0;
	int hi = strlen(s)-1;
	int ans=0;
	while(1){
		if(lo>=hi) break;
		if(s[lo]!=s[hi]){
			if(s[lo]=='x'){
				ans++;
				lo++;
			}else{
				ans++;
				hi--;
			}
		}else{
			lo++;
			hi--;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
from collections import defaultdict
def solve():
    N = int(input())
    blue = defaultdict(int)
    for i in range(N):
        s = input()
        blue[s] += 1
    
    M = int(input())
    red = defaultdict(int)
    for i in range(M):
        t = input()
        red[t] += 1

    mx = 0
    for item in blue.items():
        mx = max(mx, item[1] - red[item[0]])

    print(mx)
if __name__ == '__main__':
    solve()

Measured memory_bytes: 38384
#include <stdio.h>

int main(){
    
    int h,w;
    
    while(1){
        scanf("%d %d",&h, &w);
        if(h == 0 && w == 0){
            break;
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 

 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };



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

    int n,m; cin >> n >> m;
    vector<ll> a(n);
    for(int i=0; i<n; ++i) cin >> a[i];
    sort(a.begin(), a.end());

    vector<pair<ll, ll>> cb(m);
    for(int i=0; i<m; ++i) cin >> cb[i].second >> cb[i].first;
    sort(cb.begin(), cb.end(), greater<pair<ll, ll>>());

    ll ans = 0;
    int aid = 0;

    for(int i=0; i<m; ++i){
        int b = cb[i].second;
        ll c = cb[i].first;
        while(aid < n && a[aid] < c && 0 < b) { ++aid; ans += c; --b; }
        if(aid >= n) break;
    }

    for(int i=aid; i<n; ++i) ans += a[i];

    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] map = new char[h][w];
        for(int i = 0; i < h; i++){
            map[i] = sc.next().toCharArray();
        }
        int[] mx = {-1,0,0,1};
        int[] my = {0,1,-1,0};
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                if(map[i][j] == '.') continue;
                boolean ok = false;
                for(int k = 0; k < 4; k++){
                    int ny = i + my[k];
                    int nx = j + mx[k];
                    if(check(ny,nx,h,w,map)){
                        ok = true;
                        break;
                    }
                }
                if(!ok){
                    System.out.println("No");
                    return;
                }
            }
        }
        System.out.println("Yes");
    }
    
    public static boolean check(int y, int x, int h, int w, char[][] map){
        return (y >= 0 && y < h && x >= 0 && x < w && map[y][x] == '#');
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}

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

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

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        scanf("%d", &tmp);
        while (tmp % 2 == 0) cnt++, tmp /= 2;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	
	vector<pair<int,int>> v;
	int x,y;
	int n; cin>>n; int a;
	for(int i = 0; i < n; i++){
		cin>>a;
		v.push_back({a,i+1});
	}
	sort(v.begin(),v.end());
	for(auto xx : v) cout<<xx.second<<" "; cout<<"\n";
}


Measured memory_bytes: 1780
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    string s;
    cin>>n>>k;
    cin>>s;
    int h[100001]={};
    vector<int> vec;
    vec.push_back(0);
    int cnt=0;
    for(int i=0;i<n;i++){
        if(s[i]=='0'){
            cnt++;
            h[i+1]=cnt;
            if(s[i+1]!='0'){
                vec.push_back(i+1);
                cnt=0;
            }
        }
    }
    vec.push_back(n);
    if(vec.size()-2<k){
        cout<<n<<endl;
        return 0;
    }
    int ans=0;
    for(int i=k+1;i<vec.size();i++){
        ans=max(ans,vec[i]-h[vec[i]]-vec[i-(k+1)]);
        if(vec[i]==n) h[n]=0;
    }
    cout<<ans<<endl;
    
    return 0;
}


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

int n;
int p[100000];

int main()
{
	int t = 0;

	for (int i = 3; i < 1000000; i += 2) {
		bool f = 1;
		for (int j = 3; j * j <= i; j++) {
			if (i % j == 0) {
				f = 0;
				break;
			}
		}

		if (f) {
			p[t] = i;
			t++;
		}
	}

	cin >> n;

	while (n) {
		int m = 0, i = 0;

		while (p[i] * 2 <= n) {
			if (binary_search(p, p + t, n - p[i]))
				m++;

			i++;
		}

		cout << m << endl;

		cin >> n;
	}

	return 0;
}



Measured memory_bytes: 3352
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i = s; i < (n); ++i)
#define revrep(i,n,g) for (int i = n-1; i >= g; i--)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n; string s;
  cin >> n >> s;
  int r = 0,w = 0;
  rep(i,0,n) {
    if (s.substr(i,1) == "R") r++;
    else w++;
  }
  int k = 0,l = 0;
  rep(i,0,r) {
    if (s.substr(i,1) == "R") k++;
  }
  r -= k;
  revrep(i,n,n-w) {
    if (s.substr(i,1) == "W") l++;
  }
  w -= l;
  cout << min(r,w) << endl;
  return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    map<string, int> mp;

    int N; cin >> N;
    for(int i=0; i<N; i++){
        string s; cin >> s;
        mp[s]++;
    }
    int M; cin >> M;
    for(int i=0; i<M; i++){
        string s; cin >> s;
        mp[s]--;
    }

    int ans = 0;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++){
        ans = max(ans, itr->second);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){
    int a,b;
    cin >> a;
    cin >> b;
    int d=a/b;
    int r=a%b;
    double f=double(a)/double(b);
    cout << d;
    cout << " ";
    cout << r;
    cout << " ";
    cout << fixed << setprecision(5) << f;
    cout << endl;
    return 0;
}


Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, A, B; 
	cin >> N >> A >> B; 
	int a = 0, b = 0, c = 0; 
	for(int i = 0; i < N; i++){
		int p; 
		cin >> p; 
		if(p <= A) a++;
		else if(p <= B) b++;
		else c++;
	}
	cout << min({a, b, c}) << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define gc getchar()
#define ll long long
#define int long long
#define ri register int
#define rc register char
#define rb register bool
#define rp(i,x,y) for(ri i=x;i<=y;++i)
#define my(i,x,y) for(ri i=x;i>=y;--i)
using namespace std;
    
ll min1[1000001], min2[1000001], adds[1000001],n,q,pre;

il int read()
{
    rc ch=gc;ri x=0;rb y=1;
    while(ch!='-' && (ch>'9' || ch<'0'))ch=gc;
    if(ch=='-')ch=gc,y=0;
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc;
    return y?x:-x;
}
il void down(int nw) 
{
    if (!adds[nw])return;
    adds[ls(nw)] += adds[nw];
    adds[rs(nw)] += adds[nw];
    min1[ls(nw)] += adds[nw];
    min2[ls(nw)] += adds[nw];
    min1[rs(nw)] += adds[nw];
    min2[rs(nw)] += adds[nw];
    adds[nw] = 0;
}
void modify(int l, int r, int nw, int pt, ll num) 
{
    if (l == r) 
	{
        min1[nw] = min(min1[nw], num - l);
        min2[nw] = min(min2[nw], num + l);
        return;
    }
    int mid = (l + r) >> 1;down(nw);
    if (pt <= mid)modify(l, mid, ls(nw), pt, num);
    else modify(mid + 1, r, rs(nw), pt, num);
    min1[nw] = min(min1[ls(nw)], min1[rs(nw)]);
    min2[nw] = min(min2[ls(nw)], min2[rs(nw)]);
}
ll query1(int rl, int rr, int l, int r, int nw) 
{
    if (rl == l && rr == r)return (min1[nw]);
    int mid = (l + r) >> 1;down(nw);
    if (rl > mid)return (query1(rl, rr, mid + 1, r, rs(nw)));
    if (rr <= mid)return (query1(rl, rr, l, mid, ls(nw)));
    return (min(query1(rl, mid, l, mid, ls(nw)), query1(mid + 1, rr, mid + 1, r, rs(nw))));
}
ll query2(int rl, int rr, int l, int r, int nw) 
{
    if (rl == l && rr == r)return (min2[nw]);
    int mid = (l + r) >> 1;down(nw);
    if (rl > mid)return (query2(rl, rr, mid + 1, r, rs(nw)));
    if (rr <= mid)return (query2(rl, rr, l, mid, ls(nw)));
    return (min(query2(rl, mid, l, mid, ls(nw)), query2(mid + 1, rr, mid + 1, r, rs(nw))));
}
ll query(int l, int r, int nw) 
{
    if (l == r)return (min1[nw] + l);
    int mid = (l + r) >> 1;down(nw);return (min(query(l, mid, ls(nw)), query(mid + 1, r, rs(nw))));
}
signed main() 
{
//	freopen("2558.in","r",stdin);
    n = read(), q = read(), pre = read();memset(min1, 63, sizeof(min1));memset(min2, 63, sizeof(min2));modify(1, n, 1, read(), 0);
    while(q--)
	{
        int nw=read();ll dat=min(query1(1,nw,1,n,1)+nw,query2(nw,n,1,n,1)-nw);
        adds[1]+=abs(nw-pre);min1[1]+=abs(nw-pre);min2[1]=abs(nw-pre);modify(1,n,1,pre,dat);
        pre=nw;
    }
    printf("%lld\n",query(1,n,1));
    return (0);
}

Measured memory_bytes: 23680
#include <iostream>
#include <algorithm>
#include <vector>
#include <bits/stdc++.h>

using namespace std;

int p[100010];

int root(int x) {return p[x] < 0 ? x : p[x] = root(p[x]);}

void unit(int x, int y) {
    if ((x = root(x)) == (y = root(y))) return;
    if (p[x] > p[y]) swap(x, y);
    p[x] += p[y];
    p[y] = x;
}


int main() {
    ios::sync_with_stdio(false);
  
    int n, m, u, v, a[100005] = {}, z = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) 
      cin >> a[i], p[i] = -1;
    while (m--) cin >> u >> v, unit(u, v);
    for (int i = 1; i <= n; i++) 
      if (root(i) == root(a[i])) z++;
    cout << z;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
     char a , b ;
     cin >> a >> b ;
     
     if(a == 'H'){
          
          if(b == 'H'){
               cout << 'H' << endl ;
          }
          else{
               cout << 'D' << endl ;
          }
     }
     else{
          
          if(b == 'H'){
               cout << 'D' << endl ;
          }
          else{
               cout << 'H' << endl ;
          }
     }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define endl '\n'
#define debug(x) cerr << #x << " is " << x << endl
#define int ll

using namespace std;

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

const int INF = 1e9 + 7;

int32_t main()
{
	IO_OP;
	
	int n;
	cin >> n;
	cout << (n - 1) * n / 2 << endl;	
	
}



Measured memory_bytes: 256
def list2d(a, b, c): return [[c] * b for i in range(a)]
mod =10**9+7
H, W = map(int, input().split())

grid = []

for _ in range(H):
    grid.append(list(input()))

dp = list2d(H, W, 0)
for i in range(H-1, -1, -1):
    if(grid[i][W-1] == '#'):
        break
    dp[i][W-1] = 1

for j in range(W-1, -1, -1):
    if(grid[H-1][j]=='#'):
        break
    dp[H-1][j] = 1

for row in range(H-2, -1, -1):
    for col in range(W-2, -1, -1):
        if(grid[row][col] == '.'):
            dp[row][col] = (dp[row][col+1] + dp[row+1][col])%mod
        else:
            dp[row][col] = 0
print(dp[0][0]%mod)

Measured memory_bytes: 87280
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            int? Tate = null;
            int? Yoko = null;

            string Input = System.Console.ReadLine();


            string[] Lenght = Input.Split(' '); 

            foreach(var atai in Lenght)
            {
                if (Tate == null)
                {
                    Tate = int.Parse(atai);
                    continue;
                }


                Yoko = int.Parse(atai);

                System.Console.WriteLine("{0} {1}", Tate * Yoko, (Tate + Yoko) * 2);

            }

        }
    }
}

Measured memory_bytes: 9088
import sys

def sa(Type= int):
  return [Type(x) for x in input().split()]

def solve(h, w):
  row = ['.']*w
  row[0] = '#'
  row[-1] = '#'
  row = ''.join(row)

  frame = [row]*h
  frame[0] = '#'*w
  frame[-1] = '#'*w

  print('\n'.join(frame))
  print()

if __name__ == '__main__':
  # sys.stdin = open('input.txt', 'r')

  while True:
    h, w = sa()

    if h == 0 and w == 0:
      break

    solve(h, w)


Measured memory_bytes: 5636
#include <iostream>
#include <algorithm>
#include <cmath>

#define eps 0.000001

using namespace std;

long worst_case(long a, long b){
    long c = sqrt(a * b) - eps;
    if (a == b) return 2 * a - 2;
    else{
        if(c * (c + 1) < a * b) return 2 * c - 1;
        else return 2 * c - 2;
    }
}

int main(){
    int Q;
    cin >> Q;
    long A[Q], B[Q];
    for(int i=0; i<Q; i++) cin >> A[i] >> B[i];
    for(int i=0; i<Q; i++){
        cout << worst_case(A[i], B[i]) << endl;
    }
    return 0;
}

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

int main() {
	int n;
    while(1){
        cin>>n;
        if(!n)break;

        int a[5000]={0};
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        int sum=0,ans=a[0];
        for(int i=0;i<n;i++){
            sum=0;
            for(int j=i;j<n;j++){
                sum+=a[j];
                ans=max(ans,sum);
            }
        }
        cout<<ans<<endl;
    }
	return 0;
}

Measured memory_bytes: 3116
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
    static final long MOD = 1000000007;
	public static void main(String[] args) {
		FS reader = new FS();
		// write reader
		int S = reader.nextInt();
		solver(S);
	}
	
	public static void solver(int S) {
	    // write logic
	    long[][] dp = new long[S+1][4];
	    dp[0][0] = 1;
	    for(int i=0; i<S; i++) {
	        dp[i+1][1] = dp[i][0] + dp[i][3];
	        dp[i+1][2] = dp[i][1];
	        dp[i+1][3] = dp[i][2] + dp[i][3];
	        for (int j=1; j<=3; j++) dp[i+1][j] %= MOD;
	    }
	    
	    System.out.println(dp[S][3]);
	}
	
	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
	
		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}

Measured memory_bytes: 32516
import math


class Solution:
    def solve(self, a: int, b: int, c: int) -> str:

        epsilon = 1e-6

        if c - a - b < 0:
            return 'No'
        elif 4 * a * b < (c - a - b) ** 2:
            return 'Yes'

        else:
            return 'No'


if __name__ == '__main__':

    # standard input
    a, b, c = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(a, b, c))


Measured memory_bytes: 3060