akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
  int s,w=0;
  cin>>s>>w;
  if(s<=w){
    cout<<"unsafe";
  }else{
    cout<<"safe";
  }
}

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

int main()
{
  int n;
  cin >> n;
  int k = 100000;
  for (int i = 0; i< n; i++) {
    k *= 1.05;
    if (k % 1000 != 0) {
      k /= 1000;
      k += 1;
      k *= 1000;
    }
  }
  cout << k << endl;
}



Measured memory_bytes: 3104
D = int(input())
c = list(map(int, input().split()))
s = []
for i in range(D):
  s.append(list(map(int, input().split())))
  
sdictlist = []
sdictlistsorted = []
for i in range(D):
  onedict = {}
  for j in range(26):
    onedict[j] = s[i][j]
  sdictlist.append(onedict)
  onesorteddict = sorted(onedict.items(), key=lambda x:x[1], reverse=True)
  sdictlistsorted.append(onesorteddict)
  
for i in range(D):
  print(sdictlistsorted[i][0][0]+1)

Measured memory_bytes: 10456
#include<stdio.h>

int main(void)
{
   int a[100], b[300];
   int x, y, z;
	int n[100] = {0};
   int i = 1;
   
   while(!(a[i-1] == 0 && b[i-1] == 0)){
       scanf("%d", &a[i]);
       scanf("%d", &b[i]);

       
       for(x=1; x<=a[i]; x++){
           for(y=1; y<=a[i]; y++){
               for(z=1; z<=a[i]; z++){
                   if(x+y+z == b[i] && x > y && y > z){
                        n[i]++;
                   }
                   
       }}}
       i++;}
       
       for(x=1; x<=i-2; x++){
           printf("%d\n", n[x]);}
           
   return 0;
}


Measured memory_bytes: 2140
#include <cstdio>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

typedef long long LL;
const int p=1000000007;

int x1,x2,x3,x4,x5,x6,y1,y2,y3,y4,y5,y6,fac[2000100],inv[2000100],ans;

int calc(int n,int m)
{
    return LL(fac[n+m])*inv[n]%p*inv[m]%p;
}

int solve(int xs,int ys,int x1,int y1,int x2,int y2,int xt,int yt)
{
    int sum=0;
    repu(i,x1,x2)
    {
        sum=(sum+LL(p-i-y1)*calc(i-xs,y1-ys-1)%p*calc(xt-i,yt-y1))%p;
        sum=(sum+LL(i+y2+1)*calc(xt-i,yt-y2-1)%p*calc(i-xs,y2-ys))%p;
    }
    repu(i,y1,y2)
    {
        sum=(sum+LL(p-x1-i)*calc(x1-xs-1,i-ys)%p*calc(xt-x1,yt-i))%p;
        sum=(sum+LL(x2+i+1)*calc(xt-x2-1,yt-i)%p*calc(x2-xs,i-ys))%p;
    }
    return sum;
}

int main()
{
    fac[0]=fac[1]=inv[0]=inv[1]=1;
    repu(i,2,2e6+10)
        inv[i]=LL(p-p/i)*inv[p%i]%p;
    repu(i,2,2e6+10)
        fac[i]=LL(fac[i-1])*i%p,inv[i]=LL(inv[i-1])*inv[i]%p;
    scanf("%d%d%d%d%d%d",&x1,&x2,&x3,&x4,&x5,&x6);
    scanf("%d%d%d%d%d%d",&y1,&y2,&y3,&y4,&y5,&y6);
    repu(i,0,1)
        repu(j,0,1)
            repu(k,0,1)
                repu(l,0,1)
                {
                    int xs=i?x2:x1-1,ys=j?y2:y1-1;
                    int xt=k?x6+1:x5,yt=l?y6+1:y5;
                    int w=solve(xs,ys,x3,y3,x4,y4,xt,yt);
                    if ((i+j+k+l)&1)
                        (ans+=p-w)%=p;
                    else
                        (ans+=w)%=p;
                }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 15744
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 200005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
 
ll dup(ll a, ll b) { return (a+b-1)/b;}
 
 
int main() {
  int n;
  scanf("%d",&n);
  vl a(n);
  cin>>a;
  ll l = 2, r = 2;
  reverse(rng(a));
  for (ll x : a) {
    l = dup(l,x)*x;
    r = r/x*x;
    if (l > r) dame;
    // l = l;
    r = r+x-1;
  }
  cout<<l<<" "<<r<<endl;
  return 0;
}
 
 
 
 
 
 
 
 

Measured memory_bytes: 1152
#include<stdio.h>

 int main(void){
   int b1,b2,b3;
   scanf("%d %d %d",&b1,&b2,&b3);
   if((b1==1 && b2==1) || (b3==1))
    { printf("Open\n"); }
   else{ printf("Close\n"); }
   return 0;
 }



Measured memory_bytes: 2124
n=int(input())
a=list(map(int,input().split()))
dp=[float('inf')]*n
dp[0]=0
dp[1]=abs(a[0]-a[1])
for i in range(2,len(a)):
    for j in range(i-2,i):
        dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]))
