akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static int n,q;;
    public static int[] m = new int[201];
    public static int[] A = new int[21];
    public static void main(String[] args) {
        //データの読込
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            A[i] = sc.nextInt();
        }
        q = sc.nextInt();
        for (int i = 0; i < q; i++) {
            m[i] = sc.nextInt();
        }

        //データの処理
        for (int i = 0; i < q; i++) {
            boolean result = solved(m[i], 0, 0);
            if (result) {
                System.out.println("yes");
            } else {
                System.out.println("no");
            }
        }
    }

    public static boolean solved(int m, int index, int x) {
        if (m == x) return true;

        for (int i = index; i < n; i++) {
            if (solved(m, i + 1, x + A[i])) return true;
        }

        return false;
    }
}


Measured memory_bytes: 26800
#include<bits/stdc++.h>
using namespace std;
int n,sum=0,maxx=-1000000;
char a;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		if(a=='I') sum++;
		else   sum--;
		maxx=max(sum,maxx);
	}	
	if(maxx<0) maxx=0;
	cout<<maxx<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    long a=sc.nextLong();
    long b=sc.nextLong();
    long c=sc.nextLong();
    /*
    sqrt(a)+sqrt(b)<sqrt(c)
    a+b+2*sqrt(a*b)<c
    2*sqrt(a*b)<c-a-b
    
    4*a*b<(c-a-b)^2 (c-a-b)>0
    */
    if(c<=a+b){
      System.out.println("No");
    }else if(4*a*b<(c-a-b)*(c-a-b)){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K,S;
  cin >> N >> K;
  
  S = 1;
  
  for (int i = 0; i < N; i++) {
    
    if(S < K){
      S = S*2;
    }
    else{
      S = S + K;
    }
  }
 cout << S << endl;
}

Measured memory_bytes: 256
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n;
    cin>>n;
    unordered_map<string,int> songs;
    int dur[n];
    for(int i=0;i<n;i++){
        string x;
        int t;
        cin>>x>>t;
        songs[x] = i;
        dur[i] = t;
    }
    string x;
    cin>>x;
    int idx = songs[x];
    int sum=0;
    for(int i=idx+1;i<n;i++)  sum+=dur[i];
    cout<<sum<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;
#define FOR(i, m, n) for (int i = int(m); i < int(n); i++)
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()
#define INF 1e9 + 7
using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;
typedef long long ll;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = int_fast64_t;

