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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=0;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n;
	cin>>n;

	lli p=1;
	for(lli i=1;i<=n;i++){
		p*=i;
		p%=MOD;
	}
	cout<<p<<endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = sorted(list(map(int, input().split())))
ans = a.pop()
if n % 2:
    for i in range((n - 2) // 2):
        ans += a.pop() * 2
    ans += a.pop()
    print(ans)
else:
    for i in range((n - 2) // 2):
        ans += a.pop() * 2
    print(ans)

Measured memory_bytes: 31540
import scala.io.StdIn._
import scala.math._

object Main {
  def main(args: Array[String]): Unit = {
    val n = readLine.toInt
    val a = readLine.split(" ").map(_.toInt)
    println(solve(n, a))
  }

  def solve(n: Int, a: Array[Int]): Int = {
    val s: Double = a.sum
    val h = s / n
    var index: Int = -1
    var min: Double = 100000000
    for {
      i <- 0 to n-1
    } {
      if(abs(a(i) - h) < min){
        index = i
        min = abs(a(i) - h)
      }
    }
    index
  }
}


Measured memory_bytes: 25536
#include<iostream>
#include<algorithm>
using namespace std;
#define INFTY (1<<30)

int n;
double p[550], q[550], M[550][550], P[550][550];

void setP( void ) {
  for ( int i = 0; i < n + 1; i++ ) P[i][i] = q[i];
  for ( int i = 0; i < n; i++ ) {
    for ( int j = i + 1; j < n + 1; j++ ) P[i][j] = P[i][j - 1] + p[j] + q[j];
  }
}

void setM( void ) {
  for ( int i = 0; i < n + 1; i++ ) M[i][i] = q[i];
  for ( int l = 1; l < n + 1; l++ ) {
    for ( int i = 0; i < n - l + 1; i++ ) {
      int j = i + l;
      M[i][j] = INFTY;
      for ( int k = i + 1; k < j + 1; k++ ) {
        M[i][j] = min(M[i][j], M[i][k - 1] + M[k][j] + P[i][j]);
      }
    }
  }
}

int main() {
  cin >> n;
  for ( int i = 1; i < n + 1; i++ ) cin >> p[i];
  for ( int i = 0; i < n + 1; i++ ) cin >> q[i];
  
  setP();
  setM();

  cout << M[0][n] << endl;

  return 0;
}


Measured memory_bytes: 7584
N = int(input())
A = list(map(int, input().split()))

ans = 1
status = "Unset"
for i in range(1, N):
    if status == "Unset":
        if A[i-1] < A[i]:
            status = "UP"
        elif A[i-1] > A[i]:
            status = "DOWN"

    else:
        if status == "UP" and A[i-1] > A[i]:
            ans += 1
            status = "Unset"

        if status == "DOWN" and A[i-1] < A[i]:
            ans += 1
            status = "Unset"

print(ans)


Measured memory_bytes: 14252
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner fs = new Scanner(System.in);
        String s = fs.next();
        int max = 0 ;
        for(int i=0 ; i<3 ; i++){
            int cons = 0 ;
            if(s.charAt(i)=='R'){
                cons++;
                max = Math.max(max,cons);
            }else{
                continue;
            }
            for(int j=i+1; j<3 ; j++) {
                if(s.charAt(j)=='R'){
                    cons++;
                    max = Math.max(max,cons);
                }else{
                    break;
                }
            }
        }

        System.out.println(max);

    }
}


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

using ll=long long; 

