akhauriyash/Code-Regression huggingface dataset:
//long long -> ll
//http://web.mit.edu/~ecprice/acm/acm08/notebook.html#file12
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include<bits/stdc++.h>
typedef long long ll;
#define x first
#define y second
#define all(aaa) (aaa).begin(),(aaa).end()
#define REP(i,sss,eee) for(long long i=sss;i<=eee;++i)
#define pb push_back
#define pii pair<long long,long long>
#define vi vector<long long>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
#define N 1000000007
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}
typedef tree<
long long,
null_type,
less<long long>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
long long ex(long long a, long long b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	long long tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
long long inv(long long k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
std::vector<long long> par,num,var,sum,rem;
//num -> rank sum->tot joined vertices
std::vector<tuple<long long,long long,long long>> edg;
bool cmp(tuple<long long,long long,long long> q,tuple<long long,long long,long long> w)
{
	return ((get<2>(q))<(get<2>(w)));
}
long long findpar(long long a)
{
	if(a==par[a]){return a;}
	return findpar(par[par[a]]);
}
long long unite(long long a, long long b)
{
	long long p1=findpar(a),p2=findpar(b);
	if(num[p1]<num[p2]){SWAP(p1,p2);}
	num[p1]+=num[p2];
	sum[p1]+=sum[p2];
	rem[p1]+=rem[p2];
	par[p2]=p1;
	return 0;
}
long long solve()
{
	long long n,m;cin>>n>>m;
	par.resize(n+1);num.resize(n+1,1);sum.resize(n+1,0);
	rem.resize(n+1,0);
	iota(par.begin(),par.end(),0);
	var.resize(n+1);
	REP(i,1,n)
	{
		cin>>var[i];sum[i]=var[i];
	}
	REP(i,1,m)
	{
		long long a,b,c;cin>>a>>b>>c;
		edg.pb(make_tuple(a,b,c));
	}
	sort(edg.begin(),edg.end(),cmp);
	long long ans=0;
	for(auto it:edg)
	{
		long long a=get<0>(it),b=get<1>(it),c=get<2>(it);
		if(findpar(a)!=findpar(b))
		{
			unite(a,b);
		}
		++rem[findpar(a)];
		if(sum[findpar(a)]>=c)
		{
			ans+=rem[findpar(a)];
			rem[findpar(a)]=0;
		}
	}
	cout<<(m-ans)<<"\n";
}
signed main(){
	speed
	long long tt=1;
	//cin>>tt;
	while(tt--)
	{
		solve();
	}
	return 0;
}

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

int n, m, c[16], x[20000], table[20001][256];
const int INF = 2147483647;

int min(int a, int b){
    return a < b ? a : b;
}

int main(){
    cin >> n >> m;
    while( n != 0 || m != 0 ){
        int i;
        for(i = 0; i < m; i++){
            cin >> c[i];
        }
        for(i = 0; i < n; i++){
            cin >> x[i];
        }
        //dp
        for(i = 0; i <= n; i++){
            for(int j = 0; j < 256; j++){
                table[i][j] = INF;
            }
        }
        table[0][128] = 0;
        for(i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                for(int k = 0; k <= 255; k++){
                    if( table[i][k] < INF ){
                        int t = k + c[j];
                        if( t < 0 ) t = 0;
                        if( t > 255 ) t = 255;
                        int s = (t - x[i])*(t - x[i]);
                        table[i+1][t] = min(table[i][k] + s, table[i+1][t]);
                    }
                }
            }
            /*
            for(int j = 0; j < 256; j++){
                if( table[i][j] == INF){
                    cout << "INF ";
                }else{
                    cout << table[i][j] << ' ';
                }
            }
            */
        }
        int ans = INF;
        for(int i = 0; i <= 255; i++){
            ans = min(table[n][i], ans);
        }
        cout << ans << endl;
        cin >> n >> m;
    }
    return 0;
}

Measured memory_bytes: 21240
import sys
sys.setrecursionlimit(1000000)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = int(str(I())[-1])

if N == 3:
    print("bon")
    sys.exit()
elif N in [0, 1, 6, 8]:
    print("pon")
    sys.exit()
else:
    print("hon")    


Measured memory_bytes: 61892
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> T gcd(T a, T b){return !b?a:gcd(b,a%b);}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
ll n,m,x;

int main() {
	read(n);read(m);read(x);
	if(n>m)swap(n,m);
	cout<<(x+m-1)/m;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
int main()
{
    Hello
    int n;
    cin >> n;
    pair<ll, ll> pr[n + 5];
    ll sum = 0;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        pr[i].first = b;
        pr[i].second = a;
    }
    sort(pr, pr + n);
    for(int i = 0; i < n; i++){
        sum += pr[i].second;
        if(sum > pr[i].first)
            return cout << "No", 0;
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 3328
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true; } return false; }
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true; } return false; }

