akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
 
using namespace std;
using ll = long long int;
 
int main(void) {
    int n, k; cin >> n >> k;
    vector<int> h(n), dp(n + 100, 1000000000);
    REP(i, n) cin >> h[i];
    dp[0] = 0;
    REP(i, n) {
        REP(j, k) {
            dp[i + j + 1] = min(dp[i + j + 1], dp[i] + abs(h[i] - h[i + j + 1]));
        }
    }
    cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<set>
#include<stdio.h>
#include<ctype.h>
using namespace std;
int main()
{
	int n;
	cin >>n;
	int a[1000];
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n;j++)
		{
			if (i != j)
			{
				ans += a[i] * a[j];
			}
		}
	}
	cout << ans/2 << endl;
}

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

template<typename T>
struct BIT{
    vector<T> bit;
    BIT(int n) : bit(n+1) {}
    void add(int a,T w){
        for(int x=++a; x < bit.size(); x+=(x&(-x)) ){
            bit[x] += w;
        }
    }
    // return v[0]+v[1]+...+v[a-1];
    T sum(int a){
        T ret=0;
        for(int x=a;x>0;x-=(x&(-x)) ){
            ret+=bit[x];
        }
        return ret;
    }
};

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


    ll n;
    ll mod = 998244353;
    cin>>n;
    int x[n],y[n];
    array<int,2>  a[n];
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
        a[i] = {x[i],y[i]};
    }
    sort(a,a+n);
    sort(y,y+n);
    ll beki[n+1]={};
    beki[0] = 1;
    for(int i=1;i<=n;i++){
        beki[i] = (beki[i-1]*2)%mod;
    }
    ll ans = 0;
    BIT<int> b(n+1);
    for(int i=0;i<n;i++){
        int now = lower_bound(y,y+n,a[i][1]) - y;
        int low = b.sum(now);
        int up = b.sum(n) - low;
        ans += mod - (beki[i]*4) % mod;
        ans += beki[low] + beki[up] + beki[now-low] + beki[n-now-up-1];
        ans %= mod;
        b.add(now,1);
    }
    ans += n*(beki[n]-1);
    ans %= mod;
    cout << ans << endl;
    
}


Measured memory_bytes: 5760
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

const int MAXN = 3005, MOD = 998244353;
VEC(int) A;
int dp[MAXN][MAXN];

int F(int i, int s)
{
    // indices >= i, sum exactly s.
    const int N = A.size();
    if (s == 0)
        return 1;
    if (i == N)
        return 0;

    int& ans = dp[i][s];
    if (ans >= 0)
        return ans;
    ans = F(i + 1, s);
    if (A[i] == s) {
        ans += (N - i);
        ans %= MOD;
    } else if (s > A[i]){
        ans += F(i + 1, s - A[i]);
        ans %= MOD;
    }

    return ans;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, S;
    cin >> N >> S;
    A.resize(N);
    READVEC(A);
    memset(dp, -1, sizeof dp);

    int ret = 0;
    FOR(i, 0, N) {
        if (A[i] > S) {
            continue;
        }

        if (A[i] == S) {
            ret += (i + 1) * 1LL * (N - i) % MOD;
            ret %= MOD;
            continue;
        }

        ret += (i + 1) * 1LL * F(i + 1, S - A[i]) % MOD;
        ret %= MOD;
    }

    cout << ret << endl;
    return 0;
};

Measured memory_bytes: 35712
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 100000000

using namespace std;

