akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <chrono>
#include <queue>
#include <string>
#include <cassert>
#include <bitset>
#include <stack> 

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 1000000007
#define BASE 77747
#define PI acos(-1.0)
#define MAXLEN 29

using namespace std;

typedef pair <int, int> pii;
typedef long long ll;
typedef vector <ll> vll;

int n;
int com[21][21];
ll dp[21][1 << 21];

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) 
		cin >> com[i][j];
	for (int i = 0; i < n; i++) {
		if (com[0][i]) {
			dp[0][1 << i] = 1;
		}
	}
	for (int i = 1; i < n; i++) {
		for (int mask = 0; mask < (1 << n); mask++) {
			if (__builtin_popcount(mask) != i) continue;
			for (int j = 0; j < n; j++) {
				if ((mask & (1 << j)) == 0 && com[i][j]) {
					dp[i][mask | (1 << j)] += dp[i - 1][mask];
					dp[i][mask | (1 << j)] %= MOD;
				}
			}
		}
	}
	cout << dp[n - 1][(1 << n) - 1] << endl;
	return 0;
}

Measured memory_bytes: 307456
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double


int main(){
    ll M = 1e6;
    vector<ll> table(M+1, 1);
    for (ll i = 2; i <= M; i++) {
        if (table[i] > 1) continue;
        for (ll j = i; j <= M; j += i) table[j] = i;
    }
    
    vector<ll> exist(M+1, 0), cnt(M+1, 0);
    bool ps = true;
    
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        ll A;
        cin >> A;
        while (A > 1) {
            ll p = table[A];
            if (exist[p] > 0) ps = false;
            exist[p] = 1;
            cnt[p]++;
            while (A%p == 0) A /= p;
        }
    }
    if (ps) {
        cout << "pairwise coprime\n";
        return 0;
    }
    for (int i = 2; i <= M; i++) {
        if (cnt[i] == N) {
            cout << "not coprime\n";
            return 0;
        }
    }
    cout << "setwise coprime\n";
	return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

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

  int cnt = 0;
  for (int i = a; i <= b; ++i) {
    if ((i / 10000) == (i % 10) && (i / 1000 % 10) == (i % 100 / 10)) {
      ++cnt;
    }
  }

  cout << cnt << '\n';

  return 0;
}