print(dp[-1])

Measured memory_bytes: 52208
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c,i;
    cin>>a; cin>>b; cin>>c;
    if(a>b){
        i=a;
        a=b;
        b=i;
    }
    if (b>c){
        i=b;
        b=c;
        c=i;
    }
    if (a>b){
        i=a;
        a=b;
        b=i;
    }
 
    cout<<a<<" "<<b<<" "<<c;
      cout<< endl;
       return 0;
}


Measured memory_bytes: 3088
using System;
class A
{
    public static void Main()
    {
        string L=Console.ReadLine();
        string[] Ls = L.Split(' ');
        int a = int.Parse(Ls[0]);
        int b = int.Parse(Ls[1]);
       // Console.WriteLine(b);
        int A = 0;
        int B = 0;
        for(int i = b-1; i>-1; i--)
        {
          //  Console.WriteLine(i);
            A += a * (int)Math.Pow(10, i);

        }
        for(int j = a - 1; j > -1; j--)
        {
            B += b * (int)Math.Pow(10, j);
        }
        if (a >= b)
        {
            Console.WriteLine(B);
        }
        else
        {
            Console.WriteLine(A);
        }

        
      
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include <climits>
#include <cstdint>
#include<cmath>
#include<algorithm>

#define ll long long

using namespace std;

struct Item{
  int w,v;
};

ll solve(Item arr[],int n,int w){
    int maxVal = n * 1000;
    ll dp[n+1][maxVal+1];
    for(int val = 0;val <= maxVal;val++)
      dp[1][val] = INT_MAX;
    dp[1][0] = 0;
    dp[1][arr[1].v] = arr[1].w;
    for(int i = 2;i<=n;i++){
      for(int val = 0;val<=maxVal;val++){
        dp[i][val] = dp[i-1][val];
        if(arr[i].v > val)
          continue;
        dp[i][val] = min(dp[i][val],dp[i-1][val - arr[i].v] + arr[i].w);
      }
    }

    int ans = 0;
    for(int x = 0;x <= maxVal;x++){
      if(dp[n][x] <= w){
        ans = x;
      }
    }
    return ans;
}

int main(){
  int n,w;
  cin >> n >> w;
  Item arr[n+1];
  for(int i =1;i<=n;i++)
    cin >> arr[i].w >> arr[i].v;
  cout << solve(arr,n,w) << endl;
}


Measured memory_bytes: 78336
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
ln = len(input())
print('x'*ln)


Measured memory_bytes: 10308
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define T() int t; cin>>t; while(t--)                      
#define pb push_back
#define endl "\n"


int main()
{	
	FIO;
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	ll n,d;
	cin>>n>>d;

	int cnt = 0;
	for(int i=0;i<n;i++){
		ll x,y;
		cin>>x>>y;

		// ll check = sqrt(x*x+y*y); 
		if(x*x + y*y <= d*d) cnt++;
	}

	cout<<cnt<<endl;
	return 0;
	
}

Measured memory_bytes: 3656
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int r, g, b, t;
    r = sc.nextInt() * 100;
    g = sc.nextInt() * 10;
    b = sc.nextInt();
    t = r + g + b;
    if(t%4 == 0){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }   
  }
}


Measured memory_bytes: 21844
a, b, c, d= map(int, input().split())
def gcd(c,d):
    if c%d == 0:
        return d
    else:
        return gcd(d,c%d)
def num(n,c,d):
    lcm = c // gcd(c, d) * d
    return n - n//c - n//d + n//lcm
print(num(b,c,d)-num(a-1,c,d))
    

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
)

