akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define N (long long)(1e9 + 7)
#define fin 61
using namespace std;

long long l, r;
long long dp[70][2][2];

long long solve();
long long cnt(long long nowl, long long nowr,
              long long dig);
bool ch(long long x, long long d);

int main() {
  cin >> l >> r;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0;
  for(int i = 0; i < fin; ++i) {
    long long nbase = 1LL << i, nmax = (1LL << (i + 1)) - 1;
    if(nmax < l || nbase > r) continue;
    ans +=
        cnt(max(nbase, l) - nbase, min(r, nmax) - nbase, i);
    ans %= N;
  }
  return ans;
}

long long cnt(long long nowl, long long nowr,
              long long dig) {
  for(int i = 0; i <= dig; ++i)
    for(int j = 0; j < 2; ++j)
      for(int k = 0; k < 2; ++k) dp[i][j][k] = 0;
  long long ans = 0;
  // i l r
  dp[0][0][0] = 1;
  for(int i = 0; i < dig; ++i) {
    bool flagr = ch(nowr, dig - 1 - i),
         flagl = ch(nowl, dig - 1 - i);
    if(flagr && flagl) {
      // use 1 1
      for(int j = 0; j < 2; ++j)
        for(int k = 0; k < 2; ++k)
          dp[i + 1][j][k] = dp[i][j][k];
      // use 0 1
      for(int j = 0; j < 2; ++j) {
        dp[i + 1][1][j] += dp[i][1][j];
        dp[i + 1][1][j] %= N;
      }
      // use 0 0
      dp[i + 1][1][1] += (dp[i][1][0] + dp[i][1][1]) % N;
      dp[i + 1][1][1] %= N;
    }
    else if(flagr) {
      // use 1 1
      for(int j = 0; j < 2; ++j)
        dp[i + 1][1][j] = (dp[i][0][j] + dp[i][1][j]) % N;
      // use 0 1
      for(int j = 0; j < 2; ++j)
        for(int k = 0; k < 2; ++k) {
          dp[i + 1][j][k] += dp[i][j][k];
          dp[i + 1][j][k] %= N;
        }
      // use 0 0
      for(int j = 0; j < 2; ++j) {
        dp[i + 1][j][1] += (dp[i][j][1] + dp[i][j][0]) % N;
        dp[i + 1][j][1] %= N;
      }
    }
    else if(flagl) {
      // use 1 1
      for(int j = 0; j < 2; ++j)
        dp[i + 1][j][1] = dp[i][j][1];
      // use 0 1
      dp[i + 1][1][1] += dp[i][1][1];
      dp[i + 1][1][1] %= N;
      // use 0 0
      for(int j = 0; j < 2; ++j) {
        dp[i + 1][1][j] += dp[i][1][j];
        dp[i + 1][1][j] %= N;
      }
    }
    else {
      // use 1 1
      dp[i + 1][1][1] = (dp[i][1][1] + dp[i][0][1]) % N;
      // use 0 1
      for(int j = 0; j < 2; ++j) {
        dp[i + 1][j][1] += dp[i][j][1];
        dp[i + 1][j][1] %= N;
      }
      // use 0 0
      for(int j = 0; j < 2; ++j)
        for(int k = 0; k < 2; ++k) {
          dp[i + 1][j][k] += dp[i][j][k];
          dp[i + 1][j][k] %= N;
        }
    }
  }
  for(int i = 0; i < 2; ++i)
    for(int j = 0; j < 2; ++j) {
      ans += dp[dig][i][j];
      ans %= N;
    }
  return ans;
}

bool ch(long long x, long long d) { return (x >> d) & 1; }

Measured memory_bytes: 3624
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

W, H, N = MAP()

left = 0
right = W
bottom = 0
top = H
 
for _ in range(N):
	x, y, a = MAP()
	if a == 1:
		left = max(x, left)
	elif a == 2:
		right = min(x, right)
	elif a == 3:
		bottom = max(y, bottom)
	elif a == 4:
		top = min(y, top
			)
if right - left < 0 or top - bottom < 0:
	print(0)
else:
	print((right-left)*(top-bottom))
	

Measured memory_bytes: 5712
#include<stdio.h>
#include<stdlib.h>
int cmp ( const void *a , const void *b )
{
return *(int *)a - *(int *)b;
}
int main()
{
    int a[200001];
	int m,n,i,z=0;
	scanf("%d",&m);
	for(n=0;n<m;n++)
		scanf("%d",&a[n]);
	qsort(a,n+1,sizeof(a[0]),cmp);
	for(i=0;i<m;i++)
	{
		if(a[i]==a[i+1])
		{z=1;break;}
	}
	if(z==1)
		printf("NO");
	if(z==0)
		printf("YES");
	return 0;
}

Measured memory_bytes: 1788
import java.util.*;
public class Main {
		
