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

int main() {
  long long  n, k;
  cin >> n >> k;
  
  if (k >= n) {
    cout << 0 << endl;
    return 0;
  }

  vector<long long> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  sort(h.rbegin(), h.rend());

  long long count = 0;
  for (int i = k; i < n; i++) {
    count += h[i];
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define lint long long

using namespace std;

int main()
{
  lint h;
  cin >> h;

  lint count=0;
  lint attack=0;
  while(h){
    count++;
    attack += pow(2,count-1);
    h /= 2;
  }
  cout << attack << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
 string S;
 cin >> S;
 int ans = 700;
 if(S[0] == 'o') ans += 100;
 if(S[1] == 'o') ans += 100;
 if(S[2] == 'o') ans += 100;
 cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int N,i,work,min,ans=-1000000000;

  scanf("%d",&N);

  for(i=0;i<N;i++){
    scanf("%d",&work);
    
    if(i==0){
      min=work;
      continue;
    }
 
    if(ans<(work-min)) ans=work-min;

    if(work<min) min=work;
  }

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

  return 0;
}

Measured memory_bytes: 596
dic = [[] for i in range(31)]
dic[1].append([1])

def func(n):
  if dic[n]:
    return dic[n]
  else:
    dic[n].append([n])
    for i in range(n - 1, 0, -1):
      for l in func(n - i):
        if i >= l[0]:
          dic[n].append([i] + l)
    return dic[n]
func(30)

while True:
  n = int(input())
  if not n:
    break
  for l in dic[n]:
    print(" ".join(map(str, l)))


Measured memory_bytes: 9776
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

int main()
{
    long long n, k;
    std::cin >> n >> k;

    std::cout << std::min(n % k, k - n % k) << std::endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
using namespace std;
const int N=4001;
int n,a[N],f[N][3],dp[N][N],D[N][N][3],ans,B,W;
char c[N];
main () {
	ios::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	
	cin>>n;
	
	for (int i=1; i<=2*n; i++) {
		cin>>c[i]>>a[i];
		if (c[i]=='B') f[a[i]][0]=i;
		if (c[i]=='W') f[a[i]][1]=i;
		
		for (int j=0; j<=n; j++)
			if (c[i]=='B') D[i][j][0]=D[i-1][j][0]+(a[i]>j),D[i][j][1]=D[i-1][j][1];	
				else 
			if (c[i]=='W') D[i][j][1]=D[i-1][j][1]+(a[i]>j),D[i][j][0]=D[i-1][j][0];
	}
	
	for (int i=0; i<=n; i++)
		for (int j=0; j<=n; j++)	
			dp[i][j]=1e9;
			
	dp[0][0]=0;
	
	for (int i=0; i<=n; i++)
		for (int j=0; j<=n; j++) {
			if (j) dp[i][j]=min(dp[i][j],dp[i][j-1]+D[f[j][1]][j][1]+D[f[j][1]][i][0]);
			if (i) dp[i][j]=min(dp[i][j],dp[i-1][j]+D[f[i][0]][i][0]+D[f[i][0]][j][1]);
		}
	
	cout<<dp[n][n]<<endl;
}

Measured memory_bytes: 218624
def check(s):
    if kaibun(s) and kaibun(s[0:int((len(s) - 1) / 2)]) and kaibun(s[int((len(s) + 3) / 2) - 1:len(s)]):
        return 'Yes'
    else:
        return 'No'

def kaibun(s):
    for i in range(len(s)//2):
        if s[i] != s[-i-1]:
            return False
    return True

if __name__ == "__main__":
    s = input()
    print(check(s))

Measured memory_bytes: 3064
a,b,c=map(int,input().split())
temp=1000
i=0
while i<temp:
  if a%2!=0 or b%2!=0 or c%2!=0:
    print(i)
    break
  else:
    at=a
    bt=b
    ct=c
    a=bt//2+ct//2
    b=at//2+ct//2
    c=at//2+bt//2
    i=i+1
else:
  print(-1)

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

int main() {

    char alf[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n',
        'o','p','q','r','s','t','u','v','w','x','y','z' };
    long long ex, syou;
    int i;
    long long n;
    char ans[50] = {};

    cin >> n;
    syou = n;
    
    for (i = 0; syou > 0; i++) {
        ex = (syou - 1) % 26;
        ans[i] = alf[ex];
        syou = (syou - 1) / 26;
    }
   
    for (int j = i-1; j >= 0; j--) {
        cout << ans[j];
    }
    
    cout << endl;
    
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const long long int INF = 1e15;
vector<long long int> dijkstra(int s, int v, vector< vector< pair<int,int> > > G){
  //s: 始点, v: 頂点数, G: 隣接リスト
  priority_queue< pair<long long int, int> > wait;
  vector<long long int> result(v, INF);
  result[s] = 0;
  wait.push(make_pair(0, s));
  while(!wait.empty()){
    long long int nowpoint = wait.top().second;
    long long int nowcost = wait.top().first;
    wait.pop();
    if(nowcost <= result[nowpoint]){
      for(int i = 0; i < G[nowpoint].size(); ++i){
        long long int nextpoint = G[nowpoint][i].second;
        long long int nextcost = -nowcost + G[nowpoint][i].first;
        if(nextcost < result[nextpoint]){
          wait.push(make_pair(-nextcost, nextpoint));
          result[nextpoint] = nextcost;
        }
      }
    }
  }
  return result;
}

int main(){
  int N, M, s, t;
  cin >> N >> M >> s >> t;
  --s;--t;
  vector< vector< pair<int, int> > > G(N);
  int a, b, c, d;
  for(int i = 0; i < M; ++i){
    cin >> a >> b >> c >> d;
    --a;--b;--c;
    G[a].emplace_back(d,b);
    G[a].emplace_back(d,c);
    G[b].emplace_back(d,a);
    G[b].emplace_back(d,c);
    G[c].emplace_back(d,a);
    G[c].emplace_back(d,b);
  }
  cout << dijkstra(s,N,G)[t] << endl;
  return 0;
}



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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int H, W;
  cin >> H >> W;

  int N;
  cin >> N;

  queue<int> Q;
  rep (i, N) {
    int a;
    cin >> a;
    rep (j, a) Q.push(i + 1);
  }

  int c[H][W];

  rep (i, H) {
    if (i % 2) {
      for (int j = W - 1; j >= 0; j--) {
        c[i][j] = Q.front();
        Q.pop();
      }
    } else {
      rep (j, W) {
        c[i][j] = Q.front();
        Q.pop();
      }
    }
  }

  rep (i, H) {
    rep (j, W) cout << (j == 0 ? "" : " ") << c[i][j];
    cout << endl;
  }
}


Measured memory_bytes: 384
def main():
    n,x,m = map(int,input().split())
    a = [0] * m
    b = [x]
    ans = x
    i = 1
    while i < n:
        x = (x*x) % m
        if x == 0:
            print(ans)
            exit()

        if a[x] == 0:
            a[x] = i
            b.append(x)
            ans += x
            i += 1
        else :
            q = len(b) - a[x]
            qq = (n-len(b)) // q
            qqq = (n-len(b)) % q
            ans += sum(b[a[x]:]) * qq
            ans += sum(b[a[x]:a[x]+qqq])
            #print(b + b[a:] * qq + b[a:a+qqq])
            print(ans)
            exit()

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 13484
#include <iostream>
#include <string>
#include <vector>
#include <queue>
using namespace std;
using ll = long long;

int main() {
    int n;
    int flag=0;
    cin>>n;
    for(int i=1;i<10;i++){
        if(n%i==0){
            if(n/i<10)flag=1;
        }
    }
    if(flag==1)cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
D = int(input())
c = [int(x) for x in input().split()]
s = []
for i in range(D):
    s.append([int(x) for x in input().split()])
ans = 0
nissuu = [0] * 26
for i in range(D):
    t = int(input())
    for j in range(26):
        if j == t-1:
            nissuu[j] = 0
        else:
            nissuu[j] += 1
        ans -= c[j]*nissuu[j]
    ans += s[i][t-1]
    print(ans)

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

using namespace std;
struct sa
{
    char name[20];
    int s;
    int num;
}p[1005];
bool cmp(sa x,sa y)
{
    if(strcmp(x.name,y.name)<0)
        return x.name<y.name;
    if(strcmp(x.name,y.name)>0)
        return x.name>y.name;
    if(strcmp(x.name,y.name)==0)
        return x.s>y.s;
}
int main()
{
    ios::sync_with_stdio(false);
    int n;
    while(cin>>n)
    {
        for(int i=0;i<n;i++)
        {
            cin>>p[i].name>>p[i].s;
            p[i].num=i+1;
        }
        sort(p,p+n,cmp);
        for(int i=0;i<n;i++)
        {
            cout<<p[i].num<<endl;
        }
    }
    return 0;
}


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

int main(){
    string n;cin>>n;
    int flag=0;
    for(int i=0;i<3;i++){
        if(n[i]=='7') flag=1;
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll 

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    print(p.first, p.second);
}


signed main(){
    int n; cin >> n;
    vector<int> vec;
    vec.emplace_back(n);
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0){
            vec.emplace_back(i);
            if(i * i != n)vec.emplace_back(n / i);
        }
    }

    // print(vec);

    auto f = [](int x, int a){
        // a % x == 0
        while(a % x == 0)a /= x;
        a %= x;
        return a;
    };

    int ans = 0;
    for(auto i : vec){
        if(f(i, n) == 1)ans++;
    }

    n--;
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0){
            if(i * i == n)ans += 1;
            else ans += 2;
        }
    }
    // n-1を足す
    if(n != 1)ans++;

    cout << ans << endl;
}

Measured memory_bytes: 384
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

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

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

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

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

    ($next:expr, parser) => {
        $next
    };

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

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1e9 as usize + 9;

fn main() {
    input! {
        k: usize,
        x: usize,
    }

    if 500 * k >= x {
        println!("{}", "Yes");
    } else {
        println!("No");
    }
}


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

using namespace std;


int main() {
    map<int,int> m;
    for(int i = 0; i < 3; i++) {
        int a,b;
        cin >> a >> b;
        m[a]++;
        m[b]++;
    }
    bool ok = true;
    for(auto c : m) {
        if(c.second == 3) {
            ok = false;
        } 
    }
    if(ok) {
        puts("YES"); 
    } else {
        puts("NO");
    }
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
g = [[] for _ in range(n)]

for i in range(m):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  g[a].append(b)
  g[b].append(a)
  
from collections import deque
queue = deque([])
queue.append(0)

visited = [-1]*n
visited[0] = 0

while queue:
  x = queue.popleft()
  for new_x in g[x]:
    if visited[new_x] == -1:
      if new_x == n-1 and visited[x]+1 == 2:
        print('POSSIBLE')
        exit()
      else:
        visited[new_x] = visited[x]+1
        queue.append(new_x)
    else:
      continue
print('IMPOSSIBLE')

Measured memory_bytes: 85452
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
int main(){
  ll n;
  cin>>n;
  vvl data(2,vl(n));
  rep(i,2){
    rep(j,n)cin>>data[i][j];
  }
  ll MAX=0;
  for(int k=0;k<n;k++){
    ll ans=0;
    for(int i=0;i<=k;i++)ans+=data[0][i];
    for(int j=k;j<n;j++)ans+=data[1][j];
    MAX=max(ans,MAX);
  }
  cout<<MAX<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>s;
    char c=s[0];
    rrep(i,1,Size(s)){
        if(s[i]!=c){
            c=s[i];
            ans++;
        }
    }
    Cout(ans);
    return 0;
}


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

int N, M, K, S, P, Q;
queue< int > zombie;
vector< int > graph[100001];
int danger[100001];

void preBFS()
{
  while(!zombie.empty()) {
    int p = zombie.front(); zombie.pop();
    for(int to : graph[p]) {
      if(~danger[to]) continue;
      danger[to] = danger[p] + 1;
      zombie.push(to);
    }
  }
}

long long Dijkstra()
{
  typedef pair< long long, int > Pi;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  long long v[100001];
  fill_n(v, 100001, 1LL << 58);
  que.emplace(0, 1);
  v[1] = 0;
  while(!que.empty()) {
    long long cost, now;
    tie(cost, now) = que.top(); que.pop();
    if(cost > v[now]) continue;
    for(int to : graph[now]) {
      if(danger[to] == 0) continue;
      if(to == N) return(cost);
      long long next = cost + (danger[to] > S ? P : Q);
      if(next >= v[to]) continue;
      v[to] = next;
      que.emplace(next, to);
    }
  }
  return(-1);
}
int main()
{
  scanf("%d %d %d %d", &N, &M, &K, &S);
  scanf("%d %d", &P, &Q);

  memset(danger, -1, sizeof(danger));
  while(K--) {
    int C;
    scanf("%d", &C);
    zombie.push(C);
    danger[C] = 0;
  }
  while(M--) {
    int A, B;
    scanf("%d %d", &A, &B);
    graph[A].push_back(B);
    graph[B].push_back(A);
  }
  preBFS();
  printf("%lld\n", Dijkstra());
}

Measured memory_bytes: 11012
require 'prime'

$primes_u10000 = Prime.each(10000).to_a

def prime?(n)
	return n == $primes_u10000.bsearch{|x| n <= x} if n <= 10000

	# trial division
	limit = Math.sqrt(n).floor
	$primes_u10000.each do |d|
		break if limit < d
		return false if n % d == 0
	end

	return true
end

count = 0

gets.to_i.times do
	count += 1 if prime? gets.to_i
end

p count

Measured memory_bytes: 6252
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define rep(i,st,ed) for (register int i=st;i<=ed;++i)

const int N=25;

char s[N][N];

int match[N],n,m,flag;

bool used[N],lxf;

bool check() {
	int cnt=m;
	rep(i,1,m) used[i]=0;
	rep(i,1,m) if (!used[i]) {
		rep(j,i+1,m) if (!used[j]) {
			bool wjp=true;
			rep(k,1,n) if (s[k][i]!=s[match[k]][j]) {
				wjp=false; break;
			}
			if (wjp) {
				used[i]=used[j]=true;
				cnt-=2;
				break;
			}
		}
	}
	if (cnt==0) return true;
	if (cnt==1&&m%2==1) {
		rep(i,1,m) if (!used[i]) {
			rep(j,1,n) if (s[j][i]!=s[match[j]][i]) return false;
			break;
		}
		return true;
	}
	return false;
}

void dfs(int dep) {
	if (flag) return ;
	if (dep==(n+1)/2+1) return (void) (flag|=check());
	rep(i,1,n) if (!match[i]) {
		rep(j,i+1,n) if (!match[j]) {
			match[i]=j; match[j]=i;
			dfs(dep+1);
			match[i]=match[j]=0;
		}
		if ((n&1)&&!lxf) {
			match[i]=i; lxf=true;
			dfs(dep+1);
			match[i]=0; lxf=false;
		}
	}
}

int main(void) {
	scanf("%d%d",&n,&m);
	rep(i,1,n) scanf("%s",s[i]+1);
	dfs(1);
	puts(flag?"YES":"NO");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include <algorithm>
#include<string>
using namespace std;
int main()
{
	//int h, w,   q, D, ax[90001], ay[90001], l[100000], r[100000];
	long long int  i,a, b, c, d, e = 0, n, m, ten[1000] = { 0 }, ans = 0;
	string st[1000], stm[1000];

	cin >> n ;
	for ( a = 0; a < n; a++)
	{
		cin >> st[a];
		for ( b = 0; b < a; b++)
		{
			if (st[a]==st[b])
			{
				ten[b]++;
				ten[a] = -100000000000;
			}
		}
		

	}
	//for ( i = 0; i < 200; i++)
	//{
	//	cout << ten[i] << endl;

	//}
	//cout << "bbbbbbbbb" << endl;
	cin >> m;
	for (a = n; a < m+n; a++)
	{
		cin >> st[a];
		for (b = 0; b < a; b++)
		{
			if (st[a] == st[b])
			{
				ten[b]--;
				ten[a] = -100000000000;
			}
		}
	}
	/*for (i = 0; i < n+m; i++)
	{
		cout << ten[i] << endl;

	}*/
	c = 0;
	d = 0;
	for ( a = 0; a < n+m; a++)
	{
		if (ten[a]>=c)
		{
			c = ten[a];
			d = 1;
		}
	}
	if (d==1)
	{
		cout << c+1 << endl;

	}
	else
	{
		cout << 0 << endl;

	}
	// 出力
	return 0;
}

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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  ll n, k;
  cin >> n >> k;
  vector<int> p(n), c(n);
  rep(i, n) {
    cin >> p[i];
    p[i]--;
  }
  rep(i, n) cin >> c[i];

  ll ans = -INF;
  rep(si, n) {
    ll x = si, total = 0;
    vector<ll> s(1, 0);
    while (true) {
      x = p[x];
      s.push_back(s[s.size() - 1] + c[x]);
      total += c[x];
      if (x == si) break;
    }
    int l = s.size() - 1;
    rep(i, l) {
      if (i + 1 > k) break;
      ll now = s[i + 1] + max(0LL, total) * ((k - (i + 1)) / l);
      ans = max(ans, now);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3708
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define dump(x)  cout << #x << " = " << (x) << endl;

#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
//             0123456789 - digits. check the limits, int vs long
const int MX = 100001;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(10);
    cout << std::fixed;
    // freopen("ex.in","r",stdin);
    // freopen("ex.out","w",stdout);
    int n;
    cin >> n;
    double v[n];
    for (int i = 0; i < n; i++)
        cin >> v[i];
    sort(v, v+ n);
    double cur = v[0];
    for(int i = 1; i < n; i++) {
        cur += v[i];
        cur /= 2; 
    }
    cout << cur << "\n";
    return 0;
}

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

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

class Main{
	static int n,mat[][];
	static long ans;
	static StringBuilder allset;
	static long dp[][];
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=1;
//		Integer.parseInt(br.readLine().trim());
		OutputStream outputStream =System.out;
        PrintWriter out =new PrintWriter(outputStream);
		StringBuilder printans=new StringBuilder();
		while(t-->0)
		{
			StringTokenizer tok=new StringTokenizer(br.readLine()," ");
			n=Integer.parseInt(tok.nextToken());
			
			mat=new int[n][n];
			for(int i=0;i<n;i++) {
				tok=new StringTokenizer(br.readLine()," ");
				for(int j=0;j<n;j++)
					mat[i][j]=Integer.parseInt(tok.nextToken());
			}
			dp=new long[n+1][1<<n];
			memset();
			printans.append(call(0,0));
		}
		out.println(printans);
		out.close();
	}
	static long call(int i,int mask) {
		
		if(i==n) {
			
			if((mask&1<<n+1)==0)return 1;
			
			
			return 0;
		}
		if(dp[i][mask]!=-1)return dp[i][mask];
		long ans=0;
		for(int j=0;j<n;j++) {
			if((mask & (1<<j))==0 && mat[i][j]==1) {
				mask|=(1<<j);
				ans+=call(i+1,mask);
				mask^=(1<<j);
			}
			
			
		}
		dp[i][mask]=ans%mod;
		return ans%mod;
	}
	static void memset() {
		for(int i=0;i<dp.length;i++) {
			Arrays.fill(dp[i], -1);
		}
	}
	static int mod=(int)1e9+7;
}

Measured memory_bytes: 383700
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a[3];
    rep(i, 3) cin >> a[i];
    sort(a, a+3);
    if(a[0] == 5 and a[1] == 5 and a[2] == 7) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

	public static void main(String args[]){
		
		Scanner sc = new Scanner(System.in);
		
		double a = Double.parseDouble(sc.next());
		double b = Double.parseDouble(sc.next());
		int C    = Integer.parseInt(sc.next());
		double radian = StrictMath.toRadians(C);
		
		double area = a * b * Math.sin(radian) / 2;
		double c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b * Math.cos(radian));
		double height = 2 * area / a;
		double length = a + b + c;

		System.out.println(String.format("%.8f", area));
		System.out.println(String.format("%.8f", length));
		System.out.println(String.format("%.8f", height));

		
		sc.close();
		
		
	}

}



Measured memory_bytes: 26240
#include <bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds; 
#define ull          unsigned long long int
#define ll          long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.0000000001
#define all(a)      (a).begin(),(a).end()
#define ordered_set     tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> 
 
const long long INF = (long long) 1e11+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

ll power(ll x,ll y){
  ll res=1;
  while(y>0){
    if(y%2) res=(x%hell*res%hell)%hell;
    x=(x%hell*x%hell)%hell;    
    y=y/2;
  }
  
  return res%hell;
}
 
ll modinv(ll x){
  return power(x,hell-2);
}

ll gcd(ll a,ll b){
    while( b != 0)
	{
		ll  t = b;
		b= a %t;
		a = t;
	}
	return a;
}    
    
void fastIO(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
} 
    
void solve(){  
    string s;
    cin>>s;
    
    int n=s.length();
    forn(i,0,n){
        if(s[i]=='?')
        s[i]='D';
    }
    cout<<s;
}    

int main(){
   fastIO();
   int test;
   //cin>>test;
   test=1;    
      
   while(test--)
   solve();
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N>>S;
    vec le(N,0), ri(N,0);
    reps(i,1,N) le[i] = le[i-1] + (S[i-1] == 'W');
    reps(i,1,N) ri[i] = ri[i-1] + (S[N-i] == 'E');
    ll ans = N;
    rep(i,N) ans = min(ans, le[i] + ri[N-1-i]);
    cout<<ans<<endl;
}


Measured memory_bytes: 5380
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

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

        int s = sc.nextInt();

        System.out.println(solve(s));

        sc.close();
    }

    static int solve(int s) {
        Set<Integer> seen = new HashSet<>();
        seen.add(s);
        int current = s;
        for (int m = 2;; ++m) {
            current = (current % 2 == 0) ? (current / 2) : (current * 3 + 1);
            if (seen.contains(current)) {
                return m;
            }

            seen.add(current);
        }
    }
}

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

