akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3") 
#pragma GCC optimization ("unroll-loops")
 
// #include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
// const ll RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
// gp_hash_table<int, int> table;
 
#define ll  long long
#define vii vector< ll >
#define pb push_back
#define pii pair<ll,ll>
#define ppi pair<pii,ll>
#define all(x) x.begin(),x.end()
#define S second
#define F first
#define ins insert
#define ld long double
#define lp(l,r) for(i=l;i<=r;++i)
 
#define lpj(l,r) for(j=l;j<=r;++j)
#define lpr(l,r) for(i=r;i>=l;--i)
#define lprj(l,r) for(j=r;j>=l;--j)
 
#define swap(a,b){ auto _t=a;a=b,b=_t;}
#define flush() cout.flush()
#define popcount __builtin_popcount
#define die() return 0;
#define sz() size() 


 
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define MD          1000000007
#define M 			200011
#define LN             14
#define fftmod      998244353
#define EPS         (double)1e-10
 
long long  md=MD;
ll inf=1e18;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
 
 
inline ll exp(ll a,ll b){if(a==0&&b==0)return 1ll;if(a==0)return 0ll;ll r=1LL;while(b>0){if(b&1){r=(r%md)*(a%md);r=(r+md)%md;}b/=2;a=(a%md)*(a%md);a=(a+md)%md;}return (r+md)%md;}
ll gcd(ll a,ll b){if(b==0)return a;if(a==0)return b;return gcd(b,a%b);}
inline ll poww(ll a,ll b){ll r=1LL;while(b>0){if(b&1)r=r*a;b/=2;a=a*a;}return (ll)r;}
 
using cd=complex<double>;
const double PI=acos(-1);
 
inline ll rand(ll l,ll r){
    return l+rng()%(r-l+1);
 
}

ll a[M];
ll fa[M],iv[M];
ll chose(ll n,ll k){
	if(n<k)return 0;
	ll r=fa[n];r=r*iv[k]%md;r%=md;r=r*iv[n-k]%md;return r%md;
}

int main(){
 
     
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
 
   // ifstream fin("input.txt");ofstream fout("outut.txt");
    ll t,i,j,m,n,s,z,k,p;string s1,s2;ll q;ll x,y;
    fa[0]=iv[0]=1;
    lp(1,2e5){
    	fa[i]=fa[i-1]*i%md;fa[i]%=md;
    	iv[i]=iv[i-1]*exp(i,md-2)%md;iv[i]%=md;
    }
    cin>>n>>m>>k;
    p=0;
    for(i=1;i<=n-1;++i){
    	p=p+(n-i)*i%md;p%=md;
    }
    p=p*(m*m)%md;
    x=chose(n*m-2,k-2)%md;
    p=p*x%md;
    ll ans=p;

    p=0;
    for(i=1;i<=m-1;++i){
    	p=p+(m-i)*i%md;p%=md;
    }
    p=p*(n*n)%md;
    x=chose(n*m-2,k-2)%md;
    p=p*x%md;
    ans=ans+p%md;ans%=md;
    cout<<ans<<"\n";




}



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

#define FOR(i, min, max) for (int i = (min); i < (max); ++i) 
#define FORE(i, min, max) for (int i = (min); i <= (max); ++i) 
#define REP(i, n) for (int i = 0; i < (n); ++i) 
#define REPV(vec, i) for (int i = 0; i < (int)(vec.size()); ++i) 
#define FOR_EACH(vec, it) for (typeof((vec).begin()) it = (vec).begin(); it != (vec).end(); ++it)

using namespace std; 
static const double EPS = 1e-12; 
typedef long long ll; 

int N;
vector<int> a;
vector<vector<int> > E;
vector<int> ans;

int mem[2*100000+10];

void solve(int n, int d, int lastN) {
    int *p = lower_bound(mem, mem+d, a[n]);
    int origP = *p;
    *p = a[n];
    ans[n] = (int)(lower_bound(mem, mem+d, INT_MAX) - mem);
    for (auto nn : E[n]) if (nn != lastN) {
       solve(nn, d+1, n);
    }
    *p = origP;
}

int main(void)
{
    cin >> N;
    a.resize(N);
    REP(i, N)
        cin >> a[i];
    E.resize(N);
    REP(i, N-1) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        E[u].push_back(v);
        E[v].push_back(u);
    }
    ans.resize(N, -1);

    REP(i, N)
        mem[i] = INT_MAX;

    solve(0, 1, -1);

    REP(i, N)
        cout << ans[i] << endl;
    return 0;
}


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

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