Measured memory_bytes: 3588
/*
sonu_verma1
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(a) push_back(a)
int main()
{
  string s;
  cin>>s;
  ll sm=0,i,j,k,l,cn=1;
  l=s.size();
  vector<ll> v;
  for(i=1;i<l;i++)
  {
  	if(s[i]==s[i-1])
  	{
  		cn++;
  	}
  	else
  	{
  		v.pb(cn);
  		cn=1;
  	}
  }
  v.pb(cn);
  k=v.size();
  if(s[l-1]=='<')
  {
  	sm+=(v[k-1]*(v[k-1]+1))/2;
  	v.pop_back();
  	k=k-1;
  }
  i=0;
  if(s[0]=='>')
  {
  	sm+=(v[0]*(v[0]+1))/2;
  	i=1;
  }
  for(;i<k;i+=2)
  {
  	ll m1,m2;
  	m1=max(v[i],v[i+1]);
  	m2=min(v[i],v[i+1]);
  	sm+=(m1*(m1+1))/2;
  	sm+=(m2*(m2-1))/2;
  }
  cout<<sm;
	return 0;
}

Measured memory_bytes: 3068
import math

mod = 10**9+7
N = int(input())
'''
def modpow(x,y):
    res = 1
    for _ in range(y):
        res = res * x % mod
    return res
'''
def modpow(a,n):
    res = 1
    while n > 0:
        if n & 1:
            res = res *a % mod
        a = a * a % mod
        n >>= 1
    return res

def main():
    ans = 0
    x0 = modpow(8,N)
    x1 = modpow(9,N)
    x2 = modpow(10,N)
    ans = (x2-2*x1+x0)%mod    

    print(ans)
main()

Measured memory_bytes: 9104
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <set>
#include <bitset>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define rep(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define rrep(i,a,b) for(ll i=a-1;i>=(ll)(b);i--)

#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)

#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

#define popcount __builtin_popcount
#define LIST(a) memset(a, 0, sizeof(a))


int main(void){
    char a;
    cin >> a;
    if(a >= 'a' && a <= 'z'){
        cout << 'a' << endl;
    } else {
        cout << 'A' << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair< ll, ll > pll;
typedef pair< int, int > pii;

const double pi = 3.14159265358979323846;

// #define fio() cin.tie(0); ios::sync_with_stdio(false);
// template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
// template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define TG0 get< 0 >
#define TG1 get< 1 >
#define TG2 get< 2 >
#define F first
#define S second
#define VL vector< ll >

// to_string(123)
// atoi("123"); atoi(s.c_str());
// "abc".size()
// s.find('+') == string::npos
// 1e18

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

  ll N, A, B;
  cin >> N >> A >> B;

  ll c = (N / (A + B)) * A;
  c += min((N % (A + B)), A);

  cout << c << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)

from itertools import combinations


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n = gete(int)
    l = tuple(geta(int))

    cnt = 0

    for c in combinations(range(n), 3):

        p, q, r = l[c[0]], l[c[1]], l[c[2]]

        if p == q or p == r or q == r:
            continue

        if abs(p - q) < r and r < p + q:
            cnt += 1

    print(cnt)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9508
#インプット
l = input().split()
#インプットデータの分割
W = int(l[0])
H = int(l[1])
x = int(l[2])
y = int(l[3])
r = int(l[4])
#インプットデータの判別
#x-rが0より小さい、またはx+rがWより大きいならばNO
#x-r0以上、かつwLrがW以下ならばYesと判断
if x-r >= 0 and x + r <= W:
    if y - r >= 0 and y + r <= H:
        print("Yes")
    else:
        print("No")
else:
    print("No")



Measured memory_bytes: 5596
#include <iostream>
#include <string>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;

long long N, K;
long long R, S, P;

long long get_score(char* h) {
    if (*h == 'r') {
        return P;
    } else if (*h == 's') {
        return R;
    } else {
        return S;
    }
}

int main() {
    
    string hands;

    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> hands;

    long long score = 0;

    char last_hand;
    for (int i=0; i<K; i++) {
        int p = i;
        int j = 1;
        while (p < N) {
            if (j == 1) {
                score += get_score(&hands[p]);
                last_hand = hands[p];
            } else if (last_hand != hands[p]) {
                score += get_score(&hands[p]);
                last_hand = hands[p];
            } else {
                last_hand = 'a';
            }
            p += K;
            j += 1;
        }
    }

    cout << score;
}



Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <tuple>
#include <complex>
#include <cassert>
#include <exception>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << "\n"
static const int INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[300][300];
char field[200][200];

int main(){
  cin >> s;
  if(s == "zyxwvutsrqponmlkjihgfedcba"){
    puts("-1");
    return 0;
  }
  rep(i,0,s.sz)d[s[i] - 'a']++;
  if(s.sz < 26){
    cout << s;
    rep(i,0,26){
      if(d[i] == 0){
        cout << char(i + 'a') << endl;
        break;
      }
    }
  }else{
    t = s;
    next_permutation(all(t));
    cout << t[0];
    rep(i,0,s.sz){
      if(t[i] == s[i])cout << t[i+1];
      else break;
    }
    puts("");
  }
  return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n;
	cin >> n;
	long long t;
	cin >> t;
	vector<long long> a(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long ans = 0;
	for(int i = 1; i < n; i++) {
		ans += min(a[i] - a[i - 1], t);
	}
	cout << ans + t << endl;
	return 0;	
}


Measured memory_bytes: 1792
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;

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

void solve(){
	int n = rint;
	long[] as = rlong(n) ~ 1;
	
	bool isNG(int k){
		log("k:", k);
		if(k == 1) return 1;
		long[] au = [0];
		long[] vu = [0];
		foreach(a; as){
			if(au[$ - 1] < a){
				au ~= a;
				vu ~= 1;
				log("case 1");
			}
			else if(au[$ - 1] == a){
				vu[$ - 1] += 1;
				log("case 2");
			}
			else{
				long v = 1;
				log("case 3");
				while(au[$ - 2] >= a){
					long l = au[$ - 1] - au[$ - 2];
					v = vu[$ - 1];
					while(l > 0 && v > 0) v = (v - 1) / k, l -= 1;
					au.length -= 1;
					vu.length -= 1;
					vu[$ - 1] += v;
					log("loop", "au:", au, "vu:", vu, "v:", v);
				}
				if(au[$ - 1] > a){
					long l = au[$ - 1] - a;
					v = vu[$ - 1];
					while(l > 0 && v > 0) v = (v - 1) / k, l -= 1;
					au[$ - 1] = a;
					vu[$ - 1] = 1 + v;
					log("case 3-1", "au:", au, "vu:", vu, "v:", v);
				}
				vu[$ - 1] += 1;
				log("au:", au, "vu:", vu, "v:", v);
			}
			log("a:", a, "au:", au, "vu:", vu);
		}
		log("res:", vu[$ - 1] > k + 1);
		return vu[$ - 1] > k + 1;
	}
	
	bool f = 1;
	foreach(i; 0 .. n - 1) if(as[i] >= as[i + 1]) f = 0;
	if(f) 1.writeln;
	else (1 + uplimit(1, n, &isNG)).writeln;
	
}
T uplimit(T)(T a, T c, bool delegate(T) f){
	if(f(c)) return c; if(! f(a)) return a - 1;
	while(a + 1 < c){ T b = (a + c) / 2; if(f(b)) a = b; else c = b; }
	return a;
}
/*

5
2 3 3 2 2

6
2 3 3 2 2 2

6
2 3 3 3 2 2

7
2 3 3 3 2 2 2



*/


