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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    int n; cin >> n;
    vector<int> v(n), blk;
    rep(i, 0, n) cin >> v[i];
    int ans = 0;
    rep(i, 0, n) {
        if (blk.empty()) blk.push_back(v[i]);
        else if (blk.back() == v[i]) blk.push_back(v[i]);
        else {
            ans += blk.size() / 2;
            blk.clear();
            blk.push_back(v[i]);
        }
    }
    ans += blk.size() / 2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 55;
typedef long long ll;
const int mod = 1e9+7;
inline int add(int a,int b){a+=b;return a>=mod?a-mod:a;}
inline int mul(int a,int b){return 1ll*a*b%mod;}
int n;
int dp[N][N],binom[N][N];
int main()
{
	cin >> n ;
	for(int i=0;i<=n;i++){
		binom[i][0] = binom[i][i] = 1;
		for(int j=1;j<i;j++)binom[i][j] = add(binom[i-1][j-1], binom[i-1][j]);
	}
	dp[1][0] = dp[1][1] = 1;
	for(int i=1;i<=n;i++)
		for(int j=0;j<=i;j++)if(dp[i][j]){
			for(int x=0;x+i<=n;x++)for(int y=0;x+y+i<=n;y++)if(x+y && x+y >= j && !((x+y-j)&1)){
				dp[i+x+y][abs((x+y-j)/2+j-x)] = add(dp[i+x+y][abs((x+y-j)/2+j-x)],
						mul(dp[i][j],mul(binom[i+x+y][x+y],binom[x+y][x])));
			}
		}
	printf("%d\n",dp[n][0]);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define clr cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define _val(x) cerr << #x << " is " << x << "\n";
#define all(container) container.begin(), container.end()
#define rall(container) container.rbegin(), container.rend()
#define rep(i, a, b, c) for(ll i = a; i <= b; i += c)
#define rrep(i, a, b, c) for(ll i = a; i >= b; i -= c)
#define pb push_back
#define mp make_pair

using namespace std;

const double eps = 1e-10;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef pair<long long, long long> pll;
typedef vector<pair<long long, long long> > vpll;
const int INF = 0x3f3f3f3f;

int main(void){
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt", "r", stdin);
	// 	freopen("output.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	ll n; cin >> n;
	ll a[n], b[n], c[n], dp[n][3];
	rep(i, 0, n-1, 1) cin >> a[i] >> b[i] >> c[i];
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	rep(i, 1, n-1, 1) {
		dp[i][0] = max(dp[i-1][1], dp[i-1][2])+a[i];
		dp[i][1] = max(dp[i-1][0], dp[i-1][2])+b[i];
		dp[i][2] = max(dp[i-1][0], dp[i-1][1])+c[i];
	}
	cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << "\n";
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>

typedef long long int lli;

using namespace std;

int main() {
   
   int x;
   for(int i=0;i<5;i++){
      cin >> x;
      if(x==0){
         cout << i+1 << endl;
         return 0;
      }
   }
}

Measured memory_bytes: 3588
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <stdio.h>
#include <math.h>
#include <utility>
#include <algorithm>

using namespace std;

int main()
{
	string b;
	cin >> b;
	string c;
	if (b == "A") {
		c = "T";
	}
	if (b == "T") {
		c = "A";
	}
	if (b == "C") {
		c = "G";
	}
	if (b == "G") {
		c = "C";
	}
	cout << c;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;
class Main{


	static final int MOD = 1000000007;


	static int ans = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int N = sc.nextInt();

		System.out.println(N*N*N);


		


		




	}
	
	
	static int dfs(int x,int y,int b){
//		
		if(b < 0){
			return 0;
		}
		if(b % 3 != 0){
//			System.out.println(0);
			return 0;
		}
		if(y == 2*x){
//			System.out.println(1);
//			System.out.println(11);

			return 1;
		}else if(y == 0.5*x){
//			System.out.println(1);

			return 1;
		}else if((double)y/x > 2 ||(double)y/x < 0.5){
//			System.out.println(0);
			return 0;
		}else{
			
			int uehazix = b/3;
			int uehaziy = -uehazix + b;
			int sitahazix = 2*b/3;
			int sitahaziy = -uehazix + b;
			if(Math.abs(uehazix - x)== Math.abs(sitahazix - x)){
				return 2*dfs(x-2, y-1, b-3);
			}
			int dif = Math.min(Math.abs(uehazix - x), Math.abs(sitahazix - x));
			
			if(dif == 1){
				return b/3;
			}
			return (dfs(x-2, y-1, b-3) + dfs(x-1, y-2, b-3))%MOD;
		}
		

		
	}

	static void sieve(ArrayList<Long> list){
		int n = 50000000;
		boolean[] is_prime = new boolean[n+1];
		int[] prime = new int[n];
		for(int i= 0;i <=n;i++){
			is_prime[i] = true;
		}
		list.add((long) 1);
		for(int i = 2;i <= n;i++){
			if(is_prime[i]){
				list.add((long)i);
				for(int j = 2*i;j <= n;j+=i){
					is_prime[j] = false;
				}
			}
		}



	}




	static int upperbond(int k,int min,int[] data){		//kより小さい最大の値をdataの中から探し、返す二分探索
		int max = data.length;
		//		if(min == data.length-1){
		//			if(data[min] > k){
		//				return min;
		//			}
		//		}

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}

		return max;
	}

	static int lowerbond(int k,int min,int[] data){		//kより大きい最小の値をdataの中から探し、返す二分探索
		int max = data.length;

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}
		return min;
	}



	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}

class Town{
	int index;
	int x ;
	int y;
	public Town(int index,int x,int y) {
		this.index = index;
		this.x = x;
		this.y = y;
		// TODO 自動生成されたコンストラクター・スタブ
	}
	
	
}


class Edge extends ArrayList<P>{

}