int main(){
	int n;
	scanf("%d", &n);
	int t[n], a[n];
	for(int i=0; i<n; i++) scanf("%d", &t[i]);
	for(int i=0; i<n; i++) scanf("%d", &a[i]);
	int tk[n], ak[n];
	tk[0] = ak[n-1] = 1;
	for(int i=1; i<n; i++) tk[i] = (t[i]>t[i-1]);
	for(int i=n-2; i>=0; i--) ak[i] = (a[i]>a[i+1]);
	
	int_fast64_t ans = 1;
	for(int i=0; i<n; i++){
		if(tk[i] and ak[i]) ans *= (t[i]==a[i]);
		if(tk[i] and !ak[i]) ans *= (t[i]<=a[i]);
		if(!tk[i] and ak[i]) ans *= (t[i]>=a[i]);
		if(!tk[i] and !ak[i]) ans *= std::min(t[i], a[i]);
		ans %= 1000000007;
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 1792
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

N = i()
D = [l() for _ in range(N)]
cnt = 0
for i in range(N):
    if D[i][0] == D[i][1]:
        cnt += 1
        if cnt == 3:
            break
    else:
        cnt = 0
if cnt == 3:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 72640
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long N,A[100005]={0},i,ans=0,all=0;
	cin>>N;
	for(int n=1;n<=N;n++){
		cin>>A[n];
		all=all+abs(A[n]-A[n-1]);
	}
	all=all+abs(0-A[N]);
	for(i=1;i<=N;i++){
		ans=all-abs(A[i-1]-A[i])-abs(A[i]-A[i+1])+abs(A[i-1]-A[i+1]);
		cout<<ans<<endl;
	}
	return 0;
}

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

int main() {
    int n, k; cin >> n >> k;
    
    vector<int> v(n, 0);
    vector<int> good(n, 0);
    
    int part = 0;

    for(int i = 0; i < n; i += 1) {
        cin >> v[i];
        if(i > 0 and v[i] > v[i - 1]) {
            good[i] = 1;
        }
    }

    bool untouched = false;
    vector<int> minn(n, 0), maxx(n, 0);

    deque<int> min_d, max_d;
    
    int ans = 1;

    for(int i = 0; i < n; i += 1) {
        while(not min_d.empty() and v[min_d.back()] > v[i])
            min_d.pop_back();
        min_d.push_back(i);
        while(not min_d.empty() and i - min_d.front() >= k) 
            min_d.pop_front();

        while(not max_d.empty() and v[max_d.back()] < v[i])
            max_d.pop_back();
        max_d.push_back(i);
        while(not max_d.empty() and i - max_d.front() >= k)
            max_d.pop_front();

        minn[i] = min_d.front();
        maxx[i] = max_d.front();
        
        if(good[i])
            part += 1;
            
        if(i == k - 1 and part == k - 1) {
            untouched = true;
        }

        if(i >= k) {
            part -= good[i - k + 1];
            if(minn[i - 1] != i - k or maxx[i] != i) { 
                if(part == k - 1) {
                    if(not untouched) {
                        ans += 1;
                        untouched = true;
                    }
                } else {
                    ans += 1;
                }
            }
        }
    
        if(part == k - 1) {
            if(not untouched) {
                ans += 1;
                untouched = true;
            }
        }
        
        cerr << i << " " << ans << "\n";
    }

    cout << ans << "\n";
}

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

struct point
{
    int i;
    int j;
    int cost;
    point(int i, int j, int cost) : i(i), j(j), cost(cost) {}
};

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H, W, K;
    cin >> H >> W >> K;
    int si, sj, gi, gj;
    cin >> si >> sj >> gi >> gj;
    si--; sj--; gi--; gj--;
    vector<string> mp(H);
    for(int i=0; i<H; i++) cin >> mp.at(i);

    vector<vector<int>> cmp(H, vector<int>(W, -1));
    cmp[si][sj] = 0;
    auto comp = [](point a, point b){
        return a.cost > b.cost;
    };
    priority_queue<point, vector<point>, decltype(comp)> q {comp};
    q.emplace(si, sj, 0);
    while(!q.empty())
    {
        point p = q.top();
        q.pop();
        if(cmp[p.i][p.j] < p.cost) continue;
        // printf("%d %d %d %d\n", p.i, p.j, p.cost, p.mv);
        if(p.i == gi && p.j == gj) break;
        // 下方向の探索
        for(int i=p.i+1; i<H && i<=p.i+K; i++)
        {
            if((cmp[i][p.j]!=-1 && p.cost+1>cmp[i][p.j]) || mp[i][p.j] == '@') break;
            if(cmp[i][p.j] == -1)
            {
                cmp[i][p.j] = p.cost + 1;
                q.emplace(i, p.j, p.cost+1);
            }
            else if(chmin(cmp[i][p.j], p.cost + 1)) q.emplace(i, p.j, p.cost+1);
        }
        // 上方向の探索
        for(int i=p.i-1; i>=0 && i>=p.i-K; i--)
        {
            if((cmp[i][p.j]!=-1 && p.cost+1>cmp[i][p.j]) || mp[i][p.j] == '@') break;
            if(cmp[i][p.j] == -1)
            {
                cmp[i][p.j] = p.cost + 1;
                q.emplace(i, p.j, p.cost+1);
            }
            else if(chmin(cmp[i][p.j], p.cost + 1)) q.emplace(i, p.j, p.cost+1);
        }
        // 右方向の探索
        for(int j=p.j+1; j<W && j<=p.j+K; j++)
        {
            if((cmp[p.i][j]!=-1 && p.cost+1>cmp[p.i][j]) || mp[p.i][j] == '@') break;
            if(cmp[p.i][j] == -1)
            {
                cmp[p.i][j] = p.cost + 1;
                q.emplace(p.i, j, p.cost+1);
            }
            else if(chmin(cmp[p.i][j], p.cost + 1)) q.emplace(p.i, j, p.cost+1);
        }
        // 左方向の探索
        for(int j=p.j-1; j>=0 && j>=p.j-K; j--)
        {
            if((cmp[p.i][j]!=-1 && p.cost+1>cmp[p.i][j]) || mp[p.i][j] == '@') break;
            if(cmp[p.i][j] == -1)
            {
                cmp[p.i][j] = p.cost + 1;
                q.emplace(p.i, j, p.cost+1);
            }
            else if(chmin(cmp[p.i][j], p.cost + 1)) q.emplace(p.i, j, p.cost+1);
        }
    }
    cout << cmp[gi][gj] << endl;


    return 0;
}


Measured memory_bytes: 12132
while True:
    flg = True
    inf = []
    dic = {}
    n = int(input())
    if n==0:
        break
    for i in range(n):
        inf.append(list(map(int,input().split())))
        if inf[i][0] in dic:
            tmp = dic[inf[i][0]] + inf[i][1]*inf[i][2]
            dic[inf[i][0]] = tmp
        else:
            dic[inf[i][0]] = inf[i][1]*inf[i][2]

    for shain_id,sale in dic.items():
        if sale >= 1000000:
            print(shain_id)
            flg = False
    if flg:
        print("NA")
        

    # for i in inf:



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

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

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll Q, H, S, D; cin >> D >> S >> H >> Q;
	ll N; cin >> N;
	
	if (2 * D < S) S = 2 * D;
	if (2 * S < H) H = 2 * S;
	if (2 * H < Q) Q = 2 * H;

	ll ans = 0;
	ans += (N / 2) * Q;
	ans += (N % 2) * H;
	print(ans);
}

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

#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int, int>>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int, int>
#define int long long int
#define inf INT_MAX
#define _inf INT_MIN
#define whilet int t;cin>>t;while(t--)
const int N = 100005;


struct item {
	int wt, val;
};


