akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vl vector<ll>
typedef long long int ll;
typedef long double ld;
using namespace std;

//-------------------------------------------------------------------
#define MAX_N 1000000
int par[MAX_N];
int dep[MAX_N];

void init(int nu) {
  for(int iu=0;iu<nu;iu++){
    par[iu] = iu;
    dep[iu] = 0;
  }
}
int find(int xu){
  if(par[xu] == xu) return xu;
  return par[xu] = find(par[xu]);
}
void unite(int xu, int yu){
  xu=find(xu);
  yu=find(yu);
  if(xu == yu) return;
  if(dep[xu] < dep[yu]){
    par[xu] = yu;
  }else{
    par[yu] = xu;
    if(dep[xu] == dep[yu]) dep[xu]++;
  }
}
bool same(int xu, int yu){
  return find(xu) == find(yu);
}
//-------------------------------------------------------------------
int main(int argc, char const *argv[]) {
  ll n, m, a, b;
  std::cin >> n >> m;
  init(n+2);
  std::vector<ll> v(n);
  for(int i=0;i<n;i++) std::cin >> v[i];
  for(int i=0;i<m;i++){
    std::cin >> a >> b;
    unite(a, b);
  }
  std::vector<set<ll>> st(n+1);
  for(int i=0;i<n;i++) st[find(i+1)].insert(v[i]);
  ll ans = 0;
  for(int i=0;i<n;i++) if(st[find(i+1)].size()!=0&&st[find(i+1)].find(i+1)!=st[find(i+1)].end()) ans++;
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 12544
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var (N, X) = ReadLine().Split(' ').Select(int.Parse).ToArray();
        var x = ReadLine().Split(' ').Select(int.Parse).ToArray();

        var ans = x.Select(n => Math.Abs(n - X)).GcdAll();

        WriteLine(ans);
    }
}

static partial class MathExt
{
    public static int GcdAll(this IEnumerable<int> a) => (int)GcdAll(a.Select(x => (long)x));
    public static long GcdAll(this IEnumerable<long> a) => a.Aggregate((s, e) => Gcd(s, e));
    public static int Gcd(int a, int b) => (int)Gcd((long)a, b);
    public static long Gcd(long a, long b) => (b != 0) ? Gcd(b, a % b) : a;
    public static long Lcm(long a, long b) => a / Gcd(a, b) * b;
}

static class ArrayDeconstructExtensions
{
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2) => (i1, i2) = (a[0], a[1]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3) => (i1, i2, i3) = (a[0], a[1], a[2]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4) => (i1, i2, i3, i4) = (a[0], a[1], a[2], a[3]);
    public static void Deconstruct<T>(this T[] a, out T i1, out T i2, out T i3, out T i4, out T i5) => (i1, i2, i3, i4, i5) = (a[0], a[1], a[2], a[3], a[4]);
}


Measured memory_bytes: 38472
#include<iostream>
#include<numeric>
#include<cmath>
long long euclidean_gcd(long long, long long);
long long lcm(long long, long long);

int main(void){
	long long a, b;
	std::cin >> a >> b;
	std::cout << lcm(a, b) << std::endl;
	return 0;
}

long long euclidean_gcd(long long a, long long b){
	if(a < b)return euclidean_gcd(b, a);
	long long r;
	while((r = a % b)){
		a = b;
		b = r;
	}
	return b;
}

long long lcm(long long a, long long b){
	long long gcd = euclidean_gcd(a, b);
	//std::cout << b / gcd << std::endl;
	//std::cout << a << std::endl;
	return (b / euclidean_gcd(a, b)) * a;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
typedef long long LL;
int n; LL k;
struct Mat {
	int a[52][52];
	Mat operator*(const Mat&o)const{
		Mat res;
		memset(res.a,0,sizeof(res.a));
		for(int k=1;k<=n;k++){
			for(int i=1;i<=n;i++){
				for(int j=1;j<=n;j++){
					(res.a[i][j]+=1LL*a[i][k]*o.a[k][j]%MOD)%=MOD;
				}
			}
		}
		return res;
	}
} M;
Mat pw(Mat A, LL k){
	if(k==0) {
		memset(A.a,0,sizeof(A.a));
		for(int i=1;i<=n;i++)A.a[i][i]=1;
		return A;
	}
	Mat B = pw(A,k>>1);
	if(k%2==0) return B*B;
	return A*B*B;
}
int main() {
	scanf("%d%lld",&n,&k);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			scanf("%d",&M.a[i][j]);
		}
	}
	M=pw(M,k);
	LL ans=0;
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)(ans+=M.a[i][j])%=MOD;
	cout<<ans<<endl;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 int INF=1001001001;
const int mod=1e9+7;
int main() {
  int N;
  cin>>N;
  vector<int>L(N);
  for(int i=0;i<N;i++){
    cin>>L[i];
  }
  sort(L.begin(),L.end());
  int sum=0;
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      int x=L[i]+L[j];
      int r=lower_bound(L.begin(),L.end(),x)-L.begin();
      sum+=r-j-1;
    }
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 3580
import java.util.Scanner;
 
