akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define MOD  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
#define ps push_back
#define all(x) x.begin(),x.end()
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう

struct segmenttree{
    private:
    int n;
    vector<int> node;
    public:
    segmenttree(vector<int>v){
        int sz=v.size();
        n=1;while(n<sz)n*=2;
        node.resize(n*2-1,0);
        rep(i,0,sz)node[i+n-1]=v[i];
        for(int i=n-2;i>=0;i--)node[i]=max(node[2*i+1],node[2*i+2]);
    }
    void update(int x,int val){
        x+=n-1;
        node[x]=val;
        while(x>0){
            (x-=1)/=2;
            node[x]=max(node[2*x+1],node[2*x+2]);
        }
    }
    int getmax(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        if(r<=a||b<=l)return -1;
        if(a<=l&&r<=b)return node[k];
        int vl=getmax(a,b,k*2+1,l,(l+r)/2);
        int vr=getmax(a,b,k*2+2,(l+r)/2,r);
        return max(vl,vr);
    }
};
signed main(){
    int n;cin>>n;
    segmenttree seg(vector<int>(n,0));
    int h[214514],a[214514];
    rep(i,0,n)cin>>h[i];rep(i,0,n)cin>>a[i];
    rep(i,0,n){
        int k=seg.getmax(0,h[i]);
        seg.update(h[i]-1,a[i]+k);
    }
    cout<<seg.getmax(0,n)<<endl;return 0;
}

Measured memory_bytes: 7936
from math import *
def rad(n):
    return n * pi / 180

x, y = 0, 0
na = 90
while True:
    d, a = map(int, input().split(","))
    if d == a == 0:
        print(int(x))
        print(int(y))
        break
    x += cos(rad(na)) * d
    y += sin(rad(na)) * d
    na -= a

Measured memory_bytes: 7864
#include<stdio.h>
int main(void)
{
  int n,a,b;
  scanf("%d%d%d",&n,&a,&b);
  if((n*a)<b)
    {
      printf("%d",n*a);
    }
  else
    {
      printf("%d",b);
    }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
long long dp[110][2][110];
int main(){
    string N;
    cin >> N;
    int K; cin >> K;
    int l = N.size();
    dp[0][0][0] = 1;
    for(int i=0;i<l;++i){
        int D = N[i] - '0';
        for(int j=0;j<2;++j){
            for(int k=0;k<l;++k){
                for(int d=0;d<=(j ? 9:D);++d){
                    dp[i+1][j||(d<D)][d==0 ? k:(k+1)] += dp[i][j][k];
                }
            }
        }
    }
    cout << dp[l][0][K] + dp[l][1][K] << endl;
    return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10 ** 5 + 5)

INF = 10 ** 9

N, A, B, C = list(map(int, input().split()))
L = []
for _ in range(N):
    l = int(input())
    L.append(l)


def dfs(current, a, b, c):
    if current == N:
        cost = abs(a - A) + abs(b - B) + abs(c - C) - 30
        return cost if min(a, b, c) > 0 else INF

    r0 = dfs(current + 1, a, b, c)
    r1 = dfs(current + 1, a + L[current], b, c) + 10
    r2 = dfs(current + 1, a, b + L[current], c) + 10
    r3 = dfs(current + 1, a, b, c + L[current]) + 10

    return min(r0, r1, r2, r3)


print(dfs(0, 0, 0, 0))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long 
#define MAX_N 51
using namespace std;

// B[i] >= max(a[i],a[i+1]);

//b[i] >= a[i]
//b[i] >= a[i+1]

//a[i] <= b[i]
//a[i+1] <= b[i]

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n+2,0);
    vector<int> b(n+2,0);
    for(int i = 1;i<n; i++){
        cin>>b[i];
        if(i == 1) a[i] = b[i];
        else a[i] = min(b[i-1],b[i]);

        if(i == (n-1)) a[i+1] = b[i];
    }
    ll sum = 0;
    for(int i =1; i<=n; i++) sum+=a[i];
    cout<< sum <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

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


Measured memory_bytes: 2048
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}   

void solve(){
    int h,w,k,ans = 0;
    cin >> h >> w >> k;
    string s[h+5];
    FOR(i,1,h+1)cin >> s[i],s[i] = '$'+s[i];
    FOR(i,0,(1<<h)){
        FOR(j,0,(1<<w)){
            string tmp[h+5];
            FOR(l,1,h+1){
                tmp[l] = '$';
                FOR(m,1,w+1)tmp[l] += s[l][m];
            }
            FOR(l,1,h+1)if(i&(1<<(l-1))){
                FOR(m,1,w+1)tmp[l][m] = '$';
            }
            FOR(m,1,w+1)if(j&(1<<(m-1))){
                FOR(l,1,h+1)tmp[l][m] = '$';
            }
            int tot = 0;
            FOR(l,1,h+1){
                FOR(m,1,w+1)if(tmp[l][m] == '#')++tot;
            }
            if(tot == k)++ans;
        }
    }
    cout << ans << "\n";
}

signed main()
{
    showoff;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...#include <bits/stdc++.h>
 


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

using ll = long long;
using P = pair<int, int>;
using edge = struct
{
  int to;
  ll cost;
};

#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

const int di[] = {-1, 0, 1, 0, 1, 1, -1, -1};
const int dj[] = {0, -1, 0, 1, 1, -1, 1, -1};
const int INF = 1001001001;

const int mod = 1000000007;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
      fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
      return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);

void solve()
{
  int a, b, x;
  cin >> a >> b >> x;
  if(0 <= x - a && x - a <= b) cout << "YES" << "\n";
  else cout << "NO" << "\n";
}

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

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;


