akhauriyash/Code-Regression huggingface dataset:
n = int(input())
X = list(map(int, input().split()))
dist = float("inf")
d = 0
xmin = min(X)
xmax = max(X)
for i in range(xmin, xmax + 1):
	d = 0
	for x in X:
		d += (x - i) ** 2
	if d < dist:
		dist = d
print(dist)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ull unsigned long long
#define ll long long
#define ld long double
#define PSET(x,y) fixed<<setprecision(y)<<x
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define lop(i,a,b) for(ll i=a;i<b;i++)
#define lopr(i,a,b) for(ll i=a;i>=b;i--)
#define all(v) (v).begin(),(v).end()
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define ff first
#define ss second
#define pi pair<int,int>
#define pll pair<ll, ll>
#define ti tuple<int,int>
#define tll tuple<ll, ll>
#define si set<int>
#define sll set<ll>
#define maxheap priority_queue<ll>
#define minheap priority_queue<ll,vector<ll>,greater<ll>>
#define state tuple<int,int,int>
#define graph map<ll,list<ll>>

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const ld PI = asin(1) * 2;
inline int sbt(int x){return __builtin_popcount(x);} //returns number of set bits

using namespace std;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1<<" | ";
        __f(comma+1, args...);
    }
#else
#define deb(...)
#endif

const ll SIZE = 0;

