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

/*
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#include <set>
*/

using namespace std;

typedef long long LL;
typedef double DB;
typedef unsigned int UI;
typedef pair<int, int> PII;

const int inf = 0x7f7f7f7f;

#define rdi() read<int>()
#define rdl() read<LL>()
#define rds(a) scanf("%s", a)
#define mk(i, j) make_pair(i, j)
#define pb push_back
#define fi first
#define se second
#define For(i, j, k) for (int i = j; i <= k; i ++)
#define Rep(i, j, k) for (int i = j; i >= k; i --)
#define Edge(i, u) for (int i = head[u]; i; i = e[i].nxt)

template<typename t> t read() {
	t x = 0; int f = 1; char c = getchar();
	while (c > '9' || c < '0') f = c == '-' ? -1 : 1 , c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - 48 , c = getchar();
	return x * f;
}

template<typename t> void write(t x) {
	if (x < 0){
		putchar('-'), write(-x);
		return;
	}
	if (x >= 10) write(x / 10);
	putchar(x % 10 + 48);
}

const int P = 1e9 + 7;
const int N = 1e5 + 10;
int fac[N], facinv[N], a[N], n, pos, vis[N], id;

int power(int a, int b) {
	int c = 1;
	for (; b; b >>= 1, a = 1ll * a * a % P) if (b & 1) c = 1ll * c * a % P;
	return c;
}

int C(int x, int y) {
	return 1ll * fac[x] * facinv[y] % P * facinv[x - y] % P;
}

int main() {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = rdi() + 1;
	for (int i = 1; i <= n; i ++) a[i] = rdi();
	fac[0] = fac[1] = 1;
	for (int i = 2; i <= n; i ++) fac[i] = 1ll * fac[i - 1] * i % P;
	facinv[n] = power(fac[n], P - 2);
	for (int i = n - 1; i >= 0; i --) facinv[i] = 1ll * facinv[i + 1] * (i + 1) % P;
	for (int i = 1; i <= n; i ++) {
		if (vis[a[i]]) {
			pos = i;
			id = a[i];
			break;
		}
		vis[a[i]] = i;
	}
	int len = n - pos + 1;
	for (int i = 1; i <= n; i ++) {
		int ans = C(n, i); 
//		if (i <= len) {
//			ans -= C(len - 1, i - 1);
//			ans = (ans + P) % P;
//		}
		if (i - 1 <= len - 1 + vis[id] - 1) ans -= C(len - 1 + vis[id] - 1, i - 1);
		ans = (ans + P) % P;
		write(ans), putchar(10);
	} 
	return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
struct revran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { --i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr revran(const i64 e) noexcept: b(0), e(e) {}
  constexpr revran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(e - 1); }
  constexpr iter end() const noexcept { return iter(b - 1); }
};

struct ran {
  const i64 b, e;
  struct iter {
    i64 i;
    constexpr iter(const i64 i) noexcept: i(i) {}
    void operator++() noexcept { ++i; }
    constexpr i64 operator*() const noexcept { return i; }
    constexpr bool operator!=(const iter x) const noexcept { return i != x.i; }
  };
  constexpr ran(const i64 e) noexcept: b(0), e(e) {}
  constexpr ran(const i64 b, const i64 e) noexcept: b(b), e(e) {}
  constexpr iter begin() const noexcept { return iter(b); }
  constexpr iter end() const noexcept { return iter(e); }
  constexpr revran rev() const noexcept { return revran(b, e); }
};

constexpr ran rn0(const i64 e) noexcept { return ran(e); }
constexpr ran rn0(const i64 b, const i64 e) noexcept { return ran(b, e); }
constexpr ran rn1(const i64 e) noexcept { return ran(1, e + 1); }
constexpr ran rn1(const i64 b, const i64 e) noexcept { return ran(b, e + 1); }

int main() {
  i64 r,d,x;
  cin >> r >> d >> x;
  for(int i = 1;i <= 10;i++) {
    x = r * x - d;
    cout << x << endl;
  }
}


Measured memory_bytes: 256
def solve():
    from collections import deque
    
    while True:
        w, h = map(lambda x: int(x)+2, input().split())
        if w == 2:
            break

        result = 0
        a = ['0']*w
        for _ in [0]*(h-2):
            a += ['0'] + input().split() + ['0']
        a += ['0']*w

        for i in range(w*h):
            if a[i] != '1':
                continue
            a[i] = '0'
            result += 1
            dq = deque([i])
            while dq:
                j = dq.popleft()
                for dest in (j-w-1, j-w, j-w+1, j-1, j+1, j+w-1, j+w, j+w+1):
                    if a[dest] == '1':
                        a[dest] = '0'
                        dq.append(dest)
        print(result)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 6032
#include <stdio.h>

