akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
 int n,k;
  cin >> n >> k;
  
  int s=1;
  int s1,t1;
  for( int i=0; i<n; i++){
    s1 = 2*s;
    t1 = k+s;
    if(s1 <= t1){
    	s = s1;
    }else{
    	s = t1;
    }
  }
  cout << s << endl;
  
}


Measured memory_bytes: 256
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<deque>
#include<iomanip>
#include<set>
#include<unordered_set>
#include<tuple>
#include<map>
#include<memory>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<double> VD;
typedef pair<int, int> P1;
typedef long long int ll;

//number
#define INF 1e9
#define NUM 1000000007

//itr
#define all(x) begin(x),end(x)

//repeat
#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++)

//max,min
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

//function

/*ll gcd(ll a, ll b) {
	if (b == 0) return a;
	else return gcd(b, a%b);
}*/

/*ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	retur5n a * (b / g);
}*/

int dig(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}

//grid template
int x[] = { -1, 0, 1, 0 };
int y[] = { 0,-1,0,1 };
int xx[] = { -1,-1,1,1 };
int yy[] = { 1,-1,1,-1 };

int main() {
	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<unordered_map>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep2(i,n) for(int i = -1; i < (n); i++)
#define PI 3.141592653589793

using namespace std;
using ll = unsigned long long;


int main() {

	ll n, k;

	cin >> n >> k;

	ll n1 = n % k;
	ll n2 = -1*(n1-k);
	

	if (n1 <= n2) { cout << n1 << endl; }
	else {
		cout << n2 << endl;
	}

	return 0;
}

Measured memory_bytes: 3572
n,a,b = map(int, input().split())

p = 10 ** 9 + 7
N = 10 ** 5 *5  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)


# def f(x):
#     if x==1:
#         return 2
#     elif x==2:
#         return 4
#     elif x%2==0:
#         return f(x//2)**2
#     else:
#         return f(x//2)**2*2

di131072 = 1
for i in range(131072):
    di131072 *= 2
    di131072 %= p

q = n//131072
r = n%131072
ans = 1
for i in range(q):
    ans *= di131072
    ans %= p
for i in range(r):
    ans *= 2
    ans %= p


fact2 = []
fact2num = max(a,b)+2
now = 1
for i in range(fact2num):
    now *= (n-i)
    now %= p
    fact2.append(now)

def ncr(n,r):
    return (fact2[r-1]*factinv[r])%p


print((ans-1-ncr(n,a)-ncr(n,b))%p)


Measured memory_bytes: 70380
#include <stdio.h>

