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

char alp[200];
    string s;

typedef string::const_iterator State;
string cipher(State&);
string String(State&);
string letter(State&);


string letter(State &begin){
    string ret;
    if(*begin == '+'){
        begin++;
        ret = letter(begin);
        ret[0] = alp[ret[0] + 1];
    }else if(*begin == '-'){
        begin++;
        ret = letter(begin);
        ret[0] = alp[ret[0] - 1];
    }else{
        ret += *begin;
        begin++;
    }
    return ret;
}

// ??¬??§?????°???????????????????????????????????????????????????
string String(State &begin) {
    if (*begin == '[') {
        begin++; // '('????£???°??????
        string ret = cipher(begin);
        begin++; // ')'????£???°??????
        reverse(all(ret));
        return ret;
    }else{
        return letter(begin);
    }
    return 0;
}

// ?????????????????????????????????????????????????????????????????????
string cipher(State &begin) {
    string ret = String(begin);

    while(begin != s.end()){
        if(*begin == ']') break;
        ret += cipher(begin);
    }

    return ret;
}


//begin???expected?????????????????????begin?????????????????????
void consume(State &begin, char expected) {
    if (*begin == expected) {
        begin++;
    } else {
        cerr << "Expected '" << expected << "' but got '" << *begin << "'" << endl;
        cerr << "Rest string is '";
        while (*begin) {
            cerr << *begin++;
        }
        cerr << "'" << endl;
        //throw ParseError();
    }
}

int main(){
    for(char i = 'A'; i <= 'Z'; i++){
        alp[static_cast<int>(i)] = i;
    }
    alp[static_cast<int>('A') - 1] = 'Z';
    alp[static_cast<int>('Z') + 1] = 'A';

    while(cin >> s,s[0] != '.'){
        string ans = "";
        rep(i,100) ans += 'Z';
        vector<int> v;
        rep(i,s.size()){
            if(s[i] == '?') v.emplace_back(i);
        }
        char i[3];
        for(i[0] = 'A'; i[0] <= 'Z'; i[0]++){
            for(i[1] = 'A'; i[1] <= 'Z'; i[1]++){
                for(i[2] = 'A'; i[2] <= 'Z'; i[2]++){
                    rep(l,v.size()) s[ v[l] ] = i[l];

                    State  tmp = s.begin();
                    ans = min(ans,cipher(tmp));
                    if(v.size() == 0) goto end;
                }
            }
        }
end:
        cout << ans << endl;
    }
}

Measured memory_bytes: 3080
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Main main = new Main();
		main.solveC();
	}

	private void solveA() {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int g = sc.nextInt();
		int b = sc.nextInt();
		System.out.println((g * 10 + b) % 4 == 0 ? "YES" : "NO");
	}

	private void solveB() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int min = 1000;
		int max = 0;
		for (int i = 0; i < N; i++) {
			int a = sc.nextInt();
			if (min > a) {
				min = a;
			}
			if (max < a) {
				max = a;
			}
		}
		System.out.println(max - min);
	}

	private void solveC() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] rates = new int[9];
		for (int i = 0; i < N; i++) {
			int a = sc.nextInt();
			int index = a / 400;
			rates[index > 8 ? 8 : index]++;
		}
		int kind = 0;
		for (int j = 0; j < 8; j++) {
			if (rates[j] > 0) {
				kind++;
			}
		}
		int min = kind;
		if (rates[8] > 0 && min == 0) {
			min = 1;
		}
		int max = kind + rates[8];
		System.out.println(min + " " + max);
	}

	private void solveD() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		int left = 0;
		int need = 0;
		for (int i = 0; i < N; i++) {
			char c = S.charAt(i);
			if (c == '(') {
				left++;
			} else {
				if (left > 0) {
					left--;
				} else {
					need++;
				}
			}
		}
		for (int n = 0; n < need; n++) {
			System.out.print('(');
		}
		System.out.print(S);
		for (int n = 0; n < left; n++) {
			System.out.print(')');
		}
		System.out.println();
	}
}

Measured memory_bytes: 23892
use proconio::input;


fn solve(s: Vec::<String>) {
    let mut c = std::collections::HashMap::new();

    for si in &s {
        *c.entry(si).or_insert(1) += 1;
    }

    let max = c.values().max().unwrap();
    let mut ns = Vec::new();

    for (k, v) in &c {
        if v == max {
            ns.push(k);
        }
    }

    ns.sort();

    for si in ns {
        println!("{}", si);
    }
}


fn main() {
    input! {
        n: usize,
        s: [String; n],
    }

    solve(s);
}



Measured memory_bytes: 21440
#include<bits/stdc++.h>
using namespace std;
#define int           long long
#define	pb            push_back
#define all(a)        (a).begin(),(a).end()
#define sz(x)         (int)x.size()
#define F             first
#define S             second
#define endl          "\n"
#define inf           1000000007
#define FOR(i, a, b)  for(int i=a; i<b; i++)
#define bigboi        1e18
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); 
#define SHUF(v) shuffle(all(v), RNG);
// Use mt19937_64 for 64 bit random numbers. 