int main(void){
	int S,h,m,s;
	scanf("%d",&S);
	h = S/3600;
	m = (S%3600)/60;
	s = (S%3600)%60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 1020
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#define INT long long int
#define Mod 1000000007
using namespace std;

int main(){
    INT a, b=1, c=1, d = 1,i;
    cin >> a;
    for(i=0;i<a;i++) b = (b*10)%Mod;
    for(i=0;i<a;i++) c = (c*9)%Mod;
    for(i=0;i<a;i++) d = (d*8)%Mod;
    cout << (b - c -c +d+Mod+Mod)%Mod << endl;
}


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

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

    int h, w;
    while(1){
        cin >> h >> w;
        if (h == 0 && w == 0) break;
        rep(i, w) cout << "#";
        cout << endl;
        rrep(i, h - 2){
            cout << '#';
            rrep(j, w - 2){
                cout << '.';
            }
            cout << '#' << endl;
        }
        rep(i, w) cout << "#";
        cout << endl;
        cout << endl;
    }


    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
map <int,int>frq;
int n;

int main()
{
    cin>>n;
    while (n--)
    {
        int u;
        cin>>u;
        frq[u]++;
    }
    bool dis = true;

    for (auto  it = frq.begin(); it != frq.end(); it++)
    {
        if ((*it).second>1)
        {
            dis = false;
        }
        
    }

    if (dis)
    {
        cout<<"YES"<<endl;
    }else
    {
        cout<<"NO"<<endl;
    }
    
    
    

    return 0;
}

Measured memory_bytes: 9600
#147c
N = int(input())

xy_list = [["*"]]

for i in range(N):
    A = int(input())
    i_xy = [("*","*")] #A=0に備えて、無効なのを追加
    for j in range(A):
        x,y = map(int, input().split())
        i_xy.append((x,y))
    xy_list.append(i_xy)
    
#N<=15　なので、2**15 = 32768　間に合う。

#正直・不親切をbitで仮定。正直者の証言で矛盾しているものないかを調べる。
ans = [0]

for i in range(2**(N)):
    bit_array = str(bin(i)[2:]).zfill((N))
    #print("#############")
    #print(bit_array)
    
    break_flag = 0
    honest = 0
    
    for j in range(len(bit_array)): #生成したbit_aray内で正直者を探す。    
        #print(bit_array[j])
        
        if bit_array[j] == "1":
            #print("person ",j+1," said,")
            for xy in xy_list[j+1]:
                x = xy[0]
                y = xy[1]
                if x != "*" and y != "*":
                    x = int(x)
                    y = int(y)
                    #print("person ",x," is ",y)
                    
                    if int(bit_array[x-1]) != y:
                        #print("Contradiction!")
                        honest = 0
                        break_flag = 1
                        break
            else:
                honest += 1
                
        if break_flag == 1:
            break
            
    #print("honest:",honest) 
    ans.append(honest)
    
print(max(ans))

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

using namespace std;

#define ll long long
const int mxN=1e5;

int main() {
//#ifndef ONLINE_JUGDE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif

	ios::sync_with_stdio(0);
    cin.tie(0);
    
	string s;
	cin>>s;
	int cnt=0,ans=0;
	for(int i=0;i<(int)s.size();i++){
		if(s[i]=='R'){
			cnt++;
			ans=max(ans,cnt);
		}
		else
			cnt=0;
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 3636
import math
n, m = map(int, input().split())
p = 10**9 + 7



nf = math.factorial(n) % p
mf = math.factorial(m) % p

if abs(n-m) > 1:
  ans = 0

elif n == m:
  ans = nf * mf * 2
  
else:
  ans = nf * mf
  
print(ans % p)

Measured memory_bytes: 10008
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

ll N,M;
vl A,S;

ll people(ll i,ll x){//それぞれの片手をとってる
    ll over=N,nover=-1;
    while(abs(over-nover)>1){
        ll mid=(over+nover)/2;
        if(A[i]+A[mid]>=x){
            over=mid;
        }
        else{
            nover=mid;
        }
    }
    return nover+1;
}

ll number(ll x){//midを超える組の数
    ll res=0;
    rep(i,N){
        res+=people(i,x);//片手を固定している
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> M;
    A.resize(N);
    rep(i,N){
        cin >> A[i];
    }
  	sort(A.begin(),A.end());
    S.assign(N+1,0);
    S[0]=0;
    rep(i,N){
        S[i+1]=S[i]+A[i];
    }
    ll OVER=INF,NOVER=0;
    while(abs(OVER-NOVER)>1){
        ll mid=(OVER+NOVER)/2;
        if(number(mid)<=N*N-M){//midを超える組の数
            NOVER=mid;
        }
        else{
            OVER=mid;
        }
    }
    //cout << NOVER << endl;//サンプル1で67,ダブり拾うので訂正
    ll cnt=0;
    rep(i,N){
        ll ok=N,ng=-1;
        while(abs(ok-ng)>1){
            ll mid=(ok+ng)/2;
            if(A[i]+A[mid]>=NOVER){
                ok=mid;
            }
            else{
                ng=mid;
            }
        }
        cnt+=N-ok;
    }
    ll ans=NOVER*(M-cnt);
    rep(i,N){//それぞれの片手について調べる
        ll big=N,small=-1;
        while(abs(big-small)>1){
            ll mid=(big+small)/2;
            if(A[mid]+A[i]>=NOVER){
                big=mid;
            }
            else{
                small=mid;
            }
        }
        //cout << big << endl;
        ans+=S[N]-S[big];//他からとる
        ans+=A[i]*(N-big);//A[i]からとる
        //cout << ans << endl;
    }
    cout << ans << endl;
}


Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
const int N=1005;
map<pair<int,int> ,int> Map;
int Ans[200005],ne[N],tot,m,n,x,y,f[N][N],Min[N],Max[N],flag[N],fi[N],zz[N];
vector<int> G[N];
void jb(int x,int y){
	ne[++tot]=fi[x];
	fi[x]=tot;
	zz[tot]=y;
}
void dfs(int x){
	flag[x]=1;
	for (int i=0;i<(int)G[x].size();i++)
		if (!flag[G[x][i]])dfs(G[x][i]);
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		G[x].push_back(y);
		Map[mp(x,y)]=i;
	}
	for (int i=1;i<=n;i++){
		memset(flag,0,sizeof flag);
		dfs(i);
		for (int j=1;j<=n;j++)f[i][j]=flag[j];
	}
	for (int i=1;i<=n;i++){
		memset(Min,-1,sizeof Min);
		memset(Max,-1,sizeof Max);
		memset(flag,0,sizeof flag);
		flag[i]=1;
		for (int j=0;j<G[i].size();j++)
			if (!flag[G[i][j]]){
				dfs(G[i][j]);
				for (int k=1;k<=n;k++)
					if (Min[k]==-1&&flag[k])Min[k]=j;
			}
		memset(flag,0,sizeof flag);
		flag[i]=1;
		for (int j=G[i].size()-1;j>=0;j--)
			if (!flag[G[i][j]]){
				dfs(G[i][j]);
				for (int k=1;k<=n;k++)
					if (Max[k]==-1&&flag[k])Max[k]=j;
			}
		for (int j=0;j<G[i].size();j++)
			if ((Max[G[i][j]]!=j||Min[G[i][j]]!=j)^f[G[i][j]][i])
				Ans[Map[mp(i,G[i][j])]]=1;
	}
	for (int i=1;i<=m;i++)
		if (!Ans[i])puts("same");
		else puts("diff");
	return 0;
}


Measured memory_bytes: 20096
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int) N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=(int) n;i--)
#define p(s) cout<<(s)<<endl
#define DEBUG(x,y) cout<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl;
#define CK(n,a,b) ((a)<=(n)&&(n)<(b))
#define F first
#define S second
typedef long long ll;
using namespace std;
const int inf=1e9;

queue<int> A[310];
int cnt[310];
bool used[310];
int main(){
	int N,M;
	int ans=500;
	cin>>N>>M;
	REP(i,0,N){
		REP(j,0,M){
			int a;
			cin>>a;
			A[i].push(a);
		}
	}
	REP(k,0,M){
		int mx=0;
		int num=0;
		REP(i,0,M) cnt[i]=0;
		REP(i,0,N){
			while(used[A[i].front()])A[i].pop();
			cnt[A[i].front()]++;
			if(mx<cnt[A[i].front()]){
				mx=cnt[A[i].front()];
				num=A[i].front();
			}
		}
		used[num]=true;
		ans=min(ans,mx);
	}
	p(ans);
	return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
#include <string.h>
char *reverse(char *s){
	int i,tmp;
	for(i=0; i<strlen(s)/2; i++){
		tmp = s[i];
		s[i] = s[strlen(s)-1-i];
		s[strlen(s)-1-i] = tmp;
	}
	return s;
}
int main(){
	char str[21];

	scanf("%s",str);
	printf("%s\n",reverse(str));

	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
 
const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

ll n, m;
ll x[100000], y[100000];
vector<ll> e[100000];
ll len[100000];

void dfs(int v) {
    if (len[v] != -1) return;
    ll val = 0;
    rep(i,e[v].size()) {
        dfs(e[v][i]);
        val = max(val, len[e[v][i]]+1);
    }
    len[v] = val;
}

int main() {
    cin >> n >> m;
    rep(i,m) cin >> x[i] >> y[i];
    rep(i,m) {
        x[i]--; y[i]--;
        e[x[i]].push_back(y[i]);
    }
    memset(len, -1, sizeof(len));
    ll ans = 0;
    rep(i,n) {
        dfs(i);
    }
    rep(i,n) ans = max(ans, len[i]);
    cout << ans << endl;
}



Measured memory_bytes: 10112
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		int N = in.nextInt();
		
		if(N%7==0 || N%4==0) {
			System.out.println("Yes");
			System.exit(0);
		}
		int x = N / 7;
		int y;
		for(int i=0; i<=x; i++) {
			y = N - 7*i;
			if(y%4==0) {
				System.out.println("Yes");
				System.exit(0);
			}
		}
		System.out.println("No");
		in.close();
	}
}

Measured memory_bytes: 21972
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    long N,K;
    private static Scanner sc;
    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            N = sc.nextLong();
            K = sc.nextLong();
            if (K %2 == 1) {
                long hoge = N/K;
                System.out.println((long) Math.pow(hoge, 3));
            } else {
                long hoge = N/K;
                long huga = (N+(K/2))/K;
                System.out.println((long) (Math.pow(hoge,3)+ Math.pow(huga, 3)));
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#include <boost/math/constants/constants.hpp>
using namespace std;
typedef long long ll;
long double e = boost::math::constants::e<long double>();
long double pi = boost::math::constants::pi<long double>();
// 条件を見落としていませんか？
int main () {
    ll X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<ll> p(A), q(B), r(C);
    for (int i = 0; i < A; i++) cin >> p[i];
    for (int i = 0; i < B; i++) cin >> q[i];
    for (int i = 0; i < C; i++) cin >> r[i];
    sort(p.begin(), p.end());
    sort(q.begin(), q.end());
    sort(r.begin(), r.end());
    priority_queue<int> que;
    for (int i = A-1; i >= A-X; i--) {
        que.push(-p[i]);
    }
    for (int i = B-1; i >= B-Y; i--) {
        que.push(-q[i]);
    }
    while (r.size()) {
        int t = -que.top();
        if (r.back() > t) {
            que.pop();
            que.push(-r.back());
            r.pop_back();
        }
        else {
            break;
        }
    }
    ll ans = 0;
    while (que.size()) {
        ans -= que.top();
        que.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 3704
n,m=map(int,input().split())
ab=[]
c=[]
for _ in range(m):
  ab.append(list(map(int,input().split())))
  c.append(list(map(int,input().split())))
dp={'0'*n:0}
for i in range(m):
  a,b=ab[i]
  ci=c[i]
  dptmp={}
  for k,v in dp.items():
    s=list(k)
    for cii in ci:
      s[cii-1]='1'
    t=''.join(s)
    dptmp[t]=min(v+a,dp[t] if t in dp else float('inf'),dptmp[t] if t in dptmp else float('inf'))
  dp.update(dptmp)

t='1'*n
if t in dp:
  print(dp[t])
else:
  print(-1)
#print(dp)

Measured memory_bytes: 87176
#include "bits/stdc++.h"
#define rep(i,a,n) for(int (i) = (a);(i) < (n);(i)++)

using namespace std;

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

int main(){
	
	int h,w,memo,ans = 0;
	cin >> h >> w;
	
	memo = gcd(h,w);
	
	ans = 1 + h;
	
	ans += w - memo;
	
	cout << ans << endl;
	
	
	
	
	return 0;
}


Measured memory_bytes: 3112
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

class Main {
        public static void main(String args[]) {
                Scanner sc = new Scanner(System.in);
                String S = sc.next();
                String regex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.{6})";
                Pattern p = Pattern.compile(regex);
                Matcher m = p.matcher(S);

                if (m.find()) {
                        System.out.println("VALID");
                } else {
                        System.out.println("INVALID");
                }
        }
}

Measured memory_bytes: 26296
#include<iostream>
#include<algorithm>
#include <string>
#include<cstdio>
#include<vector>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define D(n,retu) REP(i,n)(cin>>retu[i])
#define MAX 922337203685477580
using namespace std;
typedef long long ll;

int main() {
	ll n, m, a[100000] = { 0 }, b, c, retu[100000] = { 0 }; cin >> n;
	D(n, a); bool flag = false;
	retu[1] = 1; ll now=1;
	REP(i, n) {
		now = a[now-1];
		if (now == 2) { cout << i + 1 << endl; flag = true; break; }
	}
	if (!flag) {
		cout << "-1" << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
        int a,b,c,i;
        int j=0;
        scanf("%d %d %d",&a,&b,&c);
        for(i=a;i<=b;i++){
                if(c%i==0)
                        j++;
        }
        printf("%d\n",j);
        return 0;
}


Measured memory_bytes: 2100
using System;
using System.Collections.Generic;

class Program
{
    private const string UPPERCASE = "A";
    private const string LOWERCASE = "a";
    public static void Main(string[] args)
    {
        Program pg = new Program();
        pg.Exe();
    }

    public void Exe()
    {
        string input = Console.ReadLine();
        char inchar = input[0];
        int i = (int)inchar;

        string ans = i > 96 ? LOWERCASE : UPPERCASE;
        Console.WriteLine(ans);
    }
}



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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return res;
}

ll dp[3005][3005];

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

	dp[1][1] = 1;
	for (int i = 0; i < n - 1; i++) {
		if (s[i] == '<') {
			for (int j = 2; j <= i + 2; j++) {
				dp[i + 2][j] = (dp[i + 1][j - 1] + dp[i + 2][j - 1]) % MOD;
			}
		} else {
			for (int j = i + 1; j >= 1; j--) {
				dp[i + 2][j] = (dp[i + 1][j] + dp[i + 2][j + 1]) % MOD;
			}
		}
	}

	ll ans = 0;
	for (int i = 1; i <= n; i++) (ans += dp[n][i]) %= MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 69120
import java.util.*;

public class Main{
  public static int N;
  public static String[] strs;
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    N = Integer.parseInt(sc.nextLine());
    strs = new String[N];
    List<String> list = new ArrayList<>();
    for(int i = 0; i < N; i++){
      strs[i] = sc.nextLine();
      list.add(strs[i]);
    }
    Collections.sort(list);
    List<Integer> list2 = new ArrayList<>();
    String str = "";
    int a = 0;
    for(int i = 0; i < N; i++){
      String[] S = list.get(i).split(" ");
      int n = Integer.parseInt(S[1]);
      if(i == 0){
        str = S[0];
        list2.add(n);
      }else{
        if(str.equals(S[0])){
          list2.add(n);
          
        }else{
          a = list2.size();
          Collections.sort(list2, Collections.reverseOrder());
          for(int j = 0; j < a; j++){
            func(str, list2.get(j));
          }
          str = S[0];
          list2.add(n);
        }
      }
    }
    a = list2.size();
    Collections.sort(list2, Collections.reverseOrder());
    for(int j = 0; j < a; j++){
      func(str, list2.get(j));
    }
  }
  public static void func(String s, int n){
    s = s + " " + n;
    
    for(int i = 0; i < N; i++){
      if(strs[i].equals(s)){
        System.out.println(i + 1);
      }
    }
  }
}

Measured memory_bytes: 21076
#define rep(i,n) for(i=0;i<(n);i++)
#define min(a,b) ((a)<(b)?(a):(b))
#define inf (1<<20)
int w,h,f,m,o;
int c[10][10],dp[11][10][51][10][10];

int main(){
	int i,j,k,l,r,range,it,x;
  while(scanf("%d%d",&w,&h),w){
	  scanf("%d%d%d",&f,&m,&o);
    rep(i,h)rep(j,w)scanf("%d",&c[i][j]);
    
    rep(i,h+1)rep(j,w)rep(k,m+1)rep(l,w)rep(r,w)dp[i][j][k][l][r]=inf;
    rep(i,w)dp[0][i][o][i][i]=0;
    
    rep(i,h)rep(range,w)for(k=m;k>1;k--)
    rep(it,2)rep(l,w-range)rep(x,range+1){
      int r=l+range,j=it?l+x:r-x,cost=dp[i][j][k][l][r];
      if(cost==inf)continue;
      
      if(c[i][j]>0){
        int sanso=min(m,k-1+c[i][j]);
        dp[i+1][j][sanso][j][j]=min(dp[i+1][j][sanso][j][j],cost);
      }
      else{
        dp[i+1][j][k-1][j][j]=min(dp[i+1][j][k-1][j][j],cost-c[i][j]);
      }
      if(i==0)continue;
      if(j>0){
        if(l<j)dp[i][j-1][k-1][l][r]=min(dp[i][j-1][k-1][l][r],cost);
        else{
          if(c[i-1][j-1]>0){
            int sanso=min(m,k-1+c[i-1][j-1]);
            dp[i][j-1][sanso][l-1][r]=min(dp[i][j-1][sanso][l-1][r],cost);
          }
          else{
            dp[i][j-1][k-1][l-1][r]=
            min(dp[i][j-1][k-1][l-1][r],cost-c[i-1][j-1]);
          }
        }
      }
      if(j<w-1){
        if(j<r)dp[i][j+1][k-1][l][r]=min(dp[i][j+1][k-1][l][r],cost);
        else{
          if(c[i-1][j+1]>0){
            int sanso=min(m,k-1+c[i-1][j+1]);
            dp[i][j+1][sanso][l][r+1]=min(dp[i][j+1][sanso][l][r+1],cost);
          }
          else{
            dp[i][j+1][k-1][l][r+1]=
            min(dp[i][j+1][k-1][l][r+1],cost-c[i-1][j+1]);
          }
        }
      }
    }
	{
		int ans=inf;
		rep(i,w)for(j=1;j<=m;j++)rep(l,w)rep(r,w)ans=min(ans,dp[h][i][j][l][r]);
		if(ans>f)puts("NA");
		else printf("%d\n",ans);
	}
  }
  return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int main()
{
  double a,b,c,d,e,f,x,y;
  while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF){
    x=(c*e-b*f)/(a*e-b*d);
    y=(-d*c+a*f)/(a*e-b*d);
    x = (double)((int)(x * 10000)/10)/1000;
    y = (double)((int)(y * 10000)/10)/1000;
    printf("%.3f %.3f\n",x,y);
  }
  return 0;
}

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

int main(){
  int n,count=0;
  double d;
  double x[10000000];
  double y[10000000];
  cin>>n>>d;
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i];
  }
  for(int i=0;i<n;i++){
    if(d>=sqrt(x[i]*x[i]+y[i]*y[i]))count++;
  }
  cout<<count<<endl;
}


