akhauriyash/Code-Regression huggingface dataset:
/*
memo
????????°??????

*/

#include<iostream>
#include<cstring>
#include<vector>
using namespace std;

int m, n;
int ma[300];
int ka[300][300];
vector<int> g[300];
bool go[300], ba[300];
void iki(int x)
{
	//????????§????????¨????????????????????????

	//????????????????????´??????????????????????????°?????¨??????
	//????????´??????????????°???????????????
	//???????????????????????§??????????????¶???????????????????????????????????£???
	//??????????????°????????????????????°????????????????????°?????¨???????????????????????????
	//?????????????????????????????°?????¨??°?????°????????´???????¨???????????????????
	//????????????????????´???????????£???????????´???????????????????????????????????????
	//??´?????????????????????????????´??????????§???????????????????????????????????????´????????????????????¨??????????????°????????????????????????????????????

	int i;

	if (go[x]) return;
	go[x] = true;				//????????°??????
	if (x == n + 1) return;
	for (i = 1; i <= m; i++)
	{
		int y = x + i;
		if (y <= n+1)
		{
			y = y + ma[y];
			if (y>0)
			{
				if (y > n + 1) y = n + 1;
				if (ka[y][x] == 1)continue;
				ka[y][x] = 1;

				g[y].push_back(x);
				iki(y);
			}
		}

	}
	return;
}

void kae(int x)
{
	//????????§?????°?????¨????????´???????????????????????????????????¨???????????????????????????

	//????????????????????´?????????????§??????¨??????????????????????????°????????????????????§???????????´?????????????????????
	//??????????????§?????£?????´??????????????¨?????????????????°???????????????


	int i;
	if (ba[x]) return;
	ba[x] = true;
	if (x == 0) return;
	for (i = 0; i<g[x].size(); i++)
	{
		kae(g[x][i]);
	}
	return;
}

int main()
{
	int i;
	while (cin >> m, m)
	{
		cin >> n;

		//---------------?????????--------------------//
		for (i = 0; i<300; i++)
		{
			g[i].clear();
			ma[i] = 0;
			for (int j = 0; j<300; j++)
			{
				ka[i][j] = 0;
			}
		}
		memset(go, 0, sizeof(go));
		memset(ba, 0, sizeof(ba));


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

		iki(0);
		kae(n + 1);


		/*
		for (i = 0; i <= n + 1; i++)
		{
			cout << "  " << go[i] << "  " ;
		}
		cout << endl;
		for (i = 0; i <= n + 1; i++)
		{
			cout << "  " << ba[i] << "  ";
		}
		*/



		for (i = 0; i <= n + 1; i++)
		{
			if (go[i])
			{
				if (ba[i] == 0)
				{
					cout << "NG\n";
					break;
				}
			}
			if (i == n + 1) cout << "OK\n";
		}
	}
	return 0;
}

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

