akhauriyash/Code-Regression huggingface dataset:
from functools import reduce
import itertools
import math

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())

sum = 0
# forループのネスト
for a, b, c in itertools.product(range(1, k+1), range(1, k+1), range(1, k+1)):

    sum += gcd(a, b, c)

print(sum)


Measured memory_bytes: 69188
#include<bits/stdc++.h>
#define all(x)     (x).begin() , (x).end()
typedef long long int ll;
using namespace std;

const ll     mod = 1e9+7;
const double eps = 1e-9;


int n;
const int N=103,nax=1e5+3;
ll W, w[N],v[N];
ll dp[N][nax];

ll rec(int ind,ll s) {
    if(ind==n&&s>=0)return 0;
    else if(ind==n||s<0)return -1e12;
    ll &cur=dp[ind][s];
    if(cur!=-1)return cur;
    return cur=max(v[ind] + rec(ind+1,s-w[ind]) , rec(ind+1,s));
}

void solve(){
    cin >> n >> W;
    for(int i=0;i<n;++i)
        for(int j=0;j<=W;++j)
            dp[i][j]=-1;
    for(int i=0;i<n;++i) {
        cin >> w[i] >> v[i];
    }
    cout << rec(0,W) << "\n";
}


int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    while(t--)
        solve();
    return  0;
}


Measured memory_bytes: 81636
import itertools

N = int(input())
P = ''.join(input().split())
Q = ''.join(input().split())

n_l = [str(i) for i in range(1,N+1)]
N_lists = [''.join(i) for i in itertools.permutations(n_l)]

index_P = N_lists.index(P)
index_Q = N_lists.index(Q)

ans = abs(index_P - index_Q)

print(ans)


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

int main(){
  int a,b;
  cin >> a >> b;
  int ans = 0;
  if(b == 1){
    ans = 0;
  }
  else{
    int nokori = b-1;
    while(nokori > 0){
      ans++;
      nokori -= a-1;
    }
  }
  cout << ans << endl;
}
   

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<cmath>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = n-1; i >=0; i--)
#define lint long long
#define all(x) (x).begin(), (x).end()

long N;

bool check(long x){
    bool is[10]; fill(is, is+10, false);
    while(x != 0){
        long y = x % 10;
        is[y] = true;
        x /= 10;
    }
    if(is[7] && is[5] && is[3]) return true;
    return false;
}

int rec(long x){
    if(x > N) return 0;
    int ans = 0;
    if(check(x)) ans = 1;
    ans += rec(x*10+7);
    ans += rec(x*10+5);
    ans += rec(x*10+3);
    return ans;
}

int main(){
    cin>>N;
    cout<<rec(0)<<endl;
}

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

using namespace std;

string s;
string a = "abcdefghijklmnopqrstuvwxyz";
bool flag[26];


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  while (cin >> s) {
    for (int i = 0; i < 26; i++) flag[i] = false;
    for (int i = 0; i < 26; i++) {
      for (int j = 0; j < s.size(); j++) {
        if (a[i] == s[j]) {
          flag[i] = true;
        }
      }
    }
    for (int i = 0; i < 26; i++) {
      if (!flag[i]) {
        cout << a[i] << endl;
        break;
      }
      else if (a[i] == 'z') {
        cout << "None" << endl;
      }
    }
  }
  return 0;
}


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

int main(){
	double l; cin >> l;
	cout << fixed << setprecision(8);
	cout << l*l*l /27 << endl; 
}

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
using Graph = vector<vector<int>>;
queue<int> quex,quey;
const int MOD = 1000000007;




