akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize, m: usize, q: usize,
        lr: [(usize, usize); m],
        pq: [(usize, usize); q],
    }

    let mut v = vec![vec![0; n + 2]; n + 2];
    for (l, r) in lr {
        v[l][r] += 1;
    }

    for i in 1..n + 2 {
        for j in 1..n + 2 {
            v[i][j] += v[i][j - 1];
        }
    }

    for i in 1..n + 1 {
        for j in 1..n + 1 {
            v[i][j] += v[i - 1][j];
        }
    }

    //dbg!(&v);

    for (p, q) in pq {
        let mut cnt = v[q][q] + v[p - 1][p - 1] - v[p - 1][q] - v[q][p - 1];
        println!("{}", cnt)
    }

    //println!("{}", n);
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
 
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define F0R(i, a) FOR (i, 0, a)
#define ROF(i, a, b) for(int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
 
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second

 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

const int N = 2019 + 5;
const int MOD = 2019;
bool vis [N];
 
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); 
  int L, R;
  cin >> L >> R;
  FOR (i, L, R + 1) {
    if (vis[i % MOD]) break;
    vis[i % MOD] = 1;
  }
  int res = 1e9;
  F0R (i, N) {
    if (!vis[i]) continue;
    FOR (j, i + 1, N) {
      if (!vis[j]) continue;
      res = min (res, (i * j) % MOD);
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl
#define int ll

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;

	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	vi x, y;
	x.PB(a), x.PB(b);
	y.PB(c), y.PB(d);
	if(a <= 0 && 0 <= b) x.PB(0);
	if(c <= 0 && 0 <= d) y.PB(0);
	int ans = -1e18;
	for(int sa:x)
		for(int na:y)
			ans = max(ans, sa * na);
	cout << ans << endl;
}



Measured memory_bytes: 3636
#include<stdio.h>

int main(void){
  int flag,i,n,a[100],count=0,temp,j;
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  flag=1;
  j=0;
  while(flag){
    flag=0;
    for(i=n-1;i>=j+1;i--){
      if(a[i]<a[i-1]){
        temp=a[i];
        a[i]=a[i-1];
        a[i-1]=temp;
        count++;
        flag=1;
      }
    }
    j++;
  }
  for(i=0;i<n;i++){
    if(i==n-1) printf("%d\n",a[i]);
    else printf("%d ",a[i]);
  }
  printf("%d\n",count);
  return  0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <cstring>

using namespace std;

int main() {
	char s[11], t[12];
	cin >> s;
	cin >> t;
	int n = strlen(s);
	int count = 0;
	for (int i = 0;i < n;i++) {
		if (s[i] == t[i]) count++;
		else {
			cout << "No";
			break;
		}
	}

	if (count == n) cout << "Yes";
	return 0;
}


Measured memory_bytes: 3652
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    int           MAX        = 10000001;
    boolean       is_prime[] = new boolean[MAX];
    int           prime[]    = new int[MAX];
    List<Integer> primeList  = new ArrayList<Integer>();

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Main main = new Main();
        main.calcPrime();
        while (scanner.hasNext()) {
            int ans = 0;
            int input = scanner.nextInt();
            if (input == 0) {
                break;
            }
            for (int i = 2; i < input; i++) {
                if (main.is_prime[i]) {
                    int b = input - i;
                    if (i > b) {
                        break;
                    }
                    if (main.is_prime[b]) {
                        ans++;
                    }
                }
            }
            System.out.println(ans);
        }
    }

    public void calcPrime() {
        int p = 0;
        for (int i = 0; i < MAX; i++)
            is_prime[i] = true;
        is_prime[0] = is_prime[1] = false;
        for (int i = 2; i < MAX; i++) {
            if (is_prime[i]) {
                prime[p++] = i;
                for (int j = 2 * i; j < MAX; j += i)
                    is_prime[j] = false;
            }
        }
    }
}

Measured memory_bytes: 71652
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {
        MyScanner scan = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = scan.nextInt();
        int l = scan.nextInt();
        int min = Integer.MAX_VALUE;
        int actual = 0;
        for (int i = 1; i <= n; i++) {
            int val = l + i - 1;
            if (Math.abs(min) > Math.abs(val)) {
                min = val;
            }
            actual += val;
        }
        actual -= min;
        out.println(actual);
        out.close();
    }


    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------

}

