akhauriyash/Code-Regression huggingface dataset:
#D
from collections import deque
Str = str(input())
Q = int(input())
S = deque(list(Str))
#S.append(list(Str))
#上の方法ではダメ
A = 0
B = []
C = []

for i in range(Q):
    a = list(map(str, input().split()))
    if a[0] == '1':
        if A%2==0:
            if len(B)>1:
                S.extendleft(B)
                B = []
            elif len(B) == 1:
                S.extendleft(B)
                B = []
            if len(C) > 0:
                S.extend(C)
                C = []
        else:
            if len(C)>1:
                S.extendleft(C)
                C = []
            elif len(C) == 1:
                S.extendleft(C)
                C = []
            if len(B) > 0:
                S.extend(B)
                B = []
        A += 1
    elif a[1] == '1':
        B.append(a[2])
    else:
        C.append(a[2])

if a[0] != '1':
    if A%2==0:
        if len(B)>1:
            S.extendleft(B)
            B = []
        elif len(B) == 1:
            S.extendleft(B)
            B = []
        if len(C) > 0:
            S.extend(C)
            C = []
    else:
        if len(C)>1:
            S.extendleft(C)
            C = []
        elif len(C) == 1:
            S.extendleft(C)
            C = []
        if len(B) > 0:
            S.extend(B)
            B = []

if A%2 != 0:
    S.reverse()
print(''.join(S))


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

int array[500000];
int n;

void maxheapify(int i){
	int left=(i+1)*2-1;
	int right=(i+1)*2;
	int largest=i;
	if(left<n&&array[largest]<array[left])	largest=left;
	if(right<n&&array[largest]<array[right])	largest=right;
	if(largest!=i){
		swap(array[largest],array[i]);
		maxheapify(largest);
	}
}

int main(int argc, char const *argv[]){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>array[i];
	}
	for(int i=n/2;i>=0;i--){
		maxheapify(i);
	}
	for(int i=0;i<n;i++){
		cout<<" "<<array[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>

using namespace std;

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

    int flag = 0;

    if(s[0] == s[1] && s[2] == s[3])    flag++;
    if(s[0] == s[2] && s[1] == s[3])    flag++;
    if(s[0] == s[3] && s[1] == s[2])    flag++;

    if(flag == 1)   cout << "Yes" << endl;
    else            cout << "No" << endl;

    return 0;
}

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

int main()
{
    int w,h,x,y,r;
    cin>>w>>h>>x>>y>>r;
    if(x>=r&&y>=r&&x<=w-r&&y<=h-r){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
char S[N],T[N];
int n,m,x,y,d;

int gcd(int x,int y)
{
	return y==0?x:gcd(y,x%y);	
}
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%s%s",S+1,T+1);
	d=gcd(n,m);
	x=n/d; y=m/d;
	for (int i=1,j=1;i<=n && j<=m;i+=x,j+=y)
		if (S[i]!=T[j]) {puts("-1"); return 0;} 
	printf("%lld\n",(long long)n*m/d);
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(){

  int n,i,j,Rt[200000],max=-1000000000;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&Rt[i]);
  }
int min=Rt[0];
	for(i=1;i<n;i++){
		if(max<Rt[i]-min){
      max=Rt[i]-min;
    }
    if(min>Rt[i]){
      min=Rt[i];
    }
    
  }
  printf("%d\n",max);
  return 0;
}

Measured memory_bytes: 1376
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <stdio.h>

using namespace std;

#define fo(i,n) for(int i=0; i<(int)n; i++)
#define rep(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#define mp(a,b) make_pair(a,b)
#define pb(x) push_back(x)
#define pii pair<int,int>

int n,m;
string s;
string v[13];
bool dp[5010][1<<12];
bool is[5010][12];

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

	while (scanf("%d%d",&n,&m) && n!=0) {
		for (int i=0; i<n; i++) cin>>v[i];
		s = "";
		for (int i=0; i<m; i++) {
			string str;
			cin>>str;
			s += str;
		}
		for (int i=0; i<=s.length(); i++) {
			for (int k=0; k<(1<<n); k++) dp[i][k] = 0;
		}
		for (int i=0; i<s.length(); i++) {
			for (int k=0; k<n; k++) is[i][k] = 0;
			for (int k=0; k<n; k++) if (i+v[k].length()<=s.length()) {
				if (s.substr(i,v[k].length())==v[k]) {
					is[i][k] = 1;
				}
			}
		}

		int ans = 0;
		for (int i=0; i<s.length(); i++) dp[i][0] = 1;
		for (int i=0; i<s.length(); i++) {
			for (int k=0; k<(1<<n); k++) if (dp[i][k]) {
				for (int j=0; j<n; j++) {
					if (i+v[j].length()<=s.length() && is[i][j] && (k&(1<<j))==0) {
						dp[i+v[j].length()][k+(1<<j)] = 1;
					}
				}
			}
			if (dp[i][(1<<n)-1]) ans++;
		}
		if (dp[s.length()][(1<<n)-1]) ans++;
		
		printf("%d\n",ans);
	}

    return 0;

}

Measured memory_bytes: 21332
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
#define fo(i,x,y) for(register int i=x;i<=y;++i)
#define go(i,x,y) for(register int i=x;i>=y;--i)
using namespace std;