ll f(ll x, int c, int d) {
  ll res = x;
  res -= x/c;
  res -= x/d;
  res += x/lcm(c,d);
  return res;
}

int main() {
  ll a, b;
  int c, d;
  cin >> a >> b >> c >> d;
  ll ans = f(b,c,d) - f(a-1,c,d);
  cout << ans << endl;
  return 0;
}

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

int rec[200000];

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

	for (int i = 0; i < n; i++)
		cin >> rec[i];

	int maxv = INT_MIN, minv = rec[0];
	for (int j = 1; j < n; j++)
	{
		maxv = max(maxv, rec[j]-minv);
		minv = min(minv, rec[j]);
	}

	cout << maxv << endl;
	return 0;
}

Measured memory_bytes: 3872
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
using P=pair<int,int>;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,m,Q,l,r,p,q,x[505][505]={},ans,y[505][505]={};
  cin >> n >> m >> Q;
  for(int i=0; i<m; i++) {
    cin >> l >> r;
    x[l][r]++;
  }
  for(int i=1; i<=n; i++) {
    for(int j=1; j<=n; j++) {
      y[i][j]=y[i][j-1]+x[i][j];
    }
  }
  while(Q--) {
    cin >> p >> q;
    ans=0;
    for(int j=p; j<=q; j++) {
      ans+=y[j][q]-y[j][p-1];
    }
    cout << ans << "\n";
  }
}

