akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static 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 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;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    int count = 0;
    for (int i = 0; i < n; i++) {
      if (s.substring(i).startsWith("ABC")) count++;
    }
    System.out.println(count);
  }
}

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

using namespace std;

#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define LL long long
#define ULL unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<LL,int>
#define PLL pair<LL,LL>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<LL,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





//int dx[]={-1,1,0,0};
//int dy[]={0,0,-1,1};
//int dx[]={-1,0,1,-1,1,-1,0,1};
//int dy[]={1,1,1,0,0,-1,-1,-1};




const int N=3e5+1;
int node[4*N+5];

void Update(int nodeNum,int start,int end,int pos,int x)
{
    if(start == end)
    {
        node[nodeNum]=x;
        return;
    }
    int mid=(start+end) >> 1;
    if(pos <= mid)Update(2*nodeNum,start,mid,pos,x);
    else Update(2*nodeNum+1,mid+1,end,pos,x);
    node[nodeNum]=max(node[2*nodeNum],node[2*nodeNum+1]);
}

int Query(int nodeNum,int start,int end,int l,int r)
{
    if(l == start  &&  r == end)return node[nodeNum];
    int mid=(start+end) >> 1;
    if(r <= mid)return Query(nodeNum*2,start,mid,l,r);
    if(mid < l)return Query(nodeNum*2+1,mid+1,end,l,r);
    return max(Query(nodeNum*2,start,mid,l,mid),Query(nodeNum*2+1,mid+1,end,mid+1,r));
}


int main()
{
    FAST();
    int i,k,n,x,y;
    cin >> n >> k;
    for(i=0;i<n;i++)
    {
        cin >> x;
        ++x;
        y=Query(1,1,N,max(1,x-k),min(x+k,N));
        Update(1,1,N,x,y+1);
    }
    cout << Query(1,1,N,1,N);
    return 0;
}


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

int main() {
  
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> image(H, vector<char>(W));
  
  string white_row = ".";
  for (int i = 0; i < W - 1; i++) {
    white_row += ".";
  }
  
  int count = 0;
  for (int i = 0; i < H; i++) {
    string row;
    cin >> row;
    
    if (row != white_row) {
      for (int j = 0; j < W; j++) {
        image.at(count).at(j) = row.at(j);
      }
      count++;
    }
  }
  
  vector<bool> erase_w(W, false);
  
  for (int i = 0; i < W; i++) {
    for (int j = 0; j < count; j++) {
      if (image.at(j).at(i) != '.')
        break;
      if (j != count - 1)
        continue;
      erase_w.at(i) = true;
    }
  }
  
  
  for (int i = 0; i < count; i++) {
    for (int j = 0; j < W; j++) {
      if (erase_w.at(j) == false){
        cout << image.at(i).at(j);
      }
    }
    cout << endl;
  } 
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<set>
#include<vector>
#include<queue>
#include<algorithm>
#define maxn 500005
#define LL long long
using namespace std;
typedef set<int>::iterator siter;
int n,k,p[maxn],ans[maxn],pos[maxn],vis[maxn],pr[maxn],cnt;
set<int> fr,bk;
vector<int> a[maxn];
priority_queue<int> q;
/*const int BUF_LEN=10000000;
int ccnt;
char pBuffer[BUF_LEN];
void ReadOptmized() { fread(pBuffer,BUF_LEN,1,stdin); }
void read(int &x)
{
	char ch=pBuffer[ccnt++]; x=0;
	while(ch<'0'||ch>'9') ch=pBuffer[ccnt++];
	for(;ch>='0'&&ch<='9';ch=pBuffer[ccnt++]) x=x*10+ch-'0';
}*/
int main()
{
	//ReadOptmized();
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) 
	{
		scanf("%d",&p[i]);
		ans[i]=p[i],pos[p[i]]=i;
	}
	for(int i=1;i<=k;i++) bk.insert(p[i]);
	for(int i=1;i<=n;i++)
	{
		siter f=bk.upper_bound(p[i]),g=fr.upper_bound(p[i]);
		if(f!=bk.end())
		{
			a[pos[*f]].push_back(i);
			vis[i]++;
		}
		if(g!=fr.end())
		{
			a[pos[*g]].push_back(i);
			vis[i]++;
		}
		fr.insert(p[i]);
		if(i-k+1>0) fr.erase(p[i-k+1]);
		if(i+k<=n) bk.insert(p[i+k]);
		bk.erase(p[i]);
	}
	for(int i=1;i<=n;i++)
		if(!vis[i]) q.push(i);
	while(!q.empty())
	{
		int x=q.top(); q.pop();
		pr[++cnt]=x;
		for(int i=0,siz=a[x].size();i<siz;i++)
		{
			vis[a[x][i]]--;
			if(!vis[a[x][i]]) q.push(a[x][i]);
		}
	}
	for(int i=1;i<=n;i++) p[pr[i]]=n-i+1;
	for(int i=1;i<=n;i++) printf("%d\n",p[i]);
}

Measured memory_bytes: 64640
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

ll dp[100005][13];