class P{
	int to;
	long cost;
	P(int to,long cost){
		this.to = to;
		this.cost = cost;
	}
}


class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return   from- otherpair.from;
	}








}






Measured memory_bytes: 21076
;; A - Table Tennis Training

(let* ((n (read))
       (a (read))
       (b (read)))
  (print
    (if (evenp (- b a))
        (/ (- b a) 2)
        (min (/ (+ a b -1) 2) ; aが卓1へ行った後折り返す
             (/ (+ (- n a) (- n b) 1) 2))))) ; bが卓nへ行った後折り返す

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

// input
string A, B, C;


void input() {
    cin >> A >> B >> C;
}


int main() {
    input();
    string ans;
    if (A.back() == B[0] && B.back() == C[0]) ans = "YES";
    else ans = "NO";
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <limits>
#include <algorithm>
#include <set>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,f,t) for(int i=f;i<t;i++)
#define P(ary) do { for(auto i:ary){ cout << i << " "; } cout << endl; } while (0)
int main()
{
    int N; cin >> N;
    vector<int> A(100000);
    REP(i, N) {
        int a; cin >> a;
        A[a] += 1;
    }
    int result = 0;
    REP(i, A.size() - 2) {
        result = max(result, A[i] + A[i+1] + A[i+2]);
    }
    cout << result << endl;
    return 0;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int W, H, N; cin >> W >> H >> N;
  int mins[] {0, 0};
  int maxs[] {W, H};
  rep(i, N) {
    int x, y, a; cin >> x >> y >> a;
    if(a == 1) mins[0] = max(mins[0], x);
    if(a == 2) maxs[0] = min(maxs[0], x);
    if(a == 3) mins[1] = max(mins[1], y);
    if(a == 4) maxs[1] = min(maxs[1], y);
  }

  cout << max(0, (maxs[0] - mins[0])) * max(0, (maxs[1] - mins[1])) << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<double> v(n);
    rep(i, n) cin >> v[i];
    sort(v.begin(), v.end());
    double ans = v[0];
    rep(i, n - 1) ans =(ans+v[i + 1])/2;
    printf("%lf\n",ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
using namespace std;

struct Info{
	void init(){
		isL = false;
		isB = false;
	}
	bool isL,isB;
};

int main(){

	int N,T,L,B,tmp,next_pos;
	double ans,dp[102][102];

	Info info[101];

	while(true){
		scanf("%d %d %d %d",&N,&T,&L,&B);
		if(N == 0 && T == 0 && L == 0 && B == 0)break;

		for(int i = 0; i <= T; i++){
			for(int k = 0; k <= N; k++){
				dp[i][k] = 0;
			}
		}

		for(int i = 0; i <= N; i++)info[i].init();

		for(int i = 0; i < L; i++){
			scanf("%d",&tmp);
			info[tmp].isL = true;
		}

		for(int i = 0; i < B; i++){
			scanf("%d",&tmp);
			info[tmp].isB = true;
		}

		ans = 0;
		dp[0][0] = 1;

		for(int turn = 0; turn <= T-1; turn++){
			for(int pos = 0; pos <= N-1; pos++){
				if(info[pos].isB == true || dp[turn][pos] < 0.000000001)continue;

				for(int div = 1; div <= 6; div++){
					if(pos + div > N){
						next_pos = N - (pos+div-N);
					}else{
						next_pos = pos+div;
					}

					if(info[next_pos].isB == true){
						dp[turn+1][0] += dp[turn][pos]/6.0;
					}else if(info[next_pos].isL == true){
						dp[turn+2][next_pos] += dp[turn][pos]/6.0;
					}else{
						dp[turn+1][next_pos] += dp[turn][pos]/6.0;
					}
				}
			}
			ans += dp[turn+1][N];
		}

		printf("%.6lf\n",ans);
	}

	return 0;
}

Measured memory_bytes: 2644
#include<stdio.h>

int main(void){
	int i,j,h,n,a[5000],max=0,sum;
	scanf("%d",&n);
	while(n!=0){
		for(i=0; i<n; i++){
			scanf("%d",&a[i]);
		}
		for(i=0; i<n; i++){
			sum=0;
			for(j=i; j<n; j++){
				sum+=a[j];
				if((i==0 && j==0) || max<sum){
					max=sum;
				}
			}
		}
		printf("%d\n",max);
		scanf("%d",&n);
	}
	return 0;
}

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

int main() {
	// your code goes here
  int l,r,d;
  cin>>l>>r>>d;
  int cnt=0;
  while(l<=r)
  {
    if(l%d==0)
      cnt++;
    l++;
  }
  cout<<cnt;
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
     
    using namespace __gnu_pbds;
    using namespace std;
     
    #define ff first
    #define ss second
    #define pb push_back
    #define pf push_front
    #define mp make_pair
    #define popb pop_back
    #define popf pop_front
    #define all(v) v.begin(), v.end()
    #define fori(i, j, k) for (int i = (j); i < (int)(k); i++)
    #define forb(i, j, k) for (int i = (j); i >= (int)k; i--)
    #define lchild(ind) 2 * ind + 1
    #define rchild(ind) 2 * ind + 2
    #define bug(val) cout << "# " << val << endl;
    #define bugs(val) cout << '_' << val;
    #define bugl(val) cout << "## " << val << endl;
     
    template<typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
    typedef long long ll;
    typedef long double ld;
    typedef pair<int, int> pii;
    typedef pair<int, ll> pil;
    typedef pair<ll, int> pli;
    typedef pair<ll, ll> pll;
    typedef pair<int, pll> pip;
    typedef pair<ll, pll> plp;
    typedef pair<pll, int> ppi;
    typedef pair<pll, ll> ppl;
    typedef pair<pll, pll> ppp;
    typedef vector<int> vi;
    typedef vector<ll> vll;
     
    const int maxn = 1e5 + 1;
    const ll inf = 2e18, mod = 1e9 + 7;
     
    int n, a[maxn];
     
    bool solve()
    {
    	int o = 0;
    	fori (i, 0, n)
    		if (a[i] & 1)
    			o++;
    	int e = n - o;
    	if (e & 1)
    		return true;
    	else
    	{
    		if (o == 1)
    		{
    			int val = -1;
    			fori (i, 0, n)
    				if (a[i] & 1)
    					val = a[i];
    			if (val == 1)
    				return false;
    			val--;
    			fori (i, 0, n)
    				if (!(a[i] & 1))
    					val = __gcd(val, a[i]);
    			fori (i, 0, n)
    				a[i] /= val;
    			return !solve();
    		}
    		else if (o > 1)
    			return false;
    	}
    	return false;
    }
     
    int main()
    {
    	ios_base::sync_with_stdio(false);
    	cin.tie(0);
     
    	cin >> n;
    	fori (i, 0, n)
    		cin >> a[i];
    	bool ans = solve();
    	cout << (ans ? "First" : "Second") << endl;
    }
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     
     

Measured memory_bytes: 640
N, M = gets.chomp.split(" ").map(&:to_i)
A = gets.chomp.split(" ").map(&:to_i).uniq

l = 1
A.each {|a| l = l.lcm(a/2)}

require "prime"
b = A.map{|a| a.prime_division.to_h[2] || 0 }

if b.min == b.max
  m = M / l
  if m % 2 == 1
    puts m / 2 + 1
  else
    puts m / 2
  end
else
  puts 0
end


Measured memory_bytes: 11916
#include<iostream>
//#include<>
using namespace std;
int main(){
	string s;
  	cin >> s;
  int n = s.size();
  int count = 0;
  	for (int i = 0; i < n; i++){
    	if(i%2 == 0 && s[i]=='0' ) count += 1;
      	else if(i%2==1 && s[i]=='1') count += 1;
    }
  if(count < n/2 +1) cout<< count <<'\n';
  else cout << n-count <<'\n';

	return 0;
}

Measured memory_bytes: 512
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
gcd = math.gcd
n,k = ma()
A = list(ma())
def imos(ls,st,ed):
    n = len(ls) -2
    for i in range(n):
        if 0< st[i]:
            ls[st[i]] += 1
        else:
            ls[0] +=1
        if ed[i] <=n:
            ls[ed[i]+1] -=1
        else:
            ls[n+1] -=1
    for i in range(n+1):
        ls[i+1] += ls[i]
low = []
high = []
ls = [0]*(n+2)
for i in range(n):
    a = A[i]
    low.append(i+1-a)
    high.append(i+1+a)
for i in range(k):
    imos(ls,low,high)
    if ls[1:-1] == [n]*n:
        break
    #print(ls[1:-1])
    if i==k-1:break
    for j in range(n):
        a = ls[j+1]
        low[j] = j+1-a
        high[j] = (j+1+a)
    ls = [0]*(n+2)
print(*ls[1:-1])


Measured memory_bytes: 171616
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

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

  reverse(S.begin(), S.end());

  deque<char> q;
  int cnt = 0;
  for(int i=0; i<N; i++) {
    if(S[i]=='(') {
      q.push_front('(');
      cnt++;
      if(cnt>0) {
        q.push_back(')');
        cnt--;
      }
    }
    else {
      q.push_front(')');
      cnt--;
    }
  }
  while(cnt < 0) {
    q.push_front('(');
    cnt++;
  }
  while(q.size()){
    cout << q.front();
    q.pop_front();
  }
  cout << endl;
}


Measured memory_bytes: 256
def main():
    s=input()
    for i in range(len(s)-2):
        if s[i] ==s[i+1] or s[i+1] == s[i+2] or s[i]==s[i+2]:
            print(i+1,i+3)
            exit()
    if len(s)==2 and s[0]==s[1]:
        print(1,2)
        exit()
    print(-1,-1)
if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <stdio.h>
int main(void){
    // Here your code !
    int a,b,c,i,cnt;
    scanf("%d%d%d",&a,&b,&c);
    for(i = a;i <= b;i++){
        if(c%i == 0)
        cnt += 1;
    }
    printf("%d\n",cnt);
    return 0;
}

Measured memory_bytes: 596
# -*- coding: utf-8 -*-
def main():
    s = input()
    num_zero, num_one = 0, 0
    for i in s:
        if i == "0":
            num_zero += 1
        else:
            num_one += 1
    num_pair = num_zero if num_zero < num_one else num_one

    print(num_pair*2)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
def main():
    N = int(input())
    A = [int(c) for c in input().split()]

    m = A[0]
    ans = 0
    for i, a in enumerate(A[1:]):
        m = max(m, a)
        if m > a:
            ans += m - a
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 94140
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;

ll dp[100005][2];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.size();
	dp[0][0] = 1;
	rep(i, n) {
		int d = s[i] - '0';
		rep(j, 2) {
			if (d == 1) (dp[i + 1][1] += dp[i][j]) %= mod;
			else (dp[i + 1][j] += dp[i][j]) %= mod;
			if (!(d == 0 && j == 0)) (dp[i + 1][j] += (dp[i][j] * 2) % mod) %= mod;
		}
	}
	cout << (dp[n][0] + dp[n][1]) % mod << endl;
	return 0;
}

Measured memory_bytes: 2000
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
 
 
void swap (int *x, int *y) {
  int temp;    
 
  temp = *x;
  *x = *y;
  *y = temp;
}
 
int gcd(int a,int b){
  if(a<b){
    swap(&a,&b);
  }
 
  if(b==0){
    return a;
  }
 
  int r=a%b;
  while(r!=0){
    a = b;
    b = r;
    r = (a%b);
  }
 
  return b;
}
 
/* クイックソート */
int dn(const void*a,const void*b){return*(int*)b-*(int*)a;}
 
 
int modpow(int a,int n,int mod){
  int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}
 
int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}
 
int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}
 