Measured memory_bytes: 22216
import java.util.*;
import java.util.stream.*;

class Piece{
	int h,w;

	public Piece(int w,int h){
		this.h=h;
		this.w=w;
	}

	int area(){
		return h*w;
	}

	@Override
	public String toString(){
		return "[("+w+", "+h+"), "+area()+"]";
	}
}

public class Main{

	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		ArrayList<Piece> l=new ArrayList<>();
		while(true){
			l.clear();
			int cut=s.nextInt();
			{
				Piece p=new Piece(s.nextInt(),s.nextInt());
				if(p.w==0)
					return;
				l.add(p);
			}
			for(int c=0;c<cut;++c){
				Piece p=l.remove(s.nextInt()-1),a,b;
				int w=p.w,h=p.h,k=s.nextInt()%(h*2+w*2);
				if(k<w||(w+h<k&&k<w*2+h)){
					k%=w+h;
					a=new Piece(k,h);
					b=new Piece(w-k,h);
				}else{
					k%=w+h;
					k-=w;
					a=new Piece(w,k);
					b=new Piece(w,h-k);
				}
				if(a.area()>b.area()){
					Piece t=a;
					a=b;
					b=t;
				}
				l.add(a);
				l.add(b);
			}
			System.out.println(
					l.stream().mapToInt(Piece::area)
							.filter(o->o>0)
							.sorted()
							.mapToObj(String::valueOf)
							.collect(Collectors.joining(" ")));
		}
	}
}


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