class Main {
	int n;
	int m;
	boolean[] a;
	long[] step;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
	}
	Main(Scanner sc){
		n = sc.nextInt();
		m = sc.nextInt();
		a = new boolean[n+1];
		step = new long[n+1];
		for(int i = 0; i <= n;i++){
			step[i] = 0;
			a[i] = false;
		}
		for(int i=0;i<m;i++){
			a[sc.nextInt()] = true;
		}
		step[0] = 1;
	}
	void solve(){
		for(int i = 1;i<=n;i++){
			if(a[i]) continue;
			step[i] = step[i-1];
			if(i>1) step[i] += step[i-2];
			step[i]%=1000000007;
		}
		System.out.println(step[n]);
	}
}

Measured memory_bytes: 48068
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int a, b, c, sm;
	cin >> a >> b >> c;
	sm = a + b;
	if (a + c < sm)sm = a + c;
    if (b + c < sm)sm = b + c;
	cout << sm << endl;
	int z;
	cin >> z;
}

Measured memory_bytes: 256
from sys import stdin
import math


[A, B] = list(map(int, stdin.readline().rstrip().split()))

def isKaibun(n):
    s = str(n)
    for i in range(len(s)//2):
        if s[i] == s[-(i+1)]:
            continue
        else:
            return False
    return True


count = 0
for i in range(A,B+1):
    if isKaibun(i):
        count = count + 1

print(count)



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

namespace Day_of_Week
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] week = { "thu", "fri", "sat", "sun", "mon", "tue", "wed"};

            int day = 0;

            while (day < 1 || day > 30)
            {
                day = int.Parse(Console.ReadLine());
            }

            int weekday = day % 7;
            Console.WriteLine(week[weekday]);
        }
    }
}



Measured memory_bytes: 15960
using System;

class CF2016QBA
{
	static public void Main(string[] args)
	{
		string S = Console.ReadLine();
		string cf = "CODEFESTIVAL2016";

		int ans = 0;
		for(int i=0; i < 16; i++)
		{
			if(S[i] != cf[i])
				ans++;
		}
		Console.WriteLine(ans);
	}
}


Measured memory_bytes: 13140
from collections import deque

def connected_components(U, C):
    no = 1

    for i in range(len(U)):
        if C[i] == None:
            depth_first_serch(U, C, i, no)
            no += 1

def depth_first_serch(U, C, r, no):
    S = list()
    S.append(r)

    while len(S) != 0:
        current = S[-1]
        
        if len(U[current]) != 0:
            v = U[current].popleft()
            if C[v] == None:
                C[v] = no
                S.append(v)
        else:
            C[current] = no
            S.pop()

def Main():
    N, M = map(int, input().split())
    Users = [deque() for n in range(N)]
    Color = [None for n in range(N)]

    for m in range(M):
        s, t = map(int, input().split())
        Users[s].append(t)
        Users[t].append(s)

    connected_components(Users, Color)

    Q = int(input())

    for q in range(Q):
        s, t = map(int, input().split())
        if Color[s] == Color[t]:
            print("yes")
        else:
            print("no")

Main()


Measured memory_bytes: 78256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  cin >> a >> b;
  
  int ans=0;
  if(a>=b)
    for(int i = 0; i < a; i++)
      ans +=pow(10,i)*b ;
  else
    for(int i = 0; i< b; i++)
      ans +=pow(10,i)*a;
  cout << ans << endl;
}