//INT_MAX	2,147,483,647 = 2*1.0e9

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


  vector<int> x(N), y(N), h(N);
  int cnt = N;
  int pos = -1;
  rep(i, N){
    cin >> x[i] >> y[i] >> h[i];
    if(h[i] == 0) cnt--;
    else pos = i;
  }

  if(cnt == 1){
    cout << x[pos] << " " << y[pos] << " " << h[pos] << endl;
    return 0;
  }
  

  for(int cx = 0; cx <= 100; cx++){
    for(int cy = 0; cy <= 100; cy++){
      int hTemp = -1;
      bool ok = true;
      for(int i = 0; i < N; i++){
        if(h[i] == 0) continue;
        int estH = abs(cx - x[i]) + abs(cy - y[i]) + h[i];
        if(hTemp == -1){
          hTemp = estH;
        } else {
          if(hTemp != estH){
            ok = false;
            break;
          }
        }
      }      
      if(ok && hTemp != 0){
        cout << cx << " " << cy << " " << hTemp << endl;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int r, c;
    int a = 0;
    int b = 0;
    
    cin >> r >> c;
    
    int dim[r][c];
    
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> dim[i][j];
        }
    }
    
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cout << dim[i][j] << " ";
            a += dim[i][j];
        }
        
        cout << a << endl;
        
        a = 0;
    }
    
    for(int i = 0; i < c; i++){
        for(int j = 0; j < r; j++){
            a += dim[j][i];
        }
        
        cout << a << " ";
        
        b += a;
        
        a = 0;
        
        
    }
    
    cout << b << endl;
    
}


Measured memory_bytes: 3124
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int h, w;
	scanf("%d%d", &h, &w);
	VV(int) a;
	initvv(a, h, w);
	for(int i = 0; i < h; ++i)
	for(int j = 0; j < w; ++j){
		scanf("%d", &a[i][j]);
	}

	stringstream ans;
	int sz = 0;
	int c = 0;
	for(int y = 0; y < h; ++y){
		int dir = y & 1 ? -1 : 1;
		for(int x = y & 1 ? w - 1 : 0; x >= 0 && x < w; x += dir){
			c ^= a[y][x];
			c &= 1;
			if(!c){ continue; }
 			int ny = y, nx = x + dir;
 			if(nx < 0 || nx >= w){
 				nx = x;
 				ny = y + 1;
 			}
 			if(ny >= h){ continue; }
 			ans << y + 1 << ' ' << x + 1 << ' ' << ny + 1 << ' ' << nx + 1 << '\n';
 			++sz;
		}
	}
	cout << sz << '\n' << ans.str();
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


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

int h, w;
int n;
bool ng[16][16];
int dp[16][16];

int search(int x, int y)
{
	if (x > h - 1 || y > w - 1) return 0;
	if (ng[x][y]) return 0;
	if (x == h - 1 && y == w - 1) return 1;
	if (~dp[x][y]) return dp[x][y];
	return dp[x][y] = search(x + 1, y) + search(x, y + 1);
}

int main()
{
	while (scanf("%d %d", &h, &w), h){
		memset(ng, 0, sizeof(ng));
		memset(dp, -1, sizeof(dp));
		
		scanf("%d", &n);
		for (int i = 0; i < n; i++){
			int x, y;
			scanf("%d %d", &x, &y);
			ng[--x][--y] = true;
		}
		
		printf("%d\n", search(0, 0));
	}
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

ll fact[100001];
signed main() {
	fact[0] = 1;
	for (int i = 1; i <= 100000; i++)fact[i] = (fact[i - 1] * i) % MOD;
	ll n, m; cin >> n >> m;
	if (n == m + 1||n==m-1) {
		cout << (fact[n] * fact[m]) % MOD << endl;
	}
	else if (n == m) {
		cout << (fact[n] * fact[m] * 2) % MOD << endl;
	}
	else puts("0");
}

Measured memory_bytes: 1536
from math import gcd

k = int(input()) + 1
ans = 0

for s in range(1, k):
    for t in range(s, k):
        for u in range(t, k):
            if (v := len(set([s, t, u]))) == 1:
                ans += gcd(gcd(s, t), u)
            elif v == 2:
                ans += gcd(gcd(s, t), u) * 3
            else:
                ans += gcd(gcd(s, t), u) * 6
print(ans)



Measured memory_bytes: 9196
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	long long int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(b<=0){
		if(d<=0)cout<<a*c;
		else if(c>=0)cout<<b*c;
		else cout<<a*c;
	}else if(a>=0){
		if(d<=0)cout<<a*d;
		else if(c>=0)cout<<b*d;
		else cout<<b*d;
	}else{
		if(d<=0)cout<<a*c;
		else if(c>=0)cout<<b*d;
		else cout<<max(a*c,b*d);
	}
	return 0;
}