int main() {
  // 入力受け取り
  int N,D;
  cin >> N >> D;
  
  // 計算
  int ret= N / (2*D+1);
  if (N % (2*D+1) != 0) ret++;
  
  // 出力
  cout << ret << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>

 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define LLIandI pair<long long int , int>
#define ll long long
int main(void){
    int A,B;
    scanf("%d %d",&A,&B);
    char map[100][100];
    rep(i,100){
        rep(j,100){
            if(i<50){
                map[i][j]='.';
                if(i%2==0&&j%2==0&&B-1-(i/2)*50-(j/2)>0)map[i][j]='#';
            }else{
                map[i][j]='#';
                if(i%2==1&&j%2==1&&A-1-((99-i)/2)*50-(j/2)>0)map[i][j]='.';
            }
        }
    }
    printf("100 100\n");
    rep(i,100){
        rep(j,100){
            printf("%c",map[i][j]);
        }
        printf("\n");
    }
    
    
}


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

using namespace std;

int main(){
	int n;
	cin >>n;
	long n3= n*3;
	vector<int> a(n3);
	for(auto& x:a){
		cin >> x;
	}
	sort(a.begin(), a.end());
	long sum = 0;

	for(int i =0; i<(n*2); i += 2){
		sum += a.at(n+i);
	}
	cout << sum << endl;
}


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

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    if (s1[s1.length() - 1] == s2[0] && s2[s2.length() - 1] == s3[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
from fractions  import gcd
#input=sys.stdin.readline
import bisect
n,k=map(int,input().split())
if n%k ==0:
    print(0)
else:
    print(1)

Measured memory_bytes: 77432
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static class Task {

        private boolean isWin(int h1, int s1, int h2, int s2) {
            boolean isOneTurn = true;
            while (true) {
                if (isOneTurn) {
                    h2 -= s1;
                    if (h2 <= 0) {
                        return true;
                    }
                } else {
                    h1 -= s2;
                    if (h1 <= 0) {
                        return false;
                    }
                }
                isOneTurn = !isOneTurn;
            }
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int h1 = in.nextInt();
            int s1 = in.nextInt();
            int h2 = in.nextInt();
            int s2 = in.nextInt();

            out.println(isWin(h1, s1, h2, s2) ? "Yes" : "No");
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

    }

}

Measured memory_bytes: 33904
### SNIPPET
  # n = gets.split.map(&:to_i)
  # a = [*1..m].repeated_combination(n).to_a
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end
require 'prime'
require 'set'
n = gets.to_i
s = Set.new
count = 0
temp = n
n.prime_division.each do |p,e|
  1.upto(e) do |i|
    x = i
    z = p ** x
    next if temp % z != 0  
    if s.add?(z)
      temp = temp / z
      count += 1
    end
  end
end
puts count

Measured memory_bytes: 14560
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define M (L+R)/2
#define N 500009
#define inf 99999999999
#define ll long long
#define mod 1000000007
#define sz size();
using namespace std;
ll n,ans,x,y;
int main(){

	ios::sync_with_stdio(0);
	
	cin>>n;
	x=n-1;

	for(int i=1;i<=sqrt(x);i++){
		if((x%i)==0){
			if(i==sqrt(x))ans++;
			else ans+=2;
		}
	}

	for(int i=2;i<=sqrt(n);i++){
		if(n%i==0){
			x=n;
			while(x%i==0){
				x/=i;
			}
			if((x>i && x%i==1) || x==1){
				ans++;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 256
#回文
#while文で終わりまで入力繰り返す
#沢山の入力の中で回文を見つけたらcnt+=1
#スタック機能を使い、input半分を読み込み回文を作り、それを元々と比べる
#上から読んでも下から読んでも同じ

count = 0

while 1:
    try:
        n = input()
        if n == n[::-1]: #元と逆順にしても同じ
            count += 1
    except:
        print(count)
        break


Measured memory_bytes: 5556
#include<cstdio>
const int N=3e5+10;
const int mod=1e9+7;
int n,f[N][60][2];
long long ans,a[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		for(int j=0;j<60;j++)
			if(a[i]&(1ll<<j))f[i][j][1]++;
			else f[i][j][0]++;
	}
	for(int i=n;i>=1;i--)
		for(int j=0;j<60;j++)
			for(int k=0;k<2;k++)
				f[i][j][k]+=f[i+1][j][k];
	for(int i=1;i<=n;i++)
		for(int j=0;j<60;j++)
			ans=(ans+(1ll<<j)%mod*f[i+1][j][(a[i]&(1ll<<j))?0:1]%mod)%mod;
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 143104
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto L = RD;
	auto R = RD;
	if (R - L + 1 > 2019)
	{
		writeln(0);
	}
	else
	{
		long[] x;
		foreach (i; L..R+1)
		{
			foreach (j; i+1..R+1)
			{
				x ~= (i*j) % 2019;
			}
		}
		x.sort();
		writeln(x[0]);
	}

	stdout.flush();
	debug readln();
}

Measured memory_bytes: 27132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const ll mod=1000000007;
ll a[200010],b[200010],c[200010];//b:何番目に訪れたか、c:i回目に訪れた町
int main(void){
    ll n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    fill(b,b+200010,0);
    b[1]=0;
    c[0]=1;
    ll count=0,prenum=1,onaji;
    for(int i=1;i<=n;i++){
        prenum=a[prenum];
        if(b[prenum]!=0||prenum==1){
            onaji=prenum;//ループする町の番号
            break;
        }
        count++;
        b[prenum]=count;
        c[count]=prenum;
    }
    ll ans;
    ll z=k-b[onaji];
    if(z>=0){
        ll y=count-b[onaji]+1;
        ll s=z%y;
        ans=c[b[onaji]+s];
    }
    else{
        ans=c[k];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 8112
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_A = 100000;
int n;
int cnt[MAX_A + 1];

int main() {
    fastio();

    cin >> n;
    forn(i, n) {
        int a;
        cin >> a;
        cnt[a]++;
    }

    int ans = 0;
    for (int i = 1; i <= MAX_A; i++) {
        ans += max(0, cnt[i] - 1);
    }

    cout << n - (ans % 2 == 0 ? ans : ans + 1) << endl;

    return 0;
}

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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        int max = 0, min = 500;
        for (int i = 0; i < n; i++) {
            int sum = 0;
            for (int j = 0; j < 5; j++) {
                int s;
                cin >> s;
                sum += s;
            }
            if (sum > max) {
                max = sum;
            }
            if (sum < min) {
                min = sum;
            }
        }
        cout << max << " " << min << endl;
    }
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

int main()
{
    ll x;
    cin >> x;

    ll ans = 0;
    ans += x/11 * 2;

    ll tmp = x%11;
    if (tmp > 6) ans += 2;
    else if (tmp > 0) ans += 1;
    else ans;

    cout << ans << endl; 
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  char f[20];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
char S[200002];
int main(){
  int i, k;
  long long res=0;
  N = rd(S);
  k = 0;
  for(i=0;i<N;i++){
    if(S[i]=='A'){
      k++;
      continue;
    }
    if(S[i]=='B' && S[i+1]=='C'){
      res += k;
      i++;
      continue;
    }
    k = 0;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190601-1

// --- original code ---
// int N; char S[200002];
// {
//   int i, k;
//   ll res = 0;
// 
//   rd(S@N);
//   k = 0;
//   rep(i,N){
//     if(S[i]=='A'){ k++; continue; }
//     if(S[i]=='B' && S[i+1]=='C'){
//       res += k;
//       i++;
//       continue;
//     }
//     k = 0;
//   }
//   wt(res);
// }


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication51
{
    class Program
    {
        static void Main()
        {
            while (true)
            {                  string l = Console.ReadLine();
                if (l == null) break;
                int[] a = l.Split().Select(int.Parse).ToArray();
                int b = a[0] * 10000 + a[1] * 100 + a[2];
                
                if (b < 18680908) { Console.WriteLine("pre-meiji");continue; }
                else if (b < 19120730) Console.Write("meiji "+(a[0]-1867)+" ");
                else if (b < 19261225) Console.Write("taisho " + (a[0] - 1911) + " ");
                else if (b < 19890108) Console.Write("showa " + (a[0] - 1925) + " ");
                else Console.Write("heisei " + (a[0] - 1988) + " ");
                Console.WriteLine(a[1]+" "+a[2]);
            }
        }
    }
}

Measured memory_bytes: 9484
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n, m;
  cin >> n >> m;
  cout << (int64_t)((100 * n + 1800 * m) / std::pow(2, m) *
                    (std::pow(4, m) - std::pow(2, m) + std::pow(2, m)))
       << endl;

  return 0;
}


Measured memory_bytes: 888
#define _USE_MATH_DEFINES // M_PI
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,a,n) for(int (i)=(n)-1; (i)>=(a);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2147483647;
constexpr ll mod = 1000000007;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};
int main() {
	init();

	int N;cin >> N;
	vector<string>s(2);
	rep(i, 2)cin >> s[i];
	mint ans = 0;
	rep(i, N) {
		if (i == 0) {
			if (s[0][i] == s[1][i]) {
				ans += 3;
			}
			else {
				++i;
				ans += 6;
			}
		}
		else {
			if (s[0][i] == s[1][i]) {
				if (s[0][i - 1] == s[1][i - 1])ans *= 2;
			}
			else {
				if (s[0][i - 1] == s[1][i - 1])ans *= 2;
				else ans *= 3;
				++i;
			}
		}
	}
	cout << ans.x << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int n;
  int t[100000]={};
  
  int m;
  int p[101]={};
  int x[100000]={};
  
  int i;
  
  int sum=0;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++)
  {
    scanf("%d",&t[i]);
  }
  
  for(i=0;i<n;i++)
  {
    sum=sum+t[i];
  }
  
  scanf("%d",&m);
  
  for(i=0;i<m;i++)
  {
    scanf("%d %d",&p[i],&x[i]);
  }
   
  for(i=0;i<m;i++)
  {
    printf("%d\n",sum+(x[i]-t[p[i]-1]));
  }
  
  return 0;
}
  

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

int main(){
  int a,b;
  cin >> a >> b;
  cout << a*b << endl;
}


Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<queue>
#include <string>
#include <sstream>
using namespace std;

int main()
{
  long n;
  string a, b;

  cin >> a;
  cin >> b;

  if (a.size() > b.size ()) {
    cout << "GREATER";
  } else if ( a.size() < b.size () ) {
    cout << "LESS";
  } else {
    bool isEqual = true;

    for (int i = 0; i < a.size() ; i++) {
      if ( (a[i] - '0')  > (b[i] - '0') ) {
        cout << "GREATER";
        isEqual = false;
        break;
      } else if ( (a[i] - '0')  < (b[i] - '0') ) {
        cout << "LESS";
        isEqual = false;
        break;
      }
    }


    if (isEqual){
      cout << "EQUAL";
    }



  }


  return 0;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 998244353 //1000000007 // //100000000
#define INF 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll dx[4] = {0, 0, 1, -1};
ll dy[4] = {1, -1, 0, 0};

void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}


void solve(){
    ll n, d;
    cin >> n >> d;
    ll a[n][d];
    rep(i, n) rep(j, d) cin >> a[i][j];
    ll ans = 0;
    for(ll i = 0; i < n; i++){
        for(ll j = i+1; j < n; j++){
            ll ds = 0;
            for(ll k = 0; k < d; k++) ds += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
            ll mm = sqrt(ds);
            if(mm * mm == ds) ans++;
        }
    }
    cout << ans;
}
main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
}


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

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var ass = new int[n];
        for (int i = 0; i < ass.Length; ++i)
        {
            ass[i] = int.Parse(Console.ReadLine());
        }

        int count = 1;
        var dec = new int[n];
        dec[0] = ass[0];

        for (int i = 1; i < ass.Length; ++i)
        {
            var a = ass[i];
            int lower = -1, upper = count;

            while (true)
            {
                var index = (upper + lower) / 2;

                if (dec[index] < a)
                {
                    upper = index;
                }
                else
                {
                    lower = index;
                }

                if (upper - lower == 1)
                {
                    dec[upper] = a;
                    if (upper == count)
                        ++count;
                    break;
                }
            }
        }

        Console.WriteLine(count);
    }

    private static int GCD(int a, int b) => a > b ? GCD_impl(a, b) : GCD_impl(b, a);
    private static int GCD_impl(int a, int b) => b == 0 ? a : GCD_impl(b, a % b);
    private static long LCM(int a, int b) => (long)a * b / GCD(a, b);

    private static int Comb(int m, int n)
    {
        var t = m - n;
        if (n > t)
            n = t;

        long numerator = 1;
        for (int i = 0; i < n; ++i)
        {
            numerator *= m - i;
            numerator %= MOD_N;
        }
        long denominator = 1;
        for (; n != 0; --n)
        {
            denominator *= n;
            denominator %= MOD_N;
        }

        var inv_denominator = ModInv((int)denominator, MOD_N);
        var ret = (int)(numerator * inv_denominator % MOD_N);

        return ret >= 0 ? ret : ret + MOD_N;
    }

    private static int ModInv(int a, int m)
    {
        int b = m, x = 1, y = 0;
        while (b != 0)
        {
            var t = a / b;
            a -= t * b;
            Swap(ref a, ref b);
            x -= t * y;
            Swap(ref x, ref y);
        }
        x %= m;
        return x >= 0 ? x : x + m;
    }

    private static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
}


Measured memory_bytes: 17756
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL)
    x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL)
    x = x->right;
  return x;
}

Node treeSearch(Node u, int k){

  // 現在のノードがNULLもしくは対象のキーである場合ノードを返す
  if(u == NIL || k == u->key){
    return u;
  }
  
  if(k < u->key){
    return treeSearch(u->left, k);
  }
  else{
    return treeSearch(u->right, k);
  }
  
}

Node treeSuccessor(Node x){
  if(x->right != NIL){
    return treeMinimum(x->right);
  }
  Node y = x->parent;
  
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted | 削除対象ノード
  Node x; // child of y | 削除対象ノードの子

  // 対象のノードに子が片方しかいない、もしくはいない場合yにzを入れる
  if(z->left == NIL || z->right == NIL)
    y = z;
  else // 対象のノードが子を二つ持つ場合その後継者（次に大きい数）を探してyにする
    y = treeSuccessor(z);
  
  // yの左に子ノードがある場合xをyの左の子ノードにする
  if(y->left != NIL)
    x = y->left;
  else // xをyの右の子ノードにする(このときNILが入る場合がある)
    x = y->right;
  
  // xがNULLでない場合xの親をyの親(xの親の親)にする 親替え
  if(x != NIL)
    x->parent = y->parent;

  // yの親がいない場合、つまり削除対象がrootノードである場合xをrootにする
  if(y->parent == NIL)
    root = x;
  // yが左の子ノードである場合yの親の左の子ノードをxにする 子替え
  else if(y == y->parent->left)
    y->parent->left = x;
  // それ以外の場合yの親の左の子ノードをxにする 子替え
  else
    y->parent->right = x;

  if(y != z){
    z->key = y->key;
    
  }
  

}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    } 
    else {
      x = x->right;
    }
  }
  z->parent = y;
  
  if( y == NIL ){
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else {
    y->right = z;
  }
  

}