Measured memory_bytes: 256
//
// Created by yamunaku on 2019/12/29.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    int n;
    cin >> n;
    int ans=0;
    rep(i,n){
        string s;
        cin >> s;
        if(s=="E869120") ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define US unordered_set
#define ALL(a) (a).begin(),(a).end()
const ll INF = (1ll << 60);

ll maxFlow(vvi& G,ll s,ll t) {
  ll N=G.size();
  vvi F(N,vi(N));
  while(1) {
    vi dist(N,INF);
    vi prev(N,-1);
    dist[s]=0;
    prev[s]=s;
    queue<ll> q;
    q.push(s);
    while(q.size()) {
      ll from=q.front();
      q.pop();
      REP(to,N) {
        if(G[from][to]>F[from][to]) {
          if(prev[to]==-1) {
            prev[to]=from;
            dist[to]=dist[from]+1;
            q.push(to);
          }
        }
        if(F[to][from]) {
          if(prev[to]==-1) {
            prev[to]=from;
            dist[to]=dist[from]+1;
            q.push(to);
          }
        }
      }
    }
    if(dist[t]==INF) {
      ll ret=0;
      for(ll f:F[s]) ret+=f;
      return ret;
    }
    vi route;
    route.PB(t);
    for(ll cur=t;cur!=s;cur=prev[cur]) {
      route.PB(prev[cur]);
    }
    reverse(ALL(route));
    ll newF=INF;
    REP(i,(ll)route.size()-1) {
      ll from=route[i];
      ll to=route[i+1];
      newF=min(newF,max(G[from][to]-F[from][to],F[to][from]));
    }
    REP(i,(ll)route.size()-1) {
      ll from=route[i];
      ll to=route[i+1];
      if(G[from][to]-F[from][to]>=newF) {
        F[from][to]+=newF;
      }else {
        F[to][from]-=newF;
      }
    }
  }
}

int main(){
  ll V,E; cin>>V>>E;
  vvi G(V,vi(V));
  REP(i,E) {
    ll s,t,c; cin>>s>>t>>c;
    G[s][t]=c;
  }
  cout<<maxFlow(G,0,V-1)<<endl;
}

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

#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)


int main(){
  int ans=0;
  vector<int> a(5),b;
  rep(i,5){
    cin >> a[i];
    if(a[i]%10 == 0){
      ans += a[i];
    }else{
      ans += a[i]+10-a[i]%10;
      b.push_back(a[i]%10);
    }
    //cout << ans << endl;
  }
  if(b.size()==0){
    cout << ans << endl;
    return 0;
  }
  sort(all(b));
  ans -= 10-b[0];
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  
  set<string> s;
  string str;
  while(n>0){
    cin >> str;
    s.insert(str);
    n--;
  }
  
  cout << s.size() << endl;
  
  return 0;
}

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

const int M = 1000005;
int main() {
    int n; cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    vector<int> cnt(M, 0);
    rep(i, n){
        if(cnt[a[i]] != 0){
            cnt[a[i]] = 2;
            continue;
        }
        for(int j = a[i]; j < M; j+=a[i]) cnt[j]++;
    }

    int ans = 0;
    rep(i, n){
        if(cnt[a[i]] == 1) ans++;
    }
    cout << ans << endl;

    return 0;
}

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

int main()
{
    string S;
    cin>>S;

    if(S.length()>=4&&S[0]=='Y'&&S[1]=='A'&&S[2]=='K'&&S[3]=='I'){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    def main():
        N=int(input())
        A=list(map(int,input().split()))
        if 0 in A:
            return 0
        else:
            i=0
            ans=1
            for i in range(N):
                ans*=A[i]
                i+=1
                if ans>10**18:
                    ans=-1
                    break
            return ans
    print(main())
    
    
resolve()

Measured memory_bytes: 84480
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    string S;
    int N;
    cin >> N;
    cin >> S;
    int ans = 0;
    for(int i = 0; i < S.size();i++){
        if(S.substr(i,3)=="ABC")ans++;
    }
    cout << ans <<endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	c := make([][10]int, 10)
	for i, v := range c {
		for j := range v {
			fmt.Scan(&c[i][j])
		}
	}

	for k := 0; k < 10; k++ {
		for i := 0; i < 10; i++ {
			for j := 0; j < 10; j++ {
				if c[i][j] > c[i][k]+c[k][j] {
					c[i][j] = c[i][k] + c[k][j]
				}
			}
		}
	}

	result := 0
	for i := 0; i < h*w; i++ {
		var a int
		fmt.Scan(&a)

		if a >= 0 {
			result += c[a][1]
		}
	}

	fmt.Println(result)
}


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

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 2020;
int a[N][N];
int m, n;
int ans = 0;

int getSum(int x1, int y1, int x2, int y2) {
	return a[x2][y2] + a[x1][y1] - a[x2][y1] - a[x1][y2];
}

int solve(int x, int y) {
	if (x <= n)
		return getSum(x, y, x + n, n) + getSum(0, 0, x, y) + getSum(x + n, 0, 2 * n, y);
	else
		return getSum(0, y, x - n, n) + getSum(x - n, 0, x, y) + getSum(x, y, 2 * n, n);
}

int main()
{

	scanf("%d%d", &m, &n);
	while(m--) {
		int x, y;
		char c;
		scanf("%d%d %c", &x, &y, &c);
		if (c == 'W')
			x += n;
		x %= 2 * n;
		y %= 2 * n;
		if (y >= n) {
			x += n;
			y -= n;
		}
		x %= 2 * n;
		a[x + 1][y + 1]++;
	}

	for (int x = 1; x < N; x++)
		for (int y = 1; y < N; y++)
			a[x][y] += a[x - 1][y] + a[x][y - 1] - a[x - 1][y - 1];

	for (int x = 0; x < 2 * n; x++)
		for (int y = 0; y < n; y++) {
			ans = max(ans, solve(x, y));
		}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 16128
N = int(input())
table = [0]*(N+2)
def factorize2(n): # 素因数分解　2次元素数リスト([素数,指数])
    i = 2
    m = 1
    
    sign = -1
    while i * i <= n:
        j = 0
        while n % i == 0:
            n //= i
            j += 1
        if j != 0:
            table[i] += j
        if i >= 5:
            if sign < 0:
                sign = 1
                i = 6*m + sign
            else:
                m += 1
                sign = -1
                i = 6*m + sign
        elif i == 2:
            i += 1
        elif i == 3:
            i = 5
    if n > 1:
        table[n] += 1
    return table # list


for i in range(2,N+1):
    factorize2(i)
ans = 1
for i in range(len(table)):
    if table[i] > 0:
        ans *= table[i]+1
        ans %= 10**9+7

print(ans)


Measured memory_bytes: 3064
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>

int IsYakusu8(int num);

int main()
{
    int N;
    std::cin >> N;
    
    int okCount = 0;
    
    for (int i = 1; i <= N; i=i+2) {
        okCount += IsYakusu8(i);
    }
    
    std::cout << okCount << std::endl;
}

int IsYakusu8(int num) {
    int count = 0;
    
    for (int i = 1; i <= num; i++) {
        if (num % i  == 0) count++;
    }
    if (count == 8)
        return 1;
    else
        return 0;
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://msdn.microsoft.com/library/3bstk3k5.aspx
//   http://www.cplusplus.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   http://www.boost.org/doc/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn=300005;
int a[maxn];
int chk(int l,int r){
  static int q[maxn];
  //printf("chk %d %d\n",l,r);
  int mx=1,mn=maxn;
  for(int i=l;i<=r;i++){
    mx=max(mx,a[i]);
    mn=min(mn,a[i]);
  }
  if(mx!=r||mn!=l)return 0;
  int top=0;
  for(int i=l;i<=r;i+=2){
    int x=top;
    for(;x&&a[i]>a[q[x]];x--);
    if(x==top)top++;
    if(top==3)return 0;
    q[++x]=i;
  }
  return 1;
}
int main(){
  //freopen("aa.in","r",stdin);
  int n;scanf("%d",&n);
  for(int i=1;i<=n;i++){
    scanf("%d",a+i);
  }
  for(int i=1;i<=n;i++)if(a[i]!=i){
    int j=i+2;
    for(;j<=n&&a[j]!=j&&a[j-1]==j-1;j+=2);j-=2;
    if(!chk(i,j))return puts("No"),0;
    i=j;
  }
  puts("Yes");
  return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;

int main(){
    ll n,m;cin >>n>>m;
    if(m%2==0){
        ll l=1,r=m;
        for (int i = 1; i <=m/2 ; ++i) {
            cout <<l<<" "<<r<<endl;
            l++;r--;
        }
        l=m+1;r=2*m+1;
        for (int i = 1; i <=m/2 ; ++i) {
            cout <<l<<" "<<r<<endl;
            l++;r--;
        }
    }
    if(m%2==1){
        ll l=1,r=m;
        for (int i = 1; i <=m/2 ; ++i) {
            cout <<l<<" "<<r<<endl;
            l++;r--;
        }
        l=m+1;r=2*m+1;
        for (int i = 1; i <=(m+1)/2 ; ++i) {
            cout <<l<<" "<<r<<endl;
            l++;r--;
        }
    }
    return 0;
}

Measured memory_bytes: 3608
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

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

		int n = Integer.parseInt(sc.next());
		Map<String,Integer> map = new HashMap<String, Integer>();
		List<Integer> values = new ArrayList<Integer>();
		List<String> ans = new ArrayList<String>();
		
		for(int i = 0 ; i < n ; i++) {
			String s = sc.next();

			if(map.containsKey(s)) {
				map.put(s, map.get(s)+1);
			}else {
				map.put(s,1);
			}

		}

		
		map.entrySet().stream()
		.sorted(java.util.Map.Entry.comparingByKey())
		.sorted(java.util.Collections.reverseOrder(java.util.Map.Entry.comparingByValue()))
		.forEach(s -> {
			values.add(s.getValue());
			ans.add(s.getKey());
			
			
		});

		
		int cnt = values.get(0);
		for(int i = 0 ; i < values.size() ; i++) {
			if(cnt == values.get(i)) {
				System.out.println(ans.get(i));
				
			}else {
				break;
			}
			
			
		}
		
	}



}

Measured memory_bytes: 88796
n,*a=map(int,open(0).read().split())
s=max(a)+10
d=[0]*s
ans=0
for i in a:
  d[i]+=1
for i in range(1,s):
  if d[i]:
    if d[i]==1:
      ans+=1
    for j in range(i,s,i):
      d[j]=0
print(ans)

Measured memory_bytes: 118928
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let n: usize = read!();
    let k: usize = read!();
    let ans = if k==1{0}else{ n - k};
    println!("{}", ans);
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

bool Less(const string& a, const string& b) {
  if (a.size() != b.size()) return a.size() < b.size();
  return a < b;
}

int main() {
  const vector<int> cost = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  in(int, n, m);

  vector<int> a(m);
  rep(i, m) cin >> a[i];

  vector<string> dp(n + 1);
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j < m; ++j) {
      int k = i - cost[a[j]];
      if (k < 0 || dp[k] == "" && k != 0) continue;
      string d = char('0' + a[j]) + dp[k];
      if (Less(dp[i], d)) dp[i] = d;
    }
  }
  out(dp[n]);
}


Measured memory_bytes: 51064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <utility>
using namespace std;
#define fol(i,n) for (int i=0;i<n;i++)

int main(){
    string s;
    cin >>s;
    s.replace(5,1," ");
    s.replace(13,1," ");
    cout <<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define repi(i,a,b) for(int i = (a);i < (b); i++)
#define rep(i,a) repi(i,0,a)
#define repd(i,a,b) for(int i = (a); i >= (b); i--)
#define repit(i,a) for(__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)

#define all(u) (u).begin(),(u).end()
#define rall(u) (u).rbegin(),(u).rend()
#define UNIQUE(u) (u).erase(unique(all(u)),(u).end())

#define pb push_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
#define PI acos(-1.0)

using namespace std;

typedef long long ll;
typedef vector<int> vi;

void topological_sort(vector<vi> &G, vi &in, vi & v){
  int n = in.size();
  v.clear();
  queue<int> q;
  rep(i,n) if(!in[i]) q.push(i);
  vector<bool> done(n);
  bool ok = true;
  int cnt = 0;
  while(!q.empty()){
    if(q.size() > 1) ok = false;
    int now = q.front(); q.pop();
    if(done[now]) continue;
    done[now] = true;
    cnt++;
    v.pb(now);
    rep(i,G[now].size()){
      in[G[now][i]]--;
      if(!in[G[now][i]]) q.push(G[now][i]);
    }
  }
}

ll sq(ll a) { return a * a; }
ll dst(ll x1, ll y1, ll x2, ll y2) { return sq(x1 - x2) + sq(y1- y2); }


struct circle {
  ll x, y, r;
};
bool contain(circle c1, circle c2) {
  ll d2 = dst(c1.x, c1.y, c2.x, c2.y);
  if(c1.r <= c2.r) return false;
  return d2 < sq(c1.r - c2.r);
}

bool intersect(circle c1, circle c2) {
  ll d2 = dst(c1.x, c1.y, c2.x, c2.y);
  return d2 <= sq(c1.r + c2.r);
}

int n;
ll xs, ys, xt, yt;
vector<circle> A, B;
vector<ll> x, y, r;
vector<vector<int> > G;
int BASE;
int main(){
  while(cin >> n, n) {
    cin >> xs >> ys >> xt >> yt;
    x.resize(n);
    y.resize(n);
    r.resize(n);
    rep(i, n) cin >> x[i] >> y[i] >> r[i];
    A.clear(); B.clear();
    rep(i, n) {
      bool f1 = (dst(x[i], y[i], xs, ys) < r[i] * r[i] );
      bool f2 = (dst(x[i], y[i], xt, yt) < r[i] * r[i] );
      if(f1 && !f2) {
	A.pb((circle){x[i], y[i], r[i]});
      } else if(!f1 && f2) {
	B.pb((circle){x[i], y[i], r[i]});
      }
    }
    BASE = A.size();

    G.clear();
    G.resize(BASE + B.size() + 2);
    int s = BASE + B.size();
    int t = s + 1;

    
    rep(i, A.size()) G[i].pb(t);
    rep(i, B.size()) G[s].pb(i+BASE);

    rep(i, A.size()) G[s].pb(i);
    rep(i, B.size()) G[i+BASE].pb(t);
    G[s].pb(t);

    // rat to lair
    rep(i, A.size()) rep(j, A.size()) if(i != j) {
      if(contain(A[i], A[j])) G[j].pb(i);
    }

    // lair to cat
    rep(i, A.size()) rep(j, B.size()) {
      if(!intersect(A[i], B[j])) G[i].pb(j + BASE);
    }

    // cat to fish
    rep(i, B.size()) rep(j, B.size()) if(i != j) {
      if(contain(B[i], B[j])) G[i + BASE].pb(j + BASE);
    }

    vector<int> in(G.size());
    rep(i, G.size()) rep(j, G[i].size()) in[G[i][j]]++;
    vector<int> v;
    topological_sort(G, in, v);
    
    vector<ll> len(G.size());
    rep(i, v.size()) {
      rep(j, G[v[i]].size()) len[G[v[i]][j]] = max(len[G[v[i]][j]], len[v[i]] + 1);
    }
    cout << len[t] - 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 4064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define fi first
#define se second
#define bigger (char)toupper
#define smaller (char)tolower
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<char> vc;
typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N;
    cin>>N;
    vi h(N);
    rep(i,N) cin>>h[i];
    vi dp(N);
    dp[0]=h[0];
    rep(i,N-1) {
        dp[i+1]=dp[i]+max(0,h[i+1]-h[i]);
    }
    cout<<dp[N-1]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
const int N=5e5+10;
//vector<pair<int,int> >E[maxn];
int mp[1005][1005];
int n,m,s,t;
int vis[maxn];
int d[maxn];
struct node{
	int to;
	int next;
	int dis;
}edge[N];
priority_queue<pair<int,int> >q;
int head[N],num_edge,u,v,_d,base,dist[N];
queue<int>Q;//编号队列 
void edge_add(int from,int to,int dis){
	edge[++num_edge].next=head[from];
	edge[num_edge].to=to;
	edge[num_edge].dis=dis;
	head[from]=num_edge;
}
void djs(int s){
    memset(vis,0,sizeof(vis));
    //vis[i] 为1表示点i属于S集合 为0表示点i属于T集合
    memset(d,0x3f3f3f3f,sizeof(d));
    d[s]=0;
    q.push(make_pair(0,s));
    while(!q.empty()){
    	int x=q.top().second;
    	q.pop();
    	if(vis[x])continue;
    	vis[x]=1;
    	for(int i=head[x];i;i=edge[i].next){
    		int y=edge[i].to;
    		int z=edge[i].dis;
    		if(d[y]>d[x]+z){
    			d[y]=d[x]+z;//松弛
				q.push(make_pair(-d[y],y)); 
			}
		}
    	
	}
}
map<int,int>mpp;
int main()
{
    int x,y;
    cin>>n>>x>>y;
    num_edge=0;
    int u,v,w;
    memset(mp,0x3f3f3f3f,sizeof(mp));
    for(int i=1;i<n;++i){
        u=i;
        v=i+1;
        w=1;
        edge_add(u,v,w);
        edge_add(v,u,w);
		//mp[u][v]=w;
        //E[u].push_back(make_pair(v,w));
        //E[v].push_back(make_pair(u,w));
    }
     ///for(int i=1;i<n;++i){
        u=x;
        v=y;
        w=1;
        edge_add(u,v,w);
        edge_add(v,u,w);
    for(int i=1;i<=n;++i){
    	djs(i);
        for(int j=i+1;j<=n;++j){
            mpp[d[j]]++;
        }
	}
    for(int i=1;i<n;++i){
        cout<<mpp[i]<<"\n";
    }
    return 0;
}



Measured memory_bytes: 11904
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  int n;
  cin >> n;
  int res[10] = {};
  for (int i = 0; i < n; ++i) {
    int nr[10] = {};
    int t;
    cin >> t;
    nr[t % 10] = res[0] + t;
    for (int j = 0; j < 10; ++j) {
      if (j == 0 || res[j]) {
        nr[(t + j) % 10] = max(res[(t + j) % 10], res[j] + t);
      }
    }
    for (int j = 0; j < 10; ++j) res[j] = nr[j];
  }
  res[0] = 0;
  int ans(0);
  for (const int& i: res) ans = max(ans, i);
  cout << ans;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
ans=-1
c=[[0]*10 for _ in range(11)]
for i in range(n+1):
  c[int(str(i)[0])][int(str(i)[-1])]+=1
for i in range(10):
  for j in range(10):
    ans+=c[i][j]*c[j][i]
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

int MOD = 998244353;
// int MOD = 1000000007;

//----------------------------------------------------------------
signed main(){
   
    int n;
	cin >> n;
	vll d(n);
	rep(i,n)cin >> d[i];
	ll ans = 0;
	rep(i,n){
		rep(j,n){
			if(i>j)ans += d[i]*d[j];
		}
	}
	cout << ans << endl;
	
	return 0;
}

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

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://nikkei2019-2-qual.contest.atcoder.jp/tasks/nikkei2019_2_qual_b
// rm -r -f test;oj dl https://abc143.contest.atcoder.jp/tasks/abc143_a

Measured memory_bytes: 256
namespace Coder {
  class Scanner {
    private buffer: string = '';
    private stdinQueue: any = [];

    constructor() {
      process.stdin.resume();
      process.stdin.setEncoding('utf8');
      process.stdin.on(
        'data',
        (chunk): void => {
          this.buffer += chunk;
          while (this.stdinQueue.length > 0) {
            const i = this.buffer.indexOf('\n');
            if (i < 0) {
              break;
            }
            let line = this.buffer.substr(0, i);
            if (line.endsWith('\r')) {
              line = line.slice(0, -1);
            }
            this.buffer = this.buffer.substr(i + 1);
            this.stdinQueue.shift()(line);
          }
        },
      );
    }
    public getLine(): Promise<string> {
      return new Promise((resolve, reject) => {
        const i = this.buffer.indexOf('\n');
        if (i >= 0 && this.stdinQueue.length === 0) {
          let line = this.buffer.substr(0, i);
          if (line.endsWith('\r')) {
            line = line.slice(0, -1);
          }
          this.buffer = this.buffer.substr(i + 1);
          resolve(line);
        } else {
          this.stdinQueue.push(resolve);
        }
      });
    }

    public close(): void {
      process.stdin.pause();
    }
  }

  async function solve() {
    const sc = new Scanner();
    const S: string[] = (await sc.getLine()).split('');
    const odd: string[] = S.filter((v, i) => i % 2 === 1);
    const even: string[] = S.filter((v, i) => i % 2 === 0);

    const odd1 = odd.filter((x) => x === '1').length;
    const odd0 = odd.filter((x) => x === '0').length;
    const even1 = even.filter((x) => x === '1').length;
    const even0 = even.filter((x) => x === '0').length;

    let ans = 0;
    if (even0 === 0 && odd0 === 0) {
      ans = Math.min(even1, odd1);
    } else if (even1 === 0 && odd1 === 0) {
      ans = Math.min(even0, odd0);
    } else {
      ans = Math.min(odd0 + even1, even0 + odd1);
    }

    console.log(ans);
    sc.close();
  }

  solve();
}


Measured memory_bytes: 16156
// dpの練習
// dpでなく、愚直に組んだプログラミング
// ナップサック問題とほぼ同じ

#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int wei; // 持てる最大の重さ
int n; // お宝の数
int v[1001]; // お宝の価値
int w[1001]; // お宝の重さ
 // グローバル配列は0で初期化されている
int dp[1001][1001]; //メモテーブル

int max_value(int i, int j) {
  int value;

  if( dp[i][j] >= 0 ){
    return dp[i][j];
    //すでに１回は調べている
  }
 
  if (i == n) {
    // 品物がもう残っていないときは、価値の和の最大値は0で確定
    //もうお宝がないつまり、価値は0
    value = 0;
  } else if (j < w[i]) {
    //風呂敷が持てる重さを超えてしまう
    // 残りの容量が足りず品物iを入れられないので、入れないパターンだけ処理
    // i+1 以降の品物のみを使ったときの最大値をそのままこの場合の最大値にする
    value = max_value(i + 1, j);
  } else {
    //左がお宝を入れない、右がお宝を入れた場合
    // 品物iを入れるか入れないか選べるので、両方試して価値の和が大きい方を選ぶ
    value = max( max_value(i + 1, j), max_value(i + 1, j - w[i]) + v[i] );
  } 
  return dp[i][j] = value;
  //メモに記憶させる
}

void max_weight( int ans ){

  int w_min;
   
  for (int i = wei -1 ; i >= 0 ; i--){
    if( ans != max_value( 0 , i ) ){
         w_min = i + 1;
         break;
    }
  }
  cout << w_min << endl;  
}


int main(void){

  int cnt = 1;
  while( cin >> wei ){
    memset( dp , -1 , sizeof(dp) );
    //まだ調べてないところを-1で初期化
    if( wei == 0 )break;
    cin >> n;
    char ten;
    for( int i = 0 ; i < n ; i++ ){
      cin >> v[i] >> ten >> w[i];
    }
    cout << "Case " << cnt << ":" << endl;
    int ans = max_value( 0 , wei );
    cout << ans << endl;
    max_weight(ans);
    cnt++;
  }
  return 0;
}

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

int n;
ll x[MAX];
vector<ll> X;
vector<ll> Y;
vector<ll> ans;

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x[i];
    Y.push_back(x[i] - i);
    X.push_back(x[i]);
    X.push_back(x[i] - i);
  }

  sort(X.begin(),X.end());
  sort(Y.begin(),Y.end());

  ans.resize(X.size());
  
  ll j=0;
  ll sum=0;
  ll cnt=0;
  
  for(int i=0;i<(int)X.size();i++){
    
    ll p=X[i];
    while( j < (int)Y.size() && Y[j]<p){
      j++;
      cnt++;
    }

    if(i>0){
      sum+=abs(X[i]-X[i-1])*cnt;
    }
    ans[ i ] += sum;
  }

  for(int i=0;i<(int)X.size();i++) X[i]*=-1LL;
  for(int i=0;i<(int)Y.size();i++) Y[i]*=-1LL;
  reverse(X.begin(),X.end());
  reverse(Y.begin(),Y.end());
  reverse(ans.begin(),ans.end());
  j=0;sum=0;cnt=0;
  for(int i=0;i<(int)X.size();i++){
    
    ll p=X[i];
    while( j < (int)Y.size() && Y[j]<p){
      j++;
      cnt++;
    }

    if(i>0){
      sum+=abs(X[i]-X[i-1])*cnt;
    }
    ans[ i ] += sum;
  }
  ll mini=ans[0];
  for(int i=0;i<(int)ans.size();i++)
    mini=min(mini,ans[i]);
  cout<<mini<<endl;
  return 0;
}


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

int main(){
  int N,H;
  cin >> N >> H;
  vector<int> A(N,0);
  vector<int> B(N,0);
  for(int i=0;i<N;i++){
    cin >> A[i] >> B[i];
  }
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  reverse(B.begin(),B.end());
  int count=0;
  for(int i=0;i<N;i++){
    if(B[i]>=A[N-1]){
      count ++;
      H -= B[i];
      if(H<=0){
        cout << count << endl;
        return 0;
      }
    }else{
      break;
    }
  }
  if(H%A[N-1]==0){
    count += H/A[N-1];
  }else{
    count += (H/A[N-1]+1);
  }
  cout << count << endl;
  return 0;
}

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

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

// (x, y) を始点とした BFS をして、(x, y) から最も遠いマスへの距離を答える
int bfs(vector<string> &S, int i, int j){
    int H = S.size();
    int W = S[0].size();
    vector<vector<int>> dist(H, vector<int>(W, -1));
    queue<pair<int,int>> que;

    int res = 0;
    que.push({i, j});
    dist[i][j] = 0;
    
    while(que.empty() != true){
        int x = que.front().first;
        int y = que.front().second;
        res = max(res, dist[x][y]);
        que.pop();

        for(int dir=0; dir<4; dir++){
            int nx = x+dx[dir];
            int ny = y+dy[dir];
            
            if(0<=nx && nx<H && 0<=ny && ny<W){
                if(S[nx][ny] == '#'){
                    continue;
                }
                if(dist[nx][ny] == -1){
                    dist[nx][ny] = dist[x][y] + 1;
                    que.push({nx, ny});
                }
            }
        }
    }

    return res;
}


int main(){
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for(int i=0; i<H; i++){
        cin >> S[i];
    }

    int ans = 0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(S[i][j] == '#'){
                continue;
            }else{
                ans = max(ans, bfs(S, i, j));
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::{Write, BufWriter};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[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)*}
    };
}

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

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

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

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

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

fn main() {
    input!(
        a: chars,
        b: chars,
        c: chars,
    );
    if a[a.len()-1] == b[0] && b[b.len()-1] == c[0] {
        println!("YES");
    }
    else {
        println!("NO");
    }
}

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

// Macros
#define F      first
#define S      second
#define PB     push_back
#define MP     make_pair
#define ALL(c) c.begin(),c.end()

// Rename Datatypes
using ll  = long long;
using ld  = long double;
using pii = std::pair <int,int>;

// Random
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/* [a,b] */ template<class T> T rnd_IntType(T a, T b){ return uniform_int_distribution<T>(a, b)(rng); }
/* [a,b) */ template<class T> T rnd_RealType(T a, T b){ return uniform_real_distribution<T>(a,b)(rng); }

// Common Functions
ll fastpow(ll a, ll ex){ ll res = 1; while(ex){ if(ex & 1) res *= a; a *= a; ex >>= 1; } return res; }
ll fastpow(ll a, ll ex, ll m){ a %= m; ll res = 1; while(ex){ if(ex & 1) res = (a*res) % m; a = (a*a) % m; ex >>= 1; } return res; }
ll modinverse(ll a, ll m){ ll m0 = m; ll y = 0, x = 1; while (a > 1){ ll q = a / m; a %= m; swap(a,m); x -= q*y; swap(x,y); } if(x < 0) x += m0; return x; }

// Output, Common Containers
template <typename T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <typename T> ostream& operator << (ostream &os, const deque<T> &v) { for (T i : v) os << i << ' '; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << "(" << v.F << "=>" << v.S << ") "; return os; }
template <typename T, typename S> ostream& operator << (ostream &os, const map<T, S> &v) { for (auto i : v) os << i << ' '; return os; }

// Debugging
#ifdef LOCAL
	#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); d__f(_it, args); }
	void d__f(istream_iterator<string> it) {}
	template<typename Head, typename... Tail> void d__f(istream_iterator<string> it, Head H, Tail... T) { cerr << *it << " <=> [" << H << "]\n"; d__f(++it, T...); }
#else
	#define trace(args...)
#endif


// CODE STARTS HERE

const int modulo1 = 1e9+7;
const int modulo2 = 998244353;

const int mod = 1e9+7;

ll add(ll a, ll b) { return (a + b) % mod; }
ll sub(ll a, ll b) { return (a - b) % mod; }
ll mul(ll a, ll b) { return (a * b) % mod; }

int h,w;
vector<vector<ll>> grid, dp;

ll func(int x, int y){
	if(h<=x or w<=y or grid[x][y]) return 0;
	if(dp[x][y] == -1) dp[x][y] = add(func(x+1,y), func(x,y+1));
	return dp[x][y];
}

signed main() {
	std::ios::sync_with_stdio(false); //Warning: Do NOT use C I/O now.
	std::cin.tie(nullptr); //Note: Comment out this line for interactive questions.
	// std::cout.setf(std::ios::fixed); std::cout.precision(20); //Note: To output decimals correctly.

	// int t; cin>>t;
	// for(int test_no = 1; test_no <= t; ++test_no){}

	cin>>h>>w;

	grid.resize(h, vector<ll>(w));
	for(int i=0; i<h; ++i)
		for(int j=0; j<w; ++j){
			char c;
			cin>>c;
			grid[i][j] = (c=='.') ? 0 : 1;
		}

	dp.resize(h, vector<ll>(w, -1));

	dp[h-1][w-1] = 1;

	cout<<func(0,0);
}

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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	int n; cin >> n;
	ll a[100005];
	ll ans = 1LL;
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a, a+n);
	for(int i=0;i<n;i++){
		if(a[i]==0){
			ans = 0;
			break;
		}
		if(a[i] > 1000000000000000000/ans){
			ans = -1;
			break;
		}
		ans *= a[i];
	}
	cout << ans << endl;
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main()
{
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int ans;
  if(a < c) {
    if(b < c)
      ans = 0;
    else
      ans = min(b, d)-c;
  } else {
    if(d < a)
      ans = 0;
    else
      ans = min(b, d)-a;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> *i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> " " >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

int cnt[26];
signed main() {
    string s;
    cin>>s;
    int n=SZ(s);

    int ans=n*(n+1)/2+1;
    REP(i,n) {
        cnt[s[i]-'a']++;
        ans-=cnt[s[i]-'a'];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 720
import sys

cand = set()
for i in range(0, 100+1, 4):
    for j in range(0, 100-i+1, 7):
        cand.add(i + j)

n = int(sys.stdin.readline().rstrip())

def main():
    return 'Yes' if n in cand else 'No'

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char a[10005];
	cin>>a;
	int n=0,s=0,w=0,e=0;
	for(int i=0; a[i]; i++)
	{
		if(a[i]=='N')
			n++;
		if(a[i]=='W')
			w++;
		if(a[i]=='E')
			e++;
		if(a[i]=='S')
			s++;
	}
	if(((s==0&&n==0)||(s&&n))&&((w&&e)||(w==0&&e==0)))
		puts("Yes");
	else puts("No");
//    int n,R,r;
//    cin>>n>>R>>r;
//	if(n==1)
//	{
//		if(R>r)puts("NO");
//		else puts("YES");
//	}
//	else if(n==2)
//	{
//		if(n*2>m)puts("YES");
//		else puts("YES");
//	}
//	else
//	{
//		double c=360.0/n;
//		double a, b;
//		a = sin(c*2*PI/360);
//		c = (180-c)/2;
//		b = sin(c*2*PI/360);
//		double x = 2*n*b/a;
//		if(x+n > m) cout << "NO" << endl;
//		else cout << "YES" << endl;
//	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int a[3];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    rep(i, 0, 3) cin >> a[i];
    sort(a, a+3, greater<int>());
    cout << 10 * a[0] + a[1] + a[2] << endl;
    return 0;
}


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

int main() {
  ll n,m;
  cin >> n >> m;
  if(abs(n-m)>1){
    cout << 0 << endl;
    return 0;
  }
  if(abs(n-m)==1){
    ll ans=1;
    ll k=min(n,m);
    for(ll i=1;i<k+1;i++){
      ans=(ans*i)%MOD;
    }
    ans=ans%MOD;
    cout << ((ans*ans)%MOD*max(n,m))%MOD << endl;
  }
  if(n==m){
    ll ans=1;
    for(ll i=1;i<n+1;i++){
      ans=(ans*i)%MOD;
    }
    ans=ans%MOD;
    cout << (ans*ans*2)%MOD << endl;
  }
}



Measured memory_bytes: 3592