akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <complex>
#include <map>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MOD = 1000000007;


int N, M;
vector<int> Prime;
map<int, int> PrimeFactor;
vector<int> Facts;
vector<int> Invs;

map<int, int> memo;

//a^b (mod MOD)の計算
int power(int a, int b){
    if(b == 0) return 1;
    if(b == 1) return a%MOD;
    if(memo.count(b)!=0) return memo[b];
    if(b%2 == 0){
        ll t = power(a, b/2);
        t = t * t % MOD;
        memo[b] = t % MOD;
        return memo[b];
    } else {
        ll t = power(a, b/2);
        t = t * t % MOD;
        memo[b] = t * a % MOD;
        return memo[b];
    }
}

//1!から(n+k-1)!、1!^-1から(n+k-1)!^-1を計算しておく
void prepare(int k){
    Facts.resize(N+k);
    Invs.resize(N+k);

//    1!から(n+k-1)!を計算
    Facts[0] = 1;
    for(int i=1; i<N+k; i++)
        Facts[i] = i * (ll)Facts[i-1] % MOD;

//    (n+k-1)!^-1 = (n+k-1)!^MOD-2の計算
    memo.clear();
    Invs[0] = 1;
    Invs[N+k-1] = power(Facts[N+k-1], MOD-2);
//     1!^-1まで計算
    for(int i=N+k-1; i>1; i--)
        Invs[i-1] = (ll)Invs[i] * i % MOD;

    return;
}


bool isPrime(int i){
    for(int j=2; j<=(int)sqrt(i); j++)
        if(i%j==0) return false;

    return true;
}


//(n-1+k)C(k) = (n+k-1)!* k!^-1 * (n-1)!^-1の計算
ll conbination(int k){
    ll ans = 1;
    prepare(k);
    ans = ans * Facts[N+k-1]%MOD * Invs[k]%MOD * Invs[N-1]%MOD;
    
    return ans%MOD;
}


int main() {
    cin >> N >> M;
    
    if(M == 1){
        cout << 1 << endl;
        return 0;
    }

//    [Goal]Mの素因数分解
//    まずはi=sqrt(M)までの素数を列挙　O(i√i)
    for(int i=2; i<=(int)sqrt(M); i++){
        if(isPrime(i)) Prime.push_back(i);
    }

//  Mの素因数分解
    while(!isPrime(M)){
        for(int p:Prime){
            if(M%p==0){
                M /= p;
                PrimeFactor[p]++;
                break;
            }
        }
    }
    PrimeFactor[M]++;
    
//   各素因数をN個のa[i]に割り当てる。素因数pの数をc[p]=kとすると、(n-1+k)C(k)で求まる(重複組み合わせ)
    ll ans = 1;
    for(auto f:PrimeFactor){
        ans = ans * conbination(f.second) % MOD;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi vec(n);
    rep(i, n) {
        vec[i] = i+1;
    }

    do{
        rep(i, n) {
            cout << vec[i] << (i == n-1?'\n':' ');
        }
    } while(next_permutation(all(vec)));
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  if(a+b > c+d){
		cout << "Left" << endl;
  }
  else if(a+b == c+d){
	cout << "Balanced" << endl;
  }
  else{
	cout << "Right" << endl;
  }
}

Measured memory_bytes: 3604
import java.io.IOException;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) {
		while (true) {
			int allMinutes = nextInt();
			if (allMinutes == 0) {
				break;
			}
			int teamNum = nextInt();
			int problemNum = nextInt();
			int submitNum = nextInt();

			Team[] teams = new Team[teamNum];
			for (int i = 0; i < teams.length; i++) {
				teams[i] = new Team(i + 1);
				teams[i].penalty = new int[problemNum];
			}

			for (int i = 0; i < submitNum; i++) {
				int time = nextInt();
				int team = nextInt();
				int problem = nextInt();
				int judge = nextInt();

				if (judge == 0) {
					teams[team - 1].correct++;
					teams[team - 1].minutes += time;
					teams[team - 1].minutes += teams[team - 1].penalty[problem - 1];
				} else {
					teams[team - 1].penalty[problem - 1] += 20;
				}
			}
			Arrays.sort(teams);

			for (int i = 0; i < teams.length; i++) {
				if (i != 0) {
					if (teams[i - 1].correct == teams[i].correct
							&& teams[i - 1].minutes == teams[i].minutes) {
						System.out.print("=");
					} else {
						System.out.print(",");
					}
				}
				System.out.print(teams[i].id);
			}
			System.out.print("\n");
		}

	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return -1;
	}

}

class Team implements Comparable<Team> {
	int id = 0, minutes = 0, correct = 0, realPenalty = 0;
	int[] penalty;

	Team(int id) {
		this.id = id;
	}

	public int compareTo(Team team) {
		if (team.correct == this.correct) {
			if (this.minutes == team.minutes) {
				return team.id - this.id;// 降順
			} else {
				return this.minutes - team.minutes;// 昇順
			}
		} else {
			return team.correct - this.correct;// 降順
		}
	}
}