void inorder(Node u){
  
  // 左のノードがある場合左のノードへ
  if(u->left != NIL){ 
    inorder(u->left);
    
  }
  
  // 左のノードがない、もしくは左側を踏破したとき現在のノードのキーを表示
  printf(" %d",u->key);


  // 右のノードがある場合右のノードへ
  if(u->right != NIL){
    inorder(u->right);
    
  }


}
void preorder(Node u){
  
  // 現在のノードのキーを表示
  printf(" %d",u->key);
  
  // 左のノードがある場合左のノードへ
  if(u->left != NIL){ 
    preorder(u->left);
    
  }
  
  // 右のノードがある場合右のノードへ
  if(u->right != NIL){
    preorder(u->right);
    
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);

    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
      }
  }

  return 0;
}

Measured memory_bytes: 19364
use proconio::input;

fn main(){
  input! {
    n: usize,
  }
  
  let m1 = n%100;
  let h1 = (n - m1)/100;
  let m2 = m1%10;
  let h2 = (m1 - m2)/10;
  let h3 = m2;
  let v;
  if h1==7 || h2==7 || h3==7 {
  	v = "Yes";
  } else {
    v = "No";
  }
  println!("{}", v);
}


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


int main(){
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x3,y3,x4,y4;
    x3 = x2 - (y2 - y1);
    y3 = y2 + (x2 - x1);
    x4 = x1 - (y2 - y1);
    y4 = y1 + (x2 - x1);
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << "\n";
}