Measured memory_bytes: 6972
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let mut d = 0;
    for i in n.to_string().chars() {
        d+= i.to_digit(10).unwrap() as usize;
    }
    println!("{}", if n % d == 0 {"Yes"} else {"No"});
}

Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
#define INF int(1e9)

template<class T,class U> ostream& operator<<(ostream& ost, const pair<T,U> &p) { ost << "(" << p.first << ", " << p.second << ")"; return ost; }
#define ostream_container { ost << "{"; for(const auto &t : v) { if (&t != &*v.begin()) ost << ", "; ost << t; } ost << "}"; return ost; }
template<class T> ostream& operator<<(ostream &ost, const vector<T> &v) ostream_container
template<class T> ostream& operator<<(ostream &ost, const set<T> &v) ostream_container
template<class T,class U> ostream& operator<<(ostream &ost, const map<T,U> &v) ostream_container

template<class H> void recursive_debug(string s, H h) {
    cerr << "\033[33m" << s << " = " << h << endl << "\033[m";
}
template<class H,class... T> void recursive_debug(string s, H h, T... t) {
    int comma = s.find(',');
    cerr << "\033[33m" << s.substr(0,comma) << " = " << h << ", ";
    recursive_debug(s.substr(comma+1), t...);
}
#define debug(...) recursive_debug(#__VA_ARGS__, __VA_ARGS__)