int main()
{
    int n;
    scanf("%d", &n);
    int a[n];

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


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

using namespace std;

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

int main() {
    int a, b;
    cin >> a >> b;
    cout << gcd(a, b) << endl;
    return 0;
}


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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH ;//<<"reached line "<<__LINE__<<endl
#define DMP(x) ;//<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

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

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

const int Nmax=20;
int n,m;
int dp[1<<Nmax][Nmax];
int w[1<<Nmax];
int g[Nmax][Nmax];
bool ok[1<<Nmax];
bool reached[1<<Nmax][Nmax];
bool vis[Nmax];

int dfs(int v){
	if(vis[v])return 0;
	vis[v]=true;
	int res=1;
	REP(i,n)if(g[v][i])res+=dfs(i);
	return res;
}

signed main(){
	n=read(),m=read();
	int ans=0;
	REP(_,m){
		int a=read()-1,b=read()-1,c=read();
		ans+=c;
		g[a][b]=c;
		g[b][a]=c;
	}
	FOR(bits,1,1<<n){
		memset(vis,0,sizeof(vis));
		int cnt=0;
		REP(i,n)
			if((bits>>i)&1)
				cnt++;
			else
				vis[i]=1;
		REP(i,n)if((bits>>i)&1){
			ok[bits]=(dfs(i)==cnt);
			break;
		}
	}
	FOR(bits,1,1<<n)if(ok[bits]){
		REP(i,n)if((bits>>i)&1)
		REP(j,i)if((bits>>j)&1)
			w[bits]+=g[i][j];
		if((bits&1)&&!((bits>>(n-1))&1)){
			dp[bits][0]=w[bits];
			reached[bits][0]=1;
		}
	}
	FOR(bits,2,1<<n)if(bits&1){
		int x=bits;
		do{
			int y=bits-x;
			if(x>0&&y>0&&(x&1)&&ok[y]){
				REP(i,n)if((x>>i)&1)if(reached[x][i])
				REP(j,n)if((y>>j)&1)if(g[i][j]){
					chmax(dp[bits][j],dp[x][i]+w[y]+g[i][j]);
					reached[bits][j]=1;
				}
			}
			x=(x-1)&bits;
		}while(x!=bits);
	}
	cout<<ans-dp[(1<<n)-1][n-1]<<endl;
}

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

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  
  if(n%2==1){
    puts("No");
    return 0;
  }
  
  string l = s.substr(0,n/2);
  string r = s.substr(n/2,n/2);
  
  if(l==r) puts("Yes"); else puts("No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long

using namespace std;

const int MOD = 1000000007;

int main() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);

  if (a + b + c >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
struct Graph
{
  vector<vector<pair<pair<int,ll>,bool>>> edge;
  int n;
  vector<ll> d;
  vector<int> flag;
  
  Graph(int _n)
  {
    n = _n;
    edge.resize(n);
    d.assign(n,-1);
    flag.assign(n,0);
  }

  void add(int from,int to,ll cost)
  {
    edge[from].push_back(make_pair(make_pair(to,cost),0));
  }
  
  bool dfs(int v)
  {
    bool f = true;
    flag[v] = true;
    rep(i,edge[v].size()){
      if(edge[v][i].second) continue;
      edge[v][i].second = true;
      int w = edge[v][i].first.first;
      ll co = edge[v][i].first.second;
      if(d[w]==-1) {
	d[w] = d[v] + co;
	f = f&&dfs(w);
      }
      else{
	if(d[w]-d[v]!=co) return false;
      }
    }
    return f;
  }
};
int main()
{
  int n,m;
  cin >> n >> m;
  vector<int> l(m),r(m);
  vector<ll> d(m);
  rep(i,m){
    cin >> l[i] >> r[i] >> d[i];
    l[i]--;
    r[i]--;
  }

  Graph gp(n);
  rep(i,m){
    gp.add(l[i],r[i],d[i]);
    gp.add(r[i],l[i],-d[i]);    
  }

  bool f = true;
  rep(i,n){
    if(gp.flag[i]) continue;
    gp.d[i] = 0;
    f = f&&gp.dfs(i);
  }

  cout << (f?"Yes":"No") << "\n";
  
  return 0;
}


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

using namespace std;

int a[200000];
vector <int> v[30][2];

int main() {
    int n, ans = 0, i, j, k;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    for (i = 0; i < n; i++) {
        int x;
        
        scanf("%d", &x);
        
        for (j = 0; j < 30; j++) v[j][(x >> j) & 1].push_back(x & ((1 << j) - 1));
    }
    
    for (i = 0; i < 30; i++) {
        for (j = 0; j < 2; j++) {
            sort(v[i][j].begin(), v[i][j].end());
        }
    }
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < 30; j++) {
            int p = ((a[i] >> j) & 1);
            int q = (a[i] & ((1 << j) - 1));
            
            for (k = 0; k < 2; k++) {
                int c;
                
                if (v[j][k].size() == 0) continue;
                
                c = lower_bound(v[j][k].begin(), v[j][k].end(), (1 << j) - q) - v[j][k].begin();
                
                if (p ^ k) {
                    if (c & 1) ans ^= (1 << j);
                } else {
                    if ((v[j][k].size() - c) & 1) ans ^= (1 << j);
                }
            }
        }
    }
    
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 32124
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,x,n) for(ll i=x;i<n;i++) 
#define S(v) sort(v.begin(),v.end());


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    cout<<10 - (n/100)/2;
    

}

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

const ll INF = 1e18;
int n;
vector<ll> a, pref;
vector<vector<ll>> dp;

ll rec(int l, int r) {
	if (l == r) {
		return 0;
	}
	if (dp[l][r] != -1) {
		return dp[l][r];
	}
	dp[l][r] = INF;
	for (int i = l; i < r; i++) {
		dp[l][r] = min(dp[l][r], rec(l, i) + rec(i + 1, r));
	}
	dp[l][r] += (pref[r + 1] - pref[l]);
	return dp[l][r];
}

int main() {
	ios_base::sync_with_stdio(false);

	cin >> n;
	a.resize(n);
	pref.resize(n + 1);
	pref[0] = 0;
	dp.resize(n, vector<ll> (n, -1));
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		pref[i + 1] = pref[i] + a[i];
	}
	ll answer = rec(0, n - 1);
	cout << answer;

	return 0;
}

Measured memory_bytes: 1536
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        long[] a = sc.nextLongArray(n);
        Arrays.sort(a);
        pw.println(a[n-1] - a[0]);
        pw.flush();
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }
 
        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }
 
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


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

int mod = 1000000007;

int bikkuri(int k){ //階乗
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i%mod;
        sum%=mod;
    }
    return sum;
}

ll mul(ll a, ll b){ //mul,power, div2はセット
    return ((a % mod) * (b % mod))%mod;
}

ll power(ll x, ll y){ //mul,power, div2はセット
    if(y == 0) return 1;
    else if(y == 1) return x%mod;
    else if(y % 2 == 0) return (power(x, y/2)*power(x, y/2))%mod;
    else return (power(x, y/2)*power(x, y/2))%mod*x%mod;
}

ll div2(ll a, ll b){ //mul,power, div2はセット
    return mul(a, power(b, mod-2));
}