void main() {
    writeln(readln.chomp.replace(",", " "));
}



void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int comp(const pair<int,int> &a,const pair<int,int>&b)
{
  return a.first>b.first;
}

int main()
{
    int h,w;
    cin>>h>>w;
  	int m;
  	cin>>m;
  	vector<pair<int,int> >r(h);
  	vector<pair<int,int> >c(w);
  	map<pair<int,int>,int>a;
  	for(int i=0;i<h;i++)r[i].second=i;
  	for(int i=0;i<w;i++)c[i].second=i;
  	for(int i=0;i<m;i++)
    {
      int R,C;
      cin>>R>>C;
      R--;
      C--;
      r[R].first++;
      c[C].first++;
      a[{R,C}] =1;
    }
  	sort(r.begin(),r.end(),comp);
  	sort(c.begin(),c.end(),comp);
  	if(a[{r[0].second,c[0].second}]==0)
    {
      cout<<r[0].first+c[0].first<<endl;
    }
  	else 
    {
      int temp=r[0].first+c[0].first-a[{r[0].second,c[0].second}];
      for(int i=0;i<h;i++)
      {
        for(int j=0;j<w;j++)
        {
          int t=r[i].first+c[j].first-a[{r[i].second,c[j].second}];
          if(t>temp)
          {
            cout<<t<<endl;
            return 0;
          }
          if(c[j].first<(c[0].first))break;
        }
        if(r[i].first<(r[0].first))break;
      }
      cout<<temp<<endl;
    }
  return 0;
}
 

Measured memory_bytes: 32728
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int h = scanner.nextInt();
        int w = scanner.nextInt();
        int n = scanner.nextInt();

        int divisor = h > w ? h : w;

        if (n % divisor == 0) {
            System.out.println(n / divisor);
        } else {
            System.out.println((n / divisor) + 1);
        }
    }
}


Measured memory_bytes: 24276
from math import gcd
N,*T = map(int, open(0).read().split())
if N == 1:
    print(T[0])
else:
    temp = (T[0]*T[1]) // gcd(T[0],T[1])
    for i in range(2,N):
        temp = (temp*T[i]) // gcd(temp,T[i])
    print(temp)

Measured memory_bytes: 9124
import java.util.*;

public class Main {

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

		// 入力
		int N = sc.nextInt();
		long[] a = new long[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		System.out.println(gcdex(a));
	}

	// ユークリッドの控除法(最大公約数を求める)
	private static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	// 複数の最大公約数を求める
	private static long gcdex(long param[]) {
		long g = gcd(param[0], param[1]);
		for (int i = 1; i < param.length-1; i++) {
			g = gcd(g, param[i+1]);
		}
		return g;
	}

	// 最小公倍数を求める
	private static long lcm(long a, long b) {
		return (a * b) / gcd(a, b);
	}

	//
	private static long all(long n, long count, int N) {
		if (count == N) {
			return count;
		}
		return all(1, count, N);
	}

}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;

int n, arr[MAXN+10];
ll minval=987654321, s=0, cnt;
int main()
{
    int i, j;

    scanf("%d", &n);
    for(i=1; i<=n; i++)
    {
        scanf("%d", &arr[i]);
        if(arr[i]<0) cnt++;
        arr[i]=abs(arr[i]);
        minval=min(minval, (ll)arr[i]);
        s+=arr[i];
    }
    if(cnt%2==0) printf("%lld", s);
    else printf("%lld", s-minval-minval);
}


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

class Dice{
public:
    int s[6];
    // s[0] : top
    // s[1] : south  front
    // s[2] ; east  right
    // s[3] : west  left
    // s[4] : north  back
    // s[5] : bottom
    string str = "EWNSRL";
    int d[6][4] = {{0, 3, 5, 2}, {0, 2, 5, 3}, {0, 1, 5, 4}, {0, 4, 5, 1}, {1, 2, 4, 3}, {1, 3, 4, 2}};
    void roll(char c){
        //  N
        // W E
        //  S
        // R : clock rotate
        // L : counter clock rotate
        int idx = str.find(c);
        int b = s[d[idx][0]];
        for(int i = 0; i < 3; i++){
            s[d[idx][i]] = s[d[idx][i + 1]];
        }
        s[d[idx][3]] = b;
    }
    int hash(){
        int res = 0;
        for(int i = 0; i < 6; i++) res = res * 256 + s[i];
        return res;
    }
};


int main(){
    Dice d;
    for(int i = 0; i < 6; i++){
        cin >> d.s[i];
    }
    int q;
    cin >> q;
    string s = "NRRRRNRRRRNRRRRNRRRRERRRRERRRRERRRR";
    for(int i = 0; i < q; i++){
        int top, south;
        cin >> top >> south;
        for(int j = 0; j < s.size(); j++){
            if(d.s[0] == top && d.s[1] == south){
                cout << d.s[2] << endl;
                break;
            }
            d.roll(s[j]);
        }
    }
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a == b && a == c && b == c) {
    cout << "No" << endl;
  } else if(a != b && a != c && b != c) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }  
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
map<int,int> me;
int main()
{
	int a,n,out=0;cin>>n;
	rep(i,n){
		cin>>a;me[a]++;
	}
	map<int,int>::iterator it=me.begin();
	while(it!=me.end()){
		int x=(*it).fi,y=(*it).se;
		if(y<x) out+=y;else out+=y-x;
		it++;
	}
	cout<<out<<endl;
}

Measured memory_bytes: 4736
# vim: fileencoding=utf-8


def main():
    a = int(input())
    b = int(input())
    c = int(input())
    x = int(input())
    ans = 0
    for i in range(a + 1):
        for j in range(b + 1):
            for k in range(c + 1):
                if i * 500 + j * 100 + k * 50 == x:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 64780