int knapsack(vector<item>& ar, int n, int W) {

	int dp[n + 1][W + 1];

	for (int w = 0; w <= W; w++) dp[1][w] = 0;
	dp[1][ar[1].wt] = ar[1].val;

	for (int i = 2; i <= n; i++) {
		for (int w = 0; w <= W; w++) {
			dp[i][w] = dp[i - 1][w];
			if (w - ar[i].wt < 0 ) continue;
			dp[i][w] = max(dp[i][w], ar[i].val + dp[i - 1][w - ar[i].wt] );
		}
	}

	return *max_element(dp[n], dp[n] + W + 1 );
}

void solve() {

	int n, w;
	cin >> n >> w;

	vector<item> ar(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> ar[i].wt >> ar[i].val;
	}

	cout << knapsack(ar, n, w);
}

void init() {
	ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("../input.txt", "r", stdin);
	freopen("../output.txt", "w", stdout);
#endif
}


int32_t main()
{
	init();
	// whilet solve();
	solve();
}

Measured memory_bytes: 81596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    string t;
    t=s;
    sort(t.begin(),t.end());
    ll cnt=0;
    for(ll i=0;i<n;i++){
        if(s[i]!=t[i]){
            cnt++;
        }
    }
    cout<<cnt/2<<endl;
}

Measured memory_bytes: 3864
#include <iostream>

using namespace std;

int main() {
	int a, b, c, d, n, count, sum;

	while(cin >> n) {
		if(n>50)
			continue;
		count=0;
		for(a=0; a<10; a++) {
			for(b=0; b<10; b++) {
				for(c=0; c<10; c++) {
					for(d=0; d<10; d++) {
						sum=0;
						sum+=a+b+c+d;
						if(sum==n)
							count++;
						if(sum>35)
							break;

					}
				}
			}
		}
		cout << count << endl;
	}

	return 0;

}

Measured memory_bytes: 0
INF = int(1e9+7)
s = input()
d = list('abcdefghijklmnopqrstuvwxyz')
ans = INF
for i in d:
    lis = [-1]
    for j in range(len(s)):
        if s[j] == i:
            lis.append(j)
    lis.append(len(s))
    val = 0
    for j in range(1,len(lis)):
        val = max(val,lis[j]-lis[j-1]-1)
    ans = min(ans,val)
print(ans)


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