int dp[102][100005];
void solve(){	
	int n, W;
	cin>>n>>W;
	pair<int, int> arr[n];
	FOR(i, 0, n){
		int w, v;
		cin>>w>>v;
		arr[i] = {w, v};
	}
	dp[0][0] = 0;
	FOR(i, 1, n+1){
		FOR(w, 0, W+1){
			if( arr[i-1].F <= w ){
				dp[i][w] = max(arr[i-1].S + dp[i-1][w-arr[i-1].F], dp[i-1][w]);
			}
			else{
				dp[i][w] = dp[i-1][w];
			}
		}
	}
	cout<<dp[n][W];
}
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0); 	
	int t=1;
	//cin>>t;
	FOR(i, 1, t+1){	
		//cout<<"Case #"<<i<<": ";
		solve();
	}
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
 
}


Measured memory_bytes: 78464
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const ll mod = 1e9+7;

int w,h,n;
int x[2];
int y[2];

int main()
{
    cin >> w >> h >> n;
    x[0] = 0; x[1] = w; y[0] = 0; y[1] = h;
    rep(i,n){
        int xin, yin, a;
        cin >> xin >> yin >> a;
        if(a == 1) x[0] = max(x[0], xin);
        else if(a == 2) x[1] = min(x[1], xin);
        else if(a == 3) y[0] = max(y[0], yin);
        else y[1] = min(y[1], yin);
    }
    
    if(x[1] < x[0] || y[1] < y[0]) puts("0");
    else cout << (x[1]-x[0]) * (y[1]-y[0]) << endl;
}


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

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n, m);
    Cins(int, n, h);
    vc<int> a(n, true);
    Rep(m){
        Cin(int, x, y);
        x --, y --;
        if(h[x] <= h[y]) a[x] = false;
        if(h[y] <= h[x]) a[y] = false;
    }
    int ans = 0;
    For(i, n) if(a[i]) ans ++;
    Cout(ans);
}


Measured memory_bytes: 3972
#include<stdio.h>
#include<string.h>
int main(void){
  int n,m,p,i,f,t,d[100001]={0};
  char S[3];
  scanf("%d %d",&n,&m);
  t=0;
  f=0;
  for(i=0;i<m;i++){
    scanf("%d %s",&p,S);
    if(S[0]=='W'&&d[p]!=-1){
      d[p]++;
    }
    if(S[0]=='A'&&d[p]!=-1){
      t++;
      f=f+d[p];
      d[p]=-1;
    }
  }
  printf("%d %d\n",t,f);
  return 0;
 }


Measured memory_bytes: 512
def main():
    sx, sy, tx, ty = list(map(int, input().split(' ')))
    assert sx < tx and sy < ty
    # s -> t
    ans = 'R' * (tx - sx) + 'U' * (ty - sy)
    # t -> s
    ans += 'L' * (tx - sx) + 'D' * (ty - sy)
    # s -> t
    ans += 'D' + 'R' * (tx - sx + 1) + 'U' * (ty - sy + 1) + 'L'
    # t -> s
    ans += 'U' + 'L' * (tx - sx + 1) + 'D' * (ty - sy + 1) + 'R'
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

int stack[1000],top=0;

void push(int x)
{
	stack[++top] = x;
}

int pop()
{
	top--;
	return stack[top+1];
}

int main()
{
	char s[100];
	int x,y;

	while(scanf("%s",s) != EOF){
		if(s[0] == '+'){
			x = pop();
			y = pop();
			push(x + y);
		}else if(s[0] == '-'){
			x = pop();
			y = pop();
			push(y - x);
		}else if(s[0] == '*'){
			x = pop();
			y = pop();
			push(x * y);
		}else{
			push(atoi(s));
		}
	}

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

	return 0;
}



Measured memory_bytes: 2056
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  ll N; cin >> N;
  vector<ll> A(N); rep(i,N) cin >> A[i];
  ll ans = 1e18;
  for(ll to = -100; to <= 100; to++){
    ll preans = 0;
    rep(i,N){
      preans += (A[i]-to)*(A[i]-to);
    }
    ans = min(ans, preans);
  }
  cout << ans << endl;
  return 0;
}


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

#define DIV 1000000007

long long N, M, K;

long long kaidan[10000000];

void kaical(long long n){
	kaidan[0] = 1;
	for(long long i = 1; i < n; i++){
		kaidan[i] = kaidan[i-1] * i;
		kaidan[i] %= DIV;
	}
}

long long modpow(long long ori, long long po){
	long long res = 1;
	while(po > 0){
		if(po&1){
			res *= ori;
			res %= DIV;
		}
		ori *= ori;
		ori %= DIV;
		po >>= 1;
	}
	return res;
}