int main(){
    string s;
    cin >> s;
    rep(i, 100005)rep(j, 13) dp[i][j] = 0;
    if (s[0] == '?'){
        rep(i, 10) dp[0][i] = 1;
    }else{
        rep(i, 13){
            if(i == s[0] - '0') dp[0][i] = 1;
        }
    }
    
    for (ll i = 1; i < s.size(); i++){
        if(s[i] == '?'){
            rep(j, 13){
                rep(k, 10){
                    ll num = (j * 10 + k) % 13;
                    dp[i][num] += dp[i-1][j];
                    dp[i][num] %= mod;
                }
            }
        }else{
            rep(j, 13){
                ll num = (j * 10 + (s[i] - '0')) % 13;
                // if(i == 2){
                //     cout << num << endl;
                // }
                
                dp[i][num] += dp[i-1][j];
                dp[i][num] %= mod;
            }
        }
    }

    // rep(i, s.size()){
    //     rep(j, 13){
    //         cout << dp[i][j] << " ";
    //     }cout << endl;
    // }
    cout << dp[s.size()-1][5] << endl;
    
}

Measured memory_bytes: 13848
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <climits>
#include <complex>
#include <numeric>
#include <list>
using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RREP(i,n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)
#define ALL(c) (c).begin(), (c).end()

int main(void) {
  int n;
  cin >> n;
  vector<int> a(n);
  list<int> b;
  for(int i = 0; i < n; i++) cin >> a[i];
  for(int i = 0; i < n; i++) {
    if(i % 2) {
      b.push_back(a[i]);
    } else {
      b.push_front(a[i]);
    }
  }
  if(n % 2) {
    FOR(e, b) {
      if(e != b.begin()) cout << " ";
      cout << (*e);
    }
  } else {
    RFOR(e, b){
      if(e != b.rbegin()) cout << " ";
      cout << (*e);
    }
  }
  cout << endl;
}


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