Measured memory_bytes: 3532
//#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
pair<string,int> a[100];
int main(){
	int t=0,g;
	string f,b;
	while(cin>>a[t].first>>a[t].second)t++;
	sort(a,a+t);
	b=a[0].first;
	cout<<b<<endl<<a[0].second;
	for(int i=1;i<t;i++){
		bool n=0;
		f=a[i].first,g=a[i].second;
		if(i)if(f==b)n=1;
		if(n)cout<<" "<<g;
		else cout<<endl<<f<<endl<<g;
		b=f;
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1228
s = input()
a, b, c, d = s[0], s[1], s[2], s[3]
for op1 in "+-":
  for op2 in "+-":
    for op3 in "+-":
      f = a+op1+b+op2+c+op3+d
      if eval(f)==7:
        print(f+"=7")
        exit()


Measured memory_bytes: 3060
N = int(input())
l = list(map(int,input().split(" ")))
DP = [1000]*N
for i in range(N):
  for j in range(i+1,N):
    t = DP[i]//l[i]
    DP[j] = max(DP[j-1],(DP[i]-l[i]*t)+l[j]*t)
print(DP[-1])

Measured memory_bytes: 9192
var lines = require('fs').readFileSync('/dev/stdin', 'utf8').split('\n');
var i, xy;
for (i in lines) {
  xy = lines[i].split(' ').map(Number);
  if (xy[0] === 0 && xy[1] === 0) {
    break;
  }
  xy.sort(function (a, b) {return a - b; });
  console.log(xy[0], xy[1]);
}

Measured memory_bytes: 19476
#include<bits/stdc++.h>
using namespace std;
#define nl cout<<'\n';
int fun(int a)
{
    int r=0;
    while(a>0)
    {
        r+=(a%10);
        a/=10;
    }
    return r;
}
int main()
{
    int n,a,b,s=0,r;
    cin>>n>>a>>b;
    for(int i=1; i<=n; i++)
    {
        r=fun(i);
        if(r>=a and r<=b)
        {
            s+=i;
        }

    }
    cout<<s;
    nl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int a, b, c;
  cin >> a >> b >> c;

  int ans = min({a + b, b + c, c + a});
  cout << ans << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin >>s;
	int len=s.size();
	string a,b,c,x,y;
	b=s.substr(0,(len-1)/2);
	c=s.substr((len+3)/2-1,len-(len+3)/2+1);
	a=s,x=b,y=c;
//	cout <<a<<" "<<b<<" "<<c<<" "<<endl;
	reverse(s.begin(),s.end());
	reverse(b.begin(),b.end());
	reverse(c.begin(),c.end());
	if(s==a&&b==x&&c==y) cout <<"Yes"<<endl;
	else cout <<"No"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		String S = sc.next();
		sc.close();

		int len = S.length();
		int cnt = 0;
		for(int i = 1;i < N;i++){
			if(S.charAt(i-1)==S.charAt(i)){
				cnt++;
			}
		}
		System.out.println(len-cnt);
	}
}

Measured memory_bytes: 23136
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		int x,y;
		cin>>x>>y;
		if((4*x-y)>=0 && (y-2*x)>=0)
		{
			if((4*x-y)%2==0 && (y-2*x)%2==0)
			{
				cout<<"Yes"<<endl;
			}
			else
			{
				cout<<"No"<<endl;
			}
		}
		else
		{
			cout<<"No"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3632
/*input
*/
#include <bits/stdc++.h>
using namespace std;
 
#define all(a) (a).begin(), (a).end()
#define pb push_back
 
using ll = long long;
using pii = pair<int, int>;

const int N = 12, M = 1e3 + 2;
const int inf = 1e9;
int dp[1 << N];
vector<pii> keys;

int main() {
	ios::sync_with_stdio(false);cin.tie(nullptr);
	int n, m; cin >> n >> m;
	keys.resize(m);
	fill(dp, dp + (1 << N), inf);
	for (int i = 0; i < m; ++i) {
		int a, b; cin >> a >> b;
		keys[i].first = a;
		keys[i].second = 0;
		for (int j = 0; j < b; ++j) {
			int c; cin >> c;
			--c;
			keys[i].second |= (1 << c);
		}
		for (int mask = 0; mask < (1 << n); ++mask) {
			if ((mask & keys[i].second) == mask)
				dp[mask] = min(dp[mask], keys[i].first);
		}
	}
	for (int m1 = 0; m1 < (1 << n); ++m1) {
		for (int m2 = 0; m2 < (1 << n); ++m2) {
			if ((m1 & m2) == m2) {
				dp[m1] = min(dp[m1], dp[m2] + dp[m1 ^ m2]);
			}
		}
	}
	cout << (dp[(1 << n) - 1] == inf ? -1 : dp[(1 << n) - 1]);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ACprac
{
    class Program
    {
        static void Main(string[] args)
        {
            string len = Console.ReadLine();
            string[] str = Console.ReadLine().Split(' ');
            int[] istr = new int[str.Length];
            for(int i = 0; i < str.Length; i++)
            {
                istr[i] = int.Parse(str[i]);
            }

            int N = istr.Max() - istr.Min();
            Console.WriteLine(N);
        }
    }
}


Measured memory_bytes: 13268
use std::io;


fn main() {
    let n = read_one::<usize>();
    let num = [111, 222, 333, 444, 555, 666, 777, 888, 999];
    for i in num.iter() {
        if n <= *i { println!("{}", i); break; }
    }
}


#[allow(unused)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}


#[allow(unused)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4476
# atcoder -take a rest-(easy)

def main():
    N, M = map(int, input().split())
    conflict = [tuple(map(int, input().split())) for i in range(M)]
    newest_destroyed = -1
    conflict.sort(key=lambda x: x[1])
    res = 0
    for l, r in conflict:
        if not (l <= newest_destroyed < r):
            res += 1
            newest_destroyed = r-1
    print(res)
    return


if __name__ == "__main__":
    main()




Measured memory_bytes: 91184
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#pragma GCC optimize(2)
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const double eps=1e-5;
const double pi=acos(-1.0);
const int MOD=1e9+7;
const int maxn=1e5+10;
int a[maxn];
int main ()
{
    int n;
    scanf("%d",&n);
    a[0]=1e9;
    int len=0;
    for(int i=1;i<=n;i++)
    {
        int x;
        scanf("%d",&x);
        if(x<=a[len]){
            a[++len]=x;
        }
        else{
            int l=1,r=len,mid=(l+r)>>1;
            while(l<=r)
            {
                mid=(l+r)>>1;
                if(a[mid]<x){
                    r=mid-1;
                }
                else{
                    l=mid+1;
                }
            }
            //cout<<mid<<endl;
            while(a[mid]>=x)
                mid++;
            a[mid]=x;
        }
    }
    printf("%d\n",len);
    return 0;
}

Measured memory_bytes: 4132
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	const Int MOD = 1e9 + 7;
	int N;
	cin >> N;
	vector<Int> a(N);
	for (int i = 0; i < N; ++i) { cin >> a[i]; }

	int n = 60;
	Int ans = 0;
	vector<vector<Int>> cnt(n, vector<Int>(2, 0));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < n; ++j) {
			Int x = (1LL << j) % MOD;
			if ((a[i] >> j) & 1) {
				(ans += (cnt[j][0] * x) % MOD) %= MOD;
				(cnt[j][1] += 1) %= MOD;
			} else {
				(ans += (cnt[j][1] * x) % MOD) %= MOD;
				(cnt[j][0] += 1) %= MOD;
			}
		}
	}
	cout << ans % MOD << endl;

	return 0;
}