def div2(a):
  if a%2 ==1:
    return 0
  if (a//2)%2==1:
    return 1
  else:
    return 2

_A = [div2(a) for a in A]

if _A.count(1):
  if _A.count(0) <= _A.count(2):
    print('Yes')
  else:
    print('No')
else:
  if _A.count(0) <= _A.count(2) +1:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 14252
sx, sy, tx, ty = map(int,input().split())
S = ''
S += (tx-sx)*'R'
S += (ty-sy)*'U'
S += (tx-sx)*'L'
S += (ty-sy)*'D'
S += 'D'
S += (tx-sx+1)*'R'
S += (ty-sy+1)*'U'
S += 'L'
S += 'U'
S += (tx-sx+1)*'L'
S += (ty-sy+1)*'D'
S += 'R'
print(S)

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

class Program
{
    static void Main(string[] args)
    {
        var S = sc.ReadStr();
        var c = S.IndexOf('C');
        var f = S.LastIndexOf('F');
        var ok = c != -1 && f != -1 && c < f;
        Console.WriteLine(ok ? "Yes" : "No");
    }

    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


Measured memory_bytes: 13140
N = int(input())
h = [int(i) for i in input().split()]
dp = [0]*(N)
dp[1] = abs(h[0] - h[1])
for i in range(0,N-2):
    dp[i+2] = min(dp[i]+abs(h[i] - h[i+2]), dp[i+1]+abs(h[i+1] - h[i+2]))
print(dp[-1])

Measured memory_bytes: 13928
x1, y1, x2, y2 = map(int, input().split())
v1 = [x1, y1]
v2 = [x2, y2]
v12 = [v2[0]-v1[0], v2[1]-v1[1]]

def rot(v):
	return [v[1]*(-1), v[0]]

v3 = [v2[0]+rot(v12)[0], v2[1]+rot(v12)[1]]
v23 = [v3[0]-v2[0], v3[1]-v2[1]]
v4 = [v3[0]+rot(v23)[0], v3[1]+rot(v23)[1]]

print(v3[0], v3[1], v4[0], v4[1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,w[100];
	cin>>n;
	for(int i=0;i<n;i++)
	cin>>w[i];
	int ans=30000;
	for(int i=0;i<n;i++)
	{
		int s1=0;
		for(int j=0;j<=i;j++)
		{
			s1+=w[j];
		}
		int s2=0;
		for(int j=i+1;j<n;j++)
		s2+=w[j];
		ans=min(ans,abs(s2-s1));
	}
	cout<<ans;
	return 0;
}

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

int main() {
    vector<int> num{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << num[k - 1] << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;
  double sum=0;
  for(int i=0;i<N;i++){
    double x;
    cin >> x;
    string str;
    cin >> str;
    if(str=="JPY"){
      sum+=x;
    }else{
      sum+=x*380000.0;
    }
  }

  printf("%.5lf\n",sum);
}


Measured memory_bytes: 256
n=int(input())
k=[[] for _ in range(n)]
for i in range(n-1):
  a,b,c=map(int,input().split())
  k[a-1].append([b-1,c])
  k[b-1].append([a-1,c])
s=[0]*n
from collections import deque
d=deque()
d.append(0)
v=[False]*n
v[0]=True
while d:
  g=d.popleft()
  for i in k[g]:
    if v[i[0]]:
      continue
    d.append(i[0])
    v[i[0]]=True
    if i[1]%2==0:
      s[i[0]]=s[g]
    else:
      s[i[0]]=[1,0][s[g]]
for i in s:
  print(i)

Measured memory_bytes: 84128
using System;
using System.Collections.Generic;
class At_CF
{
    static void Main(string[] args)
    {
        K_Cakes();
    }

    //Q.1
    static public void CF()
    {
        String answer = System.Text.RegularExpressions.Regex.IsMatch(Console.ReadLine(), "C.*F", System.Text.RegularExpressions.RegexOptions.IgnoreCase) ? "Yes" : "No";
        Console.Write(answer);
    }

    //Q.2
    static public void K_Cakes()
    {
        String[] a = Console.ReadLine().Split(' ');
        int[] b = Array.ConvertAll(Console.ReadLine().Split(' '),new Converter<String,int>( s => int.Parse(s) ));

        int cake = int.Parse(a[0]);
        int cakeType = int.Parse(a[1]);
        
        List<int> cakeList = new List<int>();
        cakeList.AddRange(b);

        while (cakeList.Count > 1)
        {
            cakeList.Sort();
            cakeList.Reverse();

            cakeList[0] -= 1;
            cakeList[1] -= 1;

            cakeList.RemoveAll(s => s <= 0);
        }

        int answer;
        if (cakeList.Count > 0)
        {
            answer = cakeList[0] > 1 ? cakeList[0]-1 : 0;
        }
        else
        {
            answer = 0;
        }

        Console.WriteLine(answer);



    }
}



Measured memory_bytes: 2776
import sys

input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def gcd(a, b):
    if a < b:
        d, (p, q) = gcd(b, a)
        return d, (q, p)
    if b == 0:
        return a, (1, 0)
    d, (q, p) = gcd(b, a % b)
    q -= a // b * p
    return d, (p, q)


def ch(x, y):
    a1, m1 = x
    a2, m2 = y
    d, (p, q) = gcd(m1, m2)
    if (a2 - a1) % d != 0:
        return (0, -1)

    m = m1 * m2 // d
    r = (a1 + m1 * (a2 - a1) // d * p) % m
    return (r, m)


def main():
    N, M = read_values()
    A = read_list()
    p = (0, 1)
    for a in A:
        p = ch((a // 2, a), p)
        if p[1] == -1:
            print(0)
            return
    print((M - p[0]) // p[1] + 1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 14244
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a[5];
    cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
    sort(a,a+5);
    int b[5];
    for(int i=0;i<5;i++){
       b[4-i]=a[i];
    }
    cout<<b[0]<<" "<<b[1]<<" "<<b[2]<<" "<<b[3]<<" "<<b[4]<<endl;
}


Measured memory_bytes: 3112
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#define mod 1000000007
using namespace std;
typedef long long ll;

ll rev(ll a) {
  ll now = mod - 2, ans = 1;
  while(now) {
    if(now & 1) ans *= a;
    now >>= 1, ans %= mod, a *= a, a %= mod;
  }
  return ans;
}

int main(void) {
  ll i, j, k, n, a, b, now, ans;
  scanf("%lld", &n);
  vector<ll> vec[n];
  for(i = 0; i < n - 1; ++i) {
    scanf("%lld%lld", &a, &b);
    vec[--a].push_back(--b);
    vec[b].push_back(a);
  }
  ll fact[n + 1], dp1[n], dp2[n], c1[n], c2[n], p[n];
  for(i = 0; i < n; ++i) p[i] = -1, c1[i] = c2[i] = 0;
  p[0] = 0;
  fact[0] = 1;
  for(i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i, fact[i] %= mod;
  stack<ll> s;
  queue<ll> q;
  q.push(0);
  while(q.size()) {
    now = q.front(), q.pop();
    s.push(now);
    for(i = 0; i < vec[now].size(); ++i) if(p[vec[now][i]] == -1) p[vec[now][i]] = now, q.push(vec[now][i]);
  }
  while(s.size()) {
    now = s.top(), s.pop();
    dp1[now] = 1;
    for(i = 0; i < vec[now].size(); ++i) if(vec[now][i] != p[now]) {
      c1[now] += c1[vec[now][i]] + 1;
      dp1[now] *= rev(fact[c1[vec[now][i]] + 1]);
      dp1[now] %= mod;
      dp1[now] *= dp1[vec[now][i]];
      dp1[now] %= mod;
    }
    dp1[now] *= fact[c1[now]];
    dp1[now] %= mod;
  }
  q.push(0);
  while(q.size()) {
    now = q.front(), q.pop();
    for(i = 0; i < vec[now].size(); ++i) if(vec[now][i] != p[now]) q.push(vec[now][i]);
    dp2[now] = 1;
    if(now) {
      c2[now] = n - c1[now] - 2;
      dp2[now] *= rev(fact[c2[p[now]]]);
      dp2[now] %= mod;
      dp2[now] *= dp2[p[now]];
      dp2[now] %= mod;
      dp2[now] *= dp1[p[now]];
      dp2[now] %= mod;
      dp2[now] *= rev(dp1[now]);
      dp2[now] %= mod;
      dp2[now] *= rev(fact[c1[p[now]]]);
      dp2[now] %= mod;
      dp2[now] *= fact[c1[now] + 1];
      dp2[now] %= mod;
      dp2[now] *= fact[c2[now]];
      dp2[now] %= mod;
      c2[now]++;
    }
  }
  for(i = 0; i < n; ++i) {
    ans = dp1[i] * dp2[i];
    ans %= mod;
    ans *= fact[n - 1];
    ans %= mod;
    ans *= rev(fact[c1[i]]);
    ans %= mod;
    ans *= rev(fact[c2[i]]);
    ans %= mod;
    printf("%lld\n", ans);
  }
  return 0;
}

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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

typedef long long ll;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
	int x(0), sgn(1); char ch(getchar());
	for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
	for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
	return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("E.in", "r", stdin);
	freopen ("E.out", "w", stdout);
#endif
}

const int N = 2e5 + 1e3;

int n; ll sum[N], k; vector<ll> S;

using namespace __gnu_pbds;

typedef pair<ll, int> PLI;

tree<PLI, null_type, less<PLI>, rb_tree_tag, tree_order_statistics_node_update> T;

int main () {

	File();

	n = read(); k = read();

	ll ans = 0; T.insert(make_pair(0, 0));

	For (i, 1, n) {
		sum[i] = sum[i - 1] + read();
		T.insert(make_pair(sum[i] - k * i, i));
		ans += T.order_of_key(make_pair(sum[i] - k * i, i));
	}

	printf ("%lld\n", ans);

    return 0;

}

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

#define int long long int
#define double long double
#define pb push_back
#define fi first
#define se second
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define pq priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) int a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define prdec(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define mii map<int,int>
#define all(v) v.begin(),v.end()
#define inf LLONG_MAX


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

	int n,i,j,k,ans=0;
	cin>>n;
	inp(a,n,0);
	for(i=0;i<n;i++)
		for(j=i+1;j<n;j++)
			for(k=j+1;k<n;k++)
				if(a[i]!=a[k]&&a[j]!=a[k]&&a[i]!=a[j]&&a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[j]+a[k]>a[i])
					ans++;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        int N = 3;
        var C = new int[N][];
        for (int i = 0; i < N; i++)
        {
            C[i] = cin.scanint;
        }

        for (int a1 = 0; a1 <= C[0][0]; a1++)
        {
            var A = Enumerable.Repeat(-1, N).ToArray();
            var B = Enumerable.Repeat(-1, N).ToArray();

            A[0] = a1;
            bool flag = true;
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    if (A[i] >= 0 && B[j] >= 0)
                    {
                        if (A[i] + B[j] != C[i][j])
                        {
                            flag = false;
                        }
                    }
                    else if(A[i] >= 0)
                    {
                        B[j] = C[i][j] - A[i];
                        if (B[j] < 0) flag = false;
                    }
                    else if (B[j] >= 0)
                    {
                        A[i] = C[i][j] - B[j];
                        if (A[i] < 0) flag = false;
                    }
                }
            }
            if (flag)
            {
                WriteLine("Yes");
                return;
            }
        }
        WriteLine("No");
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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


int main(){
ios::sync_with_stdio(0);
cin.tie(0);
    int k;cin>>k;
    int a,b;cin>>a>>b;
    if(a%k==0||b%k==0)cout<<"OK";
    else {
        if(b/k-a/k>0)cout<<"OK";
        else cout<<"NG";
    }
 
return 0;
}

Measured memory_bytes: 3656
import math
a,b,h,m = map(int,input().split())
ans = math.sqrt((a*math.cos((math.pi/6)*(h+m/60))-b*math.cos(2*math.pi*(h+m/60)))**2+(a*math.sin((math.pi/6)*(h+m/60))-b*math.sin(2*math.pi*(h+m/60)))**2)
print(ans)

Measured memory_bytes: 9516
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007

int main() {
    int A, P;
    cin >> A >> P;
    cout << (A * 3 + P) / 2 << endl;
}



Measured memory_bytes: 256
<?php
$s = fgets(STDIN);

$rrr = '/RRR/';
$rrs = '/RRS/';
$srr = '/SRR/';
$r = '/R/';
$sss = '/SSS/';

if (preg_match($rrr, $s)) {
    echo 3;
} elseif (preg_match($rrs, $s) || preg_match($srr, $s)) {
    echo 2;
} elseif (preg_match($r, $s)) {
    echo 1;
} elseif (preg_match($sss, $s)) {
    echo 0;
}


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

int main(){
	int n, t, a, h;
	cin >> n >> t >>a;
	float mindiff = 1e9;
	float temperature;
	int index=0;
	for (int i = 0; i < n; i++){
		cin >> h;
		temperature = (float)t - h*0.006;
		if (abs(temperature - (float) a) < mindiff){
			mindiff = abs(temperature - (float)a);
			index = i+1;
		}
	}
	cout << index;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	string s,t="";cin>>s;
	reverse(s.begin(),s.end());

	int n=s.size();
	vector<string> vec={"maerd","remaerd","esare","resare"};

	rep(i,n){
		rep(j,4){
			if(vec[j]==s.substr(i,vec[j].size())){
				t+=vec[j];
				i+=vec[j].size()-1;
			}
		}
	}
	//cout<<t<<" "<<s<<"\n";
	if(s==t) cout<<"YES"<<"\n";
	else cout<<"NO"<<"\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N,D;
  cin >> N >> D;
  
  vector<vector<int>> x(N, vector<int>(D));
  for(int i= 0; i<N;i++){
    for(int j = 0;j<D;j++){
      cin >> x.at(i).at(j);
    }
  }
  int ans = 0;
  for(int i = 0;i<N;i++){
    for(int j = i+1;j<N;j++){
      int diff = 0;
      int Y = 0;
      for(int k = 0; k<D;k++){
        diff = x.at(i).at(k) - x.at(j).at(k);
      Y += diff*diff;
      }
      for(int K = 1; K<=Y;K++){
        bool flag = false;
        if( K*K == Y ){
          ans++;
          flag = true;
        }
        if(flag) break;
      }
      
    }
  }
  cout << ans << endl;
}
      
      
        

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

typedef long long ll;

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,l,n) for(int i=(l);i<(n);i++)

template<class T>
using vi = vector<T>;
template<class T>
using vvi = vector<vector<T>>;

int main(){
    int N;
    cin >> N;
    cout << N*800-N/15*200 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)

{  

    int a,b,c,i,x;  

    x=0;  

    scanf("%d %d %d",&a,&b,&c);  

	for(i=a;i<=b;i++){
		if(c%i==0){
			x++;
		}
	}
    printf("%d\n",x);  

    return 0;

}

Measured memory_bytes: 596
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize);
    let ret = match n % 10 {
        2 | 4 | 5 | 7 | 9 => "hon",
        0 | 1 | 6 | 8 => "pon",
        3 => "bon",
        _ => unreachable!(),
    };
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


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

#define ll long long

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

void solve() {
  int a,b; cin >> a >> b;
  if(a==1) a=14;
  if(b==1) b=14;
  if(a==b) drop("Draw");
  cout << (a>b?"Alice":"Bob") << endl;

  return;
}

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

  return 0;
}


Measured memory_bytes: 3608
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
  Scanner sc;

  int h, w, c;

  int[][] field;

  int dfs(int depth) {
    if ( depth == 4 ) {
      fill( depth, c );
      return fill( depth + 1, 7 );
    }

    int max = 0;
    for ( int r = 1; r <= 6; ++r ) {
      fill( depth, r );
//      debug( depth );
//      for ( int[] a : field ) {
//        for ( int v : a ) {
//          System.err.print( ( ( v >> ( depth * 3 ) ) & 7 ) );
//          System.err.print( ":" + ( ( v >> ( ( depth + 1 ) * 3 ) ) & 7 ) + " " );
//        }
//        System.err.println();
//      }
      max = Math.max( max, dfs( depth + 1 ) );
    }
    return max;
  }

  int[][] ofs = new int[][] { { 0, 1 }, { 1, 0 }, { -1, 0 }, { 0, -1 } };

  int fill(int depth, int color) {
    int cnt = 0;
    Queue<Integer> qx = new LinkedList<Integer>();
    Queue<Integer> qy = new LinkedList<Integer>();
    qx.add( 0 );
    qy.add( 0 );
    boolean[][] done = new boolean[h][w];
    boolean[][] ok = new boolean[h + 2][w + 2];
    for ( int i = 1; i <= h; ++i ) {
      for ( int j = 1; j <= w; ++j ) {
        ok[ i ][ j ] = true;
      }
    }
    int atom = ( field[ 0 ][ 0 ] >> ( depth * 3 ) ) & 7;
    int mask = ~( 7 << ( ( depth + 1 ) * 3 ) );
    for ( int i = 0; i < h; ++i ) {
      for ( int j = 0; j < w; ++j ) {
        field[ i ][ j ] &= mask;
        field[ i ][ j ] |= ( ( field[ i ][ j ] >> ( depth * 3 ) ) & 7 ) << ( ( depth + 1 ) * 3 );
      }
    }
    field[ 0 ][ 0 ] &= mask;
    field[ 0 ][ 0 ] |= color << ( ( depth + 1 ) * 3 );
    done[ 0 ][ 0 ] = true;
    ++cnt;
    while (qx.size() > 0) {
      int x = qx.poll();
      int y = qy.poll();

      for ( int[] d : ofs ) {
        int nx = x + d[ 0 ];
        int ny = y + d[ 1 ];
        if ( ok[ ny + 1 ][ nx + 1 ] && !done[ ny ][ nx ]
            && ( ( field[ ny ][ nx ] >> ( depth * 3 ) ) & 7 ) == atom ) {
          done[ ny ][ nx ] = true;
          field[ ny ][ nx ] &= mask;
          field[ ny ][ nx ] |= color << ( ( depth + 1 ) * 3 );
          qx.add( nx );
          qy.add( ny );
          ++cnt;
        }
      }
    }

    return cnt;
  }

  void run() {
    for ( ;; ) {
      h = ni();
      w = ni();
      c = ni();
      if ( ( h | w | c ) == 0 ) {
        break;
      }

      field = new int[h][w];
      for ( int i = 0; i < h; ++i ) {
        for ( int j = 0; j < w; ++j ) {
          field[ i ][ j ] = ni();
        }
      }

      System.out.println( dfs( 0 ) );
    }
  }

  Main() {
    sc = new Scanner( System.in );
  }

  int ni() {
    return sc.nextInt();
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void debug(Object... os) {
    System.err.println( Arrays.deepToString( os ) );
  }
}

Measured memory_bytes: 288352
n = int(raw_input())
A = map(int, raw_input().strip().split(' '))
q = int(raw_input())
M = map(int, raw_input().strip().split(' '))


S = [0]*len(A)
flags = [False]*len(M)
def brute_force(n):
    if n == len(S):
        ans = 0
        for i in range(len(S)):
            if S[i] == 1: ans += A[i]
        for i in range(len(M)):
            if ans == M[i]: flags[i] = True
    else:
        S[n] = 0
        brute_force(n+1)
        S[n] = 1
        brute_force(n+1)


brute_force(0)

for flag in flags:
    if flag: print "yes"
    else: print "no"

Measured memory_bytes: 6480
n = int(input())

hitPoint = list(map(int, input().split()))

hitPoint.sort()

while not len(hitPoint) <= 1:
	a = hitPoint.pop(0)
	hitPoint = [ elem % a for elem in hitPoint if not elem % a == 0]
	hitPoint.append(a)
	hitPoint.sort()

print(hitPoint[0])



Measured memory_bytes: 14252
/*==============================================*\
ID:          shahidul_brur

Name:     Md. Shahidul Islam
Study:      CSE, BRUR
Address:  Rangpur, Bangladesh

 mail: shahidul.cse.brur@gmail.com
 FB  : fb.com/shahidul.brur
 Blog: shahidul-brur.blogspot.com(in Bengali),
       shahidul-brur-en.blogspot.com(in English)
\*===============================================*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define all(a)  a.begin(), a.end()
#define mem(a, b)     memset(a, b, sizeof(a))
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};

const double pi = acos(-1.0);
const double eps = 1e-6;
const int mod = (int)1e9+7;
const int maxn = 300005;
const int logn = 20;
bool vis[maxn];
vi g[maxn];
int s;
void dfs(int u)
{
    if(vis[u]) return;
    vis[u] = 1;
    ++s;
    for(int v:g[u]) if(!vis[v]) dfs(v);
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
//    freopen("in_a.txt", "r", stdin);
//    freopen("out_a.txt", "w", stdout);
    int n, m; cin>>n>>m;
    f0(i,m)
    {
        int x, y; cin>>x>>y;
        g[x].pb(y);
        g[y].pb(x);
    }
    int cnt = 0;
    f0(i,n) if(!vis[i]) {
        s = 0;
        dfs(i);
        cnt = max(cnt, s);
    }
    cout << cnt << "\n";
    return 0;
}


Measured memory_bytes: 23244
#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;
}

int main() {
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll t=0;
    ll k=0;
   while(a>0 ){
      a=a-d;
      t++;}
  while(c>0){
   c=c-b;
   k++;}
if(k<=t)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  }


Measured memory_bytes: 3560
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    N, X = list(map(int,readline().split()))
    L = map(int,readline().split())
    sum = 0
    cnt = 1
    for l in L:
        sum += l
        if sum <= X:
            cnt += 1
    print(cnt)

    return

if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
#include <cstdio>

using namespace std;

int n,s,ans = 0;

void dfs(int nau,int sum,int last){
	if(nau == n){
		if(sum == s) ans++;
		return;
	}
	
	for(int i = last+1;i <= 9;i++){
		if(sum + i <= s){
			dfs(nau+1,sum+i,i);
		}
	}
	
	return;
}	
		

int main(){
	

	while(1){
	
		scanf("%d%d",&n,&s);
		if(n == 0 && s == 0) break;
		ans = 0;
		dfs(0,0,-1);
		printf("%d\n",ans);
		
	}
	
	return 0;
	
}


Measured memory_bytes: 1028
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>
#include <complex>
 
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
 
const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef complex<double> P;
int n;
 
double cross(P p1,P p2) {
    return (real(p1)*imag(p2) - imag(p1)*real(p2));
}
double calc_S(P p1,P p2,P p3) {
    double ret = 0.0;
    p1 -= p3;
    p2 -= p3;
 
    ret = cross(p1,p2)/2.0;
     
    return abs(ret);
}
 
int main() {
    cin>>n;
    while(n-->0) {
        double x1_,y1_;
        double x2_,y2_;
        double x3_,y3_;
        cin>>x1_>>y1_>>x2_>>y2_>>x3_>>y3_;
        P p1(x1_,y1_);
        P p2(x2_,y2_);
        P p3(x3_,y3_);
        P A = p1-p2;
        P B = p2-p3;
        P C = p1-p3;
        double S = calc_S(p1,p2,p3);
        double R = abs(A)*abs(B)*abs(C)/S;
        R /= 4.0;
         
        P A1 = 2.0*(p2-p1);
        P B1 = 2.0*(p3-p1);
        P C1 = P(norm(p1)-norm(p2),norm(p1)-norm(p3));
        double X = cross(P(imag(A1),imag(B1)),C1)/cross(A1,B1);
        double Y = cross(C1,P(real(A1),real(B1)))/cross(A1,B1);
        printf("%.3lf %.3lf %.3lf\n",X,Y,R);
 
    }
    return 0;
}

Measured memory_bytes: 1252
N=int(input())
K=int(input())

#A+B=N
#A:C[i]*2 
#B:C[i]+K
  
C=1
for i in range(N):
  if C*2>C+K:
    C=C+K
  else:
    C=C*2
    
print(C)
  



Measured memory_bytes: 9160
#include<iostream>
#include<algorithm>
#include<vector>
#include<iterator>
#include<cmath>
using namespace std;

int main()
{
    int temp, N;
    cin>>N;
    temp = N%10;
    if(temp==3)
    {
        cout<<"bon"<<endl;
    }
    else if(temp==0 || temp==1|| temp==6|| temp==8)
    {
        cout<<"pon"<<endl;
    }
    else
    {
        cout<<"hon"<<endl;
    }
}

Measured memory_bytes: 3612
N = int(input())
S = []
for _ in range(N):
    S.append(input())


count = 0
hashset = {}

for i in range(len(S)):
    key = ''.join(sorted(S[i]))
    if key in hashset:
        count += hashset[key]
        hashset[key] += 1
    else:
        hashset[key] = 1

print(count)

Measured memory_bytes: 24976
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  set<int>s;
  cin>>a>>b;
  s.insert(a);
  s.insert(b);
  if(s.count(1)==0)
    cout<<"1"<<endl;
  else if(s.count(2)==0)
    cout<<"2"<<endl;
  else
    cout<<"3"<<endl;
}

Measured memory_bytes: 3624
import numpy as np


H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]

X = (H + W) * 80
L = X + X + 1
dp = [[0] * W for _ in range(H)]
d = abs(A[0][0] - B[0][0])
dp[0][0] = np.zeros(L, np.bool)
dp[0][0][X + d] = 1
for h in range(H):
    for w in range(W):
        a = A[h][w]
        b = B[h][w]
        if h == w == 0:
            continue
        d = abs(a - b)
        x = np.zeros(L, np.bool)
        if h != 0:
            x[d:] |= dp[h - 1][w][:L - d]  # 正への移動
            x[:L - d] |= dp[h - 1][w][d:]
        if w != 0:
            x[d:] |= dp[h][w - 1][:L - d]
            x[:L - d] |= dp[h][w - 1][d:]
        dp[h][w] = x

dp = dp[-1][-1]
can_make = np.where(dp)[0] - X

answer = np.abs(can_make).min()
print(answer)


Measured memory_bytes: 187760
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;
struct edge {
	ll to, w;
};

ll a[maxn], b[maxn], d[maxn];
vector<edge>g[maxn];


signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll h, n; cin >> h >> n;
	for (ll i = 0; i < n; i++) cin >> a[i] >> b[i];
	for (ll i = 0; i <= h; i++) {
		for (ll j = 0; j < n; j++) {
			g[i].push_back({ max(0LL, i - a[j]), b[j] });
		}
	}

	set<pair<ll, ll>> st;
	st.insert({ 0, h });
	for (ll i = 0; i <= h; i++) d[i] = 1e18;
	d[h] = 0;

	while (!st.empty()) {
		auto p = *st.begin();
		st.erase(p);
		ll u = p.Y;
		for (auto e : g[u]) {
			if (d[e.to] > d[u] + e.w) {
				st.erase({ d[e.to], e.to });
				d[e.to] = d[u] + e.w;
				st.insert({ d[e.to], e.to });
			}
		}
	}
	cout << d[0] << endl;
	return 0;
}

/*
3
0 1
3 0
1 0
*/

Measured memory_bytes: 174072
// Shift-JIS（シフトジス）

#include <bits/stdc++.h>
using namespace std;

int main()
{
    long N, cf = 0, cl = 0, f1 = 0, l1 = 0, X;
    string S;
    cin >> S;
    char s;
    N = S.size();
    for (long i = 0; i < N; i++)
    {
        s = S[i];
        if ((i + 1) % 2 == 1)
        {
            cf++;
            if (s == '1')
            {
                f1++;
            }
        }
        else
        {
            cl++;
            if (s == '1')
            {
                l1++;
            }
        }
    }
    if (f1 > l1) {
        X = cf - f1 + l1;
    } else if (l1 > f1) {
        X = cl - l1 + f1;
    } else {
        if (N % 2 == 0) {
            X = cf - f1 + l1;
        } else {
            X = cl - l1 + f1;
        }
    }
    cout << X << endl;
}

Measured memory_bytes: 512
// 有點不耐煩會破壞偉大的計劃

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

long long dp[SM * 2];

int main() {
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long n; cin >> n;

    dp[0] = 1;
    for(long long i = 3; i <= n; i++) {
        for(long long j = 3; j <= i; j++) {
            (dp[i] += dp[i - j]) %= MOD;
        }
    }

    cout << dp[n];

    return 0;
}


Measured memory_bytes: 3624
from collections import Counter
if __name__ == "__main__":
    # Problem D
    N = int(input())
    A = sorted(map(int, input().split(' ')))
    dp = [1]* (A[-1]+1)
    C = Counter(A)

    for i in A:
        j = i*2
        while j < A[-1]+1:
            dp[j] = 0
            j += i

    ans=0
    for i in set(A):
        if C[i] == 1 and dp[i] == 1:
            ans+=1
    print(ans)

Measured memory_bytes: 51184
while True:
    H, W = [int(x) for x in input().split()]
    if H == W == 0:
        break
    for i in range(H):
        cnt = i % 2
        for j in range(W):
            if (cnt % 2) == 0:
                print('#', end="")
            else:
                print('.', end="")
            cnt += 1
        print()
    print()

Measured memory_bytes: 9076
#include <stdio.h>
int main()
{
    int x, a;
    scanf("%d %d", &x, &a);
    if (x>=0 && x<=9 && a>=0 && a<=9)
    {
        if (x<a)
        {
            printf("0\n");
        }
        else
        {
            printf("10\n");
        }
    }
    else
    {
        printf("Error\n");
    }
    return 0;
}


Measured memory_bytes: 128
#!/usr/bin/env python

import math


def main():
    A, B = map(int, input().split())

    A, B = B, A

    if A == B == 1:
        print(1, 2)
        print('.#')
        return

    N = 50 if max(A, B) >= 50 else max(A, B)

    ans = []
    if A != 1:
        if B != 1:
            a = A - 1
        else:
            a = A
        while a > 0:
            tmp = []
            for i in range(N):
                if a <= 0:
                    tmp.append('..')
                else:
                    # print('#.', end='')
                    tmp.append('#.')
                    a -= 1
            ans.append(''.join(tmp))
            ans.append('.' * N * 2)
    if B != 1:
        if A != 1:
            b = B - 1
        else:
            b = B
        ans.append('#' * N * 2)
        while b > 0:
            tmp = []
            for i in range(N):
                if b <= 0:
                    tmp.append('##')
                else:
                    tmp.append('.#')
                    b -= 1
            ans.append(''.join(tmp))
            ans.append('#' * N * 2)
    print(len(ans), len(ans[0]))
    for l in ans:
        print(l)


if __name__ == '__main__':
    # print(main())
    main()

Measured memory_bytes: 3064
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
typedef long long ll;

using namespace std;



int main() {
	ll n; cin >> n;
	vector<ll> v(60, 0);
	rep(i, n) {
		ll a; cin >> a;
		rep(j, 60) {
			if (a & 1) v[j] += 1;
			a >>= 1;
			if (a == 0) break;
		}
	}
	ll ans = 0;
	ll k1 = 1;
	rep(i, 60) {
		ll k2 = k1 * (n - v[i]) % MOD;
		k2 = k2 * v[i] % MOD;
		ans = (ans + k2) % MOD;
		k1 = k1 * 2 % MOD;
	}
	cout << ans << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

const ll N_MAX = 100005;

ll inv[N_MAX],fac[N_MAX],finv[N_MAX];
void make(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        fac[i]=fac[i-1]*(ll) i%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}

ll combination(ll C, ll D){
    if(C<D||C<1) return 0;
    return fac[C]*(finv[D]*finv[C-D]%mod)%mod;
}

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

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    sort(A.begin(), A.end());
    vector<ll> B(N, 0);
    REP(i, N) B[i] = combination(i, K-1);

    ll res = 0;
    REP(i, N){
    	ll tmp = B[i] * A[i];
    	if(tmp<0){
    		ll kai = (abs(tmp)/mod);
    		tmp += (kai+2) * mod;
    	}
    	tmp %= mod;
    	res += tmp;
    	res %= mod;
    }

    REP(i, N){
    	ll tmp = B[N-i-1] * A[i];
    	if(tmp<0){
    		ll kai = (abs(tmp)/mod);
    		tmp += (kai+2) * mod;
    	}
    	tmp %= mod;
    	tmp = (tmp+mod)%mod;
    	res -= tmp;
    	res = (res+mod)%mod;
    }
    cout << res << endl;
    //cout << B << endl;

    return 0;
}

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

#define sp <<" "
#define el <<"\n"
#define S second
#define F first
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define obit __builtin_popcount
#define pof pop_front
#define For(i,a,n) for(i=a;i<n;i++)
#define all(ar) ar.begin(),ar.end() 
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned short int us;
typedef short int ss;
typedef long double ld;
const ll mod = 1000000007;

bool cmp(pair<int,int> a,pair<int,int> b){
    return a.S>b.S;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    /*
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    //*/
    int n,k,i,safe = 0;
    cin>>n>>k;
    map<int,int> oc;
    For(i,0,n){
        int x;
        cin>>x;
        oc[x]++;
    }
    vector<pair<int,int> > sor;
    for(auto r: oc) sor.pb(r);
    sort(all(sor),cmp);
    int pac = sor.size();
    pac = min(k,pac);
    For(i,0,pac){
        safe += sor[i].S;
    }
    cout<<n - safe;
    return 0;
}

Measured memory_bytes: 11764
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// UnionFind tree(N);でUnion-Find木を生成
// tree.root(X);で親ノード番号を返す
// tree.unite(X, Y);でノードを結合する
// tree.same(X, Y);でXノード、Yノードが結合しているかどうか返す
// tree.size(X);でXノードが結合しているノード数を返す
struct UnionFind{
  vector<int> par;
  vector<int> sizes;

  UnionFind(int N) : par(N), sizes(N, 1){
    for(int i = 0; i < N; i++) par[i] = i;
  }

  int root(int x){
  if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    if(sizes[rx] < sizes[ry]) swap(rx, ry);
    par[ry] = rx;
    sizes[rx] += sizes[ry];
  }

  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }

  int size(int x){
    return sizes[root(x)];
  }
};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M; cin >> N >> M;
  UnionFind tree(N);
  REP(i, M){
    int A, B; cin >> A >> B; A--; B--;
    tree.unite(A, B);
  }
  set<int> s;
  int ans = 0;
  REP(i, N){
    int tmp = tree.root(i);
    s.insert(tmp);
    ans = max(ans, tree.size(i));
  }
  cout << ans << endl;
  /*
  int NN = s.size();
  if(NN == 1){
    cout << N << endl;
    return 0;
  }
  auto itr = s.begin();
  vector<int> siz(NN);
  REP(i, NN){
    siz.push_back(tree.size(*itr));
    itr++;
  }
  sort(siz.begin(), siz.end(), greater<int>());
  */
}