Measured memory_bytes: 256
#!/usr/bin/env python3

h, w, d = list(map(int, input().split()))

index = [-1]*(h*w)
for i in range(h):
    a = list(map(int, input().split()))
    for j in range(len(a)):
        index[a[j]-1] = (i+1, j+1)
        # index[a[j]-1] = (i, j)
# print(index)

data = [[] for _ in range(d)]

for i in range(1, d+1):
    num = i
    x, y = index[num-1]
    data[i-1].append(0)
    num += d
    while(num <= h*w):
        x_new, y_new = index[num-1]
        # data[i-1].append(abs(x-x_new)+abs(y-y_new))
        data[i-1].append(abs(x-x_new)+abs(y-y_new)+data[i-1][-1])
        x, y = x_new, y_new
        num += d
# print(data)

q = int(input())
for i in range(q):
    l, r = list(map(int, input().split()))

    index_data = l % d-1

    r = (r-1)//d
    l = (l-1)//d
    print(data[index_data][r]-data[index_data][l])


Measured memory_bytes: 25584
#include<bits/stdc++.h>
using namespace std;
#define sf scanf
#define pf printf
#define pb push_back
typedef long long ll;
const ll INF = 1e18;
const int MOD = 1e9+7;
const int N = 1e6+9;

#define fast()    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int ar[100005],br[100005];