//nCk
//https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae
long long combination(long long n, long long k){
	if(n == 0 && k == 0)return 1;
	if(n < k || n < 0)return 0;
	long long n_kai = kaidan[n];
	long long k_kai = kaidan[k];
	long long nmk_kai = kaidan[n-k];

	long long ans = n_kai * modpow(k_kai, DIV - 2);
	ans %= DIV;
	ans *= modpow(nmk_kai, DIV-2);
	ans %= DIV;
	return ans;
}

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

	long long ans = 0;
	
	//x
	for(long long len = 1; len < M; len++){
		ans += len * (M- len) * N * N;
		ans %= DIV;
	}
	

	//y
	for(long long len = 1; len < N; len++){
		ans += len * (N-len) * M * M;
		ans %= DIV;
	}

	kaical(N*M);
	ans *= combination(N*M-2, K-2);
	ans %= DIV;
	cout << ans << endl;
}



Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <fstream>
#include <stdint.h>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

constexpr int evx[4] = { 1, 0, -1, 0 };
constexpr int evy[4] = { 0, 1, 0, -1 };

//----------------------------------
//----------------------------------

constexpr int Sup = 5000;
bool number[Sup];
vector<int> primes;

void era()
{
        for(int i = 0; i < Sup; ++i)
        {
                number[i] = true;
        }

        primes.push_back(2);
        primes.push_back(3);
        int prime = 1; // 2n + 1 -> n
        while(true)
        {
                int add = 2 * prime + 1;
                for(int i = prime + add; i < Sup; i += add)
                {
                        number[i] = false;
                }
                int j = prime + 1;
                while(true)
                {
                        if(j >= Sup)
                                return;
                        else
                                if(number[j])
                                {
                                        prime = j;
                                        primes.push_back(2* prime + 1);
                                        break;
                                }
                        j++;
                }
        }
}

inline bool test_divid(int n)
{
        if(n < 10000)
                return binary_search(primes.begin(),primes.end(), n);
        else
                for(auto p : primes)
                {
                        if(n % p == 0)
                                return false;
                }
                return true;
}

signed main()
{
    ios::sync_with_stdio(false);
        era();
        int n;
        cin >> n;
        int ans = 0;
        for(int i = 0; i < n; ++i)
        {
                int tmp;
                cin >> tmp;
                ans += test_divid(tmp);

        }
        cout << ans << '\n';


}

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

#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pi;
typedef vector<int> vi;
void print_pair(pi a){
  cerr<<"("<<a.first<<", "<<a.second<<") ";
}
template<int T1, int T2>
void print_2d(int a[T1][T2], int x, int y){
  For(i, x){
    For(j, y){
      cerr<<a[i][j]<<" ";
    }
    cerr<<endl;
  }
}
template<class T>
void print_array(T a[],size_t n){
  cerr<<"array:";
  REP(n-1)cerr<<a[i]<<",";
  cerr<<a[n-1]<<endl;
}

ll H,W,N;
pair<ll,ll> V[200001];
ll kanou[200001];

int main(){
  fill(V,V+200001,make_pair(-1,-1));
  cin>>H>>W>>N;
  int index=0;
  REP(N){
    ll tmp1,tmp2;
    cin>>tmp1>>tmp2;
    if(tmp1<tmp2)
      continue;
    else{
      V[index]=make_pair(tmp1-1,tmp2-1);
      index++;
    }
  }
  sort(V,V+index);
  fill(kanou,kanou+W+1,H);
  kanou[0]=0;
  ll j=0;
  for (ll i = 1; i < H; i++) {
    auto itr=lower_bound(V,V+index,make_pair(i,j+1));
    while(*itr==make_pair(i,j+1)&&i<H){
        i++;
        itr=lower_bound(V,V+index,make_pair(i,j+1));
    }
    kanou[j+1]=i;
    j++;
  }
  ll ans=0;
  REP(index){
    if(kanou[V[i].second]<V[i].first){
      ans=V[i].first;
      goto end2;
    }
  }
  cout<<H<<endl;
  return 0;
end2:
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 4992
import java.util.Scanner;

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

        String s = sc.next();

        int a = Integer.parseInt(s.substring(0, 2));
        int b = Integer.parseInt(s.substring(2, 4));

        if ((a == 0 && b == 0) || (a > 12 && b == 0) || (b > 12 && a == 0)) {
            System.out.println("NA");
        } else {
            if (a <= 12 && b <= 12) {
                if (a == 0)
                    System.out.println("YYMM");
                else if (b == 0)
                    System.out.println("MMYY");
                else
                    System.out.println("AMBIGUOUS");
            } else if (a > 12 && b <= 12) {
                System.out.println("YYMM");
            } else if (a <= 12 && b > 12) {
                System.out.println("MMYY");
            } else {
                System.out.println("NA");
            }
        }
    }
}

Measured memory_bytes: 20692
#include <iostream>

#define N 10000000

long long e[N + 1];