inline int read(){
	int x=0,fh=1;
	char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') fh=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		x=(x<<1)+(x<<3)+ch-'0';
		ch=getchar();
	}
	return x*fh;
}

void work(){
	
	//puts("");
}
int main(){
	int x=read(),y=read();
	fo(i,0,x){
		int tot=i*2+(x-i)*4;
		if(tot==y){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}

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

#define rep(i, s, n) for (Int i = s; i < (Int)(n); i++)
#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
double EPS = 1e-10;
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int a, b;
    cin >> a >> b;
    Int res = 0;
    while (a <= b) {
        res++;
        a *= 2;
    }
    dump(res);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  while (1) {
    int N, M, P;
    scanf("%d %d %d", &N, &M, &P);
    if (N == 0 && M == 0 && P == 0) break;
    int X[100];
    int sum = 0;
    for (int i = 0; i < N; i++) {
      scanf("%d", &X[i]);
      sum += X[i] * 100;
    }
    sum = sum * (100 - P) / 100;
    printf("%d\n", X[M - 1] == 0 ? 0 : sum / X[M - 1]);
  }
}



Measured memory_bytes: 2048
import sys

sys.setrecursionlimit(10**6)

X,Y = map(int,input().split())

mod = int(10**9 + 7)

res = 0

if (X + Y) % 3 != 0:
    print(res)
    sys.exit()

N = 0
M = 0
if X <= Y:
    N += X
    M += Y
else:
    N += Y
    M += X

f = [1]
for i in range(N):
    f.append(f[i]*(i+1)%mod)

def comb(A,B,mod):
    if A >= B:
        temp = f[A] * pow(f[B],mod-2,mod) * pow(f[A-B],mod-2,mod) % mod
    else:
        temp = f[B] * pow(f[A],mod-2,mod) * pow(f[B-A],mod-2,mod) % mod
    return temp

def perm(A,B,mod):
    return f[A+B] * pow(f[A],mod-2,mod) * pow(f[B],mod-2,mod) % mod

for i in range(N):
    role1 = i + 1
    role2 = int((N - role1) / 2)
    roles = role1 + role2
    temp1 = role1 + role2 * 2
    temp2 = role1 * 2 + role2
    if (temp1 == N) & (temp2 == M):
        res += perm(role1,role2,mod)

    res %= mod




print(res)


Measured memory_bytes: 42668
#include<bits/stdc++.h>
using namespace std;
#define PI          acos(-1)
#define INF         0x3f3f3f3f
#define sc(n)       scanf("%d",&n);
#define lsc(n)      scanf("%lld",&n);
#define dsc(n)      scanf("%lf",&n);
#define LL          long long int
#define UI          unsigned int
#define ULL         unsigned long long int
#define DB          double
#define pii         pair<int,int>
#define PB          push_back
#define MP          make_pair
#define M(mx,a)     mx=max(mx,a)
#define IT          ::iterator
#define all(a)      a.begin(),a.end()
#define mems(a,b)   memset(a,b,sizeof(a))
#define ARC(n)      for(i=0;i<n;i++)
#define ASC(n,aa)   for(i=0;i<n;i++)scanf("%lld",&aa[i]);
#define PNT(n,aa)   for(i=0;i<n;i++)printf("%lld ",aa[i]);
#define mod         1000000007
#define NUM         100050
#define NUM2        1000000000



int main()
{
    int T=1,QQ=0;
    //cin >> T ;
    while(T--)
    {
        int n,i,j;
        cin >> n ;
        int aa[n] ;
        for(i=0;i<n;i++)sc(aa[i]);
        sort(aa,aa+n);
        cout << aa[n/2]-aa[n/2-1] ;
    }
}
//printf("Case %d: ",++QQ);


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int A,B;
  cin >> A >> B;
  char a[110][110];

  for(int i=0;i<100;i++){
    for(int j=0;j<100;j++){
      if(i<50)a[i][j]='.';
      else if(i>=50)a[i][j]='#';
    }
  }

  int cnt=0;
  bool flag=false;
  for(int i=0;i<49;i+=2){
    for(int j=0;j<100;j+=2){
      if(cnt==B-1)flag=true;
      if(flag)break;
      a[i][j]='#';
      cnt++;

      /*if(i%2==0 && j%2==1){
        a[i][j]='#';
        cnt++;
      }else if(i%2==1 && j%2==0){
        a[i][j]='#';
        cnt++;
      }*/
    }
    if(flag)break;
  }

  cnt=0;
  flag=false;
  for(int i=51;i<100;i+=2){
    for(int j=0;j<100;j+=2){
      if(cnt==A-1)flag=true;
      if(flag)break;
      a[i][j]='.';
      cnt++;

      /*if(i%2==0 && j%2==0){
        a[i][j]='.';
        cnt++;
      }else if(i%2==1 && j%2==1){
        a[i][j]='.';
        cnt++;
      }*/
    }
    if(flag)break;
  }
  cout << 100 << " " << 100 << endl;
  for(int i=0;i<100;i++){
    for(int j=0;j<100;j++){
      cout << a[i][j];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    N, M = list(map(int, input().split()))

    if N == 1 and M == 1:
        print(1)
    elif N == 1:
        print(M - 2)
    elif M == 1:
        print(N - 2)
    else:
        print((N - 2) * (M - 2))


Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int P = sc.nextInt();
		int Q = sc.nextInt();
		int R = sc.nextInt();
		sc.close();
		int pq = P + Q;
		int pr = P + R;
		int qr = Q + R;
		System.out.println(Math.min(pq, Math.min(pr, qr)));
	}
}


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

using namespace std;

using intL = long long;

#define MOD_NUMBER 1000000007

template <class T> void vector_print(vector<T> vec) {
  for (unsigned int i = 0; i < vec.size(); i++) {
    cout << vec.at(i);
    if (i < vec.size()-1) {
      cout << " ";
    } else if (i == vec.size()-1) {
      cout << endl;
    }
  }
}

int main() {
  int n, k, q, t;
  cin >> n >> k >> q;
  vector<int> a(n, k-q);
  for (int i = 0; i < q; i++) {
    cin >> t;
    a[t-1]++;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>//solved by *ALIKHAN*
#define ll long long
#define ld long double
#define pb push_back
#define sz(x) (int)x.size()
#define F first
#define S second
#define ppb pop_back
#define mp make_pair
#define all(n) n.begin(), n.end()
#define timefaster ios_base::sync_with_stdio(0);cin.tie(0)

using namespace std;

const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18;

int main(){
	timefaster;
	int n , m;
	cin >> n >> m;
	n *= 3;
	cout << (n + m)/2;

}// Aksay sila

Measured memory_bytes: 256
import Data.List
import Data.Maybe

main = do
    n <- readLn
    p <- map read . words <$> getLine
    q <- map read . words <$> getLine
    let sorted_permutations = sort $ permutations [1 .. n]
    let index_p = elemIndex p sorted_permutations
    let index_q = elemIndex q sorted_permutations
    print $ abs $ fromJust index_q - fromJust index_p

Measured memory_bytes: 21884
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

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

	void solve(Scanner sc) {
		int[] ia = new int[5];
		ia[0] = sc.nextInt();
		ia[1] = sc.nextInt();
		ia[2] = sc.nextInt();
		ia[3] = sc.nextInt();
		ia[4] = sc.nextInt();
		int k = sc.nextInt();

		Arrays.sort(ia);


		if (ia[4] - ia[0] > k) {
			System.out.println(":(");
		} else {
			System.out.println("Yay!");
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  vector<ll>A(N),sum(N+1);
  for(int i=0;i<N;i++){
    cin>>A[i];
    sum[i+1]=sum[i]+A[i];
  }
  ll ans=INFLL;
  ll a,b,c,d;
  int left=0, right=2;
  for(int i=1;i<N-1;i++){
    while(left<=i-1 && (sum[i+1]-sum[left+1]>=sum[left+1])){
      left++;
    }
    if(abs(2*sum[left]-sum[i+1])<abs(2*sum[left+1]-sum[i+1])){
      a=sum[left];
      b=sum[i+1]-sum[left];
      left--;
    }else{
      a=sum[left+1];
      b=sum[i+1]-sum[left+1];
    }

    while(right<=N-2 && (sum[N]-sum[right+1]>=sum[right+1]-sum[i+1])){
      right++;
    }

    if(abs(sum[N]+sum[i+1]-2*sum[right])<abs(sum[N]+sum[i+1]-2*sum[right+1])){
      c=sum[right]-sum[i+1];
      d=sum[N]-sum[right];
      right--;
    }else{
      c=sum[right+1]-sum[i+1];
      d=sum[N]-sum[right+1];
    }
    ans=min(ans,max({a,b,c,d})-min({a,b,c,d}));
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3456
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

X = read()
ans = next(n for n in count(0) if n * (n+1) // 2 >= X)
print(ans)

Measured memory_bytes: 39280
#include <stdio.h>

int main(void){
  int i,j,n,u,k,v;

  scanf("%d", &n);

  int g[n+2][n+2];
  for(i = 0; i < n+2; i++)
    for(j = 0; j < n+2; j++)
      g[i][j] = 0;
    

  for(i = 1; i <= n; i++){
    scanf("%d%d", &u, &k);
    for(j = 1; j <= k; j++){
      scanf("%d", &v);
      g[u][v] = 1;
    }
  }

  for(i = 1; i < n+1; i++){
    for(j = 1; j < n; j++){
      printf("%d ", g[i][j]);
    }
    printf("%d\n", g[i][j]);
  }
      
  return 0;
}

Measured memory_bytes: 636
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define fast ios_base::sync_with_stdio(false)
typedef long long ll;
typedef pair<ll,ll> p;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
ll k,x;
cin>>k>>x;
if(k*500>=x)
{
    cout<<"Yes"<<endl;
}else
{
    cout<<"No"<<endl;
}
return 0;
}

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

int main()
{
    string S;
    cin >> S;
    if (S <= "2019/04/30") {
        cout << "Heisei" << endl;
    } else {
        cout << "TBD" << endl;
    }
    return 0;
}


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

int main() {
  int64_t a, b, c, d, e;
  cin >> a >> b >> c;
  d = 4*a*b;
  e = (c-a-b);
  
  if ( e <= 0 ) {
    cout << "No";
  }
  else if ( d < e*e ) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }
}

Measured memory_bytes: 256
#import<atcoder/all>
#define f(i)std::cout<<i<<' ';
int n,a;int main(){std::cin>>n>>a;atcoder::scc_graph g(n);for(;std::cin>>n>>a;)g.add_edge(n,a);auto v=g.scc();f(size(v))for(auto i:v){f(size(i))for(auto j:i)f(j)}}

Measured memory_bytes: 40092
def primefact(n):
    l=[]
    if n%2==0:
        while n%2==0:
            n=n//2
        l.append(2)
    for i in range(3,int(n**0.5)+1,2):
        if n%i==0:
            while n%i==0:
                n=n//i
            l.append(i)
    if n>2:
        l.append(n)
    return l

n=int(input())
c=0
a=(primefact(n))
for i in a:
    x=i
    while n%x==0:
        n=n//x
        c+=1
        x=x*i
print(c)
        

Measured memory_bytes: 9420
#include<stdio.h>
int main(){
  long long d[21][100]={0};
  int n,m,i,j;
  scanf("%d %d",&n,&m);
  d[m][0]=1;
  for(j=1;j<n-1;j++){
    scanf("%d",&m);
    for(i=0;i<21;i++){
      if(d[i][j-1]==0)continue;
      if(i-m>-1)d[i-m][j]+=d[i][j-1];
      if(i+m<21)d[i+m][j]+=d[i][j-1];
    }
    //for(i=0;i<21;i++)printf("%d:%lld ",i,d[i][j]);printf("\n");
  }
  scanf("%d",&m);
  printf("%lld\n",d[m][n-2]);
  return 0;
}

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

using u32 = uint32_t;
using u64 = uint64_t;
using i32 = int32_t;
using i64 = int64_t;

int main()
{
	std::ios_base::sync_with_stdio(0);
	
	u32 n;

	std::cin >> n;

	std::vector<u32> v;
	v.reserve(n);

	for(u32 i=0; i<n; i++)
	{
		u32 x;
		std::cin >> x;
		v.push_back(x);
	}

	u64 sum = 0;

	for(u32 i=0; i<n; i++)
	{
		for(u32 j=i+1; j<n; j++)
		{
			if(j==i) continue;
			sum += v[i] * v[j];
		}
	}

	std::cout << sum << "\n";
	
	return 0;
}

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

namespace AtTest.ABC_113
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] hwk = ReadInts();
            int h = hwk[0];
            int w = hwk[1];
            int k = hwk[2] - 1;
            long mask = 1000000000 + 7;
            var rowPats = new long[6] { 2, 3, 5, 8, 13, 21 };
            var dp = new long[h + 1, w];
            dp[0, 0] = 1;
            for (int i = 1; i <= h; i++)
            {
                for (int j = 0; j < w; j++)
                {
                    //まうえ
                    dp[i, j] = dp[i - 1, j];
                    dp[i, j] %= mask;
                    if (j >= 2)
                    {
                        dp[i,j]*= rowPats[j - 2];
                        dp[i, j] %= mask;
                    }
                    if (j + 3 <= w)
                    {
                        dp[i, j] *= rowPats[w - j - 3];
                        dp[i, j] %= mask;
                    }
                    dp[i, j] %= mask;

                    if (j < w - 1)//右
                    {
                        long right = dp[i - 1, j + 1];

                        if (j + 1 >= 3)
                        {
                            right *= rowPats[j - 2];
                            right %= mask;
                        }
                        if (j + 4 <= w)
                        {
                            right *= rowPats[w - j - 4];
                            right %= mask;
                        }
                        dp[i, j] += right;
                        dp[i, j] %= mask;
                    }
                    if (0 < j)//left
                    {
                        long left = dp[i - 1, j - 1];
                        if (j - 3 >= 0)
                        {
                            left *= rowPats[j - 3];
                            left %= mask;
                        }
                        if (j + 3 <= w)
                        {
                            left *= rowPats[w - j - 3];
                            left %= mask;
                        }
                        dp[i, j] += left;
                        dp[i, j] %= mask;
                    }
                    //Console.Write(dp[i, j] + " ");
                }
                //Console.WriteLine();
            }
            Console.WriteLine(dp[h, k]);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<int,int> P;
ll mod=pow(10,9)+7;
ll INF=pow(10,18);

int main(){
    string S;cin>>S;
    deque<char> dq;
    for(int i=0;i<S.size();i++){
        dq.push_back(S[i]);
    }
    int Q,count=0;cin>>Q;
    for(int i=0;i<Q;i++){
        int T;cin>>T;
        if(T==1){
            count++;
        }
        else{
            int F;cin>>F;
            char C;cin>>C;
            if((F==1 && count%2==0) || (F==2 && count%2==1)){
                dq.push_front(C);
            }
            else{
                dq.push_back(C);
            }
        }
    }
    string ans;
    if(count%2==0){
        for(int i=0;i<dq.size();i++){
            ans+=dq[i];
        }
    }
    else{
        for(int i=dq.size()-1;i>=0;i--){
            ans+=dq[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1412
n,w_max=map(int,input().split())
W,V=[],[]
for i in range(n):
  w,v=map(int,input().split())
  W.append(w)
  V.append(v)
DP=[[0 for i in range(w_max+1)] for j in range(n)]
for i in range(w_max+1):
  if i>=W[0]:
    DP[0][i]=V[0]
for i in range(1,n):
  for j in range(w_max+1):
    if j>W[i]:
      DP[i][j]=max(DP[i-1][j],DP[i-1][j-W[i]]+V[i])
    elif j==W[i]:
      DP[i][j]=max(DP[i-1][j],V[i])
    else:
      DP[i][j]=DP[i-1][j]
print(DP[n-1][w_max])

Measured memory_bytes: 171656
#include<bits/stdc++.h>
using namespace std;
#define LL long long int

int main(){
    LL n;
    cin>>n;
    LL a[n];
    for(LL i=0;i<n;i++){
        cin>>a[i];
    }
    LL dp[n];
    memset(dp,0,sizeof(dp));
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(LL i=2;i<n;i++){
        dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
/*
.....   .   .   .   .
  .    . .   . .   . .
  .   .....   .   .....
  .  .     .  .  .     .
*/
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
   
using namespace std;
   
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
   
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}



#define left left228
#define right right228
#define set set228

const int maxn = 228228;

int delta[maxn];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> x(n + 1), y(n + 1);
    int res = h - 1;
    map< pair<int, int>, bool> is;
    for (int i = 1; i <= n; ++i) {
        cin >> x[i] >> y[i];
        is[{x[i], y[i]}] = 1;
    }
    int d = 0;
    for (int xc = 1; xc <= h; ++xc) {
        if (is[{xc, xc - d}]) {
            ++d;
        }
        delta[xc] = d;
    }
    for (int i = 1; i <= n; ++i) {
        if (y[i] + delta[x[i]] < x[i]) {
            uin(res, x[i] - 2);
        }
    }
    ++res;
    cout << res << '\n';
    return 0;
}
  
  
  
  


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v1(n), v2(n);
    for(int i = 0; i < n; i++)
    {
        cin >> v1[i];
    }
    v2 = v1;
    sort(v1.begin(), v1.end());
    for(int i = 0; i < n; i++)
    {
        if(v2[i] != v1[n-1])
        {
            cout << v1[n-1] << endl;
        }
        else
        {
            cout << v1[n-2] << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3200
#if defined(__GNUC__)
#include <bits/stdc++.h>
#define __int32 __int32_t
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) std::sort(ALL(x))
#define RSORT(x) std::sort(ALL(x), greater<decltype(x)::value_type>())
#define RSORT2(x, T) std::sort(ALL(x), greater<T>())
#define REVERCE(x) std::reverce(ALL(x))
#define ACM(x, y) std::accumulate(ALL(x), y)

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)
#define FCT(x) [](int a) -> int {int r = 1; REP(i, a){r *= i;} return r;}(x)



itn main() {
	std::ios::sync_with_stdio(false);

	int n;

	cin >> n;

	vector<string> s(n);

	REP(i, n) {
		cin >> s[i];
	}

	SORT(s);

	vector<string> res;

	int mv = 1;
	int cnt = 1;
	string bs = "";

	REP(i, n) {
		if (i == 0) {
			bs = s[i];
		}
		else if (bs == s[i]) {
			++cnt;
		}
		else {
			if (cnt < mv) {
			}
			else if (mv == cnt) {
				res.push_back(bs);
			}
			else {
				res.clear();
				res.push_back(bs);
				mv = cnt;
			}

			cnt = 1;
			bs = s[i];
		}
	}

	if (cnt == mv) {
		res.push_back(s.back());
	}
	else if (cnt > mv) {
		res.clear();
		res.push_back(s.back());
	}

	for (auto v : res) {
		cout << v << '\n';
	}

	return 0;
}


Measured memory_bytes: 14576
#include <stdio.h>
#include<stdlib.h>
#include<string.h>

char A[101],B[101];
void input(){
    scanf("%s",A);
    scanf("%s",B);
    
}

int main(){
    input();
    
    if(strlen(A)>strlen(B)) printf("GREATER\n");
    else if(strlen(A)<strlen(B)) printf("LESS\n");
    else {
        if(strcmp(A,B)>0) printf("GREATER\n");
        else if(strcmp(A,B)<0) printf("LESS\n");
        else printf("EQUAL\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for(long long i=0; i<(long long)c; i++)
int main() {
	int x,y;

	cin>>x>>y;
	if (y%2){
		cout << "No"<<endl;
		return 0;
	}
	if (y>x*4||y<x*2){
		cout << "No"<<endl;
		return 0;

	}
	cout << "Yes"<<endl;

	return 0;
}


Measured memory_bytes: 3636
let n = int (stdin.ReadLine())
let mutable count = 0
let mutable num = 0
for i in 1..2..n do
    for j in 1..i do
        if i % j = 0 then num <- num + 1
    if num = 8 then count <- count + 1
    num <- 0
printfn "%d" count 

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

int main() {
  int r = 0;
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    if(s.at(i) == '+')
      r++;
    else
      r--;
  }
  cout << r << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)


{
	int A,B,C,D,E;

	scanf("%d",&A);
	scanf("%d",&B);
	scanf("%d",&C);
	scanf("%d",&D);
	scanf("%d",&E);


	int max = 0;
	int i;
	int time[5];//一の位を１０から引いた時の値
	int ryouri[5];//料理の時間
	int bango = 0;
	if(A%10!=0)
		time[0] = 10-A%10;
	else
		time[0] = 0;
	if(B%10!=0)
		time[1] = 10-B%10;
	else
		time[1] = 0;
	if(C%10!=0)
		time[2] = 10-C%10;
	else
		time[2] = 0;
	if(D%10!=0)
		time[3] = 10-D%10;
	else
		time[3] = 0;
	if(E%10!=0)
		time[4] = 10-E%10;
	else
		time[4] = 0;


	for(i=0;i<5;i++)
		{
			if(max<=time[i]){
				max = time[i];
				bango = i;
		}
	}


	printf("%d\n",A+B+C+D+E+time[0]+time[1]+time[2]+time[3]+time[4]-time[bango]);

return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using i64 = int64_t;
using u64 = uint64_t;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

constexpr int64_t MOD = 1'000'000'007LL;

#define INT(NAME) int NAME; cin>>NAME;
#define INT64(NAME) int64_t NAME; cin>>NAME;
#define VECTOR(NAME, TYPE, SIZE) std::vector<TYPE> NAME((SIZE));\
    for(int xxxx_i=0; xxxx_i<SIZE; xxxx_i++) cin>>NAME[xxxx_i];
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)    

bool simulate(u64 N, u64 K) {
    while (N%K==0)
        N /= K;
    return N%K==1;
}

void solve() {
    INT64(N)
    if (N==2) {
        cout<<1<<endl;
        return;
    }

    u64 ans = 1;  // 自分自身

    // Nを割り切らないKについては
    // N-1の約数の個数を数える
    u64 M = N-1;
    for (u64 k=2; k*k < M; k++) {
        if (M%k == 0) {
            ans += 2;
        }
    }
    u64 rt = sqrt(M);
    ans += (rt*rt==M);
    ans += 1;  // K=N-1

    for (u64 k=2; k*k <= N; k++) {
        if (N%k==0 && simulate(N, k))
            ++ans;
    }
    cout<<ans<<endl;
}

int main() {
    solve();

    return 0;
}

Measured memory_bytes: 256
s = input()
n = len(s)
answer = 0


for i in range(2**(n-1)):
    calc_str = s[0]
    operator_maker = str(format(i, 'b')).zfill(n-1)
    for j, c in enumerate(operator_maker):
        if c == '1':
            calc_str += '+'
        if n != 1:
            calc_str += s[j+1]
    answer += eval(calc_str)

print(answer)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> bool max_self(T & a, const T & b){ 
  return b > a ? a = b, true : false; 
}
template<class T> bool min_self(T & a, const T & b){ 
  return b < a ? a = b, true : false;    
}
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int main(){
  FAST_IO
  int r, g, b;
  cin >> r >> g >> b;
  if((10 * g + b) % 4) cout << "NO\n";
  else cout << "YES\n";

  return 0;
}


Measured memory_bytes: 3660
using System;
using System.Collections.Generic;

namespace BeautifulStrings
{
    public class MainApp
    {
        public static void Main(string[] args)
        {
            string str = Console.ReadLine();
            if (IsBeautifulString(str))
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        public static bool IsBeautifulString(string str)
        {
            var charDirectory = new Dictionary<char, int>();
            for (int i = 0; i < str.Length; i++)
            {
                if (!charDirectory.ContainsKey(str[i]))
                {
                    charDirectory.Add(str[i], 0);
                }

                charDirectory[str[i]]++;
            }

            foreach (var pair in charDirectory)
            {
                // 奇数回出現している項目が出てくる
                // -> Not Beautiful String -> return false
                if (pair.Value % 2 != 0)
                {
                    return false;
                }
            }

            return true;
        }
    }
}


Measured memory_bytes: 3160
# frozen_string_literal: true

n = gets.to_i
a = gets.split.map(&:to_i)

count = 0
c = 1

n.times do |i|
  if a[i] == c
    c += 1
  else
    count += 1
  end
end

if count == n
  count = -1
end
puts count


Measured memory_bytes: 15364
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>
using namespace std;
int main(void) {
	uint64_t n,x;
	cin >> n;
	cin >> x;
	uint64_t dist = 0;
	dist += n;
	uint64_t e1, e2;
	e1 = max(n - x,x);
	e2 = min(n - x, x);
	while (e2 > 0) {
		dist += 2 * (e1 - e1%e2);
		uint64_t swp = e1%e2;
		e1 = e2;
		e2 = swp;
	}
	dist -= e1;
	cout << dist << endl;
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
//typedef long long int;
const ll M = 1000000007;
ll A, B, C, D, G, H, N, L, K, P, Q, R, W, X, Y, Z;
string S, T;

signed main(){
	std::cin >>N;
	vector<string> vec;
	REP(i,N)
	    {std::cin >> S;
	    vec.push_back(S);
	    }
	
std::sort(vec.begin(), vec.end());
vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
std::cout << vec.size() << std::endl;
}

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

typedef long long lint;

int main(){
    int N;
    string s;
    cin >> N >> s;
    string init[4]={"SS","SW","WS","WW"};

    for(int i=0;i<4;i++){
        char *res;
        res=new char[N];
        res[0]=init[i][0];
        res[1]=init[i][1];

        for(int j=1;j<N-1;j++){
            if((s[j]=='o' && res[j]=='S')||(s[j]=='x' && res[j]=='W')) res[j+1]=res[j-1];
            else res[j+1]=(res[j-1]=='S'?'W':'S');
        }
        char test[2];

        if((s[N-1]=='o' && res[N-1]=='S')||(s[N-1]=='x' && res[N-1]=='W')) test[0]=res[N-2];
        else test[0]=(res[N-2]=='S'?'W':'S');
        if((s[0]=='o' && res[0]=='S')||(s[0]=='x' && res[0]=='W')) test[1]=res[N-1];
        else test[1]=(res[N-1]=='S'?'W':'S');

        if(test[0]==init[i][0] && test[1]==init[i][1]){
            for(int i=0;i<N;i++) cout << res[i];
            cout << endl;
            return 0;
        }
        delete[] res;
    }
    cout << (-1) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int a,b; cin>>a>>b;
	int count = 0;
	rp(i, a, b+1){
		string s = to_string(i);
		if(s[0] == s[4] && s[1] == s[3]) count++;
	}
	cout<< count <<endl;
}

Measured memory_bytes: 256
# 高橋君のモンスターは体力が A で攻撃力が B 
# 青木君のモンスターは体力が C で攻撃力が D 
# モンスターの体力が 0 以下になった方の負け、
# 高橋君が勝つなら Yes、負けるなら No を出力

A, B, C, D = map(int, input().split())

while A > 0 and C > 0:
    C -= B
    if C <= 0:
        print('Yes')
        break
    A -= D
    if A <= 0:
        print('No')
        break

Measured memory_bytes: 9052
#include <cstdio>
#include <utility>
using namespace std;

#define gcu getchar_unlocked
int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
int in() {return in(gcu());}
bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bool scan(char &c){c=gcu();gcu();return c!=EOF;}
//bool scan(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename head, typename... tail>
bool scan(head &h, tail&&... t){return scan(h) && scan(t...);}
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
//vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T> vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef vo

int main() {
	for (int a, b, n, s; s = 0, scan(a, b, n);) {
		while ((a = a % b) && n--)
			s += (a *= 10) / b;
		out(s, '\n');
	}
}


Measured memory_bytes: 2476
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define MAX 500000
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> new_data_set; 

ll arr[MAX][3];
ll dp[MAX][12];
ll f(ll index,ll n,ll prev){
	if(index==n) return 0;
	if(dp[index][prev]!=-1) return dp[index][prev];
	ll ans=0;
	For(j,0,3){
		if(j==prev) continue;
		ll temp = arr[index][j]+f(index+1,n,j);
		ans = max(ans,temp);
	}
	dp[index][prev]=ans;
	return ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	memset(dp,-1,sizeof(dp));
	ll n;cin>>n;
	For(i,0,n){
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	}
	cout<<f(0,n,10)<<endl;
}

Measured memory_bytes: 59264
"use strict";
const Main = (input) =>{
   let xs = input.trim().split(' ').map(v=>parseInt(v,10));
   if(xs[0]==xs[1]){
   	console.log('Yes');
   }else{
   	console.log('No');
   }
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
n=int(input())
weight=list(map(int,input().split()))
w=[0]*n
w[0]=weight[0]
for i in range(1,n):
    w[i]=w[i-1]+weight[i]
ans=100000
for i in range(n):
    left=w[i]
    right=w[n-1]-w[i]
    tmp=abs(left-right)
    if tmp<ans:
        ans=tmp
        
print(ans)
    

Measured memory_bytes: 3064
def clean(hh):
    while hh:
        if hh[0]==0:
            del hh[0]
        else:
            break

def apply(hh):
    dh = min(hh)
    return (dh, [h-dh for h in hh])

def solve(hh):
    clean(hh)
    if not hh:
        return 0
    ans = 0
    try:
        idx = hh.index(0)
        ans = solve(hh[idx+1::])
    except ValueError:
        idx = len(hh)
    lhh = hh[:idx]
    dh, lhh = apply(lhh)
    dh += ans
    return dh + solve(lhh)



def main():
    N = int(input())
    hh = list(map(int, input().split()))
    print(solve(hh))



if __name__ == '__main__':
    main()

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

//諸機能
#pragma region MACRO 
#define putans(x)  std::cerr << "[ answer ]: " ; cout << (x) << endl
#define dputans(x) std::cerr << "[ answer ]: "; cout << setprecision(40) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,n,a) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,n,0)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define equals(a,b) (fabs((a)-(b)) < EPS)
#ifdef _DEBUG //ファイルからテストデータを読み込む
std::ifstream ifs("data.txt");
#define put ifs >>
#else //ジャッジシステムでいい感じにやる
#define put cin >>
#endif
#pragma endregion
//デバッグなどの支援
#pragma region CODING_SUPPORT
#ifdef _DEBUG
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#else
#define dbg(var0) {}
#define dbg2(var0, var1) {}
#define dbg3(var0, var1, var2) {}
#define dbgArray(a,n) {}
#endif 
#pragma endregion 
//typedef（書き換える、書き足す可能性ある）
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef pair<long long, long long> pll;
typedef vector<string> vs; typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-10)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(2*1e9)
#pragma endregion

int main() {
	int n; put n;
	vector<ll> p(n); rep(i, n) put p[i];
	vector<ll> a(n),b(n);
	rep(i, n) {
		a[i] = i + 1;
		b[i] = n - i;
	}
	vector<ll> aimos(n);
	vector<ll> bimos(n);
	rep(i, n) {
		int k = p[n - 1-i];
		int plus = n - 1 - i;
		REP(j, k - 1, n) {
			a[j] += plus;
		}
		RREP(j,k,0) {
			b[j] += plus;
		}
		//cout << i << endl;
		//rep(j, n) cout << a[j] << " ";
		//cout << endl;
		//rep(j, n) cout << b[j] << " ";
		//cout << endl;
	}
	int amin = a[0] - 1;
	int bmin = b[n-1] - 1;
	rep(i, n) {
		a[i] -= amin;
		b[i] -= bmin;
	}

	rep(i, n-1) cout << a[i] << " ";
	cout << a[n-1] << endl;
	rep(i, n-1) cout << b[i] << " " ;
	cout << b[n-1] << endl;
	//rep(i, n) {
	//	cout << a[i] + b[i] << " ";
	//}
END:
	return 0;
}

Measured memory_bytes: 1408
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
MOD = 10**9 + 7

def sumXOR(arr, n): 
    sumation = 0
    for i in range(0, 64): 
        zc = 0
        oc = 0
        idsum = 0
        for j in range(0, n): 
            if (arr[j] % 2 == 0): 
                zc = zc + 1
            else: 
                oc = oc + 1
            arr[j] = arr[j] // 2
        idsum = oc * zc * (1 << i) 
        sumation = sumation + idsum
        sumation %= MOD
      
    return sumation
  
n = int(input())
a = [int(item) for item in input().split()]
  
print(sumXOR(a, n)) 

Measured memory_bytes: 123132
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
vector<P> tree[100010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll>> pqls;
priority_queue <P,vector<P>,greater<P>> pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
 
ll rui(ll abc,ll bed){
	//aのb乗を計算する
	if(bed==0){return 1;}
	else{
		ll ced = rui(abc,bed/2);
		ced *= ced;
		ced %= mod;
		if(bed%2==1){ced*=abc; ced%=mod;}
		return ced;
	}
} 
ll i,j,k,ii,jj;
ll n,m,sum,num;
ll ans;
ll a,b,d,e,f,g,h,w;
 
ll x[800005],y[800005],z[900005];
char s[500005];

int main(){
    cin>>n>>m;
	for(i=0;i<n;i++){
		cin>>y[i];
		if(i>0)y[i] += y[i-1];
	}
	for(i=0;i<n;i++){
		x[i] = y[i] % m;
	}
	x[n]=0;
	sort(x,x+n+1);
	for(i=0;i<n;i++){
		//pe(x[i]);
		if(x[i]!=x[i+1]){
			ans += b*(b+1)/2;
			b=0;
		}else{
			b++;
		}
	}
	ans += b*(b+1)/2;
	p(ans);

	
	return 0;
}

Measured memory_bytes: 14720
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    heap = []
    heapq.heapify(heap)

    while True:
        que = sl()
        if que[0] == 'end':
            break
        elif que[0] == 'insert':
            heapq.heappush(heap, int(que[1]) * (-1))
        elif que[0] == 'extract':
            print(heapq.heappop(heap) * (-1))


if __name__ == '__main__':
    main()



Measured memory_bytes: 47028
/*
  NAME : RISHABH SINGH
  INSTITUTION : DELHI TECHNOLOGICAL UNIVERSITY
*/
#include "bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define pii pair<int, int>
#define bi __builtin_inf()
#define ll long long
#define mp make_pair
#define ss second
#define pb push_back
#define ff first
#define speed_cubing ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define um unordered_map
#define us unordered_set
#define bp __builtin_popcount
#define ld long double
#define rep(n) for (int i = 0; i < n; i++)
#define pll pair<ll, ll>
#define mx = 1e18;
#define lb(v, val) (lower_bound(v.begin(), v.end(), val) - v.begin())
#define ub(v, val) (upper_bound(v.begin(), v.end(), val) - v.begin())
#define PI 3.1415926535
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
#define sz(v) (int)v.size()
#define endl '\n'
const int N = 1e4;
const int mod = 998244353;
ll mul_inv(ll a,ll b = mod) {ll t1=a,t2=b,t3,v1=1,v2=0,v3;while(t2!=1){ll x=t1/t2;t3=t1-x*t2;v3=v1-x*v2;t1=t2,t2=t3;v1=v2,v2=v3;}return(v2+b)%b;}


int32_t main(){
   
   speed_cubing 
   
   string s;
   cin>>s;

   if(s=="ABC")
     cout<<"ARC";
   else 
     cout<<"ABC";  
   
    
   return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define base 1000000007LL
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define CLR(a) memset(a,0,sizeof(a))
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORE(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)

using namespace std;

typedef pair<int, int> II;
typedef vector<II> vi;

int n, k, res;
bool f[11];

int main()
{
    ios::sync_with_stdio(0);
    //freopen("inp.txt", "r", stdin);
    cin >> n >> k;
    FOR(i,1,k) {
        int p;
        cin >> p;
        f[p] = true;
    }
    res = n;
    while (1) {
        int p = res;
        bool co = true;
        while (p) {
            int e = p % 10;
            p /= 10;
            if (f[e]) {
                co = false;
                break;
            }
        }
        if (co) {
            cout << res;
            break;
        }
        res++;
    }
    return 0;
}


Measured memory_bytes: 256
using System;

namespace ABC056_B_NarrowRectanglesEasy
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string[] input = Console.ReadLine().Split(' ');
			int w = int.Parse(input[0]);
			int a = int.Parse(input[1]);
			int b = int.Parse(input[2]);

			if (a + w < b)
				Console.WriteLine(b - a - w);
			else if (b + w < a)
				Console.WriteLine(a - b - w);
			else
				Console.WriteLine(0);
		}
	}
}

Measured memory_bytes: 13140