func main() {
	s, w := readInt(), readInt()

	if w >= s {
		fmt.Println("unsafe")
	} else {
		fmt.Println("safe")
	}
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 1760
using System;
namespace kozaiyApp
{
    public class A
    {
        static void Main()
        {
            string n = Console.ReadLine();

            int l = n.Length - 1;
            int x = int.Parse(n[l].ToString());

            if (x == 3)
            {
                Console.WriteLine("bon");
            }
            else if (x == 0 || x == 1 || x == 6 || x == 8)
            {
                Console.WriteLine("pon");
            }
            else
            {
                Console.WriteLine("hon");
            }
        }
    }
}


Measured memory_bytes: 27536
#include<bits/stdc++.h>
using namespace std;int main(){string a;cin>>a;int b=0;for(char c:a){if(((b&1)==0&&c=='A')||((b&1)&&c=='Z'))b++;}if(b&1)b--;b/=2;if(b==0){puts("-1");return 0;}for(int i=0;i<b;i++){cout<<"AZ";}cout<<endl;}

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

int main(){
    int N;
    cin >> N;
    int A[N];
    double resum = 0;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    //たす
    for(int i = 0; i < N; i++){
        resum += pow(A[i],-1);
    }
    cout << pow(resum,-1) << setprecision(10) << endl;
return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    N = ii()
    P = [tuple(tuple(mis()) for _ in range(ii())) for __ in range(N)]
    ho = [None] * N
    ans = 0
    for b in range(2**N):
        for i in range(N):
            ho[i] = bool(b & (1<<i))
        if ans >= sum(ho):
            continue
        flag = True
        for i in range(N):
            if not flag:
                break
            if ho[i]:
                for x, y in P[i]:
                    x -= 1
                    if bool(y) !=  ho[x]:
                        flag = False
                        break
        
        if not flag:
            continue

        ans = sum(ho)
    print(ans)




main()


Measured memory_bytes: 3796
#include <iostream>
using namespace std;
int m[1000][1000];
int maxchainorder(int p[],int a){
    int n=a;
    for(int i=1;i<=n;i++){
        m[i][i]=0;
    }
    for(int l=2;l<=n;l++){
        for(int i=1;i<=n-l+1;i++){
            int j=i+l-1;
            m[i][j]=100000000;
            for(int k=i;k<=j-1;k++){
                int q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
                if(q<m[i][j]){
                    m[i][j]=q;
                }
            }
        }
    }
    return m[1][n];
}
int main(){
    int n,p[100000];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p[i]>>p[i+1];
    }
    cout<<maxchainorder(p,n)<<endl;
    return 0;
}


Measured memory_bytes: 3472
#include<bits/stdc++.h>
using namespace std;
vector<int> h, dp;

long long solve(int i) {
    if(dp[i] != -1) return dp[i];
    if(i == 0) return 0;
    if(i == 1) return abs(h[i] - h[i-1]);
    else dp[i] = min(abs(h[i] - h[i-1]) + solve(i-1), abs(h[i] - h[i-2]) + solve(i-2));
    return dp[i];
}

int main() {
    int N;
    cin >> N;
    h.resize(N);
    dp.resize(N);
    for(int i = 0; i < N; i++) cin >> h[i];
    fill(dp.begin(), dp.end(), -1);
    cout << solve(N - 1) << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    ll W, H, x, y; cin >> W >> H >> x >> y;
    ll val = W * H;
    cout << val / 2; if (val % 2 == 1) cout << ".5";
    cout << " ";
    if (x * 2 == W && y * 2 == H) {
    	cout << 1 << endl;
    } else {
    	cout << 0 << endl;
    }

    
    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

int comb_2(int a) {
  if (a == 1) {
    return 1;
  }

  int ans = 0;
  ans = a * (a - 1) / 2;
  return ans;
}

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

  int N, M;
  cin >> N >> M;

  int ans = 0;
  if (N >= 2) {
    ans += comb_2(N);
  }

  if (M >= 2) {
    ans += comb_2(M);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N, A, B, C = map(int, input().split())
opts = []
for _ in range(N):
    opt = input()
    opts.append((ord(opt[0]) - ord("A"), ord(opt[1]) - ord("A")))

choices = []
nums = [A, B, C]
for i, opt in enumerate(opts):
    if nums[opt[0]] == 0 and nums[opt[1]] == 0:
        print("No")
        break
    if nums[opt[0]] == 1 and nums[opt[1]] == 1 and i < N - 1 and opt != opts[i + 1]:
        choice = (set(opt) & set(opts[i + 1])).pop()
    elif nums[opt[0]] >= nums[opt[1]]:
        choice = opt[1]
    else:
        choice = opt[0]
    choices.append(choice)
    nums[choice] += 1
    nums[choice ^ opt[0] ^ opt[1]] -= 1
else:
    print("Yes")
    for c in choices:
        print(chr(c + ord("A")))


Measured memory_bytes: 84436
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    string S, T;
    cin >> S >> T;
    ll ans = 0;
    rep(i, S.size()){
        if(S[i] != T[i]){
            ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
main(){
  int n;
  cin>>n;
  int arr[n];
  for(int i = 0; i < n; i++) cin>> arr[i];
  int ans[n];
  int mx = 1;
  ans[n - 1] = 1;
  for(int i = n - 2; i >= 0; i--){
    ans[i] = 1;
    if(arr[i] >= arr[i + 1]) ans[i] += ans[i + 1];
    mx = max(mx, ans[i]);
  }
  cout<<mx - 1<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#define ALL(v) (v).begin(),(v).end()

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  int a, b ;
  cin >> a >> b ;
  
  if(a+b<10){
    cout <<a+b<<endl ;
  }
  else{
    cout <<"error"<<endl ;
  }
    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 5678;
LL d[MAXN], td[MAXN];

int main() {
    int K, Q;
    scanf("%d %d", &K, &Q);
    for (int i = 0; i < K; i++)
        scanf("%lld", &d[i]);
    for (int i = 0; i < Q; i++) {
        LL n, x, m;
        scanf("%lld %lld %lld", &n, &x, &m);
        x %= m;
        LL tsum = 0;
        LL zsum = 0;
        for (int i = 0; i < K; i++) {
            td[i] = (d[i] % m);
            if (!td[i]) zsum++;
            tsum += td[i];
        }
        LL sum = tsum * ((n - 1) / K) + x;
        LL zcnt = zsum * ((n - 1) / K);
        for (int i = 0; i < ((n - 1) % K); i++) {
            sum += td[i];
            if (!td[i]) zcnt++;
        }
        printf("%lld\n", n - 1 - sum / m - zcnt);
    }
    return 0;
}


Measured memory_bytes: 384
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-11;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
char in[210000];
int main(){
	scanf("%s",in);
	int n=strlen(in);
	for(int i=0;i<n;i++){
		if(in[i]=='?')in[i]='D';
	}
	printf("%s\n",in);
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;
  vector<pair<ll, ll>> X;
  ll x;
  REP(i, N) {
    cin >> x;
    X.push_back(make_pair(x, i));
  }
  sort(X.begin(), X.end());

  int middle = N / 2;
  vector<ll> B(N);

  ll median;
  REP(i, N) {
    if (i == middle) {
      --middle;
    }

    median = X.at(middle).first;
    B.at(X.at(i).second) = median;
  }

  REP(i, N) { cout << B.at(i) << endl; }

  return 0;
}


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

using namespace std;

int main() {
  string S, T;
  
  cin >> S >> T;
  
  int ans = T.length();
  
  for (int i = 0; i < (int)(S.length() - T.length()) + 1; i++) {
    int matched = 0;
    
    for (int j = 0; j < (int)T.length(); j++) {
      if (S[i + j] == T[j]) {
        matched++;
      }
    }
    
    ans = min(ans, (int)T.length() - matched);
  }
  
  cout << ans << endl;
  
  return 0;
}

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





int main() {
  int a,b,c,d,e;
  cin >> a >> b >> c>> d>> e;
  int ans =0;
  if (a == 0) ans = 1;
  if (b == 0) ans = 2;
  if (c == 0) ans = 3;
  if (d == 0) ans = 4;
  if (e == 0) ans = 5;

 
  cout << ans <<endl;

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 30)
using namespace std;

void move(queue<int> &q){
    int tmp = q.front();
    q.pop();
    q.push(tmp);
}

int main(){
    int n, k, m;
    while(cin >> n >> k >> m, n||k||m){
        queue<int> q;
        rep(i,n) q.push(i + 1);
        rep(i,m - 1) move(q);
        q.pop();

        while(q.size() != 1){
            int k_cp = k - 1;
            k_cp%=q.size();
            rep(i,k_cp) move(q);
            q.pop();
        }
        cout << q.front() << endl;
    }
}

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


int main (){
    char a, b, c, d;
    cin>>a>>b>>c>>d;
    int count=0;
  	if(a==b){
        count++;
    }
    if(a==c){
        count++;
    }
    if(a==d){
        count++;
    }
    if(c==b){
        count++;
    }
    if(d==b){
        count++;
    }
    if(c==d){
        count++;
    }
    if(count==2){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

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

int main(){
	string S;
	cin >> S;

	int cost = 700;

	for(int i = 0; i < 3; i++){
		if(S.at(i) == 'o'){
			cost += 100;
		}
	}

	cout << cost << endl;
}


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

using namespace std;

#define ll long long
#define REP(i, n) for(int i=0; i < (int)(n); ++i)
#define REPR(i, n) for(int i=n; i>= 0; --i)
#define FOR(i, m, n) for(int i=m; i<n; ++i)

int main(){
    string s[3], ans;

    cin >> s[0] >> s[1] >> s[2];

    REP(i, 3)
        ans += s[i][0];
    transform(ans.begin(), ans.end(), ans.begin(), ::toupper);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// 
#include<bits/stdc++.h>
#define pb push_back 
#define mp make_pair
using namespace std;

const int maxn=1;
typedef long long ll;

int n,m,ans;
int a,b,x;

int main()
{
	int i,j,k,T;
	while(cin>>a>>b>>x)
	{
		if(x>=a&&x<=a+b) cout<<"YES";
		else cout<<"NO";
	}
	
	
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int X[N];
  for(int i=0;i<N;i++) cin >> X[i];
  long long int min = 1000000000000000000;
  for(int i=0;i<=100;i++){
    long long int lostPower=0;
    for(int j=0;j<N;j++){
      lostPower+=(X[j]-i)*(X[j]-i);
    }
    if(lostPower<min) min = lostPower;
  }
  cout << min;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define rep(i, n) for (ll i = 0; i < (n); i++)
int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false); 
  ll H, W, K; cin >> H >> W >> K;
  vector<string> c(6);
  ll cnt = 0;

  rep(i, H) {
    cin >> c[i];
  }

  rep(h, 1 << H) {
    rep(w, 1 << W) {
      ll blacks = 0;
      rep(i, H) {
        rep(j, W) {
          if ((h >> i & 1) && (w >> j & 1) && c[i][j] == '#') {
            blacks++;
          }
        }
      }

      if (blacks == K) {
        cnt++;
      }
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 3648
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = list(map(int, input().split()))

for i in range(1,k+1):
    if n - k + 1 >= i:
        ans = comb(n - k + 1, i) * math.factorial(k - 1) // math.factorial(k-i) // math.factorial(i-1)
        print(ans % 1000000007)
    else:
        print(0)

Measured memory_bytes: 3316
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
int n;
ll t;
typedef pair<ll,ll> Q;
vector<Q>vec;
vector<ll>take;

bool cmp(const Q&a,const Q&b){
	//a.fi/(a.sc+1) > b.fi/(b.sc+1)
	return a.fi * (b.sc+1) > b.fi * (a.sc+1);
}
ll cur[32];
int main(){
	scanf("%d",&n);scanf("%lld",&t);
	rep(i,n){
		ll a,b; scanf("%lld%lld",&a,&b);
		if(a == 0){
			take.pb(b);
		}
		else{
			vec.pb(mp(a,b));
		}
	}
	sort(vec.begin(),vec.end(),cmp);
	rep(i,32) cur[i] = 1e18;
	cur[0] = 0;
	
	rep(i,vec.size()){
		ll nw[32];
		rep(i,32) nw[i] = 1e18;
		ll a = vec[i].fi, b = vec[i].sc;
		rep(i,32){
			if(cur[i] > t) continue;
			nw[i] = min(nw[i], cur[i]);
			//(cur[i]+1) * (a+1) + b
			if(5e18/(a+1) < (cur[i]+1)) continue;
			nw[i+1] = min(nw[i+1], (cur[i]+1)*(a+1)+b);
		}
		rep(i,32) cur[i] = nw[i];
	}
	
	SORT(take);
	vector<ll>use;
	use.pb(0);
	rep(i,take.size()){
		ll v = take[i];
		use.pb(use.back() + v+1);
	}
	int ans = 0;
	rep(i,32){
		//cout << i << " " << cur[i] << endl;
		if(cur[i] > t) continue;
		ll zan = t-cur[i];
		int k = POSU(use,zan);
		ans = max(ans,i+k-1);
		//cout << i << " " << k << endl;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 6512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

template <class F>
ll lower_bound(ll i0, ll i1, F f) {
    while (i0 < i1) {
        ll i = (i0 + i1) / 2;
        if (f(i)) i1 = i; else i0 = i + 1;
    }
    return i0;
}

ll a[3][1000], r[3000];

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

    int x[3], k;
    for (int h = 0; h < 3; h++) {
        cin >> x[h];
    }
    cin >> k;

    ll s = 0, u = 0;

    for (int h = 0; h < 3; h++) {
        for (int i = 0; i < x[h]; i++) {
            cin >> a[h][i];
        }
        sort(a[h], a[h] + x[h], greater<>());
        ll t = a[h][0];
        s += t;
        for (int i = 0; i < x[h]; i++) {
            a[h][i] = t - a[h][i];
        }
        u += a[h][x[h] - 1];
    }

    ll l = lower_bound(0, u, [&](ll l) {
        int c = 0;
        for (int i0 = 0; i0 < x[0]; i0++) {
            ll s0 = a[0][i0];
            if (s0 > l) break;
            for (int i1 = 0; i1 < x[1]; i1++) {
                ll s1 = s0 + a[1][i1];
                if (s1 > l) break;
                for (int i2 = 0; i2 < x[2]; i2++) {
                    ll s2 = s1 + a[2][i2];
                    if (s2 > l) break;
                    c++;
                    if (c >= k) return true;
                }
            }
        }
        return false;
    });

    int c = 0;
    for (int i0 = 0; i0 < x[0]; i0++) {
        ll s0 = a[0][i0];
        if (s0 >= l) break;
        for (int i1 = 0; i1 < x[1]; i1++) {
            ll s1 = s0 + a[1][i1];
            if (s1 >= l) break;
            for (int i2 = 0; i2 < x[2]; i2++) {
                ll s2 = s1 + a[2][i2];
                if (s2 >= l) break;
                r[c++] = s2;
            }
        }
    }
    sort(r, r + c);
    for (int i = 0; i < c; i++) {
        cout << s - r[i] << '\n';
    }
    for (int i = c; i < k; i++) {
        cout << s - l << '\n';
    }
    cout << flush;

    return 0;
}

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

typedef long long LL;
const int N = 2000005, mod = 1000000007;
int f[N], n, qaq, ans;

void up(int &x, int y) {x += y - mod, x += x >> 31 & mod;}
void up(int &x, int y, int z) {x = (x + (LL) y * z) % mod;}
int _(int n) { return n < 0 ? 1 : f[n]; }

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n, f[0] = 1, f[1] = n; int q = (LL) (n - 1) * (n - 1) % mod;
	int sum = n - 1;
	for (int i = 2; i <= n; ++i) {
		up(f[i] = f[i - 1], q);
		up(sum, mod - 1), up(sum, _(i - 3));
		up(f[i], sum);
	}
	std::cout << f[n] << '\n';
	return 0;
}

Measured memory_bytes: 4352
# 63


n = int(input())
dp = [[int(x) for x in input().split()] for y in range(n)]
del_l = []
ans = 0

for i in range(n-1):
    for j in range(i+1,n):
        for k in range(n):
            if k in (i,j):
                continue
            if dp[i][j] > dp[i][k] + dp[k][j]:
                print("-1")
                exit()
            elif dp[i][j] == dp[i][k] + dp[k][j]:
                break
        else:
            ans += dp[i][j]

print(ans)

Measured memory_bytes: 75516
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int p[1100];
int q[1100];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	for(int i=0;i<b;i++)scanf("%d",q+i);
	std::sort(p,p+a);
	std::sort(q,q+b);
	reverse(p,p+a);
	reverse(q,q+b);
	int pat=0;
	int qat=0;
	long long ret=1;
	int cnt=0;
	for(int i=a*b;i>=1;i--){
		bool P=false;
		bool Q=false;
		if(pat<a&&p[pat]==i){
			pat++;P=true;
		}
		if(qat<b&&q[qat]==i){
			qat++;Q=true;
		}
		if(P&&Q); // 1
		else if(P){
			ret=ret*qat%mod;
		}else if(Q){
			ret=ret*pat%mod;
		}else{
			ret=ret*((max(0LL,(long long)pat*qat-cnt))%mod)%mod;
		}
		cnt++;
	}
	printf("%lld\n",ret);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  while(1){
    int x,count=0;
    cin >> x;
    if(x==0) break;
    int flag=1;
    int sum = 0;
    while(flag!=x){
      sum = 0;
      for(int i=flag;i<=x;i++){
        sum+= i;
        if(sum == x) count++;
      }
      flag++;
    }
    cout << count << endl;
  }
}



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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 N,Q;
    string s;
    cin >> N >> Q >> s;

    vector<char> t(Q),d(Q);
    rep(i,0,Q){
        cin >> t[i] >> d[i];
    }

    auto simulate_left=[&](i64 i){
        i64 p=i;
        rep(j,0,Q){
            if(t[j]!=s[p]) continue;
            if(d[j]=='L') --p;
            else ++p;
            if(p<0) return false;
            if(p==N) return true;
        }
        return true;
    };
    auto simulate_right=[&](i64 i){
        i64 p=i;
        rep(j,0,Q){
            if(t[j]!=s[p]) continue;
            if(d[j]=='L') --p;
            else ++p;
            if(p>=N) return false;
            if(p<0) return true;
        }
        return true;
    };

    i64 left,right;
    {
        if(!simulate_left(N-1)){
            cout << 0 << endl;
            return;
        }
        i64 lb=-1,ub=N-1;
        while(ub-lb>1){
            i64 mid=(lb+ub)/2;
            if(simulate_left(mid)) ub=mid;
            else lb=mid;
        }
        left=ub;
        // left以上なら左に落ちない
    }
    {
        if(!simulate_right(0)){
            cout << 0 << endl;
            return;
        }
        i64 lb=0,ub=N;
        while(ub-lb>1){
            i64 mid=(lb+ub)/2;
            if(simulate_right(mid)) lb=mid;
            else ub=mid;
        }
        right=ub;
        // right以下なら右に落ちない
    }

    if(left>right){
        cout << 0 << endl;
        return;
    }
    assert(left<=right);
    cout << right-left << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

template <typename T, typename C> void printset(const multiset<T, C> &s) {
  for (auto &t : s) {
    cout << t << " ";
  }
  cout << endl;
}

int main() {
  ll N, M;
  vector<vector<ll>> jobs(100001);
  cin >> N >> M;

  for (ll i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    jobs[a].push_back(b);
  }

  ll sum = 0;
  multiset<ll, greater<ll>> board;

  for (ll i = 1; i <= M; i++) {
    board.insert(jobs[i].begin(), jobs[i].end());

    if (board.size() > 0) {
      auto it = board.begin();
      sum += *it;
      board.erase(it);
    }
  }

  cout << sum << endl;
}


Measured memory_bytes: 11196
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>

using namespace std;
typedef long long ll;

int x[101], y[101], h[101];
int idx;
int main() {
  int N, M;
  cin >> N >> M;
  
  int ans = 1;
  for (int A = 1; A * A <= M; A++) {
    if (M % A != 0) {
      continue;
    }
    int B = M / A;
    if ((long)A * N <= M) {
      ans = max(ans, A);
    }
    if ((long)B * N <= M) {
      ans = max(ans, B);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*author: hyperion_1724
  date: 
*/

//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

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

    READV(N);
    string S;
    cin>>S;
    ll L=S.length();
    FORI(i,0,L)
    {
        S[i]=char((int)'A'+((int)S[i]+N-(int)'A')%26);
    }
    cout<<S<<endl;

    return 0;
}

Measured memory_bytes: 256
def partition(A, p, r):
    x = A[r]
    i = p-1
    for j in range(p, r):
        if A[j] <= x:
            i = i + 1
            A[i], A[j] = A[j], A[i]

    A[i+1], A[r] = A[r], A[i+1]
    A[i+1] = '[{}]'.format(A[i+1])
    return i + 1


if __name__ == "__main__":
    input()
    A = [int(x) for x in input().split()]
    target = A[-1]

    partition(A, 0, len(A) - 1)
    output_str = [str(a) for a in A]
    print(' '.join(output_str))



Measured memory_bytes: 16592
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

int N;
vector<int> A, B, C;
int search(int k) {
    int p = 0;
    for (int a = N-1; a >= 1; a /= 2) {
        while (p+a < N && A[p+a] < k){
         // cout << "p: " << p << " a: " << a << "\n";
          p += a;
        }
    }
    return p;
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  A.resize(N);
  B.resize(N);
  C.resize(N);
  for(int i=0; i<N; ++i)
    cin >> A[i];
  for(int i=0; i<N; ++i)
    cin >> B[i];
  for(int i=0; i<N; ++i)
    cin >> C[i];
  sort(all(A));
  sort(all(B));
  sort(all(C));
  long long res = 0;
  for(int i=0; i<N; ++i){
    int p = search(B[i]);
    if(A[p] >= B[i])
      continue;
    long long pp = upper_bound(all(C), B[i]) - C.begin();
    if(pp == N) continue;
    //cout << "i: " << i << " p: " << p << " pp: " << pp << "\n";
    res += (p+1)*(N-pp); 
  }
  cout << res << "\n";
  return 0;  
}
/*
O(N)
O(N^2*(log(N)^2))
1 2 3 4
5 6 7 8
9 10 11 12
*/


Measured memory_bytes: 1408
#include <vector>
#include <algorithm>
#include <cstdio>

using namespace std;
typedef long long ll;
typedef vector<int> vi;

int H;
int W;
int f[1000][1000];
vector<int> ordR;
vector<int> ordC;

bool solveRow() {
  vi prev;
  prev.push_back(0);
  for (int i = 1; i < H; ++i) {
    bool okPrev = true;
    int pi = ordR[prev.back()];
    int ci = ordR[i];
    for (int j = 0; j < W; ++j) {
      if (f[ci][j] > f[pi][j]) {
	okPrev = false;
	break;
      }
    }
    if (okPrev) {
      prev.push_back(i);
      continue;
    }
    bool ok = false;
    for (int j = prev.size() - 2; j >= 0; --j) {
      int pastI = ordR[prev[j]];
      ok = true;
      for (int k = 0; k < W; ++k) {
	if (f[ci][k] > f[pastI][k]) {
	  ok = false;
	  break;
	}
      }
      if (ok) {
	break;
      }
    }
    if (!ok) {
      return false;
    }
    prev.clear();
    prev.push_back(i - 1);
    prev.push_back(i);
  }
  return true;
}

bool solveCol() {
  vi prev;
  prev.push_back(0);
  for (int i = 1; i < W; ++i) {
    bool okPrev = true;
    int pi = ordC[prev.back()];
    int ci = ordC[i];
    for (int j = 0; j < H; ++j) {
      if (f[j][ci] > f[j][pi]) {
	okPrev = false;
	break;
      }
    }
    if (okPrev) {
      prev.push_back(i);
      continue;
    }
    bool ok = false;
    for (int j = prev.size() - 2; j >= 0; --j) {
      int pastI = ordC[prev[j]];
      ok = true;
      for (int k = 0; k < H; ++k) {
	if (f[k][ci] > f[k][pastI]) {
	  ok = false;
	  break;
	}
      }
      if (ok) {
	break;
      }
    }
    if (!ok) {
      return false;
    }
    prev.clear();
    prev.push_back(i - 1);
    prev.push_back(i);
  }
  return true;
}

int main() {
  scanf("%d %d", &H, &W);
  int mr = 0;
  int mc = 0;
  int max = 0;
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      scanf("%d", &f[i][j]);
      if (max < f[i][j]) {
	max = f[i][j];
	mr = i;
	mc = j;
      }
    }
  }
  {
    vector<ll>r(H);
    for (int i = 0; i < H; ++i) {
      r[i] = ((ll) f[i][mc] << 10) + i;
    }
    sort(r.begin(), r.end());
    ordR.resize(H);
    for (int i = 0; i < H; ++i) {
      ordR[i] = (int) (r[H - 1 - i] & ((1 << 10) - 1));
    }
  }
  {
    vector<ll> c(W);
    for (int i = 0; i < W; ++i) {
      c[i] = ((ll) f[mr][i] << 10) + i;
    }
    sort(c.begin(), c.end());
    ordC.resize(W);
    for (int i = 0; i < W; ++i) {
      ordC[i] = (int) (c[W - 1 - i] & ((1 << 10) - 1));
    }
  }
  printf(solveRow() && solveCol() ? "YES\n" : "NO\n");
  return 0;
}

Measured memory_bytes: 4956
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;

int dp[2005][2005][2];

void chmax(int& t, int f){
    if (t < f) {
        t = f;
    }
}

char S[2048], T[2048];

int main(){
    ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
    int a, b;
    cin >> a >> b;
    if(a<=0&&b>=0) cout << "Zero";
    else if(a>0) cout << "Positive";
    else{
        if((b-a)%2==0) cout << "Negative";
        else cout << "Positive";
    }
}


Measured memory_bytes: 256
import java.io.*;
import java.io.IOException;
import java.util.*;

@SuppressWarnings({"rawtypes", "unchecked"})
class Main {
    final static int INF = 1 << 28;
    final static long LNF = 1L << 60;
    final static double EPS = 1e-9;
    final static double GOLDEN_RATIO = (1.0 + Math.sqrt(5)) / 2.0;

    static final long MOD = 1_000_000_007;
    static final String YES = "Yes";
    static final String NO = "No";

    public static void main(String[] args) throws Exception {
        final MyScanner sc = new MyScanner();
        String S;
        S = sc.next();
        solve(S);
    }

    static void solve(String S){
        char[] c = S.toCharArray();
        if (c[2] == c[3] && c[4] == c[5]) System.out.println("Yes");
        else System.out.println("No");
    }


    static class MyScanner {
 
        BufferedReader br;
        StringTokenizer st;
 
        MyScanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }
 
        MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String nn() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        String next() {
            return nn();
        }

        String nextLine() {
            String ans = "";
            try {
                ans = br.readLine();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return ans;
        }
 
        char nextChar() {
            return nn().charAt(0);
        }
 
        int nextInt() {
            return Integer.parseInt(nn());
        }
 
        long nextLong() {
            return Long.parseLong(nn());
        }
 
        double nextDouble() {
            return Double.parseDouble(nn());
        }
 
        Integer[] niArr0(int n) {
            Integer[] ar = new Integer[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Integer[] niArr1(int n) {
            Integer[] ar = new Integer[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Long[] nlArr0(int n) {
            Long[] ar = new Long[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
 
        Long[] nlArr1(int n) {
            Long[] ar = new Long[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
    }

}


Measured memory_bytes: 23252