int main()
{
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  int max_xcity = x;
  for (int i = 0; i < n; i++) {
    int xcity;
    cin >> xcity;
    max_xcity = max(max_xcity, xcity);
  }
  int min_ycity = y;
  for (int i = 0; i < m; i++) {
    int ycity;
    cin >> ycity;
    min_ycity = min(min_ycity, ycity);
  }
  if (max_xcity < min_ycity) {
    cout << "No War\n";
  } else {
    cout << "War\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define db double

using namespace std;
const int N=100+10,M=N*N;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
int mod;
void ad(int &x,int y){x+=y,x-=x>=mod?mod:0;}
int fpow(int a,int b){int an=1;while(b){if(b&1) an=1ll*an*a%mod;a=1ll*a*a%mod,b>>=1;}return an;}
int ginv(int a){return fpow(a,mod-2);}
vector<int> e[N];
int n,m,k,c[N][N],pw[N][M],f[2][N][N],g[N][N];

int main()
{
///////////
    n=rd(),m=rd(),k=rd(),mod=rd();
    for(int i=0;i<=N-5;++i)
    {
	c[i][0]=1;
	for(int j=1;j<=i;++j) c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
    }
    for(int i=0;i<=N-5;++i)
    {
	pw[i][0]=1;
	for(int j=1;j<=M-5;++j) pw[i][j]=1ll*pw[i][j-1]*i%mod;
    }
    int nw=1,la=0,dx;
    f[la][0][0]=1;
    for(int h=1;h<=k;++h)
	for(int o=0;o<=1;++o)
	{
	    for(int j=0;j<=m;++j)
		for(int l=0;l<=n;++l)
		    g[j][l]=1ll*pw[k-h+1-o][l*j]*pw[h][l*(m-j)]%mod;
	    for(int i=0;i<=n;++i)
		for(int j=0;j<=m;++j)
		{
		    if(!f[la][i][j]) continue;
		    for(int l=0;i+l<=n;++l)
		    {
			dx=1ll*f[la][i][j]*c[n-i][l]%mod*g[j][l]%mod;
			ad(f[nw][i+l][j],(o&l&1)?mod-dx:dx);
		    }
		    f[la][i][j]=0;
		}
	    nw^=1,la^=1;
	    for(int i=0;i<=n;++i)
		for(int l=0;l<=m;++l)
		    g[i][l]=1ll*pw[k-h+1-o][l*i]*pw[h][l*(n-i)]%mod;
	    for(int i=0;i<=n;++i)
		for(int j=0;j<=m;++j)
		{
		    if(!f[la][i][j]) continue;
		    for(int l=0;j+l<=m;++l)
		    {
			dx=1ll*f[la][i][j]*c[m-j][l]%mod*g[i][l]%mod;
			ad(f[nw][i][j+l],(o&l&1)?mod-dx:dx);
		    }
		    f[la][i][j]=0;
		}
	    nw^=1,la^=1;
	}
    printf("%d\n",f[la][n][m]);
    return 0;
}


Measured memory_bytes: 5504
from collections import deque

n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
d = deque()
ans = a[0]
d.append(a[1])
d.append(a[1])
for i in a[2:]:
    ans+=d.popleft()
    d.append(i)
    d.append(i)
print(ans)

Measured memory_bytes: 94996
#include<iostream>
using namespace std;
#define mx 20005
int main(){
	//freopen("input.txt", "r", stdin);
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n, w;
	cin>>n>>w;
	int an[n], aw[n];
	for(int i = 0; i<n ; i++){
		cin>>aw[i]>>an[i];
	}

	long long dp[n+1][w+1];
	for(int i=0; i<=n; i++){
		for(int j=0; j<=w; j++){
			if(i==0 || j==0)dp[i][j]=0;

			else if(j>=aw[i-1]) dp[i][j] = max(dp[i-1][j], an[i-1]+dp[i-1][j-aw[i-1]]);

			else dp[i][j]=dp[i-1][j];
		}
	}

	cout<<dp[n][w]<<endl;
	return 0;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef pair<l_l,ll> lll;
typedef vector<string> vs;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
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;
}
ll n,m;
vector<l_l> g[220000];
struct Seg{
    vector<ll> sum;
    vector<ll> mx;
    Seg(){
        sum.resize(500000,0);
        mx.resize(500000,0);
    }
    void add_val(ll l,ll r,ll val,ll bottom=0,ll top=250000,ll pos=1){
        if(l<=bottom&&top<=r){
            sum[pos]+=val;
            return;
        }
        if(r<=bottom||top<=l){
            return;
        }
        ll mid=(bottom+top)/2;
        add_val(l,r,val,bottom,mid,pos*2);
        add_val(l,r,val,mid,top,pos*2+1);
        mx[pos]=max(mx[pos*2]+sum[pos*2],mx[pos*2+1]+sum[pos*2+1]);
    }
    ll max_val(ll l,ll r,ll bottom=0,ll top=250000,ll pos=1){
        if(l<=bottom&&top<=r){
            return sum[pos]+mx[pos];
        }
        if(r<=bottom||top<=l){
            return -LINF;
        }
        ll mid=(bottom+top)/2;
        return max(max_val(l,r,bottom,mid,pos*2),max_val(l,r,mid,top,pos*2+1))+sum[pos];
    }
};
int main(){
    cin>>n>>m;
    rep(i,m){
        ll l,r,a;cin>>l>>r>>a;
        g[r].pb({l,a});
    }
    Seg seg;
    for(int i=1;i<=n;i++){
        ll mx=seg.max_val(0,i);
        seg.add_val(i,i+1,mx);
        for(auto p: g[i]){
            ll l=p.fi;
            ll a=p.se;
            seg.add_val(l,i+1,a);
        }
    }
    cout<<seg.max_val(0,n+1)<<endl;
    return 0;
}

Measured memory_bytes: 22524
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include "math.h"
#include <set>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int N;
bool S[4];





int main()
{

	cin >> N;
	REP(i,N){
		char a;
		cin >> a;
		switch(a){
		case 'P':
			S[0] = true;
			break;
		case 'W':
			S[1] = true;
			break;
		case 'G':
			S[2] = true;
			break;
		case 'Y':
			S[3] = true;
			break;
		}
	}
	int ans = 0;
	REP(i,4){
		if(S[i])
			ans++;
	}

	if(ans == 4)
		cout << "Four";
	else
		cout << "Three";

}



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

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1e9+7
#define LINF (long long)4e18


int main(){
    int N; cin >> N;
    vector<int> a(N);
    int num = 0;
    rep(i,N){
        cin >> a[i];
        if(a[i] > 100000) num++;
    }
    vector<int> d(100001);
    rep(i,N){
        if(a[i] <= 100000) d[a[i]]++;
    }
    rep(i,100001){
        if(d[i] < i) num += d[i];
        else num += d[i] - i;
    }
    cout << num << endl;

}


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

int main(){
  string S;
  cin >> S;
  int N = S.size();
  bool judge1 = false;
  int count1 = 0;
  for(int i = 0; i < (N - 1) / 2; i++){
    if(S.at(i) == S.at((N - 1) / 2 - i - 1)) count1++;
  }
  if(count1 == (N - 1) / 2) judge1 = true;
  
  bool judge2 = false;
  int count2 = 0;
  for(int i = (N + 3) / 2 - 1; i < N; i++){
    if(S.at(i) == S.at(N - i - 1)) count2++;
  }
  if(count2 == (N - (N + 3) / 2 + 1)) judge2 = true;
  if(judge1 && judge2) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
bool isPrime(ll n){
	if(n==1)return false;
	for(ll i=2;i*i<=n;i++)if(n%i==0)return false;
	return true;
}
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x;
	cin>>x;
	while(1){
		if(isPrime(x)){
			cout<<x<<endl;
			return 0;
		}
		x++;
	}
}


Measured memory_bytes: 256
package main

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

type Node struct {
	left  *Node
	val   int
	right *Node
}

func main() {
	var nOps int
	fmt.Scan(&nOps)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	var node *Node
	for i := 0; i < nOps; i++ {
		sc.Scan()
		switch sc.Text() {
		case "insert":
			sc.Scan()
			val, _ := strconv.Atoi(sc.Text())
			node = insert(node, val)
		case "print":
			printValues(listByInOrder(node, []int{}))
			printValues(listByPreOrder(node, []int{}))
		}
	}
}

func printValues(vs []int) {
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range vs {
		buf.Write([]byte(fmt.Sprintf(" %d", v)))
	}
	buf.Write([]byte("\n"))
	buf.Flush()
}

func listByInOrder(node *Node, vs []int) []int {
	if node != nil {
		vs = listByInOrder(node.left, vs)
		vs = append(vs, node.val)
		vs = listByInOrder(node.right, vs)
	}
	return vs
}

func listByPreOrder(node *Node, vs []int) []int {
	if node != nil {
		vs = append(vs, node.val)
		vs = listByPreOrder(node.left, vs)
		vs = listByPreOrder(node.right, vs)
	}
	return vs
}

func insert(node *Node, val int) *Node {
	if node == nil {
		return &Node{nil, val, nil}
	}

	var parent *Node
	nd := node
	for nd != nil {
		parent = nd
		if nd.val > val {
			nd = nd.left
		} else {
			nd = nd.right
		}
	}

	if parent.val > val {
		parent.left = &Node{nil, val, nil}
	} else {
		parent.right = &Node{nil, val, nil}
	}

	return node
}


Measured memory_bytes: 49400
//Totka hai dosto
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll

int32_t main()
{
	int n;
	cin>>n;
	map<int, int> ff;
	map<int , int> ss;
	int ans=0;
	
	int a[n];
	for(auto &i:a)cin>>i;
	for(int i=0;i<n;i++)
	{
		ff[a[i]-i]++;
		ans+=ss[a[i]-i];
		ss[-(a[i]+i)]++;
	}
	cout<<ans;
}

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

using namespace std;

typedef long long ll;

int main()
{

    int n; cin >> n;
    
    if (n > 81) {
        cout << "No" << endl;
        return 0;
    }

    for(int i = 1; i < 10; i++) {
        if(n%i == 0) {
            if(n/i < 10) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;
    return 0;
}

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

int main(){
	int h,w;
	int field[1400][1400],squ[1400][1400] = {};
	int ma = 0;
	cin >> h >> w;
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			cin >> field[i][j];
		}
	}
	for(int i = 0;i < h;i++){
		if(!field[i][0]) {
			squ[i][0] = 1;
			ma = 1;
		}
	}
	for(int i = 1;i < w;i++){
		if(!field[0][i]) {
			squ[0][i] = 1;
			ma = 1;
		}
	}
	for(int i = 1;i < h;i++){
		for(int j = 1;j < w;j++){
			if(field[i][j]) continue;
			squ[i][j] = min(squ[i - 1][j],min(squ[i][j - 1],squ[i - 1][j - 1])) + 1;
			ma = max(ma,squ[i][j]);
		}
	}
	cout << ma * ma << endl;
	return 0;
}

Measured memory_bytes: 18380
#include<iostream>
#define maxn 105
#define maxg 100005

using namespace std;

long long W[maxn], P[maxn];
long long Optim[maxg];

int main() {


	int N, G;
	cin>>N>>G;

	for (int i = 1; i <= N; ++i)
		cin>>W[i]>>P[i];

	Optim[0] = 0;
	for(int i=1;i<=1e5;i++)
        Optim[i]=1e15;
	long long sol = 0;

	for( int i = 1; i <= N; ++i)
		for( int j = 1e5 - P[i]; j >= 0; --j) {
			if( Optim[j+P[i]] > Optim[j] + W[i] )
			{
				Optim[j+P[i]] = Optim[j] + W[i];
				if( Optim[j+P[i]] <= G)
					sol = max(j+P[i],sol);
			}
		}
	cout<<sol;
	return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env php
<?php
const YES = "Yes";
const NO = "No";

function solve($N, $gen) {
    $pre_x = 0;
    $pre_y = 0;
    $pre_t = 0;
    while ($gen->valid()) {
        $time = $gen->current(); $gen->next();
        $cur_x = $gen->current(); $gen->next();
        $cur_y = $gen->current(); $gen->next();
        $move_t = $time - $pre_t;
        $move_s = abs($cur_x - $pre_x) + abs($cur_y - $pre_y);
        if ($move_s > $move_t) {
            echo NO.PHP_EOL;
            return;
        }
        if (($move_s % 2) != ($move_t % 2)) {
            echo NO.PHP_EOL;
            return;
        }

        $pre_x = $cur_x;
        $pre_y = $cur_y;
        $pre_t = $time;
    }
    echo YES.PHP_EOL;
}

function getInputs() {
    while(($input = fgets(STDIN)) !== false) {
        foreach (explode(' ', $input) as $v) {
            yield $v;
        }
    }
}

$gen = getInputs();
$N = $gen->current(); $gen->next();
solve($N, $gen);


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

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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  string ans = "Yes";

  while(A>0&&C>0){
    C -= B;
    A -= D;
  }

  if(C<=0) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 3620
s=int(input())
a=[]*1000000
a+=[s]
def F(n):
    if n%2==0:
        return n//2
    else:
        return 3*n+1

for i in range(1,1000000):
    a.append(F(a[i-1]))
    if a[i] in a[:i]:
        ans=i+1
        break 

print(ans)

Measured memory_bytes: 3060
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int M = 1e6 + 10;
const int mod = 998244353;

int n, m;
int fac[M], inv[M];

inline int pwr(int a, int b) {
  int res = 1;
  while(b) {
    if(b & 1) res = 1ll * res * a % mod;
    a = 1ll * a * a % mod;
    b >>= 1;
  }
  return res;
} 

inline int C(int n, int m) {
  if(n < m || m < 0 || n < 0) return 0;
  return 1ll * fac[n] * inv[m] % mod * inv[n-m] % mod;
}

int main() {
  cin >> n >> m;
  if(n < m) swap(n, m);
  fac[0] = 1;
  for (int i = 1; i <= n + n; ++ i) fac[i] = 1ll * fac[i-1] * i % mod;
  inv[n + n] = pwr(fac[n + n], mod - 2);
  for (int i = n + n - 1; ~i; -- i) inv[i] = 1ll * inv[i+1] * (i+1) % mod;
  
  int ans = 0;
  for (int i = m; i; --i) {
    ans = ans + 1ll * C(i << 1, i) * C(n + m - (i << 1), n - i) % mod;
    if(ans >= mod) ans -= mod;
  }
  
  ans = 1ll * ans * pwr(2ll * C(n + m, n) % mod, mod - 2) % mod;
  ans = ans + n;
  if(ans >= mod) ans -= mod;
  cout << ans;
  
  return 0;
}




Measured memory_bytes: 8064
#include <iostream>

using namespace std;

const long MOD = 1000000007;

long dp[101][101][256];

int main(){
    int n, k;
    int a[100];
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    dp[0][0][0] = 1;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < 256; j++){
            for(int k = 0; k < n; k++){
                dp[i][k+1][j^a[i]] += dp[i-1][k][j];
                dp[i][k][j] += dp[i-1][k][j];
                dp[i][k+1][j^a[i]] %= MOD;
                dp[i][k][j] %= MOD;
            }
        }
    }
    
    long ans = 0;
    long fac = 1;
    for(int i = 1; i <= n; i++){
        fac *= i;
        fac %= MOD;
        ans += (fac*dp[n][i][k])%MOD;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 20480
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long int n,ans;

int main()
{
    scanf("%d",&n);
    ans = 1;
    for (int i = 2;i<=n; ++i)
    {
        ans = ((ans % mod) * i) % mod;
    }
    printf("%I64d",ans);
}


Measured memory_bytes: 256
from sys import stdin, stdout

s = stdin.readline().strip()
k = int(stdin.readline())
challengers = []

for i in range(len(s)):
    cur = ''
    for j in range(i, min(i + 5, len(s))):
        cur += s[j]
        challengers.append(cur)

challengers.sort()

for i in range(len(challengers)):
    if not i or challengers[i - 1] != challengers[i]:
        k -= 1
    
    if not k:
        stdout.write(challengers[i])
        break

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

import sys
import os
import datetime

d = {}
words = input().split()
longest_word = ''
for word in words:
    if len(word) > len(longest_word):
        longest_word = word

    if word not in d:
        d[word] = 1
    else:
        d[word] += 1

max_value = max(d.values())

for key in d.keys():
    if d[key] == max_value:
        print(key, longest_word)

Measured memory_bytes: 7788
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec[i];
  }
  
  
  int x=0;
  
  for(int i=0;i<N;i++){
    if(vec[i]!=i+1){
      x++;
    }
  }
  
  if(x<=2){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
/*vector<Type> v;
vector<Type> v();
vector<Type> v(n);
vector<Type> v(n, d);
vector<vector<Type>> vv;
vector<vector<Type>> vv();
vector<vector<Type>> vv(n);
vector<vector<Type>> vv(n, vector<Type>(m));
vector<vector<Type>> vv(n, vector<Type>(m, d));*/

int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  rep(i,n){
    cin >> a[i];
  }
  long long max=0, sum=0;
  rep(i,n){
    if(a[i]<max){
      sum += max - a[i];
    }else if(a[i]>max){
      max = a[i];
    }
  }
  cout << sum;
  return 0;
}


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

ll digitSum(ll n)
{
    ll s = 0;
    while (n)
    {
        s += n % 10;
        n /= 10;
    }
    return s;
}

void Main()
{
    int n, a, b;
    cin >> n >> a >> b;
    int cnt = 0;
    REP(i, 1, n + 1)
    {
        int s = digitSum(i);
        if (s >= a && s <= b)
            cnt += i;
    }
    cout << cnt << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int h, w;

    cin >> h >> w;

    int ch, cw, dh, dw;
    cin >> ch >> cw >> dh >> dw;
    ch--;
    cw--;
    dh--;
    dw--;

    vector<vector<char>> maze(h, vector<char>(w));
    vector<vector<ll>> warp(h, vector<ll>(w, INF));

    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> maze[i][j];
        }
    }

    queue<P> q, visited;

    q.push({ch, cw});
    warp[ch][cw] = 0;

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

    while (q.size() || visited.size())
    {
        if (q.size())
        {
            P p = q.front();
            q.pop();

            int x = p.first, y = p.second;
            visited.push({x, y});

            for (int i = 0; i < 4; i++)
            {
                int next_x = x + dx[i], next_y = y + dy[i];

                if (next_x < 0 || next_y < 0 || next_x >= h || next_y >= w)
                {
                    continue;
                }

                if (maze[next_x][next_y] == '#')
                {
                    continue;
                }

                if (warp[x][y] < warp[next_x][next_y])
                {
                    warp[next_x][next_y] = warp[x][y];

                    q.push({next_x, next_y});
                }
            }
        }
        else
        {
            P p = visited.front();
            visited.pop();

            int x = p.first, y = p.second;

            for (int i = -2; i < 3; i++)
            {
                for (int j = -2; j < 3; j++)
                {
                    int next_x = x + i, next_y = y + j;

                    if (next_x < 0 || next_y < 0 || next_x >= h || next_y >= w)
                    {
                        continue;
                    }

                    if (maze[next_x][next_y] == '#')
                    {
                        continue;
                    }

                    if (warp[x][y] + 1 < warp[next_x][next_y])
                    {
                        warp[next_x][next_y] = warp[x][y] + 1;

                        q.push({next_x, next_y});
                    }
                }
            }
        }
    }

    if (warp[dh][dw] == INF)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << warp[dh][dw] << endl;
    }
}