signed main(){
    int x,y;
    cin >> x >> y;
    if((2*x-y)%3!=0 || (2*y-x)%3!=0 || 2*x-y<0 || 2*y-x<0){
        cout << 0 << endl;
        return 0;
    }

    int a = (2*x-y)/3;
    int b = (2*y-x)/3;

    ll ans = div2(bikkuri(a+b)%mod,bikkuri(a)%mod*bikkuri(b)%mod);

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>
#include<tuple>
#include<stack>


using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tpl;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 100005

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

set<int> a[ARRAY_MAX];

int main() {

	ll n;
	cin >> n;
		
	for (int i = 1; i <= n; i++)
	{
		int tmp;
		cin >> tmp;
		a[i].insert(tmp);
	}

	int ans = 0;
	for (int i = 1; i <= n; i++)
	{
		for (auto itr : a[i])
		{
			if (i >= itr)
			{
				continue;
			}
			if (a[itr].count(i) > 0)
			{
				ans++;
			}
		}
	}

	cout << ans << endl;
	return 0;
}


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

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
using Graph = vector<vector<int>>;
inline int in() { int x; cin >> x; return x; }

int counte;
vector<bool> seen;
vector<bool> watch;
vector<int> member;
vector<int> F[100100];
vector<int> B[100100];
int answer[100100];
void dfs(int v) {
  if (!seen[v]) {
    counte++;
    member.push_back(v);
  }
  seen[v] = true;
  watch[v] = true;
  for (auto next_v : F[v]) {
    if (seen[next_v]) continue;
    dfs(next_v); // 再帰的に探索
  }
}

int main(){
  int N = in(), M = in(), K = in();
  watch.assign(N,false);
  //Graph F(N),B(N);
  REP(i,M) {
    int a = in()-1, b = in()-1;
    F[a].push_back(b);
    F[b].push_back(a);
  }
  REP(i,K) {
    int a = in()-1, b = in()-1;
    B[a].push_back(b);
    B[b].push_back(a);
  }
  REP(i,N) {
    if (watch[i] == 0) {
      counte = 0;
      seen.assign(N,false);
      member.assign(0,0);
      dfs(i);
      REP(l,member.size()){
        int counter = 0;
        REP(k,B[member[l]].size()){
          if(seen[B[member[l]][k]] == 1)counter++;
        }
        REP(k,F[member[l]].size()){
          if(seen[F[member[l]][k]] == 1)counter++;
        }
        answer[member[l]] = counte - counter - 1;
      }
    }
  }
  REP(i,N) cout << answer[i] << endl;
}


Measured memory_bytes: 13052
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s; cin >> s;
  if(s == "RRR") cout << 3 << endk;
  else if(s.substr(0, 2)=="RR" || s.substr(1, 2)=="RR") cout << 2 << endk;
  else if(s[0]=='R' || s[1]=='R' || s[2]=='R') cout << 1 << endk;
  else cout << 0 << endk;
  return 0;
}


Measured memory_bytes: 3640
import sys
import itertools
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s = S()

tmp = ""
ans = 0
for i in s:
  if i != tmp:
    ans += 1
    tmp = i
  else:
    continue
else:
  if i != tmp:
    ans += 1
print(ans)

Measured memory_bytes: 39280
def gi; gets.to_i end
def gs; gets.chomp end
def gli; gets.split(' ').map(&:to_i) end
def d(n); Math.log10(n).to_i + 1 end
class Integer
  # 約数の組み合わせを列挙する
  def divisor_combinations
    (1..Math.sqrt(self).to_i).
      select { |i| self % i == 0 }.
      map { |i| [i, self / i] }
  end
end

K, X = gli

puts 500 * K >= X ? 'Yes' : 'No'


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <cassert>
#include <cmath>

