akhauriyash/Code-Regression huggingface dataset:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# import re
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb

# slist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
T,A = map(int,input().split())
arrH = np.array(input().split(),dtype=np.float64)

arrH = abs((arrH*-0.006 + T)-A)
ans = np.argmin(arrH)+1
print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 12508
#include<bits/stdc++.h>
using namespace std;
#define int  long long 
#define speedrap ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int be(int a,int b,int mod) {if(b == 0) return 1; if(b%2 == 1) return (a*be(a,b-1,mod))%mod; else return (be(a,b/2,mod)*be(a,b/2,mod))%mod;}
const int mod = 1e9+7;
#define PI 3.14159265359
#define pf push_front
#define pb push_back
#define bitcount __builtin_popcount
#define sc(a) scanf("%d", &a);
#define sz(s) (int)s.size()
#define eb emplace_back
#define pf push_front
#define mkp(x,y) make_pair(x,y)
const int siz = 5*(1e5 + 1);
const int logi = 21;
const double epsilon = 1e-6;
int prime[siz];
bool cmp(const int &a,const int &b)
{
  return (abs(a-b)>1);
}




signed main()
{
 	
	speedrap
	int t;
	t = 1;
	//cin>>t;
	while(t--)
	{
		int n;
		cin>>n;

		int sum = 0;

		
		for(int a = 1 ; a <= n ; a++)
		{
			for(int b = 1 ; b<= n ; b++)
			{
				for(int c = 1 ; c<= n ;c++)
				{
					int g = a;
					g = __gcd(a,b);
					g = __gcd(g,c);
					sum += g;
				}
			}
		}

		cout<<sum<<"\n";
	}
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?9e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s;
	cin>>s;
	int n=s.size();
	int out=n;
	rep(i,26){
		int co=0,ans=0;
		for(int j=n-1;j>=0;j--){
			if(s[j]-'a'==i){
				ans=max(ans,co);
				co=0;
			}else co++;
		}
		ans=max(ans,co);
		out=min(out,ans);
	}
	cout<<out<<endl;
}









Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int n;
	int num[10000];
	int i;
	int t;

	scanf("%d", &n);

	for (i = 1; i <= n; i++) {
		scanf("%d", &num[i]);
	}

	for (t = n; t >= 1; t--) {
		printf("%d", num[t]);
		if (t != 1) {
			printf(" ");
		}
		if (t == 1) {
			printf("\n");
		}
	}
	
	return 0;
}

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


int main(){
  int N,Q;
  cin >> N >> Q;
  string s;
  cin >> s;
  vector<int> l(Q),r(Q),csum(N+1,0);
  for(int i=0;i<Q;i++){
    cin >> l.at(i);
    cin >> r.at(i);
  }
  
  for(int i=1;i<N;i++){
    if(s.at(i)=='C' && s.at(i-1)=='A'){
      csum.at(i+1)=csum.at(i)+1;
    } else{
      csum.at(i+1)=csum.at(i);
    }
  }
  int answer;
  for(int i=0;i<Q;i++){
    //int lstring=s.at(l.at(i)-1),rstring=s.at(r.at(i)-1);
    if(s.at(l.at(i)-1)=='A' && s.at(l.at(i))=='T') answer = csum.at(r.at(i))-csum.at(l.at(i)+1);
    else answer = csum.at(r.at(i))-csum.at(l.at(i));
    cout << answer << endl;
  }
}

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

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

  int cnt[4];
  for(int i = 0; i < 4; i++) cnt[i] = 0;
  
  for(int i = 0; i < 4; i++) {
    for(int j = 0; j < 4; j++) {
      // cout << "s[i] " << s[i] << endl;
      // cout << "s[j] " << s[j] << endl;
      if(s[j] == s[i]) cnt[i]++;
    }
  }

  int judge = 0;
  for(int i = 0; i < 4; i++) {
    if(cnt[i] == 2) judge++;
  }

  if(judge == 4) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

template<typename T> void drop(const T &x){cout<<x<<'\n';exit(0);}

const long long mod = 998244353;

