akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n; 
  vector<int> v(n);
  for(int i=0;i<n;i++)
    cin>>v.at(i);
  vector<int> c(n);
  for(int i=0;i<n;i++)
    cin>>c.at(i);
  int m=0;
  for(int i=0;i<(1<<n);i++){
    int x=i;
    vector<int> b(n);
    for(int j=0;j<n;j++){
      b.at(j)=x%2;
      x/=2;
    }
    int s=0;
    for(int j=0;j<n;j++)
      s+=(v.at(j)-c.at(j))*b.at(j);
    m=max(m,s);
  }
  cout<<m<<endl;
}

Measured memory_bytes: 256
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
	ll h, w, n, ans[110][110] = {}, x, y, a;
	cin >> h >> w >> n;
	for (int i = 0; i < n; i++) {
		cin >> x >> y >> a;
		if (a == 1) {
			for (int i = 0; i < 110; i++) {
				for (int j = 0; j < x; j++) {
					ans[i][j] = 1;
				}
			}
		}
		if (a == 2) {
			for (int i = 0; i < 110; i++) {
				for (int j = x; j < 110; j++) {
					ans[i][j] = 1;
				}
			}
		}
		if (a == 3) {
			for (int i = 0; i < y; i++) {
				for (int j = 0; j < 110; j++) {
					ans[i][j] = 1;
				}
			}
		}
		if (a == 4) {
			for (int i = y; i < 110; i++) {
				for (int j = 0; j < 110; j++) {
					ans[i][j] = 1;
				}
			}
		}
	}
	ll yojo = 0;
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			if (!ans[i][j])yojo++;
		}
	}
	cout << yojo << endl;
	return 0;
}


Measured memory_bytes: 384
//  A - Christmas Eve Eve Eve
//  main.c

#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int day = 0;
    
    scanf("%d",&day);
    
    switch(day){
        case 22:
            printf("Christmas Eve Eve Eve\n");
            break;
        case 23:
            printf("Christmas Eve Eve\n");
            break;
        case 24:
            printf("Christmas Eve\n");
            break;
        default:
            printf("Christmas\n");
            break;
    }
    
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
  char grid[100][100] = {};
  int h = 0;
  int w = 0;
  int i = 0;
  int j = 0;
  int k = 0;
  int flag = 0;
  scanf("%d %d",&h,&w);
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      scanf(" %c",&grid[i][j]);
    }
  }

  for(i=0;i<h;i++){
    flag = 1;
    for(j=0;j<w;j++){
      if(grid[i][j] == '#'){
        flag = 0;
        break;
      }
    }
    
    if(flag){
      for(k=0;k<w;k++){
       for(j=i;j<h-1;j++){
        grid[j][k] = grid[j+1][k];
        }
      }
      h--;   
      i--;
    } 
  }
  
  for(i=0;i<w;i++){
    flag = 1;
    for(j=0;j<h;j++){
      if(grid[j][i] == '#'){
        flag = 0;
        break;
      }
    }
    if(flag){
      for(k=0;k<h;k++){
        for(j=i;j<w-1;j++){
          grid[k][j] = grid[k][j+1];
        }
      }
      w--;
      i--;
    }
  }
  
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      printf("%c",grid[i][j]);
    }
    printf("\n");
  }
      
  return 0;
}