Measured memory_bytes: 12452
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main(){
 
    int v[6];
    int t[4] ={};
 
    cin >> v[0] >> v[1];
    cin >> v[2] >> v[3];
    cin >> v[4] >> v[5];
 
    for(int i; i < 6; i++){
        t[v[i] - 1]++;
    }
 
    sort(t, t + 4);
 
    if(t[0] == 1 && t[1] == 1 && t[2] == 2 && t[3] == 2){
        cout << "YES";
    }else cout << "NO";
 
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;


public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int K = sc.nextInt();
   Integer a[] = new Integer[N];
   for(int i=0; i<N; i++){
	   a[i] = sc.nextInt();
   }
   long sum = 0;
   Arrays.sort(a, Collections.reverseOrder());
   if(K > N) {K = N;}
   for(int i=0; i<K; i++){
	   a[i] = 0;
   }

   for(int i=0; i<N; i++) {
	   sum += a[i];
   }

   System.out.println(sum);

   }
}


Measured memory_bytes: 91336
/*
 *
 */
#include <cstdio>
#include <iostream>

using namespace std;

int main(){
    //freopen("c.in", "r", stdin);
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < s.size() - 1; ++i) {
        if (s[i] != s[i+1]) ans++;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 512
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		long k=s.nextLong();
		if(n*500>=k)
		System.out.println("Yes");
		else
		System.out.println("No");
	}
}