#include <bits/stdc++.h>
// #pragma GCC diagnostic warning "-std=c++11"

#define ll long long
#define pb  push_back
#define mod  1000000007
#define inf  1000000000000000000
#define pi  acos(-1.0)
#define maxn  1000009
#define sorted(s)  sort(s.begin(),s.end())
#define slc(n) scanf("%I64d", &n)
#define sl(n)  scanf("%lld", &n)
#define sf(n)  scanf("%lf", &n)
#define si(n)  scanf("%d", &n)
#define sch(n)  scanf(" %c", &n)
#define ss(n)  scanf("%s", n)
#define pb  push_back
#define fr first
#define sc second
#define all(a)  a.begin(),a.end()

using namespace std;

ll n, weight, w[110], v[110], dp[100015], maxval;

int main()
{
	cin>>n>>weight;
	for(ll i=1; i<=n; i++)
	{
		sl(w[i]);
		sl(v[i]);
	}
	ll hi = 100010;
	for(ll i=0;i<=hi;i++)
		dp[i] = 1000000000000;
	dp[0] = 0;
	for(ll i=1;i<=n;i++)
	{
		for(ll j=hi;j>=v[i];j--)
		{
			if(dp[j-v[i]]==1000000000000)
				continue;
			if(dp[j-v[i]]+w[i]<=weight){
				dp[j] = min(dp[j], dp[j-v[i]]+w[i]);
				maxval = max(maxval, j);
			}
		}
	}
	cout << maxval << endl;
	
	return 0;
}

Measured memory_bytes: 1024
from collections import deque

N = int(input())
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

P = [-1] * N
Q = deque([0])
T = []
while Q:
    i = deque.popleft(Q)
    T.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)

BUA = [0] * N # Bottom Up : i以下をすべてまわる
BUB = [0] * N # Bottom Up : i以下をすべてまわってiに戻る
TDA = [0] * N # Top Down : iの上をすべてまわる
TDB = [0] * N # Top Down : iの上をすべてまわってiに戻る
for i in T[::-1]:
    if len(X[i]) == 0:
        BUA[i] = 0
        BUB[i] = 0
        continue
    s = 0
    ma = 0
    for j in X[i]:
        s += BUB[j] + 2
        ma = max(ma, BUB[j] - BUA[j] + 1)
    BUA[i] = s - ma
    BUB[i] = s

for i in T:
    B = [0] * (len(X[i]) + 1)
    C = [0] * (len(X[i]) + 1)
    for k, j in enumerate(X[i]):
        B[k+1] = B[k] + BUB[j] + 2
        C[k+1] = max(C[k], BUB[j] - BUA[j] + 2)
    s = 0
    ma = 0
    for k in range(len(X[i]))[::-1]:
        j = X[i][k]
        TDB[j] = TDB[i] + s + B[k] + 2
        TDA[j] = min(TDB[j] - max(ma, C[k]), TDA[i] + s + B[k] + 1)
        s += BUB[j] + 2
        ma = max(ma, BUB[j] - BUA[j] + 2)

for t in [min(a+d, b+c) for a, b, c, d in zip(BUA, BUB, TDA, TDB)]:
    print(t)


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


using namespace std;

const int INF = 1000000;

int main(){
    int N;
    cin >> N;
    vector<int>A(N);
    for(int i=0;i<N;i++)cin >> A[i];

    int ans=0;

    for(int i=0;i<N-1;i++){
        if(A[i]==A[i+1]){
            ans++;
            A[i+1]=INF;
        }
    }
  	cout << ans << endl;
}


Measured memory_bytes: 256
a1=list(map(int,input().split()))
a2=list(map(int,input().split()))
a3=list(map(int,input().split()))
n=int(input())
b=[]
for i in range(n):
    b.append(int(input()))

# 3,3,2
if (a1[0] in b) and (a1[1] in b) and (a1[2] in b):
    print("Yes") 
    exit()

if (a2[0] in b) and (a2[1] in b) and (a2[2] in b):
    print("Yes") 
    exit()

if (a3[0] in b) and (a3[1] in b) and (a3[2] in b):
    print("Yes") 
    exit()

if (a1[0] in b) and (a2[0] in b) and (a3[0] in b):
    print("Yes") 
    exit()
    
if (a1[1] in b) and (a2[1] in b) and (a3[1] in b):
    print("Yes") 
    exit()

if (a1[2] in b) and (a2[2] in b) and (a3[2] in b):
    print("Yes") 
    exit()

if (a1[0] in b) and (a2[1] in b) and (a3[2] in b):
    print("Yes") 
    exit()

if (a1[2] in b) and (a2[1] in b) and (a3[0] in b):
    print("Yes") 
    exit()

print("No")
exit()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
vector<int>v[100001];
int visited[100005];
int dp[100005];
int func(int s)
{
    int ans1=0;
    if(dp[s]!=-1)return dp[s];
    visited[s]=true;
    int maxi=0;
    for(int i=0;i<v[s].size();i++) {
        ans1=1+func(v[s][i]);
        maxi=max(maxi,ans1);
    }
    return dp[s]=maxi;
}
int main()
{
    std :: ios :: sync_with_stdio(false);
    int n,m,a,b;
    cin>>n>>m;
    for(int i=1;i<=m;i++) {
        cin>>a>>b;
        v[a].push_back(b);
    }
    int ans=0,maxi=0;
    memset(dp,-1,sizeof(dp));
    for(int i=1;i<=n;i++) {
     if(!visited[i])ans=func(i);
     maxi=max(maxi,ans);
    }
    cout<<maxi<<endl;
    return 0;
}