int main()
{
    //COMinit();
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    llong ans=5000000100;
    for(int i=0; i<=max(x,y); i++)
    {
        llong cost=0;
        cost=c*2*i+a*max(0,x-i)+b*max(0,y-i);
        ans=min(ans,cost);
    }
    cout<<ans<<endl;
    return  0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#pragma GCC optimize "trapv"
#define _GLIBCXX_DEBUG
#define ll long long int
#define ld long double
#define ull unsigned long long int  // ranges from (0 - twice of long long int)
#define rep(i,a,n) for (ll i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define vll vector<ll>
#define MOD 1000000007LL
#define llpair pair<ll,ll>
#define INF 1000000000000000000ll		// this is 1e18 long long 
#define np next_permutation
#define PI acos(-1)
#define DEB(x) cout<<#x<<" "<<x<<endl;
#define rotate_left(vec,amt) rotate(vec.begin(),vec.begin()+amt,vec.end());
#define rotate_right(vec,amt) rotate(vec.begin(),vec.begin()+vec.size()-amt,vec.end());
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define clr(x) memset(x,0,sizeof(x))
using namespace std;
ll a[10004];
int main()
{
    speed;
    ll n;
  cin>>n;
  rep(i,1,102)
    rep(j,1,102)
    rep(k,1,102)
  {
    ll x;
   x=i*i+j*j+k*k+j*k+k*i+j*i;
    if(x<10004)
      a[x]++;
  }
  rep(i,1,n+1)
  {
    cout<<a[i]<<endl;
  }
  
    return 0;
}


Measured memory_bytes: 3660
import sys
s=str(input())
l=len(s)
for i in range(l-1):
  if s[i]==s[i+1]:
    print(' '.join([str(i+1),str(i+2)]))
    sys.exit()
  else:
    if i+2<=l-1:
      if s[i]==s[i+2]:
        print(' '.join([str(i+1),str(i+3)]))
        sys.exit()
    else:
      pass
print(' '.join(['-1','-1']))

Measured memory_bytes: 3188
// Problem : C - XYZ Triplets
// Contest : AtCoder - AIsing Programming Contest 2020
// URL : https://atcoder.jp/contests/aising2020/tasks/aising2020_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;

int give(int x,int y,int z)
{
	return (x*x+y*y+z*z+x*y+y*z+z*x);
}		
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n;
		cin>>n;
		vector<int> v;
		for(int i=1;i<=100;++i)
		{
			for(int j=1;j<=100;++j)
			{
				for(int k=1;k<=100;++k)
				{
					v.pb(give(i,j,k));
				}
			}
		}
		map<int,int> mp;
		for(int i:v)
		mp[i]++;
		for(int i=1;i<=n;++i)
		cout<<mp[i]<<"\n";		
    }
    return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> prices(N);
  N--;
  for(;N > -1; N--) cin >> prices.at(N);
  sort(prices.begin(), prices.end());
  int sum = 0;
  for(int i = 0; i < K; i++) {
    sum += prices.at(i);
  }
  
  cout << sum << endl;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