void solve(){
	int n,m;
	cin>>n>>m;
	vector<int> match(m+1);
	for(int i=0; i<m+1; i++){
		match[i]=0;
	}
	vector<vector<int> > a(n);
	int k;
	for(int i=0; i<n; i++){
		cin>>k;
		int x;
		for(int j=0; j<k; j++){
			cin>>x;
			a[i].push_back(x);
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<a[i].size(); j++){
			match[a[i][j]]++;
		}
	}
	int cnt=0;
	for(int i=0; i<m+1; i++){
		if(match[i]==n){
			cnt++;
		}
	}
	cout<<cnt<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
int main() 
{
    int n;
    cin >> n;

    for(int i=1;i<10;i++){
      for(int j=i;j<10;j++){
        if(i*j==n){
          cout << "Yes" << endl;
          return 0;
        }
      }
    }
      cout << "No" << endl;
  		return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cassert>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll INF = -1e18;
const int I=2001;

struct f{f(int a){cout<<a<<endl;}};
int uo() {int x; cin>>x; return x;}
int ou() {int x; cin>>x; return x;}
int main(){
  int n=uo(); int s[n];
  for(int i=0;i<n;i++) s[i] = uo();
  int q=uo(); int t[q];
  for(int i=0;i<q;i++) t[i] = ou();
  int an=0;
  for(int i=0;i<q;i++) {
    int l=-1, r=n+1; bool ok=false;
    while(r-l>1 && ok==false) {
      int md=(l+r)/2;
      if (s[md]<t[i]) l=md;
      else if (s[md]==t[i]) ok=true;
      else r=md;
      //cout<<l<<" "<<r<<endl;
    }
    an += ok;
  }
  f hello(an);
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;

int main(){
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    
    int a;
    cin >> a;

    cout << a+pow(a,2)+pow(a,3) << endl;
    return 0;
}


Measured memory_bytes: 4128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#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 (b<a) { a=b; return 1; } return 0; }
using namespace std;


int main(){
  ll N;
  cin>>N;
  ll A[N];
  REP(i,N) cin>>A[i];
  
  ll t=1;
  for(int i=0; i<N; ++i){
    if(A[i]==t) t++;
  }
  
  if(t==1){
    cout<<-1<<endl;
    return 0;
  }
  
  cout<<N-t+1<<endl;
  return 0;
}

Measured memory_bytes: 5028
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long 
#define int long long 
#define vll vector<long long>
#define pii pair<long long ,long long > 
#define vvi vector< vector<long long > > 
#define vpii vector<pair<int,int>> 
#define pll  pair<long long ,long long > 
#define pb  push_back
#define ff  first 
#define sec second  
#define SORT(a) sort(a.begin(),a.end())
#define SORTR(a) sort(a.rbegin(),a.rend()) 
#define m_p make_pair
#define all(x) (x.begin(),x.end()) 
#define sz(v) ((int)(v.size()))
#define endl '\n'
typedef vector< long long > vi ;
const int MOD=1e9 +7 ;
int size=10000000; 
 
int32_t main(){
  fast; 
/*  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif 
    */
  int T=1; //cin>>T; 
  while(T--){

    int n,d,a; cin>>n>>d>>a;  int sum=0; 
    vpii h(n); for(int i=0;i<n;i++) { int x,y; cin>>x>>y; h[i]={x,y}; sum+=y; } 


    SORT(h); int ans =0; 
    vi pfx(n+1); 

    //int j=0; //int ans=0;  
    for(int i=0;i<n;i++){
         int s=h[i].ff+2*d; 
         pii p={s,MOD}; 
         int it=lower_bound(h.begin(),h.end(),p)-h.begin(); 

        int val=(h[i].sec-pfx[i]*a+a-1)/a; 
            val=max(val,(int)0); 
        ans+=val;    
        pfx[i]+=val; 
        pfx[it]-=val;    
        pfx[i+1]+=pfx[i]; 
    }

    cout<<ans<<endl; 

  }
    


  return 0; 
} 


Measured memory_bytes: 7884
main::IO()
main = do
  str<-getLine
  putStr (b_to_YN (solver str))
  putStr "\n"

solver::String -> Bool
solver []     = False
solver (c:cs) = if c == 'C' then subsolver cs else solver cs

subsolver::String ->Bool
subsolver []     = False
subsolver (c:cs) = if c == 'F' then True else subsolver cs

b_to_YN::Bool -> String
b_to_YN b = if b then "Yes" else "No"

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

int main()
{
	int cnt = 0, r = -1, i = 0;
	string s;
	cin >> s;
	if (s[0] == 'A')
	{
		if (s[1] >= 65 && s[1] <= 90)
		{
			r = 2;
		}
		for (i = 2; i < s.length() - 1; i++)
		{
			if (s[i] == 'C')
			{
				cnt++;
			}
		}
		for (int y = i; y < s.length(); y++)
		{
			if (s[y] >= 65 && s[y] <= 90)
			{
				r = 1;
			}
		}
		if (r == -1 && cnt == 1)
		{
			cout << "AC";
		}
		else
		{
			cout << "WA";
		}
	}
	else
	{
		cout << "WA";
	}
	return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n; 
    cin >> n;
    map<string, int> mp;
    rep(i, n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;

    return;
}

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

Measured memory_bytes: 3656
N, X = list(map(int, input().split()))
pos = list(map(int, input().split()))
dis = []

for p in pos:
	dis.append(abs(p - X))

def gcd(a, b):
	p = a
	q = b
	r = p % q
	while r > 0:
		p = q
		q = r
		r = p % q
	return q

dis.sort()
ans = dis[0]
for d in dis:
	ans = gcd(d, ans)
print(ans)

Measured memory_bytes: 14224
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();
      long a = sc.nextLong();
      long b = sc.nextLong();
      long c = sc.nextLong();
      long d = sc.nextLong();
      long e = sc.nextLong();
      long x = Math.min(a,b);
      long y = Math.min(c,d);
      long min = Math.min(x,Math.min(y,e));
      long s = 0;
      if(n%min==0)s = n/min;
      else s = n/min+1;
      System.out.println(4+s);
    }
}

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

using namespace std;

int main() {
    string A, B, C, D, E;
    cin >> A;
    int ans=0;
    if (A.at(0)=='o')
    {
        ans++;
    }if (A.at(1)=='o')
    {
        ans++;
    }if (A.at(2)=='o')
    {
        ans++;
    }
    cout << 700+100*ans << endl;
    return 0;
}

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

int main() {
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end());
  cout << (a[0] == 5 && a[1] == 5 && a[2] == 7 ? "YES" : "NO") << endl;
}

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

int gunc(int i){
  int ans=1;
  for(int j=i;j>0;j--){
    ans *= j;
  }
  return ans;
}

int count(vector<int> vec,int k,int n){
  int ans =0;
  for(int i=k+1;i<n;i++){
    if(vec.at(k) > vec.at(i)){
      ans++;
    }
  }
  
  return ans;
}

int func(vector<int> vec,int n){
  int k=1;
  int m=n;
  for(int i=0;i<n-1;i++){
    k += (count(vec,i,n) -1)*gunc(m-1);
    m--;
  }
  return k;
}

int main(){
  int n;
  cin >> n;
  vector<int> p(n),q(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);
  }
  for(int i=0;i<n;i++){
    cin >> q.at(i);
  }
  
  cout << max(func(p,n)-func(q,n),func(q,n) -func(p,n)) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> S;
  sum=INF;
  N=S.size();
  rep(i,0,26){
    T="a";
    T[0]=(char)('a'+i);
    string G=S;
    num=0;
    while(101>num){
      flag=1;
      rep(i,0,N-num)if(G[i]!=T[0])flag=0;
      if(flag){
        chmin(sum,num);
        break;
      }
      num++; 
      rep(i,0,N-num)if(G[i]==T[0]||G[i+1]==T[0])G[i]=T[0];
    }
  }
  Out(sum);
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iostream>
using namespace std;
#define max(a,b) a > b ? a : b
vector<pair<int,int> > island[805];
int node_max[805][805]; // 根　各島　　との距離
bool visited[805][805] = {};
int leaf[805] = {};

void dfs(int a,int b){
  int i,j,k;
  visited[a][b] = 1;
  for( i = 0; i < island[b].size(); i++){
    //cout << "island_outloop : " << island[a][i].first << endl;
    if(!visited[a][ island[b][i].first ] && !leaf[a] && !leaf[ island[b][i].first]){
      //cout << "a = " << a << "    " << "b = " << b << endl;
      //cout << "island : " << island[b][i].first << endl;
      //cout << "node_max[a][b] = " << node_max[a][b] << endl;
      node_max[a][ island[b][i].first ] = node_max[a][b] + island[b][i].second;
      //cout << "go to dfs" << endl;
      dfs(a, island[b][i].first);
      //cout << "node_max = "  << node_max[a][island[b][i].first] << endl;
    }
  }
}

int main(){
  int i,j,k,l;
  int n;
  int p[805];
  int d[805];
  int ans,dia; //木の直径
  while(cin >> n && n){
    ans = 0;
    dia = 0;
    for(i = 2;i <= n;i++){
      cin >> p[i];//連結先の島
      //cout << p[i] << endl;
    }
    for(i = 2;i <= n;i++){
      cin >> d[i];
      island[ p[i] ].push_back(make_pair( i, d[i]));
      island[i].push_back(make_pair( p[i], d[i]));
      ans += d[i] * 3;
      //cout << d[i] << endl;
    }
    for(i = 1;i <= n;i++){ // 葉を記録
      if(island[i].size() == 1){
        leaf[i]++;
        ans -= 2* island[i][0].second;
      }
    }
    /*for(i = 1;i <= n; i++){ // 葉を削除
      if(leaf[i]){
        ans -= 2 * island[i][0].second;
        k = island[i][0].first;
        for(j = 0;j <= n;j++){
          if(island[k][j].first == i){
            cout << island[k][j].first << endl;
            break;
          }
        }
        //cout << "before:" << island[k].size() << endl;
        island[k].erase(island[k].begin() + j);
        //cout << "after:" << island[k].size() << endl;
        island[i].pop_back();
      }
    }*/
    for(i = 1;i <= n; i++){
      dfs(i,i);
      for(j = 1;j <= n;j++){
        dia = max(dia,node_max[i][j]);
      }
    }
    //cout << ans << endl;
    //cout << dia << endl;
    cout << ans-dia << endl;
    for(i = 1;i <= n;i++){
      island[i].clear();
      leaf[i] = p[i] = d[i] = 0;
      for(j = 1;j <= n;j++){
        node_max[i][j] = visited[i][j] = 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 6412
#include<bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint(){
	int x=0,p=1;char c=getchar();
	while (c<=32)c=getchar();
	if(c==45)p=-p,c=getchar();
	while (c>32)x=x*10+c-48,c=getchar();
	return x*p;
}
using namespace std;
//ruogu
//
int main(){
	int n=getint();
	if(n&1){
		int x=(n+1)/2;
		printf("%.8f\n",1.0*x/n);
	}
	else cout<<"0.5\n";
	return 0;
}


Measured memory_bytes: 256
def MII(): return map(int,input().split())
def LMI(): return list(map(int,input().split()))
import copy

n,k=MII()
hights=LMI()
money_list=[]
for i in range(2**(n-1)):
    bit = [i>>j&1 for j in range(n-1)]
    hights_copy=copy.deepcopy(hights)
    money=0
    if sum(bit)==k-1:
        for a in range(n-1):
            if bit[a]==1:
                tmp=max(hights_copy[:a+1])+1
                if tmp>hights_copy[a+1]:
                    money+=(tmp-hights_copy[a+1])
                    hights_copy[a+1]=tmp
        money_list.append(money)
print(min(money_list))

Measured memory_bytes: 77104
K,N = map(int,input().split())
A = list(map(int,input().split()))
d_0 = (K - A[N-1]) + A[0]
D = [d_0]
for i in range(N-1):
    d = A[i+1] - A[i]
    if d > D[-1]:
        D.append(d)
ans = K - D[-1]
print(ans)

Measured memory_bytes: 26060
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
using namespace std;
int parse(string in,int l,int r)
{
	if(in[l]!='[')
	{
		int res=0;
		for (int i = l; i < r+1; i++) {
			res*=10;
			res+=in[i]-'0';
		}
		return res/2+1;
	}

	vector<int> res;
	int num=0;
	int nl,nr;
	for (int i = l; i < r+1; i++) {
		if(in[i]=='[')
		{
			if(!num) nl=i;
			num++;
		}
		if(in[i]==']')
		{
			num--;
			if(!num) nr=i;
		}
		if(num==0&&in[i]==']')
		{
			int rec=parse(in,nl+1,nr-1);
			res.push_back(rec);
		}
	}
	int ans=0;
	sort(res.begin(),res.end());
	for (int i = 0; i <= res.size()/2; i++) {
		ans+=res[i];
	}
	return ans;
}
int main(void)
{
	int n; cin>>n;
	while (n--) {
		string in; cin>>in;
		int res=parse(in,0,in.size()-1);
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 1332
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define abdelrahman010 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
using namespace std;
const int N = 2e3 + 5;
int n , a[N] , freq[N];
int main() {
    abdelrahman010
    cin >> n;
    for(int i = 0;i < n;i++) {
        cin >> a[i];
        freq[a[i]]++;
    }
    sort(a , a + n);
    for(int i = 1;i < N;i++)
        freq[i] += freq[i - 1];
    ll ans = 0;
    for(int i = 0;i < n;i++)
        for(int j = i + 1;j < n;j++) {
            int dif = a[j] - a[i];
            int cnt = freq[a[i] + a[j] - 1] - freq[dif];
            if(cnt)
                ans = ans + cnt - (bool)(a[i] > dif) - (bool)(a[j] - dif);
        }
    cout << ans / 3;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll g(ll N){
    if (N%4==0){
        return N;
    }
    else if(N%4==1){
        return 1;
    }
    else if(N%4==2){
        return N+1;
    }
    else{
        return 0;
    }
}
int main(void){
    ll A,B;
    cin>>A>>B;
    cout<<(g(A-1)^g(B))<<endl;
    return 0;
}


Measured memory_bytes: 256
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>

using namespace std;
# define ll long long
# define int long long  //comment it out when MLE
# define endl "\n"
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define mod 998244353
# define pi acos(-1)
# define fi first
# define se second
int add(int a, int b) {
	a += b;
	if (a >= mod) a -= mod;
	return a;
}

int mul(ll a, int b) {
	a *= b;
	return a % mod;
}
int dp[200005],dp2[200005];
int mm=2019;
signed main()
{
    gok
  string s;
  cin>>s;

  int n=s.size();
  int ten=10;
  dp[0]=1;
  for(int i=1;i<=n;i++)
  {
      dp[i] *= dp[i-1];
      dp[i] %= mm;
      ten*=10;
  }
  reverse(s.begin(),s.end());
  dp2[0]=0;
  ten=10;
  map<int,int> mp;
  //mp[dp2[0]]++;
  mp[0]++;
  int an=0;
  for(int i=1;i<=n;i++)
  {
      int tt = ten*(s[i-1]-'0') + dp2[i-1];
      tt %= mm;
    //  cout<<tt<<" ";
      dp2[i]=tt;
    /*  if(mp[tt]!=0)
      {
          an += (mp[tt]*(mp[tt]+1))/2;

      }*/
      mp[tt]++;
      ten*=10;
      ten%=mm;
  }
for(auto ii:mp)
{
    if(ii.se>0)
    {
        an += (ii.se*(ii.se-1))/2;
    }
}

cout<<an;













    return 0;
    }


Measured memory_bytes: 6828
#include <bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;

int h,n;

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>h>>n;
    int a[n];
    int b[n];
    for(int i = 0; i<n;i++){
        cin>>a[i]>>b[i];
    }
    int dp[20010];
    memset(dp,INF,sizeof(dp));
    dp[0] = 0;
    for(int i=0;i<n;i++){
        for(int j = a[i]; j <= 20000; j++){
            dp[j] = min(dp[j], (dp[ j-a[i] ] + b[i]) );
        }
    }
    int minc = INF;
    for(int i = h; i <=20000;i++){
        minc = min(minc,dp[i]);
    }
    cout<< minc <<endl;
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();

		if(N%10==3) {
			System.out.println("bon");
		}else if((N%10==0) || (N%10==1) || (N%10==6) || (N%10==8)){
			System.out.println("pon");
		}else {
			System.out.println("hon");
		}

	}

}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;


int main() {
    int h, w; cin >> h >> w;

    V<V<int> > c(10, V<int>(10, INT_INF));
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            cin >> c[i][j];
        }
    }

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

    int ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            int a; cin >> a;
            if(a != -1) ans += c[a][1];
        }
    }
    cout << ans << endl;
}


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

int H, W;
char A[1000][1000];

const int INF = 100000000;
typedef pair<int, int> P;

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

int bfs() {
  queue<P> que;
  int maxd;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (A[i][j] == '#') {
        que.push(P(i, j));
        d[i][j] = 0;
      }
      else d[i][j] = INF;
    }
  }
  while (que.size()) {
    P p = que.front(); que.pop();
    for (int i = 0; i < 4; i++) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (0 <= nx && nx < H && 0 <= ny && ny < W &&
          A[nx][ny] == '.' && d[nx][ny] == INF) {
        que.push(P(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
        maxd = d[nx][ny];
      }
    }
  }
  return maxd;
}

