akhauriyash/Code-Regression huggingface dataset:
(defun cul-max-cnt (names)
  (let ((max-cnt 0)
        (cur-cnt 0)
        (last-name ""))
    (mapc (lambda (name)
            (if (string= name last-name)
                (incf cur-cnt)
                (progn
                  (setf last-name name)
                  (setf max-cnt (max max-cnt (setf cur-cnt 1)))))
            (setf max-cnt (max max-cnt cur-cnt)))
          names)
    max-cnt)) 

(defun collect-answer (names max-cnt)
  (let ((cur-cnt 0)
        (last-name "")
        (answers (list)))
    (mapc (lambda (name)
            (if (string= name last-name)
                (incf cur-cnt)
                (progn
                  (setf cur-cnt 1)
                  (setf last-name name)))
            (when (= max-cnt cur-cnt)
              (push name answers)))
          names)
    answers))

(let* ((n (read))
       (names  (sort (loop repeat n collect (read-line)) #'string<))
       (answers (sort (collect-answer names (cul-max-cnt names)) #'string<)))
  (loop for i in answers do
        (format t "~a~%" i)))


Measured memory_bytes: 69732
import math
s = [int(i) for i in input().split()]
N = s[0]
D = s[1]

def combinations(n, r):
    return math.factoriak(n)/(math.factorial(n-r)*math.factorial(r))

dot = []
dist = []

for i in range(N):
    dot.append([int(j) for j in input().split()])

for i in range(N-1):
    for j in range(i+1, N):
        tmp = []
        for k in range(D):
            c = (dot[i][k] - dot[j][k])**2
            tmp.append(c)
        if k == D-1:
            dist.append(sum(tmp))

answer = list(map(lambda x:pow(x, 1/2), dist))
count = 0
for i in range(len(answer)):
    if answer[i].is_integer() == True:
        count = count + 1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}

ll sum;
string s;
int a[4];
bool flag = false;

void func(int i, ll sum, string s){
  if(flag) ;
  else{
    if(i == 3){
      if(sum == 7){
        cout<<s+"=7"<<endl;
        flag = true;
      }
    }
    else{
      func(i+1,sum+a[i+1],s+'+'+to_string(a[i+1]));
      func(i+1,sum-a[i+1],s+'-'+to_string(a[i+1]));
    }
  }
}

int main(){
  int d,g;
  cin>>d>>g;
  int p[d],c[d];
  for(int i = 0; i < d; i++){
    cin>>p[i]>>c[i];
  }
  int ans = 1e9;
  for(int i = 0; i < (1<<d); i++){
    int s = 0;
    int num = 0; 
    int rest_max = -1;
    for(int j = 0; j < d; j++){
      if((i>>j)&1){
        s += 100*(j+1)*p[j]+c[j];
        num+=p[j];
      }
      else{
        rest_max = j;
      }
      }
      if(s<g){
        int s1 = 100*(rest_max+1);
        int need = (g-s+s1-1)/s1;
        if(need >= p[rest_max]){
          continue;
        }
        num+=need;
    }
    ans=min(ans,num);
  }
  cout<<ans<<endl;               
  return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	string s;
	cin >> s;
	if (s[0]!=s[s.size()-1])cout <<(s.size()%2==0 ? "Second":"First") << endl;
	else cout << (s.size()%2==0 ? "First":"Second") << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <cstring>
#include <unordered_set>
#include <unordered_map>

using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
static const ll INF = 1000010000;
static const ll MOD = 1000000007;
 
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation

//int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

#define all(c) (c).begin(), (c).end()

struct graph {
  int L, R;
  vector<vector<int>> adj;
  graph(int L, int R) : L(L), R(R), adj(L+R) { }
  void add_edge(int u, int v) {
    adj[u].push_back(v+L);
    adj[v+L].push_back(u);
  }
  int maximum_matching() {
    vector<int> visited(L), mate(L+R, -1);
    function<bool(int)> augment = [&](int u) { // DFS
      if (visited[u]) return false;
      visited[u] = true;
      for (int w: adj[u]) {
        int v = mate[w];
        if (v < 0 || augment(v)) {
          mate[u] = w;
          mate[w] = u;
          return true;
        }
      }
      return false;
    };
    int match = 0;
    for (int u = 0; u < L; ++u) {
      fill(all(visited), 0);
      if (augment(u)) ++match;
    }
    return match;
  }
};

int main(){
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n), d(n);
	REP(i, n) cin >> a[i] >> b[i];
	REP(i, n) cin >> c[i] >> d[i];
	graph g(n, n);
	REP(i, n) REP(j, n){
		if(a[i] < c[j] && b[i] < d[j]) g.add_edge(i, j);
	}
	cout << g.maximum_matching() << endl;
}

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


//defines...
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define in insert
#define pi 2*acos(0.0)1
#define srt(s) sort(s.begin(),s.end())
#define all(x) x.begin(),x.end()

const ll mod=1e9+7;
const ll MX=2e5+5;

//code goes from here...



int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);
#endif

    boost
    //---------------------------------
    char a,b;
    cin >> a >> b;
    string s1="",s2="";
    int x,y;
    x=a-'0';
    y=b-'0';
    while(x--)
    {
        s1+=b;
    }
    while(y--)
    {
        s2+=a;
    }

     cout << min(s1,s2)<< endl;
    //---------------------------------
    
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i) >> B.at(i) >> C.at(i);
  }
  vector<vector<int>> DP(N, vector<int>(3));
  DP.at(0).at(0) = A.at(0);
  DP.at(0).at(1) = B.at(0);
  DP.at(0).at(2) = C.at(0);
  for (int i = 1; i < N; i++) {
    DP.at(i).at(0) = max(DP.at(i - 1).at(1), DP.at(i - 1).at(2)) + A.at(i);
    DP.at(i).at(1) = max(DP.at(i - 1).at(0), DP.at(i - 1).at(2)) + B.at(i);
    DP.at(i).at(2) = max(DP.at(i - 1).at(0), DP.at(i - 1).at(1)) + C.at(i);
  }
  cout << max({DP.at(N - 1).at(0), DP.at(N - 1).at(1), DP.at(N - 1).at(2)}) << "\n";
}