Measured memory_bytes: 2560
n,d = map(int, input().split())
xd = [(list(int(_) for _ in input().split())) for i in range(n)]
ans =0
for i in range(n):
  x1 = xd[i]
  for j in range(i+1,n):
    x2 = xd[j]
    dis =0
    for x,y in zip(x1,x2):
      dis += (y-x) **2
    k = dis **0.5

    if int(k)**2 ==dis:
      ans +=1
print(ans)

Measured memory_bytes: 3064
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        String s = sc.next();
        String ans = "Yes";
        for(int i = 0; i < a + b + 1; i++){
            if(i == a) continue;
            else if(s.charAt(i) < '0' || s.charAt(i) > '9') ans = "No";
        }
        if(s.charAt(a) != '-') ans = "No";
        System.out.println(ans);
    }
}

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

using namespace std;

#define MODULO 1000000007

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long long n, m;
	cin >> n >> m;
	auto count = 1ll;
	if (abs(n-m) <= 1)
	{
		for (auto i = 1ll; i <= n; i++) count = (count * i) % MODULO;
		for (auto i = 1ll; i <= m; i++) count = (count * i) % MODULO;
		if (n == m) count = (count * 2) % MODULO;
	}
	else count = 0;
	cout << count << endl;
	return 0;
}


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

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

    for (int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        data[tmp]++;
    }
    int maxCnt = 0;
    for (int i = 1; i < 99999; i++)
    {
        int sum = data[i-1]+data[i]+data[i+1];
        maxCnt = (maxCnt < sum) ? sum : maxCnt;
    }

    cout << maxCnt;
    
    
}

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

int find_best(int comp, const vector<int> & ps, const vector<int> & cs, int G){
    int D = ps.size();
    int rec = 0;
    for (int i = 0; i < D; ++i){
        if (comp & (1 << i)){
            G -= ps[i] * (i + 1) + cs[i];
            rec += ps[i];
        }
    }
    if (G <= 0) return rec;
    for (int i = D - 1; i >= 0; --i){
        if (comp & (1 << i)) continue;
        if (G > ps[i] * (i + 1) + cs[i]){
            return 1000;
        }
        int k = G / (i + 1);
        if (G % (i + 1) > 0) ++k;
        if (k > ps[i]) return ps[i] + rec;
        return rec + k;
    }
    return 1000;
}

int main() {
    int D, G;
    cin >> D >> G;
    vector<int> ps(D);
    vector<int> cs(D);
    for (int i = 0; i < D; ++i) cin >> ps[i] >> cs[i];
    for (auto & c : cs) c /= 100;
    G /= 100;

    int record = 1000;
    for (int comp = 0; comp < (1 << D); ++comp){
        record = min(record, find_best(comp, ps, cs, G));
    }

    cout << record << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n,k;cin>>n>>k;
    ll arr[n+1];
    for(ll i=1;i<=n;i++)
        cin>>arr[i];
    ll vis[n+1];
    vector<ll>v;
    memset(vis,0,sizeof(vis));
    ll i=1;
    if(k<=n)
    {
       while(k>0)
       {
        k--;
        i=arr[i];
       }
       cout<<i<<endl;
       return 0;
    }
    while(1)
    {
        vis[arr[i]]+=1;
        if(vis[arr[i]]==1)
            k--;
        if(vis[arr[i]]==2)
        v.push_back(i);
        else if(vis[arr[i]]==3)
            break;
        i=arr[i];
    }
   // cout<<k<<endl;
    ll x=k%v.size();
    cout<<v[x]<<endl;
   // for(int i=0;i<v.size();i++)
     //   cout<<v[i]<<" ";
}


Measured memory_bytes: 7196
#include "bits/stdc++.h"
#define ll long long
using namespace std;