	public static void main(String[] args) {
		
		        Scanner sc = new Scanner(System.in);
		        int A = sc.nextInt(), B = sc.nextInt(), C = sc.nextInt();
		        int Big = Math.max(A, Math.max(B,C));
		        if (A==Big){
		            System.out.println(10*Big+B+C);
		        }else if (B==Big){
		            System.out.println(10*Big+A+C);
		        }else{
		            System.out.println(10*Big+A+B);
		        }
		     
	}

}

Measured memory_bytes: 35884
def main():
    N = int(input())
    D, X = map(int, input().split())
    l = []
    for i in range(N):
        l.append(int(input()))
    choco = 0
    for i in range(N):
        day = 1
        choco += 1
        multiply = 1
        while day <= D:
            day = l[i] * multiply + 1
            if day > D:
                break
            else:
                choco += 1
                multiply += 1
    print(choco + X)

main()

Measured memory_bytes: 9192
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e9;
const ll INF=2e18;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int dp[110][10010]={0};
int main(){
	int n,W;
	cin>>n>>W;
	vector<int>v(n),w(n);
	rep(i,n)cin>>v[i]>>w[i];
//	vector<vector<int> >dp(n+1,vector<int>(w+1));
	rep(i,110)rep(j,10010)dp[i][j]=-1;
	dp[0][0]=0;
	rep(i,n){
		rep(j,W+1)if(dp[i][j]>=0){
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			if(j+w[i]<=W)dp[i+1][j+w[i]]=max(dp[i+1][j+w[i]],dp[i][j]+v[i]);
		}
	}
	int out=0;
	rep(i,W+1)out=max(out,dp[n][i]);
	cout<<out<<endl;
}

Measured memory_bytes: 7396
import sys
def input():
    return sys.stdin.readline()[:-1]
n=int(input())
a=list(map(int,input().split()))
s=0
A=0
for i in range(n):
    s+=a[i]
    if i%2==0:
        if s<=0:
            A+=1-s
            s=1
    else:
        if s>=0:
            A+=s+1
            s=-1
B=0
s=0
for i in range(n):
    s+=a[i]
    if i%2==1:
        if s<=0:
            B+=1-s
            s=1
    else:
        if s>=0:
            B+=s+1
            s=-1
print(A if A<B else B)

Measured memory_bytes: 14648
# Try AtCoder
# author: Leonardone @ NEETSDKASU
############################################################
def gs() gets.chomp end
def gi() gets.to_i end
def gf() gets.to_f end
def gss() gs.split end
def gis() gss.map(&:to_i) end
def nmapf(n,f) n.times.map{ __send__ f } end
def ngs(n) nmapf n,:gs end
def ngi(n) nmapf n,:gi end
def ngss(n) nmapf n,:gss end
def ngis(n) nmapf n,:gis end
def arr2d(h,w,v=0) h.times.map{[v] * w} end
def for2p(hr,wr,&pr) hr.each{|i|wr.each{|j| yield(i,j)}} end
def nsum(n) n * (n + 1) / 2 end
def vcount(d,r=Hash.new(0)) d.inject(r){|m,e| m[e]+=1;m} end
############################################################

N, K = gis
D = gss

x = N
while x.to_s.each_char.any?{|y| D.include? y}
    x += 1
end

puts x



Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <string> 
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define lol long long
int main()
{
	int N;
	cin >> N;
	string S;
	cin >> S;
	vector<int> A(N + 1);
	A[0] = 0;
	for (int i = 1; i <= N; i++) {
		if (S[i - 1] == 'I') {
			A[i] = A[i - 1] + 1;
		}
		else {
			A[i] = A[i - 1] - 1;
		}
	}
	sort(A.begin(), A.end());
	cout << A[N] << endl;
}