using ll = long long;

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int main() {
  int n, m, a, b;
  std::cin >> n >> m >> a >> b;
  for(int i = 1;i <= n; i++) {
    for(int j = 1;j <= m; j++)
      std::cout << ((i <= b) ^ (j <= a));
    std::cout << '\n';
  }
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
string s;
int main(void){
    cin>>s;
    for(int i=0;i<3;i++){
        if(s[i]=='7'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    
}


Measured memory_bytes: 3612
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,M = map(int, readline().split())
A = np.array(list(map(int, readline().split())))

sum_A = A.sum()
select_num = sum_A * (1/(4*M))
A = A // select_num
ans = 0
for i in range(len(A)):
  if A[i] < 1:
    A[i] = 0
  else:
    A[i] = 1

print('Yes' if A.sum() >= M else 'No')


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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 100007;

int n, k;
int a[MAXN];
LL psp[MAXN], ps[MAXN];

void init ();
void input ();
void work ();



int main()
{
	init();
	input();
	work();
}



void init ()
{
	// Init Everything Here
	
	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method
	
	scanf ( "%d%d", &n, &k );
	lpi ( i, 1, n ) scanf ( "%d", &a[i] );
}

void work ()
{
	// main work
	
	lpi ( i, 1, n ) psp[i] = psp[i-1] + qmax ( a[i], 0 ), ps[i] = ps[i-1] + a[i];
	
	LL ans = 0;
	lpi ( i, 1, n-k+1 ) ans = max ( ans, psp[i-1] + psp[n] - psp[i+k-1] + max ( ps[i+k-1] - ps[i-1], 0LL ) );
	
	cout << ans << endl;
}

Measured memory_bytes: 2176
#include<iostream>

using namespace std;

int main(){
	int a, b, c, n, i, j, s, judge;
	int *damy = 0, *ok = 0, *ng = 0, *que = 0;
	int okcut = 0, ngcut = 0, check[1000][3];

	while(1){
	cin >> a >> b >> c;
	if(a == 0 && b == 0 && c == 0) break;
	s = a+b+c+1;
	que = new int[s];
	damy = new int[s];
	ok = new int[s];
	ng = new int[s];
	cin >> n;

	for(i = 0; i < n; i ++){
		for(j = 0; j < 3; j ++){
			cin >> check[i][j];
		}
		cin >> judge;
		if(judge == 1){
			ok[check[i][0]] = 1;
			ok[check[i][1]] = 1;
			ok[check[i][2]] = 1;
		}
	}
	for(i = 0; i < n; i ++){
		for(j = 0; j < 3; j	++){
			if(ok[check[i][j]] == 1) okcut ++;
			else ngcut = check[i][j];
			if(okcut == 2) ng[ngcut] = 1;
		}
		okcut = 0, ngcut = 0;
	}
	for(i = 1; i < s; i ++){
		if(ok[i] != 1 || ng[i] != 1) que[i] = 1;
	}
	for(i = 1; i < s; i ++){
		if(ok[i] == 1) cout << "1" << endl;
		else if(ng[i] == 1) cout << "0" << endl;
		else if(que[i] == 1) cout << "2" << endl;
	}
	}

	return 0;
}

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

int main(){
  int n;
  cin >> n;
  int a=0;
  string s="APPROVED";
  for(int i=0;i<n;i++){
  	cin >> a;
    if(a%2==0 && !(a%3==0 || a%5==0)){
    	s="DENIED";
    }
  }
  cout << s;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  char s[100005],b[100005],w[100005];
  cin >>s;
  strcpy(b,s);
  strcpy(w,s);
  int x = 0;
  int b_count = 0 , w_count = 0;
  int n = strlen(s);
  int count = 0;
  for(int i=0; i<n; i++){
    if(s[i] == 'W') count += 1;
  }
  if(count == 0 || count == n){
    cout <<"0\n";
    return 0;
  }  //全て同じ文字の時の処理
  if(s[0] == 'W'){
    b_count += 1;
    while(1){
      if(b[x] == 'B') break;
      b[x] = 'B';
      x += 1;
    }
  }   //左端がWだった場合
  x = 0;
  if(s[0] == 'B'){
    w_count += 1;
    while(1){
      if(w[x] == 'W') break;
      w[x] = 'W';
      x += 1;
    }
  }   //左端がBだった場合
  x = n-1;
  if(s[n-1] == 'W'){
    b_count += 1;
    while(1){
      if(b[x] == 'B') break;
      b[x] = 'B';
      x -= 1;
    }
  }   
  x = n-1;
  if(s[n-1] == 'B'){
    w_count += 1;
    while(1){
      if(w[x] == 'W') break;
      w[x] = 'W';
      x -= 1;
    }
  }
  for(int i=0; i<n; i++){
    if(b[i] == 'W' && b[i+1] == 'B'){
      b_count += 2;
    }
  }
  for(int i=0; i<n; i++){
    if(w[i] == 'B' && w[i+1] == 'W'){
      w_count += 2;
    }
  }
  if(w_count > b_count){
    cout <<b_count<<endl;
  } else {
    cout <<w_count<<endl;
  }
  return 0;
}


Measured memory_bytes: 512
K = int(input())
ls = []
def rec(digit, ini):
    ls.append(ini)
    if digit == 10: #最大10けたなので(sample4)
        return
    deltas = []
    if ini % 10 == 0:
        deltas = [0, 1]
    elif ini % 10 == 9:
        deltas = [-1, 0]
    else:
        deltas = [-1, 0, 1]
    for delta in deltas:
        new = ini * 10 + ini % 10 + delta
        rec(digit+1, new)

for ini in range(1, 10):
    rec(1, ini)
print(sorted(ls)[K-1])

Measured memory_bytes: 83292
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i=0;i<t;i++)
#define ll long long int
#define ld long double
#define umpl unordered_map<ll,ll> 
#define vl vector<ll>
#define vld vector<ld>
#define vvl vector<vl>
#define pb push_back
#define mod 1000000007
#define inf 1e18
#define pcout(x,p) cout<<fixed<<setprecision(p)<<x
#define all(a) a.begin(),a.end()
#define endl "\n"

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll min(ll a, ll b){return a<b?a:b;}
inline ll ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
inline ll mo(ll a,ll b){if(b<0){b=abs(b)%mod;b=a-b;return (b<0)?b+mod:b;}else{return (a+b)%mod;}}
inline ll pow(ll a,ll b){if(b==0){return 1;}else{if(b%2==0){ll temp=pow(a,b/2);return temp*temp;}
else{return a*pow(a,b-1);}}}

struct comp { 
    template<class T1,class T2,class T3,class T4>
    bool operator()(const pair<T1,T2> &p1,const pair<T3,T4> &p2){
        if(p1.first!=p2.first)return p1.first<p2.first;
        else return p1.second<p2.second;
    }
}; 

int main()
{
    fio;
    ll n,m;cin>>n>>m;
    vector<vector<char>> a(n,vector<char>(m));
    for(ll i=0;i<n;i++){
        for(ll j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    ll dp[n][m];memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    for(ll i=0;i<n;i++){
        for(ll j=0;j<m;j++){
            if(a[i][j]!='#'){
                if(i>0 && a[i-1][j]!='#')dp[i][j]=add(dp[i][j],dp[i-1][j]);
                if(j>0 && a[i][j-1]!='#')dp[i][j]=add(dp[i][j],dp[i][j-1]);
            }
        }
    }
    cout<<dp[n-1][m-1]<<endl;
}

Measured memory_bytes: 12044
#include <iostream>
#include <string>
#include <vector>
#include <ios>
#include <iomanip>
#include <stack>
#include <queue>
#include <algorithm>

#define REP(i, n) for(int i = 0;i < n;i++)

using namespace std;

const int INF = 100000000;

int main(){
  int n,a,b;
  int ans =0;

  cin >> n >> a >> b;

  REP(i,n){
    int num = i + 1;
    int sum = 0;
    while(true){
      if (num == 0) {
        break;
      }
      sum += (num % 10);
      num = num / 10;
    }
    if (a <= sum && sum <= b) {
      ans += i + 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[1000],sum;
int main(){
    scanf("%d",&n);
    for (int i=1;i<=2*n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+1+2*n);
    for (int i=1;i<=2*n;i+=2) sum+=a[i];
    printf("%d\n",sum);
    return 0;
}

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

int main(){
    int n;cin>>n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++){
        cin>>b[i];
        a[i] = -1;
    }

    bool key=true;

    for(int i=n-1;i>=0;i--){
        for(int j=i;j>=0;j--){
            if(b[j] == j+1){
                a[i] = b[j];
                for(int k=j;k<n;k++){
                    b[k] = b[k+1];
                }
                break;
            }
        }
        if(a[i] == -1) key=false;
    }

    if(!key) cout<<-1<<endl;
    else {
        for(int i=0;i<n;i++){
            cout<<a[i]<<endl;
        }
    }
}

Measured memory_bytes: 256
import sys

INPUT = lambda: sys.stdin.readline().rstrip()

sys.setrecursionlimit(10 ** 9)


def main():
    n = INPUT()

    ans = ""
    for i in n:
        if i == '1': ans += "9"
        elif i == '9': ans += "1"
        else: ans += i

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
#pragma region
#include <assert.h>
#include <math.h>

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;

template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &v) {
  return os << v.first << ' ' << v.second << '\n';
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  for (T t : v) os << t << ' ';
  return os << '\n';
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &t : v) is >> t;
  return is;
}
#pragma endregion

#define int long long
int mod = 1e9 + 7;  // 998244353;

void solvetestcase() {
  string s;
  cin >> s;
  if (s[s.size() - 1] == 's') {
    s += 'e';
  }
  s += 's';
  cout << s << endl;
}

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

  int t = 1;
  // cin >> t;

  for (int T = 1; T <= t; T++) {
    // cout << "Case #" << T << ": ";
    solvetestcase();
    cout.flush();
  }

  return 0;
};

/*
    AUTHOR:     KUNAL TAWATIA
    EDUCATION:  INDIAN INSTITUTE OF TECHNOLOGY, JODHPUR
*/


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i=0; i<(int64_t)(n); i++)
#define all(v) v.begin(), v.end()
//c
int main(){
  
  int N, M;
  cin >> N >> M;
  vector<int> H(N);
  rep(i, N) cin >> H[i];
  vector<vector<int>> R(N, vector<int>(0));
  rep(i, M){
    int a, b; cin >> a >> b;
    R[a-1].push_back(b);
    R[b-1].push_back(a);
  }
  
  int ans = 0;
  rep(i, N){
    bool ok = true;
    for(int j: R[i]) {
      if(H[j-1] >= H[i]) ok = false;
    }
    if(ok) ans++;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 8804
N=int(input())
ls=[int(s) for s in input().split()]
ls=[ls[i]-i for i in range(N)]
ls.sort()
ans=0
if N%2==1:
  x=ls[(N-1)//2]
  for i in range((N-1)//2):
    ans+=x-ls[i]
  for i in range((N-1)//2,N):
    ans+=ls[i]-x
else:
  x=(ls[N//2]+ls[N//2-1])//2
  for i in range(N//2):
    ans+=x-ls[i]
  for i in range(N//2,N):
    ans+=ls[i]-x
print(ans)

  

Measured memory_bytes: 26020
fun main() {
    println(solve())
}

val solve: () -> Any = {
    val (N, M, Q) = readIntList()
    val list = List(Q){readIntList()}
    val l = listOf(1)

    fun f(li:List<Int>) :Int{
        if (li.size == N) {
            var res = 0
            for (l in list) {
                if (li[l[1]-1] - li[l[0]-1] == l[2]) res += l[3]
            }
            return res
        }
        var max = 0
        for(it in li.last()..M) {
            val n = f(li + it)
            if (n > max) max = n
        }
        return max
    }
    f(l)
}

val mod: Int = 1_000_000_007

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun <T> T.alsoPrintln() = also { println(this) }

fun Boolean.toYesOrNo(yes: String = "Yes", no: String = "No") = if (this) yes else no

Measured memory_bytes: 57408
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >> n;
    vl v(n);
    ll sum=0,sumb=0;
    rep(i,n){
        cin >> v[i];
        sum+=v[i];
        if(i%2==1)sumb+=v[i]*2;
    }
    vl ans(n);
    ans[0]=sum-sumb;
    rep(i,n-1){
        ans[i+1]=v[i]*2-ans[i];
    }
    rep(i,n)cout << ans[i] << " ";
}


Measured memory_bytes: 2816
//In the name of ALLAH the most merciful the most beneficial

#include<cstdio>
#include<cstring>
#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<fstream>
#define sc(x) scanf("%d",&x)
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORd(i,a,b) for(int i=a;i>b;i--)
#define ff first
#define ss second
#define sz(x) x.size()
#define pb push_back

using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vii;
const int con = 105;
static const int INF = 0x3f3f3f3f;
static const int MOD = 998244353;

int main(){

    int N,W;sc(N);sc(W);
    ll arr[con][2];
    FOR(i,1,N+1)
        cin >> arr[i][0] >> arr[i][1]; // 0th col is weight and 1st is value

    ll ans[103][W+2];
    FOR(i,0,103){
        FOR(j,0,W+2)
            ans[i][j] = 0;
    }

    FOR(i,1,N+1){

        FOR(j,0,W+1){
            if(arr[i][0] > j)
                ans[i][j] = ans[i-1][j];
            else
                ans[i][j] = max(ans[i-1][j],ans[i-1][j-arr[i][0]]+arr[i][1]);
        }
    }
    cout << ans[N][W];
}



Measured memory_bytes: 80768
//Sinhaeng Hhjian
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=5e6+7;
typedef long long ll;
int n, a[maxn], sum;
int main(){
	scanf("%d", &n);
	for(int i=0;i<n;i++)
		scanf("%d", &a[i]);
	sort(a, a+n);
	int ans=0;sum=0;
	if(a[0]%2)
		sum=a[0];
	for(int i=1;i<n;i++){
		int x=a[i]-a[i-1];
		if(x%2)
			sum^=a[i];
	}
	for(int i=0;i<n;i++)
		if(a[i]>(sum^a[i]))
			ans++;
	if(ans)
		printf("first\n");
	else
		printf("second\n");
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define PI acos(-1.0)
int main()
{
    ll k;
    string s;
    cin>>k>>s;
    if(s.size()<=k)
    {
        cout<<s;
    }
    else{
        for(int i=0; i<k; i++)
        {
            cout<<s[i];
        }
        cout<<"...";
    }

}




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

int main()
{
	string s;
	cin >> s;
	bool strong = true;
	int n = s.length();
	for (int i = 0; i < n; i++) {
		if (s[i] != s[n - i - 1]) {
			strong = false;
		}
	}
	int m = (n - 1) / 2;
	for (int i = 0; i < m; i++) {
		if (s[i] != s[m - i - 1]) {
			strong = false;
		}
	}
	int a = (n + 3) / 2 - 1;
	int b = n - 1;
	for (int i = 0; i < (b - a + 1); i++) {
		if (s[i + a] != s[b - i]) {
			strong = false;
		}
	}
	cout << (strong ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define ll long long int

ll ar[100][2],t[100][100000];

ll fun(ll l,ll r,ll w){
  if(l>r)
   return 0;
  ll a,b;
  if(t[l][w]==-1){
    a=fun(l+1,r,w);
    if(ar[l][0]<=w){
      b=fun(l+1,r,w-ar[l][0])+ar[l][1];
      a=a>=b?a:b;
    }
    t[l][w]=a;
  }
  return t[l][w];
}

  int main(){
    for(int j=0;j<100;j++)
     for(int i=0;i<100000;i++)
      t[j][i]=-1;
    ll n,w;
    scanf("%lld%lld",&n,&w);
    for(int i=0;i<n;i++)
      scanf("%lld%lld",ar[i],ar[i]+1);
    printf("%lld\n",fun(0,n-1,w));
    return 0;
  }


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

int h,w;
bool isin(int x,int y){
  return 0 <= x and x < h and 0 <= y and y < w;
}

int main(){
#define int ll
  cin >> h >> w;
  vvi a(h,vi(w));
  rep(i,h) rep(j,w){
    cin >> a[i][j];
    a[i][j] &= 1;
  }

  int n = 0;
  vi x1,y1,x2,y2;

  rep(i,h) rep(j,w-1)
    if(a[i][j]){
      n++;
      x1.pb(i+1);
      y1.pb(j+1);
      x2.pb(i+1);
      y2.pb(j+2);
      a[i][j+1] ^= 1;
    }

  rep(i,h-1)
    if(a[i][w-1]){
      n++;
      x1.pb(i+1);
      y1.pb(w);
      x2.pb(i+2);
      y2.pb(w);
      a[i+1][w-1] ^= 1;
    }

  cout << n << endl;
  rep(i,n) cout << x1[i] << " " << y1[i] << " " << x2[i] << " " << y2[i] << endl;
}

Measured memory_bytes: 8152
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n)]

a, b, c = 0, 0, 0
for x, y, z in abc:
    a, b, c = max(b, c) + x, max(a, c) + y, max(a, b) + z

print(max(a, b, c))

Measured memory_bytes: 30580
import sys
sys.setrecursionlimit(10 ** 9)

n,a,b,c = list(map(int,input().split()))
s = []
for i in range(n):
  s.append(input())

ans = []
def dfs(i,a,b,c):
  if i == n:
    print('Yes')
    for ai in ans:
      print(ai)
    exit()
  si = s[i]
  if si == 'AB':
    if a == 0 and b == 0:
      return
    elif a == 0 and b > 0:
      ans.append('A')
      dfs(i+1,a+1,b-1,c)
    elif a > 0 and b == 0:
      ans.append('B')
      dfs(i+1,a-1,b+1,c)
    else:
      ans.append('A')
      dfs(i+1,a+1,b-1,c)
      ans.pop()
      ans.append('B')
      dfs(i+1,a-1,b+1,c)
  elif si == 'BC':
    if b == 0 and c == 0:
      return
    elif b == 0 and c > 0:
      ans.append('B')
      dfs(i+1,a,b+1,c-1)
    elif b > 0 and c == 0:
      ans.append('C')
      dfs(i+1,a,b-1,c+1)
    else:
      ans.append('B')
      dfs(i+1,a,b+1,c-1)
      ans.pop()
      ans.append('C')
      dfs(i+1,a,b-1,c+1)
  else:
    if c == 0 and a == 0:
      return
    elif c ==0 and a > 0:
      ans.append('C')
      dfs(i+1,a-1,b,c+1)
    elif c > 0 and a == 0:
      ans.append('A')
      dfs(i+1,a+1,b,c-1)
    else:
      ans.append('C')
      dfs(i+1,a-1,b,c+1)
      ans.pop()
      ans.append('A')
      dfs(i+1,a+1,b,c-1)

dfs(0,a,b,c)
print('No')


Measured memory_bytes: 177172
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <string>
#define SIZE 3005
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

ll dp[SIZE][2];
ll nxt[SIZE][2];

int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	memset(dp,0,sizeof(dp));
	for(int i=0;i<=n;i++) dp[i][0]=1;
	for(int i=0;i<m;i++)
	{
		memset(nxt,0,sizeof(nxt));
		for(int j=0;j<=n;j++)
		{
			for(int t=0;t<2;t++)
			{
				if(j-1>=0)
				{
					int nt=t;
					if(j-1==0) nt=1;
					nxt[j-1][nt]+=dp[j][t];
					if(nxt[j-1][nt]>=MOD) nxt[j-1][nt]-=MOD;
				}
				if(j<=n-1)
				{
					int nt=t;
					if(j==0) nt=1;
					nxt[j][nt]+=dp[j][t];
					if(nxt[j][nt]>=MOD) nxt[j][nt]-=MOD;
				}
			}
		}
		memset(dp,0,sizeof(dp));
		for(int j=0;j<=n;j++)
		{
			for(int t=0;t<2;t++)
			{
				if(j+1<=n)
				{
					dp[j+1][t]+=nxt[j][t];
					if(dp[j+1][t]>=MOD) dp[j+1][t]-=MOD;
				}
				dp[j][t]+=nxt[j][t];
				if(dp[j][t]>=MOD) dp[j][t]-=MOD;
			}
		}
	}
	ll ret=0;
	for(int i=0;i<=n;i++)
	{
		ret+=dp[i][1];
		if(ret>=MOD) ret-=MOD;
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<set>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    set<int>st;
    for(int i=1; i<=n; i++)
    {
        int x;
        cin>>x;
        if(st.count(x))
        {
            st.erase(x);
        }
        else st.insert(x);
    }
    cout<<st.size()<<endl;
    return 0;
}


Measured memory_bytes: 4864
n = int(input())
a = input().split()
a = [int(i) for i in a]
f = 0

for i in a:
  if i%2==0:
    if i%3!=0 and i%5!=0:
      f = 1
      break

if f==1:
  print("DENIED")
else:
  print("APPROVED")


Measured memory_bytes: 2940
n = int(input())
li = []
res = n % (-2)
ans = n // (-2)
ans1 = n
if res != 0:
    res = ans1 - (-2) * (ans + 1)
    ans = ans + 1
ans1 = ans
li.append(res)
p = 0
if ans == 0 or ans == 1:
    p = 1
    if ans == 1:
      li.append(ans)
while p == 0:
  res = ans % (-2)
  ans = ans // (-2)
  if res != 0:
      res = ans1 - (-2) * (ans + 1)
      ans = ans + 1
  ans1 = ans
  li.append(res)
  if ans == 0 or ans == 1:
    p = 1
    if ans == 1:
      li.append(ans)
li = [str(n) for n in li]
pr = ""
for i in range(len(li)):
  pr += li[-1-i]
print(pr)

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

int main(void){
  string str;
  
  cin >> str;
  
  if (str[0]=='S'){
    cout << "Cloudy" << endl;
  } else if (str[0]=='C'){
    cout << "Rainy" << endl;
  } else {
    cout << "Sunny" << endl;
  }
  
  return 0;
}

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

ll gcd(ll c, ll d){
   if(c < d) swap(c, d);
   if(d == 0) return c;
   return gcd(c%d, d);
}


int main(){
    ll a, b;
    cin >> a >> b;

    ll gcd_ab = gcd(a, b);
    ll ans = a * b / gcd_ab;


    cout << ans << endl;
    return 0;
}

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

int main() {
	int n, x;
	cin>>n;
	stack<int> st;
	for(int i=0; i<n; i++) {  cin>>x;	st.push(x); }
	for(int i=0; i<n; i++) 
	{
		cout<<st.top() << (i !=n-1 ? " " : "" );
		st.pop();
	}
	cout<<'\n';
	return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int sum=0;
  int a=1;
  int b=0;
  for(int i=0;i<9;i++) {
    if(n%a==0) {
      b=n/a;
      if(b<=9){
        sum+=1;}
      else {
        sum+=0;}}
    else {
      sum+=0;}
  a+=1;}
  if(sum>0) {
    cout << "Yes" << endl;}
  else {
    cout << "No" << endl;}
  return 0;
  }


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int main(){
  string s;
  cin>>s;
  int l;
  for(l=s.length()-2;l>0;l-=2){
    int i=l/2;
    bool flg=true;
    for(int j=0;j<i;j++){
      if(s[j]!=s[i+j]){
        flg=false;
        break;
      }
    }
    if(flg)break;
  }
  cout<<l<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys, heapq, bisect, math, fractions
from collections import deque

N = int(input())
xy = [[] for _ in range(N)]
for i in range(N):
    a = int(input())
    for _ in range(a):
        xy[i].append(tuple(map(int, input().split())))
        
def ok(i: int, j: int):
    for x, y in xy[j]:
        if y == 0 and (i >> (x - 1) & 1 == 1):
            return False
        if y == 1 and (i >> (x - 1) & 1 == 0):
            return False
    return True

res = 0
for i in range(2 ** N):
    cnt = 0
    for j in range(N):
        if i >> j & 1 == 1:
            cnt += 1
            if not ok(i, j):
                break
    else:
        res = max(res, cnt)

print(res)

Measured memory_bytes: 5068
#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
        out << '(' << p.first << ',' << p.second << ')';
            return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
        in >> p.first >> p.second;
            return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
        for (T &x : v)
                    in >> x;
            return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T> > &v)
{
        for (const vector<T> &x : v)
                    out << x << '\n';
            return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
        for (const T &x : v)
                    out << x << ' ';
            return out;
}

template <class T>
ostream& operator << (ostream& out,const set<T> &s)
{
        for (const T &x : s)
                out << x << ' ';
            return out;
}
 
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<nl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<nl
#define epsilon 0.00000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}

int main()
{
    fast();
    ll n,a,b;
    cin>>n>>a>>b;
    ll diff=abs(a-b);
    if(diff%2)
    {
        //saty at table 1 for 1 move and then move
        ll ans=a-1+1+(b-a-1)/2;

        //stay at table n for 1 move and then move
        ans=min(ans,n-b+1+(b-a-1)/2);
        cout<<ans<<nl;
    }
    else
    {
        cout<<diff/2<<nl;
    }
}


Measured memory_bytes: 3616
#include<stdio.h>

int main(void)
{
	int x, y;
	
	int i;
	
	for(i=0; i<3000; i++)
	{
		scanf("%d %d\n", &x, &y);
		
		if(x == 0 && y == 0)
		{
			break;
		}
		
		if(x<y)
		{
			printf("%d %d\n", x, y);
		}
		else
		{
			printf("%d %d\n", y, x);
		}
	}
	return 0;
}


Measured memory_bytes: 2040
s = str(input())

compare1 = "01"*int(len(s)/2)
compare2 = "10"*int(len(s)/2)
if len(compare1)!=len(s):
  compare1 = compare1 + "0"
  compare2 = compare2 + "1"

diff1=0
diff2=0
for i,j,k in zip(s,compare1,compare2):
  if i == j:
    diff1 = diff1 + 1
  if i == k:
    diff2 = diff2 + 1

print(min(diff1,diff2))
  
  

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

using namespace std;
using ll = long long;

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount


int main() {
    int N;
    cin >> N;
    vector<int> h(N+1);
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }
    h[N] = 0;

    int res = 0;
    for (int i = 0; i < 100; i++) {
        int p = 0;
        for (int j = 0; j <= N; j++) {
            if(j>0&&h[j-1]>0&&h[j]==0){
                res++;
                for (int k = p; k < j; k++) {
                    if(h[k]>0)h[k]--;
                }
                p = j;
            }
        }

    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**9
eps = 10**-7

N,A,B = map(int,readline().split())

h = [int(readline()) for i in range(N)]

C = A-B
ng = 0 #条件を常に満たさない
ok = INF #条件を常に満たす

def judge(mid):
    ans = 0
    for hi in h:
        ans += max(0,(hi-mid*B+C-1)//C)
    if ans <= mid:
        return True
    return False

while ok - ng > 1:
    mid = (ok + ng) // 2
    if judge(mid):
        ok = mid
    else:
        ng = mid
    #okが答えとなる
print(ok)



Measured memory_bytes: 72328