int main()
{
    ll i,j;
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    for(i = 0;i < n;++i){
        cin >> a.at(i);
    }
    if(k >= 50){
        for(i = 0;i < n;++i){
            cout << n << endl;
        }
        return 0;
    }else{
        rep(j,k){
            vector<ll> b(n,0);
            for(i = 0;i < n;++i){
                ++b.at(max(0ll, i-a.at(i)));
                if(i + a.at(i) + 1 < n) --b.at(i + a.at(i) + 1);
            }
            for(i = 0;i < n-1;++i){
                b.at(i+1) += b.at(i);
            }
            for(i = 0;i < n;++i){
                a.at(i) = b.at(i);
            }
        }
        for(i = 0;i < n;++i){
            cout << a.at(i) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 6352
#include <stdio.h>

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

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

def solve():
    def makeBIT(numEle):
        numPow2 = 2 ** (numEle-1).bit_length()
        data = [0] * (numPow2+1)
        return data, numPow2
    def addValue(iA, A):
        iB = iA + 1
        while iB <= numPow2:
            data[iB] += A
            iB += iB & -iB
    def getSum(iA):
        iB = iA + 1
        ans = 0
        while iB > 0:
            ans += data[iB]
            iB -= iB & -iB
        return ans
    def getRangeSum(iFr, iTo):
        return getSum(iTo) - getSum(iFr-1)

    N, Q = map(int, input().split())
    cs = list(map(lambda x: int(x)-1, input().split()))
    LRs = []
    Lss = [[] for _ in range(N)]
    for i in range(Q):
        L, R = map(int, input().split())
        L, R = L-1, R-1
        LRs.append((L, R))
        Lss[R].append((L, i))

    data, numPow2 = makeBIT(Q)

    anss = [0] * Q
    posRights = [-1] * N
    for R, c in enumerate(cs):
        if posRights[c] != -1:
            addValue(posRights[c], -1)
        addValue(R, 1)
        posRights[c] = R
        for L, i in Lss[R]:
            anss[i] = getRangeSum(L, R)

    print('\n'.join(map(str, anss)))


solve()


Measured memory_bytes: 274044
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll n,m,g;
char s[100005],t[100005];
bool o=true;
int main(void){
    cin>>n>>m>>s>>t;
    g=gcd(n,m);
    ll a=0,b=0;
    while(a<n){
        if(s[a]!=t[b])o=false;
        a+=(n/g);
        b+=(m/g);
    }
    if(o)cout<<n*m/g<<endl;
    else cout<<-1<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define fast_i_o ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int main()
{
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    for(int i=0;i<n;i++)
        {cin>>arr[i];arr[i]--;}
    ll ans=0;
    ll vis[n]={0},flag=0;
    vis[0]=1;
   while(k>0)
   {
       ans=arr[ans];
        k--;
         if(vis[ans]==1)
        {flag=1;break;}
        else
            vis[ans]=1;
   }
   if(flag==1)
   {
       ll ans1=ans,count1=0;
       while(arr[ans1]!=ans)
       {
           ans1=arr[ans1];
           count1++;
       }
       count1++;
       k=k%count1;
       while(k>0)
       {
           ans=arr[ans];
           k--;
       }
   }
   cout<<ans+1<<"\n";

}


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

const int N =1300;

int main(void)
{ 
   
      char str[N];
      while(fgets(str , 1300 , stdin))
      {
      	int sum = 0;
      	if(str[0] == '0')
      	{
      		break;
		  }
      	for(int i = 0; i< strlen(str)-1 ; i++)
      	{
      		sum+=str[i]-'0';
		  }
      		
      		printf("%d\n",sum);
		
	  }
	  return 0 ;
}


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

int main(){
  int N;
  string S;
  cin >> N >> S;
  int count = 1;
  for (int i = 0; i < (N - 1); i++){
    if (S.at(i) != S.at(i + 1)) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 1020
#include <stdio.h>
void qsort(int a[],int left,int right)
{
	if(left < right)
	{
		int pvot,tmp,i,j;
		i = left;
		j = right;
		pvot = (a[i] + a[j])/2;
		while(1)
		{
			while(a[i] < pvot)i++;
			while(a[j] > pvot)j--;
			if(i >= j)
			{
				break;
			}
			tmp = a[i];
			a[i] = a[j];
			a[j] = tmp;
			i++;
			j--;
		}
		qsort(a,left,i -1);
		qsort(a,j + 1,right);
	}
	return;
}
int main(void)
{
	int i,n;
	int array[5];
	for(i = 0;i < 5;i++)
	{
		scanf("%d",&array[i]);
	}
	qsort(array,0,4);
	for(i = 0;i < 4;i++)
	{
		printf("%d ",array[4-i]);
	}
	printf("%d\n",array[0]);
	return 0;
}

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


int main()
{
	string str;
	cin>>str;
	int n = str.size();
	int count = 0;
	for(int i = 0;i<n/2;i++)
	{
		if(str[i] != str[n-i-1])
			count++;
	}
	cout<<count<<'\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;

// Extended Print Func
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& input){
    os << "[ ";
    REP(i, input.size()){
        os << input[i];
        if (i < input.size()-1) { os << " "; }
    }
    os << " ]";
    return os;
}
void print() { std::cout << "\n"; }
template<class T, class... A> void print(const T& first, const A&... rest) { std::cout << first << " "; print(rest...); }
template<class... A> void print(const A&... rest) { print(rest...); }



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N, R;
  cin >> N >> R;
  ll ans;
  if (N>=10){
    ans = R;
  } else {
    ans = R + 100 * (10-N);
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define prsp(v) loop(i,0,v.size())cout<<v[i],sp;nl;
#define prpsp(v) loop(i,0,v.size())cout<<v[i].F<<" "<<v[i].S<<" , ";nl;
#define prnl(v) loop(i,0,v.size())cout<<v[i],nl;nl;
#define prpnl(v) loop(i,0,v.size())cout<<v[i].F<<" "<<v[i].S,nl;nl;
#define MOD 1000000007
#define mod(n) (((n%MOD)+MOD)%MOD)
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const int MAXN = 1e5+5;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
vector<pii>gr[MAXN];
bool vis[MAXN];
bool col[MAXN];

void dfs(int node, int par)
{
    vis[node]=1;
    for(int i=0;i<gr[node].size();i++)
    {
        int next = gr[node][i].F;
        if( !vis[next] )
        {
            col[next] = 1^col[node];
            if( gr[node][i].S %2 == 0 )
            {
                col[next] = col[node];
            }
            dfs(next,node);
        }
    }
}

int main() 
{
    fastio();

    ll n;
    cin>>n;
    for(int i=0;i<n-1;i++)
    {
        ll u,v,w;
        cin>>u>>v>>w;
        u--,v--;
        gr[u].pb({v,w});
        gr[v].pb({u,w});
    }

    col[0]=1;
    dfs(0,-1);

    for(int i=0;i<n;i++)
    {
        cout<<col[i],nl;
    }


    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Measured memory_bytes: 8192
import std.stdio;
import std.string;
import std.format;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.concurrency;
import std.traits;
import std.uni;
import core.bitop : popcnt;
alias Generator = std.concurrency.Generator;

enum long INF = long.max/5;
enum long MOD = 10L^^9+7;

void main() {
  long a, b;
  scanln(a, b);
  writeln(a*b/gcd(a, b));
}

// ----------------------------------------------


void times(alias fun)(long n) {
  // n.iota.each!(i => fun());
  foreach(i; 0..n) fun();
}
auto rep(alias fun, T = typeof(fun()))(long n) {
  // return n.iota.map!(i => fun()).array;
  T[] res = new T[n];
  foreach(ref e; res) e = fun();
  return res;
}

T ceil(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  // `(x+y-1)/y` will only work for positive numbers ...
  T t = x / y;
  if (y > 0 && t * y < x) t++;
  if (y < 0 && t * y > x) t++;
  return t;
}

T floor(T)(T x, T y) if (isIntegral!T || is(T == BigInt)) {
  T t = x / y;
  if (y > 0 && t * y > x) t--;
  if (y < 0 && t * y < x) t--;
  return t;
}

ref T ch(alias fun, T, S...)(ref T lhs, S rhs) {
  return lhs = fun(lhs, rhs);
}
unittest {
  long x = 1000;
  x.ch!min(2000);
  assert(x == 1000);
  x.ch!min(3, 2, 1);
  assert(x == 1);
  x.ch!max(100).ch!min(1000); // clamp
  assert(x == 100);
  x.ch!max(0).ch!min(10); // clamp
  assert(x == 10);
}

mixin template Constructor() {
  import std.traits : FieldNameTuple;
  this(Args...)(Args args) {
    // static foreach(i, v; args) {
    foreach(i, v; args) {
      mixin("this." ~ FieldNameTuple!(typeof(this))[i]) = v;
    }
  }
}

void scanln(Args...)(auto ref Args args) {
  enum sep = " ";
  enum n = Args.length;
  enum fmt = n.rep!(()=>"%s").join(sep) ~ "\n";
  static if (__VERSION__ >= 2071) {
    readf!fmt(args);
  } else {
    enum argsTemp = n.iota.map!(
      i => "&args[%d]".format(i)
    ).join(", ");
    mixin(
      "readf(fmt, " ~ argsTemp ~ ");"
    );
  }
}

// fold was added in D 2.071.0
static if (__VERSION__ < 2071) {
  template fold(fun...) if (fun.length >= 1) {
    auto fold(R, S...)(R r, S seed) {
      static if (S.length < 2) {
        return reduce!fun(seed, r);
      } else {
        return reduce!fun(tuple(seed), r);
      }
    }
  }
}

// popcnt with ulongs was added in D 2.071.0
static if (__VERSION__ < 2071) {
  ulong popcnt(ulong x) {
    x = (x & 0x5555555555555555L) + (x>> 1 & 0x5555555555555555L);
    x = (x & 0x3333333333333333L) + (x>> 2 & 0x3333333333333333L);
    x = (x & 0x0f0f0f0f0f0f0f0fL) + (x>> 4 & 0x0f0f0f0f0f0f0f0fL);
    x = (x & 0x00ff00ff00ff00ffL) + (x>> 8 & 0x00ff00ff00ff00ffL);
    x = (x & 0x0000ffff0000ffffL) + (x>>16 & 0x0000ffff0000ffffL);
    x = (x & 0x00000000ffffffffL) + (x>>32 & 0x00000000ffffffffL);
    return x;
  }
}


Measured memory_bytes: 256
//
//  main.cpp

#include <iostream>
using namespace std;
int m,n;
bool matrix[100][100];
bool visited[100][100];

void reset(){
	m = n = 0;
	for(int i=0;i<100;i++){
		for(int j=0;j<100;j++){
			matrix[i][j] = false;
			visited[i][j] = false;
		}
	}
}

int dfs(int depth,int x,int y){
	if(!matrix[x][y]){
		return depth-1;
	}
	int a=0,b=0,c=0,d=0;
	if(!visited[x+1][y]){
		visited[x+1][y] = true;
		a = dfs(depth+1,x+1,y);
		visited[x+1][y] = false;
	}
	if(!visited[x-1][y]){
		visited[x-1][y] = true;
		b = dfs(depth+1,x-1,y);
		visited[x-1][y] = false;
	}
	if(!visited[x][y+1]){
		visited[x][y+1] = true;
		c = dfs(depth+1,x,y+1);
		visited[x][y+1] = false;
	}
	if(!visited[x][y-1]){
		visited[x][y-1] = true;
		d = dfs(depth+1,x,y-1);
		visited[x][y-1] = false;
	}
	return max(a,max(b,max(c,d)));
}

int main(){	

	while(1){
		reset();
		cin >> m >> n;
		if (m==0&&n==0)break;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				int input;
				cin >> input;
				if(input){
					matrix[i][j] = true;
				}else{
					matrix[i][j] = false;
				}
			}
		}
		int answer=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++){
				visited[i][j] = true;
				answer = max(answer,dfs(1,i,j));
				visited[i][j] = false;
			}
		}
		cout << answer << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 2992
import numpy as np

N, M, X = list(map(int, input().split()))
array = np.array([list(map(int, input().split())) for _ in range(N)])

min_C = np.inf
conbi = None
m = 2**N

for i in range(m):
  tmp = []
  for _ in range(N):
    tmp.append(i%2)
    i //= 2
  
  sum_array = np.sum(array[np.where(tmp)], axis=0)
  #print(tmp)
  if np.all(sum_array[1:]>=X):
    if sum_array[0] < min_C:
      min_C = sum_array[0]
      conbi = tmp
      
if conbi is None:
  print(-1)
else:
  print(min_C)

Measured memory_bytes: 27276
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long val = log2(n);
        long dd = (long) Math.pow(2, val+1);
        System.out.println((long) dd-1);
    }


    public static int log2(long x) {
        return (int) (Math.log(x) / Math.log(2));
    }
}

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

using namespace std;

int main()
{
    int H, W;
    while (cin >> W >> H, H | W)
    {
        vector<vector<int>> order(H, vector<int>(W));
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
                cin >> order[i][j];
        }
        vector<int> C(4);
        for (int i = 0; i < 4; i++)
            cin >> C[i];

        vector<vector<vector<int>>> dp(H, vector<vector<int>>(W, vector<int>(5, 1e9)));
        dp[0][0][0] = 0;
        // →0,↓1,←2,↑3,停止4
        using tp = tuple<int, int, int>;
        priority_queue<pair<int, tp>, vector<pair<int, tp>>, greater<pair<int, tp>>> que;
        que.push(make_pair(0, make_tuple(0, 0, 0)));
        while (!que.empty())
        {
            auto s = que.top();
            que.pop();
            int d = s.first;
            int x = get<0>(s.second);
            int y = get<1>(s.second);
            int dir = get<2>(s.second);
            for (int i = 0; i < 4; i++)
            {
                int c = 0;
                if (order[y][x] != i)
                {
                    c = C[i];
                }
                int ndir = (dir + i) % 4;
                if (ndir == 0)
                {
                    if (x + 1 < W && dp[y][x + 1][ndir] > dp[y][x][dir] + c)
                    {
                        dp[y][x + 1][ndir] = dp[y][x][dir] + c;
                        que.push(make_pair(dp[y][x + 1][ndir], make_tuple(x + 1, y, ndir)));
                    }
                }
                else if (ndir == 1)
                {
                    if (y + 1 < H && dp[y + 1][x][ndir] > dp[y][x][dir] + c)
                    {
                        dp[y + 1][x][ndir] = dp[y][x][dir] + c;
                        que.push(make_pair(dp[y + 1][x][ndir], make_tuple(x, y + 1, ndir)));
                    }
                }
                else if (ndir == 2)
                {
                    if (x - 1 >= 0 && dp[y][x - 1][ndir] > dp[y][x][dir] + c)
                    {
                        dp[y][x - 1][ndir] = dp[y][x][dir] + c;
                        que.push(make_pair(dp[y][x - 1][ndir], make_tuple(x - 1, y, ndir)));
                    }
                }
                else if (ndir == 3)
                {
                    if (y - 1 >= 0 && dp[y - 1][x][ndir] > dp[y][x][dir] + c)
                    {
                        dp[y - 1][x][ndir] = dp[y][x][dir] + c;
                        que.push(make_pair(dp[y - 1][x][ndir], make_tuple(x, y - 1, ndir)));
                    }
                }
            }
        }
        // for (int k = 0; k < 4; k++)
        // {
        //     for (int i = 0; i < H; i++)
        //     {
        //         for (int j = 0; j < W; j++)
        //         {
        //             cout << dp[i][j][k] << ' ';
        //         }
        //         cout << endl;
        //     }
        //     cout << endl;
        // }

        int res = 1e9;

        for (int i = 0; i < 4; i++)
        {
            res = min(res, dp[H - 1][W - 1][i]);
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 3272
// Author -- Frame

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-(x)))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())
#define mkpr std::make_pair
#define pb push_back

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef std::pair<int,int> pi;
typedef std::pair<ll,ll> pl;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x3f3f3f3f3f3f3f3f;

Finline uint rnd()
{
	static uint seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline void read(_Tp &x)
{
	char ch(getchar());
	bool f(false);
	while(ch<48||ch>57) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();
	while(ch>=48&&ch<=57) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	if(f) x=-x;
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args){read(t);read(args...);}
template <typename _Tp,typename... Args>Finline _Tp min(const _Tp &a,const _Tp &b,const Args &...args){return a<b?min(a,args...):min(b,args...);}
template <typename _Tp,typename... Args>Finline _Tp max(const _Tp &a,const _Tp &b,const Args &...args){return a<b?max(b,args...):max(a,args...);}
Finline int read_str(char *s)
{
	char ch(getchar());
	while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	char *tar=s;
	*tar=ch,ch=getchar();
	while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=2005;
const int mod=924844033;
template<typename _Tp1,typename _Tp2>Finline void add(_Tp1 &a,_Tp2 b){(a+=b)>=mod&&(a-=mod);}
template<typename _Tp1,typename _Tp2>Finline void sub(_Tp1 &a,_Tp2 b){(a-=b)<0&&(a+=mod);}
int dp[N+N][N][2];
bool type[N+N],mark[N+N];
ll fac[N];
int main()
{
	fac[0]=1;
	for(int i=1;i<N;++i) fac[i]=fac[i-1]*i%mod;
	int n,k;read(n,k);
	int pos=0;
	auto upd=[&](int i,int j)
	{
		if(!mark[i])
		{
			int cur=i;
			for(;((j&1)?cur-n:cur)<=n;++j)
			{
				mark[cur]=true;
				type[++pos]=cur!=i;
				cur+=k;
				if(j&1) cur-=n;
				else cur+=n;
			}
		}
	};
	for(int i=1;i<=n;++i) upd(i,0),upd(i+n,1);
	dp[0][0][0]=1;
	for(int i=0;i<n+n;++i)
	{
		for(int j=0;j<=(i+1)>>1;++j)
		{
			add(dp[i+1][j][0],dp[i][j][0]),add(dp[i+1][j][0],dp[i][j][1]);
			if(type[i+1]) add(dp[i+1][j+1][1],dp[i][j][0]);
		}
	}
	ll ans=0;
	for(int i=0;i<=n;++i)
	{
		if(i&1) sub(ans,fac[n-i]*(dp[n+n][i][0]+dp[n+n][i][1])%mod);
		else add(ans,fac[n-i]*(dp[n+n][i][0]+dp[n+n][i][1])%mod);
	}
	printf("%lld\n",ans);
	return 0;
}


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

const int INF = 1 << 28;

int N;
int t[16][17];
int dp[1 << 16];

int main(void){
	while (cin >> N && N) {
		for (int i = 0; i < N; i++)
			for (int j = 0; j < N + 1; j++){
				cin >> t[i][j];
			}

		for (int i = 0; i < (1 << N); i++) dp[i] = INF;
		dp[0] = 0;
		for (int b = 0; b < (1 << N);b++) {
			for (int i = 0; i < N;i++) {

				if (b & 1 << i) continue;

				int cost = t[i][0];

				for (int j = 0; j < N; j++){

					if (!(b & 1 << j) && i != j)
						cost = min(cost, t[i][j + 1]);

				}

				int no = b | 1 << i;
				dp[no] = min(dp[no], dp[b] + cost);
			}
		}
		cout << dp[(1 << N) - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1420
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N, x;
  cin >> N >> x;
  vector<long> A(N);
  rep (i, N) cin >> A[i];

  long ans = 0;
  rep (i, N-1) {
    long tmp = A[i] + A[i+1];
    if (tmp <= x) continue;
    long aaa = tmp - x;
    ans += aaa;
    A[i+1] = max(0l, A[i+1] - aaa);
  }

  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 1024
n,k = map(int,input().split())
gcds = []


def power_func(a,n,p):
    bi=str(format(n,"b"))#2進表現に
    res=1
    for i in range(len(bi)):
        res=(res*res) %p
        if bi[i]=="1":
            res=(res*a) %p
    return res

mod = 10**9+7
for i in range(k):
    div = k//(k-i)
    count = power_func(div,n, mod)
    for j in range(1,div):
        count = count - gcds[k-((k-i)*(j+1))]
    gcds.append(count)

total = 0

for i in range(k):
    total = (total + (gcds[i]*(k-i)%mod))%mod
print(total)

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

void Main()
{
    unsigned long a;
    string b;
    cin >> a >> b;
    unsigned long bb[3];
    bb[0] = b[0] - '0';
    bb[1] = b[2] - '0';
    bb[2] = b[3] - '0';
    
    unsigned long x = a * bb[0] + (a * bb[1] + a * bb[2] / 10 ) / 10;
    cout << x << endl;
}

int main(int argc, char **argv)
{
    Main();
    return 0;
}


Measured memory_bytes: 3632
from collections import Counter

N = int(input())
S = str(input())
all_dict = {'R' : 0, 'B' : 0}

for i in range(N):
  s = S[i]
  all_dict[s] += 1

if all_dict['R'] > all_dict['B']:
  print('Yes')
else:
  print('No')


  

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
//#define int long long
const int MOD = 1e9 + 7;
using ll = long long;
using intpair = pair<int, int>;
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((ll)((a) + (b) - 1)/(ll)(b))

vector<set<int>> graph;

signed main() {
    int n, m;
    cin >> n >> m;
    
    graph = vector<set<int>>(n);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].insert(b);
        graph[b].insert(a);
    }
    
    queue<int> q;
    vector<bool> visited(n, false);
    vector<int> next(n, -1);
    q.push(0);
    visited[0] = true;
    while(!q.empty()){
        int now = q.front();
        q.pop();
        for(int to : graph[now]) {
            if(visited[to]) continue;
            visited[to] = true;
            if(next[to] == -1) next[to] = now + 1;
            q.push(to);
        }
    }
    
    cout << "Yes" << endl;
    reps(i,1,n-1){
        cout << next[i] << endl;
    }
}

Measured memory_bytes: 27464
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define LAST(i,n) if(i==n-1)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"

typedef long lint;
typedef pair<lint, lint> P;

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

    vector<lint> A;

    REP(i,N) {
      lint n; cin >> n;A.push_back(n-i-1);
    }

    SORT(A);

    lint b;

    if(N%2 == 0) {
      b = (A[N/2]+A[N/2-1])/2;
    }
    else {
      b = A[N/2];
    }

    lint res = 0;
    REP(i,N) {
      res += abs(A[i] - b);
    }

    PRINT(res);
    return 0;
}


Measured memory_bytes: 2420
#include<iostream>
using namespace std;
int main()
{
	int c,sum = 0;
	cin >> c;
	sum += c*1;
	cin >> c;
	sum += c*5;
	cin >> c;
	sum += c*10;
	cin >> c;
	sum += c*50;
	cin >> c;
	sum += c*100;
	cin >> c;
	sum += c*500;
	if(sum >= 1000){
		cout << "1\n";
	}else{
		cout << "0\n";
	}
	return 0;
}

Measured memory_bytes: 1124
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
using lint = long long;
using ppi = pair<int, int>;
const int MAXN = 200005;
const int INF = 10e8; 
typedef long long ll;

#define PI 3.14159265358979311600

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  float n;
  cin >> n;
  cout << fixed << setprecision(20);
  cout << PI * n* 2;
//  cout << 6.28318530717958623200/2;
   
  return 0;
}

/*
         ,--"""",--.__,---[],-------._         
       ,"   __,'            \         \--""""""==;-
     ," _,-"  "/---.___     \       ___\   ,-'',"
    /,-'      / ;. ,.--'-.__\  _,-"" ,| `,'   /
   /``""""-._/,-|:\       []\,' ```-/:;-. `. /
             `  ;:::      ||       /:,;  `-.\
                =.,'__,---||-.____',.=
                =(:\_     ||__    ):)=
               ,"::::`----||::`--':::"._
             ,':::::::::::||::::::::::::'.
    .__     ;:::.-.:::::__||___:::::.-.:::\     __,
       """-;:::( O )::::>_|| _<::::( O )::::-"""
   =======;:::::`-`:::::::||':::::::`-`:::::\=======
    ,--"";:::_____________||______________::::""----.          , ,
         ; ::`._(    |    |||     |   )_,'::::\_,,,,,,,,,,____/,'_,
       ,;    :::`--._|____[]|_____|_.-'::::::::::::::::::::::::);_
      ;/ /      :::::::::,||,:::::::::::::::::::::::::::::::::::/
     /; ``''''----------/,'/,__,,,,,____:::::::::::::::::::::,"
     ;/                :);/|_;| ,--.. . ```-.:::::::::::::_,"
    /;                :::):__,'//""\\. ,--.. \:::,:::::_,"
   ;/              :::::/ . . . . . . //""\\. \::":__,"
   ;/          :::::::,' . . . . . . . . . . .:`::\
   ';      :::::::__,'. ,--.. . .,--. . . . . .:`::`
   ';   __,..--'''-. . //""\\. .//""\\ . ,--.. :`:::`
   ;    /  \\ .//""\\ . . . . . . . . . //""\\. :`::`
   ;   /       . . . . . . . . . . . . . . . . .:`::`
   ;   (          . . . . . . . . . . . . . . . ;:::`
   ,:  ;,            . . . . . . . . . . . . . ;':::`
   ,:  ;,             . . . . . . . . . . . . .;`:::
   ,:   ;,             . . . . . . . . . . . . ;`::;`
    ,:  ;             . . . . . . . . . . . . ;':::;`
     :   ;             . . . . . . . . . . . ,':::;
      :   '.          . . . . . . . .. . . .,':::;`
       :    `.       . . . . . . . . . . . ;::::;`
        '.    `-.   . . . . . . . . . . ,-'::::;
          `:_    ``--..___________..--'':::::;'`
             `._::,.:,.:,:_ctr_:,:,.::,.:_;'`
________________`"\/"\/\/'""""`\/"\/""\/"____________________________
 
*/


Measured memory_bytes: 3804
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    int N;


    void solve()
    {
        N = cin.nextint;
        var s1 = "";
        var s2 = "";
        var x = new[] { '.', '#', '.', '#' };
        var y = new[] { '.', '.', '#', '#' };
        bool flag = true;

        for (int i = 0; i < N; i++)
        {
            if (flag)
            {
                flag = false;
                for (int r = 0; r < 4; r++)
                {
                    WriteLine(s1 + x[r]);
                    WriteLine(s2 + y[r]);
                    var c = ReadLine();
                    if (c == "end") return;
                    if (c == "T")
                    {
                        flag = true;
                        s1 += x[r];
                        s2 += y[r];
                        break;
                    }
                }
            }
            if (flag) continue;

            for (int r = 0; r < 4; r++)
            {
                WriteLine(x[r] + s1);
                WriteLine(y[r] + s2);
                var c = ReadLine();
                if (c == "end") return;
                if (c == "T")
                {
                    s1 = x[r] + s1;
                    s2 = y[r] + s2;
                    break;
                }
            }
        }
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13480
import Control.Monad

main = do
 n   <- read <$> getLine :: IO Int
 ans <- replicateM n getLine :: IO [String]
 putStrLn $ "AC x "++ show (length $ filter (=="AC") ans)
 putStrLn $ "WA x "++ show (length $ filter (=="WA") ans) 
 putStrLn $ "TLE x "++ show (length $ filter (=="TLE") ans) 
 putStr $ "RE x "++ show (length $ filter (=="RE") ans)  

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

#define vec              vector<int>
#define vecll            vector<ll>
#define vecd             vector<double>
#define vecst            vector<string>
#define vecb             vector<bool>
#define v2(v,n,m,init)   vector<vector<int>>  v(n, vector<int>(m, init))
#define vb2(v,n,m,init)  vector<vector<bool>> v(n, vector<bool>(m, init))
#define vll2(v,n,m,init) vector<vector<ll>>   v(n, vector<ll>(m, init))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
template <typename T>
bool chmax(T &a, const T& b){if(a<b){a=b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a>b){a=b; return true;} return false;}
//----------------------------------------------------------------

int main(void) {
  string s, t;
  cin >> s >> t;

  int ans=1e9;
  int n=s.size();
  int m=t.size();
  rep(i,n-m+1){
    int tmp=0;
    rep(j,m){
      if(s[i+j]!=t[j]) tmp++;
    }
    chmin(ans, tmp);
  }
  prt(ans);
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);
ll fac(ll x){if(x==0) return 1;  return x*fac(x-1);}

int main(){
    ll n,k; cin>>n>>k;
    if(n%k==0) cout<<0<<endl;
    else cout<<1<<endl;
}

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

int main() {
    int n, tmp, ans = 0, sum = 0;
    const int MAX_NUM = 100010;
    int b[MAX_NUM] = {};
    cin >> n;
    rep(i, n) {
        cin >> tmp;
        b[tmp]++;
        ans++;
    }
    rep(i, MAX_NUM) {
        if(b[i] > 1) {
            sum += b[i] - 1;
        }
    }
    ans -= sum;
    if(sum % 2 != 0) {
        ans--;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
// ABC161B.cpp
//#include "pch.h"
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <numeric> // accumulate
using namespace std;
int main()
{
	int N, M;
	cin >> N >> M;
	vector<int>A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A.at(i);
	}
	sort(A.begin(), A.end(), greater<int>());
	int sum = accumulate(A.begin(), A.end(), 0);
	if (A.at(M - 1)*(4*M) >=sum)
	{
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;

int dp[3001][3001];
int pre[3001][3001];
string a,b;
void lcs_fill(){
    for(int i=0;i<a.size();i++){
        for(int j=0;j<b.size();j++){
            if(a[i]==b[j]){
                dp[i+1][j+1]=dp[i][j]+1;
            }
            else{
                dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
            }
        }
    }
}
void lcs_preserve(){
    for(int i=0;i<a.size();i++){
        for(int j=0;j<b.size();j++){
            if(a[i]==b[j]){
                dp[i+1][j+1]=dp[i][j]+1;
                pre[i+1][j+1]=0;
            }
            else if(dp[i][j+1]>dp[i+1][j]){
                dp[i+1][j+1]=dp[i][j+1];
                pre[i+1][j+1]=2;//from i
            }
            else{
                dp[i+1][j+1]=dp[i+1][j];
                pre[i+1][j+1]=1;//from j
            }
        }
    }
}

string lcs_restore(){
    string ans;
    int q=a.size(),w=b.size();
    while(q>0&&w>0){
        if(pre[q][w]==0){
            ans.push_back(a[q-1]);q--;w--;
        }
        else if(pre[q][w]==2){
            q--;
        }
        else{
            w--;
        }
    }
    reverse(ans.begin(),ans.end());
    return ans;
}


int main(){
    cin>>a>>b;
    lcs_preserve();
    string ans=lcs_restore();
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 70656
from scipy.special import comb

mod = 10**9 + 7
ans = 0
S = int(input())
j = 1
while True:
  if S >= 3 * j:
    ans = (ans + comb(S-3*j+j-1, j-1, exact=True)) % mod
    j += 1
  else:
    break
print(ans)

Measured memory_bytes: 42396
s = input()
k = int(input())

subs = set()

for i in range(len(s)):
  for j in range(i+1, min(5+i+1, len(s)+1)):

    subs.add(s[i:j])
subs = list(subs) 
subs.sort()
print(subs[k-1])

Measured memory_bytes: 4464
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{

static string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
static int n = int.Parse(input[0]);//頂点数
static int m = int.Parse(input[1]);//辺数
static int[,] path = new int[n,n];//隣接行列
static int answer = 0;

	static void Main()
	{
    for(int i = 0; i < m; i++)//隣接行列の完成
    {
    int[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);
    path[nums[0]-1, nums[1]-1]++;
    path[nums[1]-1, nums[0]-1]++;
    }

    List<int> numListOriginal = Enumerable.Range(1,n-1).ToList();//順列
    List<int> numListFinal = new List<int>(){0};
    Permutation(numListOriginal, numListFinal);//順列の生成
    
	Console.WriteLine(answer);
	}

  static void Permutation(List<int> numListOriginal, List<int> numListFinal)//順列の生成
  {
    for(int i = 0; i < numListOriginal.Count(); i++)
    {
      int x = numListOriginal[i];//移動する要素
      numListFinal.Add(x);
      numListOriginal.RemoveAt(i);
      
      if(numListOriginal.Count() > 0) Permutation(numListOriginal, numListFinal);
      else CheckPath(numListFinal);
      
      numListOriginal.Insert(i, x);//listOriginalに戻す
      numListFinal.RemoveAt(numListFinal.Count()-1);
    }
  }

  static void CheckPath(List<int> numListFinal)
  {
    for(int i = 0; i < numListFinal.Count()-1; i++)
    {
      if(path[numListFinal[i],numListFinal[i+1]] == 0) break;//辺でつながっていない時
      if(i == numListFinal.Count()-2) answer++;
    }
  
  }
  
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
//#include <unordered_map>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a-1); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll re=1;
	while(b)
	{
		if(b%2==1)
		{
			re=(re*a);
			re%=mod;
		}
		a=(a*a);
		a%=mod;
		b>>=1;
	}
	return re;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		string s,t;
		cin>>s>>t;
		int n=s.size(),m=t.size();
		int sc[n]={0},tc[m]={0};
		if(s[0]=='A')
		sc[0]=1;
		else
		sc[0]=-1;
		FOR(i,1,n)
		{
			if(s[i]=='A')
			sc[i]=sc[i-1]+1;
			else
			sc[i]=sc[i-1]-1;
		}
		if(t[0]=='A')
		tc[0]=1;
		else
		tc[0]=-1;
		FOR(i,1,m)
		{
			if(t[i]=='A')
			tc[i]=tc[i-1]+1;
			else
			tc[i]=tc[i-1]-1;
		}
		int q;
		cin>>q;
		int a,b,c,d,sd,td;
		FOR(i,0,q)
		{
			cin>>a>>b>>c>>d;
			sd=(sc[b-1]-(a==1?0:sc[a-2])+600000)%3;
			td=(tc[d-1]-(c==1?0:tc[c-2])+600000)%3;
			if(sd==td)
			cout<<"YES\n";
			else
			cout<<"NO\n";
		}
	}
	return 0;
}


Measured memory_bytes: 1744
import sys
input = sys.stdin.readline
N, = map(int, input().split())
rs = []
for _ in range(N):
    A, = map(int, input().split())
    ts, fs = set(), set()
    for _ in range(A):
        x, y = map(int, input().split())
        if y:
            ts.add(x-1)
        else:
            fs.add(x-1)
    rs.append((ts, fs))
r = 0
for i in range(2**N):
    ok = True
    c = 0
    for j in range(N):
        if (i>>j) % 2:
            for t in rs[j][0]:
                if not (i>>t) % 2:
                    ok = False
            for t in rs[j][1]:
                if (i>>t) % 2:
                    ok = False
            c += 1
    if ok:
        r = max(r, c)
print(r)


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

int main(void) {
    int N;cin>>N;
    vector<int> vc(N);
    int sum = 0;
    for (int i = 0; i < N; i++) {
        cin>>vc[i];
    }
    sort(vc.begin(), vc.end());
    for (int i = 0; i < N - 1; i++) {
        sum += vc[i];
    }
    sum += vc[N - 1] / 2;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
n, m, x = map(int, input().split())
A = list(map(int, input().split()))
start = 0
end = 0
for i in range(x):
    if i in A:
        start += 1

for i in range(x,n+1):
    if i in A:
        end += 1

print(min(start, end))

Measured memory_bytes: 9048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N;
  cin >> N;
  vector<long long>A(N+1);
  for(int i=0;i<N+1;i++){
    cin >> A.at(i);
  }
  long long sum;
  for(int i=0;i<N;i++){
    long long B;
    cin >> B;
    sum+=min(A.at(i),B);
    B-=A.at(i);
    if(B>0){
      sum+=min(B,A.at(i+1));
      A.at(i+1)-=B;
      if(A.at(i+1)<0){
        A.at(i+1)=0;
      }
    }
  }
  cout << sum;
}

Measured memory_bytes: 1024
import math
while True:
  n = int(input())
  if n ==0:
    break
  else:
    a=[]
    s = list(map(int,input().split()))
    mean = sum(s)/n
    for i in s:
      a.append("{0:.8f}".format(((i-mean)**2)/n))
    print(("{0:.8f}".format(math.sqrt(sum([float(i) for i in a])))))


Measured memory_bytes: 5780
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    sort(a.begin(),a.end());
    cout << a[n/2] - a[n/2-1] << endl;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
	int cnt = 0;
	int n;

	cin >> n;

	unsigned char *a = new unsigned char[n + 1];
	unsigned char *b = new unsigned char[n + 1];
	unsigned char *c = new unsigned char[n + 1];
	cin >> a;
	cin >> b;
	cin >> c;
	
	for (int i = 0; i < n; i++) {
		if (a[i] != b[i] && b[i] != c[i] && c[i] != a[i]) {
			cnt += 2;
		}
		else if (a[i] != b[i] || b[i] != c[i] || c[i] != a[i]) {
			cnt += 1;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'              
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 314159

signed main() 
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
	int n;
	int ans=0;
	cin>>n;
	forn(i,1,n)
	{
	    int a;
	    cin>>a;
	    ans=__gcd(ans,a);
	}
     
    cout<<ans;



     return 0;

}

//       g++ -g c.cpp ; ./a.exe

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

using namespace std;

int main()
{
    char s[100005];
    int n;
    bool found = false;

    cin >> s;
    n = strlen(s);

    if(n == 2 && s[0] == s[1])
        printf("1 2\n");
    else
    {
        for(int i=0; i<n-2; i++)
        {
            if(s[i] == s[i+1] || s[i+1] == s[i+2] || s[i] == s[i+2])
            {
                found = true;
                printf("%d %d\n", i+1, i+3);
                break;
            }
        }
        if(found == false)
            printf("-1 -1\n");
    }
    return 0;
}


Measured memory_bytes: 384