Measured memory_bytes: 256
macro_rules! input {
    ($t:ty) => {
        {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty ;) => {
        {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ; $n:expr) => {
        (0..$n).map(|_|
            input!($t)
        ).collect::<Vec<_>>()
    };
}

fn main(){
    let s = input!(String);
    let mut ans = String::new();
    for c in s.chars(){
        match c {
            '0' => ans.push_str("0"),
            '1' => ans.push_str("1"),
            'B' => {ans.pop();},
            _ => {},
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
s = gets.chomp
k = gets.to_i
prenum = 1
pre = s[0]
cnt = []
len = s.length
(len-1).times do |i|
  if s[i+1] == pre
    prenum += 1
  else
    cnt << prenum
    prenum = 1
  end
  pre = s[i+1]
end
cnt << prenum
sum = 0
l = cnt.length
if l == 1
  sum = len * k / 2
elsif s[0] == s[-1]
  (l-2).times do |i|
    sum += cnt[i+1]/2
  end
  sum *= k
  connect = (cnt[0] + cnt[-1]) / 2
  sum += connect * (k-1)
  sum += cnt[0]/2 + cnt[-1]/2
else
  cnt.each do |x|
    sum += x/2
  end
  sum *= k
end
puts sum

Measured memory_bytes: 14248
chomp($s=<>);
($h,$w)=split/ /,$s;

while(<>){
    chomp;
    if($_ =~ /#/){
        push @ary,$_;
        $cnt++;
    }
}
%hash=();
for($i=0;$i<$cnt;$i++){
    for($j=0;$j<$w;$j++){
        if(substr($ary[$i],$j,1) eq "#"){
            $hash{$j}++;
        }elsif($hash{$j} eq ""){
            $hash{$j} = 0;
        }
    }
}

foreach (@ary){
    @tmp=split//,$_;
    $len=@tmp;
    for($i=0;$i<$len;$i++){
        if($hash{$i} == 0){
            $tmp[$i] = "";
        }
    }
    print join "",@tmp;
    print "\n";
}

#print $hash{1}." ".$hash{2}." ".$hash{3}." ".$hash{4};

Measured memory_bytes: 512
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
struct Node{
	int next;
	int to;
	int id;
	int col;
}a[200005];
int n,top,ans,head[100005];
void add(int x,int y,int id){
	a[++top].next=head[x];
	a[top].to=y;
	a[top].id=id;
	head[x]=top;
}
bool cmp(Node x,Node y){
	if(x.id!=y.id)return x.id<y.id;
	return x.col>y.col;
}
void dfs(int x,int fa,int col){
	int sum=0;
	for(int i=head[x];i;i=a[i].next){
		if(a[i].to!=fa){
			sum++;
			if(sum==col)sum++;
			a[i].col=sum;
			ans=max(ans,sum);
			dfs(a[i].to,x,sum);
		}
	}
}
int main(){
	in(n);
	for(int i=1;i<n;i++){
		int x,y;
		in(x);in(y);
		add(x,y,i);
		add(y,x,i);
	}
	dfs(1,0,0);
	cout<<ans<<endl;
	sort(a+1,a+(n-1)*2+1,cmp);
	for(int i=1;i<=(n-1)*2;i++){
		if(a[i].id!=a[i-1].id)printf("%d\n",a[i].col);
	}
	return 0;
}


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

int main() {
  int k,x;
  cin >>k>>x;
  
  if(k==1) cout << x <<endl;
  else{
    for(int i=x-k+1;i<x+k-1;i++){
      cout << i <<" ";
    }
    cout << x+k-1 <<endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int[] a = new int[3];
    	int i,j,b;

    	for(i=0;i<3;i++){
    		a[i] = sc.nextInt();
    	}

    	for(i=0;i<3;i++){
    		for(j=i;j<3;j++){
        		if(a[i] > a[j]){
        			b = a[i];
        			a[i] = a[j];
        			a[j] = b;
        		}
        	}
       	}
    	System.out.println(a[0] + " " + a[1] + " " + a[2]);
    }
}

Measured memory_bytes: 26040
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
int POW(int x,int k)
{
	int ans=1;
	for (;k;k>>=1,x=1LL*x*x%MOD) if (k&1) ans=1LL*ans*x%MOD;
	return ans;
}
int N,A,B;
int cal(int n,int m)
{
	long long mul=1;
	for (int i=n;i>n-m;--i) mul=mul*i%MOD;
	for (int i=1;i<=m;++i) mul=mul*POW(i,MOD-2)%MOD;
	return mul;
}
int main()
{
	cin>>N>>A>>B;
	long long Ans=POW(2,N)-1;
	Ans-=cal(N,A);
	Ans-=cal(N,B);
	Ans%=MOD;
	if (Ans<0) Ans+=MOD;
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
  int pm,pe,pj,pa,cl;
  int i=0,l;
  char a[100000];
  cin>>cl;
  while(cl!=0){
    l=i;
    for(int j=0;j<cl;j++){
      cin>>pm>>pe>>pj;
      pa=(pm+pe+pj)/3;
      if(pm==100||pe==100||pj==100||90<=(pm+pe)/2||80<=pa)a[i]='A';
      else if(70<=pa||((80<=pe||80<=pm)&&50<=pa))a[i]='B';      
      else a[i]='C';
      i++;
    }
    for(int j=l;j<i;j++)
      cout<<a[j]<<endl;
    cin >> cl;
  }
  
  
  return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int m,n,cnt;
inline int read(){
	char ch=getchar();int o=0;
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') o=(o<<3)+(o<<1)+(ch^48),ch=getchar();
	return o;
}
struct node{
	int id,val;
}a[100010];
inline bool cmp(node a,node b){
	return a.val <b.val ;
}
int main(){
	cin>>n;
	for(register int i=1;i<=n;i++){
		int x=read();
		a[i].val =x;
		a[i].id =i;
	}
	sort(a+1,a+n+1,cmp);
	for(register int i=1;i<=n;i++) cout<<a[i].id <<" ";
} 

Measured memory_bytes: 1536
#include <iostream>
#include <queue>

using namespace std;

int main(){
	int train[2];
	int bus[2];

	cin>>train[0]>>train[1];
	cin>>bus[0]>>bus[1];

	cout<<(train[0]<train[1]?train[0]:train[1])+(bus[0]<bus[1]?bus[0]:bus[1])
		<<endl;

	return 0;
}



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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(int argc, char** argv) {
    int n;
    cin >> n;
    bool r = true;

    int pt = 0;
    int px = 0;
    int py = 0;
    rep(i, n) {
        int t, x, y;
        cin >> t >> x >> y;

        if (r) {
            int dt = t - pt;
            int d = abs(x - px) + abs(y - py);

            if (d <= dt && d % 2 == dt % 2) {

            } else {
                r = false;
            }

            pt = t;
            px = x;
            py = y;
        }
    }

    if (r)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



// 操作2で要素のインデックスの偶奇は変えられない
int n, res;
pair<int,int> p[100100];

signed main() {
	cin >> n;
	rep(i,n) {
		cin >> p[i].first;
		p[i].second = i;
	}
	sort(p,p+n);
	rep(i,n) if (p[i].second%2!=i%2) res++;
	cout << res/2 << ln;
}


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


using namespace std;

/* macros */
#define all(v)			((v).begin()), ((v).end())
#define SIZE(v)			((int)((v).size()))
#define LOG(x)			log((double)x)
#define TOLOWER(x)          transform(all(x),x.begin(),::tolower)
#define TOUPPER(x)          transform(all(x),x.begin(),::toupper)
#define ROUND(x,m)			(round((double)x/m)*m)
#define DIGITS(x)			(floor(log10((double)x))+1)
#define READSTR(x)			getline(cin,x)
#define sort_g(a,b)              sort(a, b, greater<int>());
#define IOS() ios_base::sync_with_stdio(0);cin.tie(NULL);
#define REP(i, n) for (int i = 0; i < n; i++)
#define FILE_INPUT() 	freopen( "input.txt", "r", stdin)
#define FILE_OUTPUT()   freopen( "output.txt", "w", stdout)

/*typedefs*/
typedef long long ll;

/*functions*/
bool myCmp(pair<int,int> &p1 , pair<int,int>&p2)
{
    return p1.first > p2.first;
}
unsigned long long
choose(unsigned long long n, unsigned long long k) {
    if (k > n) {
        return 0;
    }
    unsigned long long r = 1;
    for (unsigned long long d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}
int toInt(string str) {
    int num;
    istringstream iss(str); //put string in input stream
    iss>>num; return num; //read from stream as integer
}

template <class T> string toStr(T par) {
    ostringstream oss;  //output stream string
    oss<<par;    //write par to the stream
    return oss.str(); //return string of output
}

const int MAXN = 50;
int arr[MAXN] = {0};

int main() {
    IOS();
    string s;
    cin>>s;
    int st = 0 ,ed = s.size()-1 ;
    while(s[st] == 'T') st++;
    //st is the first index with no T
    while(s[ed] == 'S') ed--;
    int ans  = 0;
    if(st >= ed)
    {
        cout<<s.size()<<endl;
    }
    else
    {
        int cnt_t = 0;
        int cnt_s = 0;
        for(int i = st ; i <=ed ;i++)
        {
            if(s[i] == 'S') cnt_s++;
            else {
                if(cnt_s > 0)
                {
                cnt_s--;
                ans+=2;
                }
            }
        }
        cout<<s.size()-ans<<endl;

    }

    return 0;
}


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

using namespace std;

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

	int n;
	cin >> n;
	pair<char, pair<char, char>> p[] = {
		{ 'S', { 'S', 'W' } },
		{ 'S', { 'W', 'S' } },
		{ 'W', { 'S', 'W' } },
		{ 'W', { 'W', 'S' } }
	};
	string t;
	cin >> t;
	for (auto &it : p) {
		bool g = true;;
		string s(n, 'l');
		s[0] = it.first;
		for (int i = 0; i < n; i++) {
			char c = t[i];
			int prev = ((i - 1) % n + n) % n;
			int next = ((i + 1) % n + n) % n;
			if (s[i] == 'W') {
				c = c == 'o' ? 'x' : 'o';
			}
			if (c == 'o') {
				if (s[prev] != s[next]
				    && s[prev] != 'l' && s[next] != 'l') {
					g = false;
					break;
				}
				if (s[prev] == 'l' && s[next] != 'l') {
					s[prev] = s[next];
				} else if (s[next] == 'l' && s[prev] != 'l') {
					s[next] = s[prev];
				} else if (s[prev] == 'l') {
					s[prev] = s[next] = it.second.first;
				}
			} else {
				if (s[prev] == s[next]
				    && s[prev] != 'l' && s[next] != 'l') {
					g = false;
					break;
				}
				if (s[prev] == 'l' && s[next] != 'l') {
					s[prev] = s[next] == 'S' ? 'W' : 'S';
				} else if (s[next] == 'l' && s[prev] != 'l') {
					s[next] = s[prev] == 'S' ? 'W' : 'S';
				} else if (s[prev] == 'l') {
					s[next] = it.second.first;
					s[prev] = it.second.second;
				}
			}
		}
		if (g) {
			cout << s << '\n';
			return 0;
		}
	}
	cout << "-1\n";

	return 0;
}



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

 ll dp[1000000];

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

    int n;
    while(cin>>n){
        if(n==0) break;
        ll k[n],t[n][n];
        for(int i=0;i<n;i++){
            cin>>k[i];
            for(int j=0;j<n;j++){
                cin>>t[i][j];
            }
        }
        for(int i=0;i<=(1LL<<n);i++) dp[i]=1e9;
        dp[0]=0;
 
        
        for(int bit=0;bit<(1LL<<n);bit++){
            for(int i=0;i<n;i++){
                if(bit&(1LL<<i)){
                    ll cost = k[i];
                    for(int j=0;j<n;j++){
                        if(j!=i && bit&(1LL<<j)){
                            cost = min(cost,t[i][j]);
                        }
                    }
                    dp[bit] = min(dp[bit],dp[bit^(1LL<<i)]+cost);
                }
            }
        }
        cout << dp[(1LL<<n) -1] << endl;
        


    }
    
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

i64 gcd(i64 a, i64 b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

int main() {
  i64 N, K;
  cin >> N >> K;
  N %= K;
  cout << std::min(K - N, N) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL INF = 1e18;
const int maxl = 10010;

int n;
long long sum1,sum2;
int a[maxl],b[maxl],c[maxl];

inline void prework()
{
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		scanf("%d",&b[i]),c[i]=b[i]-a[i];
}

inline void mainwork()
{
	sum1=0;sum2=0;
	for(int i=1;i<=n;i++)
	if(c[i]>0)
		sum1+=c[i]/2;
	else
		sum2-=c[i];
}

inline void print()
{
	if(sum1<sum2)
		puts("No");
	else
		puts("Yes");
}

int main()
{
	while(~scanf("%d",&n))
	{
		prework();
		mainwork();
		print();
	}
    return 0;
}
/*

*/


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

int main() {
	int n;
	cin >> n;
	map<string, int> mp;
	rep(i,n) {
		string s;
		cin >> s;
		mp[s]++;
	}
	int mx = 0;
	for (auto p : mp)	mx = max(mx, p.second);
	for (auto p : mp) {
		if (p.second == mx)	cout << p.first << endl;
	}



}

Measured memory_bytes: 25216
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
    static void Main(string[] args){
    var vals = Console.ReadLine().Split().Select(a => int.Parse(a)).ToList();
    long W=vals[0];
    long H=vals[1];
    long x=vals[2];
    long y=vals[3];
    long w=W-x;
    if(w>x){w=x;}
    long h=H-y;
    if(h>y){h=y;}
    double S1=w*H;
    double S2=h*W;
    bool flag=false;
	//中心を通る分割を考えればいいだけの話（必ず1/2Sになりはず）なのだが、
    //サンプルから勝手に類推して垂直・平行な直線に切るパターンのみを考えていた。
    //しかも、その方針でもWAが1サンプル分しか出なかったので、一般的な状況でエラーが起こっていると思えず
    //方針に固執してしまった。
    if(S1==0){
        S1=W*H*0.5;
        flag=true;
    }
    if(S2==0){
        S2=W*H*0.5;
        flag=true;
    }
    if(S1!=W*H*0.5&&S2!=W*H*0.5){
        S1=S2=W*H*0.5;
        flag=true;
    }
    if(S1>S2){
        Console.WriteLine("{0} {1}",S1,0);
    }
    else if(S1==S2){
        if(flag){
            Console.WriteLine("{0} {1}",S1,0);
        }
        else{
         Console.WriteLine("{0} {1}",S1,1);}
    }
    else{
           Console.WriteLine("{0} {1}",S2,0);
    }
    
    }
}


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

int main() {
  int A, B;
  cin >> A >> B;
  
  if ((A==1 && B==2) || (A==2 && B==1)) {
    cout << 3 << endl;
  } else if ((A==2 && B==3) || (A==3 && B==2)) {
    cout << 1 << endl;
  } else {
    cout << 2 << endl;
  }
  
  
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n, m, a[30][30], b[30], c;
int main()
{
	cin >> n >> m >> c;
	for (int i = 1; i <= m; ++i) cin >> b[i];
	for (int i = 1; i <= n; ++i) {
	for (int j = 1; j <= m; ++j)
	cin >> a[i][j], a[i][0] += a[i][j] * b[j];
	if (a[i][0] + c > 0) ++b[0]; }
	printf("%d", b[0]); return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int k = in.nextInt();
        
        for (int i = 100; i >= 1; i--)
            if (a %i == 0 && b %i == 0)
            {
                k--;
                if (k == 0)
                {
                    System.out.println(i);
                    break;
                }
            }
        
        in.close();
    }
}

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

using namespace std;
using ll = long long;
constexpr int INF = 1 << 29;

int main() {
    ll x,y;
    cin >> x >> y;
    if (x % y == 0) {
        cout << -1 << endl;
        return 0;
    }
    cout << x*(y-1) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<string>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
int main() {
  int x,a;
  cin >> x >> a;
  if (x < a) {
    cout << 0 << endl;
  }
  else cout << 10 << endl;
}
  

Measured memory_bytes: 256
#include<map>
#include<cstdio>
#include<algorithm>
using namespace std;
#define mp make_pair
map<pair<long long,long long>,long long>Map;
int n,f[105];
long long ans=0;
char st[105],str[105];
void dfs(int t,int v)
{
	if (t>n)
	{
		long long x=0,y=0;
		for (int i=1; i<=n; i++)
			if (f[i]) x=x*27+st[i]-97+1;
		for (int i=n; i>=1; i--)
			if (!f[i]) y=y*27+st[i]-97+1;
		if (v==0) Map[mp(x,y)]++;
		else ans+=Map[mp(y,x)];
		return;
	}
	f[t]=0; dfs(t+1,v);
	f[t]=1; dfs(t+1,v);
}
int main()
{
	scanf("%d%s",&n,str+1);
	for (int i=1; i<=n; i++) st[i]=str[i]; dfs(1,0);
	for (int i=1; i<=n; i++) st[i]=str[i+n]; dfs(1,1);
	printf("%lld\n",ans);
	return 0;
}



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

// boost
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
using vld = vector<ld>;
using vvld = vector<vld>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

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

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
// #define mod (998244353ll)

const long long INF = 1LL << 60;

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

  ll x;
  cin >> x;

  ll tmp = x;
  ll s = 0;
  while (tmp) {
    s += tmp % 10;
    tmp /= 10;
  }

  cout << ((x % s) ? "No" : "Yes") << endl;

  return 0;
}


Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    int n;
    cin >> n;
    int a[n];
    rep(i, n) { cin >> a[i]; }
    ll cost = pow(10, 9);
    ll temp = 0;
    repd(i, -100, 101) {
        temp = 0;
        rep(j, n) { temp += (a[j] - i) * (a[j] - i); }
        cost = min(cost, temp);
    }

    cout << cost << endl;
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=0;i<(n);++i)
#define rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep4(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vec vector<ll>
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

void solve(){
    ll n;cin>>n;
    vec h(n);
    rep(i,n)cin>>h[i];
    vec dp(n+5,LINF);
    dp[0]=0;
    rep(i,n){
        chmin(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
        chmin(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
    }
    cout<<dp[n-1]<<endl;
}

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


Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,N,M,x,cnt=0,l,ans=0;
  cin>>N>>M;
  cin>>l;
  while(l%2==0){
    l/=2;
    cnt++;
  }
  rep1(i,N){
    cin>>x;
    rep(j,cnt){
      if(x&1){
        cout<<0<<endl;
        return 0;
      }
      x/=2;
    }
    if(x%2==0){
      cout<<0<<endl;
      return 0;
    }
    l=lcm(l,x);
    if(l>M){
      cout<<0<<endl;
      return 0;
    }
  }
  rep1(i,cnt){
    l*=2;
    if(l>M){
      cout<<0<<endl;
      return 0;
    }
  }
  cout<<(M/l+1)/2<<endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
ll a[200010],h[200010];
ll d[200010],mx[450];
ll pos[200010];
int len;
int main()
{
	scanf("%d",&n);
	len=(int)sqrt(n);
	for (int i=0;i<n;i++)
	{
		scanf("%I64d",&h[i]);
		h[i]--;
		pos[h[i]]=i;
	}
	for (int i=0;i<n;i++) scanf("%I64d",&a[i]);
	for (int i=0;i<n;i++)
	{
		int x=pos[i];
		if (!x)
		{
			d[x]=a[x];
			mx[x/len]=max(mx[x/len],d[x]);
			continue;
		}
		ll res=0;
		if (x-1>=len)
		{
			for (int j=0;j<(x-1)/len;j++) res=max(res,mx[j]);
			for (int j=0;j<=(x-1)%len;j++) res=max(res,d[(x-1)/len*len+j]);
		}
		else for (int j=0;j<x;j++) res=max(res,d[j]);
		d[x]=res+a[x];
		mx[x/len]=max(mx[x/len],d[x]);
		//cout <<x+1<<" "<<d[x]<<" ##\n";
	}
	cout <<*max_element(d,d+n);
	return 0;
} 

Measured memory_bytes: 6528
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())


N = inp()
if N <= 3:
    print(1)
else:
    ans = 1
    while True:
        N = (N+2)//3
        ans += 1
        if N<= 3:
            break
    print(ans)



Measured memory_bytes: 7148
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	string S;
	cin>>S;
	int N = S.size();
	rep(i,N-1){
		if(S[i] == S[i+1]){
			cout<<i+1<<" "<<i+2<<endl;
			return 0;
		}
	}
	rep(i,N-2){
		if(S[i] == S[i+2]){
			cout<<i+1<< " " << i+3<<endl;
			return 0;
		}
	}
	
	cout<< -1 << " " << -1 <<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const int INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou((int)bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<int> hukasa;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
    }
    else{
      par.at(rx) = ry;
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};

int main(){
  long long x,k,d;
  cin >> x >> k >> d;
  if(x < 0)x*=(-1);
  if(x/d >= k){
    cout << x-k*d << endl;
  }
  else{
    long long a = x / d;
    x = x - a*d;
    a = k-a;
    long long b = a/2;
    if(a - 2*b ==1){
      cout << d-x << endl;
    }
    else{
      cout << x << endl;
    }
  }
}

Measured memory_bytes: 3584
#include<iostream>
#define ll long long int
using namespace std;
 
int main()
{
  string s;
  ll k;
  cin >> k;
  cin >> s;
  ll l = s.length();
  if(l<=k)
    cout << s << endl;
  else
  {
    for(ll i = 0; i < k; i++)
    {
      cout << s[i];
    }
      cout << "..." << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int a;
  cin >> a;
  cout << a+a*a+a*a*a << endl;
}


Measured memory_bytes: 3672
def factorization(n):
    def sieve(n):
        is_prime = [True for _ in range(n+1)]
        is_prime[0] = False

        for i in range(2, n+1):
            if is_prime[i-1]:
                j = 2 * i
                while j <= n:
                    is_prime[j-1] = False
                    j += i
        table = [ i for i in range(1, n+1) if is_prime[i-1]]
        return table
    arr = []
    temp = n
    for i in sieve(int(n**0.5)):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
cnt=1
n=int(input())
ans=0
for i in range(1,n+1,2):
    a=factorization(i)
    for j in range(len(a)):
        cnt*=a[j][1]+1
    if cnt==8:
        ans+=1
    cnt=1
print(ans)

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

int main()
{
    ll i, j, m, t, ans = 0, n, k, ro, se, pa;
    string s;
    cin >> n >> k;
    cin >> ro >> se >> pa;
    cin >> s;

    for(i = 0; i < s.size() - k; i++){
        if(s[i] == s[i + k])
            s[i + k] = '0';
    }

    for(i = 0; i < s.size(); i++){
        if(s[i] == 'r')
            ans += pa;
        else if(s[i] == 's')
            ans += ro;
        else if(s[i] == 'p')
            ans += se;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int N, K;
	cin >> N >> K;
	double ans = 0;
	rep(i, N) {
		int tmp = i + 1;
		double c = 1;
		while (tmp < K) tmp = tmp << 1, c /= 2;
		ans += c;
	}
	ans /= N;
	printf("%0.9f\n", ans);
}


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

int main() {
    int a,b,c;
    string ans="No";
    cin>>a>>b;
    if(b<10){
        c=a*10+b;
    }else if(b<100){
        c=a*100+b;
    }else{
        c=a*1000+b;
    }
    for(int i=1;i*i<=c;i++){
        if(i*i==c){
            ans="Yes";
        }
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dat[800010];
ll u;
void seginit(ll n){
  for(int i=0;;i++){
    ll y=pow(2,i);
    if(y>=n){
      u=y;
      break;
    }
  }
  fill(dat,dat+2*u,0);
}
void add(ll n,ll x){
  ll i=u+n-1;
  dat[i]=x;
  while(i>0){
    i=(i-1)/2;
    dat[i]=max(dat[2*i+1],dat[2*i+2]);
  }
}
ll que(ll a,ll b,ll k,ll l,ll r){
  if(a>=r||b<=l)return 0;
  if(a<=l&&b>=r)return dat[k];
  else{
    ll m1=que(a,b,2*k+1,l,(l+r)/2);
    ll m2=que(a,b,2*k+2,(l+r)/2,r);
    return max(m1,m2);
  }
}
int main(){
  ll n;cin>>n;
  ll h[n];
  for(int i=0;i<n;i++)cin>>h[i];
  ll a[n];for(int i=0;i<n;i++)cin>>a[i];
  seginit(n+2);
  for(int i=0;i<n;i++){
    ll y=que(1,h[i],0,0,u);
    add(h[i],y+a[i]);
  }
  ll ans=que(1,n+1,0,0,u);
  cout<<ans<<endl;
}

Measured memory_bytes: 9472
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <cstdio>
#include <cmath>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using P1 = pair<int, P>;
#define FOR(t, a, b) for (int t = (a); t < (b); ++t)
#define REP(t, n) FOR(t, 0, n)

int main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> x, y, z;
    for (ll i = 0; i < n; i++)
    {
        ll tx, ty, tz;
        cin >> tx >> ty >> tz;

        x.push_back(tx);
        y.push_back(ty);
        z.push_back(tz);
    }

    vector<ll> koho;
    for (ll i = -1; i <= 1; i += 2)
    {
        for (ll j = -1; j <= 1; j += 2)
        {
            for (ll k = -1; k <= 1; k += 2)
            {
                vector<ll> sum;
                for (ll l = 0; l < n; l++)
                {
                    ll temp = i * x[l] + j * y[l] + k * z[l];
                    sum.push_back(temp);
                }
                sort(sum.begin(), sum.end(), std::greater<ll>());
                // for (int hoge = 0; hoge < n; hoge++)
                // {
                //     cout << sum[hoge] << " ";
                // }
                // cout << endl;
                ll kohotemp = 0;
                for (ll l = 0; l < m; l++)
                {
                    kohotemp += sum[l];
                }
                koho.push_back(kohotemp);
            }
        }
    }
    sort(koho.begin(), koho.end(), std::greater<ll>());
    cout << koho[0] << endl;

    return 0;
}


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

#define ll long long int
#define endl '\n'
#define inf 1e18
ll val[100005];
ll w[100005];
ll ans[105][100005];
ll getAns(ll n,ll W)
{
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=W;j++)
        {
            if(i==0 || j==0)
            {
                ans[i][j]=0;
            }
            else if(w[i]<=j)
            {
                ans[i][j]=max(ans[i-1][j],ans[i-1][j-w[i]]+val[i]);
            }
            else{
                ans[i][j]=ans[i-1][j];
            }
        }
    }
    return ans[n][W];
}
void testCase()
{
    
   // ll t; cin>>t; while(t--)
    {
        ll n,W;
        cin>>n>>W;

        for(int i=1;i<=n;i++)
        {
            cin>>w[i]>>val[i];
        }

        cout<<getAns(n,W);
    }       
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    testCase();
    return 0;
}

Measured memory_bytes: 82520
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <string>
#include <functional>
#include <cassert>
#include <cmath>
#define SIZE 100005
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main()
{
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    vector<int> vec;
    for (int i=0; i<n; i++)
    {
        scanf("%d", &a[i]);
        vec.emplace_back(a[i]);
    }
    
    sort(a.begin(), a.end());
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    if (vec.size() == 1 && vec[0] == 0)
    {
        puts("Yes");
        return 0;
    }
    if (vec.size() > 3 || vec.size() == 1 || n%3 != 0)
    {
        puts("No");
        return 0;
    }

    vector<int> b;
    b.emplace_back(vec[0]);
    b.emplace_back(vec[1]);
    int pre_back = vec[0];
    for (int i=2; i<n; i++)
    {
        int now_back = b.back();
        b.emplace_back(pre_back ^ now_back);
        pre_back = now_back;
    }
    sort(b.begin(), b.end());
    if(a == b) puts("Yes");
    else puts("No");

	return 0;
}

Measured memory_bytes: 1784
N,M = map(int,input().split())
sa = abs(N-M)

def factorial_mod(A):
    kaiji = 1
    for i in range(A):
        kaiji*=(i+1)
        kaiji = kaiji%1000000007
    return kaiji
    
if sa >= 2:
    print(0)
elif sa == 1:
    n = N%1000000007
    m = M%1000000007
    nn = factorial_mod(n)
    mm = factorial_mod(m)
    ans =(nn*mm)%1000000007
    print(ans)
else:
    n = N%1000000007
    m = M%1000000007
    nn = factorial_mod(n)
    mm = factorial_mod(m)
    ans = (2*nn*mm)%1000000007
    print(ans)

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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n;
	cin>>n;
	if (n==3||n==5||n==7){
		cout<<"YES";
	}
	else {
		cout<<"NO";
	}
	return 0;
}

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

namespace AtCode
{
    class Class1
    {
        static void Main(string[] args)
        {
            int Input = Convert.ToInt32(Console.ReadLine());
            int BigCoin = Input / 500;
            Input = Input - BigCoin * 500;
            int SmallCoin = Input / 5;
            int Happy = BigCoin * 1000 + SmallCoin * 5;
            Console.WriteLine(Happy);
            
            
        }
        

       
    }
    
}

Measured memory_bytes: 11348