int main()
{
    for (int i = 1; i <= N; i ++)
    {
        e[i] = 1;
        for (int j = i; j % 2 == 0; e[i]++, j /= 2);
    }
    for (int i = 3; i <= N; i += 2)
    {
        if (e[i] == 1)
        {
            for (int j = i; j <= N; j += i)
            {
                int c = 0;
                int k = j;
                while (k % i == 0)
                {
                    k /= i;
                    c++;
                }
                e[j] = e[j] * (c + 1);
            }
        }
    }
    int n;
    scanf("%d", &n);
    long long s = 0;
    for (int i = 1; i <= n; i++) s += e[i] * i;
    printf("%lld\n", s);
    return 0;
}

Measured memory_bytes: 81948
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#include<bitset>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(void){
    string n;
    cin >> n;
    int count = 0;
    rep(i,3){
        if(n[i]=='1'){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
W=list(map(int,input().split()))

S=sum(W)
total=0
diff=10000
for n in range(N):
  total=total+W[n]
  S_1=total
  S_2=S-S_1
  if diff>abs(S_1-S_2):
    diff=abs(S_1-S_2)

print(diff)



Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 1 << 60


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def ep(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        ep(e - s, 'sec')
        return ret

    return wrap


class UnionFind():
    def __init__(self):
        self.__table = {}
        self.__size = defaultdict(lambda: 1)
        self.__rank = defaultdict(lambda: 1)

    def __root(self, x):
        if x not in self.__table:
            self.__table[x] = x
            return x
        else:
            a = x
            ul = []
            while a != self.__table[a]:
                ul.append(a)
                a = self.__table[a]
            for u in ul:
                self.__table[u] = a

        return self.__table[x]

    def same(self, x, y):
        return self.__root(x) == self.__root(y)

    def union(self, x, y):
        x = self.__root(x)
        y = self.__root(y)
        if x == y:
            return False

        if self.__rank[x] < self.__rank[y]:
            self.__table[x] = y
            self.__size[y] += self.__size[x]
        else:
            self.__table[y] = x
            self.__size[x] += self.__size[y]
            if self.__rank[x] == self.__rank[y]:
                self.__rank[x] += 1
        return True

    def size(self, x):
        return self.__size[self.__root(x)]

    def num_of_group(self):
        g = 0
        for k, v in self.__table.items():
            if k == v:
                g += 1
        return g



@mt
def slv(N, M, AB):
    uf = UnionFind()
    for i in range(1, N+1):
        uf.union(i, i)
    for a, b in AB:
        uf.union(a, b)

    return uf.num_of_group() - 1


def main():
    N, M = read_int_n()
    AB = [read_int_n() for _ in range(M)]
    print(slv(N, M, AB))


if __name__ == '__main__':
    main()


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

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    int ans = 0;
    bool div_by_2 = 2;
    while(div_by_2){
        for(int i=0;i<N;i++){ 
            if(a[i]%2 == 1){
                div_by_2 = false;
                break;
            }else{
                a[i] /= 2;
            }
        }
         //すべて2で割り切れる
        if(div_by_2) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define int ll
#define REP(i,n) for (int i = 0; i < (n); ++i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'

const int MOD = (int)1e9 + 7;

signed main() {
    int A, B;

    cin >> A >> B;

    if (A % 2 == 0) {
        int cnt = B - A + 1;
        int r = cnt % 4;
        if (r == 0) {
            cout << 0 << endl;
        } else if (r == 1) {
            cout << B << endl;
        } else if (r == 2) {
            cout << 1 << endl;
        } else {
            cout << (1 ^ B) << endl;
        }

        return 0;
    } else {
        // A が残る
        int cnt = B - A + 1 - 1;
        int r = cnt % 4;
        if (r == 0) {
            cout << A << endl;
        } else if (r == 1) {
            cout << (A ^ B) << endl;
        } else if (r == 2) {
            cout << (A ^ 1) << endl;
        } else {
            cout << ((A ^ 1) ^ B) << endl;
        }

        return 0;
    }



}


Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
// clang-format on

int M, K;

int main(void)
{
  cin >> M >> K;
  if (K >= (int)pow(2, M)) {
    cout << -1 << endl;
    return 0;
  }

  if (M == 0) {
    cout << "0 0" << endl;
  }
  else if (M == 1 && K == 1) {
    cout << -1 << endl;
  }
  else if (M == 1 && K == 0) {
    cout << 0 << " " << 0 << " " << 1 << " " << 1 << endl;
  }
  else if (M >= 2) {
    vector<int> b;
    for (int i = 0; i < (1 << (M)); i++) {
      if (i == K) continue;
      b.push_back(i);
    }
    vector<int> c = b;
    reverse(c.begin(), c.end());
    int si = b.size();
    for (int i = 0; i < si; i++) {
      cout << b[i] << " ";
    }
    cout << K << " ";
    for (int i = 0; i < si; i++) {
      cout << c[i] << " ";
    }
    cout << K << endl;
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 2936
x=int(input())
t=1
#a=[11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79]
for i in range(1,10):
  for k in range(1,i+1):
    if k*i==x:
      print('Yes')
      t=0
      break
  if t==0:break
else:print('No')

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

int main(){
    int n, m;
    cin >> n;
    map<ll, int> d;
    ll k = 0;
    for(int i = 0; i < n; i++){
        cin >> k;
        auto itr = d.find(k);
        if(itr == d.end()){
            d.insert(make_pair(k, 1));
        }else{
            d[k]++;
        }
    }

    cin >> m;
    ll t[m];
    for(int i = 0; i < m; i++){
        cin >> t[i];
    }

    int flag = 0;
    for(int i = 0; i < m; i++){
        auto itr = d.find(t[i]);
        if(itr == d.end()){
            flag = 1;
            break;
        }else{
            if(d[t[i]] == 1){
                d.erase(t[i]);
            }else{
                d[t[i]]--;
            }
        }
    }

    if(flag == 1){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
}

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

namespace _1_9_C_2
{
    class Program
    {
        static void Main(string[] args)
        {
            Player taro = new Player();
            Player hanako = new Player();
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                string[] word = Console.ReadLine().Split(' ');
                taro.pointsList.Add(taro.GetPoint(word,3,0));
                hanako.pointsList.Add(hanako.GetPoint(word,0,3));
            }
            Console.WriteLine("{0} {1}", taro.pointsList.Sum(), hanako.pointsList.Sum());
        }
    }
    class Player
    {
        internal List<int> pointsList = new List<int>();
        internal int GetPoint(string[] word,int leftWinPoint,int rightWinPoint)
        {
            if (word[0].CompareTo(word[1]) > 0)
            {
                return leftWinPoint;
            }
            else if(word[0].CompareTo(word[1]) < 0)
            {
                return rightWinPoint;
            }
            else
            {
                return 1;
            }
        }
    }
}



Measured memory_bytes: 16988
/** https://atcoder.jp/contests/dp/tasks/dp_s */
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
string K;
vector<int> k;
int d;
int f[10003][103][3];
const int MOD = 1e9 + 7;

int main()
{
    cin >> K >> d;

    for(int i = 0; i<(int)K.size(); i++)
        k.push_back(K[i] - '0');

    for(int i = 0; i< 10001; i++)
    for(int j = 0; j< 101; j++)
    for(int k = 0; k< 3; k++) f[i][j][k] = 0;

    for(int x = 1; x< 10; x++)
    {
        int st = (x < k[0] ? 0 : (x == k[0] ? 1 : 2 ));
        f[1][x%d][st]++;
    }

    for(int i = 1; i< k.size(); i++)
    for(int r = 0; r < d; r++)
    for(int st = 0; st < 3; st++)
    {
        if (f[i][r][st] == 0) continue;
        for(int x = 0; x < 10; x++)
        {
            int newst = st;
            if (st == 1)
                newst = (x < k[i] ? 0 : (x == k[i] ? 1 : 2 ));
            int newr = (r + x)%d;
            (f[i+1][newr][newst] += f[i][r][st])%= MOD;
        }
    }
    long long ans = 0;
    for(int i = 0; i< K.size(); i++) (ans+= f[i][0][0]+f[i][0][1]+f[i][0][2])%=MOD;
    cout << (ans+= f[K.size()][0][0]+ f[K.size()][0][1])%MOD;
    return 0;
}



Measured memory_bytes: 12416
from collections import deque,defaultdict as dd 
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]

def bo(i):
    return ord(i)-ord('a')



n=ii()
a=li()
x=0
for i in a:
    x^=i
    
ans=[]
for i in range(n):
    ans.append(x^a[i])
print(*ans)




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

int main(){
  int n, m, a, b, x[50] = {};
  cin >> n >> m;
  rep(i, m) {
    cin >> a >> b;
    x[a - 1]++;
    x[b - 1]++;
  }
  rep(i, n) cout << x[i] << endl;    
}

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

int main()
{
	int N;
	cin>>N;
	bool check=0;
	for(int a=0;a<=N;a+=4)
	{
		int tmp=N-a;
		if(tmp%7==0) check=1;
	}
	if(check)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
p = [True] * 100010
p[0] = p[1] = False
for i in range(2, 100000):
    if p[i] == True:
        for j in range(2 * i, 100000, i):
            p[j] = False

n = int(input())
a = []
i = 6
while len(a) < n:
    if p[i]:
        a.append(i)
    i += 5

for i in a:
    print(i, end = " ")

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define rep(i,i0,n) for(int i=i0;i<n;++i)
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define INF12 1000000000000 //10^12
#define INF9 1000000000 //10^9
#define MOD 10000007 //10^9+7

ll N, K;

int main() {
    cin >> N >> K;
    ll tmp = N / K;
    ll ans = min(N - tmp*K, (tmp+1)*K - N); 

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n, c, k = map(int, input().split())
t_lst = [int(input()) for _ in range(n)]
t_lst.sort()
ans = 0
cnt = 0
last = 0
if c == 1:
    print(n)
    exit()
for t in t_lst:
    if t > last:
        ans += 1
        last = t + k
        cnt = 1
    else:
        cnt += 1
        if cnt == c:
            last = 0
            cnt = 0
print(ans)

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

int A, B, C, D, E, F;
int main(){
    cin >> A >> B >> C >> D >> E >> F;
    int water, sugar, total;
    water = 0;
    sugar = 0;
    for(int a=0; 100*A*a<=F; a++){
        for(int b=0; 100*A*a+100*B*b<=F; b++){
            for(int c=0; 100*A*a+100*B*b+C*c<=F; c++){
                for(int d=0; 100*A*a+100*B*b+C*c+D*d<=F; d++){
                    total = 100*A*a+100*B*b+C*c+D*d;
                    if(((C*c+D*d)<=E*(A*a+B*b)) && (total*sugar<=(C*c+D*d)*(water+sugar))){
                        water = 100*(A*a + B*b);
                        sugar = C*c + D*d;
                    }
                }
            }
        }
    }
    cout << water+sugar << " " << sugar << endl;
}


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

#define MAX 100000
#define NIL -1

typedef struct
{
  int parent;
  int left;
  int right;
}Node;

Node T[MAX];
int D[MAX];
int n;

void print(int u)
{
  int i, c;

  printf("node %d: parent = %d, depth = %d, ", u, T[u].parent, D[u]);

  if(T[u].parent == NIL) printf("root, ");
  else if(T[u].left == NIL) printf("leaf, ");
  else  printf("internal node, ");

  printf("[");
  for(i = 0, c = T[u].left; c != NIL; i++, c = T[c].right){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
}

int depth(int u, int p)
{
  D[u] = p;

  if(T[u].right != NIL) depth(T[u].right, p);
  if(T[u].left != NIL)  depth(T[u].left, p + 1);
}

int main(void)
{
  int a, b, c, l, r, i, j;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    T[i].parent = NIL;
    T[i].left = NIL;
    T[i].right = NIL;
  }

  for(i = 0; i < n; i++){
    scanf("%d %d", &a, &b);
    for(j = 0; j < b; j++){
      scanf("%d", &c);
      if(j == 0){
        T[a].left = c;
      }
      else{
        T[l].right = c;
      }
        l = c;
        T[c].parent = a;
    }
  }
  for(i = 0; i < n; i++){
    if(T[i].parent == NIL){
      r = i;
    }
  }

  depth(r, 0);

  for(i = 0; i < n; i++){
    print(i);
  }
  return 0;
}



Measured memory_bytes: 6420
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"

#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0);}

#define SHOW(x) std::cout << #x << " = " << x << std::endl;

inline int safe_mul(int x, int y) __attribute__ ((warn_unused_result));

int main()
{
//    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false);

    int n, a,b;
    cin >> n >> a >> b;
    vector<int> arr(n);

    for(int& x : arr)
        cin >> x;


    int r = 1000000005;
    int l = 0;

    while (r - l > 1)
    {
        int mid = (l + r) >> 1;

        long long cnt = 0;
        for(int i = 0; i < n; ++i)
            cnt += max(0LL, (arr[i] - b * 1LL * mid + a - b - 1) / (a - b));
        if (cnt <= mid)
            r = mid;
        else
            l = mid;
    }
    cout << r << endl;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */


struct UnionFind{
    vector<int> parent, rank;
    UnionFind(int n) : parent(n, -1), rank(n, 0) { }
    int find(int x){
        if(parent[x] == -1) return x;
        else return (parent[x] = find(parent[x]));
    }
    bool unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(rank[x] < rank[y])
            parent[x] = y;
        else
            parent[y] = x;
        if(rank[x] == rank[y]) rank[x]++;
        return true;
    }
    bool same(int x, int y){
        return find(x) == find(y);
    }
};

template<class Type>
Type solve(Type res = Type()){
    int N,Q; cin >> N >> Q;
    UnionFind UF(N);
    while(Q--){
        int com,u,v; cin >> com >> u >> v;
        if(com == 0){
            UF.unite(u,v);
        }else{
            cout << UF.same(u,v) << endl;
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    solve<ll>(0);
    // cout << fixed << setprecision(12) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 4600
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
    string[] input = Console.ReadLine().Split(' ');
    int h = int.Parse(input[0]);//行の長さ
    int w = int.Parse(input[1]);//列の長さ
    long[,] matrix = new long[h,w];//行列
    long answer = 0;
    
    for(int i = 0; i < h; i++)//それぞれの行
    {
  	  long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
  	  for(int j = 0; j < w; j++) matrix[i,j] = nums[j];//行の全ての成分
    }

    for(int i = 0; i < h; i++)
    {
      for(int j = i+1; j < h; j++)
      {
        long length = 0;
        for(int k = 0; k < w; k++)
        {
          length += (matrix[i,k]-matrix[j,k])*(matrix[i,k]-matrix[j,k]);
        }
        for(long k = 0; k < 1000; k++)
        {
          if(length == k*k) answer++;
        }
      }
    }

		Console.WriteLine(answer);
	}
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define per(i,n,j) for(int i=(n)-1;i>=(j);i--)
using ll=long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF=1LL<<60;

ll n;
vector<ll> t(100100),x(100100),y(100100);

int main(){
    cin>>n;
    rep(i,0,n) cin>>t[i]>>x[i]>>y[i];

    bool flag=true;
    rep(i,0,n){
        if(t[i]<x[i]+y[i]){
            flag=false;
            break;
        }
        if(x[i]==0 && y[i]==0){
            if(t[i]%2!=0){
                flag=false;
                break;
            }
        }
        else if(t[i]%2!=(x[i]+y[i])%2){
            flag=false;
            break;
        }
        if(i>0){
            if(t[i]-t[i-1]<abs(x[i]-x[i-1])+abs(y[i]-y[i-1])){
                flag=false;
                break;
            }
        }
    }
    if(flag) cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
    return 0;
}

Measured memory_bytes: 5472
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

void move_E(int dice[7]){
    int new_dice[7];
    new_dice[2]=dice[2];
    new_dice[5]=dice[5];
    new_dice[3]=dice[1];
    new_dice[1]=dice[4];
    new_dice[4]=dice[6];
    new_dice[6]=dice[3];

    for(int i=0; i<7; i++){
        dice[i]=new_dice[i];
    } 
}

void move_W(int dice[7]){
    int new_dice[7];
    new_dice[2]=dice[2];
    new_dice[5]=dice[5];
    new_dice[1]=dice[3];
    new_dice[4]=dice[1];
    new_dice[6]=dice[4];
    new_dice[3]=dice[6];

    for(int i=0; i<7; i++){
        dice[i]=new_dice[i];
    } 
}

void move_N(int dice[7]){
    int new_dice[7];
    new_dice[3]=dice[3];
    new_dice[4]=dice[4];
    new_dice[1]=dice[2];
    new_dice[2]=dice[6];
    new_dice[6]=dice[5];
    new_dice[5]=dice[1];

    for(int i=0; i<7; i++){
        dice[i]=new_dice[i];
    } 
}

void move_S(int dice[7]){
    int new_dice[7];
    new_dice[3]=dice[3];
    new_dice[4]=dice[4];
    new_dice[2]=dice[1];
    new_dice[6]=dice[2];
    new_dice[5]=dice[6];
    new_dice[1]=dice[5];

    for(int i=0; i<7; i++){
        dice[i]=new_dice[i];
    } 
}

int main()
{
    int dice[7];
    for(int i=1; i<7; i++){
        scanf("%d", &dice[i]);
        //printf("%d ", dice[i]);
    }
    //printf("\n");

    char order[100];
    scanf("%s", order);

    for(int i=0; i<strlen(order); i++){
        switch (order[i]){
            case 'E':
                move_E(dice);         
                break;
            case 'W':
                move_W(dice);         
                break;
            case 'N':
                move_N(dice);         
                break;
            case 'S':
                move_S(dice);         
                break;
        }
        // for(int i=1; i<7; i++){
        //    printf("%d ", dice[i]);
        // }
        // printf("\n");
    }

    printf("%d\n", dice[1]);

    return 0;
}


Measured memory_bytes: 2092
use proconio::input;
use std::cmp;

const INF:i64 = 1e15 as i64;
fn main() {
    input! {
        n:usize,
        a:[i64;n],
    };

    let mut dp = vec![vec![-INF;n+1];n+1];
    dp[0][0] = 0;
    let mut pa:Vec<(usize,i64)> = a.into_iter().enumerate().map(|(i,x)|(i,x)).collect();
    pa.sort_by_key(|x|{
        -x.1
    });
    let pa = pa;
    for i in 0..n {
        let pos:i64 = pa[i].0 as i64;
        let a = pa[i].1;
        for j in 0..(i+1) {
            let l:i64 = j as i64;
            let r:i64 = (n-1-(i-j)) as i64;
            dp[i+1][j] = cmp::max(dp[i+1][j],(r-pos).abs()*a+dp[i][j]);
            dp[i+1][j+1] = cmp::max(dp[i+1][j+1],(pos-l).abs()*a+dp[i][j]);
        }
    }
    // println!("{:?}",dp);
    let res = dp[n].iter().max().unwrap();
    println!("{}",res);
}


Measured memory_bytes: 33408
#include <stdio.h>
int main()
{
  int a, b, c;
  if(scanf("%d", &a)== 1);
  if(scanf("%d", &b)== 1);

  if (a <= 9 && b <= 9)
  {
  c = a * b;
  printf("%d\n", c <= 81 ? c : -1);
  }else{
  printf("-1");

  }
  return 0;
}

Measured memory_bytes: 128
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let (a, b) = read_touple::<usize>();
    let ast = vec![format!("{}", a); b];
    let bst = vec![format!("{}", b); a];
    let a: String = ast.into_iter().collect();
    let b: String = bst.into_iter().collect();
    if a > b {
       println!("{}", b);
    } else {
      println!("{}", a);
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n,dp[3005][3005],sm[3005][3005];
string s;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>s;
    ll ans=0;
    dp[n-1][0]=1;
    sm[n-1][0]=dp[n-1][0];
    rep(i,1,n)
    	sm[n-1][i]=(sm[n-1][i-1]+dp[n-1][i])%M;
    sep(i,n-2,0)
    {
    	rep(j,0,n)
    	{
    		if(s[i]=='<')
    			dp[i][j]=(j?sm[i+1][j-1]:0);
    		else
    			dp[i][j]=(sm[i+1][n-i-2]-(j?sm[i+1][j-1]:0)+M)%M;
    	}
    	sm[i][0]=dp[i][0];
    	rep(j,1,n)
    		sm[i][j]=(sm[i][j-1]+dp[i][j])%M;
    }
    rep(i,1,n+1)
    	ans=(ans+dp[0][n-i])%M;
    cout<<ans;
}


Measured memory_bytes: 141184
num = int(input())

A = list(map(int, input().split()))
count = 0

flag = True
while flag:
        flag = False
        for j in range(num - 1, 0, -1):
                if A[j] < A[j - 1]:
                        A[j], A[j - 1] = A[j - 1], A[j]
                        count += 1
                        flag = True

tempA = map(str, A)
print(' '.join(tempA))
print(count)


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;
ll f(ll n){
    return (n*n + 4) / 8;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    ll a[55], b[55], c[55], d[55];
    cin >> N >> M;
    rep(i,0,N) cin >> a[i] >> b[i];
    rep(i,0,M) cin >> c[i] >> d[i];
    rep(i,0,N){
        ll mini = INF, idx = 0;
        rep(j,0,M){
            ll dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
            if(mini > dist){
                mini = dist;
                idx = j;
            }
        }
        print(idx+1);

    }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

const int LogN=20;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<ll> x(n);
    for(int i=0;i<n;i++) cin>>x[i];
    
    vector<vector<int>> mv(LogN,vector<int>(n));

    ll l;
    cin>>l;

    for(int i=0;i<n;i++){
        int lb=i;
        int ub=n;
        while(ub-lb>1){
            int mid=(lb+ub)/2;
            if(x[mid]-x[i]<=l) lb=mid;
            else ub=mid;
        }
        mv[0][i]=lb;
    }

    for(int i=0;i+1<LogN;i++){
        for(int j=0;j<n;j++){
            mv[i+1][j]=mv[i][mv[i][j]];
        }
    }

    auto query=[&](int a,int b){
        int d=0;
        for(int i=LogN-1;i>=0;i--){
            int to=mv[i][a];
            if(to<b){
                d+=(1<<i);
                a=mv[i][a];
            }

        }
        return d+1;
    };
    
    int q;
    cin>>q;
    for(int i=0;i<q;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        if(a>b) swap(a,b);
        cout<<query(a,b)<<"\n";
    }

    
    return 0;
}


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

namespace _1_6_d
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int n = int.Parse(s[0]);
            int m = int.Parse(s[1]);

            int[,] a = new int[n,m];
            int[] b = new int[m];

            int[] c = new int[n];

            for (int i = 0; i < n; i++)
            {
                string[] t = Console.ReadLine().Split(' ');
                for (int j = 0; j < m; j++)
                {
                   a[i,j] = int.Parse(t[j]);
                }
            }
            for (int i = 0; i < m; i++)
            {
                string r = Console.ReadLine();
                b[i] = int.Parse(r);
            }

            for (int i = 0; i < n; i++)
            {
                int f = 0;
                for (int j = 0; j < m; j++)
                {
                    int d = a[i, j];
                    int e = b[j];

                    f += d * e;
                }
                c[i] = f;
            }
            for (int i = 0; i < n; i++)
            {
                Console.WriteLine(c[i]);
            }
            //Console.WriteLine("\n");
            Console.ReadKey();
        }
    }
}



Measured memory_bytes: 18008
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main()
{
    int i, counter = 0;
    char W[11] = {0};
    char eot[] = "END_OF_TEXT";
    
    scanf("%s", W);
    
    while(1){
        char T[1001] = {0};
        
        scanf("%s", T);
        if(strstr(T, eot)) break;
        for(i=0; T[i]!='\0'; i++){
            if(isupper(T[i])) T[i] = tolower(T[i]);
        }
        if(strstr(T, W) && strlen(T) == strlen(W)) counter++;
    }
    
    printf("%d\n", counter);
    
    return 0;
}

Measured memory_bytes: 552