Measured memory_bytes: 8576
#include<stdio.h>
int main(){
  char text[3];
  scanf("%s",text);

  if(text[0]==text[1]){
    printf("No");
  }else if(text[1]==text[2]){
    printf("No");
  }else if(text[2]==text[0]){
    printf("No");
  }else{
    printf("Yes");
  }
}


Measured memory_bytes: 128
// 解答不能.
// arounderstand氏.
// https://atcoder.jp/contests/abc145/submissions/8497134
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define a first
#define b second
using lli = long long int;
constexpr int N = 3000;
pair<int, int> A[N];
array<lli, N + 1> R;

int main(){
    int n, t;
    scanf("%d %d", &n, &t);
    rep(i, n) scanf("%d %d", &A[i].a, &A[i].b);
    sort(A, A + n);
    rep(i, n){
        int a = A[i].a, b = A[i].b;
        int j, e = (t > a) ? t - a : 0;
        for(j = t - 1; j >= e; --j) if(R[t] < R[j] + b) R[t] = R[j] + b;
        for(; j >= 0; --j) if(R[j + a] < R[j] + b) R[j + a] = R[j] + b;
    }
    lli res = 0;
    rep(i, t + 1) if(res < R[i]) res = R[i];
    printf("%lld\n", res);
    return 0;
}

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

#define ll long long
using namespace std;
static ll imin = std::numeric_limits<ll>::min();
static ll imax = std::numeric_limits<ll>::max();
#define rep(i, n) for(int i = 0; i<n; ++i)
#define rep1(i, n) for(int i = 1; i<n; ++i)
#define rev_rep(i, n) for(int i = n - 1; i >= 0; --i)
#define dump(x) cout << #x << ":" << x << "\n";
#define all(v) v.begin(), v.end()

template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::map<T1, T2>& mp);
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::pair<T1, T2>& pair);
template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec);
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::pair<T1, T2>& pair){
  os << '(' << pair.first << ',' << pair.second << ')';
  return os;
}

template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec){
  std::size_t n = vec.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(int i = 0; i<n - 1; ++i){
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}

template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::map<T1, T2>& mp){
  std::size_t n = mp.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(auto && x:mp){
    os << x << " ";
  }
  os << std::endl;
  return os;
}
#ifndef BOOST_TEST_MAIN
int main(int const argc, char const** argv){
  ll N;
  cin >> N;
  vector<ll> a(N), b(N), as(N, 0), bs(N, 0);
  rep(i, N){
    cin >> a[i];
  }
  rep(i, N){
    cin >> b[i];
  }
  as[0] = a[0];
  bs[N - 1] = b[N - 1];

  rep1(i, N){
    as[i] = a[i] + as[i - 1];
  }
  rev_rep(i, N - 1){
    bs[i] = b[i] + bs[i + 1];
  }
  // dump(a);
  // dump(b);
  // dump(as);
  // dump(bs);
  ll res = 0;

  rep(i, N){
    res = max(res, as[i] + bs[i]);
  }
  cout << res;
}
#endif