int main(){
    ll a,b,c;  cin >> a >> b ;
    int d,e;
    for(int i=1;i<=10000;i++){
        d=i*0.08;
        e=i*0.1;
        if(a==d && b==e) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

//
void solve(long long r){
  op(r*r)
  return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long r;
    scanf("%lld",&r);
    solve(r);
    return 0;
}


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

using namespace std;


int main()
{
  int ans = 0;

  int N, M;
  cin >> N >> M;

  vector <int> a(N);

  for(int i = 0; i < M; i++)
  {
    int k;
    cin >> k;
    for(int j = 0; j < k; j++)
    {
      int s;
      cin >> s;
      s--;
      a[s] |= 1 << i;
    }
  }

  int p = 0;
  for(int i = 0; i < M; i++)
  {
    int x;
    cin >> x;
    p |= x << i;
  }

  for(int s = 0; s < (1 << N); s++)
  {
    int t = 0;
    for(int i = 0; i < N; i++)
    {
      if( (s >> i) & 1)
      {
        t ^= a[i];
      }
    }

    if(t == p){
      ans++;
    }
  }

  cout << ans;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<numeric>
#include <string>
using namespace std;
int a, b, c;
int main() {
	cin >> a >> b >> c;
	if (a == b&&b == c)cout << 1 << endl;
	else if (a == b || b == c || a == c)cout << 2 << endl;
	else cout << 3 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main (final String[] args) {
        final Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
      	int b = sc.nextInt();
      	int c = sc.nextInt();
      	int k = sc.nextInt();
        
        int result = 0;
        if(k <= a) System.out.println(k);
        else if (k <= a+b) System.out.println(a);
        else System.out.println(a-(k-(a+b)));
    }
}

Measured memory_bytes: 35780
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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 = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
ll N;
ll A[201010];
ll ans[201010];

int main()
{
    cin >> N;
    for (int i = 2; i <= N; i++)
    {
        cin >> A[i];
        ans[A[i]]++;
    }

    for (int i = 1; i <= N; i++)
    {
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 6680
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    vl a(n);cin>>a;
    ll total=sum(a),cnt=0;
    rep(i,n){
        if(a[i]*4*m>=total)cnt++;
    }
    Yn(cnt>=m);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__",", __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

bool solve(){
  int n;
  cin>>n;
  vector<int> vec(n);
  rep(i,n) cin>>vec[i];

  int mx = *max_element(all(vec));
  int mn = *min_element(all(vec));

  if( mx-mn >=2 ) return false;

  int p = 0;
  rep(i,n) if(vec[i]==mn) p++;

  if(mx==mn){
    if((1 <= mn && mn <= n/2) || mn == n-1) return true;
    else return false;
  }

  // mx = mn+1
  if( (n-p)/2+p >= mx && mx >= p+1 ) return true;
  else return false;
}

int main(){
  if(solve()) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

long dis(long n) {
    long min_d = n - 1;
    for (long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            min_d = min(min_d, (i + n / i - 2));
        }
    }
    return min_d;
}

int main() {
    long n;
    scanf("%ld", &n);
    printf("%ld\n", dis(n));
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u;
    cin >> u;    

    if (u == s) a--;
    if (u == t) b--;

    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int main()
{
	int num, a=0, b=0, ab=0, o=0;
	char blood[4];

	while(scanf("%d,%s", &num, blood) != EOF){
		if(blood[0] == 'A'){
			if(blood[1] == 'B')
				ab++;
			else
				a++;

		} else if(blood[0] == 'B')
			b++;
		else if(blood[0] == 'O')
			o++;
	}
	printf("%d\n%d\n%d\n%d\n", a, b, ab, o);
	return 0;
}

Measured memory_bytes: 596
gets
t = ARGF.map(&:to_i)
max2 = max = 0
t.each do |d|
  if(d > max)
    max2 = max
    max = d
    next
  end
  if(d > max2)
    max2 = d
  end
end
t.each do |d|
  if(d==max)
    print "#{max2}\n"
  else
    print "#{max}\n"
  end
end


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

int main(){
  int a[10][10],n,d,count=0;
  int i,j,k;
  double sum=0;
  scanf("%d %d",&n,&d);
  for(i=0;i<n;i++){
    for(j=0;j<d;j++){
      scanf("%d",&a[i][j]);
    }
  }
  
  for(i=0;i<n-1;i++){
    for(j=i+1;j<n;j++){
      for(k=0;k<d;k++){
        sum+= abs(a[i][k]-a[j][k])*abs(a[i][k]-a[j][k]);
      }
      //printf("%f\n",floor(sqrt(sum)));
      if(floor(sqrt(sum)) == sqrt(sum)) count++;
      sum=0;
    }
  }
  printf("%d\n",count);
  return 0;
}

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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    ll n,d;
    cin>>n>>d;
    d=d*d;
    ll ans=0;
    rep(i,n)
    {
      ll x,y;
      cin>>x>>y;
      if(x*x + y*y <=d) ans++;
    }
    cout<<ans<<'\n';
    return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


Measured memory_bytes: 3612
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = a;i < n;i++)
#define fs first
#define sc second
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
    int n,m,a,b,dx,dy,tempx,tempy,cnt,ans = 0;
    pair<int,int> m_list[200],n_list[1000];
    
    while(1){
        cin >> m;
        
        if(m == 0) break;
        ans = 0;
        cnt = 0;
        tempx = 0;
        tempy = 0;
        dx = 0;
        dy = 0;
        
        rep(i,0,m){
            cin >> a >> b;
            m_list[i] = pair<int,int>(a,b);
        }
        
        cin >> n;
        
        rep(i,0,n){
            cin >> a >> b;
            n_list[i] = pair<int,int>(a,b);
        }
        
        rep(i,0,n){
            cnt = 0;
            dx = n_list[i].fs - m_list[0].fs;
            dy = n_list[i].sc - m_list[0].sc;
            
            
            
            rep(j,0,n){
                tempx = n_list[j].fs - dx;
                tempy = n_list[j].sc - dy;
                
                rep(k,0,m){
//if(dx == 2 && dy == -3) cout << tempx << " " << tempy << " " << m_list[k].fs << " " <<m_list[k].sc << endl;
                  if(tempx == m_list[k].fs && tempy == m_list[k].sc){
                        cnt++;
                        break;
                    }
                }
            }
            if(cnt == m){
                cout << dx << " " << dy << endl;
              	break;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 
int N;
int A[20];
int x[20][20];
int y[20][20];

int counter(int x) {
	if(x == 0) return 0;
	return counter(x >> 1) + (x & 1);
}

void solve() {
	cin >> N;
	for(int i = 1; i <= N; i++) {
		cin >> A[i];
		for(int j = 1; j <= A[i]; j++) {
			cin >> x[i][j] >> y[i][j];
		}
	}
	int ans = 0;
	for(int bits = 1; bits < (1 << N); bits++) {
		bool ok = true;
		for(int i = 1; i <= N; i++) {
			if(!(bits & (1 << (i-1)))) continue;
			for(int j = 1; j <= A[i]; j++)
				if(((bits >> (x[i][j]-1)) & 1) ^ y[i][j]) ok = false;
		}
		if(ok) ans = max(ans, counter(bits));
	}
	cout << ans << endl;
}

int main() {
	solve();
	return 0;
}



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

int main() {
    int dy[4] = {1, 0, -1, 0};
    int dx[4] = {0, 1, 0, -1};
    int H, W;
    cin >> H >> W;
    vector<string> G(H);
    for (int i = 0; i < H; ++i) cin >> G[i];
    vector<vector<int> > dist(H, vector<int>(W, -1));
    dist[0][0] = 1;
    queue<pair<int, int> > que;
    que.push(make_pair(0, 0));

    while (que.size()) {
        pair<int, int> p = que.front();
        que.pop();
        if (p.first == H - 1 && p.second == W - 1) break;
        for (int i = 0; i < 4; ++i) {
            int ny = p.first + dy[i];
            int nx = p.second + dx[i];
            if (ny >= 0 && ny < H && nx >= 0 && nx < W && G[ny][nx] != '#' && dist[ny][nx] == -1) {
                que.push(make_pair(ny, nx));
                dist[ny][nx] = dist[p.first][p.second] + 1;
            }
        }
    }
    int res = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (G[i][j] == '.') ++res;
        }
    }
    if (dist[H - 1][W - 1] == -1) cout << -1 << endl;
    else cout << res - dist[H - 1][W - 1] << endl;
    
    return 0;
}

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

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	vector<pair<int,pair<int,int>>> in;
	int ans = 0;
	
	cin>>N;
	
	in.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>in[i].second.second>>in[i].second.first;
		in[i].first = in[i].second.second + in[i].second.first;
	}
	
	sort(in.begin(), in.end());
	
	for(int i = 0, x = -INF; i < N; i++){
		// cout<<x<<" "<<in[i].second.second - in[i].second.first<<" "<<in[i].first<<endl;
		if(x <= in[i].second.second - in[i].second.first) {
			x = in[i].first;
			ans++;
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 2560
fun main(args: Array<String>) {
    val (N, K) = readLongList()

    val nk = N % K
    println(Math.min(nk, Math.abs(K-nk)))
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)


Measured memory_bytes: 36028
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;
using System.Linq;
class Program
{
    static List<int> s = new List<int>();
      static List<int> t = new List<int>();
    static decimal result;
static Hashtable ht=new Hashtable();
static int N,M;
 static int max;
  static bool maxtoo;
static long[,] table;
    static void Main()
    {
Read1();
Read2();
    for(int i=0;i<N;i++){
                    if(s[i]<max || maxtoo==true){Console.WriteLine(max.ToString());}
      else
      {
        int tmp2=0;
      for(int j=0;j<N;j++){if(s[j]>tmp2 && s[j]<max){tmp2=s[j];}}
        Console.WriteLine(tmp2.ToString());
      }
    }

    }

    static void Read1()
    {
        string tmp = Console.ReadLine();
        N = int.Parse(tmp);
    }

    static void Read2()
    {
        string tmp;
      for(int i=0;i<N;i++){
          tmp = Console.ReadLine();
        s.Add(int.Parse(tmp));
                if(s[s.Count-1]==max){maxtoo=true;}
        if(s[s.Count-1]>max){max=s[s.Count-1];maxtoo=false;}

      }
    }


    static long Gcd(long a, long b)
    {
        var v = new[] { a, b };
        while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
        return v[0];
    }

    static long Lcm(long a, long b)
    {
        return a / Gcd(a, b) * b;
    }


}

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

using LL = long long;

// �����Ŀ�ǿ��ǵ����� x , x - 1���ʣ�������x��������֮���Ϊ1��ֻ�����ֿ��ܣ�x ���� x - 1
// ���Լ���x - 2 �������ǿ��Եģ���������������������ֱ�Ӽ�Ϊ2�����Գ���x-1��x�Լ�������Ҳ�ǿ��Ե�
// ���⣬�����⣬ע���Ƶ����ɣ��й���������Ŀע��%������
// ����: �ٴ����������ܴ������ʱ��ȫ����LL�ɣ���Ȼ��������� ���ڼ��������ʱ��ֻ��Ҫ����sqrtС���ǲ���
int main(){
    LL k, ans = 0;
    cin >> k;
    for (LL i = 1; i * i <= k - 1; ++ i){   // ���ﲻ��Ҫ��2 ��ʼ����Ϊ��2��ʼ��©��k - 1������
        if ((k - 1 )% i == 0){
            if(i > 1) ++ ans;
            if (i != (k - 1) / i) ++ ans;
        }
    }
    auto check = [&](LL a){
        LL f = k;
        while (f % a == 0) f /= a;
        if (f % a == 1) ++ ans;
    };
    for (LL i = 1; i * i <= k; ++ i){ // ����ע��ҪLL,��Ϊ������Ϊ 1e12 ��Ȼi * i ����� ͬ������Ҳ����Ҫ�� i = 1 ��ʼ����Ϊ����ܻ�����©������ k ������
        if (k % i == 0){
            if (i > 1) check(i);
            if (i != k / i) check(k / i);
        }
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=100009;
int fa[N],n,m;
set<int>w;
int findl(int x)
{
    return fa[x]==x?x:(fa[x]=findl(fa[x]));
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        fa[i]=i;
    for(int i=1;i<=m;i++)
    {
        int x,y,tmp,tmp1;
        scanf("%d%d",&x,&y);
        tmp=findl(x),tmp1=findl(y);
        if(tmp!=tmp1)
            fa[tmp]=tmp1;
    }
    for(int i=1;i<=n;i++)
        w.insert(findl(i));
    printf("%d",w.size()-1);
    return 0;
}


Measured memory_bytes: 7968
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;

void swap(int &a, int &b){
	int temp;
	temp = a;
	a = b;
	b = temp;
}

int main(){
	int n, count;
	cin>>n;
//	vector<int> array;
	int array[100];
	for(int i=0;i<n;i++) 
	{
		int input;
		cin>>input;
//		array.push_back(input);
		array[i] = input;
	}
	for(int i=n-1;i>=0;i--)
	{
		for(int j=0;j<=i-1;j++)
		{
			if(array[j]>array[j+1])
			{
				swap(array[j], array[j+1]);
				count++;
			}			
		}
	}
	for(int i=0; i<n; i++)
	{
		if(i!=0) cout<<" ";
		cout<<array[i];
	}
	
	cout<<endl<<count<<endl;
	return 0;
}

Measured memory_bytes: 1160
package main

import(
	"bufio"
	"strconv"
	"fmt"
	"os"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func main() {
	sc.Split(bufio.ScanWords)
	buf := make([]byte, 10000)
	sc.Buffer(buf, 301000)

	n := nextInt()
	s := nextLine()

	data := strings.Split(s, "")

	min := 1000000
	right := make([]int, n)
	left := make([]int, n)

	for i := 1; i < n; i++ {
		if data[i-1] == "W" {
			left[i] = left[i-1] + 1
		} else {
			left[i] = left[i-1]
		}
	}

	for i := n-1; i > 0; i-- {
		if data[i] == "E" {
			right[i-1] = right[i] + 1
		} else {
			right[i-1] = right[i]
		}
	}

	for i := 0; i < n; i++ {
		sum := right[i] + left[i]
		if min > sum {
			min = sum
		}
	}
	fmt.Println(min)
}


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

int main()
{
    int n;
    cin >> n;
    int arr[n];
    for(int i = 0; i < n; i++) cin >> arr[i];
    sort(arr, arr+n);
    int res = abs(arr[n-1] - arr[0]);
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int n,q; cin >> n >> q;
  vector<int> tree[n+1];
  for(int i=0;i<n-1;i++) {
    int x,y; cin >> x >> y;
    tree[x].push_back(y);
    tree[y].push_back(x);
  }
  vector<int> p(n+1);
  for(int i=0;i<q;i++) {
    int x,y; cin >> x >> y;
    p[x] += y;
  }
  // for(auto e: p) cout << e << ' ';
  // cout << '\n';
  vector<int> ans(n+1);
  stack<pair<int,int>> st;
  st.push({1,0});
  bool visited[n+1] = {false};
  while(!st.empty()) {
    auto temp = st.top();
    st.pop();
    int node = temp.first;
    int pval = temp.second;
    visited[node] = true;
    ans[node] = p[node] + pval;
    for(auto e: tree[node]) {
      if (!visited[e]) st.push({e,ans[node]});
    }
  }
  for(int i=1;i<=n;i++) cout << ans[i] << ' ';
  return 0;
}

Measured memory_bytes: 17396
#include<iostream>
#include<algorithm>
#define MAX 100
#define INFTY (1 << 21)
using namespace std;

int p[MAX + 1], mat[MAX + 1][MAX + 1];

void matrixChainMultiplication(int n) {
	for (int i = 1; i <= n; i++) {
		mat[i][i] = 0;
	}
	for (int l = 2; l <= n; l++) {
		for (int i = 1; i <= n - l + 1; i++) {
			int j = i + l - 1;
			mat[i][j] = INFTY;
			for (int k = i; k <= j - 1; k++) {
				mat[i][j] = min(mat[i][j], (mat[i][k] + mat[k + 1][j] + (p[i - 1] * p[k] * p[j])));
			}
		}
	}
}

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i - 1] >> p[i];
	}
	matrixChainMultiplication(n);
	cout << mat[1][n] << endl;
	return 0;
}

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

int main(){
  string s,a[3];
  cin>>s;
  
  rep(i,0,3){
    a[i]=s.substr(i,1);
  }
  
  if(a[0]==a[1]&&a[1]==a[2]){cout<<"No"<<endl;}
  else{cout<<"Yes"<<endl;}
  
  return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int>B(N-1);
    for(int i = 0; i < N-1; i++) {
        cin >> B[i];
    }
    int ans = B[0]+B[N-2];
    for(int i = 0; i < N-2; i++) {
        ans+=min(B[i],B[i+1]);
    }
    cout << ans << endl;
} 

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        var nx = Console.ReadLine().Split().Select(int.Parse).ToArray();
        long X = nx[1];
        //ちゅーごくじょーよてーり
        //オーダーによってSの終端が決定する
        //まず影響するのは降順のみなことは自明に分かって、
        //で、「次」を選ぶことができる順番は
        //「確率」「期待値」
        //aを取り除いた場合、その後に適用できるのはそれ以前全て。

        List<int> s = Console.ReadLine().Split().Select(int.Parse).OrderByDescending(x => x).ToList();
        ModInt[] dp = new ModInt[X + 1];
        dp[X] = 1;
        int remain = s.Count - 1;
        foreach (var mod in s)
        {
            ModInt[] newDP = new ModInt[X + 1];

            for (int i = 0; i < dp.Length; i++)
            {
                newDP[i % mod] += dp[i];
                newDP[i] += dp[i] * remain;
            }
            remain--;
            dp = newDP;
        }
        ModInt res = 0;
        for (int i = 0; i < dp.Length; i++)
        {
            res += dp[i] * i;
        }
        Console.WriteLine(res);
    }
}


struct ModInt
{
    const int MOD = 1000000007;
    long Data;
    public ModInt(long data) { Data = data; Eval(); }

    private long Eval() => (Data %= MOD) < 0 ? Data += MOD : Data;
    public static implicit operator long(ModInt modInt) => modInt.Eval();
    public static implicit operator ModInt(long val) => new ModInt(val);
    public static ModInt operator +(ModInt a, ModInt b)
    {
        long res = a.Data + b.Data;
        return new ModInt() { Data = res >= MOD ? res - MOD : res };
    }
    public static ModInt operator -(ModInt a, ModInt b)
    {
        long res = a.Data - b.Data;
        return new ModInt() { Data = res < 0 ? res + MOD : res };
    }
    public static ModInt operator *(ModInt a, ModInt b) => new ModInt(a.Data * b.Data);
    public static ModInt operator /(ModInt a, ModInt b) => a * Power(b, MOD - 2);

    static ModInt Power(ModInt n, long m)
    {
        ModInt res = 1;
        while (m > 0)
        {
            if ((m & 1) == 1) res *= n;
            n *= n;
            m >>= 1;
        }
        return res;
    }
}


Measured memory_bytes: 30824
//============================================================================
// Name        : ICPC.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;


int v[1000];
int N;

int getdigit(int n) {
	int k = 0;
	while (n > 0) {
		n /= 10;
		k++;
	}
	if ( k == 0 ) return 1;
	return k;
}

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

	int n = 0;
	while (1) {
		int d = getdigit(n);
		int ok = 1;
		for (int i = 0; i < N - d + 1; ++i) {
			int k = 1;
			int p = 0;
			for (int j = i + d - 1; j >= i; --j ) {
				p += v[j] * k;
				k *= 10;
			}
			if (p == n) {
				ok = 0;
			}
		}
		if (ok) break;
		if (N == d) {
			n++;
			break;
		}
		n++;
	}
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 3120
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var V = cin.ReadIntArray(N);
            var C = cin.ReadIntArray(N);

            var diff = new List<int>();
            for(var i=0; i<N; i++)
            {
                diff.Add(V[i] - C[i]);
            }
            var ans = 0;
            foreach(var d in diff)
            {
                if (d > 0)
                {
                    ans += d;
                }
            }
            WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

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

int main() {
  int N;
  int count = 0;
  cin >> N;
  
  rep(i, N) {
    int l, r;
    cin >> l >> r;
      count += r - l + 1;
  }
  cout << count << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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;}

ld dp[3000][3000];

int main(){
    int n;
    cin>>n;
    vd p(n+1);
    for(int i=1;i<=n;++i)cin>>p[i];
    mem(dp,0);
    dp[0][0]=1;
    for(int i=1;i<=n;++i){
        dp[i][0]=dp[i-1][0]*(1-p[i]);
        for(int j=1;j<=i;++j){
            dp[i][j]+=dp[i-1][j-1]*p[i];
            dp[i][j]+=dp[i-1][j]*(1-p[i]);
        }
    }
    ld ans=0;
    int m=n/2;
    if(n%2==1)m++;
    for(int i=m;i<=n;++i){
        ans+=dp[n][i];
    }
    cout<<setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 144444
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
inline int read(int&x){
	x=0;int f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
int n, d;
int a[N], buc[N];
int main(void) {
    read(n);
    for (int i = 1; i <= n; i++) {
        read(a[i]); ++buc[a[i]];
    }
    d = *max_element(a + 1, a + n + 1);
    if (d & 1) {
        for (int i = d - d / 2; i <= d; i++) {
            buc[i] -= 2; if (buc[i] < 0) goto fuck;
        }
        for (int i = d - d / 2; i; i--)
            if (buc[i]) goto fuck;
    } else {
        if (!buc[d / 2]) goto fuck; --buc[d / 2];
        for (int i = d / 2 + 1; i <= d; i++) {
            buc[i] -= 2; if (buc[i] < 0)goto fuck;
        }
        for (int i = d / 2; i; i--)
            if (buc[i]) goto fuck;
    }
    puts("Possible");
    return 0;fuck:
    puts("Impossible");;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int f[51];
int t[51];
int n;

int v[51];
int cancan(int f, int t, ll mask){
	queue<int> q;
	for(int i=0; i<=50; ++i) v[i]=0;
	q.push(f); v[f]=1;
	while(q.size()){
		int x=q.front(); q.pop();
		for(int i=1; i<=50; ++i) if(1&(mask>>i)){
			int y=x%i;
			if(!v[y]){
				v[y]=1; q.push(y);
			}
		}
	}
	return v[t];
}

int can(ll mask){
	for(int i=1; i<=n; ++i) if(!cancan(f[i], t[i], mask)) return 0;
	return 1;
}

int main()
{
	read(n);
	for(int i=1; i<=n; ++i) read(f[i]);
	for(int i=1; i<=n; ++i) read(t[i]);
	ll mask = 2*((1ll<<50)-1);
	if(!can(mask)){
		puts("-1");
		return 0;
	}
	for(int i=50; 1<=i; --i){
		if(i == 1){
			i = i;
		}
		if(can(mask ^ (1ll<<i))) mask ^= (1ll<<i);
	}
	printf("%lld\n", mask);
	return 0;
}


Measured memory_bytes: 256
def Sieve(n): #n以下の素数全列挙(O(nloglogn)) retは素数が入ってる。divlisはその数字の素因数が一つ入ってる

    ret = []
    divlis = [-1] * (n+1) #何で割ったかのリスト(初期値は-1)
    
    flag = [True] * (n+1)
    flag[0] = False
    flag[1] = False

    ind = 2
    while ind <= n:

        if flag[ind]:
            ret.append(ind)

            ind2 = ind ** 2

            while ind2 <= n:
                flag[ind2] = False
                divlis[ind2] = ind
                ind2 += ind

        ind += 1

    return ret,divlis

N = int(input())

A = list(map(int,input().split()))
A.sort()

ans = 0
lis = [0] * (10**6+1)
tmp,dl = Sieve(10**6+2)

for i in range(N):

    if i != N-1 and A[i+1] == A[i]:
        lis[A[i]] = 1
        continue

    dic = {}
    now = A[i]
    while dl[A[i]] != -1:

        if dl[A[i]] not in dic:
            dic[dl[A[i]]] = 1
        else:
            dic[dl[A[i]]] += 1
        A[i] //= dl[A[i]]

    if A[i] != 1:
        if A[i] not in dic:
            dic[A[i]] = 1
        else:
            dic[A[i]] += 1

    l1 = [1]
    #print (now,dic)
    for i in dic:
        l2 = [i**j for j in range(dic[i]+1)]

        tmp = len(l1)
        for x in range(tmp):
            for y in l2:
                if y != 1:
                    l1.append(l1[x]*y)

    flag = True
    #print (now , l1)
    for i in l1:
        if lis[i] > 0:
            flag = False
            break

    if flag:
        ans += 1
    lis[now] = 1

print (ans)


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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int main() {
	int n, q;
	cin >> n >> q;
	int s = 0;
	for (int i : range(q)) {
		int a, b;
		cin >> a >> b;
		if (a == 0)cout << (s + b - 1) % n + 1 << endl;
		else s = (s + b) % n;
	}

	return 0;
}



Measured memory_bytes: 3204
int main(){
	int s[9000],n,m,t,f,i;
	while(scanf("%d%d",&n,&m),n)
		for(i=t=f=1;i<=n+m;i++){
			scanf("%d",&s[i]);
			if(i>n)
				if(t+=s[t+=s[i]],t>=n&f==1)
					printf("%d\n",i-n,f=0);
			
		}
}

Measured memory_bytes: 0
#include<iostream>


void print_list(int* a, int n){
  for(int i = 0; i < n - 1; i++){
    std::cout << a[i] << " ";
  }
  std::cout << a[n - 1] << std::endl;
}

void insertionSort(int* a, int n){
  print_list(a, n);
  for(int i = 1; i < n; i++){
    int v = a[i];
    int j = i - 1;
    while(i >= 0 && a[j] > v){
      a[j + 1] = a[j];
      j--;
    }
    a[j + 1] = v;

    print_list(a, n);
  }
}

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

  int a[n];
  for(int i = 0; i < n; i++){
    std::cin >> a[i];
  }
  
  insertionSort(a, n);
 
  return 0;
}



Measured memory_bytes: 3096
#include <stdio.h>
#define LOOP(val,times) for(val = 0;val < (times);val++)


int main(){
    int i;
    int l,r,N,S;
    S = 0;
    scanf("%d",&N);
    LOOP(i,N){
        scanf("%d %d",&l,&r);
        S += r - l +1;
    }
    printf("%d\n",S);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

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

    int ans = *min_element(ap.begin(), ap.end()) + *min_element(bp.begin(), bp.end());
    rep(i, m) {
        int x, y, c;
        cin >> x >> y >> c;
        x--; y--;
        chmin(ans, ap[x] + bp[y] - c);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3972
n = int(input())
s = input()
c_r = 0
c_g = 0
c_b = 0
for i in range(n):
    if s[i] == "R":
        c_r += 1
    elif s[i] == "G":
        c_g += 1
    elif s[i] == "B":
        c_b += 1
c = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] == "R" and s[j] == "G":
            if j < 2*j-i < n:
                if s[2*j-i] == "B":
                    c += 1
        if s[i] == "R" and s[j] == "B":
            if j < 2*j-i < n:
                if s[2*j-i] == "G":
                    c += 1
        if s[i] == "G" and s[j] == "R":
            if j < 2*j-i < n:
                if s[2*j-i] == "B":
                    c += 1
        if s[i] == "G" and s[j] == "B":
            if j < 2*j-i < n:
                if s[2*j-i] == "R":
                    c += 1
        if s[i] == "B" and s[j] == "R":
            if j < 2*j-i < n:
                if s[2*j-i] == "G":
                    c += 1
        if s[i] == "B" and s[j] == "G":
            if j < 2*j-i < n:
                if s[2*j-i] == "R":
                    c += 1
        else:
            pass
print(c_r*c_g*c_b-c)

Measured memory_bytes: 74028
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long N, A, B;
    cin >> N >> A >> B;
    long long ans;
    long long edge;
    long long t1, t2;
    long long delta;
    delta = B - A;
    if(delta%2 == 0){
        ans = delta/2;
    }else{
        t1 = A-1;
        t2 = N-B;
        if(t1 < t2){
            edge = t1;
        }else{
            edge = t2;
        }
        ans = edge + 1 + (delta-1)/2;
    }
    cout << ans << endl;
}




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

// // #define n = 0

// void dp(int n){
//     vector<vector<long long> > note( vector<long long>(n, 0));
// }

// int main(){
//     int n, m, k;
//     cin >> n >> m >> k;
//     vector<long long> a(n+1, 1e9+1), b(m+1, 1e9+1);
//     for(int i=0; i<n; i++){
//         cin >> a[i];
//     }
//     for(int i=0; i<m; i++){
//         cin >> b[i];
//     }
//     int ans = 0;
//     int i=0, j=0;
//     while(k>0){
//         if((k-a[i] < 0 && k-b[j]<0) || (i==n && j==m)){
//             break;
//         }
//         // else if(i<n || j<m){
//         while(a[i]<b[j] && i<n && (k-a[i] >= 0 || k-b[j] >= 0)){
//             k -= a[i];
//             i++;
//             ans++;
//         }
//         while(a[i]>=b[j] && j<m && (k-a[i] >= 0 || k-b[j] >= 0)){
//             k -= b[j];
//             j++;
//             ans++;
//         }
//         // }
//         // ans++;
//     }
//     cout << ans << endl;
//     return 0;

// }


int main(){
    int n,m,k;
    cin >> n >> m >> k;
    long long a[n];
    long long b[m];
    long long sum=0;
    int aindex = -2;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if (aindex == -2 && sum + a[i]<=k){
            sum+= a[i];
        }else if(aindex == -2){
            aindex = i-1;
        }
    }
    if(aindex==-2){
        aindex = n-1;
    }

    int bindex = -2;
    for(int i=0;i<m;i++){
        cin >> b[i];
        if (bindex == -2 && sum + b[i]<=k){
            sum+= b[i];
        }else if(bindex == -2){
            bindex = i-1;
        }
    }
    if(bindex==-2){
        bindex = m-1;
    }

    int ans = aindex + bindex + 2;
    int now = aindex + bindex + 2;

    bindex++;

    for (int i=aindex; i>=0; i--){
        sum -= a[i];
        now -= 1;
        while(sum + b[bindex] <= k){
            sum += b[bindex];
            bindex++;
            now++;
            if(bindex==m){
                break;
            }
        }
        ans = std::max(ans, now);
        if(bindex==m){
            break;
        }
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 6668
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        int b = input.nextInt();
        if((a >= 1 && a <=9) && (b >= 1 && b <=9)){
            for (int i = 0; i < Math.max(a,b); i++){
                System.out.print(Math.min(a, b));
            }
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    if(s[0] == 'S')
        cout << "Cloudy\n";
    else if(s[0] == 'C')
        cout << "Rainy\n";
    else
        cout << "Sunny\n";

    return 0;
}


Measured memory_bytes: 256