Measured memory_bytes: 21204
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int n; cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    int m = INF;
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        if(p[i] <= m) ans++;
        m = min(m, p[i]);
    }
    cout << ans << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main(){
    int h, w;
    cin >> h >> w;
    int masu_cnt = 0;
    rep(i, h) rep(j, w) {
        char masu;
        cin >> masu;
        if ( masu == '#' ) {
            ++masu_cnt;
        } 
    }
    
    if ( masu_cnt == ( h + w - 1 ) ) {
        cout << "Possible" << endl;
    }
    else {
        cout << "Impossible" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  int sum = 0;
  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
    sum += A[i];
  }

  REP(i, N-1) A[i+1] += A[i];

  int ans = sum;
  REP(i, N){
    chmin(ans, abs((sum-A[i])-A[i]));
  }

  cout << ans << "\n";

  return 0;
}

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

int main(){
  	int cnt(0);
  	char c, ch[5];
  	for(int i=0; i<3; i++){
    	cin>> ch[i];
    }
  	for(int i=0; i<3; i++){
    	cin>> c;
      	if(c==ch[i]) cnt++;
    }
  	cout<< cnt << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()

dp = [[0] * (N+1) for i in range(N+1)]

for i in range(N-1,-1,-1):
    for j in range(N-1,i-1,-1):
        # print(i,j)
        if S[i] == S[j]:
            dp[i][j] = dp[i+1][j+1] + 1 

# print(dp)
ans = 0
for i in range(N):
    for j in range(i+1,N):
       val = min(abs(i-j),dp[i][j])
       ans = max(val,ans)

print(ans) 

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

using namespace std;

#define _int64 long long

int du[100];

int main()
{
  int i,j,n,m,x,y;
  scanf("%d%d",&n,&m);
  memset(du,0,sizeof(du));
  for (i=0;i<m;i++)
  {
    scanf("%d%d",&x,&y);
    x--;y--;
    du[x]++;
    du[y]++;
  }
  for (i=0;i<n;i++)
    printf("%d\n",du[i]);
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AB = (A, B)
INF = 10**18

ans = INF
for state in range(1 << N):
    even = []
    odd = []

    for i in range(N):
        isReverse = (state & (1 << i)) >> i
        val = AB[isReverse][i]

        if i % 2 == 0:
            (even, odd)[isReverse].append((val, i))
        else:
            (odd, even)[isReverse].append((val, i))

    if len(even) != -(-N // 2) or len(odd) != N // 2:
        continue

    even.sort()
    odd.sort()
    odd.append((-1, -1))
    V = []
    P = []
    for (l, i), (r, j) in zip(even, odd):
        V.append(l)
        P.append(i)
        if r >= 0:
            V.append(r)
            P.append(j)

    if not all(l <= r for l, r in zip(V, V[1:])):
        continue

    cnt = 0
    for i, p in enumerate(P):
        for q in P[:i]:
            if p < q:
                cnt += 1
    ans = min(ans, cnt)

print(ans if ans != INF else -1)


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

typedef long long ll;

const int MAX = 1e5 + 5;

ll prefix[MAX];
ll abs_prefix[MAX];
ll sum(int l, int r){
    if(l > r) return 0;
    return prefix[r] - (l == 0 ? 0 : prefix[l - 1]);
}
ll abs_sum(int l, int r){
    if(l > r) return 0;
    return abs_prefix[r] - (l == 0 ? 0 : abs_prefix[l - 1]);
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector<int> a(n);
    cin >> a[0];
    for(int i = 0; i < n - 1; i++){
        char sgn; int val; cin >> sgn >> val;
        if(sgn == '-') a[i + 1] = -val;
        else a[i + 1] = val;
    }
    ll res = 0;
    bool neg = false;
    for(int i = 0; i < n; i++){
        if(a[i] < 0) neg = true;
        if(i) prefix[i] = prefix[i - 1] + a[i];
        else prefix[i] = a[i];
        if(i) abs_prefix[i] = abs_prefix[i - 1] + abs(a[i]);
        else prefix[i] = abs(a[i]);
    }
    if(!neg){
        cout << sum(0, n - 1) << '\n';
        return 0;
    }
    int it1 = 0;
    int it2 = 0;
    ll ans = 0;
    while(a[it1] > 0) it1++;
    it2 = it1 + 1;
    while(it1 != n){
        while(a[it2] > 0) it2++;
        ll val = sum(0, it1) - abs_sum(it1 + 1, it2 - 1) + abs_sum(it2, n - 1);
        ans = max(ans, val);
        it1 = it2;
        it2 = it1 + 1;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 5292
import sys
sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline
from itertools import permutations,  combinations, accumulate
from functools import *
from collections import deque, defaultdict, Counter
from heapq import heapify, heappop, heappush, heappushpop

INF = float('inf')
NIL = - 1

""" Input
S = input().rstrip()
N = int(input())
A = list(map(int, input().split()))
A = np.array(input().split(), dtype=np.float64)
D = [int(input()) for _ in range(N)]
AB = [[int(x) for x in input().split()] for _ in range(N)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
"""

t, B, a, D = map(int, input().split())

while True:
    a -= B
    if a <= 0:
        print('Yes')
        exit()
    t -= D
    if t <= 0:
        print('No')
        exit()







# def main():

# if __name__ == '__main__':
#     main()


Measured memory_bytes: 9576
import queue


def bfs(index, before):
    if direct[index] != -1:
        return
    print(index, before)
    direct[index] = before
    for next in graph[index]:
        bfs(index=next, before=index)


def main():
    n, m = map(int, input().split())
    graph = [[]for i in range(n+2)]
    direct = [-1 for i in range(n+2)]
    q = queue.Queue()

    for i in range(m):
        # a,b = map(lambda x:int(x)-1,input().split())
        a, b = map(int, input().split())
        graph[a].append(b)
        graph[b].append(a)
    q.put([1, 1])
    while q.qsize() != 0:
        index, before = q.get()
        if direct[index] == -1:
            direct[index] = before
            for next in graph[index]:
                q.put([next, index])
    print("Yes")
    for i in range(2, n+1):
        print(direct[i])

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 133544
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stack>

using namespace std;

int minimum=-1;


int main(){
	int n,row,num,col;
	scanf("%d",&n);
	int table[n][n];
	for(int i=0;i<n;i++){
		for(int k=0;k<n;k++){
			table[i][k] = 0;
		}
	}

	for(int i=0;i<n;i++){
		scanf("%d %d",&row,&num);
		for(int k=0;k<num;k++){
			scanf("%d",&col);
			table[row-1][col-1]=1;
		}
	}

	for(int i=0;i<n;i++){
		for(int k=0;k<n-1;k++){
			printf("%d ",table[i][k]);
		}
		printf("%d\n",table[i][n-1]);
	}

    return 0;
}



Measured memory_bytes: 3224
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC126_B_YYMM_or_MMYY
{
	class Program
	{
		static void Main(string[] args)
		{
			string input = Console.ReadLine();

			int front = int.Parse(input.Substring(0, 2));
			int back = int.Parse(input.Substring(2, 2));
			string output = "NA";

			if(front >= 1 && front <= 12)
			{
				output = "MMYY";

				if(back >= 1 && back <= 12)
				{
					output = "AMBIGUOUS";
				}
			}
			else if(back >= 1 && back <= 12)
			{
				output = "YYMM";
			}

			Console.WriteLine(output);
		}
	}
}


Measured memory_bytes: 11092
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#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;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#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 MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
	int a;
	cin >> a;
	int b[3];
	b[0]=a%10; a/=10;
	b[1]=a%10; a/=10;
	b[2]=a%10;
	if(b[0]!=7&&b[1]!=7&&b[2]!=7){
		cout << "No" <<endl;
	}
	else cout << "Yes" <<endl;

}



Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
/// Macros ---------------------
#define ll long long
#define sz(a) (int)a.size()
#define int long long
#define pb push_back
#define vi vector<int>
#define f first
#define s second
#define ii pair<int,int>
#define lb lower_bound
#define up upper_bound
#define rep(i,x,y) for(int i=(x);i<=(y);i++)
#define ld long double
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
/// Constracts -----------------------------------------------
const int maxn=1e5;
const int INF=(1ll)<<(30ll);
const int inf=1000000000000000000;
const int eps=1e-9;
const int mod=1e9+7;
/// Quick Pow ------------------------------------------------
int qpow(int b,int e)
{
    if( !e ) return 1;
    if( e & 1 ) return qpow(b, e - 1) * b;
    int pwur = qpow(b, e >> 1);
    return pwur * pwur;
}

int lcm(int a,int b){
    return a*b/__gcd(a,b);
}

/// My Code ---------------------------------------------------

int dp[55][55][2505];
int v[55];

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,a;
    cin>>n>>a;
    for(int i=1;i<=n;i++){
        cin>>v[i];
    }
    dp[0][0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<=n;j++){
            for(int k=0;k<=2500-v[i+1];k++){
                dp[i+1][j][k]+=dp[i][j][k];
                dp[i+1][j+1][k+v[i+1]]+=dp[i][j][k];
            }
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans+=dp[n][i][i*a];
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 54672
#coding:utf-8
n = int(input())
F = [False for i in range(n+1)]
def fib(n):
    if n == 0 or n == 1:
        F[n] = 1
        return 1
    if F[n]:
        return F[n]
    F[n] = fib(n-2) + fib(n-1)
    return F[n]

a = fib(n)
print(a)



Measured memory_bytes: 5608
/*
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<math.h>
#include<list>
#include<complex>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vvvll vector<vector<vector<ll>>>
#define vtype(type) vector<type>
#define vvtype(type) vector<vector<type>>
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;
struct wall
{
	long long r; ll c;
	bool operator<(const wall& rhs) const {
		if (r != rhs.r) {
			return r < rhs.r;
		}
		else {
			return c < rhs.c;
		}
	}
};

ll const MAX = 5e3 + 5;
vvll G(MAX);
vvvll dp(2, vvll(MAX, vll(MAX)));
vll parent(MAX);
vll ffct(1e6 + 5);
vll color(MAX);

ll const MOD = 998244353;
ll opp(ll x) {
	return (x + 1) % 2;
}


ll mod_p(ll x, ll y) {
	//x %= MOD;
	//y %= MOD;
	return (x + y + MOD) % MOD;
}

ll mod_m(ll x, ll y) {
	x %= MOD;
	y %= MOD;
	return x * y%MOD;
}

ll mod_pow(ll x, ll t) {
	x %= MOD;
	if (t == 0) {
		return 1;
	}
	else {
		ll v = mod_pow(x, t / 2);
		if (t % 2 == 0) {
			return v * v % MOD;
		}
		else {
			return v * v%MOD * x %MOD;
		}
	}
}

ll mod_inv(ll x) {
	return mod_pow(x, MOD - 2);
}


int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		int t = s[i] - 'a' + 13;
		t %= 26;
		s[i] = 'a' + t;
	}
	cout << s << endl;
}
*/

#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main() {
	string s;
	cin >> s;
	int zero = 0;
	int one = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0') {
			zero++;
		}
		else {
			one++;
		}
	}
	cout << 2 * min(zero, one) << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstring>
#include <map>
#include<cmath>
#include <algorithm>
#include <queue>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
vector<int> graph[250000];
bool visited[250001];
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    int a, b;
    for(int i = 0; i < m; i ++){
        cin >> a >> b;
        a --;
        b --;
        graph[a].push_back(b);
    }
    memset(visited, false, sizeof visited);
    queue<int> q;
    q.push(0);
    q.push(0);
    int node, cekor;
    visited[0] = true;
    int ret = (1 << 30);
    while(!q.empty()){
        node = q.front();
        q.pop();
        cekor = q.front();
        q.pop();
        if(node == n - 1){
            if(cekor == 2){
                return 0 * printf("POSSIBLE");
            }
            continue;
        }
        for(int i  =0; i < graph[node].size(); i ++){
            int neigh = graph[node][i];
            if(!visited[neigh]){
                visited[neigh] = true;
                q.push(neigh);
                q.push(cekor + 1);
            }
        }
    }
    puts("IMPOSSIBLE");
    return 0;
}


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

int main() {
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>> ab(M, { 0,0 });
	for (int i = 0; i < M; i++) cin >> ab[i].second >> ab[i].first;
	sort(ab.begin(), ab.end());
	int ans = 0;
	int E = 0;
	for (int i = 0; i < M; i++) {
		if (ab[i].second >= E) {
			ans++;
			E = ab[i].first;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;
//import java.util.Arrays;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		int y = sc.nextInt();
		int count = 0;
		int[] group = {1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
		System.out.println(group[x-1] == group[y-1] ? "Yes" : "No");
	}
}


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

int main() {
    int h,w,c[10][10];
    cin >> h >> w;
    REP(i,10)REP(j,10)cin >> c[i][j];
    REP(k,10)REP(i,10)REP(j,10)c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    int ans = 0;
    REP(i,h)REP(j,w){
        int a;
        cin >> a;
        if(a==-1)continue;
        ans += c[a][1];
    }
    cout << ans << endl;
    return 0;
}


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

#define fs first
#define se second
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb emplace_back

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int main() {
	lint n = in() - 2, a = in(), b = in();
	lint d = b - a;

	cout << max(b * n - a * n + 1, 0ll) << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define rep(a,b,c) for (int a=b;a<=c;a++)
#define ask(a) (a[x2][y2]+a[x1][y1]-a[x1][y2]-a[x2][y1])
using namespace std;
const int N=2010;
int get(){
	char ch;
	while ((ch=getchar())!='0'&&ch!='1');
	return ch-'0';
}
int n,m,q,x1,x2,y1,y2,ans,mp[N][N],s1[N][N],s2[N][N],s3[N][N];
int main(){
	scanf("%d%d%d",&n,&m,&q);
	rep(i,1,n) rep(j,1,m) mp[i][j]=get();
	rep(i,1,n) rep(j,1,m){
		s1[i][j]=mp[i][j];
		s2[i][j]=mp[i][j]&mp[i+1][j];
		s3[i][j]=mp[i][j]&mp[i][j+1];
	}
	rep(i,1,n) rep(j,1,m)
		s1[i][j]+=s1[i][j-1],
		s2[i][j]+=s2[i][j-1],
		s3[i][j]+=s3[i][j-1];
	rep(i,1,n) rep(j,1,m)
		s1[i][j]+=s1[i-1][j],
		s2[i][j]+=s2[i-1][j],
		s3[i][j]+=s3[i-1][j];
	rep(i,1,q){
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		--x1,--y1;
		ans=ask(s1);
		--x2,ans-=ask(s2),++x2;
		--y2,ans-=ask(s3);
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 64768
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leading zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll h,w;
    cin>>h>>w;
    ll a[h+1][w+1];
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            char ch;
            cin>>ch;
            if(ch=='.')a[i][j]=1;
            else a[i][j]=0;
        }
    }
    ll dp[h+2][w+2];
    memset(dp,0,sizeof(dp));
    //dp[0][0]=1;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(i==1 && j==1)dp[i][j]=1;
            else{
               dp[i][j]=dp[i-1][j]+dp[i][j-1];
               dp[i][j]%=1000000007;
               if(a[i][j]==0)dp[i][j]=0;
            }
        }
    }
    if(a[1][1]==0 || a[h][w]==0)cout<<0<<endl;
    else cout<<dp[h][w]<<endl;
}


Measured memory_bytes: 19220
// Goods things are coming, just keep believing 
 
#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 FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define okay cout << "okay" << endl
// #define hey cout << "hey" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
// #define mpp make_pair
#define endl '\n'
#define ff first 
#define int unsigned long long
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()
 #define ld long double
#define INF 1000000000;
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
 
 
 
const int N = 2e5 + 5;
const int LG = 20;
const int mod = 1e9 + 7;

int arr[N];
int pos[N];
vector<int> v[N];

int n;

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

void solve()
{
	string a, b;
	cin >> a >> b;
	cout << b << a << endl;
}
 
int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int t = 1;
	// cin >> t;
	while(t--)
	{
		solve();
	}
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		int l, r;
		cin >> l >> r;
		ans += r - l + 1;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int S;cin>>S;
  bool x=0<S%100&&S%100<13,y=0<S/100&&S/100<13;
  if(x&&!y)cout<<"YYMM"<<endl;
  if(!x&&y)cout<<"MMYY"<<endl;
  if(x&&y)cout<<"AMBIGUOUS"<<endl;
  if(!x&&!y)cout<<"NA"<<endl;
}

Measured memory_bytes: 256
strings = list(input())

num_a = 0
num_z = 0
flag = 0
for i in range(len(strings)):
    if strings[i]=='A' and flag==0:
        num_a = i
        flag = 1
    if strings[i]=='Z':
        num_z = i
x = num_z-num_a+1
print(x)

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

#ifdef LOCAL
#include "../debug.h"
#else
#define debug(x...) 141
#endif
#define forn(i,x,n) for(int i = x; i < n; ++i)
#define forit(it, m) for(auto it = m.begin(); it!=m.end(); ++it)
typedef long long ll;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    string s;

    cin>>n;
    map<string,int> m;
    forn(i,0,n){
    	cin>>s;
    	m[s]++;
    }
    cout<<"AC x "<<m["AC"]<<'\n';
    cout<<"WA x "<<m["WA"]<<'\n';
    cout<<"TLE x "<<m["TLE"]<<'\n';
    cout<<"RE x "<<m["RE"]<<'\n';
    
    return 0;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<int> a1(n);
    vector<int> a2(n);
    for(int i = 0; i < n; i++){
        cin >> a1[i];
    }
    for(int i = 0; i < n; i++){
        cin >> a2[i];
    }

    int ans = 0, a1sum = 0;
    for(int i = 0; i < n; i++){
        a1sum += a1[i];
        int a2sum = 0;
        for(int j = i; j < n; j++){
            a2sum += a2[j];
        }
        ans = max(ans, a1sum + a2sum);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <map>

using namespace std;

map<char, int> mcxi;

string toMCXI(int num){
    char m[] = {'m', 'c', 'x', 'i'};
    string ret = "";
    for(int i=0;i<4;i++){
        int k = num/mcxi[m[i]];
        if(k==1){
            ret += m[i];
        }else if(k!=0){
            ret += (char)('0'+k);
            ret += m[i];
        }
        num -= k*mcxi[m[i]];
    }
    return ret;
}

int toInt(string num){
    int ret = 0;
    int index = 0;
    while(index<num.length()){
        if(num[index]-'0'>9){
            ret += mcxi[num[index]];
        }else{
            ret += mcxi[num[index+1]]*(num[index]-'0');
            index++;
        }
        index++;
    }
    return ret;
}

int main(){
    mcxi['m'] = 1000;
    mcxi['c'] = 100;
    mcxi['x'] = 10;
    mcxi['i'] = 1;

    int n;
    cin >> n;
    while(n--){
        string num1, num2;
        cin >> num1 >> num2;
        int ans = toInt(num1) + toInt(num2);
        cout << toMCXI(ans) << endl;
    }
}

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

using namespace std;

const int mod = 1e9 + 7;

int n;
vector<int> G[100010];
long long dp[100010][2];

long long f(int u, int flag, int p) {
    auto &ans = dp[u][flag];
    if(ans != -1) return ans;
    ans = 1;
    for (int v: G[u]) {
        if(v == p) continue;
        if(flag) {
            ans *= (f(v, !flag, u));
            ans %= mod;
        } else {
            ans *= (f(v, flag, u) + f(v, !flag, u)) % mod;
            ans %= mod;
        }
    }
    return ans;
}

int main() {
    memset(dp, -1, sizeof dp);
    cin >> n;

    for (int i = 0; i < n - 1; ++i) {
        int x,y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    cout << (f(1,0,1) + f(1,1,1)) % mod<< "\n";
    return 0;
}


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

int main(){
  string x;
  char last;
  int N;
  bool flag = true;
  set<string> db;
  cin >> N;
  cin >> x;
  last = x.c_str()[x.size()-1];
  db.insert(x);
  for(int i = 1; i < N; i++ ){
    cin >> x;
    if( x.c_str()[0] != last || db.count(x) > 0 ){
      flag = false;
      break;
    }
    last = x.c_str()[x.size()-1];
    db.insert(x);
  }
  if( flag ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
/*
ID: espr1t
TASK: 
KEYWORDS: 
*/

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>

using namespace std;
FILE* in = stdin; FILE* out = stdout;

const int MAX = 10001;

int n;
int a[MAX];
vector <int> v[MAX];
int deg[MAX];
bool used[MAX];
int value[MAX];

void solve() {
    queue <int> q;
    memset(used, 0, sizeof(used));
    for (int node = 0; node < n; node++) {
        deg[node] = (int)v[node].size();
        if (deg[node] == 1) {
            q.push(node);
            used[node] = true;
        }
    }
    
    int idx = 0;
    sort(a, a + n);
    memset(value, -1, sizeof(value));

    int ans = 0;
    while (!q.empty()) {
        int node = q.front(); q.pop();
        value[node] = a[idx++];
//        fprintf(stderr, "Current node %d with value %d\n", node, value[node]);
        for (int i = 0; i < (int)v[node].size(); i++) {
            if (value[v[node][i]] == -1) {
                ans += value[node];
                deg[v[node][i]]--;
                if (deg[v[node][i]] <= 1 && !used[v[node][i]]) {
                    q.push(v[node][i]);
                    used[v[node][i]] = true;
                }
            }
        }
    }
    fprintf(out, "%d\n", ans);
    for (int node = 0; node < n; node++)
        fprintf(out, "%d%c", value[node], node + 1 == n ? '\n' : ' ');
    
    /*
    for (int node = 0; node < n; node++)
        for (int i = 0; i < (int)v[node].size(); i++)
            value[v[node][i]] += (int)v[node].size();
    vector < pair <pair <int, int>, int > > p;
    for (int node = 0; node < n; node++)
        p.push_back(make_pair(make_pair((int)v[node].size(), value[node]), node));
    sort(p.rbegin(), p.rend());
    for (int i = 0; i < (int)p.size(); i++)
        value[p[i].second] = a[i];
    
    int ans = 0;
    for (int node = 0; node < n; node++) {
        for (int i = 0; i < (int)v[node].size(); i++)
            if (node < v[node][i]) ans += min(value[node], value[v[node][i]]);
    }
    fprintf(out, "%d\n", ans);
    for (int node = 0; node < n; node++) {
        fprintf(out, "%d%c", value[node], node + 1 == n ? '\n' : ' ');
    }
    */
}

/*
int eval(int origin) {
    memset(value, -1, sizeof(value));
    queue <int> q;
    int ans = 0;
    int idx = 0;
    value[origin] = a[idx++];
    q.push(origin);
    while (!q.empty()) {
        
    }
}

int solve() {
    int ans = 0;
    for (int origin = 0; origin < n; origin++) {
        ans = max(ans, eval(origin));
    }
    return ans;
}
*/

int main(void) {
//	in = fopen("D.in", "rt");
	
	fscanf(in, "%d", &n);
	for (int i = 0; i < n - 1; i++) {
	    int node1, node2;
	    fscanf(in, "%d %d", &node1, &node2);
	    node1--, node2--;
	    v[node1].push_back(node2);
	    v[node2].push_back(node1);
    }
    for (int i = 0; i < n; i++)
        fscanf(in, "%d", &a[i]);
    sort(a, a + n);
    reverse(a, a + n);
    
    solve();
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int count = 0;
  for (int C = 1; C < N; C++) {
    double a = sqrt(N - C);
    for (int B = 1; B <= a; B++) {
      if ((N - C) % B == 0) {
        if (B < a) {
          count += 2;
        }
        else {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}

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

// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for (int i = 1; i <= N; ++i) {
    int sum = findSumOfDigits(i); 
    if (sum >= A && sum <= B) { 
      total += i;
    }
  }
  cout << total << endl;
}

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

using namespace std;

int main() {
    while(true) {
        int N, M;
        string str;
        cin >> N;
        if(!N) break;
        cin >> M >> str;

        int ans = 0;
        int p = 0;
        int phase = 0;
        for(int i = 0; i < str.size(); ++i) {
            if(phase == 0) {
                if(str[i] == 'I') {
                    if(p >= N) ++ans;
                    phase = 1;
                }
                else p = 0;
            }
            else {
                if(str[i] == 'O') {
                    ++p;
                    phase = 0;
                }
                else {
                    p = 0;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1976
def gcd(a, b):
    return gcd(b % a, a) if a and b else max(a, b)
    
n = int(input())
arr = sorted(list(map(int, input().split(' '))))
maxi = arr[-1]
gc = maxi
for num in arr[:-1]:
    if gcd(num, maxi) < gc:
        gc = gcd(num, maxi)

print(gc)

Measured memory_bytes: 114772
#include "bits/stdc++.h"
using namespace std;
const int maxn = 200200;
long long x[maxn], v[maxn];
vector<pair<int, int> > g[maxn];
vector<tuple<long long, int, int> > edges;
int dad[maxn];
void init(){
    for(int e = 0; e < maxn; e++) dad[e] = e;
}
int find(int x){
    if(x == dad[x]) return x;
    return dad[x] = find(dad[x]);
}
int sz[maxn], vis[maxn];
void init(int cur, int p = -1){
    sz[cur] = 1;
    for(auto e : g[cur]){
        if(e.first == p) continue;
        if(vis[e.first]) continue;
        init(e.first, cur);
        sz[cur] += sz[e.first];
    }
}
int get_centroid(int cur, int N, int p = -1){
    int biggest = -1;
    for(auto e : g[cur]){
        if(e.first == p) continue;
        if(vis[e.first]) continue;
        if(biggest == -1) biggest = e.first;
        else if(sz[biggest] < sz[e.first]) biggest = e.first;
    }
    if(biggest == -1 || 2*sz[biggest] <= N) return cur;
    return get_centroid(biggest, N, cur);
}
vector<pair<long long, int> > dp;
void push(int cur, int p = -1, long long d = 0){
    dp.push_back({x[cur] + d, cur});
    for(auto e : g[cur]){
        if(e.first == p) continue;
        if(vis[e.first]) continue;
        push(e.first, cur, d + e.second);
    }
}
void f(int cur){
    init(cur);
    cur = get_centroid(cur, sz[cur]);
    dp.clear();
    push(cur);
    sort(dp.begin(), dp.end());
    for(int e = 1; e < dp.size(); e++)
        edges.push_back(make_tuple(dp[0].first + dp[e].first, dp[0].second, dp[e].second));
    vis[cur] = 1;
    for(auto e : g[cur]){
        if(vis[e.first]) continue;
        f(e.first);
    }
}
int main(){
    int n;
    scanf("%d", &n);
    for(int e = 1; e <= n; e++) scanf("%lld", x + e);
    for(int e = 0; e < n - 1; e++){
        int u, v, w;
        scanf("%d %d %d", &u, &v, &w);
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }
    f(1);
    init();
    sort(edges.begin(), edges.end());
    long long ans = 0;
    for(auto e : edges){
        int u, v;
        long long w;
        tie(w, u, v) = e;
        u = find(u);
        v = find(v);
        if(u != v){
            ans += w;
            dad[u] = v;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 99428
import collections

s = input()
a = collections.deque(s)
ans = 0
while 1 < len(a):
	if a[0] != a[len(a) - 1]:
		ans += 1
		if a[0] != 'x':
			a.appendleft('x')
			if a[len(a) - 1] != 'x':
				ans = -1
				break
		else:
			a.append('x')
	else:
		a.popleft()
		a.pop()
print(ans)

Measured memory_bytes: 4212
#include<stdio.h>
int n,k,i=-1;
char s[100001],a;
int main(){
    scanf("%d%d%s",&n,&k,s);
    if(s[0]=='L')while(s[++i]==s[i+1]);
    a=s[n-1];
    while(s[++i]!='\0'){
        while(s[i]==s[i+1])i++;
        if(s[i]=='L')k--;
        if(k>=0)continue;
        if(s[i]=='L')n-=2;
        else if(s[i+1]=='\0')n--;
    }
    if(k>0||s[0]=='R'&&k==0||s[0]=='L'&&k<0||a=='L'&&s[0]=='L'&&k==0)n--;
    else if(s[0]=='L'&&k==0)n-=2;
    printf("%d",n);
    return 0;
}

Measured memory_bytes: 256
A, B, C, D = map(int, input().split())

right_boundary =D
left_boundary = C

if (B<C)or(D<A):
    print(0)
else:
    if C<A:
        left_boundary = A
    else:
        pass
    if B<D:
        right_boundary = B
    else:
        pass
    
    print(right_boundary - left_boundary)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <queue>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define vsort(v) sort(v.begin(),v.end)
using namespace std;
signed main() {
	int n, a, b, c;
	cin >> n >> a >> b >> c;
	cout << n - (a + b - c) << endl;
}


Measured memory_bytes: 3092
#include <iostream>
#include <string>

int main()
{
    while(1)
    {
        std::string ostr = "";
        std::string current = "";

        std::cin >> ostr;

        if (ostr == "-") {
            break;
        }

        int n = 0;

        std::cin >> n;

        int shuffle[n] = {};

        for (int i = 0; i < n; i++) {
            std::cin >> shuffle[i];
        }

        for (int i = 0; i < n; i++) {
            for (int j = shuffle[i]; j < ostr.length(); j++) {
                current += ostr[j];
            }

            for (int j = 0; j < shuffle[i]; j++) {
                current += ostr[j];
            }
            ostr = current;
            current = "";
        }


        std::cout << ostr << std::endl;


    }

    return 0;

}

Measured memory_bytes: 3132
#include <stdio.h>

int main(void)
{
    int n;
    int i, num;

    scanf("%d", &n);

    num = 100000;
    for (i = 1; i <= n; i++){
        num = num * 1.05;
        //printf("%d\n", num);
        if (num % 1000 != 0){
            num = num / 1000 + 1;
            num = num * 1000;
            //printf("%d\n", num);
        }
        //printf("%d\n", num);
    }

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

    return (0);
}



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

int main(){
  int N, i, j, c = 0;
  
  cin >> N ;

  vector<int> a(N);

  for(i=0;i<N;i++){
    cin >> a.at(i);
  }

  sort(a.begin(),a.end());
  
  for(i=0;i<N-1;i++){
    if(a.at(i) == a.at(i+1)){
      c++;
    }
  }
  
  cout << N-c << endl;    

}


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

bool check(char a){
  if(a=='0'||a=='1'||a=='2'||a=='3'||a=='4'||a=='5'||a=='6'||a=='7'||a=='8'||a=='9'){
    return true ;
  }
  return false ;
}

int main(){
  int a,b ;
  cin >> a >> b ;
  char x ;
  for(int i=0;i<a;i++){
    cin >> x ;
    if(!check(x)){
      cout << "No" << endl ;
      return 0 ;
    }
  }
  cin >> x ;
  if(x!='-'){
    cout << "No" << endl ;
    return 0 ;
  }
  for(int i=0;i<b;i++){
    cin >> x ;
    if(!check(x)){
      cout << "No" << endl ;
      return 0 ;
    }
  }
  cout << "Yes" << endl ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x,a,b;
  cin >> x >> a >> b;
  if(b-a<=0){
    cout << "delicious" << endl;
  }else if(x>=b-a){
    cout << "safe" << endl;
  }else{
    cout << "dangerous" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,x,t,sum=0,c=0;
    cin>>n>>x>>t;
   if(n%x==0)
   {
    cout<<(n/x)*t;
   }
   else{
    cout<<((n/x)+1)*t;
   }
   
}    
        
 
       


Measured memory_bytes: 3592