Measured memory_bytes: 22608
from statistics import median

N = int(input())
numbers = [int(a)-i for i, a in enumerate(input().split())]
b = median(numbers)
abs_1 = sum([abs(c-int(b)) for c in numbers])
abs_2 = sum([abs(c-int(b)-1) for c in numbers])
print(min(abs_1, abs_2))

Measured memory_bytes: 27248
N, M = input().split()
N, M = [int(N), int(M)]
x = [None] * (M+1)
y = [None] * (M+1)

for i in range(1, M+1):
    x[i], y[i] = input().split()
    x[i], y[i] = [int(x[i]), int(y[i])]

R = [0] + [1] + [0] * (N-1) # 赤いボールが入っている可能性があるかどうか
S = [0] + [1] * (N) # ボールの個数

for i in range(1, M+1):
    S[x[i]] -= 1
    S[y[i]] += 1

    if R[x[i]] == 1:
        R[y[i]] = 1
        if S[x[i]] == 0:
            R[x[i]] = 0

sum = 0
for i in range(1, N+1):
    sum += R[i]

print(sum)

Measured memory_bytes: 13284
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext())
        {
          int x = in.nextInt();
          int y = in.nextInt();
          int z = in.nextInt();
          int max = 0;
          int min =0;
          if(x==y && y==z)
              max=x;
          if(x==y)
          {
              if(y>z)
                  max=y;
              else
                  max=z;
          }
          if(x>y){
              if(x>z) {
                  max = x;
                  min=z;
              }
              else if(y>z) {
                  max = y;
                  min =z;
              }
              else {
                  max = z;
                  min =y;
              }
          }
          else
          {
              if(y>x)
              {
                  if(y>z) {
                      max = y;
                      min = x;
                  }
                  else {
                      max = z;
                      min=x;
                  }
              }
          }

          String s = Integer.toString(y);
          String t = Integer.toString(z);
          String q = Integer.toString(x);
          if(max==y) {
              String v = s+z;
              System.out.println(Integer.valueOf(v)+x);
          }
          else if(max==z) {
              String r = t+y;
              System.out.println(Integer.valueOf(r)+x);
          }
          else if(max==x){
              String f = q+y;
              System.out.println(Integer.valueOf(f)+z);
          }

        }
    }
}