Measured memory_bytes: 14264
#include<iostream>
#include<cstdlib>
#include<string>

using namespace std;

int main(){

	int n,T;
	long long a;
	long long b;
	long long inum;
	string fn;
	string snum;

	cin>>n>>T;
	cin>>fn;

	inum=0;
	for(int i=0;i<fn.size();i++){
		if(fn[i]!='n'&&fn[i]!='^'&&fn[i]!='+'){
			snum="";
			while(i!=fn.size()&&fn[i]!='n'&&fn[i]!='^'&&fn[i]!='+'){
				snum+=fn[i];
				i++;
			}
			a=atoi(snum.c_str());
			b=n;
			if(a==0) b=1;
			a--;
			while(a --> 0){
				if(inum+b>1000000000){
					cout<<"TLE"<<endl;
					return 0;
				}
				b=b*n;
			}
			inum+=b;
			if(inum>1000000000){
				cout<<"TLE"<<endl;
				return 0;
			}
		}
	}

	inum*=T;

	if(inum<=1000000000) cout<<inum<<endl;
	else cout<<"TLE"<<endl;

	return 0;
}

Measured memory_bytes: 1208
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    int w,h,x,y;
    scanf("%d%d%d%d", &w, &h, &x, &y); 
    
    double s = (double)w*h;
    double eps = 1.0e-12;
    int ans = ((fabs((double)w/2-x)<eps && fabs((double)h/2-y)<eps)? 1: 0);
    printf("%.10lf %d\n", s/2, ans);






    return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    t1,t2=map(int,input().split())
    a1,a2=map(int,input().split())
    b1,b2=map(int,input().split())
    v1=a1-b1
    v2=a2-b2

    # v1とv2が同符号なら0回
    if(v1*v2>0):
        print(0)
        return
    # v1t1+v2t2 が0ならば無限
    if(v1*t1+v2*t2==0):
        print("infinity")
        return
    # abs(v1t1)>abs(v2t2)ならば0回
    if(abs(v1*t1)>abs(v2*t2)):
        print(0)
        return

    # 以下、v1を負の方の大きさ、v2を正の方の大きさとする
    v1=abs(v1); v2=abs(v2)
    d=v2*t2-v1*t1

    ans=-1
    ans-=(v1*t1%d==0)
    k=(v1*t1-1)//d+1+(v1*t1%d==0)
    ans+=2*k
    print(ans)
resolve()

Measured memory_bytes: 38384