akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

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

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int a, b, c;
	cin >> a >> b >> c;
	if(a == b && b != c) cout << "Yes" << endl;	
	else if(b == c && b != a) cout << "Yes" << endl;	
	else if(a == c && b != a) cout << "Yes" << endl;	
	else cout << "No" << endl;
}




Measured memory_bytes: 256
import math
import collections
from operator import mul
from functools import reduce
import bisect

b=[]
def test(a):
    if len(a)>=8:
        b.append(a+"3")
        b.append(a+"5")
        b.append(a+"7")
    else:
        b.append(a+"3")
        b.append(a+"5")
        b.append(a+"7")
        test(a+"3")
        test(a+"5")
        test(a+"7")

#n,m=map(int,input().split())

n=int(input())
test("")
c=[]
b=set(b)
for bi in b:
    if bi.count("3")>0 and  bi.count("5")>0 and bi.count("7")>0 :
        c.append(bi)

c=sorted(list(map(int,c)))
d=bisect.bisect(c,n)
print(d)



Measured memory_bytes: 47340
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
 
int main(){
   string s; cin >> s;
   ll a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';
   if(a - b - c - d == 7)cout << a  << "-" << b << "-" << c <<"-" <<d<<"=7";
   else if(a - b - c + d == 7)cout << a  << "-" << b << "-" << c <<"+" <<d <<"=7";
   else if(a - b + c - d == 7)cout << a  << "-" << b << "+" << c <<"-" <<d<<"=7";
   else if(a - b + c + d == 7)cout << a  << "-" << b << "+" << c <<"+" <<d<<"=7";
   else if(a + b - c - d == 7)cout << a  << "+" << b << "-" << c <<"-" <<d<<"=7";
   else if(a + b - c + d == 7)cout << a  << "+" << b << "-" << c <<"+" <<d<<"=7";
   else if(a + b + c - d == 7)cout << a  << "+" << b << "+" << c <<"-" <<d<<"=7";
   else if(a + b + c + d == 7)cout << a  << "+" << b << "+" << c <<"+" <<d<<"=7";
   return 0;
}


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

using namespace std;
using ll = long long;

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

    int n;
    cin >> n;
    string s;
    cin >> s;

    int nw = count(s.begin(), s.end(), 'W');
    int nwr = count(s.begin(), s.end() - nw, 'W');

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

    return 0;
}

Measured memory_bytes: 3852
#include                        <bits/stdc++.h>
#define   lli                   unsigned long long int
#define   ll                    long long int
#define   PI                    acos(-1.0)
#define   UNIQUE(V)             (V).erase(unique(ALL(V), (V).end()) //vector/string etc must need to be sorted
#define   timesave              ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define   ALL(V)                (V).begin(), (V).end()
#define   MEMSET(a, val)        memset(a, val, sizeof(a))
using     namespace             std;


template  <class T> T GCD(T a, T b) { return (b != 0 ? GCD <T> (b, a%b) : a); }
template  <class T> T LCM(T a, T b) { return ((a*b)  / GCD <T> (a, b)); }

const int M = 1e5+5;
int a[M];