Measured memory_bytes: 24020
#include<stdio.h>
 int main(void){
     long long int x,z,a=100,flg=0;
     scanf("%lld",&x);
     for(int i=0;i>=0;i++){
         flg++;
         z=a+a/100;
         if(z>=x){
             printf("%lld",flg);
             return 0;
         }
         a=z;
     }
 }

Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include<set>
using namespace std;
using ll = long long;
#define PI (acos(-1))

int main()
{
  int X;
  cin >> X;
  int n=0;

  while(X >= 0){
    n++;
    X-=200;
  }

  cout << 11-n;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }
 

ll N, M, Q;
vector<ll> A, B, C, D;

ll calc(vector<ll> &a)
{
	ll res{0};
	for (ll i = 0; i < Q; ++i)
		if (a[B[i]-1] - a[A[i]-1] == C[i]) res += D[i];
	return res;
}

void dfs(vector<ll> &a, ll &res)
{
	if ((ll)a.size() == N)
	{
		// std::cout << a << std::endl;
		res = max(res, calc(a));
		return;
	}

	ll ba = a.back();
	for (ll add = ba; add <= M; ++add)
	{
		a.push_back(add);
		dfs(a, res);
		a.pop_back();
	}
}

int main(int argc, char **argv)
{
	cin >> N >> M >> Q;
	A.resize(Q);
	B.resize(Q);
	C.resize(Q);
	D.resize(Q);

	for (ll i = 0; i < Q; ++i) cin >> A[i] >> B[i] >> C[i] >> D[i];
	vector<ll> a{1};
	ll res{0};
	// for (ll i = 1; i <= M; ++i)
	// {
	// 	a.push_back(i);
	// 	dfs(a, res);
	// 	a.pop_back();
	// }
	dfs(a, res);
	std::cout << res << std::endl;
}


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