Measured memory_bytes: 2944
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 99999999



int main(){
    int n,g;
    while(cin>>n&&n){
        vector<pii> card;
        int sum=0;
        rep(i,n){
            int a,b;
            cin>>a>>b;
            card.pb(pii(a,b));
        }
        
        ll dp[8000]={};
        dp[0]=1;
        for(int i=1;i<=n;i++){
            for(int j=8000-1;j>=1;j--){
                for(int k=1;k<=card[i-1].second;k++){
                    if(j-k*card[i-1].first>=0){
//                        if(dp[j-k*card[i-1].first]>0)cout<<i<<" "<<j<<" "<<k<<" "<<"dp["<<j<<"]="<<dp[j]<<"+"<<dp[j-k*card[i-1].first]<<" "<<dp[j]+dp[j-k*card[i-1].first]<<endl;
                        dp[j]+=dp[j-k*card[i-1].first];
                    }
                }
            }
        }

        cin>>g;
        rep(i,g){
            int m;
            cin>>m;
            cout<<dp[m]<<endl;
            
        }
    }
    
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int N;
  cin >> N;
  int n = (1 << N);
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  dump(a);
  vector<int> s;
  s.push_back(a.back());
  a.back() = -1;
  rep(i, N) {
    vector<int> p = s;
    sort(p.begin(), p.end());
    dump(p);
    int j = n - 1;
    while (p.size() > 0 && j >= 0) {
      if (a[j] == -1) {
        j--;
        continue;
      }
      if (a[j] < p.back()) {
        s.push_back(a[j]);
        a[j] = -1;
        p.pop_back();
      }
      j--;
    }
    dump(a);
    dump(s);
    if (p.size() > 0) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 2932
#include <iostream>

int main() {
	int a,b, res;
  	std::string op;
  
  	std::cin >> a >> op >> b;
      
    if (op == "+") {
    	res = a + b;
    } else {
    	res = a - b;
    }
  
  std::cout << res << std::endl;
}

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


const int md = 1000000007;

int main() {
	int n, m; long long ans = 1; cin >> n >> m;
	if (abs(n -m) >=0 && abs(n-m) <=1) {
		for (int i = n; !(i==1); i--) {
			ans *= (i%md);
			ans %= md;
		}
		for (int i = m; !(i==1); i--) {
			ans *= (i % md);
			ans %= md;
		}
		if (n == m) {
			ans *= 2;
			ans %= md;
		}
	}
	else {
		ans = 0;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;

int main(void){
  int q,i,t,f,e;
  char c;
  string s,ry[2];
  
  cin >> s >> q;
  
  e=1;
  for (i=0;i<q;i++){
    cin >> t;
    if (t==1){
      e=1-e;
    }else{
      cin >> f >> c;
      ry[(e+f)%2]+=c;
    }
  }
  
  for (i=ry[1-e].size()-1;i>=0;i--) cout << ry[1-e][i];
  
  if (e==1) cout << s;
  else{
    for (i=s.size()-1;i>=0;i--) cout << s[i];
  }

  for (i=0;i<ry[e].size();i++) cout << ry[e][i];
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 1088
"""
Writer: SPD_9X2
https://atcoder.jp/contests/agc001/tasks/agc001_c

今度こそ通すぞ！！
制約が小さいので、各頂点に関して最短距離探索するぐらいはできる

直径の中央で全探索する？
→距離K//2以内の頂点の数を数え、残りを取り除けばよい
→その点を通らない長さK以上のパスは存在しえない

Kが偶数なら、1点を中心(深さ0)とし探索
Kが奇数なら、隣接する2点を深さ0とすればよい

計算量はO(N**2)

"""
from collections import deque
N,K = map(int,input().split())

AB = []

lis = [ [] for i in range(N) ]

for i in range(N-1):

    A,B = map(int,input().split())

    A -= 1
    B -= 1

    lis[A].append(B)
    lis[B].append(A)

    AB.append([A,B])

ans = float("inf")

if K % 2 == 0: #偶数の場合

    for st in range(N):
        q = deque([st])
        dis = [float("inf")] * N
        dis[st] = 0
        nps = 0

        while len(q) > 0:

            now = q.popleft()
            nps += 1

            if dis[now] < K//2:

                for nex in lis[now]:
                    if dis[nex] > dis[now] + 1:
                        dis[nex] = dis[now] + 1
                        q.append(nex)
                        
        ans = min(ans , N - nps)

else:

    for i in range(N-1):
        a,b = AB[i]
        q = deque([a,b])
        dis = [float("inf")] * N
        dis[a] = 0
        dis[b] = 0
        nps = 0

        while len(q) > 0:

            now = q.popleft()
            nps += 1

            if dis[now] < K//2:

                for nex in lis[now]:
                    if dis[nex] > dis[now] + 1:
                        dis[nex] = dis[now] + 1
                        q.append(nex)
                        
        ans = min(ans , N - nps)   

print (ans)


Measured memory_bytes: 54008
h1, m1, h2, m2, k = list(map(int, input().split()))
#n, m = list(map(int, input().split()))
# a = list(map(int, input().split()))
# data = [list(map(int, input().split())) for i in range(n)]
# k = int(input())
# a = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
#py = [list(map(int, input().split())) for i in range(m)]
# b = list(map(int, input().split()))


total = (h2-h1)*60
if m1 <= m2:
    total += (m2-m1)
else:
    if m2 == 0:
        total += 60-m1
        total -= 60
    else:
        #total += (m1-m2)
        total -= (m1-m2)


ans = total - k
print(ans)


Measured memory_bytes: 9072
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

template<typename T> bool chmin(T a, T &b) { return a < b ? b = a, true : false; }
template<typename T> bool chmax(T a, T &b) { return a > b ? b = a, true : false; }

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool is_prime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}

/*------------------------------------------------------------------------*/

void solve();

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}

void solve() {
    ll n, m;
    std::cin >> n >> m;

    vvll g(n);
    for (ll i = 0; i < m; i++) {
        ll a, b; std::cin >> a >> b;
        a--, b--;
        g[a].push_back(b), g[b].push_back(a);
    }

    vll r(n);
    std::iota(r.begin(), r.end(), 0);

    ll ans = 0;
    do {
        bool flg = true;
        for (ll i = 0; i < n - 1; i++)
            if (std::find(g[r[i]].begin(), g[r[i]].end(), r[i + 1]) == g[r[i]].end()) {
                flg = false; break;
            }
        ans += flg;
    } while (std::next_permutation(r.begin(), r.end()) && !r.front());

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


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

using namespace std;
const int N = 3e3+7;

int dp[N][N];  //dp[i][j] 到 i，j为止最长的公共子序列长度 

int main()
{
	string s,t;
	cin>>s>>t;
	s = "0" + s;
	t = "0" + t;
	int ls = s.size(),lt = t.size();
	
	for(int i=1;i<ls;i++){
		for(int j=1;j<lt;j++){
			dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			if(s[i]==t[j]) dp[i][j] = max(dp[i-1][j-1] + 1,dp[i][j]);
		}
	}
	string ans = "";
	for(int i=ls-1,j=lt-1 ; i&&j ;){
		if(s[i]==t[j]) ans += s[i],i--,j--;
		else if(dp[i-1][j]>dp[i][j-1]) i--;
		else j--;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<"\n";
	return 0;
} 

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

using namespace std;


int main(){
	long long int N;
	cin >> N;
	vector < long long int >D(N + 2);
	long long int sum = 0;
	for( size_t i = 1; i <= N; i++ ){
		cin >> D[i];
	}
	for( size_t i = 0; i < N + 1; i++ ){
		sum += abs(D[i + 1] - D[i]);
	}
	for( size_t i = 0; i < N; i++ ){
		cout << sum - abs(D[i + 1] - D[i]) - abs(D[i + 2] - D[i + 1]) + abs(D[i + 2] - D[i]) << endl;
	}
}

Measured memory_bytes: 2048
#include <iostream>

using namespace std;

int bi_search(int Arr[], int n, int key){
  int top = n;
  int bottom = -1;

  while(true){
    int check = (top+bottom)/2;
    if(key==Arr[check]){
      return check;
    }else if(key<Arr[check]){
      top = check;
    }else if(key>Arr[check]){
      bottom = check;
    }
    if(top - bottom == 1) return -1;
  }
}

int main(){
  int n; cin>>n;
  int S[n];
  for(int i=0;i<n;i++){
    cin>>S[i];
  }
  int q; cin>>q;
  int sum=0;
  for(int i=0;i<q;i++){
    int t;
    cin>>t;
    if(bi_search(S,n,t)>=0){
      sum++;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3476
import java.util.*

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!


    var rcnt = 0L
    var gcnt = 0L
    var bcnt = 0L
    repeat(n) {
        when {
            s[it] == 'R' -> {
                rcnt++
            }
            s[it] == 'G' -> {
                gcnt++
            }
            s[it] == 'B' -> {
                bcnt++
            }
        }
    }

    val answer = rcnt * gcnt * bcnt
    var minus = 0
    for (a in 0 until n-2) {
        for (b in a+1 until n-1) {
            val c = b + (b-a)
            if (c < n && s[a] != s[b] && s[a] != s[c] && s[b] != s[c]) minus++
        }
    }
    println(answer - minus)
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

const double PI = acos(-1);
int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	vector<VI> r(n);
	rep(i, m){
		int a, b; cin >>a >>b;
		r[a-1].push_back(b-1);
		r[b-1].push_back(a-1);
	}
	
	const int INF= 1<<28;
	VI dd(n, INF);
	VI ps(n);
	queue< int > que;
	que.emplace(0); dd[0]=0;
	while(!que.empty()){
		int cy = que.front();
		que.pop();
		for(auto v: r[cy]){
			if(dd[v] == INF){
				que.emplace(v);
				dd[v] = dd[cy] + 1;
				ps[v] = cy;
			}
		}
	}

	//for(auto x :dd) cerr<<x<<" "; dbg();
	rep(i, n) if(dd[i]==INF){ cout<<"No\n"; return 0;}
	cout<<"Yes\n";
	rep2(i,1, n) cout <<ps[i]+1 <<"\n";
	return 0;
	
}


Measured memory_bytes: 10644
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}
std::uint32_t euclidean_gcd(std::uint32_t a, std::uint32_t b){return b != 0 ? euclidean_gcd(b, a % b) : a;}


void solve(long long N, std::string S){
    LL ans=0;
    REP(i, N-2){
        if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C')ans++;
    }
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
void uruu(int year, bool&);
 
int main()
{
    int a, b;
    std::cin >> a >> b;
     
    while (true) {
        bool write = false;
 
        for (int i = a; i <= b; i++) {
            uruu(i, write);
        }
        if (!write) {
            std::cout << "NA" << std::endl;
        }
 
        std::cin >> a >> b;
        if (a == 0 && b == 0) {
            break;
        }
        std::cout << std::endl;
    }
 
    return 0;
}
 
 
void uruu(int year, bool& write)
{
    if (year % 400 == 0) {
        std::cout << year << std::endl;
        write = true;
        return;
    } else if (year % 100 == 0) {
        return;
    } else if (year % 4 == 0) {
        std::cout << year <<std::endl;
        write = true;
        return;
    } else {
        return;
    }
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);

    map<long long, long long> mp;
    rep(i, n) mp[a.at(i)]++;

    string answer = "No";
    if (mp.size() == 1 && mp.begin()->first == 0)
    {
        answer = "Yes";
    }
    else if (n % 3 == 0)
    {
        if (mp.size() == 2)
        {
            pair<long long, long long> z = *(mp.begin());
            if (z.first == 0)
            {
                if (z.second == n / 3 || z.second == 2 * n / 3)
                    answer = "Yes";
            }
        }
        else if (mp.size() == 3)
        {
            answer = "Yes";
            long long xsum = 0;
            auto itr = mp.begin();
            while (itr != mp.end())
            {
                if (itr->second != n / 3)
                    answer = "No";
                xsum ^= itr->first;
                itr++;
            }
            if (xsum)
                answer = "No";
        }
    }
    cout << answer << endl;
}

Measured memory_bytes: 5376