void Main(){
	int n, m;
	cin >> n >> m;
  	vi a(m);
  	ll sum = 0;
  	rep(i,m) {
      cin >> a[i];
      sum += a[i];
    }
  
	if(n - sum >= 0) cout << n - sum << endl;
	else cout << -1 << endl;
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


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

using namespace std;
long long h;
long long n, ans = 2;
int main() {
	cin >> h;
	while (h > 0) {
		h /= 2;
		ans *= 2;
	}
	ans = ans / 2 - 1;
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner (System.in);
        String s =sc.next();
        char a[] = s.toCharArray();
        int count = 0 ;
        for(int i = 0 ; i<s.length() ; i++){
            if((i%2)==0)
            {
                if(a[i]=='R'|a[i] =='U'|a[i] =='D')count++;
            }
            else
            {
                if(a[i]=='L'|a[i]=='U'|a[i]=='D')count++;
            }
            
        } if(s.length() == count) System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  string a[h];
  for(int i=0;i<h;i++){
    cin >> a[i];
    cout << a[i] << endl;
    cout << a[i] << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

class Main {
	public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int[] input_number = new int[3];
    input_number[0]  = Integer.parseInt(scan.next());
    input_number[1]  = Integer.parseInt(scan.next());
    input_number[2]  = Integer.parseInt(scan.next());
    Arrays.sort(input_number);
    System.out.println(input_number[0] + " " + input_number[1] + " " + input_number[2]);
	}
}



Measured memory_bytes: 26056
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

class BIT
{
public:
    vector<int> bit;
    int M;

    BIT(int M):
        bit(vector<int>(M+1, 0)), M(M) {}

    int sum(int i) {
        if (!i) return 0;
        return bit[i] + sum(i-(i&-i));
    }

    void add(int i, int x) {
        if (i > M) return;
        bit[i] += x;
        add(i+(i&-i), x);
    }
};

signed main(){

    int T0 = 10800, Tday = 86400;
    BIT bit(Tday + 1);
    int t = 0;
    int N; cin >> N;
    int a, b;
    REP(i, N){
        cin >> a >> b;
        t += a;
        t %= Tday;
        if(t + T0 < Tday){
            bit.add(t + 1, 1);
            bit.add(t + T0 + 1 + 1, -1);
        }else{
            bit.add(t + 1, 1);
            bit.add(Tday + 1, -1);
            bit.add(1, 1);
            bit.add(t + T0 + 1 + 1 - Tday, -1);
        }
        t += b;
        t %= Tday;
    }
    int ans = 0;
    FOR(i, 1, Tday + 1){
        ans = max(ans, bit.sum(i));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 896
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
from math import sqrt
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

N, mod = getNM()
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = getNM()
    X[x - 1].append(y - 1)
    X[y - 1].append(x - 1)

class Reroot():
    def __init__(self, graph):
        self.graph = copy.deepcopy(graph)
        ##### Settings #####
        self.unit = 1
        self.merge = lambda a, b: a * b % mod
        self.adj_bu = lambda a, i: a + 1
        self.adj_td = lambda a, i, p: a + 1
        self.adj_fin = lambda a, i: a
        ####################
        # トポソ
        P = [-1] * N # 親
        Q = deque([0])
        R = [] # 巡回した順番
        while Q:
            i = deque.popleft(Q)
            R.append(i)
            for a in self.graph[i]:
                if a != P[i]:
                    P[a] = i
                    # 親への辺を消す
                    self.graph[a].remove(i)
                    deque.append(Q, a)
        # bottom-up
        ME = [self.unit] * N # mergeを使う
        XX = [0] * N # dpする
        for i in R[1:][::-1]: # 巡回を逆順に辿る
            XX[i] = self.adj_bu(ME[i], i)
            p = P[i] # 親を取り出す
            ME[p] = self.merge(ME[p], XX[i]) # iの親要素とiの値をマージする
        XX[R[0]] = self.adj_fin(ME[R[0]], R[0])

        TD = [self.unit] * N
        for i in R: # 巡回した順番に
            ac = TD[i] # 左からDP
            for j in self.graph[i]: # 各子要素について
                TD[j] = ac
                ac = self.merge(ac, XX[j])  # マージする
            ac = self.unit
            for j in self.graph[i][::-1]:
                TD[j] = self.adj_td(self.merge(TD[j], ac), j, i)
                ac = self.merge(ac, XX[j])
                XX[j] = self.adj_fin(self.merge(ME[j], TD[j]), j)
        self.res = XX

tree = Reroot(X)
for i in tree.res:
    print(i)

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

using namespace std;

int main(){
    double N,M,sum=0;
    int ok=0;
    cin >> N >> M;
    vector<double> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
        sum += A[i];
    }

    for(int i=0;i<N;i++){
        if(sum/((double)4*M)<=A[i]){
            ok++;
        }
    }

    if(M<=ok){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  
  int ans = 0;
  int cnt = 0;
  rep(i,n){
    if(s[i]=='I') cnt++;
    else cnt--;
    maxs(ans,cnt);
  }
  cout<<ans<<endl;
  return 0;
}

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

#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cin.tie(nullptr);
#define range(v) v.begin(),v.end()
#define int long long
#define pb push_back
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define N (int)(2e5 + 10)

using namespace std;


int solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	int tot = 0;
	for (int &i : a) {
		cin >> i;
		tot ^= i;
	}

	for (int i = 0; i < n; i++) {
		cout << (tot ^ a[i]) << " ";
	}
	return 0;
}

int32_t main() {
	fast
	int t_c = 1;
	// cin >> t_c;
	while (t_c--) {
		auto ans = solve();
		// cout << ans << endl;
	}
}

Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
char s[15][N];
int num[15][N];
int main()
{
    int h, w, k, ans = 0;
    scanf("%d%d%d", &h, &w, &k);
    for (int i = 1; i <= h; i++)
        scanf("%s", s[i] + 1);
    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
            num[i][j] = num[i - 1][j] + num[i][j - 1] - num[i - 1][j - 1] + s[i][j] - '0';
    }
    if (h == 1)
    {
        int st = 0;
        for (int i = 1; i <= w; i++)
        {
            if (num[1][i] - num[1][st] == k && i < w)
            {
                ans++;
                st = i;
            }
            printf("%d\n", ans);
            return 0;
        }
    }
    ans = h * w;
    for (int i = 0; i < (1 << (h - 1)); i++) //number of types of rows
    {
        int c = 0, r;
        int res = __builtin_popcount(i);
        bool g = 0;
        for (int j = 1; j <= w; j++) // enumeration column
        {
            bool f = 0;
            r = 0;
            for (int u = 1; u <= h; u++)
            {
                if ((1 & (i >> (u - 1))) || u == h)
                {
                    int t = num[u][j] + num[r][c] - num[r][j] - num[u][c];
                    r = u;
                    if (t > k)
                        f = 1;
                }
            }
            if (f && j == c + 1)
            {
                g = 1;
                break;
            }
            if (f)
            {
                res++;
                c = j - 1;
            }
        }
        if (!g)
            ans = min(res, ans);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm;

void main(){
	auto N = readln.chomp.to!int;
	auto V = readln.split.to!(int[]);
	auto C = readln.split.to!(int[]);
	int X;
	int Y;

	foreach(i; 0..N){
		if(V[i] > C[i]){
			X += V[i];
			Y += C[i];
		}
	}
	if(X-Y<=0){
		writeln(0);
	}
	else{
		writeln(X-Y);
	}
}

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

#define swap(type,a,b) {type t; t=a; a=b; b=t;}
#define forN(i,n) for(int i=0;i<n;i++)
#define forS(i,start,n) for(int i=start;i<n;i++)
#define ll long long
#define pb(t,d,n) {t p;int i;forN(i,n){cin>>p;d.push_back(p);}}
#define DOUBLE fixed << setprecision(15)

using namespace std;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

int main(){
    int n,m,cnt=0;
    string s;

    int q;
    cin>>n>>q>>s;
    vi x(n+1,0);
    vpii lr(q);
    forN(i,q){
        pii tmp;
        cin >> tmp.first >> tmp.second;
        lr[i] = tmp;
    }
    int j=0;
    forS(i,1,n+1){
        if(s[i-1]=='A' && s[i]=='C') j++;
        x[i]=j;
    }
    forN(i,q){
        cout << x[lr[i].second-1] - x[lr[i].first-1] << endl;
    }
}


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

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

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let nm: Vec<u32> = read_vec();
    if nm[0] == nm[1] {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 100;
char s[maxn];
bool check(int l, int r){
    for(int i = l; i <= r; i++){
        if(s[i] != s[r - i + l]) return false;
    }
    return true;
}

int main(){
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    if(check(1, n) && check(1, (n - 1) / 2) && check((n + 3) / 2, n)) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 256
class ModComb:

    def __init__(self, bound, mod):
        self.bound, self.mod = bound, mod
        self.g1, self.g2, self.inv = [1, 1], [1, 1], [0, 1]
        for i in range(2, self.bound + 1):
            self.g1.append(self.g1[-1] * i % self.mod)
            self.inv.append(-self.inv[self.mod % i]
                            * (self.mod // i) % self.mod)
            self.g2.append(self.g2[-1] * self.inv[-1] % self.mod)

    def f(self, r, c):
        if r == 0 or c == 0:
            return 0
        tmp = self.g1[r + c + 2] * self.g2[r + 1] * self.g2[c + 1] % self.mod
        return (tmp - (r + c + 2)) % self.mod


r1, c1, r2, c2 = map(int, input().split())
modcomb = ModComb(2 * 10 ** 6 + 2, 10 ** 9 + 7)
print((modcomb.f(r2, c2) - modcomb.f(r1 - 1, c2)
       - modcomb.f(r2, c1 - 1) + modcomb.f(r1 - 1, c1 - 1)) % (10 ** 9 + 7))


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

  int num, ans;

int main(void){
  char s[5];
  
  cin >> s ;
  
  for(int i = 0; i < 4; i++){
    if(s[i]==s[0]) num++;
    if(s[i]==s[1]) num++;
    if(s[i]==s[2]) num++;
    if(s[i]==s[3]) num++;
    if(num == 2) ans++;
    num = 0;
  }
  
  if(ans == 4){
      cout << "Yes" << endl;
  }else{
      cout << "No" << endl;
  }
  
  return 0;
    
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    int i,j;
    for(i=1;i<=9;i++)
    for(j=1;j<=9;j++)
    printf("%dx%d=%d\n",i,j,i*j);

    return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
int a[100001], n, num, cmax = 0, cmax1 = 0; 
int main()
{
    scanf ("%d", &n);
    for (int i = 1; i <= n; i ++)
    {
    	cin >> num;
    	for (int j = -1; j <= 1; j ++) a[num + j] ++;
    	cmax1 = max(cmax1, num + 1);
	}
	for (int i = 0; i <= cmax1; i ++) cmax = max(cmax, a[i]);
	cout << cmax;
    return 0;
}


Measured memory_bytes: 640
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


n, a, b = map(int, input().split())
ans = n//(a+b)*a
x = n % (a+b)
ans += min(x, a)
print(ans)


Measured memory_bytes: 3832
n=int(input())
floor=[0 for i in range(10)]
bill=[[0 for i in range(10)] for j in range(3)]
kosha=[[[0 for i in range(10)] for j in range(3)]for k in range(4)]
flag=0

for l in range (1, n+1):
    b,f,r,v=map(int,input().split())
    kosha[b-1][f-1][r-1]+=v

for bill in kosha:
    if flag==1: 
        print("####################")
    for floor in bill:
        print(" ",end="")
        print(*floor,)
    flag=1




Measured memory_bytes: 5624
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
const ll MOD=1000000007;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const vector<pll> dir={{0,1},{1,0},{-1,0},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}};
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=b-1;i>=a;i--)
#define range(i) (i).begin(),(i).end()
#define rrange(i) (i).rbegin(),(i).rend()
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm (ll a,ll b) {return a*b/gcd(a,b);}
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
inline constexpr int modf(ll n){
    ll ans=1;
    rep(i,0,n) {ans=ans*(n-i)%MOD;}
    return ans;
}

vector<ll> func,inv;
void init(ll n){
    func.resize(n+1);inv.resize(n+1);
    func[0]=1;
    rep(i,0,n) {func[i+1]=func[i]*(i+1)%MOD;}
    inv[n]=intpow(func[n],MOD-2);
    rrep(i,1,n+1) {inv[i-1]=inv[i]*i%MOD;}
}
ll comb(ll a,ll b) {return func[a]*inv[b]%MOD*inv[a-b]%MOD;}

inline long double median(vector<ll> v){
    ll size=v.size();
    sort(v.begin(),v.end());
    if (size % 2 == 1) return v[(size - 1) / 2];
    else return v[(size / 2) - 1] ;
}
template<class T> inline bool chmax(T& a,T b) {if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b) {if(a>b){a=b;return 1;} return 0;}

int main(){
    ll n;
    cin>>n;
    vector<double> v(n);
    rep(i,0,n) cin>>v[i];
    sort(range(v));
    rep(i,1,n){
        v[i]+=v[i-1];
        v[i]/=2;
    }
    cout<<v[n-1];
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>

int main(void){
	char s[6];
	int i, a=0;
	scanf("%s", &s);
	for(i=0;i<6;i++){
		if(s[i] == '1') a++;
	}
	printf("%d\n", a);
	return 0;
}

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

#define   ll     long long int

int get(int x)
{
    if (x < 400) {
        return 0;
    }
    if (x < 800) {
        return 1;
    }
    if (x < 1200) {
        return 2;
    }
    if (x < 1600) {
        return 3;
    }
    if (x < 2000) {
        return 4;
    }
    if (x < 2400) {
        return 5;
    }
    if (x < 2800) {
        return 6;
    }
    if (x < 3200) {
        return 7;
    }
}

int main( )
{
    set<int> st;
    int n, i, c = 0;
    cin >> n;
    for (i = 1; i <= n; i++) {
        int j; cin >> j;
        if (j >= 3200) {
            c++;
            continue;
        }
        st.insert(get(j));
    }
    cout << max(1, (int) st.size()) << ' ' << ((int) st.size() + c) << '\n';
    return 0;
}




Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(X: int, Y: int, Z: int):
    print(Z,X,Y)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    solve(X, Y, Z)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

long long gcd(long long a, long long b) { return b?gcd(b,a%b):a;}
long long ngcd(vector<long long> a){
    long long result = a[0];
    for(int i = 1; i < a.size() && result != 1; ++i) {
        result = gcd(result, a[i]);
    }
    return result;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];
    auto ans = ngcd(a);
    cout << ans << endl;
}

Measured memory_bytes: 1792
N = int(input())
S = input()
T = []
c = 0
m = 0
for s in S:
  if s == ")":
    c += 1
  else:
    if c > 0:
      m += c #先頭につける"("の数
      c = 0
    c -= 1
  if c > 0:
    m += c #先頭につける"("の数
    c = 0
print("("*m + S + ")"*(-c))
  

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

const int INF = 1e9;

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

    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, -INF));
    vector<vector<int>> rev(n + 1, vector<int>(m + 1));
    dp[0][0] = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            if (i + 1 <= n) {
                if (dp[i + 1][j] < dp[i][j]) {
                    dp[i + 1][j] = dp[i][j];
                    rev[i + 1][j] = 0;
                }
            }
            if (j + 1 <= m) {
                if (dp[i][j + 1] < dp[i][j]) {
                    dp[i][j + 1] = dp[i][j];
                    rev[i][j + 1] = 1;
                }
            }
            if (i + 1 <= n && j + 1 <= m && s[i] == t[j]) {
                if (dp[i + 1][j + 1] < dp[i][j] + 1) {
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                    rev[i + 1][j + 1] = 2;
                }
            }
        }
    }
    vector<char> ans(3001);
    int ns = n;
    int nt = m;
    int at = dp[n][m] - 1;
    while (ns || nt) {
        if (rev[ns][nt] == 0)
            ns--;
        else if (rev[ns][nt] == 1)
            nt--;
        else {
            ns--;
            nt--;
            ans[at] = s[ns];
            at--;
        }
    }
    for (int i = 0; i < dp[n][m]; i++)
        cout << ans[i];
    cout << endl;

	return 0;
}

Measured memory_bytes: 73528
#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 5;
const int mod = 1e9 + 7;
map<int,int> primeNum;

void factorize(int x) {
    for(int i = 2; i*i <= x; i++) {
        if(x % i) {
            continue;
        }
        int cnt = 0;
        while(x % i == 0) {
            cnt++;
            x /= i;
        }
        primeNum[i] += cnt;
    }
    if(x != 1) {
        primeNum[x]++;
    }
}

int main() {
    int n;
    scanf("%d", &n);
    for(int i = 2; i <= n; i++) {
        factorize(i);
    }
    long long ans = 1;
    for(auto p: primeNum) {
        ans = ans*(p.second+1)%mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
abc = []
for i in range(N):
    abc.append(list(map(int,input().split())))

dp = [[0,0,0] for i in range(N+1)]
#dp[0] = abc[0]

for i in range(1,N+1):
    dp[i][0] = max(dp[i-1][1] + abc[i-1][0] , dp[i-1][2] + abc[i-1][0])
    dp[i][1] = max(dp[i-1][0] + abc[i-1][1] , dp[i-1][2] + abc[i-1][1])
    dp[i][2] = max(dp[i-1][0] + abc[i-1][2] , dp[i-1][1] + abc[i-1][2])

print(max(dp[-1]))

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

int main(){
	multiset<string> se;
	string str,str2;
	while(cin>>str){
		se.insert(str);
	}

	int cnt=0,cnt2=0;
	for(auto it=se.begin();it!=se.end();it++){
		int tmp=se.count(*it);
		if(tmp>cnt){
			cnt=tmp;
			str=(*it);
		}
		int tmp2=(int)(*it).length();
		if(tmp2>cnt2){
			cnt2=tmp2;
			str2=(*it);
		}
	}
	cout<<str<<" "<<str2<<endl;
	return 0;
}

Measured memory_bytes: 3016
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937_64 mt64(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/

int n, a[2005];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	sort(a, a + n);
	int ans = 0;
	rep(i, n) {
		for (int j = i + 1; j < n; j++) {
			int maindex = upper_bound(a, a + n, max(a[i] - a[j], a[j] - a[i])) - a;
			if (maindex <= j)maindex = j + 1;
			int miindex = lower_bound(a, a + n, a[i] + a[j]) - a;
			ans += max(0ll, miindex - maindex);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import sys
import math
import itertools 
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N,M,Q=nm()
a=[0]*Q
b=[0]*Q
c=[0]*Q
d=[0]*Q
for i in range(Q):
    a[i],b[i],c[i],d[i]=nm()

A_lb=[i+1 for i in range(M)]
A_cmb=list(itertools.combinations_with_replacement(A_lb,N))

sumd=0
sumd_max=0
for alist in A_cmb:
    for i in range(Q):
        if(alist[b[i]-1]-alist[a[i]-1]==c[i]):
            sumd+=d[i]
    if(sumd>sumd_max):
        sumd_max=sumd
    sumd=0

print(sumd_max)

Measured memory_bytes: 21444
#include <cstdio>
#include <vector>

int main()
{
    int n, m, x; scanf("%d %d %d", &n, &m, &x);
    std::vector<std::vector<int>> book(n, std::vector<int>(m+1));
    std::vector<int> count_cost(m+1, 0);
    int min_cost = 13 * 100000;

    for (int i=0; i<n; i++)
    {
        for (int j=0; j<m+1; j++)
        {
            scanf("%d", &book.at(i).at(j));
        }
    }

    for (int i=1; i < (1 << n); i++)
    {
        int bit = i;
        int current = 0;
        for (int j=0; j<m+1; j++) count_cost.at(j) = 0;
        while (1)
        {
            if (bit % 2 == 1)
            {
                for (int j=0; j<m+1; j++) count_cost.at(j) += book.at(current).at(j);
            }
            current++;
            bit /= 2;

            bool all_true = true;
            for (int j=1; j<m+1; j++)
            {
                if (count_cost.at(j) < x) all_true = false;
            }
            if (all_true && count_cost.at(0) < min_cost) {min_cost = count_cost.at(0); break;}

            if (bit == 0) break;
        }

    }

    if (min_cost == 13 * 100000) printf("-1\n");
    else printf("%d\n", min_cost);

    return 0;
}



Measured memory_bytes: 3228
n,k = map(int,input().split())
s = list(input())


if s[k-1] == "A":
    s[k-1] = "a"
    
elif s[k-1] == "B":
    s[k-1] = "b"
    
elif s[k-1] == "C":
    s[k-1] = "c"

ss = "".join(s)

print(ss)



Measured memory_bytes: 3060
#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 <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <fstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second


//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EPS 1e-8

set<string> sstr;

int main(){
	int n;
	cin>>n;
	REP(i,n){
		string tmp;
		cin>>tmp;
		sstr.insert(tmp);
	}
	cin>>n;
	int flag = 0;
	REP(i,n){
		string tmp;
		cin>>tmp;
		if(EXIST(sstr, tmp)){
			if(flag){
				cout << "Closed by " << tmp << endl;
			}else{
				cout << "Opened by " << tmp << endl;
			}
			flag = !flag;
		}else{
			cout << "Unknown " <<tmp << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1232
s = input()


def main():
#    s = ['0' for _ in range(10**5)]
#   TLE check py3 だとちょっと遅いかもしれない？
    n = len(s)
    mod = 10**9 + 7

    dp = [[0]* 13 for _ in range(n+1)]
    dp[0][0] = 1

    #print(len(dp),len(dp[0]))

    # i : 桁数
    # j : 13で割った余り
    # k : ? をkと仮定
    # dp[i][j] : i+1 桁目 までの数字を13で割ったとき、余りがjになる数の個数
    for i in range(n):
        if s[i] != '?':

            c = int(s[i]) - int('0')
            for j in range(13):
                i_ = i+1
                j_ = (j*10+c); j_%=13
                dp[i_][j_] += dp[i][j]
                dp[i_][j_] %= mod
        else: 
            for j in range(13):
                for k in range(10):
                    i_ = i+1
                    j_ = j*10+k ; j_ %= 13
                    dp[i_][j_] += dp[i][j]
                    dp[i_][j_] %= mod

        # print(i,j,dp[i+1])
    print(dp[-1][5])      
     
main()
        


Measured memory_bytes: 61916
from sys import stdin
import sys

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs

def rev(s):
	return s[-1::-1]

# def main(inputs):
# 	s=inputs[0][0]
# 	q=int(inputs[1][0])
# 
# 	for qi in range(q):
# 		ti=int(inputs[qi+2][0])
# 		if ti==1:
# 			s=rev(s)
# 		else:
# 			f=int(inputs[qi+2][1])
# 			c=inputs[qi+2][2]
# 			if f==1:
# 				s=c+s
# 			else:
# 				s=s+c
# 	print(s)


class E:
	def __init__(self, c, pre, nex):
		self.c=c
		self.pre=pre
		self.nex=nex
		

	
def main(inputs):
	s=inputs[0][0]
	q=int(inputs[1][0])
	
	prev=None
	for ci,c in enumerate(s):
		e=E(c, prev, None)
		if prev is not None: prev.nex=e
		prev=e
		if ci==0:
			head=e
	tail=e
	
	size=len(s)
	order=0 #0: forward, 1: backward
	for qi in range(q):
		ti=int(inputs[qi+2][0])
		if ti==1:
			order=1-order
		else:
			f=int(inputs[qi+2][1])
			c=inputs[qi+2][2]
			e=E(c, None, None)
			size+=1
			if f==1:
				if order==0:
					e.nex=head
					head.pre=e
					head=e
				else:
					e.pre=tail
					tail.nex=e
					tail=e
			else:
				if order==1:
					e.nex=head
					head.pre=e
					head=e
				else:
					e.pre=tail
					tail.nex=e
					tail=e
	
	cList=[None]*size
	if order==0:
		e=head
		for i in range(size):
			cList[i]=e.c
			e=e.nex
	else:
		e=tail
		for i in range(size):
			cList[i]=e.c
			e=e.pre
	
	print("".join(cList))
	

if __name__=="__main__":
	inputs=getInputs()
# 	inputs=simInputs()
	main(inputs)
	


Measured memory_bytes: 92148
#include <cstdio>
#include <cmath>
#include <vector> 
#include <limits>
using namespace std;
int N;
int K;
int int_inf = numeric_limits<int>::max();

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

int jump(int history, int h_destination, int h_departure){
  return history + abs(h_destination-h_departure);
}

int main(){
  scanf("%d %d", &N, &K);
  vector<int> footing(N);
  vector<int> dp(N,int_inf);
  for(int i=0; i<N; i++) scanf("%d", &footing[i]);
  
  chmin(dp[0], 0);
  for(int i=1; i<N; i++){
    for(int k=1; k<K+1; k++){
      if(i-k>=0) chmin(dp[i], jump(dp[i-k], footing[i], footing[i-k]));
    }
  }
  printf("%d\n", dp[N-1]);
}

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

#define EPSILON 1e-6
#define ll long long
#define pii pair<int, int>

int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, k;
  cin >> n >> k;

  double prob = 0;
  for (int i=1; i<=n; i++) {
    if (k > i) {
      int x = ceil(log2(k/(1.0*i)));
      prob += (1.0 / n) * pow(0.5, x);
    }
    else {
      prob += (1.0 / n);
    }
  }

  cout << setprecision(18);
  cout << prob << "\n";
  return 0;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << ""; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	string s;

	cin >> s;

	ll cnt = 0;

	REP(i, s.size()) {
		if (s[i] == 'p') {
			cnt++;
		}
	}

	cout << s.size() / 2 - cnt << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


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

    int A, B, N;
    cin >> A >> B >> N;
    int Q = A*min(N, (B-1) )/B;
    cout << Q << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
const ll inf = 1000000001, INF = (ll)1e18 + 1, maxn = 405;

void solve() {
	int n;
	cin >> n;
	
	vi a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	vector<vector<ll>> dp(maxn, vector<ll>(maxn, INF));
	for(int l = n - 1; l >= 0; l--) {
		for(int r = l; r < n; r++) {
			if(r == l) dp[l][r] = 0;
			else {
				ll cost = 0;
				for(int i = l; i <= r; i++) cost += a[i];
				for(int i = l; i <= r; i++) {
					dp[l][r] = min(dp[l][r], dp[l][i] + dp[i + 1][r] + cost);
				}
			}
		} 
	}
	
	cout << dp[0][n - 1] << endl;
}

int main(){
#define MULTITEST 0
#if MULTITEST   
 
    CASET {
        solve();
    }
    
#else

    solve();
    
#endif

    return 0;
}

Measured memory_bytes: 4916
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define prec fixed << setprecision(20)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define test int t; cin >> t; while(t--)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;

void solve() {
	int n;
	cin >> n;
	int sum = 0;
	rep(a, 1, n) {
		rep(b, 1, n) {
			rep(c, 1, n) {
				sum += __gcd(a, __gcd(b, c));
			}
		}
	}
	cout << sum;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);


#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// test
	solve();

	return 0;
}

Measured memory_bytes: 3636
#pragma region def
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;

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

using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
using pint = pair<int, int>;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const long long llINF = 1e18;
#pragma endregion

int main () {
    int a[3][3], n;
    bool table[3][3] = {false};
    rep(i, 3) {
        rep(j, 3) {
            cin >> a[i][j];
        }
    }
    cin >> n;
    vint b(n);
    rep(i, n) cin >> b[i];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < n; k++) {
                if (b[k] == a[i][j]) {
                    table[i][j] = true;
                }
            }
        }
    }
    bool check = false;
    int temp = 0;

    for (int i = 0; i < 3; i++) {
        temp = 0;
        for (int j = 0; j < 3; j++) {
            if (table[i][j] == true) temp++;
        }
        if (temp == 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    for (int i = 0; i < 3; i++) {
        temp = 0;
        for (int j = 0; j < 3; j++) {
            if (table[j][i] == true) temp++;
        }
        if (temp == 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    if (table[0][0] == true && table[1][1] == true && table[2][2] == true) {
        cout << "Yes" << endl;
        return 0;
    }

    if (table[0][2] == true && table[1][1] == true && table[2][0] == true) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

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

using namespace std;

const long long INF =  1LL << 60;
long long dp[101000];

int main(){
    int N, K;
    cin >> N >> K;
    vector<long long> hight(N);
    //init
    for(int i=0; i<N; ++i) cin >> hight[i];
    for(int i=0; i<N; ++i) dp[i] = INF;


    dp[0] = 0;
    dp[1] = abs(hight[1]- hight[0]);

    for(int i=0; i<N; ++i){
        for(int j=i+1; j<=i+K; ++j){
            dp[j] = min( dp[j], dp[i] + abs(hight[i] - hight[j]));
        }
    }
    cout << dp[N-1] << endl;

}


Measured memory_bytes: 1792