Measured memory_bytes: 256
/*
 * short          2^15-1 ~ 3e4
 * int, long x86  2^31-1 ~ 2e9
 * long long      2^63-1 ~ 9e18
 */
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define fr(a, b) for (int a = 0; a < b; ++a)
using namespace std; typedef long long ll; const int inf = numeric_limits<int>::max(); void print() {cerr << endl;}
template<typename T, typename... Ts> void print(T&&a, Ts&&...etc) {cerr << a << ' '; print(etc...);}
template<typename T, typename U> ostream& operator<<(ostream& s, const pair<T,U>&p) {s << "<" << p.x << ", " << p.y << ">"; return s;} // ver. 2020-02-17
template<typename T> ostream& operator<<(ostream& s, const vector<T>&v) {s << "["; for (auto &x : v) s << x << ", "; if (!v.empty()) s << "\b\b"; s << "]"; return s;}
struct io{io(){ios_base::Init i; ios_base::sync_with_stdio(0); cin.tie(0);}}io;

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<ll> p(a), q(b), r(c);
    fr(i, a) cin >> p[i];
    fr(i, b) cin >> q[i];
    fr(i, c) cin >> r[i];

    sort(p.begin(), p.end(), greater<ll>());
    sort(q.begin(), q.end(), greater<ll>());
    sort(r.begin(), r.end(), greater<ll>());
    vector<ll> t;
    t.reserve(x + y);
    fr(i, x) t.pb(p[i]);
    fr(i, y) t.pb(q[i]);
    sort(t.begin(), t.end(), greater<ll>());
    // print("no coloring", t);
    int last = x+y-1;
    int next = 0;
    while (last >= 0 && next < c) {
        if (t[last] < r[next]) {
            // print("take ", r[next], "instead of ", t[last]);
            --last;
            ++next;
        } else {
            break;
        }
    }
    ll ans = 0;
    fr(i, last+1) {
        ans += t[i];
    }
    fr(i, next) {
        ans += r[i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3968
n=int(input())
s=list(map(int,input().split()))
a=bin(s[0]^s[1])

ans=bin(s[0])


i=1
while i!=n:
    ans=int(ans,2)
    ans=bin(ans^s[i])
    i+=1

ans=int(ans,2)
if ans==0:
    print("Yes")
else:
    print("No")



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

string s;
int K;

set<string> compare;

int main(){
	cin >> s >> K;
	for(int i = 0; i < s.length(); i++){
		for(int j = 0; j <= K; j++){
			compare.insert(s.substr(i, j));
		}
	}
	set<string>::iterator itr = compare.begin();
	for(int i = 0; i < K; i++) itr++;
	cout << *itr << endl;
	return 0;
}

Measured memory_bytes: 1664
/*
 *
 *   Author     : Amit Kumar
 *   Date    	: August 10
 * 
 */

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>
#define FAST_INPUT_OUTPUT
//#define MORE_THAN_ONE_TESTCASE // COMMENT IT

#define vi vector<int>
#define vl vector<long long>
#define mii map<int , int>
#define mll map<long long , long long>
#define msi map<string , i>
#define msl map<string , long long>
#define umii unordered_map<int,int>
#define umll unordered_map<long long ,long long>
#define umsi unordered_map<string , int>
#define umsl map<string , long long> 
#define si set<int>
#define sl set<long long>
#define pii pair<int , int >
#define psi pair<string,int>
#define psl pair<string , long > 
#define pll pair<long long , long long>
#define vpii vector<pii>
#define vpll vector<pll>
#define vpsi vector<psi>
#define vpsl vector<psl>
#define pqi priority_queue<int>
#define pql priority_queue<long long>
#define ub upper_bound
#define lb lower_bound
#define bint long long int
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define iv(v) for(auto &i:v){cin>>i;}
#define ov(v) for(auto i:v){cout<<i<<" ";}cout<<endl;
#define ovn(v) for(auto i:v){cout<<i<<endl;}
#define euv(v) for(auto i:v){cerr<<i<<" ";}cerr<<endl;
#define eovn(v) for(auto i:v){cerr<<i<<endl;}
#define os(s) for(auto itr:s){cout<<itr<<" ";}cout<<endl;
#define osn(s) for(auto itr:s){cout<<itr<<endl;}
#define eos(s) for(auto itr:s){cerr<<itr<<" ";}cerr<<endl;
#define eosn(s) for(auto itr:s){cerr<<itr<<endl;}
#define rep(x) for(auto i=0 ; i<(x); ++i)
#define _rep(a,b) for(auto i=(a); i<(b); ++i)
#define ef else if
#define wh while
#define el else
#define ivv(x) int x; cin>>x
#define lv(x) bint x; cin>>x
#define sv(x) string x; cin>>x
#define cv(x) char x; cin>>x
#define fv(x) float x; cin>>x
#define dv(x) double x; cin>>x
#define endl '\n'
using namespace std;




auto SOLUTION_FUNCTION( void ) ->void {

    // your solution goes here 

    ivv(a);
    ivv(b);
    cout<<max({a+b,a-b,a*b})<<endl;



    return ;
}




int main(void){
#ifdef FAST_INPUT_OUTPUT
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout<<setprecision(10);
    cout<<fixed;
    cout<<boolalpha;
#endif
#ifdef MY_LOCAL_PROJECT
    freopen("input","r",stdin);
    freopen("output","w",stdout);
#endif
    int testcase = 1;


#ifdef MORE_THAN_ONE_TESTCASE
    cin>>testcase;
#endif
    
    while(testcase--){
        SOLUTION_FUNCTION();
    }

#ifdef MY_LOCAL_PROJECT
    cout<<"Time : "<<1.0*(double)clock()/CLOCKS_PER_SEC<<endl;
#endif
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long; using ld = long double; using ull = unsigned long long; using uint = unsigned int;
using vi  = vector<int>; using vb  = vector<bool>; using vd  = vector<double>; using vl  = vector<ll>;
using vvi = vector<vi>;  using vvb = vector<vb>;   using vvd = vector<vd>;     using vvl = vector<vl>;
 
#define REP(i,n) for(ll i=0; i<(n); ++i)
#define FOR(i,b,n) for(ll i=(b); i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define TEN(x) ((ll)1e##x)
 
template<typename T> inline string join(const vector<T>& vec, string sep = " ") { stringstream ss; REP(i, vec.size()) ss << vec[i] << ( i+1 == vec.size() ? "" : sep ); return ss.str(); }
 
 
///////////////
 
#define EPS (1e-10)
#define NEXT(x, i) (x[(i + 1) % x.size()])
 
template<class T> using CR = const T &;
using P = complex<ld>;
using G = vector<P>;
 
int sgn(ld a, ld b = 0) {
    if (a > b + EPS) return 1;
    if (a < b - EPS) return -1;
    return 0;
}
 
ld dot(P a, P b) { return real(conj(a)*b); }
ld cross(P a, P b) { return imag(conj(a)*b); }
 
int ccw(P a, P b, P c) {
    b -= a;
    c -= a;
    if (sgn(cross(b, c))) return sgn(cross(b, c)); // clockwise or counter clockwise
    if (sgn(dot(b, c)) == -1) return 2;            // c--a--b
    if (sgn(norm(b), norm(c)) == -1) return -2;    // a--b--c
    return 0;                                      // a--c--b
}

bool is_convex(CR<G> g, bool strict = false) {
	REP(i, g.size()) {
		int c = ccw(g[(i + g.size() - 1) % g.size()], g[i], g[(i + 1) % g.size()]);
		if (c == -1 || (strict && c != 1)) return false;
	}
	return true;
}
 
 
//////////////
 
int main() {
#ifdef INPUT_FROM_FILE
    ifstream cin("sample.in");
    ofstream cout("sample.out");
#endif
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(30);
    ll n; cin >> n;
 
    G g(n);
    REP(i,n){
        ld x, y;
        cin >> x >> y;
        g[i] = { x, y };
    }
    cout << is_convex(g) << endl;
 
    return 0;
}

Measured memory_bytes: 3312
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll int,ll int>
#define pb push_back
#define sbit __builtin_popcount
#define vec vector <int>
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define bg begin()
#define en end()
#define endl "\n"
#define ff first
#define ss second
#define all(x) x.bg,x.en
#define sz(a) (int)a.size()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define sp(x) setprecision(x)
#define fill(a,b) memset(a,b,sizeof(a))
#define fr(i,n) for(int i=0;i<n;i++)
#define rp(i,a,b) for(int i=a;i<b;i++)
#define rr(i,a,b) for(int i=a;i>=b;i--)
#define ft(it,x) for(auto it : x)
#define dbg(x) cerr<<#x<<" "<<x<<endl;
#define dbga(arr,n) cerr<<#arr<<": "; rep(tt,0,n)cerr<<arr[tt]<<" "; cerr<<endl;
#define mapi map<int,int>
#define mapl map<ll int,ll int>
#define val_at(x) find_by_order(x)
#define idx_of(x) order_of_key(x)
#define scni(x) scanf("%d",&x)
#define prt(x) printf("%d\n",x)
#define test(t) int t;cin>>t;while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> myset;
const int mod=1e9+7;
const int mex=1e6+1;
inline ll power(ll a,ll b)
{
    ll ans=1,temp=a;
    while(b!=0)
    {
        if(b&1)
        ans=ans*temp;
        ans=ans%mod;
        temp=temp*temp;
        temp=temp%mod;
        b/=2;
    }
    return ans;
}
int pr[mex];
vec prime;
inline void seive()
{
    rp(i,2,mex) pr[i]=1;
    for(int i=2;i*i<mex;i++)
    {
        if(pr[i])
        for(int j=i*i;j<mex;j+=i)
        pr[j]=0;
    }
    vec prime;
    rp(i,2,mex)
    {
        if(pr[i]) prime.pb(i);
    }
}
ll int xx,xy,d1;
void exeu(ll int a1,ll int b1)
{
    if(b1==0)
    {
        xx=1;
        xy=0;
        d1=a1;
    }
    else
    {
        exeu(b1,a1%b1);
        ll int temp=xx;
        xx=xy;
        xy=temp-(a1/b1)*xy;
    }
}
ll int modinv(ll int A,ll int M)
{
    exeu(A,M);
    return (xx%M+M)%M;
}
int main()
{
    fast
    int n,m;
    cin>>n>>m;
    int wa[n]={0},ac[n]={0};
    fr(i,m)
    {
        int x;
        string s;
        cin>>x>>s;
        x--;
        if(s=="WA")
        {
            if(ac[x]==0) wa[x]++;
        }
        else
        {
            ac[x]=1;
        }
    }
    int cnt1=0,cnt2=0;
    fr(i,n)
    {
        cnt1+=ac[i];
        if(ac[i]) cnt2+=wa[i];
    }
    cout<<cnt1<<" "<<cnt2;
}

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


int main() {
    int n;
    cin >> n;
    if(n == 0) return !printf("0\n");
    int m = -2;
    vector< int> v;
    while(n != 0) {
        if(n < 0) {
            int z = abs(n);
            v.emplace_back(z % 2);
            n = (z + 1) / 2;
        } else {
            v.emplace_back(n % 2);
            n = n / 2;
            n = - n;
        }
    }
    reverse(v.begin(), v.end());
    for(int x: v) cout << x;
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;
int dp[1000001];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("a.in","r",stdin);
    #endif
    ll h;
    cin>>h;
    int n;
    cin>>n;
    vector <pii > a(n);
    for (int i=0;i<=1000000;i++)
        dp[i]=INF;
    dp[0]=0;
    rep(i,n)
    cin>>a[i].fi>>a[i].se;
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<=h;j++)
        {
         dp[j+a[i].fi]=min(dp[j+a[i].fi],dp[j]+a[i].se);
        }
    }
    int ans=INF;
    for (int i=h;i<=1000000;i++)
        ans=min(dp[i],ans);
    cout<<ans;

}

Measured memory_bytes: 4224
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
#include<math.h>
//#include<string.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
int main() {
	int d, w, h, r, n;
	double dw, wh, dh;
	while (~fscanf(stdin, "%d%d%d", &d, &w, &h), d || w || h) {
		dw = sqrt(d*d + w*w);
		wh = sqrt(w*w + h*h);
		dh = sqrt(d*d + h*h);
		fscanf(stdin, "%d", &n);
		while (n--) {
			fscanf(stdin, "%d", &r);
			r *= 2;
			if (dw < r || wh < r || dh < r) puts("OK");
			else puts("NA");
		}
	}
	return 0;
}

Measured memory_bytes: 584
#import numpy as np
n,c=list(map(int,input().split()))
difference=[list(map(int,input().split())) for _ in range(c)]
base=[list(map(int,input().split())) for _ in range(n)]
#tmp_d=np.array(difference)
#tmp_b=np.array(base)
cal_col=[[0 for _ in range(c)] for _ in range(3)]
for i in range(n):
    for j in range(n):
        cal_col[(i+j)%3][base[i][j]-1]+=1
ans=float("inf")
for f_i in range(c):
    for s_i in range(c):
        for t_i in range(c):
            if f_i==s_i or f_i==t_i or s_i ==t_i:
                continue
            cal_val=0
            for n_i in range(c):
                cal_val+=difference[n_i][f_i]*cal_col[0][n_i]
                cal_val+=difference[n_i][s_i]*cal_col[1][n_i]
                cal_val+=difference[n_i][t_i]*cal_col[2][n_i]
            ans=min(ans,cal_val)

print(ans)

Measured memory_bytes: 45916
from collections import deque
S = deque(input().rstrip())
Q=int(input())
cnt=True
for i in range(Q):
    query_list=input().split()
    if query_list[0] == "1":
        cnt=(cnt==False)
    else:
        if cnt:
            if query_list[1] == "1":
                S.appendleft(query_list[2])
            else:
                S.append(query_list[2])
        else:
            if query_list[1] == "1":
                S.append(query_list[2])
            else:
                S.appendleft(query_list[2])
if cnt:
    print("".join(S))
else:
    print("".join(reversed(S)))

Measured memory_bytes: 8692
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <list>
#include <math.h>
#include <string.h>
using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)