int main(void) {
    int n;
    cin >> n;
    int r = sqrt(n)+1;
    vector<int> cnt(n+1);
    rep1(x,r)rep1(y,r)rep1(z,r){
        int res = x*x + y*y + z*z + x*y + y*z + z*x;
        if (res <= n) cnt[res]++;
    }
    rep1(i,n){
        cout << cnt[i] << endl;
    }
    return 0;
}


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

int main(){
  vector<int> time(5);
  for(int i = 0; i < 5; i++){
    cin >> time[i];
  }
  
  sort(begin(time), end(time), [](int x, int y){
    return x % 10 < y % 10;
  });
  
  int sum = 0;
  bool l = true;
  for(int i: time){
    if(i % 10 != 0){
      if(l){
        sum += i;
        l = false;
      }else{
        sum += i + 10 - (i % 10);
      }
    }else{
      sum += i;
    }
  }
  
  cout << sum << endl;
  return 0;
}
  

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
int main(){
  struct chan{
    ll a;
    ll b;
  };
  ll n;
  cin>>n;
  vector<chan> key(n);
  for(int i=0;i<n;i++){
    ll p;
    ll q;
    cin>>p>>q;
    key[i].a=p;
    key[i].b=q;
  }
  sort(key.begin(),key.end(),[](const chan& x,const chan& y){return x.b<y.b;});
  ll time=0;
  bool ch=true;
  for(int i=0;i<n;i++){
    time+=key[i].a;
    if(time>key[i].b){
      ch=false;
      break;
    }
  }
  if(ch) cout<<"Yes";
  else cout<<"No";
  return 0;
}

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