int main(){
  int d;
  int c[27];
  int s[400][27];
  int t[400];
  static int last[27];//最後の開催日

  cin >> d;
  rep(i, 26)cin >> c[i+1];
  rep(i, d){
    rep(j, 26){
      cin >> s[i+1][j+1];
    }
  }

  for(int i=1;i<=d;i++){
    int mx = -INF;
    int mxi;
    for(int j=1;j<=26;j++){
      int tmp=0;
      tmp += s[i][j];
      for(int k=1;k<=26;k++){
        if(j!=k)tmp-=(i-last[k])*c[k];
      }
      if(tmp>mx){
        mx = tmp;
        mxi = j; 
      }
    }
    t[i]=mxi;
    last[t[i]]=i;
  }

  //
  int target = 0;
  rep(i, 26)last[i+1]=0;
  for(int i=1;i<=d;i++){
    target += s[i][t[i]];
    last[t[i]]=i;
    for(int j=1;j<=26;j++)target-=(i-last[j])*c[j];
  }

  pair<int, int> pr[26];
  rep(i, 26){
    pr[i] = pair<int, int>(c[i+1], i+1);
  }
  sort(pr, pr+26);
  
  //ここから局所探索法
  rep(l, 600){
    int aft = pr[l%26].second;
    for(int k=1;k<=d;k++){
      //k日目をaftに変更する
      int tmp = 0;
      rep(i, 26)last[i+1]=0;
      for(int i=1;i<=d;i++){
        if(i==k){
          tmp += s[i][aft];
          last[aft]=i;
          for(int j=1;j<=26;j++)tmp-=(i-last[j])*c[j];
          continue;
        }
        tmp += s[i][t[i]];
        last[t[i]]=i;
        for(int j=1;j<=26;j++)tmp-=(i-last[j])*c[j];
      }
      // cout << target << ":" << tmp << endl;
      if(tmp>target){
        t[k]=aft;
        target = tmp;
      }
    }
  }
  
  rep(i, d)cout << t[i+1] << endl;
  return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	vector<int> p(n);
	rep(i, n) {
		scanf("%d", &p[i]);
	}
	sort(p.begin(), p.end());
	int sum = 0;
	rep(i, k) {
		sum += p[i];
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 3696
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;



int main(){
int N;
cin>>N;
string S;
cin>>S;
char table[N+1];
rep3(i,N)table[i]=S[i-1];
int leftb[N+2];
int rightw[N+2];
memset(leftb,0,sizeof(leftb));
memset(rightw,0,sizeof(rightw));
leftb[1]=0;
rep3(i,N){
    if(table[i]=='#'){
        leftb[i+1]=leftb[i]+1;


    }
    else{
        leftb[i+1]=leftb[i];
    }
}
repr3(i,N){
    if(table[i]=='.'){
        rightw[i-1]=rightw[i]+1;
    }
    else{
        rightw[i-1]=rightw[i];
    }
}
int ans=N+1;
rep3(i,N){
    ans=min(ans,leftb[i]+rightw[i]);
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 5508
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int l;
  cin>>l;
  vector<lint> a(l),odd(l),even(l),cum(l);
  for(int i=0;i<l;i++){
    cin>>a[i];
    if(a[i]==0){
      odd[i]=1;
      even[i]=2;
    }else{
      odd[i]=(a[i]%2==0)?1:0;
      even[i]=(a[i]%2==0)?0:1;
    }
    cum[i]=a[i];
    if(i!=0){
      cum[i]+=cum[i-1];
    }

  }
  const lint INF=INT64_MAX-10;
  vector2d<lint> dp(l,vector<lint>(5,INF));
  dp[0][0]=a[0];
  dp[0][1]=even[0];
  dp[0][2]=odd[0];
  for(int i=1;i<l;i++){
    dp[i][0]=dp[i-1][0]+a[i];
    dp[i][1]=min(dp[i-1][0],dp[i-1][1])+even[i];
    dp[i][2]=min({dp[i-1][0],dp[i-1][1],dp[i-1][2]})+odd[i];
    dp[i][3]=min(dp[i-1][2],dp[i-1][3])+even[i];
  }
  lint result=min({dp[l-1][0],dp[l-1][1],dp[l-1][2],dp[l-1][3],dp[l-1][4]});
  for(int i=1;i<l;i++){
    for(int j=0;j<4;j++){
      if(dp[i-1][j]==INF) continue;
      lint tmp_result=dp[i-1][j]+cum[l-1]-cum[i-1];
      UpdateMin(result,tmp_result);
    }
  }
  cout<<result<<endl;

  return 0;
}




Measured memory_bytes: 20608
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#pragma warning(disable : 4996)
using namespace std;
int a, b, c, d, e;
int f(int x) {
	if (x < 0) return c * (x + 1000);
	return c * 1000 + d + e * x;
}
int main() {
	cin >> a >> b >> c >> d >> e;
	cout << f(b) - f(a) << endl;
	return 0;
}

Measured memory_bytes: 3060
def main():
    n,k = map(int,input().split())
    arr = list(map(int,input().split()))
    for i in range(n):
        arr[i] = (arr[i]+1)/2

    max_val = 0
    val = 0
    count = 0
    start = 0
    for i in arr:
        val += i
        count += 1
        if count == k:
            max_val = max(max_val,val)
            count -= 1
            val -= arr[start]
            start += 1

    print(max_val)

main()


Measured memory_bytes: 71792
#include<bits/stdc++.h>
using namespace std; 
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a==c&&a!=b)
		cout<<"Yes";
	else if(a==b&&a!=c)
		cout<<"Yes";
	else if(b==c&&b!=a)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n,ans=0;
    while(scanf("%d",&n)!=-1){
        ans=0;
        for(int i=0;i<10;i++){
            for(int j=0;j<10;j++){
                for(int k=0;k<10;k++){
                    for(int l=0;l<10;l++){
                        if(i+j+k+l==n){
                            ans++;
                        }
                    }
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1028
//omajinai c++ atcoder
#include <iostream> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<cmath>
#include<iomanip>
#include<type_traits>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define itn int
#define yes() printf("Yes\n")
#define no() printf("No\n")
typedef long long ll;
constexpr auto mod = 1000000007;
using namespace std;

int main() {
    long int a,b,n;
    cin>>a>>b>>n;
    int ma=0;
    if(n>=b-1){
        ma=a-ceill((long double)a/(long double)b);
    }
    else{
        ma=floor((long double)a*(long double)n/(long double)b)-a*floor((long double)n/(long double)b);

    }
  cout<<ma;
}


Measured memory_bytes: 3680
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

//#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;

#define INF   (1e9 + 7)
#define MAX_N (50)

int N, A, B;
ll V[MAX_N];
ll C[MAX_N + 1][MAX_N + 1];

void solve() {
  sort(V, V + N);
  double ave = 0.0;
  for (int i = 0; i < A; i++) ave += V[N - i - 1];
  ave /= A;

  ll x = V[N - A];
  int lb = (int) (lower_bound(V, V + N, x) - V);
  int ub = (int) (upper_bound(V, V + N, x) - V);
  debug_printf("x = %lld, ub = %d, lb = %d\n", x, ub, lb);

  ll comb = 0;
  if (x == V[N - 1]) {
    int p = ub - lb;
    for (int q = A; q <= min(B, N - lb); q++)
      comb += C[p][q];
  } else {
    int p = ub - lb;
    int q = A - (N - ub);
    debug_printf("p = %d, q = %d\n", p, q);
    comb = C[p][q];
  }

  printf("%f\n", ave);
  printf("%lld\n", comb);
}

int main() {
  scanf("%d %d %d", &N, &A, &B);
  for (int i = 0; i < N; i++) scanf("%lld", &V[i]);

  C[0][0] = 1;
  for (int i = 1; i <= N; i++) {
    C[i][0] = 1; C[i][i] = 1;
    for (int j = 1; j < i; j++) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
    // for (int j = 0; j <= i; j++) debug_printf("%lld ", C[i][j]);
    // debug_printf("\n");
  }

  solve();

  return 0;
}


Measured memory_bytes: 384
n,y = map(int,input().split())

a,b,c = (-1,-1,-1)
for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i + 5000*j + 1000*(n-i-j) == y:
            a,b,c = (i,j,n-i-j)
            break

print(a,b,c) 

Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;

int main()
{
    vector<string> names(3);
    for (int i = 0; i < 3; ++i)
        cin >> names[i];
    for (int i = 0; i < 3; ++i)
        cout << names[i].front();
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func check(sIn string, sOut []string, n int) bool {
	if sIn[0:1] == "o" {
		if sOut[0] == "S" {
			if sOut[1] != sOut[n-1] {
				return false
			}
		} else {
			if sOut[1] == sOut[n-1] {
				return false
			}
		}
	} else {
		if sOut[0] == "S" {
			if sOut[1] == sOut[n-1] {
				return false
			}
		} else {
			if sOut[1] != sOut[n-1] {
				return false
			}
		}
	}

	if sIn[n-1:n] == "o" {
		if sOut[n-1] == "S" {
			if sOut[0] != sOut[n-2] {
				return false
			}
		} else {
			if sOut[0] == sOut[n-2] {
				return false
			}
		}
	} else {
		if sOut[n-1] == "S" {
			if sOut[0] == sOut[n-2] {
				return false
			}
		} else {
			if sOut[0] != sOut[n-2] {
				return false
			}
		}
	}

	return true
}

func solve(sIn string, sOut []string, n int) bool {
	for i := 1; i < n-1; i++ {
		if sIn[i:i+1] == "o" {
			if sOut[i] == "S" {
				sOut[i+1] = sOut[i-1]
			} else {
				if sOut[i-1] == "S" {
					sOut[i+1] = "W"
				} else {
					sOut[i+1] = "S"
				}
			}
		} else {
			if sOut[i] == "S" {
				if sOut[i-1] == "S" {
					sOut[i+1] = "W"
				} else {
					sOut[i+1] = "S"
				}
			} else {
				sOut[i+1] = sOut[i-1]
			}
		}
	}
	return check(sIn, sOut, n)
}

func output(sOut []string) {
	for _, v := range sOut {
		fmt.Print(v)
	}
	fmt.Println()
}

func main() {
	var n int
	var sIn string
	fmt.Scan(&n, &sIn)

	sOut := make([]string, n)

	sOut[0] = "S"
	sOut[1] = "S"
	if solve(sIn, sOut, n) {
		output(sOut)
		return
	}

	sOut[0] = "S"
	sOut[1] = "W"
	if solve(sIn, sOut, n) {
		output(sOut)
		return
	}

	sOut[0] = "W"
	sOut[1] = "S"
	if solve(sIn, sOut, n) {
		output(sOut)
		return
	}

	sOut[0] = "W"
	sOut[1] = "W"
	if solve(sIn, sOut, n) {
		output(sOut)
		return
	}

	fmt.Println(-1)
}


Measured memory_bytes: 4608
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
#include <list>
#include <set>
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
using namespace std;
using ll = long long;
const int INF = 1e9 + 1;
ll MOD = 1e9+7;


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

    string S;
    cin >> S;
    for(int i = 0; i < S.length(); i++){
        if(i % 2 == 1){
            if(S[i] == 'R'){
                cout << "No" << endl;
                return 0;
            }
        }else{
            if(S[i] == 'L'){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    
    long long ans = 0,res=0;
    int right = 1; // [0, 1) は確実に条件を満たす
    for (int left = 0; left < n; ++left) {
        // right を 1 個進めたものが条件を満たすかどうか
        while (right < n && (right <= left || a[right - 1] >= a[right])) {
            ++right;
        }
        res = right - left;
        ans=max(ans,res);
        if (left == right) ++right;
    }

    cout << ans-1 << endl;
}

Measured memory_bytes: 1024
s=list(input())

a=0
for i in range(len(s)):
    if s[i]=='A':
        a=i
        break
b=0
for i in range(len(s)):
    if s[len(s)-i-1]=='Z':
        b=len(s)-i-1
        break
print(b-a+1)

Measured memory_bytes: 4840
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;

namespace AtCoder
{
    class Program
    {
        private static long mod = 1000000007;
        static void Main(string[] args)
        {
            //var n = long.Parse(ReadLine());
            var line = ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
            var l = line[0];
            var r = line[1];
            var d = line[2];

            var count = 0;
            for(var i = l; i <= r; i++)
            {
                if(i % d == 0)
                {
                    count++;
                }
            }

            WriteLine(count);
        }
    }
}


Measured memory_bytes: 19008
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        var hei = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var dp = new int[num];
        dp[0] = 0;
        dp[1] = Abs(hei[0] - hei[1]);
        for(var i = 2; i < num; i++)
        {
            dp[i] = Min(Abs(hei[i] - hei[i - 2]) + dp[i - 2], Abs(hei[i] - hei[i - 1]) + dp[i - 1]);
        }
        WriteLine(dp[num - 1]);
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


Measured memory_bytes: 18912
#include <bits/stdc++.h>
using namespace std;
#define sort(vec) sort(vec.begin(),vec.end())
#define reverse(vec) reverse(vec.begin(),vec.end())
#define unsort(vec); sort(vec);reverse(vec);
#define int long long
long long ans;

int gcd(int x,int y){
	if(y==0) return x;
	else return gcd(y,x%y);
}

int lcm(int x,int y){
	return x/gcd(x,y)*y;
}
 
signed main(){
	int n,m,c;
	cin>>n>>m>>c;
	int b[m],a[n][m];
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<n;i++){
		int cnt=0;
		for(int j=0;j<m;j++){
			cnt+=b[j]*a[i][j];
		}
		if(cnt+c>0)ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
aCnt = [0] * n
bCnt = [0] * n

for elem in a:
    aCnt[elem - 1] += 1
for elem in b:
    bCnt[elem - 1] += 1

ans1 = [-1] * n
ans2 = [-1] * n
isPossible = True

aLast = -1
aLastRemaining = 0
bLast = -1
bLastRemaining = 0
curIndex = 0

cntArray = []

for i in range(n):
    cntArray.append((aCnt[i] + bCnt[i],i))

cntArray.sort(reverse = True)

for j in range(n):
    i = cntArray[j][1]
    if aCnt[i] + bCnt[i] > n:
        isPossible = False
        break
    aRemaining = aCnt[i]
    bRemaining = bCnt[i]
    while aRemaining and curIndex < n:
        aRemaining -= 1
        ans1[curIndex] = i
        curIndex += 1
    while bRemaining and curIndex < n:
        bRemaining -= 1
        ans2[curIndex] = i
        curIndex += 1
    if curIndex >= n:
        aLast = j
        bLast = j
        aLastRemaining = aRemaining
        bLastRemaining = bRemaining
        break

if isPossible:
    for i in range(n):
        if ans1[i] == -1:
            while aLastRemaining == 0:
                aLast += 1
                aLastRemaining = aCnt[cntArray[aLast][1]]
            aLastRemaining -= 1
            ans1[i] = cntArray[aLast][1]
        if ans2[i] == -1:
            while bLastRemaining == 0:
                bLast += 1
                bLastRemaining = bCnt[cntArray[bLast][1]]
            bLastRemaining -= 1
            ans2[i] = cntArray[bLast][1]
    aCorrespondingList = []
    for _ in range(n):
        aCorrespondingList.append([])
    
    for i in range(n):
        aCorrespondingList[ans1[i]].append(ans2[i])
    newB = []
    for elem in a:
        newB.append(aCorrespondingList[elem - 1].pop() + 1)
    print("Yes")
    print(" ".join(map(str,newB)))
else:
    print("No")

Measured memory_bytes: 166312
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    vector<int> v(2*n);
    for(int i=0; i<n; ++i){
        v[2*i] = a[i];
        v[2*i+1] = b[i];
    }
    sort(v.begin(), v.end());

    long long ans = min(accumulate(a.begin(), a.end(), 0LL), accumulate(b.begin(), b.end(), 0LL));
    long long sum = accumulate(v.begin(), v.begin() + (n - 2), 0LL);
    for(int i=0; i<n; ++i){
        long long tmp = sum + a[i] + b[i];
        int x = min(a[i], b[i]);
        int y = max(a[i], b[i]);
        if(x <= v[n-3]){
            tmp -= x;
            tmp += v[n-2];
            if(y <= v[n-2]){
                tmp -= y;
                tmp += v[n-1];
            }
        }
        else if(y <= v[n-3]){
            tmp -= y;
            tmp += v[n-2];
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
x,n = map(int, input().split())

if n == 0:
    print(x)
else:
    ps = list(map(int, input().split()))
    
    if x not in ps:
      print(x)
    else:
      i = 1
      while True:
          minus = x - i
          plus = x + i

          if not minus in ps:
              print(minus)
              break
          elif not plus in ps:
              print(plus)
              break

          i += 1

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

int main(){
  string s;
  cin >> s;
  if(s[0] == s[1] && s[0] == s[2]){
    cout << "Yes" << endl;
  }else if(s[1] == s[2] && s[1] == s[3]){
    cout << "Yes" << endl;
  }else
    cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string n;
  int a[n.size()]={0};
  long long ans=0;
  cin >> n;
  for(int i=0; i<n.size(); i++) {
    ans+=n.at(i)-'0';
  }
  //cout << ans << endl;
  if(ans%9==0) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3724
N,K = map(int,input().split())
A = list(map(int,input().split()))
count = 0
x = dict()
ans = 0
for i in range(N):
    if A[i] in x:
        x[A[i]] += 1
    else:
        x[A[i]] = 1
        count += 1
l = []
if count <= K:
    print(0)
else:
    for idx in x:
        l.append(x[idx])
    l.sort()
    for i in range(count-K):
        ans += l[i]

    print(ans)

Measured memory_bytes: 32184
/*
ID: dorijan1
TASK: tu napisi ime zadatka molim te molim te ali samo ako si na usaco training
LANG: C++11
*/
#include <bits/stdc++.h>
#define x first
#define y second
#define pii pair<int,int>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
const int MOD=1000000007;
const int MOD2=998244353;
vector<int> bases;
const ll LLINF=1ll<<60;
const char en='\n';

void yes() {cout<<"YES"<<en; exit(0);}
void no() {cout<<"NO"<<en; exit(0);}
template<class T>
void prVec(vector<T> w)
{
	cout<<w.size()<<endl;
	for (int i=0;i<int(w.size())-1;++i) cout<<w[i]<<' ';
	cout<<w[w.size()-1]<<endl;
}

ll raand()
{
	ll a=rand();
	a*=RAND_MAX;
	a+=rand();
    return a%(MOD-7);
}

string to_upper(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
	return a;
}

string to_lower(string a)
{
	for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
	return a;
}

ll sti(string a)
{
	ll k=0;
	for (int i=0;i<(int)a.size();++i)
	{
		k*=10;
		k+=a[i]-'0';
	}
	return k;
}

string its(ll k)
{
	if (k==0) return "0";
	string a;
	while (k)
	{
		a.push_back((k%10)+'0');
		k/=10;
	}
	reverse(a.begin(),a.end());
	return a;
}

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

template<class T,class K>
pair<T,K> mp(T a,K b)
{
	return make_pair(a,b);
}

ll mult(ll a,ll b)
{
	return (a*b)%MOD;
}

ll pot(ll n,ll k)
{
	if (k==0) return 1;
	ll a=pot(n,k/2);
	a=mult(a,a);
	if (k%2) return mult(a,n);
	else return a;
}

ll divide(ll a,ll b)
{
	return mult(a,pot(b,MOD-2));
}

ll sub(ll a,ll b)
{
	return (a-b+MOD)%MOD;
}

ll add(ll a,ll b)
{
	return (a+b)%MOD;
}

bool prime(ll a)
{
	if (a==1) return 0;
	for (int i=2;i<=round(sqrt(a));++i)
	{
		if (a%i==0) return 0;
	}
	return 1;
}

pair<int,int> has(string x)
{
	ll h1=0,h2=0;
	x=to_lower(x);
	for (char a: x)
	{
		h1*=bases[0];
		h1+=a-'a';
		h1%=MOD;
		h2*=bases[1];
		h2+=a-'a';
		h2%=MOD2;
	}
	return make_pair(h1,h2);
}

const int N=300010;
int n,k;
ll su1[N],su2[N];
int h[N];
ll mi=MOD;
vector<ll> a,b;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};

int main()
{
	ios_base::sync_with_stdio(false);
	srand((long long)new char);
	for (int i=0;i<10;++i) bases.push_back(raand()+13893829);
	cin>>n>>k;
	for (int i=0;i<n;++i)
	{
		cin>>h[i];
		if (h[i]<=0) a.push_back(-h[i]);
		else b.push_back(h[i]);
	}
	mi*=3;
	a.push_back(0);
	b.push_back(0);
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	for (int i=0;i<=k;++i)
	{
		if (i>=a.size() || k-i>=b.size()) continue;
		mi=min(mi,a[i]+b[k-i]+min(a[i],b[k-i]));
	}
	cout<<mi;
}


Measured memory_bytes: 2040
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
char s[1010];

int main() {
	while(1) { 
		scanf("%s", s);
		if(s[0] == '0' && s[1] == '\0') break;
		int sum = 0;
		for(int i = 0; s[i] != '\0'; ++i) {
			sum += s[i] - '0';
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int n,d;
  cin >>n>> d;
  vector<vector<int> > v(n,vector<int>(d));
  int ans = 0;
  rep(i,n) rep(j,d) cin >> v[i][j];
  //rep(i,n) rep(j,d) cout << v[i][j]<<endl;
  rep(i,n)
    for(int j=i+1;j<n;j++){
      int buf=0;
      rep(k,d) buf += (v[i][k] - v[j][k])*(v[i][k]- v[j][k]);
      //cout<<buf<<endl;
      rep(k,MOD){
        if(buf == k*k) ans++;
        if(buf <= k*k) break;
      }
    }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
from collections import deque

H, W = list(map(int, input().split()))
field = [[i=='#' for i in input()] for _ in range(H)]
count = 0

def bfs():
  global count
  q = deque()
  for y in range(H):
    for x in range(W):
      if field[y][x]:
        q.append((y, x))
  while True:
    nq = deque()
    while len(q) > 0:
      y, x = q.popleft()
      for dy, dx in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        ny, nx = y + dy, x + dx
        if ny < 0 or ny >= H or nx < 0 or nx >= W:
          continue
        if field[ny][nx]:
          continue
        field[ny][nx] = True
        nq.append((ny, nx))
    if len(nq) > 0:
      q = nq
    else:
      break
    count += 1
      
bfs()
print(count)

Measured memory_bytes: 84700
// In the name of Allah the Most Merciful.

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
ll dp[(1<<8)+10][10];
int Set(int n , int pos)
{
    return n|(1<<pos);
}
bool Check(int n , int pos)
{
    return n&(1<<pos);
}
vector<int>edges[10];
int n , m;

ll f(int mask , int u)
{
    if(mask==(1<<n)-1)return 1;
    if(dp[mask][u]!=-1)return dp[mask][u];
    ll value = 0;
    for(auto v:edges[u]){
        if(Check(mask , v)==false){
            value+=f(Set(mask , v) , v);
        }
    }
    return dp[mask][u] = value;
}

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

    cin >> n >> m;
    for(int i=0;i<m;i++){
        int in1 , in2;
        cin >> in1 >> in2;
        in1--;
        in2--;
        edges[in1].push_back(in2);
        edges[in2].push_back(in1);
    }
    memset(dp , -1 , sizeof(dp));
    ll ans = 0;
    int mask = Set(0 , 0);
    for(int i=0;i<edges[0].size();i++){
        ans+=f(Set(mask , edges[0][i]) , edges[0][i]);
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
  int ans = 0, temp;
  
  for(int i = 0; i < 3; i++){
    cin >> temp;
    ans += temp;
  }
  
  if(ans > 21)
    cout << "bust";
  else
    cout << "win";
  
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

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

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

bool cmp(pii a,pii b){
	return a.S<b.S;
}

int find(vector<int> &dp,int t){
	int hi=sz(dp)-1,lo=-1;
	while(hi-lo>1){
		int m=(hi+lo)/2;
		if(dp[m]<=t) lo=m;
		else hi=m;
	}
	return hi;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s; cin>>s;
	int n=sz(s);
	s+='R';
	int r=1,l=0;
	int i=1,tag;
	vector<int> ans(n,0);
	while(i<n){
		for(;!(s[i-1]=='L' && s[i]=='R');i++){
			if(s[i]=='R') r++;
			else l++;
			if(s[i-1]=='R' && s[i]=='L') tag=i;
		}
		if((r+l)%2==0){
			ans[tag]=(r+l)/2;
			ans[tag-1]=(r+l)/2;
		}
		else if(r%2==1){
			ans[tag]=(r+l)/2;
			ans[tag-1]=(r+l)/2+1;
		}
		else{
			ans[tag]=(r+l)/2+1;
			ans[tag-1]=(r+l)/2;
		}
		r=1,l=0;
		i++;
	}
	For(id,0,n-1) cout<<ans[id]<<" \n"[id==n-1];
	return 0;
}



























Measured memory_bytes: 1488
s=input()
l=len(s)
ok=0
ng=1
mod=10**9+7
for i in range(l):
  if s[i]=='1':
    ok=(ng+ok*3)%mod
    ng=(ng*2)%mod
  elif s[i]=='0':
    ok=(ok*3)%mod
    ng=ng%mod
print((ok+ng)%mod)

Measured memory_bytes: 3188
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int,int,int> T;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 0; i < n; i++)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}

using Graph = vector<vector<pair<int, int>>>;
using Ki = vector<vector<int>>;
using vec = vector<int>;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n;
    cin>>n;
    vector<P> x(n);
    rep(i,n){
        int a,b;
        cin>>a>>b;
        x[i].fs=a+b;
        x[i].sc=a-b;
    }
    sort(all(x));
    int ans=0;
    int t=INF*(-1);
    rep(i,n){
        if(t<=x[i].sc){
            ans++;
            t=x[i].fs;
        }
    }
    cout<<ans<<endl;
}

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

int main() {
  int n;
  cin >> n;
  int R[n];
  for (int t=0; t<n; t++) {
    cin >> R[t];
  }
  int maxv=R[1]-R[0];
  int minv=R[0];
  for (int j=1; j<n; j++) {
    maxv=max(maxv,R[j]-minv);
    minv=min(minv,R[j]);
  }
  printf("%d\n",maxv);
  return 0;
}

Measured memory_bytes: 3908
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using llu=unsigned long long;
#define mod 1000000007
#define mode 998244353
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mms(x,y) memset(x,y,sizeof(x))
#define pqm priority_queue<ll,vector<ll>,greater<ll>>
#define pb push_back
#define um unordered_map
#define pr pair
#define mm multimap
#define ms multiset
#define mp make_pair
#define vr vector
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define inf INT_MAX
#define ninf INT_MIN
#define ff first
#define ss second
#define gcd __gcd
int main()
{
    fast;
    ll t,n,m,i,j,k;
    cin>>n>>m;
    ll w[n],val[n];
    for(i=0;i<n;i++)cin>>w[i]>>val[i];
    ll dp[n+1][m+1];
    mms(dp,0);
    for(i=1;i<=n;i++)
    {
        for(j=0;j<=m;j++)
        {
            if(j>=w[i-1])
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+val[i-1]);
            }
            else dp[i][j]=dp[i-1][j];
        }
    }
    cout<<dp[n][m];
}


Measured memory_bytes: 79232
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> M(N);
  vector<int> P(N);
  vector<int> Q(N);
  rep(i, N) { M[i] = i + 1; }
  rep(i, N) { cin >> P[i]; }
  rep(i, N) { cin >> Q[i]; }

  int ans0 = 0;
  int ans1 = 0;
  int cnt = 0;
  do {
    // rep(i, N) cout << M[i] << " ";
    // cout << endl;
    if (M == P) {
      ans0 = cnt;
    }
    if (M == Q) {
      ans1 = cnt;
    }
    cnt++;
  } while (next_permutation(M.begin(), M.end()));

  int ans = abs(ans0 - ans1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()

if int(s) >= 10:
    if len(set(s[1:])) == 1 and list(set(s[1:]))[0] == "9":
        print((len(s)-1)*9+int(s[0]))
    else:
        print((len(s)-1)*9+int(s[0])-1)
else:
    print(s)

Measured memory_bytes: 12488
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var n, k int
	n, k = nextInt(), nextInt()
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = nextInt()
	}
	sort.Ints(h)
	count := 0
	for i := 0; i < len(h)-k; i++ {
		count += h[i]
	}
	fmt.Print(count)
}

func init() {
	const max = 1024
	var buf = make([]byte, max)
	sc.Buffer(buf, max)
	sc.Split(bufio.ScanWords)
	return
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


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

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, k; cin >> n >> k;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        int hi; cin >> hi;
        v.push_back(hi);
    }
    sort(v.begin(),v.end());
    ll ans = 0;
    for (int i = 0; i < n-k; i++) {
        ans += v[i];
    }
    cout << ans << endl;
}



Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std ;
#define rep(i,a,n) for(int i =a;i<n;i++)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);

int main(){
	ios;
    long long a,b,c;
    cin>>a>>b;
    c=min(a%b,abs((a%b)-b));
    cout<<c<<endl;
	return 0;	
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cmath>
#define INF 1000000000000000000
typedef long long ll;
std::vector<ll> enum_div(ll n)//nの約数を列挙
{
	std::vector<ll> ret;
	for(ll i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	ret.push_back(n);
	return ret;
}

bool is_integer( double x ){
  return std::floor(x)==x;
}

int main()
{
	ll N;
	ll cnt;
	ll wk;
	ll flg;
	flg=0;
	std::cin >> N;
	ll min;
	std::vector<ll> r = enum_div(N);
	min=INF;
	std::sort(r.begin(),r.end());//昇順ソート
	/*
	for(ll i=0;i<r.size();i++){
		printf("%lld\n",r[i]);
	}
	*/
	
	wk=sqrt(N);
	
	if(wk*wk==N){
		flg=1;
	}
	std::sort(r.begin(),r.end());//昇順ソート
	/*
	for(ll i=0;i<r.size();i++){
		printf("%lld\n",r[i]);
	}
	*/
	
	for(ll i=1;i<r.size();i++){
		if(min>r[i-1]+r[r.size()-i]-2){
			min=r[i-1]+r[r.size()-i]-2;
			//printf("%lld\n",r[i-1]);
			//printf("%lld\n",r[r.size()-i]);
		}

	}
	
	if(flg==1){
		if(min>sqrt(N)+sqrt(N)-2){
			min=sqrt(N)+sqrt(N)-2;
		}
	}
	
	printf("%lld",min);
	return 0;
}

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

int f(int n){
  if(n%2==0){
    return n/2;
  }
  else{
    return 3*n+1;
  }
}

int main(){
  map<int, bool>M;
  int s;
  cin >> s;
  M[s] = true;
  for(int i=2; i<1000003; i++){
    s=f(s);
    if(M[s]){
      cout << i;
      return 0;
    }
    M[s] = true;
  }
  return 0;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <math.h>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,T;
    cin >> N >> T;
    int c[1010],t[1010];
    rep(i,N){
        cin >> c[i] >> t[i];
    }
    int mini = 114514,tle=0;
    rep(i,N){
        if(t[i]<=T){
            tle=1;
            mini = min(mini,c[i]);
        }
    }
    if(tle==0){
        cout << "TLE" << endl;
        return 0;
    }
    cout << mini << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = list(map(int, input().split()))
sum_a = sum(a)

# print(n)
# print(m)

# print(sum_a)
# print(sum_a // n)

count = 0
for aa in a:
    # print(aa)
    if aa >= sum_a / (4 * m):
        count += 1
        
# print(count)
if count >= m:
    print('Yes')
else:
    print('No')

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


int main(){
  int S,h,m,s;

  cin >> S;

  h = S/3600;
  m = (S%3600)/60;
  s = (S%3600)%60;

  cout << h << ":" << m << ":" << s << endl;

return 0;
}


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

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0);
#define fread           freopen("input.txt","r",stdin);
#define fwrite          freopen("output.txt","w",stdout);
#define nl              "\n"
#define ll              long long
#define ull             unsigned long long
#define mk              make_pair
#define pb              push_back
#define sz(a)           (int)a.size()
#define pii             pair<int,int>
#define pLL             pair<ll,ll>
#define mem(a)          memset(a,-1,sizeof a)
#define clr(a)          memset(a,0,sizeof a)
#define all(a)          a.begin(),a.end()
#define UNIQUE(a)       sort(all(a)),a.erase(unique(all(a)),a.end())
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define ff              first
#define ss              second
#define sq(a)           ((a)*(a))
#define For(i,a,b)      for(int i=a;i<=b;i++)
#define Rof(i,a,b)      for(int i=a;i>=b;i--)
#define Rep(i,b)        for(int i=0;i<b;i++)
#define MOD             1000000007
#define PI              acos(-1.0)
#define eps             1e-9
#define Linf            2e18
#define inf             1<<30
#define MX5             100005
#define MX6             1000006

int dx[] = {-1,+0,+1,+0,+1,+1,-1,-1,+0};
int dy[] = {+0,-1,+0,+1,+1,-1,+1,-1,+0};
//..........................................GEO................................
#define isRight(r,a,b)  ((b.y-r.y)*(a.x-r.x)<(b.x-r.x)*(a.y-r.y))
#define dot(r,a,b)      ((a.x-r.x)*(b.x-r.x)+(a.y-r.y)*(b.y-r.y))
#define ABSDIS(a,r)     (sqrt(sq(a.x-r.x)+sq(a.y-r.y)))
#define angle(r,a,b)    ((180.0*(acos(dot(r,a,b)/(ABSDIS(a,r)*ABSDIS(b,r)))))/PI)
template <typename T> inline T SqrDis(T x1, T y1, T x2, T y2){return sq(x1 - x2) + sq(y1 - y2);}
template <typename T> inline T Area2(T Ax, T Ay, T Bx, T By, T Cx, T Cy){T ret = Ax * (By - Cy) + Bx * (Cy - Ay) + Cx * (Ay - By);
    if(ret < 0) return ret = -ret;return ret;
}
//struct coord{double x,y;bool operator==(coord a){return (x==a.x && y==a.y);}};
//..........................................NT.................................
template <typename T> inline T bigmod(T A,T B,T M = MOD){T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invmod (T A,T M = MOD){return BigMod(A,M-2,M);}

//.........................................END..................................

ll func(ll a, ll b , ll c){
    if(a%2==0) return 0;
    else return b*c;

}

int main(){
    FastRead

    ll a ,b ,c ;
    cin>>a>>b>>c;
    ll ans=func(a,b,c);
    ans=min(ans,func(a,c,b));
    ans=min(ans,func(b,a,c));
    ans=min(ans,func(c,a,b));
    ans=min(ans,func(c,b,a));
    ans=min(ans,func(b,c,a));
    cout<<ans;


}


Measured memory_bytes: 256