void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }
 
  return;
}
 
void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }
 
  return;
}
 

int main(void){
  char s;
  int i;
  int ans=0;
  int count=0;
  for(i=0;i<3;i++){
    scanf("%c",&s);
    if(s=='R'){
      count++;
    }else{
      count=0;
    }
    if(ans<=count){
      ans=count;
    }
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 1668
N, M = map(int, input().split())
Cakes = [[] for i in range(N)]
for i in range(N):
  Cakes[i] = [int(x) for x in input().split()]
ans = 0
for s in range(8):
  sx = 1 if s % 2 else -1
  sy = 1 if s // 2 % 2 else -1
  sz = 1 if s // 4 % 2 else -1
  ans = max(sum(sorted([sx * x + sy * y + sz * z for x, y, z in Cakes], reverse=True)[:M]), ans)
print(ans)

Measured memory_bytes: 3292
#include "bits/stdc++.h"

using namespace std;

int cnt(int x) {
    int rv = 0;
    while (x) {
        rv ++;
        x /= 10;
    }
    return rv;
}

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

    int n;
    cin >> n;

    int res = 0;
    for (int i = 1; i <= n; i ++) {
        if (cnt(i) & 1) res ++;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  	int a,b,p,q,r;
  	cin >> a >> b;
  	p=a+b;
  	q=a-b;
  	r=a*b;
  	if(p>q){
    	if(p>r){
        	cout << p << endl;
        }
      	else{
        	 cout << r << endl;
        }
    }
    else{
    	if(q>r){
         cout << q << endl;
        }
      else{
      	cout << r << endl;
      }
    }
  	
	return 0;
}

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

#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MN = 2e5 + 5, LN = 17, MOD = 1e9 + 7, INF = 0x3f3f3f3f, BSZ = 320;
int N, Q;
int ans[MN];

struct qu {
    ll t, x, q;

    bool operator<(const qu &e) const {
        if (t == e.t) return q < e.q;
        return t < e.t;
    }
};

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> N >> Q;
    vector<qu> times;
    for (int i = 0; i < N; i++) {
        ll s, t, x;
        cin >> s >> t >> x;
        times.push_back({s - x, x, 1});
        times.push_back({t - x, x, 2});
    }
    for (int i = 0; i < Q; i++) {
        ll d;
        cin >> d;
        times.push_back({d, i, 3});
    }
    sort(all(times));
    multiset<int> ms;
    for (qu &e : times) {
        if (e.q == 1) {
            ms.insert(e.x);
        } else if (e.q == 2) {
            ms.erase(ms.find(e.x));
        } else {
            if (ms.empty()) ans[e.x] = -1;
            else ans[e.x] = *ms.begin();
        }
    }
    for (int i = 0; i < Q; i++) cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 26600
object Main extends App {
	val n = scala.io.StdIn.readInt
	val a = new Array[Int](n)

	for(i<-0 until n){
		a(i) = scala.io.StdIn.readInt - 1
	}

	var ans = 1
	var tp = 0

	while(ans < n && a(tp) != 1){
		tp = a(tp)
		ans += 1
	}

	if(ans == n) println(-1)
	else println(ans)

} 

Measured memory_bytes: 35416
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int j[n+10];
    int s[n+10];
    for(int i=1;i<=n;i++){
        s[i]=0;
    }
    for(int i=2;i<=n;i++){
        scanf("%d",&j[i]);
        s[j[i]]++;
    }
    for(int i=1;i<=n;i++){
        printf("%d\n",s[i]);
    }
    return 0;
}

Measured memory_bytes: 3280
def gcd(a, b):
    while b: a, b = b, a % b
    return abs(a)

N = int(input())
s, t = 1, 1
for _ in range(N):
    a, b = map(int, input().split())
    g = gcd(a, b)
    a, b = a//g, b//g
    mi = max(-(-s//a), -(-t//b))
    s, t = a*mi, b*mi
print(s+t)

Measured memory_bytes: 3064
w,h,n = map(int, input().split())
wl=0
hb=0
for i in range(n):
    x,y,a = map(int, input().split())
    if a==1:
        if x>wl:
            wl=x
    if a==2:
        if x<w:
            w=x
    if a==3:
        if y>hb:
            hb=y
    if a==4:
        if y<h:
            h=y
if h>=hb and w>=wl:
    ans=(h-hb)*(w-wl)
else:
    ans=0
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
struct ZFunc{
    vector<int> z;
    ZFunc(const vector<int> & v): z(v.size()){
        int n = v.size(), a = 0, b = 0;
        if(!z.empty()) z[0] = n;
        for(int i = 1; i < n; ++i) {
            int end = i; if(i < b) end = min(i + z[i-a], b);
            while(end < n && v[end] == v[end-i]) ++end;
            z[i] = end - i; if(end > b) a = i, b = end;
        }
    }
};
int min_psz(string s){
	vector<int> v;
	for(auto e : s) v.push_back(e);
	ZFunc z(v);
	int len = s.size();
	for(int i = 1; i <= len; i++){
		if(len % i == 0){
			bool bad = false;
			for(int j = 0; j < len; j += i){
				if(z.z[j] < i) bad = true;
			}
			if(!bad) return i;
		}
	}
	assert(0);
	return -1;
}
int good_pos(string s){
	vector<int> v;
	for(auto e : s) v.push_back(e);
	ZFunc z(v);
	int len = s.size();
	vector<bool> good_cut(len + 1, true);
	for(int i = 1; i <= len; i++){
		for(int j = i; j < len; j += i){
			if(z.z[j] >= i){
				good_cut[j + i] = false;
			} else {
				break;
			}
		}
	}
	int ans = 0;
	for(int i = 1; i < len; i++){
		ans += good_cut[i];
	}
	return ans;
}
int main(){
	string s; cin >> s;
	int p = min_psz(s);
	int len = s.size();
	vector<vector<int> > divs(len + 1);
	for(int i = 1; i <= len; i++) for(int j = i + i; j <= len; j += i) divs[j].push_back(i);
	if(len == p) cout << "1\n1\n";
	else if(p == 1) cout << len << "\n1\n";
	else {
		cout << 2 << endl;
		long long ans = 0;
		vector<int> vs; for(auto e : s) vs.push_back(e);
		vector<int> vn = vs; reverse(vn.begin(), vn.end());
		ZFunc zs(vs), zn(vn);
		int len = s.size();
		for(int i = 1; i < len; i++){
			int oc = 0;
			{
				bool ok = false;
				for(int v: divs[i]){
					ok |= zs.z[v] >= i - v;
				}
				if(!ok) oc++;
			}
			{
				bool ok = false;
				for(int v: divs[len - i]){
					ok |= zn.z[v] >= len - i - v;
				}
				if(!ok) oc++;
			}
			if(oc == 2) ans++;
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 64324
#include<stdio.h>
#include<string.h>
typedef struct{
    int shop_number;
    char city_name[11];
    int point;
} _info_shop;
_info_shop shop[100];
int comp_city_name(char city_name1[11], char city_name2[11]){
    
    int length1 = strlen(city_name1);
    int length2 = strlen(city_name2);
    int comp_length;
    int longer;
    if(strcmp(city_name1, city_name2) == 0){
        return -1;
    }
    
    if(strcmp(city_name1, city_name2) == 0){
        return longer;
    }else if(strcmp(city_name1, city_name2) < 0){
        return 1;
    }else{
        return 0;
    }
}
int comp_point(int point1, int point2){
    if(point1 < point2){
        return 0;
    }
    return 1;
}
void exchange(int judge, int j){
    _info_shop temp;
    if (judge == 1){
        temp = shop[j];
        shop[j] = shop[j-1];
        shop[j-1] = temp;
    }
}
int main() {
    int info_num;
    int comp_name_result;
	scanf("%d",&info_num);
    for(int i = 0; i < info_num ; i++){
        shop[i].shop_number = i + 1;
        scanf("%s %d", shop[i].city_name, &shop[i].point);
    }
    for(int i = 0; i < info_num; i++){
        for(int j = info_num - 1; j > i; j--){
            if((comp_name_result = comp_city_name(shop[j].city_name, shop[j - 1].city_name)) == -1){
                exchange(comp_point(shop[j].point, shop[j-1].point), j);
            }else{
                exchange(comp_name_result, j);
            }
        }
    }
    for(int i = 0; i < info_num ; i++){
        printf("%d\n", shop[i].shop_number);
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<S<<endl
#define ck(n,a,b) (a<=(n)&&(n)<=b)
using namespace std;

int main(){
	string s;
	int bx,by,nx,ny;
	while(cin>>s>>by>>bx>>ny>>nx&&s!="#"){
		char maps[10][10]={'.'};
		int w,h,y=0,x=0;
		int notb=0;
		vector<char> ans;
		REP(u,0,(int)s.size()){
				if(s[u]=='/'){
					w=x;y++;x=0;
				}else if(s[u]=='b') {
					maps[y][x]='b';x++;
				}
				else x+=s[u]-'0';
		}
		h=y+1;
		maps[ny-1][nx-1]='b';
		maps[by-1][bx-1]='.';
		REP(i,0,h){
			notb=0;
			REP(j,0,w){
				if(maps[i][j]=='b'){
					if(notb>0) cout<<notb;
					cout<<'b';
					notb=0;
				}else 	notb++;
			}
			if(notb>0) cout<<notb;
			if(i==h-1) break;
			cout<<'/';
		}
		p("");
	}
	return 0;
}

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

#ifndef __HEADERS__
#define __HEADERS__

#define up(i,j,k) for (int i = j; i <= k; i++)
#define down(i,j,k) for (int i = j; i >= k; i--)

#define lb long double
#define ll long long
#define ull unsigned long long

#define mp std::make_pair
#define pb push_back

#define all(x) x.begin(), x.end()
#define lowbit(x) ((x) & (-x))
#define mem(a) memset(a, 0, sizeof(a))
#define File(x)                       \
    freopen("" #x ".in", "r", stdin); \
    freopen("" #x ".out", "w", stdout);

#endif

inline int read() {
    int data = 0, w = 1; char ch = 0;
    while (ch != '-' && (ch > '9' || ch < '0')) ch = getchar();
    if (ch == '-') w = -1, ch = getchar();
    while (ch >= '0' && ch <= '9') { data = data * 10 + ch - '0'; ch = getchar(); }
    return data * w;
}

inline void print (ll v) {
    if (v < 0) { putchar('-'); v = -v; }
    if (v > 9) print(v / 10);
    putchar(v % 10 + '0');
}

int main () {
    int a;
    a = read();
    up (i, 1, 9) up (j, 1, 9) if (i * j == a) return puts("Yes"), 0;
    return puts("No"), 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        StringTokenizer st = new StringTokenizer(br.readLine());
        br.close();
        double a1=0;
        double[] dam = new double[n];
        double[] mount = new double[n];
        for(int i=0;i<n;i++) {
            double d=Double.parseDouble(st.nextToken());
            if(i%2==0){
                a1+=d;
            }else{
                a1-=d;
            }
            dam[i]=d;
        }
        mount[0]=a1;
        System.out.print((int)mount[0]);
        for(int i=0;i<n-1;i++){
            mount[i+1] = (dam[i]-mount[i]/2)*2;
            System.out.print(" ");
            System.out.print((int)mount[i+1]);
        }
        System.out.println("\n");
    }
}


Measured memory_bytes: 53832
#include <cstdio>
#include <map>
#include <queue>
#include <cstring>

#define PRINTF(...) 

int h, w;
char area[100][100];

void visualize() {
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            PRINTF("%c", area[i][j]);
        }
        PRINTF("\n");
    }
}

void replace(char c, int i, int j) {
    int dirs[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    if (i < 0 || i >= h || j < 0 || j >= w || area[i][j] != c) {
        return;
    }
    area[i][j] = '.';
    for (int k = 0; k < 4; k++) {
        replace(c, i + dirs[k][0], j + dirs[k][1]);
    }

}

int solve() {
    char buf[4096];
    int count = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (area[i][j] != '.') {
                count++;
                replace(area[i][j], i, j);
            }
        }
    }
    return count;
}

int main() {
    while (true) {
        scanf(" %d %d", &h, &w);
        PRINTF("h: %d w: %d\n", h, w);
        if (h == 0 && w == 0)
            break;

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (scanf(" %c", &area[i][j]) == EOF) 
                    return 0;
            }
        }
        printf("%d\n", solve());
    }

}

Measured memory_bytes: 3460
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 調査対象の人数 N (1 ≤ N ≤ 100) が与えられる。と、それに続いて組織 
		int N = sc.nextInt();

		boolean belongA[] = new boolean[N + 1];

		boolean belongB[] = new boolean[N + 1];

		boolean hasC[] = new boolean[N + 1];

		// 組織 A に属している者の数 X (0 ≤ X ≤ N)
		int X = sc.nextInt();
		for (int i = 0; i < X; ++i) {
			int a = sc.nextInt();
			belongA[a] = true;
		}

		// 組織 B に属している者の数 X (0 ≤ X ≤ N)
		int Y = sc.nextInt();
		for (int i = 0; i < Y; ++i) {
			int a = sc.nextInt();
			belongB[a] = true;
		}

		// 商品 C を所持している者の数 X (0 ≤ X ≤ N)
		int Z = sc.nextInt();
		for (int i = 0; i < Z; ++i) {
			int a = sc.nextInt();
			hasC[a] = true;
		}

		int answer = 0;
		for (int i = 1; i <= N; ++i) {
			// 組織Aに属さず、かつ、商品Cを所持している者。
			// 組織Bに属し、かつ、商品Cを所持している者。
			if ((!belongA[i] && hasC[i]) || (belongB[i] && hasC[i])) {
				answer++;
			}
		}

		System.out.println(answer);

	}
}



Measured memory_bytes: 26620
import java.util.*;

public class Main {
	public static void main(String[] args) {

		Scanner keyboard = new Scanner(System.in);

		int N = keyboard.nextInt();
		long[] H = new long[N];
		
		for(int i=0; i<N; i++) {
			H[i] = keyboard.nextLong();
		}
		String ans = "Yes";
		
		for(int n=0; n<N; n++) {
			if(n==0) {
				H[n]--;
			}else if(n==N-1) {
				if(H[n]-H[n-1]<0) {
					ans = "No";
				}
			}else {
				if(H[n+1]-H[n]<=-2) {
					ans = "No";
					break;
				}
				if(H[n]-H[n-1]>=1) {
					H[n]--;
				}
				else {
					if(H[n+1]-H[n]<=-1) {
						ans = "No";
						break;
					}
				}
			}
		}
		
		System.out.println(ans);
		keyboard.close();
	}
}


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

from heapq import heappush, heappop
def io_generator():
	return input()

#+++++++++++++++++++
	
class Foo(object):
	def __init__(self, value, state):
		self.state = state
		self.value = value

	def __lt__(self, other):
		return self.value > other.value

def get_c(aa,ab,ac, amm):
	if ac < amm[2]-1:
		ret=[[aa,ab,ac+1]]
	else:
		ret=[]
		
	if ab<amm[1]-1:# and ab >= ac:
		ret.append([aa,ab+1,ac])
	
	if aa<amm[0]-1:# and aa >= ab and aa >= ac:
		ret.append([aa+1,ab,ac])
	return ret
	
def gv(al,bl,cl,s):
	return al[s[0]]+bl[s[1]]+cl[s[2]]
	
def lss(l):
	return '_'.join([str(i) for i in l])
	
def main(io):
	x,y,z,k=map(int, io().split())
	ml=[x,y,z]
	al =list(map(int, io().split()))
	al.sort(reverse=True)
	bl =list(map(int, io().split()))
	bl.sort(reverse=True)
	cl =list(map(int, io().split()))
	cl.sort(reverse=True)
	init=[0,0,0]
	ggv=lambda l : gv(al,bl,cl,l)
	
	qq = []
	heappush(qq,Foo(ggv(init), init))
	
	ol=set()
	ol.add(lss(init))
	
	for _ in range(k):
		ff=heappop(qq)
		vv=ff.value
		cs=ff.state
		nc=get_c(cs[0],cs[1],cs[2],ml)
		print(vv)
		for ns in nc:
			if lss(ns) in ol:
				continue
			else:
				heappush(qq, Foo(ggv(ns), ns))
				ol.add(lss(ns))
	return 1

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	#print (main(io))
	main(io)

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

int main()
{
	int N,M,Q;cin >> N >> M >> Q;
	vector<vector<int>> dp(N+1,vector<int> (N+1,0));
	int L,R;
	for (int i=0;i<M;i++)
	{
		cin >> L >> R;
		dp[L][R]++;
	}
	for (int i=1;i<N+1;i++)
	{
		for (int j=1;j<N+1;j++)
		{
			dp[i][j]+=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
		}
	}
	int p,q;
	for (int i=0;i<Q;i++)
	{
		cin >> p >> q;
		cout << dp[q][q]-dp[p-1][q]-dp[q][p-1]+dp[p-1][p-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define ll long long
#define rint register int
#define Maxn 100
#define inf 1<<30
#define cmin(x,y) (x>y)&&(x=y)
#define cmax(x,y) (x<y)&&(x=y)
using namespace std;
inline int read(){int s=0,w=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();return s*w;}
void write(int v){if(v<0){putchar('-');v=-v;}if(v>9)write(v/10);putchar(v%10+'0');}
int main()
{
	//freopen("xxx.in", "r", stdin);
    //freopen("xxx.out", "w", stdout);
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max(max(max(b*d,a*d),a*c),b*c);
	return 0;
}
/*
 * ┌───┐   ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┬───┐ ┌───┬───┬───┐
 * │Esc│   │ F1│ F2│ F3│ F4│ │ F5│ F6│ F7│ F8│ │ F9│F10│F11│F12│ │P/S│S L│P/B│  ┌┐    ┌┐    ┌┐
 * └───┘   └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┴───┘ └───┴───┴───┘  └┘    └┘    └┘
 * ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───────┐ ┌───┬───┬───┐ ┌───┬───┬───┬───┐
 * │~ `│! 1│@ 2│# 3│$ 4│% 5│^ 6│& 7│* 8│( 9│) 0│_ -│+ =│ BacSp │ │Ins│Hom│PUp│ │Num│ / │ * │ - │
 * ├───┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─────┤ ├───┼───┼───┤ ├───┼───┼───┼───┤
 * │ Tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │{ [│} ]│ | \ │ │Del│End│PDn│ │ 7 │ 8 │ 9 │   │
 * ├─────┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴┬──┴─────┤ └───┴───┴───┘ ├───┼───┼───┤ + │
 * │ Caps │ A │ S │ D │ F │ G │ H │ J │ K │ L │: ;│" '│ Enter  │               │ 4 │ 5 │ 6 │   │
 * ├──────┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴────────┤     ┌───┐     ├───┼───┼───┼───┤
 * │ Shift  │ Z │ X │ C │ V │ B │ N │ M │< ,│> .│? /│  Shift   │     │ ↑ │     │ 1 │ 2 │ 3 │   │
 * ├─────┬──┴─┬─┴──┬┴───┴───┴───┴───┴───┴──┬┴───┼───┴┬────┬────┤ ┌───┼───┼───┐ ├───┴───┼───┤ E││
 * │ Ctrl│ Win│ Alt│         Space         │ Alt│ Win│Menu│Ctrl│ │ ← │ ↓ │ → │ │   0   │ . │←─┘│
 * └─────┴────┴────┴───────────────────────┴────┴────┴────┴────┘ └───┴───┴───┘ └───────┴───┴───┘
 */


Measured memory_bytes: 3616
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String s = sc.next();
		String t = sc.next();
		
		// 計算
		String result = t + s;
		
		
		// 出力
		System.out.println(result);
	}
}


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

int main() {
  int N;
  cin >> N;

  vector<int> d(N);

  for (int i=0; i<N; i++) {
    cin >> d[i];
  }

  sort(d.begin(),d.end());

  int count = 1;
  int i = N;

  while (i > 0) {
    if (d[i] > d[i-1]) {
      count += 1;
    }
    i--;
  }
  
  cout << count << endl;

}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;
int main()
{

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	int value = max(a*b, c*d);
		cout << value;

	int wait;
	cin >> wait;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

struct less_key {
    bool operator()(const std::pair<i64,i64> &left, const std::pair<i64,i64> &right) {
        return left.first < right.first;
    }
};

const i64 MAXN = 300005;

i64 n, k;
i64 a[MAXN];

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    string s;
    string t = "ABC";

    cin >> n;
    cin >> s;

    i64 R = 0;
    for(;;) {
        auto i = s.find(t);
        if (i == string::npos) {
            break;
        }
        R += 1;
        s = s.substr(i + t.size());
    }
    cout << R << endl;
    return 0;
}

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

unsigned long long solve(unsigned long long a, unsigned long long b){
	if(a==0||b==0) return 0;
	if(a < b) swap(a, b);
	unsigned long long fac = a/b;
	return 3*fac*b+solve(b, a-fac*b);
}

int main(){
	unsigned long long N, X;
	scanf("%lld %lld", &N, &X);
	printf("%lld\n", solve(N-X, X));
}


Measured memory_bytes: 256
h, w = map(int, input().split())
n = int(input())
a = list(map(int, input().split()))
ans = [[0] * w for _ in range(h)]
now_color = 1
now_a_index = now_color - 1
ans_index = [0, 0]
for i in range(h * w):
    ans[ans_index[0]][ans_index[1]] = now_color
    a[now_a_index] -= 1
    if a[now_a_index] == 0:
        now_color += 1
        now_a_index += 1
    ans_index[1] += 1
    if ans_index[1] >= w:
        ans_index[1] = 0
        ans_index[0] += 1
cnt = 0
for l_ans in ans:
    if cnt % 2 == 1:
        for ll_ans in reversed(l_ans):
            print(ll_ans, end=" ")
        cnt += 1
    else:
        for ll_ans in l_ans:
            print(ll_ans, end=" ")
        cnt += 1
    print("")

Measured memory_bytes: 9336
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>

using namespace std;

#define int long long

const int MAX_N = 3005;
int n, mod, fact[MAX_N+1], invfact[MAX_N+1], pow2[MAX_N * MAX_N + 100];

int powMod(int a, int p)
{
    int ans = 1;
    while (p > 0) {
        if (p & 1) ans = ans * a % mod;
        p >>= 1;
        a = a * a % mod;
    }
    return ans;
}

int powMod(int a, int p, int m)
{
    int ans = 1;
    while (p > 0) {
        if (p & 1) ans = ans * a % m;
        p >>= 1;
        a = a * a % m;
    }
    return ans % m;
}

int combi(int n, int k)
{
    return k > n ? 0 : (fact[n] * invfact[k] % mod) * invfact[n-k] % mod;
}

signed main()
{
    cin >> n >> mod;

    // pre-process
    fact[0] = invfact[0] = 1;
    for (int i = 1; i <= MAX_N; ++i) {
		fact[i] = fact[i-1] * i % mod;
        invfact[i] = powMod(fact[i], mod - 2);
    }

    pow2[0] = 1;
    for (int i = 1; i <= MAX_N * MAX_N + 50; ++i) pow2[i] = (pow2[i-1] * 2) % mod;

    int stirling[MAX_N+1][MAX_N+1]; // s2[n][k]
    // n = 1
    for (int j = 0; j <= MAX_N; ++j) stirling[1][j] = 0;
    stirling[1][1] = 1;

    for (int i = 2; i <= MAX_N; ++i) {
		stirling[i][0] = 0;
        for (int j = 1; j <= MAX_N; ++j) {
            stirling[i][j] = (stirling[i-1][j-1] + stirling[i-1][j] * j) % mod;
        }
    }

    int f[n+1];
    f[0] = powMod(2, powMod(2, n, mod - 1));
//    cerr << f[0] << ' ';
    for (int x = 1; x <= n; ++x) {
        f[x] = 0;
        for (int i = 1; i <= x; ++i) {
            f[x] = (f[x] + stirling[x][i] * ((pow2[(n-x)*(i-1)] * i + pow2[(n-x)*i]) % mod)) % mod;
        }
//        cerr << f[x] << ' ';
        f[x] *= powMod(2, powMod(2, n-x, mod - 1));
        f[x] %= mod;
        f[x] *= combi(n, x);
        f[x] %= mod;
    }

//    cerr << endl;
//    for (int x = 0; x <= n; ++x) cerr << f[x] << ' '; cerr << endl;

    int ans = 0;
    for (int i = 0; i <= n; ++i) {
        ans += (i & 1) ? mod - f[i] : f[i];
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 141440
package main
import (
	"fmt"
)

func main() {
  var a, b, c, k, ans int
  fmt.Scan(&a)
  fmt.Scan(&b)
  fmt.Scan(&c)
  fmt.Scan(&k)
  if a <= k {
    ans += a
  } else { 
    ans += k
  }
  k = k - a - b

  if k > 0 {
    ans -= k
  }
	fmt.Printf("%v\n", ans)
}

Measured memory_bytes: 1832
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int dx = x2 - x1;
    int dy = y2 - y1;
    int x3 = x2 - dy;
    int y3 = y2 + dx;
    int x4 = x3 - dx;
    int y4 = y3 - dy;
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

    return 0;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    ac = 0
    wa = 0
    tle = 0
    re = 0
    for i in range(0, N):
        res = input()
        if (res == 'AC'):
            ac += 1
        if (res == 'WA'):
            wa += 1
        if (res == 'TLE'):
            tle += 1
        if (res == 'RE'):
            re += 1
    print(f"AC x {ac}")
    print(f"WA x {wa}")
    print(f"TLE x {tle}")
    print(f"RE x {re}")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9212
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	String fileName = "erase";

	public void solve() throws IOException {
		int n = nextInt();
		int t[] = new int[n + 1];
		int x[] = new int[n + 1];
		int y[] = new int[n + 1];
		t[0] = 0;
		x[0] = 0;
		y[0] = 0;
		for (int i = 1; i < n + 1; i++) {
			t[i] = nextInt();
			x[i] = nextInt();
			y[i] = nextInt();
		}
		boolean b = true;
		for (int i = 0; i < n; i++) {
			int time = t[i + 1] - t[i];
			int dx = Math.abs(x[i + 1] - x[i]);
			int dy = Math.abs(y[i + 1] - y[i]);
//			out.println(dx + " " + dy + " " + time);
			int d = dx + dy;
			if ((time - d < 0) || (time - d) % 2 == 1) {
				b = false;
			}
		}
		if (b)
			out.println("Yes");
		else
			out.println("No");
	}

	public void run() {
		try {
			InputStreamReader isr = new InputStreamReader(System.in);
			br = new BufferedReader(isr);
			out = new PrintWriter(System.out, true);
			// out = new PrintWriter(fileName + ".out");
			// br = new BufferedReader(new FileReader(fileName + ".in"));
			solve();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	BufferedReader br;
	StringTokenizer in;
	static PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

}


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


int n;
long long a, b;

bool C(long long mid, vector<long long> h){
    long long cnt = 0;
    rep(i,n){
        h[i] -= mid * b;
        if(h[i] < 0) continue;
        cnt += h[i] / a;
        if(h[i] % a != 0) cnt++;
    }
    return cnt <= mid;
}

int main(){
    cin >> n >> a >> b;
    a-=b;

    vector<long long> h;
    rep(i,n){
        int x;
        cin >> x;
        h.emplace_back(x);
    }

    long long right = 1e9, left = 0;
    rep(i,50){
        long long mid = (right + left) / 2;
        if(C(mid, h)) right = mid;
        else left = mid;
    }
    cout << right << endl;
}


Measured memory_bytes: 1908
#include<stdio.h>
int fibonacci(int,int[]);
int main(){
  int n, Fibo[50];
  int i;
  scanf("%d",&n);

  for(i = 0; i < 50 ;i++){
    Fibo[i] = -1;
  } 

  printf("%d\n",fibonacci(n,Fibo));
  return 0;
}


int fibonacci(int n, int Fibo[]){
  Fibo[0] = Fibo[1] = 1;
  if (n == 0 || n == 1) return 1;
  if(Fibo[n] == -1){
    Fibo[n] = fibonacci(n-2, Fibo) + fibonacci(n-1, Fibo);
  }
  return Fibo[n];
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}

using namespace std;

int main()
{
    ll N;
    cin >> N;
    vector<vector<ll>> data(N, vector<ll>(2));

    rep(i, N)
    {
        cin >> data.at(i).at(0);
        data.at(i).at(1) = i + 1;
    }
    sort(all(data));
    rep(i, N)
    {
        cout << data.at(i).at(1) << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 6272