ll dph[1500 * 1000 + 1];
ll dpw[1500 * 1000 + 1];

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int N, M;
	while (true) {
		cin >> N >> M;
		if (N == 0 && M == 0)break;
		vector<ll> H(N + 1, 0), W(M + 1, 0);

		for (int i = 1; i <= 1500 * 1000;i++) dph[i] = dpw[i] = 0;

		for (int i = 1; i <= N;i++) {
			cin >> H[i];
			H[i] += H[i - 1];

		}
		for (int i = 1;i <= M;i++) {
			cin >> W[i];
			W[i] += W[i - 1];
		}
		ll ans = 0;

		for (int i = 0;i <= N;i++) {
			for (int j = i + 1; j <= N;j++) {
				dph[H[j] - H[i]]++;
			}
		}

		for (int k = 0; k <= M;k++) {
			for (int l = k + 1;l <= M;l++) {
				dpw[W[l] - W[k]]++;
			}
		}

		ll MIN_HW = min(H[N], W[M]);

		for (int i = 1; i <= MIN_HW;i++) {
			//cout << "i = " << i << endl;
			//cout << "dph = " << dph[i] << " dpw = " << dpw[i] << endl;
			ans += dph[i] * dpw[i];
		}

		/* ????¬? TLE
		for (int i = 0;i <= N;i++) {
			for(int j = i + 1; j <= N;j++){

				for (int k = 0; k <= M;k++) {
					for (int l = k + 1;l <= M;l++) {
						if (H[j] - H[i] == W[l] - W[k])ans++;
					}
				}

			}
		}
		*/
		cout << ans << endl;
	}
}

Measured memory_bytes: 26604
#include <stdio.h>
#include <string.h>

int func_idx(int flg,char dt)
{
	if (flg ==0) {
		switch (dt){
		case 'S':
			return 0;
		case 'H':
			return 1;
		case 'C':
			return 2;
		default:
			return 3;
		}
	}
	else {
		switch (dt){
		case 0:
			return (int)'S';
		case 1:
			return (int)'H';
		case 2:
			return (int)'C';
		default:
			return (int)'D';
		}
	}
}