Measured memory_bytes: 128
//naveen mall
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto i: a)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        fl(i,0,n){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";cout<<"\n";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define PB                pop_back
#define endl              "\n"
#define what(x) cerr <<  #x << " is " << x << endl;
int sum() { return 0; }template<typename T,typename... Args>T sum(T a, Args... args) { return a + sum(args...); }


#define m 1000000007
 


void solve()
{  
 
  int n,k;
  cin>>n>>k;
  int ans=0;
  for(int i=k;i<=n+1;i++)
  	  {
  	     int min=i*(i-1)/2;
  	     int max=n*i-min;
  	     ans+=max-min+1;
  	     ans%=m;
  	  }
cout<<ans;


//cout<<ans;


 
   
}
signed main()
{fast
    int t;
 t=1;
 //return 0;
  // cin>>t;
  while(t--)
     {
      solve();
     }
 
 
 
}

Measured memory_bytes: 3652
#!/usr/bin/env python3
# Bitset 1 - Bit Operation 1


def run():
    n = int(input())
    fmt = "{:032b}"

    print(fmt.format(n))
    print(fmt.format(~n + 2**32))
    print(fmt.format(n << 1 & ~(1 << 32)))
    print(fmt.format(n >> 1))


if __name__ == '__main__':
    run()



Measured memory_bytes: 5608
#include <stdio.h>
#include <string.h>
int main(){
  char T[1000],P[1000];
  int i,j,l,m,count;
  scanf("%s",T);
  scanf("%s",P);
  l=strlen(T);
  m=strlen(P);
  for(i=0;i<l;i++){
    count=0;
    for(j=0;j<m;j++){
      if(T[i+j]==P[j]) count++;
    
    }
    if(count==m) printf("%d\n",i);
  }
  return 0; 
}  

Measured memory_bytes: 536
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m;i>n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C=0,D=0,E=0,F=INF,G=INF,H=0,N,M,K,sum=0;
  cin >> N;
  Vec(P,lli,N-1,0);Vec(Q,lli,N,0);
  rep(i,0,N-1)cin >> P[i];
  Q[0]=P[0];Q[N-1]=P[N-2];
  rep(i,1,N-1){
    Q[i]=min(P[i-1],P[i]);
  }
  rep(i,0,N)sum+=Q[i];
  Out(sum);
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  if (n % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }
  for (int i = 0; i < n / 2; i++){
    if(s[i]!=s[i+n/2]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    HashSet<String> words = new HashSet<>();
    String lastWord = scanner.next();
    words.add(lastWord);
    for (int i = 1; i < N; ++i) {
      String word = scanner.next();
      if (word.charAt(0) != lastWord.charAt(lastWord.length() - 1)) {
        System.out.println("No");
        return;
      }
      if (words.contains(word)) {
        System.out.println("No");
        return;
      }
      lastWord = word;
      words.add(word);
    }
    System.out.println("Yes");
    return;
  }
}

Measured memory_bytes: 21844
N, M = map(int,input().split())
data = []
dp = ['.' for i in range(N + 1)]
dp[0] = 1
dp[1] = 1
for i in range(M):
    k = int(input())
    data.append(k)
    dp[k] = 0
mod = 10**9 + 7
for i in range(2,N + 1):
    if dp[i] != 0:
        dp[i] = (dp[i - 1] + dp[i - 2]) % mod
print(dp[N] % mod)

Measured memory_bytes: 7836
import bisect
from collections import deque

N = int(input())
a_list = [int(input()) for i in range(N)]

colors = deque([])
colors.append(a_list[0])
for i in range(1, N):
    a = a_list[i]
    idx = bisect.bisect_left(colors, a)
    if idx == 0:
        colors.appendleft(a)
    else:
        colors[idx-1] = a

print(len(colors))

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

using namespace std;

const int N = (int) 2e6;

int n;
char s[N];
vector <int> a;

bool check(int n, int k) {
	return ((n - k) & k) == 0;
}

int main() {

	scanf("%d %s", &n, s);

	for (int i = 0; i < n - 1; i++) {
		a.push_back((int) abs(s[i] - s[i + 1]));
	}

	n--;

	vector <int> cnt(3, 0);

	for (int x : a) {
		cnt[x]++;
	}

	int coeff = 1;

	if (cnt[1] == 0) {
		coeff *= 2;
		for (int i = 0; i < a.size(); i++) {
			a[i] >>= 1;
		}
	}

	int res = 0;

	for (int i = 0; i < n; i++) {
		if (check(n - 1, i)) {
			res ^= a[i];
		}
	}

	printf("%d\n", (res & 1) * coeff);

	return 0;

}

Measured memory_bytes: 7280
#include<stdio.h>
#include<string.h>

struct card{
	char mark;
	int number;
};
int main(void)
{
	int i,j,m,c=0, n;
	scanf("%d",&n);
	struct card a[n];
	struct card b[n];
	struct card d;
	for(i=0; i<n; i++){
	scanf(" %c%d",&a[i].mark, &a[i].number);
		b[i]=a[i];
	}
	
	for(i=0; i<n; i++){
		for(j=n-1; j>i; j--){
			if(a[j-1].number>a[j].number)
			{
				d=a[j];
				a[j]=a[j-1];
				a[j-1]=d;
			}
		}
	}
	for(i=0;i<n-1; i++){
		printf("%c%d ",a[i].mark,a[i].number);
	}
	printf("%c%d\n",a[n-1].mark,a[n-1].number);
		
	printf("Stable\n");
	
	for(i=0; i<n; i++){
		m=i;
		for(j=i; j<n; j++){
			if(b[j].number<b[m].number){
				m=j;
			}

		}
				if(b[i].number!=b[m].number)
			{
				d=b[m];
				b[m]=b[i];
				b[i]=d;
			}
	}
	for(i=0;i<n-1; i++){
		printf("%c%d ",b[i].mark,b[i].number);
		if(b[i].mark!=a[i].mark){
			c++;
		}
	}
		printf("%c%d\n",b[n-1].mark,b[n-1].number);
			if(b[n-1].mark!=a[n-1].mark){
			c++;
			}
		if(c==0){printf("Stable");}
				else{printf("Not stable");}
	printf("\n");
	return 0;
}


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

int main(){
        
    int N; cin >> N;
    string S;cin >> S;
    
    int need_left = 0;
    int pointer = 0;
    for(int i = 0; i < S.size();i++){
        if(S[i]=='(')++pointer;
        else{
            if(pointer == 0)++need_left;
            else pointer--;
        }
    }
    
    int need_right = pointer;
    
    string res ="";
    for(int i = 0; i < need_left;i++)res += '(';
    res += S;
    for(int i = 0; i < need_right;i++)res += ')';
    cout << res << endl;
    
    
}



Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
B.sort()
C.sort()

cnt = 0
tmp = N
while tmp != 0:
  cnt += 1
  tmp //= 2

def binary_search(v, L, M, m):
  if M <= v:
    return 0
  elif m > v:
    return N
  else:
    l, r = 0, N
    d = (l + r) // 2
    for _ in range(cnt):
      if L[d] <= v:
        l = d + 1
        d = (l + r) // 2
      else:
        r = d
        d = (l + r) // 2
    return N - d
MB, mB, MC, mC = B[N-1], B[0], C[N-1], C[0]
LB = [binary_search(B[_], C, MC, mC) for _ in range(N)]
for i in range(N-1, 0, -1):
  LB[i-1] += LB[i]
S = 0
for i in range(N):
  X = N - binary_search(A[i], B, MB, mB)
  if X != N:
    S += LB[X]
print(S)

Measured memory_bytes: 23328
A, B, N = [int(_) for _ in input().split()]

from math import gcd, floor

g = A * B // gcd(A, B)
if N >= g:
    N = g

if N < B:
    n = N
else:
    n = N // B * B - 1

result = floor(A * n / B) - A * floor(n / B)

print(result)


Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
constexpr int mod = 1e9 + 7;
string s;
string pre, suf, c;
int rev, q, t, f;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> s >> q;
	while(q--)
	{
		cin >> t;
		if(t==1) rev ^= 1;
		else
		{
			cin >> f >> c;
			if(f==1)
			{
				if(rev) suf += c;
				else pre += c;
			}
			else
			{
				if(rev) pre += c;
				else suf += c;
			}
		}
	}
	reverse(all(pre));
	string res = pre + s + suf;
	if(rev) reverse(all(res));
	cout << res;
	return 0;
}

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