Measured memory_bytes: 6912
#include<stdio.h>
#define MAX 200000
int max(int a,int b){return a>b ? a:b;}
int min(int a,int b){return a<b ? a:b;}

int main(void){
	int R[MAX],i,n;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&R[i]);
	
	int maxv = -2000000000;
	int minv = R[0];
	
	for(i=1;i<n;i++){
		maxv = max(maxv,R[i]-minv);
		minv = min(minv,R[i]);
	}
	
	printf("%d\n",maxv);
	
	return 0;
}


Measured memory_bytes: 2640
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
//#include <chrono> //1e+9で割る auto end= chrono::system_clock::now()-st;  cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
typedef long double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)

int N,K;
ll A[100000];
ll imp[100000];
ll imn[100000];
bool b;
int id;
ll am=0xffffffffffffff;

int main()
{
	cin>>N>>K;
	rep(i,N){
		cin>>A[i];
		if(A[i]>0) imp[i]=A[i];
		else if(A[i]<0) imn[i]=-A[i];
	}
	rep1(i,N-1){
		imp[i]+=imp[i-1];
		imn[i]+=imn[i-1];
	}
	if(imp[K-1]<imn[K-1]){
		am=imp[K-1];
		id=0;
		b=1;
	}
	else{
		am=imn[K-1];
		id=0;
		b=0;
	}
	for(int i=1;i<N-K+1;i++){
		if(imp[i+K-1]-imp[i-1]<imn[i+K-1]-imn[i-1]){
			if(am>imp[i+K-1]-imp[i-1]){
				am=imp[i+K-1]-imp[i-1];
				id=i;
				b=1;
			}
		}
		else{
			if(am>imn[i+K-1]-imn[i-1]){
				am=imn[i+K-1]-imn[i-1];
				id=i;
				b=0;
			}
		}
	}
	ll ans;
	if(id==0) ans=imp[N-1]-imp[K-1];
	else ans=imp[N-1]-imp[id+K-1]+imp[id-1];
	if(!b){
		for(int i=id;i<id+K;i++){
			ans+=A[i];
		}
	}
	//cout<<id<<" "<<b<<endl;
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>

using namespace std;
int w, h, ans;
const int maxn = 105;
char tile[maxn][maxn];

void dfs(int m, int n, char temp)
{
    int a[4] = {-1, 0, 0, 1}, b[4] = {0, -1, 1, 0};
    tile[m][n] = '.';
    for(int i=0; i<4; ++i)
    {
        int x = m + a[i], y = n + b[i];
        if(x>=0 && x<h && y>=0 && y<w && tile[x][y]==temp)
        {
            dfs(x, y, temp);
        }
    }
}

int main()
{
    while(scanf("%d %d", &h, &w)!=EOF && h && w)
    {
        for(int i=0; i<h; ++i)
        {
            scanf("%s", tile[i]);
        }
        ans = 0;
        for(int i=0; i<h; ++i)
        {
            for(int j=0; j<w; ++j)
            {
                if(tile[i][j]!='.')
                {
                    dfs(i, j, tile[i][j]);
                    ++ans;
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}



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

int main(){
  int n, m;
  cin >> n >> m;
  vector <int > h(n+1), ma(n+1);
  for(int i=1; i<n+1; i++){
    cin >> h[i];
    ma[i]=0;
  }
  for(int i=0; i<m; i++){
    int a, b;
    cin >> a >> b;
    ma[a] = max(h[b], ma[a]);
    ma[b] = max(h[a], ma[b]);
  }
  int ans=0;
  for(int i=1; i<n+1; i++){
    if(h[i] > ma[i])ans++;
  }
  cout << ans << endl;
  return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n;
  cin >> n;
  vector<int> a(n),count(30,0);
  int xo=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    xo^=a[i];
    for(int j=0;j<30;j++){
      if(a[i]&(1<<j)){
        count[j]++;
        break;
      }
    }
  }
  int ans=0;
  for(int i=29;i>=0;i--){
    if(xo&(1<<i)){
      if(count[i]==0){
        cout << -1 << endl;
        return 0;
      }else{
        ans++;
        xo^=(1<<i)-1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
const int p = (int)1e9+7;

double dp[310][310][310];
int N;

double rec(int i, int j, int k) {
	if(dp[i][j][k] >= 0) return dp[i][j][k];
	if(i==0 && j==0 && k==0) return 0.0;

	double res=0.0;
	if(i>0) res += rec(i-1, j, k) * i;
	if(j>0) res += rec(i+1, j-1, k) * j;
	if(k>0) res += rec(i, j+1, k-1) * k;
	res += N;
	res *= 1.0 / (i+j+k);

	return dp[i][j][k] = res;
}

int main() {
	cin >> N;
	int one=0, two=0, three=0;
	for (int i = 0; i < N; i++) {
		int a; cin >> a;
		if(a==1) one++;
		else if(a==2) two++;
		else three++;
	}

	memset(dp, -1, sizeof(dp));

	cout << fixed << setprecision(10) << rec(one, two, three) << endl;
}

Measured memory_bytes: 233088
#include<iostream>
#include<stdio.h>

using namespace std;

int main(int n, int x) {
    while (true) {
        int c = 0;
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        for (int i = 1; i <= n-2; i++) {
            for (int j = i+1; j <= n-1; j++) {
                for (int k = j+1; k <= n; k++) {
                    if (i+j+k == x) c++;
                }
            }
        }
        cout << c << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

int n;
string s;

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

    cin >> n >> s;
    string t[2];
    t[0] = s.substr(0, n);
    t[1] = s.substr(n, n);
    reverse(t[1].begin(), t[1].end());

    map<pair<string, string>, ll> mp[2];
    for(int ti=0;ti<=1;ti++){
        for(int i=0;i<(1<<n);i++){
            string key[2] = {"", ""};
            for(int j=0;j<n;j++){
                if((i & (1 << j))){
                    key[1] += t[ti][j];
                }else{
                    key[0] += t[ti][j];
                }
            }
            mp[ti][make_pair(key[0], key[1])]++;
        }
    }

    ll ans = 0;
    for(auto itr=mp[0].begin();itr!=mp[0].end();itr++){
        ans += (itr->second) * mp[1][itr->first]; 
    }
    cout << ans << endl;
}


Measured memory_bytes: 108288
#include <iostream>
#include <math.h>
using namespace std;
#define prt(var) cout << (var) << endl;

int main() {
  string s;
  cin>>s;
  
  bool ok=false;
  if(s[0]==s[1] && s[1]==s[2]) ok=true;
  if(s[2]==s[3] && s[1]==s[2]) ok=true;
  
  prt(ok?"Yes":"No");
}

Measured memory_bytes: 3604
x, y = list(map(int,input().split()))
A = [1, 3, 5, 7, 8,10, 12]
B = [4, 6, 9, 11]
C = [2]

if (x in A and y in A) or (x in B and y in B):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-8
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}

int main() {
//	file();
	fast();
	int a, b, c; cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << ' ' << b << ' ' << c << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
#include <queue>
#include <numeric>


int main()
{
	int n;

	int ans = 1;

	std::cin >> n;

	while (ans <= n) {
		ans *= 2;
	}

	std::cout << ans / 2 << std::endl;
}


Measured memory_bytes: 256
// C - Flip,Flip, and Flip......
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ll N,M; cin>>N>>M;
	ll ans = 0;
	if(N<2 && M<2) ans = 1;
	else if(N<2 || M<2) ans = max(N, M) - 2;
	else ans = (N-2) * (M-2);
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define prArr(Arr,n) for(int _=0;_<n;_++)   cout<<(Arr)[_]<<" ";
#define f first
#define s second
using namespace std;
const int INF=(int)0x3f3f3f3f;
const int MOD=(int)1e9+7;
const double eps=1e-9;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int cnt2=0;
    vector<int> freq(26);
    string s;
    cin>>s;
    for(int i=0;i<4;i++)
        freq[s[i]-'A']++;
    for(int i=0;i<26;i++)
        cnt2+=(freq[i]==2);
    cout<<(cnt2==2?"Yes":"No");
    return 0;
}



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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main() {
    li a[5];
    rep(i, 5) {
        cin >> a[i];
    }
    rep(i, 5) {
        if (a[i] == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3588
n = int(input())
A = list(map(int, input().split()))
from collections import Counter
cntr = Counter(A)
ans = 'No'
if len(set(A)) == 1 and A[0] == 0:
  ans = 'Yes'
elif n % 3 == 0:
  if len(cntr) == 3:
    k = list(cntr.keys())
    v = list(cntr.values())
    if k[0]^k[1]^k[2] == 0 and v[0] == v[1] and v[1] == v[2]:
      ans = 'Yes'
  elif len(cntr) == 2:
    if sorted(cntr.keys())[0] == 0 and cntr.get(0) == n//3:
      ans = 'Yes'
print(ans)

Measured memory_bytes: 14704
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<set>
#include<chrono>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll dp[3001][3001];
signed main(){
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
  ll n,t,mid=0,tmp,ans=0;
  cin >> n >> t;
  set<ll> st;
  ll a[n],b[n];
  vector<pair<P,ll>> v;
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
    v.push_back({P(b[i],a[i]),i});
  }
  ll idx=0;
  sort(v.begin(),v.end(),greater<pair<P,ll>>());
  while(idx<n){
    end = chrono::system_clock::now();
    double time=  static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0);
    if(time>=1800) break;
    fill(dp[0],dp[3001],0);
    a[v[idx].second]=0;
    b[v[idx].second]=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<t;j++){
        dp[i+1][j] = dp[i][j];
        if(j>=a[i]&&dp[i+1][j]<=dp[i][j-a[i]]+b[i]){
          dp[i+1][j] = dp[i][j-a[i]]+b[i];
        }
      }
    }
    ans = max(ans,dp[n][t-1]+v[idx].first.first);
    a[v[idx].second]=v[idx].first.second;
    b[v[idx].second]=v[idx].first.first;
    idx++;
  }
  cout << ans << endl;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

// Number of bits to  
// represent int 
#define INT_BITS 62
  
// Function to return 
// maximum XOR subset 
// in set[] 
ll maxSubarrayXOR(ll set[], int n) 
{ 
    // Initialize index of 
    // chosen elements 
    int index = 0; 
  
    // Traverse through all 
    // bits of integer  
    // starting from the most 
    // significant bit (MSB) 
    for (int i = INT_BITS-1; i >= 0; i--) 
    { 
        // Initialize index of 
        // maximum element and 
        // the maximum element 
        ll maxInd = index; 
        ll maxEle = INT_MIN; 
        for (int j = index; j < n; j++) 
        { 
            // If i'th bit of set[j] 
            // is set and set[j] is  
            // greater than max so far. 
            if ( (set[j] & (1LL << i)) != 0  
                     && set[j] > maxEle ) 
                maxEle = set[j], maxInd = j; 
        } 
  
        // If there was no  
        // element with i'th 
        // bit set, move to 
        // smaller i 
        if (maxEle == INT_MIN) 
        continue; 
  
        // Put maximum element 
        // with i'th bit set  
        // at index 'index' 
        swap(set[index], set[maxInd]); 
  
        // Update maxInd and  
        // increment index 
        maxInd = index; 
  
        // Do XOR of set[maxIndex] 
        // with all numbers having 
        // i'th bit as set. 
        for (int j=0; j<n; j++) 
        { 
            // XOR set[maxInd] those 
            // numbers which have the 
            // i'th bit set 
            if (j != maxInd && 
               (set[j] & (1LL << i)) != 0) 
                set[j] = set[j] ^ set[maxInd]; 
        } 
  
        // Increment index of 
        // chosen elements 
        index++; 
    } 
  
    // Final result is  
    // XOR of all elements
    ll res = 0; 
    for (int i = 0; i < n; i++) 
        res ^= set[i]; 
    return res; 
} 

  
ll a[200000];
int cnt[65];

int main(){
	int n;cin>>n;
	rep(i,n){
		scanf("%lld",&a[i]);
		rep(j,62){
			cnt[j]+=(a[i]>>j&1);
		}
	}
	ll ans=0;
	rep(j,62){
		if(cnt[j]%2==1){
			ans^=(1LL<<j);
			rep(i,n){
				if(a[i]>>j&1){
					a[i]^=(1LL<<j);
				}
			}
		}
	}
	//~ ll C=0;
	//~ rep(i,n){
		//~ C^=a[i];
	//~ }
	ll S=maxSubarrayXOR(a,n);
	cout<<ans+S*2<<endl;
}

Measured memory_bytes: 1024
/*
    問題をよく読もう！
    論理的に考えよう！
    サンプルを確認しよう!
    絶対に諦めるな！
    工夫をしろ！

    Twitterは終わるまでログアウト！
    （間違えて解法をツイートしてはいけないから）

*/
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言

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

  if(A+B >= C) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

int main(){
    ll n, m; cin >> n >> m;
    vector<string> a(n); rep(i,n) cin >> a[i];
    vector<string> b(m); rep(i,m) cin >> b[i];

    if(n-m == 0 && a == b){
        put("Yes");
        return 0;
    }

    for(int i = 0; i < n-m; i++){
        ll flag;
        auto index = a[i].find(b[0]);
        if(index != string::npos) flag = 1;
        else flag = 0;
        //put(index);
        for(int y = 1; y < m; y++){
            for(int x = 0; x < m; x++){
                if(a[i+y][index+x] != b[y][x]){
                    flag = 0;
                    break;
                }
            }
        }
        if(flag){
            put("Yes");
            return 0;
        }
    }
    put("No");
}

Measured memory_bytes: 3596
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits
from datetime import date

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A,B,K=MAP()

ans=[]
for i in range(1, max(A,B)+1):
    if A%i==0 and B%i==0:
        ans.append(i)
ans.reverse()
print(ans[K-1])


Measured memory_bytes: 6020
n = int(input())
h = list(map(int, input().split()))

for i in range(n - 1, 0, -1):
    dif = h[i - 1] - h[i]
    if dif >= 2:
        print("No")
        exit()
    elif dif == 1:
        h[i - 1] -= 1
print("Yes")


Measured memory_bytes: 14252
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;

ll INF = 1e+18;
using G = vector<map<int, int>>;

ll N, M;

ll
solve(ll mid, vector<ll> &arr)
{
  ll count = 0;
  rep(i, 0, N){
    count += arr.end() - lower_bound(arr.begin(), arr.end(), mid - arr[i]);
  }
  return count;
}

int 
main()
{
  cin >> N >> M;
  vector<ll> arr(N);
  rep(i, 0, N) cin >> arr[i];
  sort(arr.begin(), arr.end());

  ll ok = 0;
  ll ng = 1 << 18;
  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    ll comp = solve(mid, arr);
    if(comp >= M) ok = mid;
    else ng = mid;
  }
  
  vector<ll> acum(N + 1, 0);
  rep(i, 0, N) acum[i + 1] = acum[i] + arr[i];
  
  ll ans = 0;
  rep(i, 0, N){

    int len = arr.end() - lower_bound(arr.begin(), arr.end(), ok - arr[i]);
    if(len > 0){
      int diff = N - len;
      ans += len * arr[i] + (acum[N] - acum[diff]);
      M -= len;
    }
  }
  ans += M * ok;

  cout << ans << endl;
}

Measured memory_bytes: 4808
#include <bits/stdc++.h>
#define fi first
#define se second
#define pr pair <int, int> 
using namespace std;

const int N = 400005;
int n, s, cnt, num1, num2, ans; bool ok;
int b[N], din[N], dout[N];
pr a[N]; bool vis[N];
map <int, int> g, id;
vector <int> v[N]; 
bool sam () {
	for (int i = 1; i <= n; ++i)
		if (a[i].fi != a[i].se) return 0;
	return 1;
}
void Discreting () {
	for (int i = 1; i <= n; ++i)
		b[++cnt] = a[i].fi, b[++cnt] = a[i].se;
	b[++cnt] = s;
	sort(b + 1, b + 1 + cnt);
	cnt = unique(b + 1, b + 1 + cnt) - b - 1;
	for (int i = 1; i <= cnt; ++i) id[b[i]] = i;
}
void add (int x, int y) {
	++dout[x], ++din[y], v[x].push_back(y);
	vis[x] = vis[y] = 0;
}
void dfs (int x) {
	vis[x] = 1;
	for (int i = 0, y; i < v[x].size(); ++i) {
		y = v[x][i];
		if (!vis[y]) dfs(y);
	}
}
int main () {
	cin >> n, g.clear();
	for (int i = 1, x; i <= n; ++i)
		scanf("%d", &x), s ^= x, ++g[x], a[i].fi = x;
	++g[s];
	for (int i = 1, x; i <= n; ++i) {
		scanf("%d", &x), a[i].se = x;
		if (g[x] == 0) return puts("-1"), 0;
		--g[x];
	}
	if (sam()) return puts("0"), 0; else Discreting();
	memset(vis, 1, sizeof vis); 
	for (int i = 1; i <= n; ++i) if (a[i].fi != a[i].se)
		add(id[a[i].se], id[a[i].fi]), ++ans;
	
	dfs(id[s]);
	for (int i = 1; i <= cnt; ++i)
		if (!vis[i]) dfs(i), ++ans;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 32640
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int f(int g[],int m[],int gg,int mm,int imin){
  int i;
  int mmin=8000;
  if(gg==0)
    return mm;
  else{
    for(i=imin;i<6;i++){
      if(g[i]<=gg)
	mmin=min(f(g,m,gg-g[i],mm+m[i],i),mmin);
    }
  }
  return mmin;
}
int main(){
  int gg;
  int g[6]={1500,1200,1000,500,300,200};
  int m[6]={2244,1870,1520,850,550,380};
  for(;;){
    cin>>gg;
    if(gg==0)
      break;
    cout<<f(g,m,gg,0,0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
import math

a,b,h,m=map(int,input().split())


h=h*30+0.5*m
m*=6
x=min(abs(h-m),360-abs(h-m))
y=math.cos(math.radians(x))

if x==1:
    print(0)
else:
    print(math.sqrt(a**2+b**2-2*a*b*y))

Measured memory_bytes: 9392
#include<stdio.h>
int main(void)
{
  int n,a;
  scanf("%d %d",&n,&a);
  if(n<=a){
    puts("Yes");
    return 0;
  }
  if(n%500<=a){
    puts("Yes");
  }else{
    puts("No");
  }
  return 0;
}


Measured memory_bytes: 1636
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		int cnt = 0;
		for(int i = 0 ; i < 3 ; ++i){
			if(S.charAt(i) == T.charAt(i)){
				++cnt;
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) ((a)<<(b))
#define Rshift(a,b) ((a)>>(b))
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define sz(a) int(a.size())
#define mset(x) memset(x, 0, sizeof(x))
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll ans(0);
    ans += min(a, k);
    k -= min(a, k);
    k -= min(k, b);
    ans -= min(k, c);
    cout << ans << endl;
}


Measured memory_bytes: 3640
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
const long long MaxN = 1e5;

long long sum[2 * MaxN + 5];

int main()
{
	long long n,piu,ans;
	while(~scanf("%lld",&n))
	{
		sum[0] = 0;
		for(long long i = 1;i <= n;i++) 
		{
			scanf("%lld",&piu);
			sum[i] = sum[i - 1] + piu;
		}
		sort(sum,sum + 1 + n);
		piu = 1;
		ans = 0;
		for(long long i = 1;i <= n;i++)
		{
			if(sum[i] != sum[i - 1])
			{
				ans += piu * (piu - 1) / 2;
				piu = 1;
			}
			else piu++;
		}
		ans += piu * ( piu - 1 ) / 2;
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1664
# -*- coding: utf-8 -*-
import sys
sum = [0]*4

for i in range(0,3):
    a, b = map(int, input().split())
    sum[a-1] +=1
    sum[b-1] +=1

for i in range(0,4):
    if sum[i] >= 3:
        print("NO")
        sys.exit()

print("YES")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int r;
	cin >> r;
	cout << r * r << endl;
}

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

int main()
{
    string s;
    unsigned long long int k;
    cin >> s;
    cin >> k;

    for (int i = 0; i < k; i++)
    {
        if (s[i] != '1')
        {
            break;
        }

        if (i == k - 1)
        {
            cout << 1 << endl;
            return 0;
        }
    }

    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] > '1')
        {
            cout << s[i] << endl;
            return 0;
        }
    }

    return 0;
}

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

int dp[maxn][3];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

   //freopen("d.in", "r", stdin);

    int n;cin >> n;
    for (int i = 1; i <= n; i++){
        int a, b, c;cin >> a >> b >> c;
        if (i == 1){
            dp[i][0] = a;
            dp[i][1] = b;
            dp[i][2] = c;
            continue;
        }
        dp[i][0] = max(dp[i - 1][1] + a, dp[i - 1][2] + a);
        dp[i][1] = max(dp[i - 1][0] + b, dp[i - 1][2] + b);
        dp[i][2] = max(dp[i - 1][1] + c, dp[i - 1][0] + c);
    }

    cout << max(dp[n][0], max(dp[n][1], dp[n][2]));

    return 0;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#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 mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vi a(n),b(n);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    vi T(n);
    rep(i,n) T[i] = b[i]^b[(i+1)%n];
    rep(i,2*n-1) T.pb(a[i%n]^a[(i+1)%n]);
    int N = T.size();
    vi A(N); A[0]=N;
    int i=1,j=0;
    while(i<N){
        while(i+j<N && T[i+j]==T[j]) j++;
        A[i] = j;
        if (j==0){ i++; continue;}
        int k = 1;
        while(i+k<N && k+A[k]<j) A[i+k]=A[k], k++;
        i+=k; j-=k;
    }
    FOR(i,n,N-1)if(A[i]>=n){
        int k=i-n;
        cout<<k<<" "<<(b[0]^a[k])<<"\n";
    }
    return 0;
}


Measured memory_bytes: 10324
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n,k;
	cin >> n >> k;
	int ans=k;
	for(int i=1;i<n;i++)
	{
		ans*=k-1;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
n,q=gets.split.map(&:to_i)
str=gets.chomp.split('')
sumarray=Array.new(n,0)

i=0
(n-1).times{
    if str[i]=="A"&& str[i+1]=="C"
        sumarray[i+1]=sumarray[i]+1
    else
        sumarray[i+1]=sumarray[i]
    end
    i+=1
}

q.times{
    l,r=gets.split.map(&:to_i)
    
    if l==1
        puts sumarray[r-1]
    
    elsif str[l-2]=="A"&& str[l-1]=="C"
        puts sumarray[r-1]-sumarray[l-2]-1
    else
        puts sumarray[r-1]-sumarray[l-2]
    end
    
}

Measured memory_bytes: 10876
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <fstream>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

const int MAXN = 105;

int n,m;
int match[MAXN];
int cnt[MAXN][MAXN];

bool vis[MAXN];

pair<int,int> b[MAXN];
pair<int,int> a[MAXN][MAXN];

bool dfs(int i)
{
	if (vis[i])
		return 0;
	vis[i] = 1;
	for (int j = 1;j <= n;j++)
		if (cnt[j][i] && (!match[j] || dfs(match[j])))
		{
			match[j] = i;
			vis[i] = 0;
			return 1;
		}
	return 0;
}

int main()
{
	scanf("%d%d",&n,&m);
	for (int i = 1;i <= n;i++)
		for (int j = 1;j <= m;j++)
		{
			scanf("%d",&a[i][j].first);
			a[i][j].second = (a[i][j].first - 1) % m + 1;
			a[i][j].first = (a[i][j].first - 1) / m + 1;
			cnt[i][a[i][j].first]++;
		}
	for (int i = 1;i <= m;i++)
	{
		memset(vis,0,sizeof(vis));
		memset(match,0,sizeof(match));
		for (int j = 1;j <= n;j++)
			dfs(j);
		for (int j = 1;j <= n;j++)
		{
			cnt[j][match[j]]--;
			for (int k = i;k <= m;k++)
				if (a[j][k].first == match[j])
				{
					swap(a[j][k],a[j][i]);
					break;
				}
		}
	}
	for (int i = 1;i <= n;i++,printf("\n"))
		for (int j = 1;j <= m;j++)
			printf("%d ",(a[i][j].first - 1) * m + a[i][j].second);
	for (int i = 1;i <= m;i++)
		for (int j = 1;j <= n;j++)
			for (int k = j + 1;k <= n;k++)
				if (a[j][i].first > a[k][i].first)
					swap(a[j][i],a[k][i]);
	for (int i = 1;i <= n;i++,printf("\n"))
		for (int j = 1;j <= m;j++)
			printf("%d ",(a[i][j].first - 1) * m + a[i][j].second);
	return 0;
}

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

#define ll long long

using namespace std;

ll a[200010];

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

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

    ll ans = 0;

    for(int i=0;i<n;i++)
        ans += abs(a[i]);

    ll l,h;
    l = 0;
    h = 1000000000;

    while(l<h)
    {
        ll mid = (l+h)/2;

        ll temp1 = 0,temp2 = 0;

        for(int i=0;i<n;i++)
            temp1 += abs(a[i]-mid);

        for(int i=0;i<n;i++)
            temp2 += abs(a[i]-mid-1);

        //cout << l << " " << h << endl;
        //cout << mid << " " << temp1 << " " << temp2 << endl;

        if(temp1 <= temp2)
        {
            h = mid;
        }
        else
        {
            l = mid+1;
        }
    }

    ll ans1 = 0;

    for(int i=0;i<n;i++)
        ans1 += abs(a[i]-l);

    l = 0;
    h = 1000000000;

    while(l<h)
    {
        ll mid = (l+h)/2;

        ll temp1 = 0,temp2 = 0;

        for(int i=0;i<n;i++)
            temp1 += abs(a[i]+mid);

        for(int i=0;i<n;i++)
            temp2 += abs(a[i]+mid+1);

        //cout << l << " " << h << endl;
        //cout << mid << " " << temp1 << " " << temp2 << endl;

        if(temp1 <= temp2)
        {
            h = mid;
        }
        else
        {
            l = mid+1;
        }
    }

    ll ans2 = 0;

    for(int i=0;i<n;i++)
        ans2 += abs(a[i]+l);

    cout << min(ans1,ans2) << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int sc[110],num[110],rank[110];
int main(){
  int N;
  cin>>N;
  for(int i=0;i<N*(N-1)/2;++i){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(c>d) sc[a-1]+=3;
    else if(c<d) sc[b-1]+=3;
    else{
      sc[a-1]++;
      sc[b-1]++;
    }
  }
  for(int i=0;i<N;++i) num[i]=i+1;
  for(int i=0;i<N;++i){
    for(int j=N-1;j!=i;--j){
      if(sc[i]<sc[j]){
	swap(num[i],num[j]);
	swap(sc[i],sc[j]);
      }
    }
  }
  int x=1;
  for(int i=0;i<N;++i){
    if(i>0&&sc[i]==sc[i-1]){
      rank[num[i]-1]=rank[num[i-1]-1];
      x++;
    }else rank[num[i]-1]=x++;
  }
  for(int i=0;i<N;++i) cout<<rank[i]<<endl;
  return 0;
}

Measured memory_bytes: 3068
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
5
0 3 2 3 3 1 1 2
1 2 0 2 3 4
2 3 0 3 3 1 4 1
3 4 2 1 0 1 1 4 4 3
4 2 2 1 3 3

output:
0 0
1 2
2 2
3 1
4 3
"""

import sys
import heapq as hp

WHITE, GRAY, BLACK = 0, 1, 2


def generate_adj_table(v_table):
    for each in v_table:
        v_index, v_adj_length, *v_adj_list = map(int, each)
        # assert len(v_adj_list) == v_adj_length * 2
        for pair in zip(v_adj_list[::2], v_adj_list[1::2]):
            init_adj_table[v_index][pair[0]] = pair[1]

    return init_adj_table


def dijkstra_path_heap():
    # path search init
    distance[init_vertex] = 0
    path_heap = []
    # heapq: rank by tuple[0], at here it's d[u]
    hp.heappush(path_heap, (0, init_vertex))

    while path_heap:
        current = hp.heappop(path_heap)[1]

        color[current] = BLACK

        for adj, cost in adj_table[current].items():
            if color[adj] is not BLACK:
                # alt: d[u] + w[u,v]
                alt_path = distance[current] + cost
                if alt_path < distance[adj]:
                    # update path_list
                    distance[adj] = alt_path
                    # update heap
                    hp.heappush(path_heap, (alt_path, adj))
                    color[adj] = GRAY
                    parents[adj] = current

    return distance


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices = int(_input[0])
    v_info = map(lambda x: x.split(), _input[1:])
    # assert len(init_vertices_table) == vertices_num

    distance = [float('inf')] * vertices
    parents = [-1] * vertices
    color = [WHITE] * vertices
    init_adj_table = tuple(dict() for _ in range(vertices))
    init_vertex = 0

    adj_table = generate_adj_table(v_info)
    ans = dijkstra_path_heap()
    for i, v in enumerate(ans):
        print(i, v)

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll X; cin >> X;
  string result = X>=30 ? "Yes" : "No";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<climits>
#include<numeric>
using namespace std;

int main(void)
{
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;

	vector<int> a(N), b(N), c(N);
	for(int i=0; i<N; i++)
		cin >> a[i] >> b[i] >> c[i];

	const int sum_a = accumulate(a.begin(), a.end(), 0);
	const int sum_b = accumulate(b.begin(), b.end(), 0);
	vector<vector<vector<int>>> dp(N+1, vector<vector<int>>(sum_a+1 ,vector<int>(sum_b+1, INT_MAX)));
	dp[0][0][0] = 0;

	for(int i=0; i<N; i++)
	{
		for(int j=0; j<sum_a+1; j++)
		{
			for(int k=0; k<sum_b+1; k++)
			{
				if(dp[i][j][k] == INT_MAX)
					continue;

				dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
				dp[i+1][j+a[i]][k+b[i]] = min(dp[i+1][j+a[i]][k+b[i]], dp[i][j][k] + c[i]);
			}
		}
	}

	int ret = INT_MAX;
	for(int i=1; i*Ma<=sum_a&&i*Mb<=sum_b; i++)
		ret = min(ret, dp[N][i*Ma][i*Mb]);

	if(ret == INT_MAX)
		ret = -1;

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 9984
n, m = gets.split(' ').map(&:to_i)

h = {}

m.times do
  pp, s = gets.chomp.split(' ')
  pp = pp.to_i

  h.key?(pp) ? h[pp] << s : h[pp] = [s]
end

ac =
  h.reduce(0) do |result, hh|
    pp, s = hh

    s.include?('AC') ? result + 1 : result
  end

pe =
  h.reduce(0) do |result, hh|
    pp, s = hh

    next result unless s.include?('AC')

    result + s.find_index('AC')
  end

puts "#{ac} #{pe}"



Measured memory_bytes: 20988
import java.util.Scanner;

public class Main {

    private static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    private static long factorize(long n) {
        int count = 1;
        for (int i = 2; i <= Math.sqrt(n); i++) {
            if (n % i != 0) {
                continue;
            }
            while (n % i == 0) {
                n /= i;
            }
            count++;
        }
        if (n != 1) {
            count++;
        }
        return count;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        // 最大公約数
        long gcd = gcd(a, b);
        // aとbの公約数 = gcd(a,b)の約数より、
        // gcdを素因数分解して素因数の個数を数える
        System.out.println(factorize(gcd));
    }

}


Measured memory_bytes: 22612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF 100000000

int main() {
	long long a, ans;
	cin >> a;

	ans = a + (a*a) + (a*a*a);

	cout << ans;
	return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vb = vector<bool>;
using vs = vector<string>;
using pint = pair<int, int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
    int n;
    cin >> n;
    vi p(n);
    rep(i, n) cin >> p[i];

    int m = p[0];
    int cnt = 0;
    rep(i, n) {
        if(m >= p[i]) {
            cnt++;
            m = min(m, p[i]);
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
i = n - 1

ans = 0

n.times do
  
  if b[i] > a[i+1]
    ans += a[i+1]
    b[i] = b[i] - a[i+1]
    a[i+1] = 0
  else
    ans += b[i]
    a[i+1] = a[i+1] - b[i]
    b[i] = 0
  end
  
  if  b[i] > a[i]
      ans += a[i]
      a[i] = 0
  else
    ans += b[i]
    a[i] = a[i] - b[i]
  end  
  
  i = i - 1
end

puts ans

Measured memory_bytes: 15500
#include <bits/stdc++.h>
using namespace std;
const int mod=1e9;
const int maxn=1e5+5;
typedef long long ll ;
int main()
{
    int n;
    int a,b;
    int p[105];
    scanf("%d",&n);
    scanf("%d%d",&a,&b);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&p[i]);
    }
    sort(p,p+n);
    int cnt1=0;
    int cnt2=0;
    int cnt3=0;
    for(int i=0;i<n;i++)
    {
        if(p[i]<=a)cnt1++;
        else if(a<p[i] && p[i]<=b)cnt2++;
        else if(p[i]>b)cnt3++;
    }
    int ans=min(min(cnt1,cnt2),cnt3);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
struct Info {
	int i,j,k;
	Info(int _i,int _j,int _k) {i=_i,j=_j,k=_k;}
};
vector<Info> info[2];
int result[300];
int main() {
	int a,b,c,N;
	while(scanf("%d %d %d",&a,&b,&c),a|b|c) {
		scanf("%d",&N);
		info[0].clear();
		info[1].clear();
		memset(result,0,sizeof(result));
		for(int i=0;i<N;i++) {
			int I,J,K,R;
			scanf("%d %d %d %d",&I,&J,&K,&R);
			info[R].push_back(Info(I-1,J-1,K-1));
		}
		for(int i=0;i<info[1].size();i++) {
			Info I=info[1][i];
			result[I.i]=result[I.j]=result[I.k]=1;
		}
		for(int i=0;i<info[0].size();i++) {
			Info I=info[0][i];
			if(result[I.i]==1&&result[I.j]==1) result[I.k]=2;
			if(result[I.i]==1&&result[I.k]==1) result[I.j]=2;
			if(result[I.j]==1&&result[I.k]==1) result[I.i]=2;
		}
		for(int i=0;i<(a+b+c);i++) {
			printf("%d\n",(result[i]==2)?0:(result[i]==0)?2:1);
		}
	}
}

Measured memory_bytes: 1056
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
typedef pair<ll,ll>PLL;
#define X first
#define Y second
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};

int main(){
	int X,Y,Z;
	cin>>X>>Y>>Z;
	swap(X,Y);
	swap(X,Z);
	cout<<X<<" "<<Y<<" "<<Z<<endl;
	return 0;
}

Measured memory_bytes: 256