void milkshake() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for(int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  vector<int> dp(n+1);
  vector<int> dps(n+1);
  dp[1] = dps[1] = 1;
  for(int i = 2; i <= n; i++) {
    for(int j = 0; j < k; j++) {
      int li = i - r[j];
      li = max(li, 1);
      int ri = i - l[j];
      if(ri < 1) continue;
      dp[i] = ((long long)dp[i] + dps[ri] - dps[li-1]) % mod;
    }
    dps[i] = ((long long)dps[i-1] + dp[i]) % mod;
  }
  cout << (dp[n] + mod) % mod << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) milkshake();

  return 0;
}


Measured memory_bytes: 4756
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()

def prime_factorization(n):
    assert n > 1
    factor=[]
    for d in range(2, int(n ** .5) + 1):
        while n % d == 0:
            n //= d
            factor.append(d)
    if n != 1: factor.append(n)
    return factor

from collections import Counter
def resolve():
    n = int(input())
    if n == 1:
        print(0)
        return
    C = Counter(prime_factorization(n))
    res = 0
    for v in C.values():
        n = 1
        while 2 * v >= n * (n + 1):
            n += 1
        res += n - 1

    print(res)
resolve()

Measured memory_bytes: 66488
#include<stdio.h>
#define MAX 500000
int A[MAX+1],N;
void maxHeapify(int);
void buildMaxHeap();
void swap(int *,int *);
int main(){
  int i;
  scanf("%d",&N);
  for(i=1;i<=N;i++){
    scanf("%d",&A[i]);
  }
  buildMaxHeap();
  for(i=1;i<=N;i++) printf(" %d",A[i]);
  printf("\n");
  return 0;
}
void maxHeapify(int i){
  int l,r,largest;
  l=i*2;
  r=i*2+1;
  if(l<=N && A[l]>A[i]) largest = l;
  else largest=i;
  if(r<=N && A[r]>A[largest]) largest = r;
  if(largest != i){
    swap(&A[i],&A[largest]);
    maxHeapify(largest);
  }
}
void buildMaxHeap(){
  int i;
  for(i=N/2;i>=1;i--){
    maxHeapify(i);
  }
}
void swap(int *x,int *y){
  int z;
  z=*x;
  *x=*y;
  *y=z;
}