int main()
{
	int n;
	char dt[4][14];
	char wk[512];
    char *p,*wk_p;
	char wk_dt;
	int i,data,idx,k;

	memset(wk,'\0',sizeof(wk));
	memset(dt,'\0',sizeof(dt));
	gets(wk);
	sscanf(wk,"%d",&n);

	for (i=0 ; i<n ; i++) {
		gets(wk);
		p = wk;
		p=strtok(p," ");

		sscanf(p,"%c",&wk_dt);
	    p=strtok(NULL," ");
		if (p==NULL) {
			printf("ERROR\n");
		}
		/*- num */
		sscanf(p,"%d",&data);
		idx=func_idx(0,wk_dt);
		dt[idx][data-1]++;
	}

	for(k=0 ; k<4 ; k++) {
		for(i=0 ; i<13 ; i++) {
			if (dt[k][i]==0) {
				idx=func_idx(1,k);
				printf("%c %d\n",idx,i+1);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
#define int long long
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
#define X first
#define Y second
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)

int gcd(int x,int y){ return (!y ? x : gcd(y, x%y)); }

int32_t main(){
	IOS;
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if(k & 1)
		cout << b - a << endl;
	else
		cout << a - b << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll= long long ;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i<(ll)(n); i++)
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<ll> vcl;

ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t =rep_jijo(n,x/2);
        return t*t%mod;
  }
  return n*rep_jijo(n,x-1)%mod;
}
ll c2(ll n){
    return n*(n-1)/2;
}

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

Measured memory_bytes: 3596
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
#include <array>
#include <set>

const uint32_t D = 365 + 1;
const uint32_t contests = 26 + 1;

int main() {
  {
    uint32_t Dtmp = 0;
    std::cin >> Dtmp;
  }

  std::array<uint32_t, contests> cost;
  for (size_t c = 1; c < contests; c++) std::cin >> cost[c];
  
  std::array<std::array<uint32_t, contests>, D> sat;
  for (size_t d = 1; d < D; d++) for (size_t c = 1; c < contests; c++) std::cin >> sat[d][c];
  
  // solve problem
  std::array<uint32_t, D> test;
  for (size_t d = 1; d < D; d++) std::cin >> test[d];
  // for (size_t d = 1; d < D; d++)
  // {
  //   uint32_t max_val = 0, max_ind = 0;
  //   for (size_t c = 1; c < contests; c++){
  //     if(sat[d][c] > max_val){
  //       max_val = sat[d][c];
  //       max_ind = i;
  //     }
  //   }
  //   test[d] = max_ind + 1;
  // }
  
  // for(size_t d = 1; d < D; d++) std::cout << test[d] << std::endl;

  // calc satisfaction
  std::array<int64_t, D> value;
  value[0] = 0;
  std::array<std::set<uint32_t>, contests> history;
  for (auto &&h : history) h.insert(0), h.insert(D);
  for (size_t d = 1; d < D; d++)
  {
    value[d] = value[d-1] + sat[d][test[d]];
    history[test[d]].insert(d);

    int64_t c_sum = 0;
    for (size_t c = 1; c < contests; c++) c_sum += cost[c]*(d-*std::next(history[c].crbegin()));
    value[d] -= c_sum;
  }

  // query
  int64_t v = value.back();
  uint32_t M = 0;
  std::cin >> M;
  for (size_t m = 0; m < M; m++)
  {
    uint32_t d = 0, c = 0;
    std::cin >> d >> c;

    v += sat[d][c];
    v -= sat[d][test[d]];

    auto it_before = history[test[d]].find(d);
    v -= cost[test[d]]*(d-*std::prev(it_before))*(*std::next(it_before)-d);
    history[test[d]].erase(it_before);

    history[c].insert(d);
    auto it_after = history[c].find(d);
    v += cost[c]*(d-*std::prev(it_after))*(*std::next(it_after)-d);

    test[d] = c;

    std::cout << v << std::endl;
  }
  
  return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    ll S;

    ll m = 1e9;
    cin >> S;
    ll X1 = m;
    ll Y1 = 1;
    ll X2 = (m - (S % m)) % m;
    ll Y2 = (S + X2 * Y1) / m;
    cout << X1 << " " << Y1 << " " << X2 << " " << Y2 << " "
         << "0 0" << endl;
}


Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

#define MOD 1000000007

long long dp[100005];

int main()
{
	long long n;
	cin >> n;
	vector<long long> a(n);
	for(long long i=0;i<n;i++)
		cin >> a[i];
	vector<vector<long long>> col(n,vector<long long>(3,0));
	if(a[0]!=0)
	{
		cout << 0 << endl;
		return 0;
	}
	col[0][0]=1;
	dp[0]=1;
	for(long long i=1;i<n;i++)
	{
		long long cnt=0;
		for(long long j=0;j<3;j++)
		{
			col[i][j]=col[i-1][j];
			if(col[i-1][j]==a[i])
				cnt++;
		}
		for(long long j=0;j<3;j++)
		{
			if(col[i][j]==a[i])
			{
				col[i][j]++;
				break;
			}
		}
			
		dp[i]=dp[i-1]*cnt;
		dp[i]%=MOD;
	}

	cout << dp[n-1]*3%MOD << endl;

}


Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (long long i = (a); i < (n); i++)
#define REP(i, n) for(long long i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
using namespace std;

typedef long long ll;

long long myGcd(long long a, long long b)
{
	if (a % b == 0)return b;
	return myGcd(b, a % b);
}

int myGcd(int a, int b)
{
	if (a % b == 0)return b;
	return myGcd(b, a % b);
}

long long myLcm(long long a, long long b)
{
	return a * b / myGcd(a, b);
}

int myLcm(int a, int b)
{
	return a * b / myGcd(a, b);
}


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

	ll N, M, st, et;
	ll count = 0;
	bool good = true;

	cin >> N >> M;

	vector<vector<ll> > road(N, vector<ll>(1, -1));
	vector<ll> H(N, 0);

	REP(i, N) cin >> H[i];

	REP(i, M)
	{
		cin >> st >> et;
		road[st - 1].pb(et);
		road[et - 1].pb(st);
	}

	REP(i, N)
	{
		good = true;
		ll max_hight = H[i];
		FOR(j, 1, road[i].size())
		{
			ll tmp_hight = H[road[i][j] - 1];

			/*
			cout << "Location: " << i + 1 << " Hight: " << max_hight << endl;
			cout << "Location: " << road[i][j] << " Hight: " << tmp_hight << endl;
			cout << endl;
			*/

			if (max_hight <= tmp_hight)
			{
				good = false;
				break;
			}
		}

		if (good == true)
		{
			count++;
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 11652
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let mut a: Vec<u64> = sc.vec(n);
    let all = a.iter().fold(0, |xor, &a| xor ^ a);
    for i in 0..n {
        a[i] &= !all;
    }

    let mut rank = 0;
    for pos in (0..63).rev() {
        match (rank..n).find(|&i| a[i] & (1 << pos) != 0) {
            Some(x) => {
                a.swap(rank, x);
                for i in 0..n {
                    if i != rank && a[i] & (1 << pos) != 0 {
                        a[i] ^= a[rank];
                    }
                }
                rank += 1;
            }
            None => {}
        }
    }

    let max = a.iter().fold(0, |xor, &a| xor ^ a);
    println!("{}", max * 2 + all);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
#include<numeric>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
#define mkp(a,b) make_pair(a,b)
using namespace std;

inline int mex(unordered_set<int> st)
{
	int m = 0;
	while (st.find(m) != st.end())
	{
		m += 1;
	}
	return m;
}
inline int calculateGrundy(int n)
{
	if (n == 1)
		return 0;
	unordered_set<int> mexi;
	for (int i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			if (n / i != n)
				mexi.insert(calculateGrundy(n / i));
			mexi.insert(calculateGrundy(i));
		}
	}
	return mex(mexi);
}
inline ll gcd(ll a, ll b)
{
	// This is code taken from geeksforgeek
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
ll power(ll x, ll y)
{
	// This is code taken from geeksforgeek
	ll res = 1;

	x = x % N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % N;
		y = y >> 1;
		x = (x * x) % N;
	}
	return res;
}
bool check(ll a)
{
	ll count = 0;
	while (a % 2 == 0)
	{
		a /= 2;
		count += 1;
	}
	if (count > 1)
		return false;
	bool flag = true;
	for (ll i = 3; i <= sqrt(a); i += 2)
	{
		if (a % i == 0)
		{
			flag = false;
			break;
		}
	}
	return flag;
}
ll sum(ll n)
{
	return (n * (n + 1)) / 2;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	vector<ll> arr(5,0);
	f(i,0,5)
	{
		cin>>arr[i];
		if(arr[i]==0)
			cout<<i+1;
	}
	return 0;
}

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

int main(){
  int h, w; cin >> h >> w;
  vector<string> c(h);
  for(int i=0; i<h; ++i) cin >> c[i];
  for(int i=0; i<h; ++i){
    cout << c[i] << endl;
    cout << c[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 
#define PI 3.141592653589793238

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
   vector<vector<long int>> v(3,vector<long int>(3));
   for(long int i = 0; i < 3; i++)
      for(long int j = 0; j < 3; j++)
          cin>>v[i][j];

   long int m;
   cin>>m;

   set<long int> s;

   for(long int i = 0; i < m; i++){
     long int x;
     cin>>x;
     s.insert(x);
   }

   for(long int i = 0; i < 3; i++){
    for(long int j = 0; j < 3; j++){
      if(s.find(v[i][j]) != s.end()){
        v[i][j] = -1;
      }
    }
   }

   for(long int i = 0; i < 3; i++){
      bool done = true;

      for(long int j = 0; j < 3; j++){
        if(v[i][j] != -1){
          done = false;
          break;
        }
      }

      if(done)
        return cout<<"Yes",0;
   }



   for(long int i = 0; i < 3; i++){
      bool done = true;

      for(long int j = 0; j < 3; j++){
        if(v[j][i] != -1){
          done = false;
          break;
        }
      }

      if(done)
        return cout<<"Yes",0;
   }

   bool done = true;
   for(long int i = 0; i < 3; i++){
      if(v[i][i] != -1){
        done = false;
        break;
      }
   }

   if(done)
    return cout<<"Yes",0;

  done = true;
   for(long int i = 0; i < 3; i++){
    if(v[i][2 - i] != -1){
      done = false;
      break;
    }
   }

   if(done)
    cout<<"Yes";
  else
    cout<<"No";


   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;


const ll MOD = 1e9+7;
 
template <ll MOD>
struct modint{
    ll x;
    modint() : x(0) {}
    modint(ll a): x((a % MOD + MOD) % MOD) {}
    
    
 
    bool operator!() const{return !x;}
 
    bool operator<(const modint &a) const{
        modint res(*this);
        return res.x < a.x;
    }
    
    bool operator>(const modint &a) const{
        modint res(*this);
        return res.x > a.x;
    }
 
    modint &operator+=(const modint &a){
        if((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator-=(const modint &a){
        if((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
 
    modint &operator*=(const modint &a){
        (x *= a.x) %= MOD;
        return *this;
    }
 
    modint &operator/=(const modint &a){
        *this *= a.inv();
        return *this;
    }
 
    modint &operator%=(const modint &a){
        x %= a.x;
        return *this;
    }
 
    modint operator-() const{ return modint(-x); }
 
    modint operator+(const modint &a) const{ return modint(*this) += a; }
    modint operator-(const modint &a) const{ return modint(*this) -= a; }
    modint operator*(const modint &a) const{ return modint(*this) *= a; }
    modint operator/(const modint &a) const{ return modint(*this) /= a; }
    modint operator%(const modint &a) const{ return modint(*this) %= a; }
    bool operator==(const modint &a) const{ return x == a.x; }
    bool operator!=(const modint &a) const{ return x != a.x; }
 
 
    modint pow(ll n) const{
        modint res(1), a(x);
        while(n > 0){
            if(n & 1) res *= a;
            a *= a;
            n /= 2;
        }
        return res;
    }
 
    modint inv() const{
        return this->pow(MOD-2);
    }
 
    friend ostream &operator<<(ostream &os, const modint &m){
        return os << m.x;
    }
 
    friend istream &operator>>(istream &is, modint &m){
        ll t;
        is >> t;
        m = modint<MOD>(t);
        return (is);
    }
    
    static ll get_mod(){ return MOD; }
};
using mint = modint<MOD>;


int main(){
    ll x,y;
    cin >> x >> y;
    if((x+y) % 3) cout << 0 << endl;
    else{
        ll a = (x+y)/3;
        ll b = max((2*x-y)/3,(2*y-x)/3);
        mint fact[max(a,b)+1];
        fact[0] = 1; fact[1] = 1;
        ll temp = 2;
        while(temp <= max(a,b)){
            fact[temp] = fact[temp-1]*temp;
            temp++;
        }
        if(a-b >= 0) cout << fact[a]*fact[b].inv()*fact[a-b].inv() << endl;
        else cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 5504
N=int(input())
S=input()

def z_algo(S):
    N = len(S)
    A = [0]*N
    i = 1; j = 0
    A[0] = l = len(S)
    while i < l:
        while i+j < l and S[j] == S[i+j]:
            j += 1
        if not j:
            i += 1
            continue
        A[i] = j
        k = 1
        while l-i > k < j - A[k]:
            A[i+k] = A[k]
            k += 1
        i += k; j -= k
    return A

s=[[0]*N for i in range(N)]
k=0
for k in range(N):
  s[k]= [0]*k + z_algo(S[k:])

ans=0
for i in range(N):
  for j in range(i+1,N):
    if s[i][j]+i > j:
      ans = max(ans,j - i)
    else:
      ans=max(s[i][j],ans)
    
print(ans)
      
 
 

Measured memory_bytes: 378888
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const double PI=3.14159265358979323846;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

int main()
{
	ll n;
	ll min_v =  10000000;
	ll max_v = -10000000;
	ll sum = 0;

	cin >> n;
	REP(i, n){
		ll v;
		cin >> v;

		min_v = min(v, min_v);
		max_v = max(v, max_v);
		sum += v;
	}

	printf("%lld %lld %lld\n", min_v, max_v, sum);

	return 0;
}




Measured memory_bytes: 3224
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll p[11];
    cin >> N;
    rep(i,0,N) cin >> p[i];
    sort(p, p+N,greater<ll>());
    ll ans = 0;
    ans += p[0]/2;
    rep(i,1,N) ans += p[i];
    print(ans);
    

}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<algorithm>
using namespace std;
typedef pair<int, int> P;
#define F first
#define S second
P p[3010];
bool m[5010][5010];
int main(void){
  int n;
  int dx, dy, ans = 0;
  for( ; ; ans = 0){
    scanf("%d", &n);
    if(!n) break;
    memset(m, false, sizeof(m));
    for(int i = 0;i < n; i++){
      scanf("%d %d", &p[i].F, &p[i].S);
      m[p[i].F][p[i].S] = true;
    }
    for(int i = 0;i < n; i++){
      for(int j = 0;j < n; j++){
	if(i == j) continue;
	dx = p[i].F - p[j].F; dy = p[i].S - p[j].S;
	if(p[i].F + dy <= 5000 && p[i].F + dy >= 0 && p[i].S - dx <= 5000 && p[i].S - dx >= 0 && m[p[i].F + dy][p[i].S - dx])
	  if(p[j].F + dy <= 5000 && p[j].F + dy >= 0 && p[j].S - dx <= 5000 && p[j].S - dx >= 0 && m[p[j].F + dy][p[j].S - dx])
	    ans = max(ans, dx * dx + dy * dy);
      }
    }
    printf("%d\n", ans);
  }
}


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

int main() {
    int n, k, a;
    cin >> n >> k;
    vector<int> b(n+1,0);
    for (int i = 0; i < n; i++) {
        cin >> a;
        b[a]++;
    }
    sort (b.begin(), b.end());
    b.erase (b.begin(), upper_bound(b.begin(), b.end(),0));
    reverse (b.begin(), b.end());
    ll ans = 0;
    for (int i = k; i < b.size(); i++) ans += b[i];
    cout << ans << endl;
}

Measured memory_bytes: 4036
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
long long n,ans; 
int s;
int main()
{
    cin>>n;
    for(int i=sqrt(n);i>0;i--) 
    {
    	if(n%i==0)
		{
			ans=n/i;
            break;
		}
	}               
    while(ans>0)
	{
        s++;
        ans=ans/10;
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 256
import math

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

A,B = map(int,input().split())
a = prime_factorize(A)
b = prime_factorize(B)
ans = 1

while a != []:
    x = a[0]
    if x in b:
        ans+=1
    a = [i for i in a if i != x]

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  int N;
  cin>>N;
  
  vector<int> x(N);
  rep(i,N){
    cin>>x[i];
  }
  
  int ans=10000000;
  
  for(int i=1;i<=100;++i){
    int c=0;
    for(int j=0;j<N;++j){
      c+=(i-x[j])*(i-x[j]);
    }
    ans=min(ans,c);
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
/**
 *		author:  zvm
 *		created: 28.09.2020 10:18:12
**/

#include <bits/stdc++.h>

using namespace std ;

const int mxN = 16001 ;

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

	string s ;
	cin >> s ;
	
	int x, y ;
	cin >> x >> y ;

	int n = s.size();
	vector<vector<int>> move(2);

	int dir = 0, steps = 0 ;
	for( int i = 0 ; i < n ; ++i ) {
		if( s[i] == 'T' ) {
			move[dir].push_back(steps);
			steps = 0 ;
			dir ^= 1 ;
		}
		else {
			steps++ ;
		}
	}
	move[dir].push_back(steps);

	int N = move[0].size();
	int M = move[1].size();
	
	bitset<mxN> dpx[N+1] ;
	bitset<mxN> dpy[M+1] ;

	dpx[0][n] = dpx[1][n+move[0][0]] = true ;
	dpy[0][n] = true ;

	for( int i = 2 ; i <= N ; ++i ) {
		dpx[i] |= (dpx[i-1]<<move[0][i-1]) | (dpx[i-1]>>move[0][i-1]) ;
	}
	for( int i = 1 ; i <= M ; ++i ) {
		dpy[i] |= (dpy[i-1]<<move[1][i-1]) | (dpy[i-1]>>move[1][i-1]) ;
	}

	cout << ( dpx[N][n+x] && dpy[M][n+y] ? "Yes" : "No" ) << endl ;
}


Measured memory_bytes: 19200