signed main(){

	int N;
	int a[101];
	cin >> N;
	int sum=0;
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	double ave = (double)sum / N;

	double diff = 10000.0;
	int index;
	for (int i = 0; i < N; i++){
		if (fabs(a[i] - ave) < diff){
			diff = fabs(a[i] - ave);
			index = i;
		}
	}

	cout << index << endl;
	return 0;
}


Measured memory_bytes: 256
import numpy as np


n = int(input())
minlim = 10**15
for i in range(5):
    lim = int(input())
    if lim < minlim:
        minlim = lim

if minlim < n:
    if n % minlim == 0:
        print(n//minlim + 4)
    else:
        print(n//minlim + 5)
else:
    print(5)


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

#define int long long
// logic: Print, Help, For, Equal, eXclusive, Decrease
#define P(x) cout << x << endl
#define H(x) P(#x << ": " << x)
#define F(i,n) for (int i=0; i<(n); i++)      // [0,n)
#define FE(i,n) for (int i=0; i<=(n); i++)    // [0,n]
#define FX(i,a,b) for (int i=(a); i<(b); i++) // [a,b)
#define D(i,n) for (int i=(n); --i>=0;)       // (n,0]
#define DX(i,a,b) for (int i=(b); --i>=(a);)  // (b,a]
#define S(s) (int)((s).size())
#define ALL(v) v.begin(), v.end()
#define V vector
#define pb push_back
#define mt make_tuple

using namespace std;

V<int> ps, lp, np;
void sieve(int m){
	lp.assign(m, 0), np.assign(m,0);
	FX(i,2,m){
		np[i] = np[i-1];
		if(!lp[i]){
			lp[i] = i;
			ps.pb(i);
			if(i % 2 && lp[(i+1)/2] == (i+1)/2) np[i]++;
		}
		for(int p : ps){
			if(p > lp[i] || i*p>=m) break;
			lp[i*p] = p;
		}
	}
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	sieve(100100);

	int q, l, r; cin >> q;
	F(i,q){
		cin >> l >> r;
		cout << (np[r]-np[l-1]) << endl;
	}
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M,C;
  cin >> N >> M >> C;
  vector<int> B(M);
  vector<vector<int>> A(N,vector<int> (M));
  for (int i = 0; i < M; i++) {
    cin >> B.at(i);
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> A.at(i).at(j);
    }
  }  
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int s = 0;
    for (int j = 0; j < M; j++) {
      s += A.at(i).at(j) * B.at(j);
    }
    s += C;
    if (s > 0) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	String reverse(String s) {
		String ans = "";
		int len = s.length();
		for (int i = 0; i < len; i++)
			ans += s.charAt(len-i-1);
		return ans;
	}
	
	void run() {
		int n = Integer.parseInt(sc.nextLine());
		Set<String> set = new HashSet<String>();
		String s;
		for (int i = 0; i < n; i++) {
			set.clear();
			s = sc.nextLine();
			set.add(s);
			for (int j = 0; j < s.length()-1; j++) {
				set.add(s.substring(j+1)+s.substring(0, j+1));
				
				set.add(reverse(s.substring(0, j+1))+s.substring(j+1));
				set.add(s.substring(j+1)+reverse(s.substring(0, j+1)));
				
				set.add(s.substring(0, j+1)+reverse(s.substring(j+1)));
				set.add(reverse(s.substring(j+1))+s.substring(0, j+1));
				
				set.add(reverse(s.substring(0, j+1))+reverse(s.substring(j+1)));
				set.add(reverse(s.substring(j+1))+reverse(s.substring(0, j+1)));
			}
			out.println(set.size());
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 150052
import heapq

N, M = map(int, input().split())
A = list(-int(i) for i in input().split())

heapq.heapify(A)
 
for _ in range(M):
    temp = -heapq.heappop(A) // 2
    heapq.heappush(A, -temp)
 
print(-sum(A))

Measured memory_bytes: 14180
#include <iostream>
#include <vector>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include "iomanip"
#include <cstdio>
#include <cstring>
#include <set>
#include <vector>
#include <fstream>
#include <algorithm>
#include <queue>
#include <cassert>
#include <stack>


using namespace std;

void print(vector<int> &b);


void print(vector<int> &b) {
    for (auto i : b) {
        cout << i << " ";
    }
    cout << endl;
}

bool comp(int a, int b) {
    int l = (a % 10) == 0 ? 10 : a % 10;
    int r = (b % 10) == 0 ? 10 : b % 10;
    return l > r;
}

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

    int a, b, k;
    cin >> a >> b >> k;
    if (b - a + 1 <= k * 2){
        for (int i = a; i <= b ; ++i) {
            cout << i << endl;
        }
    } else {
        for (int i = a; i < a + k; ++i) {
            cout << i << endl;
        }
        for (int i = b - k + 1; i <= b; ++i) {
            cout << i << endl;
        }
    }
    return 0;
}




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

#define I cin
#define O cout
#define EN endl
#define ln cout<<endl
#define pb(a) push_back(a)

typedef long long int llint;

int n;
int i, j;
llint cnt = 0;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

llint a[200001];

int gcd(int a, int b)
{
  return (b ? gcd(b, a % b) : a);
}

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

int main()
{
  I >> n;

  for(i = 0; i < n; i++) {
    llint aa;
    I >> aa;

    a[i] = aa;
    if(a) a[i] += a[i - 1];
  }

  llint mn = -1;

  for(i = 0; i < n - 1; i++) {
    llint x = a[i];
    llint y = a[n - 1] - a[i];

    if(mn == -1) mn = abs(x - y);
    else mn = min(mn, abs(x - y));
  }

  O << mn << EN;
    
  return 0;
}


Measured memory_bytes: 1792
//超絶苦手. 式を書く.
#include <iostream>
#include <string>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

string s;
int cnt[2019];

signed main() {
	cin >> s;
	int n = s.length();
	
	int i;
	int r = 0;
	int mul = 1;
	cnt[r]++;
	for (i = s.length() - 1; i >= 0; i--) {
		r = (r + (s[i] - '0') * mul) % 2019;
		mul = (mul * 10) % 2019;
		cnt[r]++;
	}
	
	int ans = 0;
	for (i = 0; i < 2019; i++) {
		ans += cnt[i] * (cnt[i] - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int64_t x;
  cin >> x;
  int64_t sum=100;
  for(int i=1;i<10000;i++){
    sum*=1.01;
    if(sum>=x){
      cout << i<<endl;
      break;
    }
  }
}
  

  

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

int main(){
  long long N;
  cin >> N;
  vector<int>number(N-1,0);
  for(int i=0;i<N-1;i++){
    int input;
    cin >> input;
    number.at(input-1)++;
  }
  for(int i=0;i<N-1;i++){
    cout << number.at(i) << endl;
  }
  cout << '0' << endl;
}


Measured memory_bytes: 3988
n,d = map(int,input().split())
x = [0 for i in range(n)]
y = [0 for i in range(n)]
b = d*d
ans=0
for i in range(n):
  x[i],y[i] = map(int,input().split())
  c=x[i]*x[i]+y[i]*y[i]
  if c<=b:
    ans+=1
print(ans)

Measured memory_bytes: 24632
#include <bits/stdc++.h>
using namespace std;
 
// #define int long long
 
/* short */
#define pb push_back
#define print(x) cout << x << '\n'
 
/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define DEPS(i, a, n) for (int i = (a); i >= n; i--)
#define DEP(i, a) for (int i = (a); i >= 0; i--)

/* typedef */
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;

/* const */
const int INF = INT_MAX;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

/* func */
inline bool is_uruu(int y) {return (y % 4 == 0 && (y % 100 != 0 || y % 400 == 0));}

signed main()
{
  //ios::sync_with_stdio(false);
  int n;

  cin >> n;
  
  for (;n--;){
    int a, b;
    cin >> a >> b;
    if (a < b){
      REPS(i, a, b + 1){
        printf("%d%c", i, (i != b) ? ' ' : '\n');
      }
    } else {
      if (0 <= a && a <= 5){
        DEPS(i, a, b){
          printf("%d%c", i, (i != b) ? ' ' : '\n');
        }
      } else {
        if (0 <= b && b <= 5){
          REPS(i, a, 10){
            printf("%d ", i);
          }
          DEPS(i, 5, b){
            printf("%d%c", i, (i != b) ? ' ' : '\n');
          }
        } else {
          REPS(i, a, 10){
            printf("%d ", i);
          }
          DEPS(i, 5, 1){
            printf("%d ", i);
          }
          REP(i, b + 1){
            printf("%d%c", i, (i != b) ? ' ' : '\n');
          }
        }
      }
    }
  }

  return (0);
}

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

#define MyREP(i, n) for (long long i = 0; i < (long long)(n); i++)

template <typename T>
ostream& operator<<(ostream& s, const vector<T> &vec){
    for(int i=0;i<vec.size();i++){
        if(i) s << ',';
        else s << '{';
        s <<setw(2)<< vec[i];
    }
    s << '}' << endl;
    return s;
}


int main(){
    long long n,mod = 1000000007;
    cin>>n;
    long long x7=1,x8=1,x9=1;
    MyREP(i,n){
        x7=x7*8%mod;
        x8=x8*9%mod;
        x9=x9*10%mod;
    }
    cout<<(x9+x7+mod*3-2*x8)%mod<<endl;
    return 0;
}

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

int main(){
    int s;
    cin >> s;
    int a = s/100;
    int b = s%100;

    if((1 <= a && a <= 12)){
        if((1 <= b && b <= 12)){
            cout << "AMBIGUOUS" << endl;
        }else{
            cout << "MMYY" << endl;
        }
    }else{
        if((1 <= b && b <= 12)){
            cout << "YYMM" << endl;
        }else{
            cout << "NA" << endl;
        }
    }
    return 0;
}
 

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

int main()
{
    string N;
    
    // 標準入力から数値を得る
    cin >> N;
    
    //得られた数値を１の位から分解する。
    int length = N.length();
    int sum = 0;
    
    for(int i =0; i<length;i++)
    {
        sum +=(N.at(i)-'0');
    }
    if(stoi(N)%sum == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define int ll
#define tcase int t; cin>> t; for( ; t; --t)
#define s second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	while(exp > 0){
		if(exp % 2 == 1){
			total = mod(((mod(total, m)) * (mod(base, m))), m);
			exp--;
		}
		base= mod((mod(base, m) * mod(base, m)), m);
		exp /= 2;
	}
	return mod(total, m);
}

int n;

int32_t main(){
	fastio;

	cin>> n;
	n = n%10;
	if(n == 3) cout<< "bon\n";
	else if(n == 2 or n == 4 or n == 5 or n == 7 or n == 9) cout << "hon\n";
	else cout << "pon\n";

	return 0;
}

Measured memory_bytes: 3648