Measured memory_bytes: 3656
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        if(i%3==0)cout<<' '<<i;
        else
        {
            int j = i;
            while(j>0)
            {
                if(j%10==3)
                {
                    cout<<' '<<i;
                    break;
                }
                j = j/10;
            }
        }
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	string S;
	cin >> N >> S;
	
	int cnt[110][26] = { 0 };
	REP(i, N){
		cnt[i + 1][S[i] - 'a']++;
		REP(j, 26) {
			cnt[i + 1][j] += cnt[i][j];
		}
	}
	int ans = 0;

	eFOR(i, 1, N - 1) {
		int res =0;
		REP(j, 26) {
			if (cnt[i][j] && cnt[N][j] - cnt[i][j] > 0)res++;
		}


		chmax(ans, res);
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
# https://atcoder.jp/contests/abc080/submissions/1829635

N, C = map(int, input().split())
ps = [[] for _ in range(C)]

for _ in range(N):
    s, t, c = map(int, input().split())
    c -= 1
    ps[c].append((s, t))

N_max = 10 ** 5
imos = [0] * (N_max + 1)

for c in range(C):
    ps[c].sort()
    cont = False
    for i, (s, t) in enumerate(ps[c]):
        if not cont:
            imos[s - 1] += 1
        if i + 1 < len(ps[c]) and t == ps[c][i + 1][0]:
            cont = True
        else:
            imos[t] -= 1
            cont = False

ans = t = 0
for imo in imos:
    t += imo  # ここでシミュレート
    ans = max(ans, t)
print(ans)


Measured memory_bytes: 17740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef pair<double,ll> pdl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<pdd> vdd;
typedef vector<pdi> vdi;
typedef vector<pdl> vdl;
typedef vector<string> vs;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
const ll MAXLL=0x3f3f3f3f3f3f3f3f;
const int MAX=0x3f3f3f3f;
const ll MOD=1000000007;
const ll mod=998244353;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template<class T>
void rsort(vector<T>& v){
	sort(v.rbegin(),v.rend());
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
bool is_sorted(vector<T>& v){
	return is_sorted(v.begin(),v.end());
}
template<class T>
bool sorted(vector<T>& v){
	return is_sorted(v);
}
void precompute(){

	return;
}
void solve(){
	ll n;
	cin>>n;
	ll ans=0;
	for(int i=1;i<=n;i++){
		ans+=i;
		if(ans>=n){
			cout<<i;
			return;
		}
	}
	return;
}

int main(){
	ios::sync_with_stdio(0);
	int numberofsubtestcases=1;
//	cin>>numberofsubtestcases;
	precompute();
	for(int looping=1;looping<=numberofsubtestcases;looping++){
//		cout<<"Case #"<<looping<<": ";
		solve();
	}
	return 0;
}




Measured memory_bytes: 3656
import sys
import math
X,Y = map(int, input().split())
Ans = 0

if (X + Y) % 3 != 0 or 2 * X < Y or 2 * Y < X:
  print(Ans)
  sys.exit()

move = (X + Y) // 3
yori = int(abs(X - Y))
move1 = (move - yori) // 2


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

Ans = cmb(move,move1,mod)

print(Ans)

Measured memory_bytes: 121844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll t;
     map<string ,ll>mp;
     cin>>t;
     for(int i=0;i<t;i++)
     {
         string str;
         cin>>str;
         mp[str]++;
     }
     cout<<mp.size()<<endl;

}



Measured memory_bytes: 19232
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>
#include<utility>
#include<string>

using namespace std;

main(){
  int i,j,n,ans=0;
  string fi,ny;
  cin >> fi ;
  cin >> n;
  for(i=0;i<n;i++){
    cin >>ny;
    ny+=ny;
    if(ny.find(fi)!=-1){
      ans++;
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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 (a>b) { a=b; return 1; } return 0; }


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

    vei v = {0,1,2,3};
    ve_vei co(4, vei(4,0));

    rep(i,3) {
      int a, b;
      cin >> a >> b;
      a--; b--;
      co[a][b] = co[b][a] = 1;
    }
    do{
       if(co[ v[0] ][ v[1] ] == 1 and co[ v[1] ][ v[2] ] == 1 and co[ v[2] ][ v[3] ] == 1){
         cout << "YES" << endl;
         return 0;
       }
    }while(next_permutation(all(v)));

    cout << "NO" << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353 

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

ll power(ll a, ll n, ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=(ans*a)%m;
        n>>=1;
        a=(a*a)%m;
    }
    return ans;
}

int main()
{
    IOS; 
    ll n,m;
    cin>>n>>m;
    vector<bool> a(n+1,false);
    vector<int> c(n+1,0);
    ll pen=0,val=0;
    repf(i,0,m)
    {
        ll p;
        string s;
        cin>>p>>s;
        if(!a[p] && s=="WA") c[p]++;
        else if(!a[p] && s=="AC")
        {
            a[p]=true;
            pen+=c[p];
            val++;
        }
    }
    cout<<val<<" "<<pen<<endl;
}  

Measured memory_bytes: 640
import numpy as np

N=int(input())

a=[[],[]]
a[0]=list(map(int,input().split()))
a[1]=list(map(int,input().split()))

s=np.array(a)

s[1]=np.cumsum(s[1][::-1])[::-1]

s[0][-1]+=s[1][-1]

for i in range(N-2,-1,-1):
    s[0][i]+=max(s[1][i],s[0][i+1])
print(s[0][0])

Measured memory_bytes: 21660
#include<bits/stdc++.h>
using namespace std;
int main()
{
	double n;
	cin>>n;
	double p;
	if((int)n%2)
	    p=((int)(n/2)+1)/n;
	else
	    p=((n/2)/n);
	cout<<fixed<<setprecision(10)<<p;
	//cout<<p<<endl;
}

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

def divisors(n):
    divs = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divs.append(i)
            if i != n // i:
                divs.append(n//i)
    divs.sort()
    return divs

divs = divisors(m)
ans = 1
for d in divs:
    if m // d >= n:
        ans = d
print(ans)


Measured memory_bytes: 38896
// ABC080-D
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

int N, C;
const int NN = 200100;
ll chan[32][NN];

int main() {
   cin >> N >> C;
   ll Max = 0;
   rep (i, N) {
      ll s, t, c;
      cin >> s >> t >> c;
      chan[c][s*2-1]++, chan[c][t*2+1]--;
      Max = max(Max, t*2);
   }

   for (int i = 1; i <= C; i++) { // チャンネル 1~C
      // printf("channel %d\n", i);
      for (int j = 1; j <= Max+2; j++) { // 時刻
         chan[i][j] += chan[i][j-1];
         // printf("%2lld", chan[i][j]);
         // if (chan[i][j] >= 2) chan[i][j] = 1;
      }
      // puts("");
      for (int j = 1; j <= Max+2; j++) { // 時刻
         if (chan[i][j] >= 2) chan[i][j] = 1;
      }
   }

   for (int i = 0; i < NN; i++) {
      for (int j = 1; j <= C; j++) {
         chan[j][i] += chan[j-1][i];
      }
   }

   ll ans = 0;
   for (int i = 0; i < NN; i++) {
      ans = max(ans, chan[C][i]);
      // printf("%3d", chan[C][i]);
   }
   // puts("");
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 47872
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;


using ll = long long;

//#define int ll


const int N = 1e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
bool prime(int n) {
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){return 0;}
    }return 1;}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int a[N] , logs[N];
int n;
int table[20][N];

void bldSpraseTable() {
    for(int i = 0; i <= logs[n]; i ++) {
        int curLen = 1 << i;
        for(int j = 1; j + curLen - 1 <= n; j ++) {
            if(i == 0) {
                table[i][j] = a[j];
            }
            else {
                table[i][j] = __gcd(table[i-1][j] , table[i-1][j + curLen/2]);
            }
        }
    }
}

int get(int l , int r) {
    int len = (r - l + 1);
    int plen = logs[len];
    return __gcd(table[plen][l] , table[plen][l + len - (1<<plen)]);
}

int main() {
    cin >> n;
    logs[0] = -1;
    for(int i = 1; i <= n; i ++) {
        logs[i] = logs[i/2] + 1;
        cin >> a[i];
    }
    bldSpraseTable();
    int ans = 0;

    for(int i = 2; i < n; i ++) {
        ans = max(ans , __gcd(get(1 , i-1) , get(i + 1, n)));
    }
    ans = max(ans , get(1 , n-1));
    ans = max(ans , get(2 , n));

    cout << ans;
    return 0;
}


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

int main() {

    // 現在のレート
    int r;
    
    // 目標レート
    int g;
     
     // r, gを入力
     cin >> r >> g;
     
     // 取るべきレートを出力
     cout <<  2 * g - r << endl;
}  

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

using namespace std;

typedef long long ll;

#ifdef RED
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const int N = (int)1e6 + 5;

int main() {
#ifdef RED
  freopen("a.in", "r", stdin);
#endif
  ios_base :: sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  if (s == "Sunny")
    cout << "Cloudy";
  else if (s == "Cloudy")
    cout << "Rainy";
  else 
    cout << "Sunny";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
vector<int> compose(const vector<int>& a, const vector<int>& b) {
	int n = a.size();
	vector<int> c(n);
	for (int i = 0; i < n; ++i) c[i] = a[b[i]];
	return c;
}
vector<int> power(vector<int> a, ll b) {
	int n = a.size();
	vector<int> x(n);
	iota(x.begin(), x.end(), 0);
	while (b) {
		if (b & 1) x = compose(x, a);
		a = compose(a, a);
		b >>= 1;
	}
	return x;
}
int main() {
	int n;
	scanf("%d", &n);
	vector<int> perm(n);
	vector<ll> X(n);
	iota(perm.begin(), perm.end(), 0);
	for (int i = 0; i < n; ++i) scanf("%lld", &X[i]);
	int m;
	ll k;
	scanf("%d%lld", &m, &k);
	vector<int> A(m);
	for (int i = 0; i < m; ++i) {
		scanf("%d", &A[i]);
		--A[i]; // swap A[i], A[i]+1.
		swap(perm[A[i]], perm[A[i] + 1]);
	}
	perm = power(perm, k);
	ll ans = X[0];
	printf("%lld\n", ans);
	for (int i = 1; i < n; ++i) {
		ans += X[perm[i]] - X[perm[i] - 1];
		printf("%lld\n", ans);
	}
}


Measured memory_bytes: 2944
#include<iostream>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n;
	cin>>n;
	int a[100001];
	int sum=0;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		if(a[i]==i){
			int t=a[i];
			a[i]=a[i+1];
			a[i+1]=t;
			sum++;
		}	
	cout<<sum<<endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);


int main(){
  FAST_IO  
 
  int N, k, s; cin >> N >> k >> s;

  for(int rep = 0; rep < k; ++rep) cout << s << " ";
  for(int rep = 0; rep < N - k; ++rep) cout << (s == 1e9 ? s - 1 : s + 1) << " ";

  return 0;
}

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

using namespace std;

int main(){
    long long int m = 0;
    int n, k;
    string s;
    cin >> n >> k >> s;
    for(int i = 0;i < n-1; i++){
        if(s[i] != s[i+1]){
            m++;
        }
    }
    cout << n-1-max((long long int)0,(m-2*k))<< endl;
    return 0;
}

Measured memory_bytes: 512
N,A,B = map(int,input().split())

AB = A + B

def blue(n):
    if n <= A:
        return n
    else:
        return A


if A == 0:
    print(0)
elif N <= AB:
    r = blue(N)
    print(r)
else:
    t = N // AB
    m = N % AB
    r = blue(m)
    print(t*A+r)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<math.h>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int>a(n);
    int left,right;
    REP(i,n){
        cin >>a[i];
        if(a[i] == 1){
            left = i;
            right = n-i-1;
        }
    }
    int answer = 0;
    //answer += (left+(k-2))/(k-1);
    //answer += (right+(k-2))/(k-1);
    //answer += (int)(ceil((double)left/(k-1)));
    //answer += (int)(ceil((double)right/(k-1)));
    if(n == k){
        cout << 1 << endl;
        return 0;
    }
    answer = (int)(ceil((double)(n-1)/(k-1)));
    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1LL << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<int> b = a;
	sort(rall(b));
	rep(i, n) {
		if (a[i] == b[0]) cout << b[1] << endl;
		else cout << b[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 3200
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        long x=sc.nextLong();
        long y=sc.nextLong();
  		long ans=1;
  
  		while(y>x){
         if(y>=x*2){
         x*=2;
         ans++;  
         }else{
         break;
         }
        }
    

    	System.out.println(ans);
    }
}



Measured memory_bytes: 35688
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-13;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

const int MAX_N = 100000;

double dp[MAX_N+1] = {0};

int main()
{
	dp[1] = 1.0;
	
	for(int i = 2; i <= MAX_N; i++)
	{
		double p = 1.0, win = 0.5;
		
		for(int k = 1; k < i && EPS < p; k++)
		{
			double rev = p * (1 - win);
			dp[i] += rev * (k + dp[max(0, i - k - 1)]);
			p *= win; win /= 2;
		}
		
		dp[i] += i * p;
	}

	for(int n; cin >> n && n; ) printf("%.3lf\n", dp[n]);
}

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

using namespace std;

int main()
{
  vector<int> S(3);

  cin >> S[0] >> S[1] >> S[2];

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

  if(S[0] == 5 && S[1] == 5 && S[2] == 7) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;

namespace B
{
	internal class Program
	{
		static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };

		public static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			var l = Console.ReadLine().Split().Select(int.Parse).ToArray();

			var isYes = l.Max() * 2 < l.Sum();

			Console.WriteLine(isYes ? "Yes" : "No");
		}
	}
}

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

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

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  string s;
  cin >> s;
  s = "-" + s;

  bool flg = true;
  for (int i = a; i < c; i++) {
    if (s[i] == '#' && s[i + 1] == '#') flg = false;
  }
  for (int i = b; i < d; i++) {
    if (s[i] == '#' && s[i + 1] == '#') flg = false;
  }
  if (c > d) {
    bool flg2 = false;
    for (int i = b; i <= d; i++) {
      if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') flg2 = true;
    }
    if (flg) flg = flg2;
  }
  cout << (flg ? "Yes" : "No") << endl;
}