int main()
{
    fast();
    int t, num, x, y, z, c0=0, c1=0, sum=0, ans=0, res=0, m0;
    cin>>x>>y;
    if(x<y)
    {
        cout<<1<<endl;
    }
    else
    {
        while(x>0)
        {
            x-=y;
            ++c0;
        }
        cout<<c0<<endl;
    }
}


Measured memory_bytes: 256
from itertools import product
def main():
    s = list(input())
    koho = len(s) - 1
    pat = tuple(product(('+', ''), repeat = koho))
    r = 0
    for pate in pat:
        a = []
        for i, p in enumerate(pate):
            a.append(s[i])
            a.append(p)
        a.append(s[-1])
        r  += eval("".join(a))
    print(r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main() {
  int a, b, c;
  cin >> a >> b;
  c = a + b;
  if (c % 2 == 0) cout << (a + b) / 2 << endl;
  else cout << (a + b) / 2 + 1 << endl;
  return 0;
}

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

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

const int maxn = 1e6 + 11;

int n;
ll w;

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    cin >> n >> w;

    vector<ll> dp(w+10,0LL);
    for (int i = 0; i < n; i++) {
        ll wei, val;
        cin >> wei >> val;
        for (int j = w; j >= 0; j--) {
            if (j+wei <= w) {
                dp[j+wei] = max(dp[j+wei], val+dp[j]);
            }
        }
    }

    ll ans = 0LL;
    for (int i = 0; i <= w; i++) {
        ans = max(ans, dp[i]);
    }
    
    out(ans);
    
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#define NIL -1

int depth(int);
void print();

struct Node{
  int parent;
  int left;
  int right;
};

struct Node T[1000001];
int num=0;
int i,j,n,id,c,r,l;
int ids[100001];
int k;

int main(){
 
  scanf("%d",&n);

  for(i=0;i<n;i++){
    T[i].parent=NIL;
    T[i].left=NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&id,&k);
    ids[id]=k;
    for(j=0;j<k;j++){
      scanf("%d",&c);
      T[c].parent=id;
      if(j==0) T[id].left=c;
      else if(j>0){
	T[l].right=c;
      }
      l=c;
    }
  }

  for(i=0;i<n;i++){
    num=0;
    printf("node %d: parent = %d, depth = %d, ",i,T[i].parent,depth(i));
    if(T[i].parent==NIL){
      printf("root, [");
      print();
      printf("]\n");
    }
    else if( T[i].left>=0){
      printf("internal node, [");
      print();
      printf("]\n");
    }
    else if(T[i].left==NIL) printf("leaf, []\n");
  }

  return 0;
}