int main(){
	int n,k;
	string s;
	cin >> n >> k;
	cin >> s;
	if(s.at(k-1)=='A'){
		s.at(k-1)='a';
	}else if(s.at(k-1)=='B'){
		s.at(k-1)='b';
	}else if(s.at(k-1)=='C'){
		s.at(k-1)='c';
	}
	cout << s << endl;
	
}


Measured memory_bytes: 256
S = input()

S1='abc'
S2='acb'
S3='bac'
S4='bca'
S5='cab'
S6='cba'
if S==S1:
    print ('Yes')
elif S==S2:
    print ('Yes')
elif S==S3:
    print ('Yes')
elif S==S4:
    print ('Yes')
elif S==S5:
    print ('Yes')
elif S==S6:
    print ('Yes')
else:
    print ('No')

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int n;
	int ssn;
	int i;
	int bit[7] = {0};
	int sd[10][7] = {
		{0, 1, 1, 1, 1, 1, 1},
	    {0, 0, 0, 0, 1, 1, 0},
	    {1, 0, 1, 1, 0, 1, 1},
	    {1, 0, 0, 1, 1, 1, 1},
	    {1, 1, 0, 0, 1, 1, 0},
	    {1, 1, 0, 1, 1, 0, 1},
	    {1, 1, 1, 1, 1, 0, 1},
	    {0, 1, 0, 0, 1, 1, 1},
	    {1, 1, 1, 1, 1, 1, 1},
	    {1, 1, 0, 1, 1, 1, 1},
	};
	
	while (scanf("%d", &n), n != -1){
		
		while (n--){
			scanf("%d", &ssn);
			for (i = 0; i < 7; i++){
				if (bit[i] == sd[ssn][i]){
					printf("0");
				}
				else {
					printf("1");
				}
				bit[i] = sd[ssn][i];
			}
			printf("\n");
		}
		for (i = 0; i < 7; i++){
			bit[i] = 0;
		}
	}
	
	return (0);
}

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

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

int main() {
  int n, k, b, c;
  cin >> n >> k;
  vector<ll> v(k);

  for (int i = 1; i <= n; ++i) v[i % k]++;

  ll ans = 0;
  for (int a = 0; a < k; ++a) {
    b = c = (k - a) % k;
    if ((b + c) % k != 0) continue;
    ans += v[a] * v[b] * v[c];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
import math
A, B ,H, M = map(int, input().split())

H_rad = H*360/12 +((M*360)/(60*12))

M_rad = M*360/60
AtoB_Cos = math.cos(math.radians(H_rad-M_rad)) 

solve = math.sqrt(A*A+B*B-2*A*B*AtoB_Cos)
print(solve)

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

#define endl '\n'
#define fr first
#define sc second

using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> ii;
const int NMAX = 1e5 + 1, INF = 1e9;
ll LINF = 1e18;
const double EPS = 1e-8;

main()
{
//    freopen("input.txt", "r", stdin);
    int n;
    scanf("%d", &n);
    ll ans = 1;
    vector<ll> t(n);
    for (int i = 0; i < n; ++i) {
        scanf("%lld", &t[i]);
        ans = ans / __gcd(ans, t[i]) * t[i];
    }
    printf("%lld", ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s; cin >> s;
    int first = 10000000, last = 0;
    for(int i = 0; i<s.size(); i++){
        if(s[i] == 'A') first = min(first, i);
    }
    for(int i = s.size()-1; 0<i; i--){
        if(s[i] == 'Z') last = max(last,i);
    }
    cout << last+1-first << endl;
    return 0;
}

Measured memory_bytes: 640