signed main(){
	int i, N;
	char *s = (char *)malloc(sizeof(char) * 200001);
	scanf("%s", s);
	for(N = 0; s[N] != '\0'; N++);
	vector<int> A(N + 1, 0);
	for(i = N - 2; i >= 0; i--){
//		printf("i = %lld\n", i);
		if(s[i] == 'B' && s[i + 1] == 'C'){
			A[i] = A[i + 2] + 1;
		}
		else if(s[i] == 'A'){
			A[i] = A[i + 1];
		}
	}
	int ans = 0;
	for(i = 0; i < N; i++){
		if(s[i] == 'A'){
			ans += A[i];
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2048
<?php

class Answer
{
    private $input_number;
    public function __construct()
    {
        while (1) {
            $line = FGETS(STDIN);
            if ($line == false) {
                break;
            }
            $line = trim($line);
            $lines[] = $line;
        }
        $this->input_number = explode(' ', $lines[0]);
    }

    public function getGreatestCommonDivisor()
    {
        $x = $this->input_number[0];
        $y = $this->input_number[1];
        if ($x < $y) {
            $tmp = $y;
            $y = $x;
            $x = $tmp;
        }
        while ($x % $y != 0) {
            $tmp = $y;
            $y = $x % $y;
            $x = $tmp;
        }
        echo $y, PHP_EOL;
    }
}
    $answer = new Answer;
    $answer -> getGreatestCommonDivisor();



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

using namespace std;
using ll = long long;

int main(void) {
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> v(n, vector<pair<int, int>>());
  vector<int> v2(n);
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    v2[i] = m;
    for (int j = 0; j < m; j++) {
      int a, b;
      cin >> a >> b;
      v[i].push_back(make_pair(a - 1, b));
    }
  }
  int ans = 0;
  for (int i = 0; i < (1 << n); i++) {
    bitset<15> b(i);
    bool f = true;
    int tmp = 0;
    for (int i = 0; i < n; i++) {
      if (b[i] == 0) {
        continue;
      }
      tmp++;
      for (int j = 0; j < v2[i]; j++) {
        if (v[i][j].second == 1 && b[v[i][j].first] == 0) {
          f = false;
        }
        if (v[i][j].second == 0 && b[v[i][j].first] == 1) {
          f = false;
        }
      }
    } 
    if (f) {
      ans = max(ans, tmp);
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int a[5];
int main() {
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
	}
	sort(a,a+5);
	for (int i = 4; i >= 0; i--) {
		cout << a[i];
		if (i == 0)cout << endl;
		else cout << " ";
	}

	return 0;

}


Measured memory_bytes: 3100
using System;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i <= 7; i++)
            {
                if (n < Math.Pow(2, i))
                {
                    Console.WriteLine((int)Math.Pow(2, i - 1));
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 11092
W, H, N = map(int, input().split())
P = [None for _ in range(N)]
a = [None for _ in range(N)]
for i in range(N):
  *P[i], a[i] = map(int, input().split())

ans = [[1] * W for _ in range(H)]
for i in range(N):
  if a[i] == 1:
    for j in range(H):
      for k in range(P[i][0]):
        ans[j][k] = 0
  elif a[i] == 2:
    for j in range(H):
      for k in range(P[i][0],W):
        ans[j][k] = 0
  elif a[i] == 3:
    for j in range(P[i][1]):
      for k in range(W):
        ans[j][k] = 0
  else:
    for j in range(P[i][1],H):
      for k in range(W):
        ans[j][k] = 0
  #print(P[i],i,ans)
print(sum(map(sum,ans)))

Measured memory_bytes: 3188
use std::io::{stdin, BufRead, BufReader};


fn gcd(x: i64,y:i64)-> i64{
    if y==0{
       return x;
    }
    return gcd(y,x%y);
}
fn lcm(x: i64,y:i64) ->i64{
    if x==0 || y==0{
        return 0;
    }
    return x*y/gcd(x,y);
}


fn main(){
    let input = BufReader::new(stdin());

    for line in input.lines(){
        
        let v: Vec<i64> = line.unwrap().split_whitespace().filter_map(|x| x.parse::<i64>().ok()).collect();
        println!("{} {}",gcd(v[0],v[1]),lcm(v[0],v[1]));

            
    }
}
    

// --- template ---
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
 
pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n {
        vs.push(readln());
    }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(
    String,
    bool,
    f32,
    f64,
    isize,
    i8,
    i16,
    i32,
    i64,
    usize,
    u8,
    u16,
    u32,
    u64
);
impl<T> FromLn for Vec<T>
where
    T: FromLn,
{
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);



Measured memory_bytes: 5028
#include<bits/stdc++.h>
using namespace std;
int ara[101];
main()
{
    int n,i;
    while(~scanf("%d",&n))
    {
        for(i=0;i<n;i++) scanf("%d",&ara[i]);
        sort(ara,ara+n);
        printf("%d\n",ara[n-1]-ara[0]);
    }
    return 0;
}

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

int main()
{
	

	int n, q;

	cin >> n >> q;

	vector<vector<int>> v(n);

	for (int i = 0; i < q; i++) {
		int command, t;
		cin >> command >> t;

		if (command == 0) {
			int x;
			cin >> x;
			v[t].push_back(x);
		}
		else if (command == 1) {
			for (int j = 0; j < v[t].size(); j++) {
				cout << v[t][j];
				if (j + 1 != v[t].size()) {
					cout << " ";
				}
			}
			cout << endl;
		}
		else {
			v[t].clear();
		}
	}

	return 0;
}



Measured memory_bytes: 5836
tHP,tAT,aHP,aAT = map(int,input().split())

while tHP>0 and aHP>0:
    aHP = aHP - tAT
    if aHP<=0:
        print("Yes")
        break
    tHP = tHP - aAT
    if tHP<=0:
        print("No")
        break



Measured memory_bytes: 9168
/*
ID: seekho
PROG: friday
LANG: C++14                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

//find_by_order gives kth-largest element
//order_of_key gives the number of items in the set that are strictly smaller!!

// OT.find_by_order(k-1)
// 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define db4(x, y, z, w) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << "," << #w << "=" << w << endl
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define X first
#define Y second
#define sz(x) (int)((x).size())
#define pii pair<int,int>
#define MOD (ll)(998244353)
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
typedef vector<int> vi;
#define inf (ll)(1e18)
#define double long double
#define int long long

//////////////////////
const int N = 100005;

int n,w;
int wt[101];
int val[101];
int memo[101][N];

int go(int ind, int value) {
	if(value < 0) return -1;
	if(ind >= n and value != 0) return -1;
	else if(ind >= n) return w;

	if(memo[ind][value] != -inf) return memo[ind][value];

	// rep(i,N) {
		if(go(ind + 1, value - val[ind]) - wt[ind] >= 0) {
			memo[ind][value] = max(go(ind + 1, value - val[ind]) - wt[ind], go(ind + 1, value));
		}
		else memo[ind][value] = go(ind + 1, value); 
	// }
	return memo[ind][value];
}

int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(0); 
    cout.tie(0);

    cin >> n >> w;
    rep(i,n) cin >> wt[i] >> val[i];

    rep(i,n) {
    	rep(j,N)
    		memo[i][j] = -inf;
    }

    repD(i,N-1,0) {
    	if(go(0,i) >= 0) {
    		cout << i << '\n';
    		return 0;
    	}
    }
}

Measured memory_bytes: 78464
#pragma GCC optimize("Ofast")

//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)



int main() {
  // 高速化
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);


    int k;
    cin >> k;
    vector<ll> a;

    FOR(i, 1, 9){
       a.push_back(i);
    }

    while(1){
      if(k <= a.size()){
        cout << a[k-1] << "\n";
        return 0;
      }
      k -= a.size();
      vector<ll> old;

      swap(a, old);
      for(ll x: old){
        FOR(i, -1, 1){
          int num = x%10 + i;
          if(num < 0 || num > 9){
            continue;
          }
          a.push_back(x*10 + num);
        }
      }
    }


    return 0;



}


Measured memory_bytes: 1712
using System;

namespace AizuOnline
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] i = Console.ReadLine().Split();
            int w = int.Parse(i[0]),
                h = int.Parse(i[1]),
                x = int.Parse(i[2]),
                y = int.Parse(i[3]),
                r = int.Parse(i[4]);
            string arranged = "Yes";

            if (x < r || x > w-r)
            {
               arranged = "No";
            }
            if (y < r || y > h-r)
            {
               arranged = "No";
            }
            Console.WriteLine(arranged);
        }
    }
}


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

 
int main() {
    string s;
    cin>>s;
    int ans=0;
    for(int i=0;i<s.length()-1;i++){
        if(s[i+1]!=s[i])ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define fora(i,a,b) for(int i=a,Wub=b;i<Wub;++i)
#define ford(i,a,b) for(int i=a,Wub=b;i>=Wub;--i)
#define SPEEDIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MAX 1000000
#define MOD 1073741824
using namespace std;
typedef long long ll;

int main(){
    int a,b;
    cin>>a>>b;
    if(a==1)a+=100;
    if(b==1)b+=100;
    if(a>b)cout<<"Alice\n";
    else if(b>a)cout<<"Bob\n";
    else cout<<"Draw\n";
    return 0;
}


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

int main(){
    string S;

    cin>>S;

    string n="";
    n+=S[0];
    n+=S[1];
    n+=S[2];
    n+=S[3];
    string g="";
    g+=S[5];
    g+=S[6];
    string h="";
    h+=S[8];
    h+=S[9];
    long nen=stoi(n);
    long getu=stoi(g);
    long hi=stoi(h);

    //cout<<nen<<" "<<getu<<" "<<hi<<endl;

    if(nen>2019){
        cout<<"TBD"<<endl;
    }else if(nen==2019&&getu>4){
        cout<<"TBD"<<endl;
    }else{
        cout<<"Heisei"<<endl;
    }

}

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

#define deb(x) cout << #x << " " << x << "\n";
#define fo(i, n) for(i=0; i<n; i++)
#define Fo(i, k, n) for(i=k; i<n; i++)
#define endl "\n"
#define ll long long
#define vi vector<int>

// memset(arr, value, size);

int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);

	int l , r, n, i, count = 0;
	cin >> l >> r >> n;
	Fo(i, l, r + 1) {
		if (i % n == 0) count++;
	}
	cout << count;

	return 0;
}

Measured memory_bytes: 3640
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 1e5 + 10 ;
const ll INF = 1e18 + 10 ;
int main(){
    fastio
    string s ;
    cin >> s ; 
    string ar[] = {"SUN", "MON", "TUE","WED","THU","FRI","SAT"} ; 
    for(int i = 0; i < 7; i++){
        if ( s == ar[i] ){
            return cout << 7 - i << endl, 0 ;
        }
    }
    return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <functional>
#include <limits>
#include <queue>
#include <iomanip>
#include <deque>
#include <stack>
#include <cstdio>
#include <cmath>
#include <complex.h>
#include <cstdio>
#include <random>
#include <chrono>
#include <numeric>
#include <cassert>
#include <iso646.h>
#include <exception>
#include <stdexcept>

using namespace std;

typedef long long i64;

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

    int n, k;
    cin >> n >> k;

    int min_distance = 0;
    for (int y = 1; y <= n; y++)
    {
        int x;
        cin >> x;

        min_distance += 2 * min(x, k - x);
    }

    cout << min_distance;
}

Measured memory_bytes: 256
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;


int main() {

	int n, m;
	cin >> n >> m;
	vector<int> p(m);
	vector<string> s(m);
	vector<int> aorw(n, 0);
	vector<int> cheak(n, 0);
	int accnt = 0;
	int wacnt = 0;

	rep(i, m) {
		cin >> p.at(i);
		cin >> s.at(i);
		if (aorw.at(p.at(i) - 1) == 0 && s.at(i) == "AC") {
			accnt++;
			aorw.at(p.at(i) - 1) = 1;
		}
	}
	rep(i, m) {

		if (cheak.at(p.at(i) - 1) == 0 && s.at(i) == "AC") {
			cheak.at(p.at(i) - 1) = 1;
		}
		else if (cheak.at(p.at(i) - 1) == 0 && aorw.at(p.at(i) - 1) == 1 && s.at(i) == "WA") {
			wacnt++;
		}
	}
	cout << accnt << ' ' << wacnt << endl;

	
	return 0;
}

Measured memory_bytes: 6912
#include<cstdio>
#include<cstring>
#include<algorithm>

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

using namespace std;

int main(){
	for(int n;scanf("%d",&n),n;){
		int a[25][24]={};
		rep(_,n){
			int m,t,q; scanf("%d%d",&m,&t);
			rep(i,m) scanf("%d",&q), a[m][(i-t+m)%m]+=q;
		}

		// 55440 = LCM({1,2,...,24}\{13,17,19,23})
		static int L[55440];
		memset(L,0,sizeof L);
		for(int m=1;m<=24;m++) if(m!=13 && m!=17 && m!=19 && m!=23) {
			rep(j,55440) L[j]+=a[m][j%m];
		}

		int ans=*max_element(L,L+55440)
			   +*max_element(a[13],a[13]+13)
			   +*max_element(a[17],a[17]+17)
			   +*max_element(a[19],a[19]+19)
			   +*max_element(a[23],a[23]+23);
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int solve(char c, string S){
  int ret = 0;

  while(true){
    bool flg = true;
    rep(i,S.size()){
      if(S[i] != c) flg = false;
    }
    if(flg) break;
    ret++;
    
    string T;
    rep(i,S.length()-1){
      if(S[i] == c || S[i+1] == c){
        T += c;
      }else{
        T += S[i];
      }
    }
    S = T;
  }
  return ret;
}


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

  int ret = 100000000;
  for(char c='a'; c<='z'; c++){
    ret = min(ret, solve(c, S));
  }

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int[] stack=new int[100];
		int stackPointer=0;
		String s;
		while(scan.hasNext()){
			s=scan.next();
			if(s.equals("+")){
				stack[stackPointer-2]=stack[stackPointer-2]+stack[stackPointer-1];
				stackPointer-=1;
			}else if(s.equals("-")){
				stack[stackPointer-2]=stack[stackPointer-2]-stack[stackPointer-1];
				stackPointer-=1;
			}
			else if(s.equals("*")){
				stack[stackPointer-2]=stack[stackPointer-2]*stack[stackPointer-1];
				stackPointer-=1;
			}
			else{
				stack[stackPointer++]=Integer.parseInt(s);
			}
		}
		System.out.println(stack[0]);
		scan.close();
	}
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()
#define arr array

template<typename T> void umin(T& a,T b){a = min(a,b);}
template<typename T> void umax(T& a,T b){a = max(a,b);}

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using pll = pair<ll, ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;


void pre(){

    

}

const ll N = 2005;
vector<ll> A;
ll dp[N];
bool vis[N];

ll go(ll sum){
    if(sum < 0)
        return 0;
    if(sum == 0)
        return 1;
    if(vis[sum]){
        return dp[sum];
    } 
    vis[sum] = true;
    ll ans=0;
    for(auto it : A){
        ans += go(sum-it);
        ans %= mod;
    }
    return dp[sum] = ans;
}

void solve(){

    int s;
    cin >> s;
    // for(int i=3;i<=s;i++){
    //     A.push_back(i);
    // }
    // reverse(all(A));
    // ll ans = go(s);
    // cout << ans;
    vector<ll> dp(s+1);
    dp[0] = 1;
    for(int i=3;i<=s;i++){
        for(int j=i;j>=3;j--){
            dp[i] += dp[i-j];
            dp[i] %= mod;
        }
    }
    cout << dp[s];  

}


int32_t main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 3644
if __name__ == '__main__':
	K = int(input())

	L = [['0'],['1'],['2'],['3'],['4'],['5'],['6'],['7'],['8'],['9']]

	ans = 0
	count = 9
	check = 0

	if K < 10:
		ans = L[K][0]
		check = 1

	while check == 0:
		newL = [['']] * 10
		for i in range(10):
			newls = []
			if i == 0:
				for s in L[0]:
					newls.append(str(i)+s)
				for s in L[1]:
					newls.append(str(i)+s)
			elif i == 9:
				for s in L[8]:
					newls.append(str(i)+s)
					count += 1
					if count == K:
						ans = newls[-1]
						check = 1
				for s in L[9]:
					newls.append(str(i)+s)
					count += 1
					if count == K:
						ans = newls[-1]
						check = 1
			else:
				for j in range(-1,2):
					for s in L[i+j]:
						newls.append(str(i)+s)
						count += 1
						if count == K:
							ans = newls[-1]
							check = 1

			newL[i] = newls[:]

		L = newL[:]


	print(int(ans))

Measured memory_bytes: 16360
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		int b = scan.nextInt();
		int h = scan.nextInt();
		int m = scan.nextInt();
		
		scan.close();
		
		double aDeg = ((double)h / 12 * 360 + (double) m / 60 * 30) % 360;
		double bDeg = ((double)m / 60 * 360) % 360;
		
		double deg = Math.abs(aDeg - bDeg);
		
		double answer = Math.sqrt(a * a + b * b - 2 * a * b * Math.cos(Math.toRadians(deg)));
		
		//System.out.println(aDeg);
		//System.out.println(bDeg);
		//System.out.println(deg);
		
		System.out.println(answer);
		
		
		
	}

}


Measured memory_bytes: 27140
#include<bits/stdc++.h>
using namespace std;
int read(){
	int x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1; ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int tree[100005];
int lowbit(int x){
	return (x&(-x));
}
int n,m,k;
struct Li{
	int l,r;
}a[200005];
struct Que{
	int l,r,id;
}q[200005];
int ans[200005];
bool cmp1(Li a,Li b){
	return a.r<b.r;
}
bool cmp2(Que a,Que b){
	return a.r<b.r;
}
void modify(int x,int y){
	for (int i=x;i<=n;i+=lowbit(i))
	tree[i]+=y;
}
int query(int x){
	int ans=0;
	for (int i=x;i;i-=lowbit(i))
	ans+=tree[i];
	return ans;
}
int main(){
	n=read(),m=read(),k=read();
	for (int i=1;i<=m;i++){
		a[i].l=read(); a[i].r=read();
	}
	sort(a+1,a+1+m,cmp1);
	for (int i=1;i<=k;i++){
		q[i].l=read(); q[i].r=read(); q[i].id=i;
	}
	sort(q+1,q+1+k,cmp2);
	int j=1,tot=0;
	for (int i=1;i<=k;i++){
		while (j<=m&&a[j].r<=q[i].r){ modify(a[j].l,1); j++; tot++; }
		ans[q[i].id]=tot-query(q[i].l-1);
	}
	for (int i=1;i<=k;i++)
	printf("%d\n",ans[i]);
	return 0;
} 

Measured memory_bytes: 5120
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

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

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	S := sc.nextStr()
	X, Y := sc.nextInt(), sc.nextInt()
	Ax := []int{}
	Ay := []int{}
	count := 0
	isX := true
	for _, r := range S {
		if r == 'F' {
			count++
		} else {
			if isX {
				Ax = append(Ax, count)
			} else {
				Ay = append(Ay, count)
			}
			count = 0
			isX = !isX
		}
	}
	if count > 0 {
		if isX {
			Ax = append(Ax, count)
		} else {
			Ay = append(Ay, count)
		}
	}

	if f(X, Ax[1:], 0+Ax[0]) && f(Y, Ay, 0) {
		fmt.Fprintln(wtr, "Yes")
	} else {
		fmt.Fprintln(wtr, "No")
	}
}

const MAX = 8000

func f(target int, A []int, start int) bool {
	// 0: -8000, 8000: 0, 16000: 8000
	dp := make([][MAX*2 + 1]bool, len(A)+1)
	dp[0][MAX+start] = true
	for i := 1; i <= len(A); i++ {
		for j := 0; j <= MAX*2; j++ {
			if dp[i-1][j] {
				dp[i][j+A[i-1]] = true
				dp[i][j-A[i-1]] = true
			}
		}
	}
	return dp[len(A)][target+MAX]
}


Measured memory_bytes: 124160
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    int sz = s.size();
    int ans = 0;
    for(int i=sz-2;i>=0;i-=2) {
        int c = i/2;
        bool ok = true;;
        for(int j=0;j<c;j++) {
            if(s[j] != s[j+c]) {
                ok = false;
                break;
            }
        }
        if(ok) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}


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

int a[100010];
long long dp[100010];

int main () {
	int n, E, T; scanf("%d%d%d", &n, &E, &T);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 0;
	int pos = 0;
	long long minj = 0x3f3f3f3f3f3f3f3f;
	for (int i = 1; i <= n; i++) {
		while (2 * (a[i] - a[pos + 1]) >= T) minj = min(minj, dp[pos] - 2 * a[pos + 1]), pos++;
		dp[i] = minj + 2 * a[i];
		if (pos != i) dp[i] = min(dp[i], dp[pos] + T);
	}
	printf("%lld\n", dp[n] + E);
	return 0;
}


Measured memory_bytes: 1408
from collections import defaultdict

MOD = int(1e9) + 7


def main():
    N = int(input())
    S = input()
    cnt = defaultdict(lambda: 0)
    ans = 1
    for c in S:
        ans = ans + ans // (cnt[c]+1)
        cnt[c] += 1
    print(ans % MOD-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 41068
#include <bits/stdc++.h>
using namespace std;
#define itn int

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        mp[a]++;
    }
    for (int i = 0; i < m; i++) {
        int b, c;
        cin >> b >> c;
        mp[c] += b;
    }
    long long ans = 0;
    int rem = n;
    while (1) {
        auto a = mp.end();
        a--;
        int b = a->first, c = a->second;
        if (rem >= c) {
            ans += 1ll * b * c;
            rem -= c;
            mp.erase(a);
        } else {
            ans += 1ll * b * rem;
            cout << ans << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 201000
#define ac 101000

int n, cnt, tot;
int ll[ac], rr[ac];

struct node{
	int id, sum;
}l[AC], r[AC];

inline bool cmp(node a, node b)
{
	return a.sum > b.sum;
}

int read()
{
	int x = 0;char c = getchar();
	while(c > '9' || c < '0') c = getchar();
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x;
}

void pre()
{
	n = read();
	int b = n / 2;
	for(R i = 1; i <= b; i ++) 
		++ ll[read()], ++ rr[read()];
}

void work()
{
	for(R i = 1; i <= 100000; i ++)
	{
		if(ll[i]) l[++cnt] = (node){i, ll[i]};
		if(rr[i]) r[++tot] = (node){i, rr[i]};
	}
	sort(l + 1, l + cnt + 1, cmp);
	sort(r + 1, r + tot + 1, cmp);
	if(l[1].id != r[1].id)
	{
		printf("%d\n", n - l[1].sum - r[1].sum);
		return ;
	}
	else
	{
		int x = l[1].sum + r[2].sum, y = l[2].sum + r[1].sum;
		printf("%d\n", n - max(x, y));
	}
}

int main()
{
	pre();
	work();
	return 0;
}

Measured memory_bytes: 1792
def min(a,b):
    if a < b:
        return a
    else:
        return b
n,m,x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
right = 0
left = 0

for i in range(x + 1,n):
    if i in a:
        right += 1

for i in range(1,x):
    if i in a:
        left += 1

print(min(right, left))


Measured memory_bytes: 3060
# B - Buffet
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
####
stsf = 0
before = N
for a in A:
    stsf += B[a-1]
    if a == before+1:
        stsf += C[a-2]
    before = a
print(stsf)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int t1,t2,t3,t4;
	int a,b,c,d;
	cin>>t1>>a>>t2>>b>>t3>>c>>t4>>d;
	switch(t1){
		case 1: cout<<a*6000<<endl;break;
		case 2:cout<<a*4000<<endl;break;
		case 3:cout<<a*3000<<endl;break;
		case 4:cout<<a*2000<<endl;break;

	}
	switch(t2){
		case 1: cout<<b*6000<<endl;break;
		case 2:cout<<b*4000<<endl;break;
		case 3:cout<<b*3000<<endl;break;
		case 4:cout<<b*2000<<endl;break;

	}
	switch(t3){
		case 1: cout<<c*6000<<endl;break;
		case 2:cout<<c*4000<<endl;break;
		case 3:cout<<c*3000<<endl;break;
		case 4:cout<<c*2000<<endl;break;

	}
	switch(t4){
		case 1: cout<<d*6000<<endl;break;
		case 2:cout<<d*4000<<endl;break;
		case 3:cout<<d*3000<<endl;break;
		case 4:cout<<d*2000<<endl;break;

	}
	return 0;
}


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

int knapSackRec(int W, int wt[], int val[],
                int i, int** dp)
{
 
    if (i < 0)
        return 0;
    if (dp[i][W] != -1)
        return dp[i][W];

    if (wt[i] > W) {
    
        dp[i][W] = knapSackRec(W, wt, val, i - 1, dp);
        return dp[i][W];
    }
    else {

        dp[i][W] = max( val[i] + knapSackRec(W - wt[i], wt, val, i - 1, dp),knapSackRec(W, wt, val, i - 1, dp));

        return dp[i][W];
    }
}

int knapSack(int W, int wt[], int val[], int n)
{
    int** dp;
    dp = new int*[n];

    for (int i = 0; i < n; i++)
        dp[i] = new int[W + 1];

    for (int i = 0; i < n; i++)
        for (int j = 0; j < W + 1; j++)
            dp[i][j] = -1;
    return knapSackRec(W, wt, val, n - 1, dp);
}

int32_t main()
{
    int n,w; 
    cin>>n>>w;
    int value[n+1],weight[n+1];

    for(int i=0;i<n;i++)
    {
        cin>>weight[i]>>value[i];
    }

    cout<<knapSack(w, weight,value,n);
}



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

int main() {
  int N;
  cin >> N;
  
  int count = 30;
  
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    
    int countSub = 0;
    int exp = 2;
    
    while (A % exp == 0) {
      exp *= 2;
      countSub ++;
    }
    
    if (countSub < count){
      count = countSub;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <queue>
#include <sstream>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), a + n
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)

using namespace std;

typedef long long ll;

const double EPS = 1e-10;
const double PI = acos(-1.0);

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

int main() {
	int n;
	scanf("%d", &n);
	vector<int> h(n);
	REP(i, n) { scanf("%d", &h[i]); }
	int m = 0;
	int num = 0;
	REP(i, n - 1) {
		if(h[i] >= h[i + 1]) {
			num++;
		} else {
			m = max(num, m);
			num = 0;
		}
	}
	m = max(num, m);

	printf("%d\n", m);

	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String t = scanner.nextLine();
        System.out.println(lcs(s,t));
    }


    private static String lcs(String s, String t){
        if(s.isEmpty() || t.isEmpty()) return "";
        int m = s.length();
        int n = t.length();
        int[][] dp = new int[m+1][n+1];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if(s.charAt(i)==t.charAt(j)) dp[i+1][j+1]=dp[i][j]+1;
                else dp[i+1][j+1] = Math.max(dp[i][j+1],dp[i+1][j]);
            }
        }
        int length = dp[m][n];
        char[] ans = new char[length];
        for (int i = m-1, j = n-1; length>0 ;) {
            if(s.charAt(i)==t.charAt(j)){
                ans[--length]=s.charAt(i);
                i--;
                j--;
            }else if(dp[i+1][j]>dp[i][j+1]) j--;
            else i--;
        }
        return new String(ans);
    }
}


Measured memory_bytes: 85368
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 998244353;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main(void) {
	ll n;
	string ans = "";
	cin >> n;
	while (n) {
		n--;
		ans += ('a' + n % 26);
		n /= 26;
	}
	reverse(all(ans));
	puts(ans.c_str());
	return 0;
}


Measured memory_bytes: 3628
import itertools

N, M, Q = map(int, input().split(' '))
_list = [list(map(int, input().split(' '))) for i in range(Q)]

kouho = [i for i in range(1, M+1)]

_max = 0
for j, comb in enumerate(itertools.combinations_with_replacement(kouho, N)):
    _sum = 0
    for __list in _list:
        if comb[__list[1]-1] - comb[__list[0]-1] == __list[2]:
            _sum += __list[3]
        # print(comb)
        # print(__list)
        #print(_sum)
    # print('-----------')
    if _sum > _max:
        _max = _sum

print(_max)



Measured memory_bytes: 9232
def nxt(u)
	u.each do |val|
		if $d[val] == nil
			return val
		end
	end
	return nil
end

def dfs(u)
	$cnt += 1
	$stk.push(u)
	$d[u] = $cnt
	while $stk != []
		u = nxt($l[$stk.last])
		if u != nil
			$stk.push(u)
			$cnt += 1
			$d[u] = $cnt
		else
			$cnt += 1
			$f[$stk.pop] = $cnt
		end
	end
end


n = gets.chomp.to_i
$l=[]
n.times do
	u, k, *v = gets.chomp.split(" ").map(&:to_i)
	$l[u] = v
end
$stk = []
$d = []
$f = []
$cnt=0

1.upto(n) do |i|
	if $d[i] == nil
		dfs(i)
	end
end

1.upto(n) do |i|
	print "#{i} #{$d[i]} #{$f[i]}\n"
end


Measured memory_bytes: 6884