Measured memory_bytes: 772
X , Y = map(int,input().split())
ans = 0
if X == 3:
    ans += 100000

elif X == 2 :
    ans += 200000

elif X == 1 :
    ans += 300000


if Y == 3:
    ans += 100000
elif Y == 2 :
    ans += 200000
elif Y == 1 :
    ans += 300000

if X==1 and Y == 1:
    ans += 400000
print(ans)

Measured memory_bytes: 3064
#include <cstdio>

const int maxn = 20;

int main() {
    char buf[maxn];
    scanf("%s", buf);
    for (int i = 0; i < 12; ++i) {
        if (i == 4) printf(" %c", buf[i]);
        else printf("%c", buf[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p){os<<"("<<p.first<<","<< p.second<<")";return os;}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v){os<<"{";REP(i,(int)v.size()){if(i)os<<",";os<<v[i];}os<<"}";return os;}
template <typename T, size_t S> void printArray(const T (&array)[S]){for(auto val : array)std::cout << val << ", ";std::cout << "\n";}
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
//const int dx[4] = {1, 0, -1, 0};
//const int dy[4] = {0, 1, 0, -1};
//const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve(){
    int n; cin >> n;
    string s; cin >> s;
    int res = -1;
    for(int i=1; i<=n-1; i++){
        int cnt = 0;
        string a = s.substr(0, i);
        string b = s.substr(i);
        //cout << a << " " << b << endl;
        map<char, int> mp1, mp2;
        REP(j, a.size()){
            mp1[a[j]]++;
        }
        REP(k, b.size()){
            mp2[b[k]]++;
        }
        for(auto x : mp1){
            for(auto y : mp2){
                if(x.fi == y.fi && x.se >=1 && y.se >=1) cnt++;
            }
        }
        //cout << cnt << endl;
        res = max(res, cnt);
    }
    cout << res << endl;
}

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

Measured memory_bytes: 256
MOD=10**9+7
lim=200000
inv_t = [-1 for i in range(lim+1)]
factrial = [-1 for i in range(lim+1)]
factrial_inv = [-1 for i in range(lim+1)]


def mod_inv(x, mod=MOD):
    y, u, v, _x = mod, 1, 0, x
    while y:
        t = _x//y
        _x -= t*y
        _x, y = y, _x
        u -= t*v
        u, v = v, u
    u %= mod
    if u < 0:
        u += mod
    return u

def mod_pow(a, n, mod=MOD):
    res = 1
    while n:
        if n & 1:
            res = res*a % mod
        a = a*a % mod
        n >>= 1
    return res

def COMinit(max=lim, mod=MOD):
    factrial[0] = factrial_inv[0] = 1
    factrial[1] = factrial_inv[1] = 1
    inv_t[0] = inv_t[1] = 1
    for i in range(2, max):
        factrial[i] = factrial[i-1]*i % mod
        inv_t[i] = -inv_t[mod % i]*(mod//i) % mod
        factrial_inv[i] = factrial_inv[i-1]*inv_t[i] % mod

def comb(a, b, mod=MOD):
    if a<b:
        return 0
    if factrial[0] == -1:
        COMinit()
    return (factrial[a]*factrial_inv[b]*factrial_inv[a-b]) % mod


n=int(input())
ans=0
for i in range(n//3):
    if i==0:
        ans+=1
    else:
        ans += comb(i+1+n-3*(i+1)-1,n-3*(i+1))
    # print(ans)
print(ans%MOD)

Measured memory_bytes: 32664
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll n, m;
	cin >> n >> m;
	ll MIN = 1, MAX = n;
	for (int i = 0; i < m; i++) {
		ll l, r;
		cin >> l >> r;
		MIN = max(MIN, l);
		MAX = min(MAX, r);
	}
	dump(max(MAX - MIN + 1, 0ll));
	return 0;
}

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

using namespace std;
#define REPP(i,a,b,c) for(int i=a; i<=b; i+=c)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,c) for(int i=a; i>=b; i-=c)
#define REV(i,a,b) REVV(i,a,b,1)
#define FOR(i,a) REP(i,0,(int)a-1)
#define FORD(i,a) REV(i,(int)a-1,0)
#define MP make_pair
#define PB push_back
#define POB pop_back
#define FI first
#define SE second
typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef vector < int > vi;
typedef vector < pii > vii;
typedef vector < ll > vl;

const double PI = acos(-1);
const double EPS = 1e-9;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

///////////////////////////////////////////////////////

string str;
vi lst[30];

void solve(){
	FOR(i,str.length()) lst[str[i]-'a'].PB(i);
	FOR(i,26){
		FOR(j,lst[i].size()-1){
			if(lst[i][j+1] - lst[i][j] <= 2){
				cout << lst[i][j]+1 << " " << lst[i][j+1]+1 << endl;
				return;
			}
		}
	}
	cout << -1 << " " << -1 << endl;
}

int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> str;
	solve();
	return 0;
}

Measured memory_bytes: 1104
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define MAX 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define zoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main() {

    zoom;
    ll N, i;
    cin >> N;
    string S;
    cin >> S;
    bool present[10][10][10];
    memset(present, false, sizeof(present));
    vector<ll> past(10, 0), future(10, 0);
    for(i = 1; i < N; i += 1)
    	future[S[i] - '0'] += 1;
    for(i = 0; i < N; i += 1) {
    	for(ll j = 0; j < 10; j += 1) {
    		if(past[j] == 0)
    			continue;
    		for(ll k = 0; k < 10; k += 1) {
    			if(future[k] == 0)
    				continue;
    			present[j][S[i] - '0'][k] = true;
    		}
    	}
    	if(i == N - 1)
    		break;
    	past[S[i] - '0'] += 1;
    	future[S[i + 1] - '0'] -= 1;
    }
    ll cnt = 0;
    for(i = 0; i < 10; i += 1) {
    	for(ll j = 0; j < 10; j += 1) {
    		for(ll k = 0; k < 10; k += 1) {
    			if(present[i][j][k])
    				cnt += 1;
    		}
    	}
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }
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 main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N, D;
    cin >> N >> D;

    vec2 X(N, vec(D, 0));
    rep(i, N) rep(j, D) cin >> X[i][j];

    ll ans = 0;
    rep(i, N) rep(j, N) if(i < j) {
        ll d2 = 0;
        rep(k, D) d2 += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
        bool flag = false;
        rep(k, 160) if(k * k == d2) flag = true;
        ans += flag;
    }

    print(ans);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	int q;
	long long a, b, c;
	cin >> q;
	while (q--)
	{
		cin >> a >> b;
		c = sqrt(a * b);
		if (a != b && c * c == a * b)c--;
		if (c * (c + 1) >= a * b)
			cout << 2 * c - 2 << endl;
		else cout << 2 * c - 1 << endl;
	}
	return 0;
}
/*https://www.cnblogs.com/widsom/p/8763564.html*/

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

const int w[10]={1,2,4,8,16,32,64,128,256,512};
int c[10];
int main(void){
	int n;
	int a;
	while(~scanf("%d",&n)){
		bool b=false;
		for(a=0;a<=9;a++)c[a]=0;
		for(a=9;a>=0;a--){
			if(n>=w[a])c[a]=1,n-=w[a];
			if(n==0)break;
		}
		for(a=0;a<=9;a++){
			if(c[a]==1){
				if(b==true)cout << " " << w[a];
				if(b==false){
					cout << w[a];
					b=true;
				}
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
from bisect import *
input=lambda :sys.stdin.readline().rstrip()


K,N=map(int,input().split())
A=list(map(int,input().split()))

value=10**9
value=min(value,-(A[0]-A[-1]))
for i in range(1,N):
    value=min(value,K-(A[i]-A[i-1]))
    #value=min(value,K-(A[i+1]-A[i]))
print(value)


Measured memory_bytes: 100700
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,o,s,m;
	
	scanf("%d",&m);
	while(m!=0){
		a=0;
		b=0;
		c=0;
		d=0;
		e=0;
		f=0;
		s=0;
		
		o=1000-m;
		a=o/500;
		o=o-500*a;
		b=o/100;
		o=o-100*b;
		c=o/50;
		o=o-50*c;
		d=o/10;
		o=o-10*d;
		e=o/5;
		o=o-5*e;
		f=o/1;
		o=o-1*f;
	
	s=a+b+c+d+e+f;
	
	printf("%d\n",s);
	scanf("%d",&m);
	}
	
	return 0;
}

Measured memory_bytes: 1028
using System;
using System.Linq;

namespace D___Knapsack_1
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var N = read[0];
            var W = read[1];

            var items = new int[N+1,2];
            for(int i = 1 ; i < N+1 ; i++)
            {
                read = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                items[i,0] = read[0];
                items[i,1] = read[1];
            }

            var DP = new long[N+1,W+1];
            for(int item = 1 ; item < N+1 ; item++)
            {
                for(int weight = 1 ; weight < W+1 ; weight++)
                {
                    if(weight >= items[item,0])
                    {
                        DP[item,weight] = Math.Max(DP[item-1,weight],DP[item-1,weight-items[item,0]] + items[item,1]);
                    }else{
                        DP[item,weight] = DP[item-1,weight];
                    }
                }
            }

            Console.WriteLine(DP[N,W]);
        }
    }
}


Measured memory_bytes: 91104
x1, y1, x2, y2 = map(int, input().split())

difx = x2 - x1
dify = y2 - y1

x3, y3 = x2 - dify, y2 + difx
x4, y4 = x1 - dify, y1 + difx

print(x3, y3, x4, y4)


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define high 100000000000
int n;

void func(int x,long long int *a,long long int *b)
{
	if(x==n-1) return;
	if(b[x+1]>b[x]+abs(a[x+1]-a[x])) b[x+1]=b[x]+abs(a[x+1]-a[x]);
	if(x!=n-2)if(b[x+2]>b[x]+abs(a[x+2]-a[x])) b[x+2]=b[x]+abs(a[x+2]-a[x]);
	return func(x+1,a,b);
}

int main()
{
	
	cin>>n;
	long long int a[n],i,b[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		b[i]=high;
	}
	b[0]=0;
	func(0,a,b);
	cout<<b[n-1]<<endl;
	return 0;

}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,cnt=0;
    cin>>a>>b>>c;
    if(b<a) swap(a,b);
    for(int i=a;i<=b;i++)
    {
        if(c%i==0) cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5+7;

int main(){
	int N,K;
	cin>>N>>K;
	int h[MAX];
	rep(i,N)cin>>h[i];
	sort(h,h+N);
	int ans=1e9+7;
	rep(i,N-K+1){
		ans=min(ans,h[i+K-1]-h[i]);
	}
	cout<<ans;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int A, B;
    cin >> A >> B;
    cout << (B - 1 + A - 2) / (A - 1) << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
x=[]
for i in range(m):
    p,y=map(int,input().split())
    x.append([y,p,i]) # i で sort 前の index を保持
x.sort() # y の昇順が優先される

# print(x)

a=[0]*n
ans=[""]*m
for y,p,i in x:  	
    a[p-1]+=1
    # 解答は保持した index である i の順に list 化する
    ans[i]=str(p).rjust(6,"0")+str(a[p-1]).rjust(6,"0")
for i in ans:
    print(i)

Measured memory_bytes: 32100
#include "bits/stdc++.h"

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

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cerr << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cerr << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#define debug(...) CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) (__VA_ARGS__)

using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> p(a), q(b), r(c);
  rep(i, a) cin >> p[i];
  rep(i, b) cin >> q[i];
  rep(i, c) cin >> r[i];
	std::sort(p.begin(),p.end(),std::greater<int>());
	std::sort(q.begin(),q.end(),std::greater<int>());
	std::sort(r.begin(),r.end(),std::greater<int>());
  vector<int> A;
  rep(i, x) A.push_back(p[i]);
  rep(i, y) A.push_back(q[i]);
  sort(A.begin(), A.end());
  int j = 0;
  for(int i = 0; i<x+y && A[i] < r[j]; ++i) A[i] = r[j++];
  ll ans = 0;
  for(int a : A) ans += a;
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



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

typedef double f64;
typedef long long i64;
typedef int i32;
typedef pair<i32, i32> pi32;
typedef unsigned long long u64;
typedef unsigned int u32;
typedef vector<i32> vi32;
typedef deque<i32> di32;

#define all(c) (c).begin(), (c).end()
#define REP(i, a, b) for (auto i = a; i < b; i++)
#define REPA(i, a, b, acc) for (auto i = a; i < b; i += acc)
#define PB push_back
#define PF push_front
#define PRINT(x) cout << #x ": " << (x) << endl;
#define TR(c, it) for (auto(it) = (c).begin(); (it) != (c).end(); (it)++)
#define MAX_PRECISION cout << setprecision(numeric_limits<double>::max_digits10);

i32 main() {
  ios::sync_with_stdio(false);  // Makes IO faster, remove this line if C style scanf/printf needed.

  i64 n;
  cin >> n;
  i64 s = INT64_MAX;
  REP(i, 0, 5) {
    i64 num;
    cin >> num;
    s = min(num, s);
  }
  cout << 4 + (n / s) + (n % s > 0 ? 1 : 0) << endl;
}


Measured memory_bytes: 256