int depth(int t){
  int p=T[t].parent;
  if(p==NIL) return num;
  num++;
  depth(p);
}

void print(){
  for(j=0;j<ids[i];j++){
    if(j==0) {
      printf("%d",T[i].left);
      l=T[i].left;
    }
    else if(j<ids[i]-1){
      printf(", %d",T[l].right);
      l=T[l].right;
    }
    else if(j<=ids[i]-1){
      printf(", %d",T[l].right);
    }
  }
  
  
}
  

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

int main() {
  int64_t K;
  cin >> K;
  if(K%2==0||K%5==0){
    cout << -1 << endl;
    return 0;
  }
  int64_t ans=1;
  int64_t kazu=0;
  int64_t a=1;
  while(true){
    kazu+=7*a;
    kazu%=K;
    if(kazu==0){
      cout << ans << endl;
      return 0;
    }
    ans++;
    a*=10;
    a%=K;
  }
}

Measured memory_bytes: 3620
package main

import "fmt"
import "sort"

func main() {
    var n int
    fmt.Scan(&n)
    v := make([]int, n)
    for i := 0; i < n; i ++ {
        fmt.Scan(&v[i])
    }
    sort.Sort(sort.IntSlice(v))
    a := float64(v[0])
    for i := 1; i < n; i ++ {
        a = (a + float64(v[i])) / 2.0
    }
    fmt.Println(a)
}


Measured memory_bytes: 512
#include<iostream>
#include<string>

using namespace std;

int main(){
  int n,k,i;
  string s;
  cin>>n;
  cin>>s;
  cin>>k;
  for(i=0;i<n;i++){
    if(s[i]!=s[k-1]){
      s[i]='*';
    }
  }
  cout<<s<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <string>
#include <functional>

using namespace std;


int main() {
	int N, MAX = 0, MIN =  1000000000;
	cin >> N;
	int val;
	for (int i = 0; i < N; i++) {
		cin >> val;
		MAX = max(MAX, val);
		MIN = min(MIN, val);
	}
	cout << abs(MAX - MIN) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    char s[101][101];
    int i, j, h, w;
    scanf("%d%d", &h, &w);
    for(i = 0; i < h; i++) scanf("%s", s[i]);
    for(i = 0; i < h + 2; i++){
        if(i == 0 || i == h + 1){
            for(j = 0; j < w + 2; j++){
                printf("#");
            }
        }else{
            printf("#%s#", s[i-1]);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <queue>

using namespace std;

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

  priority_queue<int64_t> q;

  for(int n = 0;n < N;n++){
    int64_t a;
    cin >> a;
    q.push(a);
  }

  for(int m = 0;m < M;m++){
    int64_t a = q.top()/2;
    q.pop();
    q.push(a);
  }

  int64_t sum = 0;
  while(!q.empty()){
    sum += q.top();
    q.pop();
  }

  std::cout << sum << std::endl;
}


Measured memory_bytes: 1400
N=int(input())
a=input().split()
numbers=[0]*10**5
A=[int(b) for b in a]
answer=0
for c in A:
    if c>10**5:
        answer+=1
    else:
        numbers[c-1]+=1
for d in range(10**5):
    if numbers[d]==0:
        continue
    elif numbers[d]==d+1:
        continue
    else:
        if numbers[d]>d+1:
            answer+=numbers[d]-d-1
        else:
            answer+=numbers[d]
print(answer)


Measured memory_bytes: 15388