int main()
{
//  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);

    timesave;

    //while(1){

    int n, m, l, r;

    cin >> n >> m;


    for(int i = 0; i < m; i++){
        cin >> l >> r;
        a[l]++; a[r+1]--;
    }

    for(int i = 2; i <= n; i++) a[i] += a[i-1];

    int cnt = 0;
    for(int i = 1; i <= n; i++){
        if(a[i] >= m) cnt++;
    }

    cout << cnt << endl;


    //}

    return 0;
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

vector<ll> table;
vector<bool> kaidan;

ll dp(ll n)
{
  if(kaidan.at(n)) return 0;
  if(n==0) return 1;
  if(n==1) return 1;
  if(table.at(n)>-1) return table.at(n);
  
  table.at(n)=(dp(n-1)+dp(n-2))%MOD;
  
  return table.at(n);
}  

int main() 
{
  ll N,M; cin>>N>>M;
  kaidan=vector<bool>(N+1,false);
  rep(i,M)
  {
    ll a; cin>>a;
    kaidan.at(a)=true;
  }
  table=vector<ll>(N+1,-1);
  cout<<dp(N)<<endl;
  /*
  rep(i,N+1)
  {
    if(i!=0) cout<<" ";
    cout<<kaidan.at(i);
  }
  */
  cout<<endl;
  return 0;
}

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

int main(){
	string s;
  	cin >> s;
  
  	int ans = 0;
  	rep(i, 3){
    	if(s[i] == 'R') ans++;
    }
	if(s[1] == 'S' && ans > 1) ans = 1;
  	
  	cout << ans << endl;
}

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

int main(){
  ll N, K, S; cin >> N >> K >> S;
  vector<ll> ans;
  rep(i,N){
    if(i<K) ans.pb(S);
    else {
      if(S!=1e9) ans.pb(1e9);
      else ans.pb(1);
    }
  }
  rep(i,N){
    if(i) cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 2292
K = input().strip()
K_int = int(K)

A, B = input().strip().split(" ")
A_int = int(A)
B_int = int(B)

possible = False

for i in range(A_int, B_int + 1):
    if i % K_int == 0:
        possible = True
        break

if possible:
    print("OK")
else:
    print("NG")


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

int main() {
  int N;
  cin >> N;
  priority_queue<double, vector<double>, greater<double>> Q;
  double q, ans=0;
  for (int i=0; i<N; i++) {
    cin >> q;
    Q.push(q);
  }
  while (Q.size()>1) {
    double p1, p2;
    p1=Q.top();
    Q.pop();
    p2=Q.top();
    Q.pop();
    ans=(p1+p2)/2;
    Q.push((p1+p2)/2);
  }
  cout << ans << endl;
}


Measured memory_bytes: 3828
fn main() {
    let scan = std::io::stdin();
    let mut line = String::new();
    let _ = scan.read_line(&mut line);
    let mut vec: Vec<&str> = line.split_whitespace().collect();

    let mut n: Vec<i32> = Vec::new();

    for x in vec {
        n.push(x.parse().unwrap());
    }

    if (n[0] + n[1]) > (n[2] + n[3]){
        println!("Left");
    }else if  (n[0] + n[1]) < (n[2] + n[3]){
        println!("Right");
    }else{
        println!("Balanced");
    }

}


Measured memory_bytes: 4352
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

int solve(ll curr, int mask, int n) {
  if(curr > n) return 0;
  int ret = 0;
  if(mask == 7) ret++;
  ret += solve(10*curr+3, mask | 1, n);
  ret += solve(10*curr+5, mask | 2, n);
  ret += solve(10*curr+7, mask | 4, n);
  return ret;
}

void solve() {
  int n;
  cin >> n;
  cout << solve(0, 0, n) << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[10001];
int main()
{
	int n;
	cin>>n;
	for(int x=1;x<=100;x++)
		for(int y=1;y<=100;y++)
			for(int z=1;z<=100;z++)
				if((x*x+y*y+z*z+x*y+y*z+x*z)<=10000)
					a[x*x+y*y+z*z+x*y+y*z+x*z]++;
	for(int i=1;i<=n;i++)
		cout<<a[i]<<endl;
	return 0;
}


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

public class Main{

    public static void main(String[] args) {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

        try {
            Integer dataNum = Integer.valueOf(in.readLine());

            for (int i = 0; i < dataNum.intValue(); i++) {

                String[] problemData = in.readLine().split("\\s");

                int max = 0;

                int other1 = 0;

                int other2 = 0;

                for (String data : problemData) {

                    int dataInt = Integer.valueOf(data);

                    other2 = other1;

                    if (dataInt > max) {
                        other1 = max;
                        max = dataInt;
                    } else {
                        other1 = dataInt;
                    }
                }

                if ((max * max) == (other1 * other1 + other2 * other2)) {
                    System.out.println("YES");
                } else {
                    System.out.println("NO");
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

Measured memory_bytes: 20204
#coding: UTF-8

def Range(a,b,c):
    if a < b and b < c:
        return "Yes"
    else:
        return "No"

if __name__=="__main__":
    a = input().split(" ")
    ans = Range(int(a[0]),int(a[1]),int(a[2]))
    print(ans)

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

typedef long long ll;
const ll INF = 1LL << 60;

ll N, M, L, Q;
vector<ll> A, B, C, s, t;

int main() {
    cin >> N >> M >> L;
    A.resize(M);
    B.resize(M);
    C.resize(M);

    // dist
    // 初期値 INF
    // 辺のコスト
    // [i][i] は 0
    vector<vector<ll>> dist(N, vector<ll>(N, INF));
    rep(i, M) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        dist[a][b] = c;
        dist[b][a] = c;
    }

    // ワーシャルフロイド
    rep(k, N)rep(i, N)rep(j, N) dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    rep(i, N) dist[i][i] = 0;

    // rep(i, N) {
    //     rep(j, N) {
    //         cout << i << " " << j << " " << dist[i][j] << endl;
    //     }
    // }
    // cout << " end " << endl;

    // L で通過できる区間かをみる
    vector<vector<ll>> dist2(N, vector<ll>(N, INF));
    rep(i, N)rep(j, N) {
        if (dist[i][j] <= L) dist2[i][j] = 1;
    }

    rep(k, N)rep(i, N)rep(j, N) dist2[i][j] = min(dist2[i][j], dist2[i][k] + dist2[k][j]);

    cin >> Q;
    s.resize(Q);
    t.resize(Q);
    rep(i, Q) {
        ll start, end;
        cin >> start >> end;
        start--; end--;

        ll ans = dist2[start][end] - 1;
        if (dist2[start][end] == INF) ans = -1;
        cout << ans << endl;
    }
}

Measured memory_bytes: 4352
#include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <functional> //sort(A,A.end(),greater<int>());???????????????
#include <queue>
#include <stack>
#include <vector>

#define INF 10 << 10

int main() {
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	int time = 0;
	if (a < 0) {
		time += c * (0 - a);
		a = 0;
	}
	if (a == 0) {
		time += d;
	}
	if (a >= 0) {
		time += e * (b - a);
	}
	cout << time << endl;
	return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <queue>

using namespace std;

#define N 50

bool S[N+2][N+2] = {false};
int D[N+2][N+2] = {0};

class V;
queue<V*> Q;

class V {
  int h, w, d;

public:
  V(int h, int w, int d)
    : h(h), w(w), d(d)
  {
    D[h][w] = d;
  }
  
  void next()
  {
    if (S[h-1][w] && D[h-1][w] == 0)
      Q.push(new V(h-1,w,d+1));
    if (S[h][w-1] && D[h][w-1] == 0)
      Q.push(new V(h,w-1,d+1));
    if (S[h+1][w] && D[h+1][w] == 0)
      Q.push(new V(h+1,w,d+1));
    if (S[h][w+1] && D[h][w+1] == 0)
      Q.push(new V(h,w+1,d+1));
  }

  bool is_goal(int H, int W)
  {
    return (h==H && w==W);
  }
};

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

  int num_white = 0;
  
  for (int h=1; h<=H; ++h) {
    for (int w=1; w<=W; ++w) {
      char s;
      cin >> s;
      S[h][w] = (s=='.');
      if (s=='.')
	++num_white;
    }
  }
  
  Q.push(new V(1,1,1));
  V* v = NULL;
  bool ok = false;
  while(!Q.empty()) {
    v = Q.front();
    if (v->is_goal(H,W)) {
      ok = true;
      break;
    }
    v->next();
    Q.pop();
    delete v;
  }

  int score = (ok) ? num_white - D[H][W] : -1;
  std::cout << score << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int n,i;
  double a, sum;
  char u[3];
  
  scanf("%d", &n);
  
  for(i=0;i<n;i++){
    scanf("%lf %s",&a ,u);
    if(u[0]=='J'){
    sum=sum+a;
      continue;
    }
    sum=sum+a*380000;
  }
  
  printf("%f", sum);
  
  return 0;
}

Measured memory_bytes: 128
/*  -*- coding: utf-8 -*-
 *
 * a.cc: C: 2D Plane 2N Points
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_N2 = MAX_N * 2;

/* typedef */

typedef vector<int> vi;
typedef vector<bool> vb;

/* global variables */

int xs[MAX_N2], ys[MAX_N2];
vi nbrs[MAX_N2];

/* subroutines */

bool max_match_rec(const vi *nbrs, int u, vi &matches, vb &visited) {
  if (u < 0) return true;
  const vi &nbru = nbrs[u];
  for (vi::const_iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
    const int &v = *vit;
    if (! visited[v]) {
      visited[v] = true;
      if (max_match_rec(nbrs, matches[v], matches, visited)) {
	matches[u] = v;
	matches[v] = u;
	return true;
      }
    }
  }
  return false;
}

int max_match(const int n, int l, const vi *nbrs) {
  vi matches(n, -1);
  int count = 0;
  
  for (int u = 0; u < l; u++) {
    vb visited(n, false);
    if (max_match_rec(nbrs, u, matches, visited)) count++;
  }

  return count;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);
  int n2 = n * 2;

  for (int i = 0; i < n2; i++) scanf("%d%d", &xs[i], &ys[i]);

  for (int i = 0; i < n; i++)
    for (int j = n; j < n2; j++)
      if (xs[i] < xs[j] && ys[i] < ys[j]) nbrs[i].push_back(j);

  int cnt = max_match(n2, n, nbrs);
  printf("%d\n", cnt);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;

#define DE 1
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(__typeof__(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}


const int MAX = 1000100;
int t, n;


long long Phi[MAX];
void Euler(int n) {
    for (int i = 0; i <= n; ++i) Phi[i] = i;
    for (int i = 2; i <= n; ++i) {
        if (Phi[i] == i) {
            for (int j = i; j <= n; j += i) Phi[j] = Phi[j] / i *(i-1);
        }
    }
}

int main() {
    Euler(MAX-1);
    Phi[1] = 2;
    for (int i = 1; i < MAX; ++i) {
        Phi[i+1] += Phi[i];
    }
    
    cin >> t;
    for (int i = 0; i < t; ++i) {
        scanf("%d", &n);
        printf("%lld\n", Phi[n]);
    }
    
    return 0;
}


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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code

vector<int> g[N];
bool visA[N];
bool visT[N];
ll distA[N];
ll distT[N];

// Normal DFS
void dfsA(int curr, int par, int dist)
{
	distA[curr] = dist;
	visA[curr] = 1;
  for(auto x: g[curr])
   {
   		if(visA[x] == 0)
   		{
   			dfsA(x, curr, dist+1);
   		}
   		else
   		{
   			if(distA[x] > (distA[curr] + 1))
   			{
   				dfsA(x, curr, dist+1);
   			}
   		}
   }
}

void dfsT(int curr, int par, int dist)
{
	distT[curr] = dist;
	visT[curr] = 1;
  for(auto x: g[curr])
   {
   		if(visT[x] == 0)
   		{
   			dfsT(x, curr, dist+1);
   		}
   		else
   		{
   			if(distT[x] > (distT[curr] + 1))
   			{
   				dfsT(x, curr, dist+1);
   			}
   		}
   }
}

int main()
{
	int n, u, v;
	cin>>n>>u>>v;
	rep(i, 1, n)
	{
		int x, y;
		cin>>x>>y;
		g[x].pb(y);
		g[y].pb(x);
	}
	dfsA(v, -1, 0);
	dfsT(u, -1, 0);
	ll ans = 0;
	repn(i, 1, n)
	{
		if(distA[i] > distT[i])
		{
			chmax(ans, distA[i] - 1);
		}
	}
	cout<<ans<<endl;
}



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


typedef long long ll;
struct NT{
  vector<bool>isprime;

  ll mod_mult(ll a, ll b, ll m) {
    ll res = 0;
    ll exp = a % m;
    while (b) {
      if (b & 1) {
        res += exp;
        if (res > m) res -= m;
      }
      exp <<= 1;
      if (exp > m) exp -= m;
      b >>= 1;
    }
    return res;
  }

  ll mod_exp(ll a, ll b, ll m) {
    ll res = 1;
    ll exp = a % m;
    while (b) {
      if (b & 1) res = mod_mult(res, exp, m);
      exp = mod_mult(exp, exp, m);
      b >>= 1;
    }
    return res;
  }

  bool miller_rabin(ll n, ll times) {
    if (n < 2) return false;
    if (n == 2) return true;
    if (!(n & 1)) return false;
    ll q = n-1;
    int k = 0;
    while (q % 2 == 0) {
      k++;
      q >>= 1;
    }
    for (int i = 0; i < times; i++) {
      ll a = rand() % (n-1) + 1;
      ll x = mod_exp(a, q, n);
      if (x == 1) continue;
      bool found = false;
      for (int j = 0; j < k; j++) {
        if (x == n-1) {
          found = true;
          break;
        }
        x = mod_mult(x, x, n);
      }
      if (found) continue;
      return false;
    }
    return true;
  }

  ll pollard_rho(ll n, int c) {
    ll x = 2;
    ll y = 2;
    ll d = 1;
    while (d == 1) {
      x = mod_mult(x, x, n) + c;
      y = mod_mult(y, y, n) + c;
      y = mod_mult(y, y, n) + c;
      d = __gcd((x-y >= 0 ? x-y : y-x), n);
    }
    if (d == n) return pollard_rho(n, c+1);
    return d;
  }
};

int sum;

int main(){
  NT N;
  ll n;
  cin>>n;
  while(n--){
    ll a;
    scanf("%ld",&a);
    if(N.miller_rabin(a,2))sum++;
  }
  cout<<sum<<endl;
}


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

#define rp(i,n) for(int i=0;i<n;i++)
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define llrp(i,n) for(long long i=0;i<n;i++)
#define llrep(i,m,n) for(long long i=m;i<=n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define elif else if
#define vcin(a); rp(i,a.size()){cin>>a[i];}
#define vcout(a); rp(i,a.size()){cout<<a[i]<<endl;}

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef string S;
typedef pair<int,int> P;

int modpow(int a,int b,int p){
    if(b==0){
        return 1;
    }elif(b%2==0){
        return modpow((a*a)%p,b/2,p);
    }else{
        return (a*modpow(a,b-1,p))%p;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    S s;
    cin >> s;
    vi num(26);
    rp(i,26){
        num[i]=0;
    }
    rp(i,s.size()){
        num[s.at(i)-'a']++;
    }
    if(s.size()!=26){
        for(char c='a';c<='z';c++){
            if(num[c-'a']==0){
                s+=c;
                cout << s << endl;
                return 0;
            }
        }
    }else{
        if(s=="zyxwvutsrqponmlkjihgfedcba"){
            cout << -1 << endl;
            return 0;
        }
        int p;
        rp(i,s.size()-1){
            if(s.at(s.size()-1-i-1)<s.at(s.size()-1-i)){
                p=s.size()-i-2;
                break;
            }
        }
        char c='z';
        rep(i,p+1,s.size()-1){
            if(s.at(i)>s.at(p)){
                c=(c>s.at(i)?s.at(i):c);
            }
        }
        rp(i,p){
            cout<<s.at(i);
        }
        cout << c << endl;
    }
    return 0;
}


Measured memory_bytes: 256
class Solution:
    def solve(self, A: int, B: int, C: int) -> str:

        s = sorted([A, B, C])

        return s[0] + s[1] + 10*s[2]


if __name__ == '__main__':

    # standard input
    A, B, C = map(int, input().split())

    # solve
    solution = Solution()
    print(solution.solve(A, B, C))


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a){cout<<((a)?"Yes":"No")<<endl;}
void YESNO(int a){cout<<((a)?"YES":"NO")<<endl;}
void AorB(int a,string b,string c){cout<<((a)?b:c)<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    string s,t="";
    int ans=0;
    cin>>s;
    Vs a;
    REP(i,0,s.size()){
        if(s[i]=='A') t+="A";
        else if(s[i]=='B' && s[i+1]=='C'){
            t+="X";
            i++;
        }else{
            if(t!="") a.pb(t);
            t="";
        }
    }
    if(t!="") a.pb(t);
    REP(i,0,a.size()){
        int acnt=0;
        REP(j,0,a[i].size()){
            if(a[i][j]=='A') acnt++;
            if(a[i][j]=='X') ans+=acnt;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
int dp[1005][20005];
tuple<int,int,int> arr[1005];
bool cmp(tuple<int,int,int>a,tuple<int,int,int>b)
{
	return get<0>(a)+get<1>(a)<get<0>(b)+get<1>(b);
}
signed main()
{
	int n,i,j;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		int w,s,v;
		cin>>w>>s>>v;
		arr[i]=make_tuple(w,s,v);
	}
	sort(arr+1,arr+n+1,cmp);
	for(i=1;i<=n;i++)
	{
		int w,s,v;
		tie(w,s,v)=arr[i];
		for(j=1;j<=20000;j++)
		{
			dp[i][j]=/*max*/(dp[i-1][j]/*,dp[i][j-1]*/);
			if(s>=j-w&&j>=w)
			{
			dp[i][j]=max(dp[i-1][j-w]+v,dp[i][j]);
		}
		}
	}
	int x=0;
	for(i=1;i<=20000;i++)
	if(x<dp[n][i])
	x=dp[n][i];
	cout<<x<<"\n";
	/*cout<<dp[n][20000]<<"\n";*/
}

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

using namespace std;

typedef long long ll;

ll ans = 0;ll x;
void add(int a, int b, int sum){
	if(b == a){
		if(sum <= x){
			int s = sum;bool th=false; bool fi = false; bool se = false;
			for(int c = 0; c < a; c++){
				if(s%10==3)th=true;
				else if(s%10==5)fi=true;
				else if(s%10==7)se=true;
				s/=10;
			}
			if(th && fi && se)ans++;
		}
		return;
	}
	int m = 1;
	for(int i = 0; i < b; i++)m*=10;
	add(a,b+1,sum+m*3);
	add(a,b+1,sum+m*5);
	add(a,b+1,sum+m*7);
	return;
}
				

int main(){
	cin >> x;
	ll ch = 10;
	int i;
	for(i = 0; i < 10; i++){
		if(x < ch)break;
		ch*=10;
	}
	for(int j = 3; j <= i+1; j++)add(j,0,0);
	cout << ans << endl;

    return 0;
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

const int mod = 1000000007;

// a^n mod を計算 再帰
ll modpow(ll a,ll n,ll mod){
  if(!n) return 1;
  ll x = modpow(a,n/2,mod)%mod;
  x *=x;
  if(n%2==1)x*=a;
  return x%mod;
}

// a^n mod を計算する bit
ll modpow2(ll a,ll n,ll mod){          // n=45,a=3
  ll res = 1;
  while(n>0){                          //桁数比較 with 000001
    if(n & 1) res = res * a%mod;     // flag たってるところで何乗か済のaかける
    a = a*a%mod;                       //毎度倍々
    n >>=1;                            //右シフト
  }
  return res;
}

ll Cmod(ll n,ll a,ll mod){
  ll nframod=1;
  ll adenomod=1;
  rep(i,a)nframod = (n-i) * nframod%mod;
  reps(i,a)adenomod= i*adenomod%mod;
  return modpow2(adenomod,mod-2,mod)*nframod%mod;
}




int main() {
    int n,a,b;
    cin >> n >> a >> b;
    cout << (modpow(2,n,mod)-Cmod(n,a,mod)-Cmod(n,b,mod)+mod+mod-1)%mod;

}

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

int main()
{
    // int N,M;
    // cin >> N>>M;
    // int Mat[N][M];
    int r, c;
    cin >> r >> c;
    int RC[r+1][c+1];
    for (int i =0; i < r;i++){
        for (int j = 0; j < c; j++){
            cin >> RC[i][j];
        }
    }
    int sum;
    for (int i =0; i < r;i++){
        sum =0;
        for (int j = 0; j < c; j++){
            sum+=RC[i][j];
            cout << RC[i][j] << " ";
        }
        RC[i][c]=sum;
        cout << RC[i][c] <<endl;
    }

    for (int i =0; i < c+1;i++){
        sum =0;
        for (int j = 0; j < r; j++){
            sum+=RC[j][i];
        }
        RC[r][i]=sum;
        if (i != c){
            cout << RC[r][i] << " ";
        }else{
            cout << RC[r][i]<<endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3120
n=int(input())
a=list(map(int,input().split()))
dic1,dic2,freq1,freq2=[0]*(n+1),[0]*(n+1),{},{}
for i,a in enumerate(a,1):
  dic1[i]=i+a
  dic2[i]=i-a
#print(dic1,dic2)
for i in range(n+1):
  if freq1.get(dic1[i],0)==0:
    freq1[dic1[i]]=1
  else:
    freq1[dic1[i]]+=1
    
for i in range(n+1):
  if freq2.get(dic2[i],0)==0:
    freq2[dic2[i]]=1
  else:
    freq2[dic2[i]]+=1
#print(freq1,freq2)
ans=0
for i in range(1,n+1):
    x=dic1[i]
    if freq2.get(x,0)!=0:
        ans+=freq2[x]
        #print(i,x)
        
print(ans)

Measured memory_bytes: 55740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct number {
  int siz, low, high;
  number(): siz(0), low(0), high(0) {
  }
};
int main() {
  do {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
  } while (false);
  int n;
  cin >> n;
  string str;
  cin >> str;
  vector<vector<int> > adj(n);
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[--u].push_back(--v);
    adj[v].push_back(u);
  }
  auto add = [&] (number a, number b) {
    number res;
    res.siz = a.siz + b.siz;
    res.high = a.high + b.high;
    if (a.low > b.low) {
      swap(a, b);
    }
    if (a.high > b.low) {
      res.low = res.high % 2;
    } else {
      res.low = b.low - a.high;
    }
    return res;
  };
  int ans = INT_MAX;
  for (int root = 0; root < n; root++) {
    vector<number> dp(n);
    function<int (int, int, int)> dfs = [&] (int u, int fa, int depth) {
      int res = 0;
      for (int v : adj[u]) {
        if (v != fa) {
          res += dfs(v, u, depth + 1);
          dp[v].low += dp[v].siz;
          dp[v].high += dp[v].siz;
          dp[u] = add(dp[u], dp[v]);
        }
      }
      if (str[u] == '1') {
        dp[u].siz++;
        res += depth;
      }
      return res;
    };
    int result = dfs(root, -1, 0);
    if (!dp[root].low) {
      ans = min(ans, result / 2);
    }
  }
  cout << (ans == INT_MAX ? -1 : ans) << endl;
  return 0;
}


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

using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define all(vec) vec.begin(),vec.end()
#define ff first
#define ss second
#define inf 4e18
#define MOD 1000000007
#define pb push_back
#define for1(low,high,k) for(int i=low;i<high;i+=k)
#define for2(low,high,k) for(int j=low;j<high;j+=k)
#define rev(high,low,k) for(int i=high;i>=low;i-=k) 

string bin(int i,int ans){
	string s;
	while (i>0){
		if (i%2==0) s=s+'0';
		else s=s+'1';
		i=i/2;
	}
	if (s.size()<ans){
		for (int i=s.size();i<ans;i++) s+='0';
	}
	return s;
}

int main(){
	fast;
	lli n,m,x;
	cin>>n>>m>>x;
	vector <lli> cost(n);
	vector <vector <lli> > know(n,vector <lli> (m));
	for (int i=0;i<n;i++){
		cin>>cost[i];
		for (int j=0;j<m;j++) cin>>know[i][j];
	}
	lli ans=pow(2,n);
	lli minn=inf;
	for (int p=0;p<=ans;p++){
		string s=bin(p,n);
		lli c=0;
		vector <lli> vec(m,0);
		for (int i=0;i<n;i++){
			if (s[i]=='1'){
				c+=cost[i];
				for (int j=0;j<m;j++){
					vec[j]+=know[i][j];
				}
			}
		}
		int i;
		for (i=0;i<m;i++){
			if (vec[i]<x) break;
		}
		if (i==m) minn=min(minn,c);
	}
	if (minn==inf) cout<<"-1"<<endl;
	else cout<<minn<<endl;
}

Measured memory_bytes: 4072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
int main() {
    int n, m; scanf("%d%d", &n, &m);
    if(abs(n - m) > 1) { 
        printf("0\n");
        return 0;
    }
    // 同数の場合 N! * M! * 2
    // 1個違いの場合 N! * M!
    ll n_kai = 1;
    ll m_kai = 1;
    for(int i = 1; i <= n; i++) n_kai = (n_kai * i) % MOD;
    for(int i = 1; i <= m; i++) m_kai = (m_kai * i) % MOD;

    ll ans = 1;
    if(n == m) {
        ans = (n_kai * m_kai * 2) % MOD;
    }
    else {
        ans = (n_kai * m_kai) % MOD;
    }
    printf("%lld\n", ans % MOD);
    return 0;
}

Measured memory_bytes: 3792
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;

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

	vector<string> v(n);

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

	sort(v.begin(), v.end());

	for (auto i : v) {
		cout << i;
	}
	cout << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
vector<ll> myints,P,Q;
bool check(vector<ll> &a){
	for(ll i=0;i<a.size();++i){
		if(a[i]!=myints[i])
			return false;
	}
	return true;
}
int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll n;
	cin>>n;
	for(ll i=1;i<=n;++i){
		myints.pb(i);
	}
	for(ll i=1;i<=n;++i){
		ll e;
		cin>>e;
		P.pb(e);
	}
	for(ll i=1;i<=n;++i){
		ll e;
		cin>>e;
		Q.pb(e);
	}
	ll a=1,b=1;
	do{
		if(check(P)){
			break;
		}
		a++;
	}
	while ( std::next_permutation(myints.begin(),myints.end()) );
	sort(myints.begin(),myints.end());
	do{
		if(check(Q)){
			break;
		}
		b++;
	}
	while ( std::next_permutation(myints.begin(),myints.end()) );
	cout<<abs(a-b)<<endl;
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    for (auto &e: s) cin >> e;
    
    for (auto &e: s) sort(e.begin(), e.end());
    
    sort(s.begin(), s.end());
    
    ll ans = 0;
    ll cur = 1;
    for (int i = 1; i<n; i++) {
        if (s[i] != s[i-1]) {
            ans += cur*(cur-1)/2;
            cur = 1;
        } else {
            cur++;
        }
    }
    ans += cur*(cur-1)/2;
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 7680
#include<cstdio>

int W, H, x, y, r;

bool included(){
	if(0 <= x - r && x + r <= W && 0 <= y - r && y + r <= H) return true;
	else return false;
}

int main(void){
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if(included() == true) printf("Yes\n");
	else if(included() == false) printf("No\n");

	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
using ll=long long;
using namespace std;
const ll mod=1e9+7;
int main(){
    ll k;
    cin>>k;
    queue<ll> x;
    rep(i,1,10)x.push(i);
    while(k>=0){
        ll y=x.front();
        x.pop();
        if(y%10>0)x.push(y*10+y%10-1);
        x.push(y*10+y%10);
        if(y%10<9)x.push(y*10+y%10+1);
        k--;
        if(k==0)cout<<y;
    }
}

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

#define ll long long

using namespace std;

void solve() {
    int n;
    cin >> n;

    vector<ll> v(n), deltas;
    for (int i = 0; i < n; ++i)
        cin >> v[i];

    ll cash = 1000, stocks;
    ll mi = v[0], ma = v[0];
    for (int i = 1; i < n; ++i) {
        if (v[i] > ma)
            ma = v[i];
        else if (v[i] < ma) {
            // COMPRA E VENDE
            stocks = (ll) floor((double) cash / (double) mi);
            cash = cash % mi;
            cash += (ll) floor((double) stocks * (double) ma);
            ma = v[i];
            mi = v[i];
        } else if (v[i] < mi) {
            mi = v[i];
        }
    }
    if (ma > mi) {
        // COMPRA E VENDE
        stocks = (ll) floor((double) cash / (double) mi);
        cash = cash % mi;
        cash += (ll) floor((double) stocks * (double) ma);
    }

    cout << cash << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int t = 1;
    // cin >> t;

    while (t--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const double PI = acos(-1.0);

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

	int n;
	cin >> n;
	
	vector<int> a;
	for(int i = 0; i < n; i++) {
		int t;
		cin >> t;
		a.push_back(t);
	}
	
	sort(a.begin(), a.end());
	int min = a[0];
	sort(a.rbegin(), a.rend());
	int max = a[0];
	ll sum = 0;
	for(int i = 0; i < a.size(); i++) {
		sum += a[i];
	}
	
	cout << min << " " << max << " " << sum << "\n";
	
	return 0;
}

Measured memory_bytes: 1336
#include<bits/stdc++.h>
using namespace std;
char s[110];
long long rubbish;
int cnt=0;
int main()
{
	scanf("%s%d",s,&rubbish);
	int n=strlen(s);
	for(int i=0;i<n;i++)
	{
		int num=s[i]-'0';
		if(num==1)
		{
			++cnt;
			if(cnt==rubbish)
			{
				printf("%d\n",num);
				break;
			}
		}
		else
		{
			printf("%d\n",num);
			break;
		}
	} 
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i, n, d;
	int ans = 1;
	
	scanf("%d %d",&d, &n);
	for(i = 0; i < d; i++){
		ans *= 100;
	}
	if(n == 100){
		n++;
	}
	ans *= n;
	printf("%d\n", ans);
	return 0;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    int ans = -1;
    rep2(i,1,1011){
        if(i*8/100==a && i*10/100==b){
            ans = i;
            break;
        }
    }

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

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll popcount(ll x){
  ll res=0;
  for(ll i=0; i<=40; i++){
    if(x>>i&1) res++;
  }
  return res;
}

ll f(ll x){
  if(x==0) return 0;
  ll cnt=popcount(x);
  return 1+f(x%cnt);
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  string s; cin>>s;
  
  ll cnt=0;
  rep(i,n) if(s[i]=='1') cnt++;
  
  vll t1(n+1,1), t2(n+1,1);
  for(ll i=1; i<=n; i++){
    t1[i]=t1[i-1]*2%(cnt+1);
    if(cnt>1) t2[i]=t2[i-1]*2%(cnt-1);
  }
  
  ll f1=0, f2=0;
  for(ll i=0; i<n; i++){
    f1=f1*2+(s[i]=='1');
    f1%=(cnt+1);
    if(cnt>1){
      f2=f2*2+(s[i]=='1');
      f2%=(cnt-1);
    }
  }
  
  // 1度cntのmodを取ってしまえば、その桁数は20未満なので、2回目以降modを取る計算量は定数と見て良い
  // 各iについて、1回目の操作がO(n)となるので、これを高速化する
  // 元のpopcountをcntとするとbit反転後のpopcountはcnt+1かcnt-1のいずれかになる
  // これを利用して、s mod (cnt+1), s mod (cnt-1) を予め求めておき、反転して立つ or 消えるbitを足し引きすることでO(1)で計算する
  // 例えばi bit目が立つならmod cnt+1となるので、(s+1<<i)%(cnt+1) つまり s%(mod+1)+(1<<i)%(cnt+1) が計算できれば良い
  // s%(mod+1)は上で求めたf1である
  // (1<<i)%(mod+1)は上で求めたt1[n-1-i]である
  // NOTE: t1について
  // iは最大2*10^5になるので、これを単にbitシフトするとオーバーフローする
  // そのため各桁ごとにmod cnt+1を求めていく
  // 2進数において今見ている桁の値は前の桁の値*2で求まるので、これに対してmod cnt+1を計算してt1に格納していく
  // t1はt[0]がs[n-1]の値、t[n-1]がs[0]の値に対応している
  
  for(ll i=0; i<n; i++){
    if(s[i]=='1'){
      if(cnt==1) cout<<0<<endl;
      else{
        ll tmp=f2-t2[n-1-i];
        tmp%=(cnt-1);
        if(tmp<0) tmp+=cnt-1;
        ll ans=f(tmp)+1;
        cout<<ans<<endl;
      }
    }else{
      ll tmp=f1+t1[n-1-i];
      tmp%=(cnt+1);
      ll ans=f(tmp)+1;
      cout<<ans<<endl;
    }
  }
  
}

Measured memory_bytes: 6768
#include<iostream>
using namespace std;
long dp[41][402][402];
long n,ma,mb,a[40],b[40],c[40];
long INF=1LL<<50;
main()
{
	cin>>n>>ma>>mb;
	for(int i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
	for(int i=0;i<=n;i++)for(int j=0;j<402;j++)for(int k=0;k<402;k++)dp[i][j][k]=INF;
	dp[0][0][0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=400;j++)
		{
			for(int k=0;k<=400;k++)
			{
				if(dp[i][j][k]==INF)continue;
				dp[i+1][j][k]=min(dp[i][j][k],dp[i+1][j][k]);
				dp[i+1][j+a[i]][k+b[i]]=min(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
			}
		}
	}
	long ans=INF;
	for(int i=1;i<=400;i++)
	{
		for(int j=1;j<=400;j++)
		{
			if(ma*j!=mb*i)continue;
			ans=min(ans,dp[n][i][j]);
		}
	}
	cout<<(ans==INF?-1:ans)<<endl;
}

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

long long comb(long long n, long long r){
  long long ans = 1;
  for(long long i = 0; i < r; i++){
    ans *= n - i;
    ans /= i+1;
  }
  return ans;
}

int main(){
  int n,a,b;
  cin >> n >> a >> b;
  // vector<long long> v(n)
  map<long long, int> mp;
  for(int i = 0; i < n; i++){
    long long t;
    cin >> t;
    if(mp.find(t) == mp.end()){
      mp.insert({t, 1});
    }else{
      mp[t]++;
    }
  }
  // sort(v.begin(), v.end(), greator<long long>());
  // for(auto itr = mp.rbegin(); itr != mp.rend(); itr++){
  //   cout << itr->first << "  " << itr->second << endl;
  // }
  long long sum = 0;
  int kosuu = 0;
  long long ans = 1;
  bool flag = false;
  for(auto itr = mp.rbegin(); itr != mp.rend(); itr++){
    if(a <= itr->second){
      // 終わり.
      sum += a * itr->first;
      kosuu += a;

      long long tmp = 0;
      if(flag){
        tmp += comb(itr->second, a);
      }else{
        for(int t = a; t <= b; t++){
          tmp += comb(itr->second, t);
        }
      }
      ans = tmp;
      break;
    }else{
      sum += itr->first * itr->second;
      kosuu += itr->second;
      a -= itr->second;
      b -= itr->second;
      flag = true;
    }
  }

  cout << fixed << (double)sum / kosuu << endl;
  cout << ans << endl;
}


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

//00c
//00b
int main(void) {
  int n, k, i, cou=0, tmp;
  scanf("%d", &n);
  int a[n];
  for(i=0; i<n; i++){
    scanf("%d", &a[i]);
    if(a[i]%2==1 && i%2==0)cou++;
  }
  printf("%d", cou);
}

Measured memory_bytes: 1728
import java.util.*; 
import java.lang.*; 

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		long K = scan.nextInt();
		int N = scan.nextInt();
			
		long[] A = new long[N];
		long[] P = new long[N+1];
		
		long Ans = 0;
		
		for(int i=0; i<N;i++){
			A[i] = scan.nextInt();
		}
		
		for(int i=1; i<N;i++){
			P[i-1] = A[i] -A[i-1];
		}
		
		P[N-1] = K - A[N-1] + A[0];
		
		long max = 0;
		
		for(int i=0; i<=N;i++){
			if(max<=P[i]){
				max = P[i];
			}
		}
		
		for(int i=0; i<=N;i++){
			Ans = Ans + P[i];
		}
		
		Ans = Ans - max;
			
		System.out.println(Ans);
	}
}

Measured memory_bytes: 89044
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include <bitset>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<string>
typedef long long ll;
using namespace std;
#define maxn 1e9;
int a, b;
int main() {
	cin >> a >> b;
	if (a > 0) {
		cout << "Positive" << endl;
	}
	else if (b >= 0 ) {
		cout << "Zero" << endl;
	}
	else if (a == b) {
		cout << "Positive" << endl;
	}
	else {
		if ((abs(a) + abs(b) )% 2==0) {
			cout<<"Negative"<<endl;
		}
		else {
			cout << "Positive" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
	BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
        boolean bPrime[] = new boolean[1000000];
        int pNum,num;
        String buf;
        
        Arrays.fill(bPrime,true);
        bPrime[0] = false;
        bPrime[1] = false;
       
        for(int i = 2;i < bPrime.length;i++){  
        	 
        	for(int j=2*i;j<bPrime.length;j+=i)
        		bPrime[j] = false;	
        }
     
        while((buf= br.readLine())!=null)
        {
        	num = Integer.parseInt(buf);
        	pNum = 0;
        	for(int i=2;i<=num;i++){
        		if(bPrime[i])
        			pNum++;
        	}
        	System.out.println(pNum);
        }
	}
}

Measured memory_bytes: 25944
N = gets.chomp.to_i
A = Array.new(N) { Array.new }
N.times do |i|
  a = gets.chomp.to_i
  a.times do
    A[i].push(gets.chomp.split.map(&:to_i))
  end
end

ans = 0
[0, 1].repeated_permutation(N) do |arr| # 0:嘘つき, 1:正直者
  next_flag = false
  A.each_with_index do |a, index|
    a.each do |x, y|
      if arr[index] == 1 && arr[x-1] != y # 矛盾がある時(正直者の証言が間違っている時)
        next_flag = true
        break
      end
    end
    break if next_flag
  end
  next if next_flag
  num = arr.inject(:+)
  ans = num if num > ans
end
p ans


Measured memory_bytes: 3964
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    ll n, X; cin>>n>>X;
    vector<ll> x(n);
    for(int i=0; i<n; i++) cin>>x[i];

    vector<ll> xsum(n+10, 0);
    for(int i=0; i<n; i++){
        xsum[i+1] = xsum[i] + x[i];
    }

    double ans = INF;
    // The Number of Round Trips
    for(ll i=1; i<=n; i++){
        ll numOdd = 5;
        // First Collection
        double sum = numOdd * (xsum[n] - xsum[max(0LL, n - i * 2)]);
        sum += i * X + n * X;

        // Simulate
        for(ll j=max(0LL, n-i*2); j>=0; j-=i){
            numOdd += 2;
            sum += numOdd * (xsum[j] - xsum[max(0LL, j - i)]);
        }

        chmin(ans, sum);
    }

    cout << (ll)ans << endl;
}

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

int main() {
    int N, res, A, B;
    A = 0;
    B = 0;

    cin >> N;

    vector <int> vec(N);
    for (int i = 0; i < N; i++){
        cin >> vec[i];
    }

    for (int i = 0; i < N/2 + 1; i++){
        int max = *max_element(vec.begin(), vec.end());
        int max_ind = max_element(vec.begin(), vec.end()) - vec.begin();
        A += max;
        vec[max_ind] = 0;

        max = *max_element(vec.begin(), vec.end());
        max_ind = max_element(vec.begin(), vec.end()) - vec.begin();
        B += max;
        vec[max_ind] = 0;
    }

    cout << A - B << endl;
}

Measured memory_bytes: 256
def is_lunlun(n):
    m = str(n)
    for i in range(1,len(m)):
        if abs(int(m[i]) - int(m[i-1])) > 1:
            return False
    return True

def main():
    K = int(input())
    A = [format(str(i),"0>5") for i in range(100000) if is_lunlun(i)]
    B = [int(a1+a2) for a1 in A for a2 in A if int(a1+a2) < 3234566668 and is_lunlun(int(a1+a2))]
    B2 = sorted(set(B))
    print(B2[K])

if __name__ == "__main__":
    main()

Measured memory_bytes: 13276
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> a(H,vector<char>(W));
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> a[i][j];
    }
  }
  
  vector<bool> cols(H,false);
  vector<bool> rows(W,false);
  
  
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if(a[i][j]=='#'){
        cols[i] = true;
        rows[j] = true;
      }
    }
  }

  for (int i = 0; i < H; i++){
    if(cols[i]){
      for (int j = 0; j < W; j++){
        if(rows[j]){
          cout << a[i][j];
        }
      }
      cout << endl;
    }
  }
  
}

Measured memory_bytes: 256
n,m = map(int, input().split())

diff=abs(n-m)
if diff < -1 or diff > 1:
    print(0)
    exit()

def factmod(n,mod):
    result=1
    for i in range(1,n+1):
        result*=i
        result = result % mod
    return result % mod

from math import factorial
res =  factmod(n,7+10**9)*factmod(m,7+10**9)
if diff==0:
    res*=2
res = res%(7+10**9)
print(res)

Measured memory_bytes: 3064