Measured memory_bytes: 19396
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n=0,d=0) Array.new(n,d)end
def na2(n=0,m=0,d=0) Array.new(n){Array.new(m,d)}end
def na3(n=0,m=0,l=0,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
n = inp[0]
t = inp
dd=t[0]
 
 
max = t.max
min = t.min
minc = t.count(min)
maxc = t.count(max)
 
  if(max - min >= 2)
    puts "No"
    exit
  end
 
if(max == min)
  if(n == (min+1))
    puts "Yes"
    exit
  end
  g = 2*min
  if(t.count(max) >= g)
     puts "Yes"
  else
     puts "No"
  end
end
if(max != min)

  c = max - minc
  g = 2*c
  if(g <= 1)
    puts "No"
    exit
  end
  if(t.count(max) >= g)
     puts "Yes"
  else
     puts "No"
  end
   exit
end

Measured memory_bytes: 8724
#include <stdio.h>

int width,height;
char map[500][501];
int map_ruiseki[500][500];
int chousa_now[500];

int main(void) {
	int i,j,k;
	int now;
	int result;
	int prev_atai;
	while(1) {
		scanf("%d%d",&height,&width);
		if(height==0 && width==0)break;
		for(i=0;i<height;i++)scanf("%s",map[i]);
		for(i=0;i<width;i++) {
			now=0;
			for(j=0;j<height;j++) {
				if(map[j][i]=='*')now=0; else now++;
				map_ruiseki[j][i]=now;
			}
		}
		result=0;
		for(i=0;i<height;i++) {
			for(j=0;j<500;j++)chousa_now[j]=0;
			prev_atai=0;
			for(j=0;j<width;j++) {
				for(k=0;k<map_ruiseki[i][j];k++) {
					chousa_now[k]++;
					if((k+1)*chousa_now[k]>result) {
						result=(k+1)*chousa_now[k];
					}
				}
				if(map_ruiseki[i][j]<prev_atai) {
					for(k=map_ruiseki[i][j];k<prev_atai;k++) {
						chousa_now[k]=0;
					}
				}
				prev_atai=map_ruiseki[i][j];
			}
		}
		printf("%d\n",result);
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
void main()
{
  int a,b,c,d;
  scanf("%d%d%d%d",&a,&b,&c,&d);
  while(a>0 && c>0)
  {
    c=c-b;
    a=a-d;
  }
  if(c<=0)
    printf("Yes");
  else
    printf("No");
}

Measured memory_bytes: 1732
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N = int(input())
    A = list(int(_) for _ in input().split())
    min_cnt = 0
    for i in range(N):
        if A[i] < 0:
            min_cnt +=1
        A[i] = abs(A[i])
    if min_cnt % 2 ==0:
        ans = sum(A)
    else:
        ans = sum(A)-2*(min(A))
    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 14692
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		I18n solver = new I18n();
		solver.readInput();
		solver.solve();
		solver.writeOutput();
	}

	static class I18n {

		private String input;
		private String answer;
		private Scanner scanner;



		public I18n() {
			scanner = new Scanner(System.in);
		}

		public void readInput() {
			input = scanner.next();
		}

		public void solve() {
			int t = input.length()-2;
			answer = input.charAt(0) + String.valueOf(t) + input.charAt(input.length()-1);
		}

		public void writeOutput() {
			System.out.println(answer);
		}
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


typedef map <string, int> NAME_TO_ID;
const int SIZE = 101;
int n;
int ww, wh;
string NAME[SIZE]; 
int K[SIZE];
NAME_TO_ID NTI; 
int X1[SIZE][SIZE], Y1[SIZE][SIZE], X2[SIZE][SIZE], Y2[SIZE][SIZE];
string TO[SIZE][SIZE];

int H[30000000];
int cur;
int upper;

void init() {
    NTI.clear();
    H[0] = 0;
    cur = 0;
    upper = 1;
}

int click( int x, int y ) { 
    int cid = H[cur];
    for ( int i = 0; i < K[cid]; ++ i ) {
        if ( X1[cid][i] <= x && x <= X2[cid][i] ) {
            if ( Y1[cid][i] <= y && y <= Y2[cid][i] ) {
                return NTI[TO[cid][i]];
            }
        }
    }
    return -1;
}


void input() {
    cin >> ww >> wh;
    for ( int i = 0; i < n; ++ i ) { 
        cin >> NAME[i] >> K[i];
        NTI[NAME[i]] = i;
        for ( int j = 0; j < K[i]; ++ j ) {
            cin >> X1[i][j] >> Y1[i][j];
            cin >> X2[i][j] >> Y2[i][j];
            cin >> TO[i][j];
        }
    }
}

void push( int id ) {
    H[++cur] = id;
    upper = cur + 1;
}

string getCurrentName() {
    int cid = H[cur];
    return NAME[cid];
}


void back() {
    if ( cur - 1 < 0 ) return;
    cur --;
}

void forward() {
    if ( cur + 1 >= upper ) return;
    cur ++;
}

void solve() {
    int m;
    cin >> m;
    for ( int i = 0; i < m; ++ i ) {
        string cmd;
        cin >> cmd;
        if ( cmd == "click" ) {
            int x, y;
            cin >> x >> y;
            int ret = click( x, y );
            if ( ret == -1 ) continue;
            push(ret);
        } else if ( cmd == "show" ) {
            cout << getCurrentName() << endl;
        } else if ( cmd == "back" ) {
            back();
        } else if ( cmd == "forward" ) {
            forward();
        }
    }
}

int main() {
    while ( cin >> n && n ) {
        init();
        input();
        solve();
    }
    return 0;
}

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

 using namespace std;
 
 #define ll long long
 #define inf (int)1e9
 #define odd(x) x&1
 #define pow2(x) 1 << x
 #define log2bin(x) 32-__builtin_clz(x)-1
 #define popcnt(x) __builtin_popcount(x)
 #define mod7(x) x%1000000007

 #define cinarr(A,len) for(int i=0;i<len;i++){cin>>A[i];}
 #define coutarr(A,len) for(int i=0;i<len;i++){cout<<A[i]<<' ';}cout<<endl
 #define coutin(V) for(auto& i : V){cout << i << ' ';}cout<<endl // for vect and set
 #define coutmap(U) for(auto& i : U){cout << i.first << "->" << i.second << ' ';}cout<<endl // for map

 // ==== fast function ====
 /*
 bool prime(long long n){ const long long sqrtn = floor(sqrt(n)); if(n!=2 && n&1^1){return false;} for(long long i = sqrtn; i>=3; i-=2){ if(n%i==0){ return false;} } return true;}
 long long fastexp(long long base, long long pwr){ if(!pwr || !base)return 0; if(n&1^1){return fastexp(a*a, b/2);}else{return a*fastexp(a*a, b/2);}}
 */
 
/*========================================================================*/
/* strategi/note:

sama seperti frog1 cuman min() nya beda, pakai iterasi

/================================*/



void solve(){
    int n, k;
    cin >> n >> k;
    
    int h[n];
    cinarr(h,n);
    
    int dp[n]; // max cost to reach n+1 stone
    dp[0] = 0; // max cost to reach 1st stone is 0 because it is the initial pos
    
    for(int i = 1; i<n; i++){ // from second index
        int m = inf;
        for(int j = i-1; j>=max(i-k, 0); j--){
            m = min(m, dp[j]+abs(h[i]-h[j]) );
        }
        dp[i] = m;
    }
    
    cout << dp[n-1] << endl;

}

int main(){
     ios_base::sync_with_stdio(0);
     cin.tie(0);
     //cout.setprecision( ) // iomanip **

	solve();
//	int t;cin>>t;while(t--){solve();}
//	int t;cin>>t;((int))* ans=new ((int))[(( ))];solve();((int)) in;while(t--){cin>>in;cout<<ans[in-(( )) ];}delete[] ans;

	 //cout.flush(); cin.get();
     return 0;
}


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

int main() {
  int w, a, b;
  scanf("%d %d %d", &w, &a, &b);
  if(a + w < b)
    printf("%d\n", b - a - w);
  else if(b + w < a)
    printf("%d\n", a - b - w);
  else
    printf("0\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

///////////////////////////



int main() {
	ll A, B;
	cin >> A >> B;

	if (A*B % 2 == 1) { cout << "Yes"; }
	else { cout << "No"; }

	

	system("PAUSE");
}

Measured memory_bytes: 504
def main():
    N = int(input())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    from operator import itemgetter
    AB.sort(key=itemgetter(1))
    t = 0
    for a, b in AB:
        t += a
        if b < t:
            return print("No")
    print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 89304
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

int main(){
  int n;
  cin>>n;
  printf("%.10lf\n",(double)((n+1)/2)/(double)n);
}


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

#define int long long

signed main() {
	int A, B, N;
	cin >> A >> B >> N;
	vector<bool> F(1010, false);
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		if (A == a && b == B) {
			cout << 1 << endl;
			return 0;
		}
		for (int j = a; j <= b; j++) {
			F[j] = true;
		}
	}
	bool ans = 1;
	for (int i = A+1; i < B; i++) {
		if (F[i])ans = false;
	}
	if (A + 1 == B) {
		if (F[A] && F[B])ans = false;
	}
	cout << !ans << endl;

	return 0;
}


Measured memory_bytes: 3132
def main():
    x, k, d = map(int, input().split())
    if x < 0: x = -x

    if k * d <= x:
        print(x - k*d)
        return

    x %= d + d
    if k % 2 == 1:
        x -= d
    else:
        x = min(abs(x-d-d), x)

    print(abs(x))

main()


Measured memory_bytes: 9172
n , a, b = map(int, input().split())
s = input()
t = 0
count = 1
ans = []
for i in range(n):
    if s[i] == 'a' and count <= (a+b):
        ans.append('Yes')
        count += 1
    elif s[i] == 'b':
        t += 1
        if count <= (a+b) and  t <= b:
            ans.append('Yes')
            count += 1
        else:
            ans.append('No')
    else:
        ans.append('No')
for i in ans:
    print(i)

Measured memory_bytes: 4784
#include <stdio.h>
#pragma warning (disable:4996)

int main() {
	long long A, B, C, K;
	(void)scanf("%lld%lld%lld%lld", &A, &B, &C, &K);
	if (A < K) {
		K -= A;
		if (B < K) {
			K -= B;
		}
		else {
			K = 0;
		}
	}
	else {
		A = K;
		K = 0;
	}
	printf("%lld", A - K);
}

Measured memory_bytes: 1736
#include "bits/stdc++.h"
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T & a, const T & b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, MAX = LLONG_MAX;
typedef pair<string, lint> pa;

unordered_multimap<string, pa> lft, rgh;
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s, l, r;
	lint N;
	cin >> N;
	cin >> s;
	l = s.substr(0, N);
	r = s.substr(N, N);
	reverse(r.begin(), r.end());
	REP(i, 1 << N) {
		string red = "", blue = "";
		REP(j, N) {
			if ((i >> j) % 2 == 1) {
				red += l[j];
			}
			else {
				blue += l[j];
			}
		}
		bool flag = true;
		auto range = lft.equal_range(red);
		for (auto i = range.first; i != range.second; i++) {
			if ((*i).second.first == blue) {
				(*i).second.second++;
				flag = false;
			}
		}
		if(flag) lft.emplace(pair<string, pa>(red, pa(blue, 1)));

		red = "", blue = "";
		REP(j, N) {
			if ((i >> j) % 2 == 1) {
				red += r[j];
			}
			else {
				blue += r[j];
			}
		}
		flag = true;
		range = rgh.equal_range(red);
		for (auto i = range.first; i != range.second; i++) {
			if ((*i).second.first == blue) {
				(*i).second.second++;
				flag = false;
			}
		}
		if (flag) rgh.emplace(pair<string, pa>(red, pa(blue, 1)));
	}

	lint cnt = 0;
	for (auto itr : lft) {
		string key = itr.first, value = itr.second.first;
		auto range = rgh.equal_range(value);
		for (auto i = range.first; i != range.second; i++) {
			if ((*i).second.first == key) {
				cnt += itr.second.second * (*i).second.second;
			}
		}
	}
	cout << cnt << endl;
}


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

int main()
{
  int h,n;
  int sum=0;
  vector<int> a;
  cin>>h>>n;
  for(int i=0;i<n;i++)
  {
    int num;
    cin>>num;
    a.push_back(num);
  }
  
  for(int i=0;i<n;i++)
  {
    sum = sum + a[i];
  }
  if(sum>=h)
    cout<<"Yes"<<endl;
  
  else
    cout<<"No"<<endl;
  return 0;
}

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

int main(){
    int N, K, min, ans=0, index;
    cin >> N >> K;
    vector<int> p(N);
    for(int i=0; i<N; i++)
        cin >> p.at(i);
    
    for(int n=0; n<K; n++){
        min = p.at(0);
        index = 0;
        for(int i=1; i<N-n; i++){
            if(p.at(i) <= min){
                min = p.at(i);
                index = i;
            }
        }
        p.erase(p.begin()+index);
        ans = ans + min;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
s = input()

ss = s.split(" ")

N = int(ss[0])
A = int(ss[1])
B = int(ss[2])

if A == 0:
  print(0)
elif B == 0:
  print(N)
else:
  ans = 0
  div = N //( A + B ) # A > 0
  ans = div * A
  ans += min( N % (A + B) , A)
  # mod = N % ( A + B )


  # if mod > A :
  #   ans += A
  # else :
  #   ans += mod
  
  print(ans)

Measured memory_bytes: 3064
unittest
{
	assert( [ "5 100 90 80", "98", "40", "30", "21", "80" ].parse.expand.solve == 23 );
	assert( [ "8 100 90 80", "100", "100", "90", "90", "90", "80", "80", "80" ].parse.expand.solve == 0 );
	assert( [ "8 1000 800 100", "300", "333", "400", "444", "500", "555", "600", "666" ].parse.expand.solve == 243 );
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nabc = input.front.split.to!( long[] );
	auto ls = new long[ nabc[ 0 ] ];
	foreach( ref l; ls )
	{
		input.popFront;
		l = input.front.to!( long );
	}
	
	return tuple( nabc[ 1 ], nabc[ 2 ], nabc[ 3 ], ls );
}

auto solve( long a, long b, long c, long[] ls )
{
	return dfs( a, b, c, 0, 0, 0, ls );
}

long dfs( long la, long lb, long lc, long ca, long cb, long cc, long[] ls )
{
	if( ls.length == 0 )
	{
		// 延長、縮小したときのコストを計算
		if( ca == 0 || cb == 0 || cc == 0 ) return long.max - 100;					// 1本も選んでなかったらダメ
		else                                return la.abs + lb.abs + lc.abs;
	}
	
	// 合成したときのコストを計算
	auto cs = new long[ 4 ];
	cs[ 0 ] = dfs( la,           lb,           lc,           ca    , cb    , cc    , ls[ 1 .. $ ] );							// この竹を使わないとき
	cs[ 1 ] = dfs( la - ls[ 0 ], lb,           lc,           ca + 1, cb    , cc    , ls[ 1 .. $ ] ) + ( ca == 0 ? 0 : 10 );		// この竹をAに合成したとき（1本目だったら合成コスト足さない）
	cs[ 2 ] = dfs( la,           lb - ls[ 0 ], lc,           ca    , cb + 1, cc    , ls[ 1 .. $ ] ) + ( cb == 0 ? 0 : 10 );		// この竹をBに合成したとき（1本目だったら合成コスト足さない）
	cs[ 3 ] = dfs( la,           lb,           lc - ls[ 0 ], ca    , cb    , cc + 1, ls[ 1 .. $ ] ) + ( cc == 0 ? 0 : 10 );		// この竹をCに合成したとき（1本目だったら合成コスト足さない）
	return cs.reduce!min;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
constexpr long long INF = 1e18;



signed main(){
	int N,M;
	cin>>N>>M;
	vector<int>a(M),b(M);
	vector<vector<int>>g(N,vector<int>(N,0));
	REP(i,N)g[i][i]=1;
	REP(i,M){
		cin>>a[i]>>b[i];
		a[i]--;b[i]--;
		g[a[i]][b[i]]=g[b[i]][a[i]]=1;
	}
	vector<vector<int>>gg(N);
	REP(i,N){
		REP(j,N){
			if(g[i][j]==0){
				gg[i].push_back(j);
			}
		}
	}
	int bi = 0;
	vector<pair<int,int>>p;
	vector<int>used(N,0);
	auto dfs = [&](auto&&f,int now,int color,vector<int>&col)->void{
		used[now] = true;
		col[now] = color;
		color ^= 1;
		for(auto e:gg[now]){
			if(col[e]!=-1){
				if(col[e]!=color)bi=0;
			}else{
				f(f,e,color,col);
			}
		}
	};
	REP(i,N){
		if(used[i])continue;
		bi = 1;
		vector<int>col(N,-1);
		dfs(dfs,i,0,col);
		if(bi==0){
			cout<<-1<<endl;
			return 0;
		}
		int b = 0,w = 0;
		REP(i,N){
			if(col[i]==0)w++;
			else if(col[i]==1)b++;
		}
		p.push_back({w,b});
	}
	int dp[707][707]={};
	dp[0][0]=1;
	REP(i,p.size()){
		REP(j,707){
			if(dp[i][j]==0)continue;
			dp[i+1][j+p[i].first]=true;
			dp[i+1][j+p[i].second]=true;
		}
	}
	int ans = INF;
	REP(i,707){
		if(dp[p.size()][i]){
			int ni = N-i;
			CHMIN(ans,i*(i-1)/2+ni*(ni-1)/2);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define ull unsigned long long
#define poly vector<ll>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
inline ll read(){
	ll x=0;char ch=getchar();bool d=1;
	for(;!isdigit(ch);ch=getchar()) if(ch=='-') d=0;
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return d?x:-x;
}
inline void write(ll x){
	if(x<0) x=-x,putchar('-');
	if(x>=10) write(x/10);
	putchar('0'+x%10);
}
inline void writeln(ll x){write(x);puts("");}
inline void writep(ll x){write(x);putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=5e5+5;
int fa[N],a[N],b[N];
poly v[N];
bool used[N];
int find(int x){
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
ll ans;
int main(){
	int n=read(),m=read();
	For(i,1,n) a[i]=read(),fa[i]=i;
	For(i,1,m){
		int u=find(read()+1),v=find(read()+1);
		if(u==v) continue;
		fa[u]=v;
	}
	For(i,1,n) v[find(i)].pb(i);
	int cnt=0;
	For(i,1,n) if(find(i)==i){
		cnt++;
		int mn=0x3f3f3f3f,pos=0;
		for(auto x:v[i]){
			if(a[x]<mn) mn=a[x],pos=x;
		}
		used[pos]=1;ans+=mn;
	}
	if(cnt==1) return puts("0"),0;
	m=0;
	For(i,1,n) if(!used[i]) b[++m]=a[i];
	int tot=(cnt-1)*2-cnt;
	if(tot>m) return puts("Impossible"),0;
	sort(b+1,b+m+1);
	For(i,1,tot) ans+=b[i];
	cout<<ans;
}

Measured memory_bytes: 19292
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  string a;
  cin>>a;
  int c=a.size();
  int b=0;
  for(int i=0;i<c/2;i++){
    if(a.at(i)!=a.at(c-i-1)){
      b++;
    }
  }
  cout<<b<<endl;
}


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

int N,x,y,visited[100010] = {0};
vector<vector<int>> v(100010);

int dfs(int n){
	visited[n] = 1;
	int g = 0;
	if(n!=1 && v[n].size()==1) return 0;
	for(int i=0;i<v[n].size();i++){
		int s = v[n][i];
		if(visited[s]==0){
			if((n==1 && v[n].size()==1) || n!=1 && v[n].size()==2) return dfs(s)+1;
			else{
				g ^= dfs(s)+1;
			}
		}
	}
	return g;
}

int main(){
	cin >> N;
	for(int i=0;i<N-1;i++){
		cin >> x >> y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	cout << (dfs(1)==0? "Bob":"Alice") << endl;
}

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

int main(void){
    int a,b,c;

    cin >> a >> b >> c;

    int list[3] = {a, b, c};
    int cnt_5 = 0,cnt_7 = 0;

    for(int i = 0; i<3; i++){
        if(list[i] == 5)cnt_5++;
        if(list[i] == 7)cnt_7++;
    }

    if(cnt_5 == 2 && cnt_7 == 1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return  0;
}


Measured memory_bytes: 3520
#include <stdio.h>

int main(void) {
	while (1) {
		int n;
		scanf("%d\n", &n);
		
		if (n == 0) {
			break;
		}
		
		int a_score = 0;
		int b_score = 0;
		
		int i;
		for (i = 0; i < n; i++) {
			int a;
			int b;
			scanf("%d %d\n", &a, &b);
			
			*(a >= b ? &a_score : &b_score) += a;
			*(b >= a ? &b_score : &a_score) += b;
		}
		
		printf("%d %d\n", a_score, b_score);
	}
	
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int D_MAX = 10;
int p[D_MAX+1], c[D_MAX+1];
int D, G;

int dfs(int s, int g, int a){
  if(s == D + 1){
    if(g <= 0 || a == 0) return 0;
    if(g - a*100*(p[a]-1) > 0) return INF;
    return (g + a*100 - 1)/(a*100);
  }
  return min(dfs(s+1, g-100*s*p[s]-c[s], a) + p[s] , dfs(s+1, g, s));
}

int main(){
  cin >> D >> G;
  for(int i = 1; i <= D; i++){
    cin >> p[i] >> c[i];
  }
  cout << dfs(1, G, 0) << endl;
  return 0;
}


Measured memory_bytes: 256
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#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 int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

string s;

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  int n;
  cin >> n;
  int ans = 0;
  cin >> s;
  int r=0,g=0,b=0;

  for(int i=0;i<n;i++){
    if(s[i]=='R')r++;
    else if(s[i]=='G')g++;
    else b++;
  }

  ans = r*g*b;

  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(s[i]!=s[j]){
        int nxt = j+(j-i);
        if(nxt<n){
          if(s[nxt]!=s[i] && s[nxt]!=s[j])ans--;
        }
      }
    }
  }

  cout << ans << endl;


return 0;
}
///....


Measured memory_bytes: 3672
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
//const ll mod = 1e9 + 7;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;

const int N = 2e5 + 10;
int t;

int main() 
{
	int a, b;
	while (cin >> a >> b)cout << a * b << endl;
		 
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
n = int(input())
ab = [list(map(int,input().split())) for i in range(n-1)]
ans = [0] * (n-1)
abi = [[] for _ in range(n+1)]
#再起のlimitを上げる
import sys
sys.setrecursionlimit(4100000)
for i,(a,b) in enumerate(ab):
    abi[a].append((i,b))
    abi[b].append((i,a))

def dfs(v,parent=-1,color=-1):
    k=1
    for i in abi[v]:
        if parent==i[1]:continue
        if(k==color):k+=1
        ans[i[0]]=k
        k+=1
        dfs(i[1],v,ans[i[0]])

dfs(1)

print(max(ans))
for i in ans:
    print(i)

Measured memory_bytes: 93560
#include <iostream>
using namespace std;
int main(){
  int a[]={5,7,5,7,7},n,i,j,c,k;
  while(cin>>n,n){
    string s[n];
    for(i=0;i<n;i++)cin>>s[i];
    for(i=0;i<n;i++){
      c=k=0;
      for(j=i;j<n;j++){
        c+=s[j].size();
        if(c==a[k]){
          c=0;
          if(++k==5)goto L;
        }
      }
    }
    L: if(k==5)cout<<i+1<<endl;
  }
}

Measured memory_bytes: 3192
program ABC111B
    implicit none
    integer(8)::i
    integer(8)::N

    read(5,*)N

    do i=1,9
        if(100*i+10*i+i>=N)then
            exit
        end if
    end do

    print'(i0)',100*i+10*i+i
    
end program ABC111B

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

using namespace std;

string s;

int main()
{
    cin>>s;
    if(s.size() % 2 != 0)
    {
        cout<<"No\n";
        return 0;
    }
    for(int i = 0; i < s.size(); i++)
    {
        if(i % 2 == 0)
            if(s[i] != 'h' || s[i + 1] != 'i')
            {
                cout<<"No\n";
                return 0;
            }
    }
    cout<<"Yes\n";
    return 0;
}


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

int main() {
	int n,p;
	string s;
	cin>>n>>p>>s;
	ll ans=0;
	if(p==2){
	    for(int i=0;i<n;++i){
	        if((s[i]-'0')%2==0)ans+=i+1;
	    }
	}
	else if(p==5){
	    for(int i=0;i<n;++i){
	        if((s[i]-'0')%5==0)ans+=i+1;
	    }
	}
	else{
	    map<int,int> mp;
	    ++mp[0];
	    int t=0;
	    int p2=1;
	    for(int i=n-1;i>=0;--i){
	        t=(t+(s[i]-'0')*p2)%p;
	        ans+=mp[t];
	        mp[t]++;
	        p2=p2*10%p;
	    }
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3968
/* DSL1_A: Disjoint Set */

#include <iostream>

class UnionFindTree {
    int *parents;
    int *ranks;

    public:
        UnionFindTree(int n) {
            parents = new int[n];
            ranks   = new int[n];
            for (int i = 0; i < n; i++) {
                parents[i] = i;
                ranks[i]   = 0;
            }
        }

        void unite(int x, int y) {
            x = find(x);
            y = find(y);
            if ( ranks[x] < ranks[y] ) {
                parents[x] = y;
            }
            else if ( ranks[y] < ranks[x] ) {
                parents[y] = x;
            }
            else if (x != y) {
                parents[x] = y;
                ranks[y] += 1;
            }
        }

        int find(int x) {
            if (parents[x] == x)
                return x;
            else
                return parents[x] = find( parents[x] );
        }

        bool is_grouped(int x, int y) {
            return find(x) == find(y);
        }
};

int main() {
    std::ios::sync_with_stdio(false);

    int n, q;
    std::cin >> n >> q;

    UnionFindTree uft(n);

    int command, x, y;
    for (int i = 0; i < q; i++) {
        std::cin >> command >> x >> y;
        switch (command) {
            case 0:
                uft.unite(x, y);
                break;
            case 1:
                bool same = uft.is_grouped(x, y);
                std::cout << ( same ? 1 : 0 ) << "\n";
                break;
        }
    }

    return 0;
}

Measured memory_bytes: 1276
import fractions
a,b,c,d = map(int,input().split())
AdivC = (a-1)//c
BdivC = b//c
AdivD = (a-1)//d
BdivD = b//d
gc = fractions.gcd(c,d)
div = (c*d)//gc
AdivCandD = (a-1)//div
BdivCandD = b//div

divC = BdivC - AdivC
divD = BdivD - AdivD
divCandD = BdivCandD - AdivCandD
ans = b-a+1
ans = ans -(divC+divD-divCandD)
print(ans)

Measured memory_bytes: 5048
n = int(input())
s = input()

r = s.count('R')
g = s.count('G')
b = s.count('B')

minus = 0

for i in range(n):
    for j in range(i+1,n):
        k = 2*j - i
        if k >= n or j >= n:
            break
        if s[i] != s[j] and s[j]!= s[k] and s[i] != s[k]:
            minus += 1
            
            
print(r*g*b - minus)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define pi 3.14159
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
template<class T> using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
int main()
{
long long n,m,array1[200005],array2[200005],k,i,counter=0,maxi=0,sum=0;
ordered_set<long long>s,s2;
cin>>n>>m>>k;
for(i=0;i<n;++i){
    cin>>array1[i];
    sum+=array1[i];
    s2.insert(sum);
}
sum=0;
for(i=0;i<m;++i){
    cin>>array2[i];
    sum+=array2[i];
    s.insert(sum);
}
sum=0;
for(i=0;i<n;++i){
    counter=i+1;
    sum+=array1[i];
    if(sum>k){
        break;
    }
    counter+=s.order_of_key(k-sum);
    if(s.find(k-sum)!=s.end()){
        counter++;
    }
    maxi=max(maxi,counter);
}
sum=0;
for(i=0;i<m;++i){
    counter=i+1;
    sum+=array2[i];
    if(sum>k){
        break;
    }
    counter+=s2.order_of_key(k-sum);
    if(s2.find(k-sum)!=s2.end()){
        counter++;
    }
    maxi=max(maxi,counter);
}
cout<<maxi<<endl;

    return 0;
}


Measured memory_bytes: 31672
#include<bits/stdc++.h>
#define N 
#define mod
#define inf 1000000000
#define rg register
typedef double db;
typedef long long ll;

using namespace std;

inline int gi(){
	int w=0,q=0; char c=getchar();
	while((c<'0'||c>'9')&&(c!='-')) c=getchar();
	if(c=='-') q=1,c=getchar();
	while (c>='0'&&c<='9') w=w*10+c-'0',c=getchar();
	return q?-w:w;
}

int n,x,ans,sum,sum2;

int main(){
	//freopen (".in","r",stdin);
	//freopen (".out","w",stdout);
	n=gi(),ans=inf;
	for (int i=1;i<=n;++i)
		x=gi(),sum+=x,sum2+=x*x;
	for (int p=1;p<=100;++p){
		int tmp=n*p*p-2*p*sum;
		ans=min(ans,tmp);
	}
	ans+=sum2;
	printf ("%d\n",ans);
	

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#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 dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int a[10][10];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	rrep(i, n + 1) {
		int c = i % 10;
		int b = i;
		while (b >= 10) b /= 10;
		a[c][b]++;
	}
	ll ans = 0;
	rep(i, 10)rep(j, 10) {
		ans += a[i][j] * a[j][i];
	}
	dunk(ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x1,x2,x3,x4,x5;
    scanf("%d %d %d %d %d",&x1,&x2,&x3,&x4,&x5);
    if(x1==0)
        printf("1");
    else if(x2==0)
        printf("2");
    else if(x3==0)
        printf("3");
    else if(x4==0)
        printf("4");
    else
        printf("5");
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll fac[1] = {1}, inv[1] = {1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}
ll cmb(ll r, ll c) {return fac[r] * inv[c] % MOD * inv[r - c] % MOD;}

char s[4];

int main() {
    scanf("%s", s);
    int n = strlen(s);

    int ans = 0;
    int cnt=0;
    for (int i = 0; i < n; i++) {
        if (i  && s[i]!=s[i-1]) ans = max(ans, cnt), cnt = 0;
        if (s[i]=='R') cnt++;
    }
    ans = max(ans, cnt);
    printf("%d", ans);
}

Measured memory_bytes: 3756
n = int(input())
x = input()

init_pop_cnt = x.count('1')
init_pop_cnt_less = init_pop_cnt - 1
init_pop_cnt_more = init_pop_cnt + 1

valid_l = init_pop_cnt_less != 0

# x's state after f
init_res_less = 0
init_res_more = 0
seed_more = 1
seed_less = 1
for i in range(1, n+1):
  xp = x[-1 * i]
  if xp == '1':
    if valid_l:
      init_res_less += seed_less % init_pop_cnt_less
    init_res_more += seed_more % init_pop_cnt_more
  if valid_l:
    seed_less = (seed_less * 2) % init_pop_cnt_less
  seed_more = (seed_more * 2) % init_pop_cnt_more


dif_less = [0] * (2 * 10**5 + 100)
dif_more = [0] * (2 * 10**5 + 100)
if valid_l:
  dif_less[0] = 1 % init_pop_cnt_less
dif_more[0] = 1 % init_pop_cnt_more
for i in range(1, n+1):
  if valid_l:
    dif_less[i] = (dif_less[i-1] * 2) % init_pop_cnt_less
  dif_more[i] = (dif_more[i-1] * 2) % init_pop_cnt_more


def get_pc(dec):
  out = 0
  while dec > 0:
    if dec % 2 == 1:
      out+=1
    dec = dec // 2
  return out

def f(dec):
  pc = get_pc(dec)
  return dec % pc

cnt = [0] * (2 * 10**5 + 200)

for i in range(1, 2 * 10**5 + 100):
  c = 0
  cur = i
  while cur > 0:
    c += 1
    cur = f(cur)
  cnt[i] = c

for i in range(n):
  xi = x[i]

  if xi == '1':
    if valid_l:
      lx = init_res_less
      lx -= dif_less[n-i-1]
      lx %= init_pop_cnt_less
      print((cnt[lx] % init_pop_cnt_less) + 1)
    else:
      print(0)
  else:
    lx = init_res_more
    lx += dif_more[n-i-1]
    lx %= init_pop_cnt_more
    print((cnt[lx] % init_pop_cnt_more) + 1)


Measured memory_bytes: 83500
import math
L = int(input())
if L >= 2**19: #lは橋の数
    l = 19
else:
    l = int(math.log2(L))

L -= 2**l
cnt = 2**l
M = 2*l
stack = []
for i in range(l,0,-1): #iは橋の番号
    while L >= 2**(i-1):
        L -= 2**(i-1)
        stack.append([i,l+1,cnt])
        M += 1
        cnt += 2**(i-1)

N = l+1
print(str(N)+' '+str(M))
for i in range(1,l+1):
    print(str(i)+' '+str(i+1)+' '+'0')
    print(str(i)+' '+str(i+1)+' '+str(2**(i-1)))

for i in range(len(stack)):
    print(str(stack[i][0])+' '+str(stack[i][1])+' '+str(stack[i][2]))

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

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

const ll INF=1LL<<60;

// 入力
ll n,m,a[100000];
ll h[100010];

// DPテーブル
ll dp[100010];

int main(){
  cin>>n>>m;
  for(int i=0;i<m;++i)cin>>a[i];
  // for(int i=0;i<n;++i)cin>>h[i];
  for(int i=0;i<100010;++i)dp[i]=0;
  dp[0]=1;
  int j=0;
  for(int i=1;i<=n;++i){
    if(i==a[j]){j++;continue;}
    dp[i]+=dp[i-1];
    if(i>1)dp[i]+=dp[i-2];
    dp[i]%=1000000007;
    // chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
    // if(i>1)chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout<<dp[n];
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

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

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    init();

    int N; cin >> N;
    vector<ll>A(N);
    rep(i, 0, N) {
        int a;cin >> a;
        A[(a + N + 1) / 2 - 1]++;
        A[(-a + N + 1) / 2 - 1]++;
    }
    if (N % 2 == 1)A[N / 2] /= 2;
    rep(i, (N + 1) / 2, N) {
        A[i]--;
    }
    mint ans = 1;
    rep(i, 0, N) {
        ans *= A[i];
    }
    cout << ans.x << "\n";

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <list>
#include <map>
using namespace std;

int main(void){
  int N;
  cin >> N;
  long long ans = 1;
  for(int i= 1; i <= N; i++){
    ans *= i;
    ans %= 1000000007;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstdio>

using namespace std;

const long long INF = 100000000;
const long long MOD = 1000000007;


long long gcd(long long a,long long b){
  if(a<b){
    swap(a, b);
  }
  if(a%b==0)
    return b;
  return gcd(a % b, b);
}

int main()
{
  long long H, W;
  cin >> H >> W;
  char S[H][W];
  for (int i = 0; i < H;i++){
    for (int j= 0; j < W; j++)
      cin >> S[i][j];
  }
  long long dpH[H][W];
  long long dpW[H][W];

  for (int j = 0; j < W;j++){
    for (int i = 0; i < H; i++)
    {
      //cout << i << j << "y";
      //縦方向の探索
      if (S[i][j] == '#')
      {
        dpH[i][j] = -1;
        continue;
      }
      if (i - 1 >= 0)
      {
        if (dpH[i - 1][j] != -1){
          dpH[i][j] = dpH[i - 1][j];
          continue;
        }

      }

      long long an = 0;
      long long d = 0;
      while(1)
      {
        if (i + d >= H)
          break;
        if(S[i+d][j]=='#')
          break;

        an++;
        d++;
        //cout << an << d << endl;
      }
      dpH[i][j] = an;
      //cout << dpH[i][j] << endl;
    }
  }


  for (int i = 0; i < H;i++){
    for (int j = 0; j < W; j++){
      //cout << i << j << "y";
      //縦方向の探索
      if (S[i][j] == '#')
      {
        dpW[i][j] = -1;
        continue;
      }
    if (j - 1 >= 0)
    {
      if (dpW[i][j-1] != -1)
      {
        dpW[i][j] = dpW[i][j-1];
        continue;
      }
    }

      long long an = 0;
      long long d = 0;
      while (1)
      {
        if (j + d >= W)
          break;
        if (S[i][j + d] == '#')
          break;

          an++;
          d++;
          //cout << an << j+d << endl;
      }
      dpW[i][j] = an;
      //cout << dpH[i][j] << endl;
    }
  }
  long long ans = 0;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W;j++){
      if(S[i][j]!='#')
        ans = max(ans, dpH[i][j] + dpW[i][j]-1);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 66688
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%lld", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%lld\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 3e2 + 5;
const double eps = 1e-9;
int a[MAXN];
int cnt[3];
double dp[MAXN][MAXN][MAXN];

int main()
{
    int n;
    ni(n);
    for (int i = 0; i < n; i++) {
        ni(a[i]);
        cnt[a[i] - 1]++;
    }
    for (int k = 0; k < MAXN; k++)
        for (int j = 0; j + k < MAXN; j++)
            for (int i = 0; i + j + k < MAXN; i++) {
                if (i + j + k == 0) continue;
                dp[i][j][k] = 1.0 * n / (i + j + k);
                if (i) dp[i][j][k] += dp[i - 1][j][k] * 1.0 * i / (i + j + k);
                if (j) dp[i][j][k] += dp[i + 1][j - 1][k] * 1.0 * j / (i + j + k);
                if (k) dp[i][j][k] += dp[i][j + 1][k - 1] * 1.0 * k / (i + j + k);
            }
    printf("%.20f\n", dp[cnt[0]][cnt[1]][cnt[2]]);
    return 0;
}


Measured memory_bytes: 221440