int main(){
    // clock_t tStart = clock();    
    FastIO
    
    int a,b,c;
    cin>>a>>b>>c;

    if( a<b && c>a && c<b)
    	cout<<"Yes";
    else if( b<a && c>b && c<a)
    	cout<<"Yes";
    else
    	cout<<"No";

    // printf("Time taken: %.6fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define COUT cout<<fixed<<setprecision(12)
#define fast ios:: sync_with_stdio(false),cin.tie(0);
ll M=1000000007;
void solve()
{
	ll n;
	cin>>n;
	ll a[n+1];
	for(ll i=0;i<n;i++)
	cin>>a[i];
	//ll s[n+1];
	//s[n-1]=a[n-1];
	
	ll sum=0;
	
/*	for(ll i=n-2;i>=0;i--)
	{
	    s[i]=s[i+1]+a[i];
	}*/
	ll s=a[n-1];
	for(ll i=n-2;i>=0;i--)
	{
	    sum=((sum%M)+(s*a[i])%M)%M;
	    s=(s%M+a[i] %M)%M;
	}
	cout<<sum;
}

int main()
{
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 5184
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        long X = sc.nextLong();
        long Y = sc.nextLong();

        if (Math.abs(X - Y) <= 1) {
            _out.println("Brown");
        } else {
            _out.println("Alice");
        }
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 21972
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1147&lang=jp

#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>

#include<numeric>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int main() {
	
	int N;

	while(cin >> N && N)
	{
		vector<int> score(N,0);
		rep(i, N){
			cin >> score[i];
		}

		int max_s = *max_element(ALL(score));
		int min_s = *min_element(ALL(score));

		//dump(max_s); dump(min_s);

		rep(i,N){if(score[i]==max_s){score.erase(score.begin()+i);break;}}
		rep(i,N){if(score[i]==min_s){score.erase(score.begin()+i);break;}}
	
		//DUMP(score);

		int ave = accumulate(ALL(score),0) / score.size();
		
		cout << ave << endl;
	}

	return 0;
}

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

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

#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define all(a) (a).begin(),(a),end()
#define pll pair<lli,lli>

int main(){
  lli H,W;

  while(1){
    cin>>H>>W;
    if(H==0 and W==0)break;

    rep(i,H){
      rep(j,W){
	cout<<"#";
      }
      cout<<endl;
    }
    cout<<endl;
  }
  
  return 0;
}

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

int main() {
  int n, maxl = 0;;
  string s;
  cin >> n >> s;
  for (int d = n - 1; d > 0; d--) {
    int l = 0;
    for (int i = 0; i < n - d; i++) {
      if (s.at(i) == s.at(i + d)) {
        l++;
        if (l >= d) {
          if (l > maxl) maxl = l;
          break;
        }
      } else {
        if (l > maxl) maxl = l;
        l = 0;
      }
      if (l > maxl) maxl = l;
    }
  }
  cout << maxl << endl;
}


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

int sum(int n){
    if (n==1){
        return 1;
    }else{
        return n + sum(n-1);
    }
}

int main(){
    int a;
    cin >> a;
    cout << sum(a);
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

vector<pair<int,LL>> uf;

int root(int x){
  if(x==uf[x].first) return x;
  return uf[x].first=root(uf[x].first);
}

void uni(int x,int y){
  x=root(x);
  y=root(y);
  if(x==y) return;
  uf[x].first=y;
  uf[y].second+=uf[x].second;
}

int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<pair<int,LL>>> e(n);
  uf=vector<pair<int,LL>>(n);
  for(int i=0;i<n;i++){
    uf[i].first=i;
    cin >> uf[i].second;
  }
  vector<pair<LL,pair<int,int>>> ve(m);
  vector<LL> tw(m);
  int a,b,y;
  for(int i=0;i<m;i++){
    cin >> a >> b >> y;
    a--,b--;
    e[a].push_back({b,y});
    e[b].push_back({a,y});
    ve[i]={y,{a,b}};
  }
  sort(all(ve));
  for(int i=0;i<m;i++){
    int x=root(ve[i].second.first);
    int y=root(ve[i].second.second);
    if(x==y) tw[i]=uf[x].second;
    else tw[i]=uf[x].second+uf[y].second;
    uni(x,y);
  }
  vector<int> c(n,-1);
  int ans=0;
  queue<int> bfs;
  int now;
  for(int i=m-1;i>=0;i--){
    if(c[ve[i].second.first]!=-1&&c[ve[i].second.first]==c[ve[i].second.second]) continue;
    if(tw[i]>=ve[i].first){
      c[ve[i].second.first]=c[ve[i].second.second]=i;
      bfs.push(ve[i].second.first);
      bfs.push(ve[i].second.second);
      while(!bfs.empty()){
        now=bfs.front();
        bfs.pop();
        for(auto &p:e[now]){
          if(c[p.first]==-1&&p.second<=ve[i].first){
            c[p.first]=i;
            bfs.push(p.first);
          }
        }
      }
    }else{
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12160
#include <iostream>
#include <iterator>
#include <vector>

#define MAX_M 100

using namespace std;

int N, M;
int A[MAX_M];

vector<int> solve()
{
    vector<int> B;

    vector<int> O; // 奇数のインデックス
    for ( int i = 0; i < M; i++ )
        if ( A[i] % 2 ) O.push_back( i );

    switch ( O.size() )
    {
    case 2:
        swap( A[O[1]], A[M - 1] );
    case 1:
        swap( A[O[0]], A[0] );
        break;
    case 0:
        break;
    default:
        return B;
    }

    if ( A[0] > 1 ) B.push_back( A[0] - 1 );

    for ( int i = 1; i < M - 1; i++ ) B.push_back( A[i] );

    B.push_back( M == 1 ? 1 : A[M - 1] + 1 );

    return B;
}

int main( int argc, char **argv )
{
    cin >> N >> M;

    for ( int i = 0; i < M; i++ ) cin >> A[i];

    auto B = solve();

    if ( B.size() == 0 )
        cout << "Impossible" << endl;
    else
    {
        copy( A, A + M, ostream_iterator<int>( cout, " " ) );
        cout << endl;

        cout << B.size() << endl;

        copy( B.begin(), B.end(), ostream_iterator<int>( cout, " " ) );
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
def rank_a(m,e,j):
    if m == 100 or e == 100 or j==100:return True
    if (float(m) + e) /2 >= 90:return True
    if (float(m) + e + j) / 3 >= 80: return True

    return False

def rank_b(m,e,j):
    if (float(m) + e + j) / 3 >= 70: return True
    if (float(m) + e + j) / 3 >= 50 and \
        (m >= 80 or e >= 80):
            return True
while True:
    n = int(input())
    if n == 0: break
    for i in range(n):
        pm,pe,pj = list(map(int,input().split()))
        if rank_a(pm,pe,pj):
            print("A")
        elif rank_b(pm,pe,pj):
            print("B")
        else:
            print("C")

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

int main() {
  int N;
  cin >> N;
  vector <int> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int score = N;
  for(int i = 0; i < N-1; i++){
    if(vec.at(i) == vec.at(i+1)){
      score--;
    }
    else{
    }
  }
  cout << score;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int result[6];
	float height;
	int i, j, n;

	for (i = 0; i < 6; i++) {
		result[i] = 0;
	}

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf(" %f", &height);

		if (height < 165.0) {
			result[0]++;
		} else if (height < 170.0) {
			result[1]++;
		} else if (height < 175.0) {
			result[2]++;
		} else if (height < 180.0) {
			result[3]++;
		} else if (height < 185.0) {
			result[4]++;
		} else {
			result[5]++;
		}
	}

	for (i = 1; i <= 6; i++) {
		printf("%d:", i);
		for (j = 0; j < result[i - 1]; j++) {
			printf("*");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 636
N, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
count = 0

for i in range(len(a)):
    tmp = a[i]

    if x >= tmp and i != len(a) - 1:
        count += 1
        x -= tmp
    else:
        if tmp == x:
            count += 1
        break

print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n;
char op[10];
int k,k1,k2,k3;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>op;
		if(*op=='A') k++;
		else if(*op=='T') k1++;
		else if(*op=='W') k2++;
		else if(*op=='R') k3++;
	}
	printf("AC x %d\n",k);
	printf("WA x %d\n",k2);
	printf("TLE x %d\n",k1);
	printf("RE x %d\n",k3);
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


/*
aababab
頭から順に見ていく
一致すれば
*/


void solve(){
    string s;
    cin >> s;
    int siz = s.size();
    int pointer = 0; //pointerは次の文字の先頭を指す. siz-1までの値をとる
    int count=0;
    string tmp=""; //前の文字列が代入される

    while(pointer<siz){
        char c = s[pointer];
        string ch{c};
        //cout << "ch:" << ch << " tmp:" << tmp << endl;
        if(tmp.size()==2) {
            pointer++;
            count++;
            tmp = ch;
            //cout << "前に2つに分割したので、次は必ず1文字" << endl;
            //cout << 1 << endl;
        }
        else if(tmp==ch){
            pointer += 2;
            count++;
            tmp = ch + s[pointer-1];
            //cout << "前の部分文字列が1文字で、かつ次の文字列と被っているので、次の文字列は2文字" << endl;
            //cout << 2 << endl;
        }
        else{
            pointer++;
            count++;
            tmp = ch;
            //cout << "前の部分文字列が1文字だが、次の文字とは異なるので、次の文字列は1文字" << endl;
            //cout << 3 << endl;
         }
         //cout << pointer << endl;
    }

    if(pointer>siz) cout << count-1 << endl;
    else cout << count << endl;
}

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


Measured memory_bytes: 720
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
using ll = long long int;
//typedef pair<int,int> P;

int main(void){
	int X,N;
	cin >> X>>N;
	if(N==0){
		cout <<X;
		return 0;
	}
	vector<int> p;
	int i;
	for(int a=0;a<N;a++){
		cin >> i;
		p.push_back(i);
	}
	sort(p.begin(),p.end());
	int num=0;
	for(int i=0;i<p.size();i++){
		if(X==p[i]){
			num=i;
			break;
		}
		if(X<p[i]){
			cout << X;
			return 0;
		}
		if(i==p.size()){
			cout << X;
			return 0;
		}
	}
		int min=num-1;int max=num+1;
		int k=1;
		while(1){
			if(min<0){
				cout << p[0]-1;
				return 0;
			}
			if(p[min]!=X-k){
				cout <<X-k;
				return 0;
			}
			min--;
			if(max>p.size()){
				cout << p[N-1]+1;
				return 0;
			}
			if(p[max]!=X+k){
				cout <<X+k;
				return 0;
			}
			max++;
			k++;
		}

	return 0;
}


Measured memory_bytes: 3628
/*
 * b.cc: 
 */

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

using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

/* global variables */

int as[MAX_N];

/* subroutines */

int partition(int A[], int p, int r) {
  int x = A[r];
  int i = p-1;
  for (int j = p; j < r; j++)
    if (A[j] <= x) {
      i++;
      swap(A[i], A[j]);
    }
  i++;
  swap(A[i], A[r]);
  return i;
}

/* main */

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

  int k = partition(as, 0, n - 1);

  for (int i = 0; i < n; i++) {
    if (i) putchar(' ');
    if (i == k) printf("[%d]", as[i]);
    else printf("%d", as[i]);
  }
  putchar('\n');

  return 0;
}

Measured memory_bytes: 1532
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <limits>
#include <ctype.h> 
#include <stdio.h> 
#include <set> 
#include <iomanip>
#include <vector>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '


int main() {
    int h = 0, a = 0;
    cin >> h >> a;
    cout << (a+h-1)/a << endl;    
    

    return 0;
} 


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static String s = null;
    
    public static void main(String[] args) throws Exception {
        s = sc.next();
        String ans = (s.matches(".*C.*F.*")) ? "Yes" : "No";
        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>

using namespace std;

#define ll long long int
#define pll pair<double,ll>

vector<vector<ll>> dp;

int main()
{
    int k, s;
    cin >> k >> s;
    
    ll sum = 0;
    for(int x = 0;x <= k; x++)
    {
        ll c = x;
        for(int y = 0;y <= k;y++)
        {
            ll d = y;
            ll r = s - c - d;
            if(r >= 0 && r <= k)
            {
                sum++;
            }
        }
    }
    cout << sum << endl;
    return 0;
}

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

using namespace std;

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


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define sz(X) (int)(X).size()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define fornr(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define forab(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(X) X.begin(), X.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef double dbl;
typedef long double ld;
typedef vector<int> vi;
typedef vector<pair<ll, ll>> vpll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n, d;
    cin >> n >> d;
    int cnt = 0;
    while (n--) {
        ll x, y;
        cin >> x >> y;
        if (x * x + y * y <= d * d) cnt++;
    }
    cout << cnt << "\n";
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;

int main(){
    ll N;cin>>N;
    ll x[100010],l[100010],h=-9999999999,cn=0;
    vector<pair<ll,ll> > arm(N);
    rep(i,0,N){
        cin>>x[i]>>l[i];
        arm.at(i)=make_pair(x[i]+l[i],x[i]-l[i]);
    }
    sort(arm.begin(),arm.end());
    rep(i,0,N){
        if(h<=arm.at(i).second)h=arm.at(i).first;
        else cn++;
    }
    cout<<N-cn<<endl;
}







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

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  public static void main(String[] args) {
    FastReader sc = new FastReader();
	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();
	int d = sc.nextInt();
	System.out.println(Math.max(Math.min(b, d) - Math.max(a, c), 0));
	
  }
  
  static class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }
  
    String next() { 
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException  e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() { 
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
        try{
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
      }
  }
}


Measured memory_bytes: 23252
#include<iostream>
using namespace std;
int main()
{

  int a,b,c;
  cin >> a >> b >> c;

  if( b/a == c ){
    cout << c << endl;
  }else if( b/a >= c ){
    cout << c << endl;
  }else{
    cout << b/a << endl;
  }

  return(0);

}


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

class Program {
    static void Main() {
        var n = NextInt();
        var s = new long[n + 1];

        foreach (var i in Enumerable.Range(0, n)) {
            var a = NextInt();
            s[i + 1] = s[i] + a;
        }
        Array.Sort(s);
        var ans = 0L;
        var cnt = 0;
        foreach (var i in Enumerable.Range(0, s.Length - 1)) {
            if (s[i] == s[i + 1]) {
                cnt++;
            } else {
                cnt = 0;
            }
            ans += cnt;
        }
        WriteLine(ans);
    }

    static int NextInt() {
        return int.Parse(NextString());
    }

    static string NextString() {
        var result = new List<char>();
        while (true) {
            int next = Read();
            if (next < 0)
                break;
            var nextChar = (char)next;
            if (!char.IsWhiteSpace(nextChar))
                result.Add(nextChar);
            else if (nextChar != '\r')
                break;
        }
        return string.Join("", result);
    }
}

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

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

    string s;
    cin >> s;
    int n = s.size();
    string cnvd = "";
    for(int i = 0; i < n-1; ++i){
        if(s[i] == 'B' && s[i+1] == 'C'){
            cnvd += 'D';
            ++i;
        }
        else cnvd += s[i];
    }
    
    n = cnvd.size();
    int base = -1;
    long long res = 0;
    for(int i = 0; i < n; ++i){
        if(cnvd[i] == 'A' || cnvd[i] == 'D'){
            if(base == -1){
                base = i;
                if(cnvd[i]=='D') ++base;
            }
            else{
                if(cnvd[i]=='D'){
                    res += i-base;
                    ++base;
                }
            }
        }
        else{
            base = -1;
        }
    }

    cout << res << endl;
}

Measured memory_bytes: 3824
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	var n, k int
	var d string
	fmt.Scan(&n, &k)
	d = getInput()
	dislikes := strings.Split(d, " ")
	// fmt.Printf("n = %d, k = %d, d = %s, dislikes = %v\n", n, k, d, dislikes)

	var result int
	for i := n; i <= n*10; i++ {
		s := strconv.Itoa(i)
		isContain := false
		for _, dislike := range dislikes {
			if strings.Contains(s, dislike) {
				isContain = true
				break
			}
		}
		if !isContain {
			// fmt.Printf("not contain! i = %d\n", i)
			result = i
			break
		}
	}

	fmt.Println(result)
}


Measured memory_bytes: 1024
def gcd(x, y)
  x, y = y, x if x < y
  while true
    r = x % y
    break if r == 0
    x = y
    y = r
  end
  return y
end

def lcm(x, y)
  g = gcd(x, y)
  return x * y / g
end

a, b, c, d = gets.split.map(&:to_i)
n_b_c = b / c
n_a1_c = (a - 1) / c
n_b_d = b / d
n_a1_d = (a - 1) / d
n_b_cd = b / lcm(c, d)
n_a1_cd = (a - 1) / lcm(c, d)

puts (b - a + 1) - ((n_b_c - n_a1_c) + (n_b_d - n_a1_d) - (n_b_cd - n_a1_cd))


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

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  if (A+K-1<(A+B)/2) {
    for (int i=A; i<A+K; i++) cout << i << endl;
    for (int i=B-K+1; i<B+1; i++) cout << i << endl;
  }
  else {
    for (int i=A; i<B+1; i++) cout << i << endl;
  }
}

Measured memory_bytes: 256
s=input()
if s[0]==s[1]==s[2]==s[3]:
  print("No")
elif s[0]==s[1] and s[2]==s[3]:
  print("Yes")
elif s[0]==s[2] and s[1]==s[3]:
  print("Yes")
elif s[0]==s[3] and s[2]==s[1]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9064
#include <iostream>
using namespace std;
int main(void){
  int h, w;
  while (true) {
    cin >> h >> w;
    if (h==0 && w==0) {
      break;
    } else {
      for (int hh=0; hh<h; hh++) {
        for (int ww=0; ww<w; ww++) {
          cout << "#";
        }
        cout << endl;
      }
      cout << endl;
    }
  }
}



Measured memory_bytes: 3096
//#include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    string S,T;
    cin >> S >> T;

    cout << T+S << endl;

}

Measured memory_bytes: 760
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 100005
#define TRACE(x) cout<<#x<<" = "<<x<<'\n'
#define TRACE2(x, y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<'\n'
#define TRACEA(arr, i) cout<<#arr<<"["<<i<<"]"<<" = "<<arr[i]<<'\n'
#define PRINT(arr, n) for (int iDx = 0; iDx < n; iDx++) printf("%d%c", arr[iDx], " \n"[iDx == n-1])
#define SZ(x) (int)(x).size()
using namespace std;
struct ii {
	int a, b;
	bool operator < (ii o) const { return tie(a, b) < tie(o.a, o.b); }
};
struct iii {
	long long a, b, c;
	bool operator < (iii o) const { return tie(a, b, c) < tie(o.a, o.b, o.c); }
};
int TC, N, M, K, Q, x, y, z;

map<iii, bool> sudah;
long long a[5];

int main() {
	#ifdef FAIRUZI10
	freopen("/home/fairuzi/Documents/CP/input.in", "r", stdin);
	#endif
	
	scanf("%lld%lld%lld", &a[0], &a[1], &a[2]);
	if (a[0]&1 || a[1]&1 || a[2]&1) {
		puts("0");
		return 0;
	}
	int cnt = 0;
	while (1) {
		cnt++;
		long long x = a[0], y = a[1], z = a[2];
		a[0] = (y+z)>>1;
		a[1] = (x+z)>>1;
		a[2] = (x+y)>>1;
		sort(a, a+3);
		if (sudah[{a[0], a[1], a[2]}]) {
			puts("-1");
			return 0;
		}
		sudah[{a[0], a[1], a[2]}] = 1;
		if (a[0]&1 || a[1]&1 || a[2]&1) {
			printf("%d\n", cnt);
			return 0;
		}
	}
	
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>

#define LL  long long
using namespace std;
const int MAXN = 2e5+10;

LL T[MAXN];
int mod[2019];
LL ans = 0;

inline LL count(int n) {
    return 1LL*n*(n-1)/2;
}
int main() {
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int n = S.length();

    T[n] = 0;
    int pre = 1;
    mod[0] = 1;
    for(int i=n-1; i>=0; i--) {
    	pre *= 10;
        T[i] = T[i+1]+pre*(S[i]-'0');
        T[i] %= 2019;
        mod[T[i]]++;
        pre %= 2019;
    } 

    ans  = 0;
    for(int i=0; i<2019; i++) {
    	if(mod[i])
        	ans += count(mod[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5240
#include<bits/stdc++.h>
	using namespace std;
	typedef long long ll;
	typedef double d;
	#define for(i,a,b) for(int i=a;i<b;i++)
	#define f(i,a,b) for(int i=a;i<=b;i++)
    int main()
    {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int x;
    cin>>x;
    if (x>=30) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	}

Measured memory_bytes: 3644
import java.io.*;
import java.util.*;

class Main {
	static final int M = 1000000007;

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		int a = sc.nextInt();
		int b = sc.nextInt();
		long answer = pow(2, n, M) - 1;
		answer = ((answer - f(n, a)) % M + M) % M;
		answer = ((answer - f(n, b)) % M + M) % M;
		System.out.println(answer);
	}

	private static long f(long n, int a) {
		long[] x = new long[a];
		long[] y = new long[a];
		x[0] = n;
		y[0] = a;

		for (int i = 1; i < a; i++) {
			x[i] = (x[i - 1] * (n - i)) % M;
			y[i] = (y[i - 1] * (a - i)) % M;
		}

		return (x[a - 1] * pow(y[a - 1], M - 2, M)) % M;
	}

	private static long pow(long x, long n, long M) {
		long a = 1;
		while (n > 0) {
			if ((n & 1) == 1) a = (a * x) % M;
			x = (x * x) % M;
			n >>= 1;
		}
		return a;
	}
}


Measured memory_bytes: 27220
from bisect import bisect
import numpy as np

N, M, K = map(int, input().split(' '))
A = np.array([0, *map(int, input().split(' '))])
B = np.array([0, *map(int, input().split(' '))])

A = A.cumsum()
B = B.cumsum()

ans = 0
for i in range(N + 1):
    k = A[i]
    if k > K:
        break

    j = bisect(B, K - k)
    ans = max(ans, i + j - 1)

print(ans)


Measured memory_bytes: 53632
using System;
using System.Linq;
namespace Sample
{
	class Program
    {
    	        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var array = input.Select(int.Parse).ToArray();
            int num = array[0] * 100 + array[1] * 10 + array[2] * 1;
            if (num % 4 == 0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}

Measured memory_bytes: 13268
# coding: utf-8
# Your code here!
n=int(input())

xy=[]

for i in range(n):
    xy.append(list(map(int,input().split())))

d=0

for i in range(n):
    for j in range(i+1,n):
        d+=((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)**(1/2)

print(d*2/n)

Measured memory_bytes: 3188
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr> () -> T {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let N = read::<usize>();
    let mut vec = Vec::new();
    for i in 0..N{
        vec.push(read::<i64>());
    }
    let cpy = vec.clone();
    //for i in 0..N {
    //    let max1 = match &vec[0..i].iter().max() {
    //        &Some(&x) => x,
    //        &None => -1,
    //    };
    //    let max2 = match &vec[(i+1)..N].iter().max() {
    //        &Some(&x) => x,
    //        &None => -1
    //    };
    //    println!("{}", std::cmp::max(max1, max2));
    //}
    //
    vec.sort_by_key(|c| -c);
    let max = vec[0];
    let second = vec[1];
    for i in 0..N {
        if max == cpy[i] {
            println!("{}", second);
        }
        else {
            println!("{}", max);
        }
    }
}



Measured memory_bytes: 9724
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(j,n) for(int j = 0; j < (n); ++j)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define drep2(j,n) for(int j = (n)-1; j >= 0; --j)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define srep2(j,s,t) for (int j = s; j < t; ++j)
#define srep3(k,s,t) for (int k = s; k < t; ++k)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  int d = 0;
  int n = N;
  while(n > 0) {
    d += n % 10;
    n = n / 10;
  }
  if(N % d == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void)
{
 int x,y,R,temp_x,temp_y;
 while(scanf("%d %d",&x,&y)!=EOF)
 {
  temp_x = x;
  temp_y = y;
  while(x % y != 0)
  {
   R = x % y;
   x = y;
   y = R;
  }
  printf("%d %d\n",y,temp_x*(temp_y/y));
 }
 return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

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

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main() {
    string s;
    cin >> s;
    int n = s.length();
    int half = (n - 1) / 2 + 1;

    bool can = true;
    rep(i, half) {
        if(s[i] != s[n-i-1]) can = false;
    }
    string t = s.substr(0, half - 1);
    rep(i, t.length()/2+1) {
        if(t[i] != t[t.length()-i-1]) can = false;
    }
    string r = s.substr(half);
    rep(i, s.length()/2+1) {
        if(r[i] != r[r.length()-i-1]) can = false;
    }

    Yn(can);

    return 0;
}


Measured memory_bytes: 256
def inv(a):
    m=10**9+7
    b=m
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return lastx % m


def main():
    MOD=10**9+7
    n,k=map(int,input().split())
    a=list(map(int,input().split()))

    frac=[1]
    for i in range(1,n+1):
        frac.append(frac[-1]*i%MOD)
    
    fracinv=[inv(frac[i]) for i in range(n+1)]


    dp=[[0]*(n+1) for _ in range(k)]

    for x in range(a[0]+1):
        dp[0][x]=frac[n]*frac[n-x]*fracinv[a[0]-x]%MOD*fracinv[n-a[0]]*fracinv[x]%MOD

    for i in range(k-1):
        ai=a[i+1]
        for j in range(n+1):
            for x in range(ai+1):
                p=j+x
                if p>n: break
                tmp=dp[i][j]*frac[n-x]%MOD*fracinv[ai-x]%MOD*fracinv[n-ai]%MOD*fracinv[x]%MOD
                dp[i+1][p]=(dp[i+1][p]+tmp)%MOD
    print(dp[k-1][n]%MOD)

if __name__ == "__main__":
    main()

Measured memory_bytes: 63324
n, q = gets.chomp.split.map(&:to_i)
s = gets.chomp.split("")
ac = Array.new(n, 0)
ac[0] = cnt = 0
for i in 1..(n-1)
  if s[(i-1)..i].join == "AC"
    cnt += 1
    ac[i] = cnt
  else
    ac[i] = cnt
  end
end
for i in 1..q
  l, r = gets.chomp.split.map(&:to_i)
  puts ac[r-1] - ac[l-1]
end

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

int main()
{
  int N, K;
  cin >> N >> K;
  int num = 1;
  for (int i = 0; i < N; ++i)
  {
    if (K < num)
      num += K;
    else
      num <<= 1;
  }
  cout << num;
  return 0;
}


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

if abs(n-m) > 1:
    print("0")
elif abs(n-m) == 1:
    ans = math.factorial(n) * math.factorial(m)
    print(ans%(10**9+7))
else:
    ans = math.factorial(n) * math.factorial(m) * 2
    print(ans%(10**9+7))


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

const int MAXD = 1e5, MAXK = 105, MOD = 1e9 + 7;
vector<int> d;
void addb(int a) {
	int m = a;
	d.push_back(1);
	while (m && m != 1) {
		int t = a / m, nxm = a / (t + 1);
		d.push_back(nxm + 1);
		d.push_back(t);
		m = nxm;
	}
	sort(d.begin(), d.end());
	d.resize(unique(d.begin(), d.end()) - d.begin());
	d.push_back(a + 1);
}
long long dp[MAXD], dpo[MAXD];
int n, k;

int main() {
	cin >> n >> k;
	addb(n);
	dpo[0] = d[1] - d[0];
	for (int i = 1; i < d.size() - 1; i++)
		dpo[i] = d[i + 1] - d[i] + dpo[i - 1];
	for (int i = 1; i < k; i++) {
		for (int j = 0; j < d.size() - 1; j++) {
			int ind = upper_bound(d.begin(), d.end(), n / d[j]) - d.begin();
			dp[j] = dpo[ind - 1] * (d[j + 1] - d[j]) % MOD;
		}
		swap(dp, dpo);
		for (int i = 1; i < d.size() - 1; i++)
			dpo[i] += dpo[i - 1], dpo[i] %= MOD;
	}
	cout << dpo[d.size() - 2];
}

Measured memory_bytes: 2424
#include <iostream>
#include <algorithm>
#include <iterator>

#include <vector>
#include <queue>
#include <unordered_map>

using namespace std;

int main(){
    int A, B;
    cin >> A >> B;
    int answer;

    if ((B-1)%(A-1)==0){
        answer = (B-1)/(A-1);
    }else{
        answer = (B-1)/(A-1)+1;
    }

    cout << answer <<endl;
    return 0;
}


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

#define int long long int
#define mp make_pair
using namespace std;

int32_t main() {
    string s;
    cin >> s;
    if(s.length() == 2){
        cout << s;
    }
    else{
        reverse(s.begin(), s.end());
        cout << s;
    }
    return 0;
}

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

int main()
{
	int h,w;
	cin>>h>>w;
	
	int m;
	cin>>m;
	
	vector<int> arr[h];
	int cnt[w]={0};
	
	int a,b;
	
	for(int i=0;i<m;i++)
	{
		cin>>a>>b;
		a--,b--;
		
		arr[a].push_back(b);
		cnt[b]++;
	}
	
	multiset<int> ms;
	for(int i=0;i<w;i++)
	{
		ms.insert(cnt[i]);
	}
	
	int ans=0;
	
	for(int i=0;i<h;i++)
	{
		vector<int> vals;
		int sz=arr[i].size();
		
		for(auto j:arr[i])
		{
			ms.erase(ms.find(cnt[j]));
			
			ans=max(ans,cnt[j]+sz-1);
			
			vals.push_back(j);
		}
		
		if(ms.size())
			ans=max(ans,sz+*(ms.rbegin()));
		
		for(auto j:vals)
			ms.insert(cnt[j]);
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 35228
#include <iostream>
using namespace std;
int main()
{
        int n;
        cin >> n;

        int a[2][n];

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

        int max=0,candy;

        for(int i=0;i<n;i++){
                int j;
                candy=0;
                for(j=0;j<i || j==0;j++) candy+=a[0][j];
                if(j!=0) j--;
                for(;j<n;j++) candy+=a[1][j];

                if(candy>max) max=candy;
        }

        cout << max << endl;

        return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
const int maxn=100100;
int a[maxn];
int cnt[maxn];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		cnt[a[i]]++;
	}
	int sum,ans=0;
	for(int i=0;i<=100000;i++){
		sum=cnt[i];
		if(i>0) sum+=cnt[i-1];
		if(i<100000) sum+=cnt[i+1];
		if(sum>ans) ans=sum;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 896
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n, m = intin()
    ablist = intinl(m)

    ablist.sort()
    candidates = []

    for a, b in ablist:
        if not candidates:
            candidates.append((a, b - 1))
            continue
        ca, cb = candidates[-1]
        if a <= cb:
            candidates[-1] = (max(a, ca), min(b - 1, cb))
            continue
        candidates.append((a, b - 1))

    print(len(candidates))


if __name__ == '__main__':
    main()


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

using namespace std;

const int MAXN = 100000 + 10;
const int INF = (int)(1e9);

int n;
long long a[MAXN], b[MAXN];

void run() {
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i] >> b[i];
    long long res = 0, s = 0;
    for(int i = n; i >= 1; i--) {
        a[i] += s;
        long long x = (a[i] % b[i] == 0) ? 0 : (b[i] - (a[i] % b[i]));
        res += x; s += x;
    }
    cout << res << endl;
}

int main()
{
    int ntests = 1;
    //cin >> ntests;
    for(int tc = 1; tc <= ntests; ++tc) {
        run();
    }
}


Measured memory_bytes: 1920
//
//  main.cpp
//  AOJ
//
//  Created by user on 2014/06/01.
//  Copyright (c) 2014年 user. All rights reserved.
//

#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <cstring>
using namespace std;

const int SIZE = 3628810;
typedef pair< vector<int>, int > Pack;

int getPermId(const vector<int>& v){
    const int N = (int)v.size();
    
    int fact = 1;
    int res = 0;
    
    for(int i=N-1;i>=0;i--){
        for(int j=i+1;j<N;j++){
            if(v[j] < v[i]){
                res += fact;
            }
        }
        fact *= (N - i);
    }
    
    return res;
}

int dist[2][SIZE];
vector<Pack> Queue[2];

int bfs(const vector<int>& start, const vector<int>& goal){
    memset(dist, -1, sizeof(dist));
    
    const int N = (int)start.size();
    const int startId = getPermId(start);
    const int goalId  = getPermId(goal);
    
    if(startId == goalId){
        return 0;
    }
    
    int curr = 0, next = 1;
    
    dist[curr][startId] = 0;
    dist[next][goalId]  = 0;
    
    Queue[curr].push_back(make_pair(start, startId));
    Queue[next].push_back(make_pair(goal,  goalId));
    
    for(;;){
        vector<Pack> nextQueue;
        for(int i=0;i<Queue[curr].size();i++){
            Pack &pack = Queue[curr][i];
            
            vector<int> &perm = pack.first;
            int permId = pack.second;
            int nowCost = dist[curr][permId];
            
            for(int s=0;s<N;s++)for(int t=s+1;t<N;t++){
                reverse(perm.begin() + s, perm.begin() + t + 1);
            
                int nextPermId = getPermId(perm);
                if(dist[curr][nextPermId] == -1){
                    dist[curr][nextPermId] = nowCost + 1;
                
                    if(dist[next][nextPermId] != -1){
                        return dist[curr][nextPermId] + dist[next][nextPermId];
                    } else {
                        nextQueue.push_back(make_pair(perm, nextPermId));
                    }
                }
                
                reverse(perm.begin() + s, perm.begin() + t + 1);
            }
        }
        Queue[curr].swap(nextQueue);
        
        swap(curr, next);
    }
    
    return 1;
}

int main(){
    int N;
    cin >> N;
    
    vector<int> start(N);
    for(int i=0;i<N;i++){
        cin >> start[i];
        --start[i];
    }
    
    vector<int> goal = start;
    sort(goal.begin(), goal.end());
    
    int res = bfs(start, goal);
    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 77984
#include <stdio.h>

int weight(int w)
{
     int x = 1;
     
     while(w>0){
	  x = x * 2;
	  w--;
     }

     return x;
}

int potate(int n, int w, int space)
{
     if(space!=0) printf(" ");

     if(n<2){
	  printf("%d", weight(w));
     }
     else{
	  if(n%2==0){
	       potate(n/2, w+1, 0);
	  }
	  else if(n%2==1){
	       printf("%d", weight(w));
	       potate(n/2, w+1, 1);
	  }
     }
}

int main(void)
{
     int n, w=0;
     
     while(0<1){
	  if(scanf("%d", &n)==-1) break;
	  
	  potate(n, w, 0);
	  printf("\n");
     }

     return 0;
}

Measured memory_bytes: 596
N,*A = $<.read.split.map &:to_i
H = Hash.new(0)
A.each {|i| H[i]+=1}
t = 0
H.each {|k,v|
  t += v*(v-1)/2
  H[k] = v-1
}
puts A.map {|i| t-H[i]}

Measured memory_bytes: 31868
def main():
    H, W, K = map(int, input().split())
    Field = []

    sharpNum = 0

    for i in range(H):
        rowString = input()

        colSharpNum = rowString.count("#")
        sharpNum = sharpNum + colSharpNum
        wField = []

        for j in range(W):
            wField.append(rowString[j])
                    
        Field.append(wField)
    
    answer = 0

    for maskR in range(1<<H):
        for maskC in range(1<<W):
            black = 0
            for i in range(H):
                for j in range(W):
                    if(((maskR >> i) & 1) == 0) and (((maskC >> j) & 1) == 0) and Field[i][j] == "#":
                        black = black + 1
            if black == K:
                answer = answer + 1

    print(answer)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9120
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s;

    cin >> n;
    cin >> s;

    int count1 = 0;
    for(int i=0; i<n; i++)
    {
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
        {
            count1++;
            //i = i + 3;
        }
    }

    cout << count1;

    return 0;
}







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

//snukeさんのコードをほぼ写した

int N;

vector<int> G[100010];

vector<int> dist;

void dfs(int v, int d=0, int p=-1) {
    dist[v] = d;
    for (int u : G[v]) {
        if (u == p) continue;
        dfs(u,d+1,v);
    }
}

vector<int> calcDist(int s) {
    dist.resize(N);
    dfs(s);
    return dist;
}



int main(){ 
    int u, v, ans = 0;
    cin >> N >> u >> v;
    u--;
    v--;

    rep(i,N-1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    vector<int> distU = calcDist(u);
    vector<int> distV = calcDist(v);
    
    rep(i,N) {
        if (distU[i] < distV[i]) {
            ans = max(ans, distV[i]);
        }
    }

    ans--;
    cout << ans << endl;
}

Measured memory_bytes: 10752