int main() {
    unsigned x; cin >> x;
    bitset<32> b(x);
    cout << b << endl;
    cout << ~b << endl;
    cout << (b << 1) << endl;
    cout << (b >> 1) << endl;
    return 0;
}


Measured memory_bytes: 3156
a,b,c,d,e,f = map(int, input().split())

waters = []
for i in range(f // (100 * a) + 1):
    for j in range(f // (100 * b) + 1):
        amount = 100 * (i * a + j * b)
        if amount <= f:
            waters.append(amount)

sugers = []
for i in range(f // c + 1):
    for j in range(f // d + 1):
        amount = i * c + j * d
        if amount <= f:
            sugers.append(amount)

waters = set(waters)
sugers = set(sugers)

maxp = -1.0
res_w = 0
res_s = 0

for w in waters:
    for s in sugers:
        if w + s > f or w + s == 0:
            continue
        capa = w // 100 * e
        if s > capa:
            continue
        p = 100 * s / (w + s)
        if maxp < p:
            maxp, res_w, res_s = p, w + s, s

print("%d %d" % (res_w, res_s))

Measured memory_bytes: 12440
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using i64 = int64_t;
#define rep(i, s, n) for (i64 i = (s); i < (n); ++i)

constexpr i64 kModulo{1000000007};

int main() {
  cin.tie(nullptr);

  i64 n, m;
  cin >> n >> m;
  map<int, set<int>> adj{};
  for (i64 i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    if (adj.find(a) != adj.end()) {
      adj[a].insert(b);
    } else {
      adj[a] = set<int>{b};
    }
    if (adj.find(b) != adj.end()) {
      adj[b].insert(a);
    } else {
      adj[b] = set<int>{a};
    }
  }
  i64 n_max{1};
  while (adj.begin() != adj.end()) {
    const auto& [k, v] = *adj.begin();
    deque<int> q{};
    q.push_back(k);
    i64 n{0};
    while (!q.empty()) {
      const auto& k = q.front();
      q.pop_front();
      if (adj.find(k) != adj.end()) {
        ++n;
        for (const auto x : adj[k]) {
          q.push_back(x);
        }
        adj.erase(k);
      }
    }
    n_max = max(n, n_max);
  }
  cout << n_max << endl;

  return 0;
}


Measured memory_bytes: 37624
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-4;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;


int n;
bool m[1 << 18];
ll a[1 << 18];
ll s[1 << 18];
ll sx[1 << 18];
vector<int> v;
int main() {
	cin >> n;
	cin >> a[0];
	rep1(i, n-1) {
		char t; cin >> t >> a[i];
		if (t == '-') {
			m[i] = true;
			v.push_back(i);
		}
	}
	rep(i, n) {
		s[i + 1] = s[i] + a[i];
		if(!m[i])sx[i + 1] = sx[i] + a[i];
		else sx[i + 1] = sx[i] - a[i];
	}
	ll ans = sx[n];
	rep(i, (int)v.size() - 1) {
		int le = v[i], ri = v[i + 1];
		ll z = sx[le] - (s[ri] - s[le]) + s[n] - s[ri];
		ans = max(ans, z);
	}
	cout << ans << endl;
	//stop
	return 0;
}

Measured memory_bytes: 5752
$memo = {}
def fib(n)
  if n == 0
    1
  elsif n == 1
    1
  else
    a = $memo[n - 1]
    if a.nil?
      a = fib(n - 1)
      $memo[n - 1] = a
    end
    b = $memo[n - 2]
    if b.nil?
      b = fib(n - 2)
      $memo[n - 2] = b
    end
    a + b
  end
end


n = STDIN.gets.to_i
puts fib(n)

Measured memory_bytes: 8656
/* 

*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <bitset>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define LSOne(S) (S & (-S))
#define EPS 1e-9
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pd;
typedef tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0); // BEFORE SUBMIT DON'T FORGET TO UNCOMMENT THIS
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<pair<ll, int>> vec; // {val, color} 
    vec.reserve(a+b+c+5);
    vector<ll> red(a+1), green(b+1), color(c);

    for(int i = 1; i <= a; ++i)
    {
        cin >> red[i];
        vec.push_back({red[i], 1});
    } 
    for(int i = 1; i <= b; ++i)
    {
        cin >> green[i];
        vec.push_back({green[i], 2});
    } 
    for(int i = 0; i < c; ++i)
    {
        cin >> color[i];
        vec.push_back({color[i], 3});
    } 

    sort(vec.begin(), vec.end());
    ll ans = 0; int numr = 0, numg = 0, numc = 0;
    for(int i = vec.size()-1; i >= 0; --i)
    {
        ll currVal = vec[i].first;
        int currColor = vec[i].second;
        if(currColor == 1)
        {
            if(numr == x) continue;
            ++numr;
            ans += currVal;
        }
        else if(currColor == 2)
        {
            if(numg == y) continue;
            ++numg;
            ans += currVal;
        }
        else
        {
            ans += currVal;
            ++numc;
        }
        if(numr+numg+numc == x+y) break;
    }
    cout << ans << "\n";
    return 0; 
}


Measured memory_bytes: 7296
def solve():
    N, W = map(int, input().split())
    dp = [0] * (W + 1)
    for _ in range(N):
        w, v = map(int, input().split())
        for i in range(W, w - 1, -1):
            dp[i] = max(dp[i], dp[i - w] + v)
    return max(dp)

print(solve())


Measured memory_bytes: 66808
n = int(input())
li = list(map(int, input().split()))

ans = 0
for i in range(1, n-1):
  if li[i-1] > li[i] and li[i+1] < li[i]:
    ans += 1
  if li[i-1] < li[i] and li[i+1] > li[i]:
    ans += 1
print(ans)


Measured memory_bytes: 3060
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        int odd = 0;
        for (int i = 0; i < N; ++i) {
            int a = sc.nextInt();
            if (a % 2 != 0) {
                ++odd;
            }
        }
        if (odd % 2 == 1) {
            if (N - odd == 0) {
                _out.println("YES");
            } else {
                _out.println("NO");
            }
        } else {
            _out.println("YES");
        }
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 48536
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  ll n,k;
  cin>>n>>k;
  vector<pair<ll, ll>> p(n);
  rep(i,n) cin>>p[i].first>>p[i].second;
  sort(p.begin(), p.end());
  ll tmp = 0;
  rep(i,n) {
    tmp += p[i].second;
    if(tmp >= k) {
      cout << p[i].first << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
using namespace std;
int main (void) {
    int N;

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

    sort(L, L + 2 * N);

    int ans = 0;
    for (int i = 0; i < 2 * N; i += 2) {
        ans += L[i];
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string N ;
    cin >> N;
    if((N.at(0)==N.at(1)&&N.at(1)==N.at(2))
    ||(N.at(1)==N.at(2)&&N.at(2)==N.at(3)))
    {cout<<"Yes"<<endl;}
    else {cout << "No" << endl;
    }
}

Measured memory_bytes: 256
/* To Kaise Hain Aaplog*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) (x).begin(), (x).end()

void shuru_krte_hai_bina_kisi_bakchodi_ke()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
const ll m = 998244353;

const ll s = 1e6 + 2;
ll a[s];
ll mss(vector<ll> v){
    ll temp = 0;
    ll ans = 0;
    for(int i=0;i<v.size();i++){
        temp+=v[i];
        temp = max(temp,0ll);
        ans = max(ans,temp);
    }
    return ans;
}
int main()
{
    //shuru_krte_hai_bina_kisi_bakchodi_ke();

    /* long long yaad se daal de har jagah*/
    #define int long long

    int n;
    cin>>n;
    string ans = "";
    while(n>0){
        n--;
        ans+=('a' + n%26);
        n/=26;
    }
    reverse(all(ans));
    cout<<ans;
}

Measured memory_bytes: 3592
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (((A == B) && (A != C)) || ((B == C) && (A != C)) ||
      ((A == C) && (B != C)))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
from sys import stdin


def input():
    return stdin.readline().strip()


def main():
    k = int(input())
    a, b = map(int, input().split())
    
    for n in range(a, b+1):
        if n % k == 0:
            print('OK')
            return
    
    print('NG')


if __name__ == "__main__":
    main()


Measured memory_bytes: 9172
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll  long long
#define PR  pair<int, int>

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const long long INF = 5e18;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll a[N];
set<ll> s;
map<ll, int> bad, done, cnt;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[a[i]]++;
        s.insert(a[i]);
    }
    for (auto i : s) {
        if (done.find(i) != done.end()) {
            continue;
        }
        for (ll x = 1; x * x <= i; x++) {
            if (i % x == 0) {
                ll fx = x;
                ll sx = i / x;
                if (s.find(fx) != s.end()) {
                    if (fx == i) {
                        if (cnt[i] > 1) bad[i] = 1;
                    } else {
                        bad[i] = 1;
                    }
                }
                if (s.find(sx) != s.end()) {
                     if (sx == i) {
                        if (cnt[i] > 1) bad[i] = 1;
                    } else {
                        bad[i] = 1;
                    }
                }
            }
        }
        done[i] = 1;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (bad.find(a[i]) == bad.end()) {
            ans++;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 52052
#include "bits/stdc++.h"
using namespace std;

int main()
{
	int k, n;
	cin >> k >> n;
	vector<int> d(n);
	
	for (int j = 0; j < n; j++)
		cin >> d[j];

	int lng = k + d[0] - d[n - 1] ;

	for (int i = 0; i < n - 1; i++)
	{
		int num = d[i + 1] - d[i];
		if (num > lng)
			lng = num;
	}
	cout << k - lng;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

int main(){
    int n;cin>>n;
    int maxV = 0;
    int minV = 10000;
    fore(i,0,n){
        int val;cin>>val;
        maxV = max(maxV,val);
        minV = min(minV,val); 
    }
    cout<<maxV-minV;
	return 0;
}

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

using namespace std;

struct Station
{
    int cost;
    int start;
    int period;
};

int FindTime(const vector<Station> &s, int start)
{
    int time = 0;
    for (size_t i = start; i < s.size(); i += 1) {
        time = max(time, s[i].start);
        if (time % s[i].period != 0) {
            time = (time / s[i].period + 1) * s[i].period;
        }
        time += s[i].cost;
    }
    return time;
}

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

    vector<Station> stations(n - 1);
    for (auto &s : stations) {
        cin >> s.cost >> s.start >> s.period;
    }

    for (int i = 0; i < n; i += 1) {
        cout << FindTime(stations, i) << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
import copy
from collections import deque
h,w=map(int,input().split())
maze=[]
for i in range(h):
    maze.append(list(input()))


def dfs(start_h,start_w):
    q=deque()
    maze_copy=copy.deepcopy(maze)
    walk_count=[[0 for _ in range(w)] for _ in range(h)]
    q.append([start_h,start_w])
    maze_copy[start_h][start_w]="#"
    max_count=0
    while(len(q)!=0):
        position=q.popleft()
        now_h=position[0]
        now_w=position[1]
        now_count=walk_count[now_h][now_w]
        if(now_h>0 and maze_copy[now_h-1][now_w]=='.'):
            walk_count[now_h-1][now_w]=now_count+1
            maze_copy[now_h-1][now_w]="#"
            q.append([now_h-1,now_w])
            if(max_count<now_count+1):
                max_count=now_count+1

        if(now_h<h-1 and maze_copy[now_h+1][now_w]=='.'):
            walk_count[now_h+1][now_w]=now_count+1
            maze_copy[now_h+1][now_w]="#"
            q.append([now_h+1,now_w])
            if(max_count<now_count+1):
                max_count=now_count+1

        if(now_w>0 and maze_copy[now_h][now_w-1]=='.'):
            walk_count[now_h][now_w-1]=now_count+1
            maze_copy[now_h][now_w-1]="#"
            q.append([now_h,now_w-1])
            if(max_count<now_count+1):
                max_count=now_count+1

        if(now_w<w-1 and maze_copy[now_h][now_w+1]=='.'):
            walk_count[now_h][now_w+1]=now_count+1
            maze_copy[now_h][now_w+1]="#"
            q.append([now_h,now_w+1])
            if(max_count<now_count+1):
                max_count=now_count+1
    return max_count

ans=0
for i in range(h):
    for j in range(w):
        if(maze[i][j]=='.'):
            ij_count=dfs(i,j)
            if(ans<ij_count):
                ans=ij_count
print(ans)


Measured memory_bytes: 3444
#!/usr/bin/python3

import array
import math
import os
import sys


def main():
    S = inp()
    print(solve(S))


def solve(S):
    N = len(S) + 1
    A = [-1] * N

    if S[0] == '<':
        A[0] = 0
    if S[N - 2] == '>':
        A[N - 1] = 0
    for i in range(N - 2):
        if S[i : i + 2] == '><':
            A[i + 1] = 0

    for i in range(N):
        if A[i] != 0:
            continue

        j = i - 1
        while j >= 0 and S[j] == '>':
            A[j] = max(A[j], A[j + 1] + 1)
            j -= 1

        j = i + 1
        while j < N and S[j - 1] == '<':
            A[j] = max(A[j], A[j - 1] + 1)
            j += 1

    dprint(A)
    return sum(A)


###############################################################################
# AUXILIARY FUNCTIONS

DEBUG = 'DEBUG' in os.environ


def inp():
    return sys.stdin.readline().rstrip()


def read_int():
    return int(inp())


def read_ints():
    return [int(e) for e in inp().split()]


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


if __name__ == '__main__':
    main()


Measured memory_bytes: 47816
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prd(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
const int inf = 1e9+10;
const ll INF = 2e18+10;
const int Mod = 1e9+7;
const int MAXN = 1000010;
const int N=2e5+10;
const int M=210;
const int M1=1e9+7;
const int M2=1e9+9;
const int base=131;
int main()
{
  ios::sync_with_stdio(0), cin.tie(0); cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int n;
  cin>>n;
  vector<int> a;
  for(int i=0;i<n;i++)
  {
    int x;
    cin>>x;
    a.pu(x);
  }
  sort(a.rbegin(),a.rend());
  ll ans=0;
  n--;
  if(n>0)
  {
    ans+=a[0];
    n--;
    int i=1;
    while(n>0)
    {
      ans+=a[i];
      n--;
      if(n>0)
      {
        ans+=a[i];
        n--;
      }
      else break;
      i++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4252