int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      cin >> A[i][j];
  cout << bfs() << endl;
  return 0;
}

Measured memory_bytes: 13328
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>

using namespace std;

#define RED false
#define BLACK true

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

bool valid(int x, int y, const vector<vector<bool> >& area){
  return 0 <= x && x < w && 0 <= y && y < h && area[x][y];
}

int main(){
  while(true){
    cin >> w >> h;
    if(w == 0 && h == 0)
      return 0;

    vector<vector<bool> > area(w, vector<bool>(h, BLACK));
    pair<int, int> hito;
    for(int i = 0; i < h; i++){
      string line;
      cin >> line;
      for(int j = 0; j < w; j++){
        if(line[j] == '#'){
          area[j][i] = RED;
        } else if(line[j] == '@'){
          hito = { j, i };
        }
      }
    }

    queue<pair<int, int> > qu;
    qu.push(hito);

    vector<vector<bool> > visit(w, vector<bool>(h, false));
    visit[hito.first][hito.second] = true;

    int ans = 1;

    while(!qu.empty()){
      auto now = qu.front();
      // cout << "now: " << now.first << ", " << now.second << endl;
      qu.pop();
      for(int i = 0; i < 4; i++){
        auto dst = make_pair( now.first + dx[i], now.second + dy[i] );
        if(valid(dst.first, dst.second, area) && !visit[dst.first][dst.second]){
          visit[dst.first][dst.second] = true;
          ans++;
          qu.push(dst);
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3132
#include <iostream>
using namespace std;
int main()
{
  int n;
  cin >> n;
  int x,count = 0;
  for(int i = 0;i < n;i++)
  {
    cin >> x;
    while(x % 2 == 0)
    {
      x = x / 2;
      count++;
    }
  }
  cout << count << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string K;
	int D;
	cin >> K >> D;
	vector<vvll> dp(SZ(K) + 1, vvll(D, vll(2, 0)));
	dp[0][0][1] = 1;
	REP(i, SZ(K)) {
		int r = K[i] - '0';
		REP(next, 10) {
			REP(j, D) {
				if (r == next) {
					dp[i + 1][(next + j) % D][1] += dp[i][j][1];
					dp[i + 1][(next + j) % D][0] += dp[i][j][0];
				}
				else if(r > next){
					dp[i + 1][(next + j) % D][0] += dp[i][j][0] + dp[i][j][1];
				}
				else {
					dp[i + 1][(next + j) % D][0] += dp[i][j][0];
				}
				dp[i + 1][(next + j) % D][0] %= MOD;
				dp[i + 1][(next + j) % D][1] %= MOD;
			}
		}
	}
	cout << (dp[SZ(K)][0][0] + dp[SZ(K)][0][1] - 1 + MOD) % MOD << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 55552
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<10;i++)
        for(int j=1;j<10;j++)
            if(i*j==n)
            {
                cout<<"Yes";
                return 0;
            }
    cout<<"No";
}

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


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

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


int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	int k, x, ans =0;
	cin >>k >>x;
	if(k*500>=x) puts("Yes");
	else puts("No");
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int parent(int);
int left(int);
int right(int);

int main()
{

  int H, i;
  int A[250];

  scanf("%d", &H);

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

  for(i=1; i<=H; i++){
    printf("node %d: ", i);
    printf("key = %d, ", A[i]);
    if(parent(i) > 0 && parent(i) <= H) printf("parent key = %d, ", A[parent(i)]);
    if(left(i) > 0 && left(i) <= H) printf("left key = %d, ", A[left(i)]);
    if(right(i)> 0 && right(i) <= H) printf("right key = %d, ", A[right(i)]);
    printf("\n");
  }

  return 0;
}

int parent(int i){

  return i / 2;

}

int left(int i){

  return 2 * i;

}

int right(int i){

  return 2 * i + 1;

}

Measured memory_bytes: 600
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<i_i, int> p_i;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
template<class T> using vv=vector<vector< T > >;
typedef deque<int> di;
typedef deque<deque<int> > ddi;

vvi edge;
vi prenum;
vi lowest;
vi parent;
int timer;

void dfs(int u, int prev) {
  prenum[u] = timer;
  lowest[u] = timer;
  timer += 1;

  for (auto v : edge[u]) {
    if (prenum[v] < 0) {
      parent[v] = u;
      dfs(v, u);
      lowest[u] = min(lowest[u], lowest[v]);
    } else if (v != prev) {
      lowest[u] = min(lowest[u], prenum[v]);
    }
  }
}

int main() {
  int v, e;
  cin >> v >> e;
  edge.resize(v);
  prenum.resize(v, -1);
  lowest.resize(v);
  parent.resize(v);
  rep (i, e) {
    int s, t;
    cin >> s >> t;
    edge[s].pb(t);
    edge[t].pb(s);
  }
  timer = 0;
  dfs(0, -1);

  int zero_parent = 0;
  set<int> ans;
  FOR(i, 1, v) {
    if (parent[i] == 0) {
      zero_parent += 1;
    } else {
      if (prenum[parent[i]] <= lowest[i]) {
        ans.insert(parent[i]);
      }
    }
  }
  if (zero_parent >= 2) {
    ans.insert(0);
  }
  for (auto i : ans) {
    printf("%d\n", i);
  }

  return 0;
}

Measured memory_bytes: 4652
x1, y1, x2, y2 = map(int, input().split())
dx, dy = x2 - x1, y2 - y1
def rot(x, y):
    return -y, x
dx, dy = rot(dx, dy)
x3, y3 = x2 + dx, y2 + dy
dx, dy = rot(dx, dy)
x4, y4 = x3 + dx, y3 + dy
print(x3, y3, x4, y4)


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


int main(){

    ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;

    int n ; cin >> n ;
    double t ; cin >> t ;
    int a ; cin >> a;
    vector < double > ve;
    for(int i = 0 ; i < n ; i++){
         double x ; cin >> x ;
         ve.push_back(x) ;
    }

    double res = 1e9 ;
    int idx = -1 ;
    for(int i = 0 ; i < n ; i++){
         double avg = t - ( ve[i] * 0.006 ) ;
         if(fabs(avg - a) < res){
             res = fabs(avg - a);
             idx = i + 1;
         }
    }

    cout << idx << endl ;


    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Program {
    static void Main (string[] args) {
        int K = int.Parse (Console.ReadLine ());

        if (K % 2 == 0 || K % 5 == 0) {
            Console.WriteLine (-1);
        } else {
            if (K % 7 == 0) {
                K = K / 7;
            }
            if (K == 1) {
                Console.WriteLine (1);
            } else {
                K = K * 9;
                long ans = 1;
                long tmp = 10;
                while (tmp != 1) {
                    tmp = 10 * tmp % K;
                    ans++;
                }
                Console.WriteLine (ans);
            }

        }
    }

}

//dotnet run --project test

Measured memory_bytes: 27504
a,b = map(int, input().split())
c = input().split()
m = 0
for i in range(len(c)):
    c[i] = int(c[i])
    m += c[i]
c.sort(reverse=True)
if c[b-1] >= m * (1 / (4*b)):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  int N;
  int A;
  cin >> N>> A;
  int x=(N+A-1)/A;
  cout << x << endl;
}

Measured memory_bytes: 256
#C - Skip
import sys

N, X = map(int, input().split())
x_list = list(map(int, input().split()))

residual = [abs(x - X) for x in x_list]

def gcd(a,b):
    if(b==0):
        return a
    else:
        return gcd(b, a%b)
        
max_ = 0
for i in range(len(residual)):
    if(N==1):
        print(residual[0])
        break
    
    if(i == 0):
        max_ = gcd(residual[i], residual[i+1])
    elif(i == N-1):
        print(max_)
    else:
        max_ = gcd(residual[i], max_)

        

Measured memory_bytes: 14224
//stay hungry, stay foolish
//#include <iostream>
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define loopi(stop) for(int i=0; i<stop; i++)
#define loopj(stop2) for(int j=0; j<stop2; j++)
#define loopk(stop3) for(int k=0; k<stop3; k++)
#define loopi1(stop) for(int i=1; i<=stop; i++)
#define loopj1(stop2) for(int j=1; j<=stop2; j++)
#define loopk1(stop3) for(int k=1; k<=stop3; k++)
#define loopse(kt,sstart, eend) for(int kt = sstart; kt<eend; kt++)
#define faster_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define file_io_cf freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define p_b push_back
#define pii pair<int,int>
#define fi first
#define se second
#define prec_10 << fixed << setprecision(10)
#define DEB cout<<"DEBUG"<<'\n';
#define SRAND srand(time(0));
#define rev_comp  greater<int>()
using namespace std;
 
template <typename T>
void O(T x){
    cout<<x<<'\n';
}

ld dp[305][305][305];

int n;

ld go(int a, int b, int c){

    if(dp[a][b][c] != -1){
        return dp[a][b][c];
    }

    if((a==0) && (b==0) && (c==0)){
        return 0;
    }

    //expected number of trials for selecting this sushi
    ld ans = (ld)n/(ld)(a+b+c);

    //(expected number of trials from remaining sushi's if the chosen dish (this one) has 1 shushi) * (probability of selecting a dish with one sushi this time)
    if(a!=0){
        ans += (go(a-1,b,c) * ((ld)a/(ld)(a+b+c))); 
    }

    if(b!=0){
        ans += (go(a+1,b-1,c) * ((ld)b/(ld)(a+b+c)));
    }
    
    if(c!=0){
        ans += (go(a,b+1,c-1) * ((ld)c/(ld)(a+b+c)));
    }

    dp[a][b][c] = ans;

    return dp[a][b][c];
}




int32_t main(){
        
    faster_io
    // file_io_cf
        
    loopi(305){
        loopj(305){
            loopk(305){
                dp[i][j][k] = -1;
            }
        }
    }

    int arr[4] = {0};

    cin>>n;
    int temp;
    loopi(n){
        cin>>temp;
        arr[temp] += 1;
    }

    cout prec_10<<go(arr[1],arr[2],arr[3]);
         
    return 0;
}


Measured memory_bytes: 443648
#include <bits/stdc++.h>
#define MAXN 110
#define MAXK 100100
#define M 1000000007
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int n,K;
int A[MAXN];
int dp[MAXN][MAXK];

inline int mod(int a,int m){
	int r = a%m;
	if(r<0)r+=m;
	return r;
}



int32_t main(){
	fastio;
	cin>>n>>K;
	for(int i=1;i<=n;i++)cin>>A[i];
	
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	for(int i=1;i<=n;i++)dp[i][0]=1;
	int soma=0;
	 
	for(int i=1;i<=n;i++){
			soma=dp[i-1][0];
		for(int j=1;j<=K;j++){
			
			soma=mod(soma+dp[i-1][j],M);
			
			if(j>A[i]){
			soma=mod(soma-dp[i-1][j-A[i]-1],M);
			
			//	cout<<j<<" "<<A[i]<<" "<<j-A[i]<<endl;
			}
			
			dp[i][j]=mod(soma,M);
		//	cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
		}
	}	   	 	
	
		
	
	   	cout<<dp[n][K]<<endl; 		
	   	 		
}

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

int main()  {
  int h,w;
  cin >> h >> w;
  vector<string> vec(h);
  for(int i = 0; i < h; i++) {
    cin >> vec.at(i);

}
  for(int i = 0; i < w+2; i++) {
    cout << "#";

  }
cout << endl;

  for(int i = 0; i < h; i++) {
    cout << "#" + vec.at(i) + "#" << endl;
  }
  for(int i = 0;i < w+2; i++ ) {
    cout << "#";
} 
    cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int str_chnum(const char *str, int c)
{
    int count = 0;

    while (*str)
        if (*str++ == c)
            count++;
        return (count);
}

int main()
{
    int i, n;
    char str[256];
    int r, b;
    
    scanf("%d", &n);
    scanf("%s", str);
    r = str_chnum(str, 'R');
    b = str_chnum(str, 'B');

    if (r > b)
        puts("Yes");
    else
        puts("No");

    return (0);
}

Measured memory_bytes: 128
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
using namespace std;

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

	for (int i = 0; i < m; i++) {
		cout << accumulate(t.begin(), t.end(), 0) - t[p[i]-1] + x[i] << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define EPS 1e-8
#define DEB 0

/*
const int dx[] = {0,1,0,-1}; //u,r,d,l
const int dy[] = {-1,0,1,0};
*/
const int dx[] = {1,0,-1,0}; //r,d,l,u
const int dy[] = {0,1,0,-1};

int w,h,sx,sy,home,last;
int field[16][16];
int num[16][16];

class state{
public:
  char x,y;
  int s;
  state(char _x, char _y, int _s){
    x = _x;
    y = _y;
    s = _s;
  }
  
  bool operator<(const state& a)const{
    if( s==a.s ){
      if( x==a.x ) return y<a.y;
      else         return x<a.x;
    }else{
      return s<a.s;
    }
  }
  
};

int numofbits(int bits) {
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
  return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}



map<state,int> msi;

bool isgoal(int s){
  return (((last&s)) == last);
}
bool inside(int x, int y){
  return (x<0 || y<0 || x>=w || y>=h);
}


int dfs(int x, int y, int s){
  if( (1<<home)-1 == s ){ //âÎÉßêé
    return 1;
  }
  if( isgoal(s) ){ //³ïÉßé½ßÌÆðÁïµ½©Ç¤©
    return 0;
  }
  if( msi.count(state(x,y,s)) ){ //ùÉÊÁ½óÔ
    return msi[state(x,y,s)];
  }
  
  int ret = 0;
  rep(k,4){
    for(int i=1; i<20; i++){
      int tx = x + dx[k]*i;
      int ty = y + dy[k]*i;
      if( inside(tx,ty) ) break;
      if( field[ty][tx]==1 ){
	field[ty][tx] = 0;
	ret += dfs(tx,ty,s|(1<<num[ty][tx]));
	field[ty][tx] = 1;
	break;
      }
    }
  }
  if( ret!=0 ){
    msi[state(x,y,s)] = ret;
  }
  return ret;
}

int main(){

  while(scanf("%d%d",&w,&h),w|h){
    msi.clear();
    memset(num,-1,sizeof(num));
    home = last = 0;
    rep(i,h){
      rep(j,w){
	scanf("%d",&field[i][j]);
	if( field[i][j]==2 ){
	  sx = j;
	  sy = i;
	}
	if( field[i][j]==1 ){
	  num[i][j] = home;
	  home++;
	}
      }
    }

    //last homes
    rep(k,4){
      for(int i=1; i<20; i++){
	int tx = sx + dx[k]*i;
	int ty = sy + dy[k]*i;
	if( inside(tx,ty) )break;
	if( field[ty][tx]==1 ){
	  last |= (1<<num[ty][tx]);
	}
      }
    }

    printf("%d\n",dfs(sx,sy,0));
  }
  

  return 0;
}

Measured memory_bytes: 12000
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define reg register
#define rep(i, a, b) for (reg int i = (a), i##end = (b); i <= i##end; ++i)
#define dep(i, a, b) for (reg int i = (a), i##end = (b); i >= i##end; --i)

template <typename _typer> inline _typer read() {
    _typer init = 0;
    char ch = getchar(), k = 0;
    for ( ; !isdigit(ch); ch = getchar()) k = (ch == '-');
    for ( ; isdigit(ch); ch = getchar())
        init = (init << 3) + (init << 1) + (ch ^ 48);
    return k ? -init : init;
}
const ll N = 3005, INF = 1e9;

int P, B[N], C[N][N];

void PreMake() {
    rep (i, C[0][0] = 1, P - 1) rep (j, C[i][0] = 1, i)
        C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % P;
}

void Add(int x) {
    int res = 1, t = -1;
    ++B[0];
    dep (i, P - 1, 0)
        (B[i] += t * C[P - 1][i] * res % P) %= P, (res *= x) %= P, t *= -1;
}

int main() {
    P = read<int>();

    PreMake();

    rep (i, 0, P - 1) {
        int a = read<int>();
        if (a) Add(i);
    }

    rep (i, 0, P - 1) printf("%d%c", (B[i] % P + P) % P, " \n"[i == P - 1]);
    return 0;
}



Measured memory_bytes: 34176
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int x=0,n=s.size();
	for(int i=0;i<n;i++)s[i]-'o'?x++:0;
	cout<<(15-x>7?"YES":"NO")<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.IOException;

class Main{
	public static void main(String args[]){
		
		Scanner sc=new Scanner(System.in);
		
		String str=sc.next();
		
		
		if(str.charAt(2)==str.charAt(3) &&str.charAt(4)==str.charAt(5)){
				System.out.println("Yes");
		}else{
			    System.out.println("No");
		}
		
		
	}
}
	





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

using namespace std;
typedef long long ll;

bool f(vector<ll>::iterator a, vector<ll>::iterator ea, vector<ll>::iterator b, vector<ll> ::iterator eb){
    if(b == eb){
        return false;
    }else if(a == ea){
        return true;
    }else if(*a < *b){
        return true;
    }else if(*a > *b){
        return false;
    }else{
        return f(a+1, ea, b+1, eb);
    }
    return false;
}

int main(){
    ll n, t;
    vector<ll> a, b;
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++){
        scanf("%lld", &t);
        a.push_back(t);
    }
    scanf("%lld", &n);
    for(ll i = 0; i < n; i++){
        scanf("%lld", &t);
        b.push_back(t);
    }
    if(f(a.begin(), a.end(), b.begin(), b.end())){
        printf("1\n");
    }else{
        printf("0\n");
    }
    return 0;
}


Measured memory_bytes: 3212
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>

using namespace std;

int main ()
{
    int n;
    int m;
    map<int,int> p;
    int s,c;
    int ans = 0;
    
    p.clear();
    
    cin >> n;
    cin >> m;
    for (int i = 0;i < m;i++){
        cin >> s >> c;
        if (s == 1 && c == 0 && n >= 2){
            ans = -1;
            break;
        }
        else if (p.count(s) && p[s] != c){
            ans = -1;
            break;
        }
        else if (p.count(s) && p[s] == c){
            ;
        }
        else {
            int k = 1;
            p[s] = c;
            for (int i = 1;i <= n-s;i++){
                k *= 10;
            }
            ans += c*k;
        }
    }
    
    if (ans >= 0 && n >= 2 && p.count(1) == 0){
        if (n == 2){
            ans += 10;
        }
        if (n == 3){
            ans += 100;
        }
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 256
N=input()
L=len(N)

ans=0
u=0

for i in range(L-1,0,-1):
    s=int(N[i])+u
    if s < 5: 
        ans+=s
        u=0
    if s > 5:
        ans+=10-s
        u=1
    if s == 5:
        if int(N[i-1]) < 5:
            ans+=s
            u=0
        else:
            ans+=10-s
            u=1

        
s=int(N[0])+u
if s <= 5: 
    ans+=s
    u=0
if s > 5:
    ans+=10-s
    u=1

if u==1:
    ans+=1 

print(ans)



Measured memory_bytes: 5492
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
typedef long long ll;

using Weight = int;
using Flow = int;
struct Edge {
    int s, d; Weight w; Flow c;
    Edge() {};
    Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }

using Edges = vector<Edge>;
using Graph = vector<Edges>;

struct UnionFind {
    vector<int> parent;
    int size;
    UnionFind(int n) :parent(n, -1), size(n) {}
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y)return false;
        if (sizeOf(x) < sizeOf(y))swap(x, y);
        parent[x] += parent[y]; parent[y] = x; size--;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
    int sizeOf(int x) { return -parent[root(x)]; }
};

ll kruskal(const Graph &g) {
    int n = g.size();
    ll ans = 0;
    UnionFind uf(n);
    Edges es;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < g[i].size(); j++) {
            Edge e = g[i][j];
            es.push_back(e);
        }
    sort(es.begin(), es.end());
    for (int i = 0; i < es.size(); i++) {
        Edge e = es[i];
        if (!uf.same(e.s, e.d)) {
            ans += e.w;
            uf.unite(e.s, e.d);
        }
    }
    return ans;
}

ll N,a,b;
int main(){
    cin >> N;
    Graph g(N);
    vector<pair<ll,ll> > x,y;
    REP(i,N){
        cin >> a >> b;
        x.push_back(make_pair(a,i));
        y.push_back(make_pair(b,i));
    }
    // x[i] < x[i+1] < x[i+2] の場合、　i~i+2のコストは(i~i+1)+(i+1~i+2)より小さくならない
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    // make edges
    REP(i,N-1){
        g[x[i].second].emplace_back(x[i].second,x[i+1].second,abs(x[i+1].first-x[i].first));
        g[x[i+1].second].emplace_back(x[i+1].second,x[i].second,abs(x[i+1].first-x[i].first));
    }

    REP(i,N-1){
        g[y[i].second].emplace_back(y[i].second,y[i+1].second,abs(y[i+1].first-y[i].first));
        g[y[i+1].second].emplace_back(y[i+1].second,y[i].second,abs(y[i+1].first-y[i].first));
    }

    cout << kruskal(g) << endl;
}

Measured memory_bytes: 25440