akhauriyash/Code-Regression huggingface dataset:
class Scanner {
    private var stack = [String]()
    private var index = 0
    
    func peek() -> String {
        if stack.count == index {
            stack += readLine()!.split(separator: " ").map{ String($0) }
        }
        return stack[index]
    }
    
    func next() -> String {
        let value = peek()
        index += 1
        return value
    }
    
    func nextInt() -> Int {
        return Int(next())!
    }
    
    func nextDouble() -> Double {
        return Double(next())!
    }
}

var scanner = Scanner()

let N = scanner.nextInt()
let A = (0 ..< N).map { _ in scanner.nextInt() }

var count = [Int](repeating: 0, count: 1000001)

for x in A {
    count[x] += 1
}

var answer = 0
for i in 1 ... 1000000 {
    if count[i] == 1 {
        answer += 1
    }
    if count[i] > 0 {
        for j in stride(from: i, through: 1000000, by: i) {
            count[j] = 0
        }
    }
}

print(answer)


Measured memory_bytes: 23536
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;
list<long long int> Prime(int M) {
	list<long long int>P;
	P.push_back(2);
	P.push_back(3);
	for (int i = 5; i <= M; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	return P;
}

long long int N, M, K, Q, W, H;
long long int ans;

int main() {
	ios::sync_with_stdio(false);
	cin >> N >> K;
	bool flag[10] = {};
	for (int i = 0; i < K; i++) {
		int a;
		cin >> a;
		flag[a] = true;
	}
	for (int i = N; i < 1000000; i++) {
		int box = i;
		bool can = true;
		while (box) {
			if (flag[box % 10]) {
				can = false;
				break;
			}
			box /= 10;
		}
		if (can) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int A=a,flag=0;
  for(int i=0;i<b+1;i++){
    if(A%b==c){
      flag=1;
      break;
    }else A+=a;
  }
  if(flag)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

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

// infty
#define ULLINF (ULLONG_MAX)
#define LLINF  (LLONG_MAX)
#define IINF   (INT_MAX)
#define INF    (1<<29)

// math
#define Sq(x) ((x)*(x))

// container utility
#define ALL(x) (x).begin(), (x).end()
#define MP make_pair
#define PB push_back

// rep
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;

typedef long long ll;

// pair util
#define FST first
#define SND second

// range validator
#define CK(n,a,b) (a<=n && n<b)

// conversion
template<class T> inline string toStr(T a) { ostringstream oss_; oss_ << a; return oss_.str(); }
inline int toInt(string s) { return atoi(s.c_str()); }

// prime
bool isPrime(int a) { for(int i=2; i*i <=a; i++) if(a%i == 0) return false; return true; }

int const dx[] = {-1,0,1,0,-1,1,1,-1};
int const dy[] = {0,-1,0,1,-1,-1,1,1};

//////////////////////////////////////////////////////////////

int const MAX_M = 31;
int const MAX_N = 9;

double edge[MAX_M][MAX_M];
double dp[MAX_M][1<<MAX_N];

int main() {
  
  int N, M, P, S, T;
  while(cin >> N >> M >> P >> S >> T) {
    if(!(N|M|P|S|T)) break;
    S --; T --;
    fill(edge[0], edge[MAX_M], INF);
    
    double tickets[N]; rep(i, N) cin >> tickets[i];
    
    rep(i, P) {
      int a, b, c; cin >> a >> b >> c; a--, b--;
      edge[a][b] = edge[b][a] = c;
    }
    
    fill(dp[0], dp[MAX_M], INF);
    dp[S][0] = 0;
    
    for(int stT=0; stT<(1<<N); stT++) {
      for(int u=0; u<M; u++) {
	for(int i=0; i<N; i++) {
	  if(stT & (1<<i)) continue;
	  for(int v=0; v<M; v++) {
	    if(edge[u][v] == INF) continue;
	    dp[v][stT|(1<<i)] = min(dp[v][stT|(1<<i)], dp[u][stT] + edge[u][v]/tickets[i]);
	  }
	}
      }
    }
    
    double ans = *min_element(dp[T], dp[T+1]);
    if(ans == INF) {
      cout << "Impossible" << endl;
    }
    else {
      printf("%.3f\n", ans);
    }
  }
  
  return 0;
}

Measured memory_bytes: 1416
/* author   : mpily :-()
title : Competing.cpp
time :Sat May 16 10:36:41 2020

*/
#include<bits/stdc++.h>
using namespace std;
const int64_t mod = 1e9+7;
bool isrot = false;

void rev(){
	isrot = !isrot;
}
int main(){
	//ios_base::sync_with_stdio(false);
	//cin.tie(nullptr);
	list<char>ans;
	string s;
	cin >> s;
	for(auto a : s){
		ans.push_back(a);
	}
	int q;
	cin >> q;
	for(int i = 0; i < q; ++i){
		int t ;
		cin >> t;
		if(t == 1){
			rev();
		}
		else{
			int f;char c;
			cin >> f >> c;
			if(f == 1){
				if(isrot){
					ans.push_back(c);
				}
				else{
					ans.push_front(c);
				}
			}
			else{
				if(!isrot){
					ans.push_back(c);
				}
				else{
					ans.push_front(c);
				}
			}
		}
	}
	if(!isrot)
		for(auto a = ans.begin(); a != ans.end(); ++a){
			cout << *a;
		}
	else
		for(auto a = ans.rbegin(); a != ans.rend(); ++a)
			cout << *a;
	cout << "\n";
	return 0;
}

Measured memory_bytes: 9984
n,m,v,p = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)

def check(mid):
    remain = v*m
    more = 0
    less = 0
    same = 0
    tmp = [0]
    for i in range(n):
        if a[i]+m <= a[mid]+m:
            less += 1
            remain -= m
        elif a[i]<=a[mid]+m:
            same += 1
            remain -= a[mid]+m-a[i]
            tmp.append(tmp[-1] + a[i]-a[mid])
        else:
            more += 1
            remain -= m
    if more >= p:
        return False
    if remain <= 0:
        return True
    hoge = p-more-1
    if (len(tmp) >= hoge+1 and tmp[hoge] >= remain) or (len(tmp) < hoge+1 and tmp[-1] >= remain):
        return True
    return False

left = 0
right = n
while right-left > 1:
    mid = (right+left)//2
    if check(mid):
        left = mid
    else:
        right = mid

print(left+1)


Measured memory_bytes: 116120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	string s; cin >> s;
	zep(i, 0, 3)cout << s[i];
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
#define INF 1<<20

struct edge{
	int to;
	int cost;
	edge() {};
	edge(int a, int b) {
		to = a;
		cost = b;
	}
};

struct Node {
	int pos;
	int cost;
	Node() {};
	Node(int a, int b) {
		pos = a;
		cost = b;
	}
	bool operator <(const Node& rhs) const {
		return cost > rhs.cost;
	}
};

void dijkistra(int st, int TO,int V,vector<vector<edge> > graph) {
	priority_queue<Node> q;
	vector<int> d(V);
	for (int i = 0;i < V;i++) {
		d[i] = INF;
	}
	d[st] = 0;
	q.push(Node(st, 0));
	while (!q.empty()) {
		Node s = q.top(); q.pop();
		int pos = s.pos;
		for (int i = 0;i < graph[pos].size();i++) {
			int to = graph[pos][i].to;
			int cost = graph[pos][i].cost;
			if (d[pos] + cost < d[to]) {
				d[to] = d[pos] + cost;
				q.push(Node(to, d[to]));
			}

		}
	}
	cout << d[TO] << endl;
}
int partition(int A[],int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p;j < r;j++) {
		if (x >= A[j]) {
			i = i + 1;
			swap(A[i], A[j]);
		}
	}
		swap(A[i + 1], A[r]);
		return i + 1;
}
void quicksort(int A[], int p, int r) {
	if (p < r) {
		int q = partition(A, p, r);
		quicksort(A, p, q-1);
		quicksort(A, q + 1, r);
	}
}

int getNumberOfCoin(int C[],int n,int m) {
	int T[50000];
	for (int j = 0;j <= n;j++) {
		T[j] = INF;
	}
	T[0] = 0;
	for (int i = 0;i < m;i++) {
		for (int j = 0;j <= n;j++) {
			if (j - C[i] >=0  ) {
				T[j] = min(T[j], T[j - C[i]] + 1);
			}
		}
	}
	return T[n];
}
int knapsack(int w, int n,int* v,int* ww) {
	int W[101][10001];
		for (int j = 0;j <= w;j++) {
			W[0][j] = 0;
		}
	for (int i = 0;i < n;i++) {
		for (int k = 0;k < n;k++){
			for (int j = 0;j <= w;j++) {
				if (j - ww[k] < 0) {
					W[i + 1][j] = W[i][j];
				}
				if (j - ww[i] >= 0) {
					W[i + 1][j] = max(W[i][j], W[i][j - ww[k]] + v[k]);

				}
			}
		}
	}
	return W[n][w];
}
int fib(int n) {
	vector<int> v(n+1);
	v[0] = 1;
	v[1] = 1;
	for (int i = 2;i < n+1;i++) {
		v[i] = v[i - 2] + v[i - 1];
	}
	return v[n];
}
int isPrime(int x) {
	if (x <= 1) return false;
	if (x>2 && x % 2 == 0) return false;
	for (int i = 2;i <= sqrt(x);i++) {
		if (x%i == 0) {
			return false;
		}
	}
	if (x == 2) return true;
	return true;
}
vector<long long int> a;
void Prime(int x) {
	vector<int> prime(x+1,1);
	int num = 2;
	while (num <= sqrt(x)) {
		a.push_back(num);
		for (int i = 2;i <= x / num;i++) {
			prime[num*i] = 0;
		}
		num++;
		while (prime[num] == 0)
			num++;
	}
	int count = 0;
	for (int i = 2;i < x + 1;i++) {
		if (prime[i] == 1) count++;
	}
	
}
int main() {
	string a;
	int sum = 0;
	while (cin >> a) {
		int len = a.length();
		int t = 0;
		for (int i = 0;i < len;i++) {
			if (a[i] <= '9'&&a[i] >= '0') t = t * 10 + int(a[i] - '0');
			else {
				sum += t;
				t = 0;
			}
		}
		sum += t;
	}
	cout << sum << endl;
	}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

string day[7] =  {"Sunny", "Cloudy", "Rainy"};

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


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<vector>
#include<queue>
#include<set>
#define ll long long
using namespace std;
const int maxn=1e5+5;

int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	int h[maxn]={0},flag[maxn]={0};
	int n,m,ans=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>h[i];
	}
	int ai,bi;
	for(int i=1;i<=m;i++){
		cin>>ai>>bi;
		if(h[ai]==h[bi]){
			if(!flag[ai]){
				flag[ai]=1;ans++;
			}
			if(!flag[bi]){
				flag[bi]=1;ans++;
			}
			continue;
		}
		if(h[ai]>h[bi])ai=bi;
		if(!flag[ai]){
				flag[ai]=1;ans++;
			}
	}
	cout<<n-ans;
    return 0;
}



Measured memory_bytes: 4420
A,B,C = map(int,input().split())
ans = 0
if ((A+B+C)-max(A,B,C))%2 == 0:
    ans = (max(A,B,C)*3-(A+B+C))//2
else:
    ans = (max(A,B,C)*3-(A+B+C))//2 + 2
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <limits>
#include <math.h>
#include <cmath>
#include <cctype>
#include <cstdio>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll> ;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vvll = vector<vector<long long >>;
#define PI  3.1415926535
#define rep(i, k, n) for(ll i = k; i < n; i++)

int main(){
  ll n; cin >> n;
  vvll shift (n, vll(10));
  vvll profit (n, vll(11));
  
  rep(i, 0, n){
    rep(j, 0, 10){
      cin >> shift[i][j];
    }
  }
  
  rep(i, 0, n){
    rep(j, 0, 11){
      cin >> profit[i][j];
    }
  }
  ll ans = -100000000000;
  for(ll bit = 1; bit < (1<<10); bit++){
    ll res = bit;
    vll s (0);
    while(res > 1){
      s.emplace_back(res%2);
      res /= 2;
    }
    s.emplace_back(1);
    
    while(s.size() < 10){
      s.emplace_back(0);
    }
    
    ll score = 0;
    rep(i, 0, n){
      ll ju = 0;
      rep(j, 0, 10){
        if(shift[i][j] && s[j]){
          ju++;
        }
      }
      score += profit[i][ju];
    }
    
    ans = max(ans, score);
  }
  cout << ans << endl;
}
      
    
  
  
    
    

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
static const int MAX = 1405;

int G[MAX][MAX];
int d[MAX][MAX];
int H, W;

int main()
{
    int maxWidth = 0;
    cin >> H >> W;
    for (int i = 1; i <= H; ++i)
    {
        for (int j = 1; j <= W; ++j)
        {
            cin >> G[i][j];
        }
    }
    for (int i = 0; i <= W; ++i)
    {
        d[0][i] = 0;
    }
    for (int i = 0; i <= H; ++i)
    {
        d[i][0] = 0;
    }
    for (int i = 1; i <= H; ++i)
    {
        for (int j = 1; j <= W; ++j)
        {
            if (G[i][j] == 1)
            {
                d[i][j] = 0;
            }
            else
            {
                d[i][j] = min(min(d[i-1][j-1], d[i-1][j]), d[i][j-1]) + 1;
                maxWidth = max(maxWidth, d[i][j]);
            }
        }
    }
    cout << maxWidth * maxWidth << endl;
    return 0;
}


Measured memory_bytes: 18460
////////////////////////////////////////////////////
//                                                //
//  For her who keeps the fire kindling in me...  //
//                                                //
////////////////////////////////////////////////////

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
// import java.util.Scanner;
// import java.util.Arrays;
// import java.util.ArrayList;
// import java.util.Collections; 
// import java.util.StringTokenizer;
import java.util.*;
import java.lang.Math;
import java.awt.Point;

import java.awt.geom.*;

class Main {

    public static void main(String args[]) {
        try {
            FastReader s = new FastReader();
            BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out));
            int i, j, k, v, x, y, t, n, key, size, poster, minglob, minloc, beg, end, begl, endr, ind, max, l, r;
            long ans, f, ansmin, count, mincount;
            boolean flag;

            //n = s.nextInt();
            //k = s.nextInt();
            //TreeSet<Integer> ts = new TreeSet<Integer>();
            //int arr[] = new int[n];
            String str = s.nextLine();
            String str2 = s.nextLine();
            
            

            count = 0l;
            for(i=0; i<3; i++)
                if(str.charAt(i)==str2.charAt(i))
                    count++;
                

            w.write(count + "\n");
            w.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

// ========================================### FAST IO
// ###=========================================//
class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

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

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

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

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

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

Measured memory_bytes: 23380
#include<cstdio>
#include<cstring>

int main(){
    char s[202], t[101], p[101];
    scanf("%s %s", s, p);
    strcpy(t, s);
    strcat(s, t);
    if(strstr(s,p) == NULL) printf("No\n");
    else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 2760
a = [list(map(int, input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
flag = False
for i in range(3):
    if all(a[i][j] in b for j in range(3)): #bの中にa[i][j]があるかどうか
        flag = True
    if all(a[j][i] in b for j in range(3)):
        flag = True
if all(a[i][i] in b for i in range(3)) or all(a[i][2-i] in b for i in range(3)):
    flag = True
 
if flag:
    print("Yes")
else:
    print("No")

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

int main(){
    int N;
    string S;
    cin>>N;
    for (int i=0;i<N;i++){
      cin>>S;
      if (S=="Y"){
          cout<<"Four"<<endl;
          break;
      }
    }
  if(S=="P"||S=="W"||S=="G"){
    cout<<"Three"<<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <set>
typedef long long ll;

int main(void) {
  ll i, n, ans = 0;
  scanf("%lld", &n);
  ll a, pos[n];
  for(i = 0; i < n; ++i) {
    scanf("%lld", &a);
    pos[--a] = i;
  }
  std::set<ll> s;
  std::set<ll>::iterator it;
  for(i = 0; i < n; ++i) {
    ll x = pos[i] + 1, y = n - pos[i];
    it = s.lower_bound(pos[i]);
    if(it != s.end()) y = (*it) - pos[i];
    if(it != s.begin()) x = pos[i] - *(--it);
    ans += x * y * (i + 1);
    s.insert(pos[i]);
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
int f[5050],a[5050],n,k,sum=0;
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;++i)scanf("%d",&a[i]),a[i]=min(a[i],k),sum+=a[i];
    sort(a+1,a+n+2),f[0]=1;
    for(int i=n+1;i;--i){
        bool check=true;
        for(int j=k-1;j>=k-sum&&j>=0;--j)if(f[j]){check=false;break;}
        if(check){printf("%d",i-1);return 0;}
        for(int j=k;j>=a[i];--j)f[j]|=f[j-a[i]];
        sum-=a[i];
    }
    return 0;
}


Measured memory_bytes: 256
/*
   Author: Shivam Shukla
*/
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pair<ll,ll> > vpll;
 
const int MOD=1e9+7;
const int MAX=1e5+5;
const double PI= acos(-1.0);
const long double EPS=1e-10;
const int64_t INF=1e18+10;
 
#define fastio() ios_base::sync_with_stdio(false);cin.tie(0), cout.tie(0)
#define trace(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vi vector<int>
#define vl vector<ll>
#define vs vector<str>
#define vc(x) vector<x>
#define mapll map<ll,ll>
#define mapib map<int,bool>
#define mapiv map<int,vector>
#define mapsi map<string,int>
#define rep(i,j,k) for(ll i=j;i<k;i++)
#define down(i,j,k) for(ll i=j;i>=k;i--)
#define repa(i,n) for(ll i=0;i<n;i++)
#define dowa(i,n) for(ll i=n;i>=0;i--)
#define reps(i,j,k,s) for(ll i=j;i<k;i+=s)
#define downs(i,j,k,s) for(ll i=j;i>=k;i-=s)
#define trv(i,x) for(auto i:x)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)x.size()
#define ff first
#define ss second
#define str string 
#define dub double
#define pqmax priority_queue<ll>
#define pqmin priority_queue<ll,vl,greater<ll> >
 
template<typename t> t lcm(t a, t b) {return (a*b)/__gcd(a,b);}
template<typename t> t gcd(t a, t b) {return __gcd(a,b);}
template<typename t> t mul_mod(t a, t b, t m){t res=((a%m)*(b%m)%m); return res;}
template<typename t> t add_mod(t a, t b, t m){t res=((a%m)+(b%m))%m; return res;}
template<typename t> t pow_mod(t a,t b,t m) {t res=1;while(b){if(b&1) res=mul_mod(res,a,m);a=mul_mod(a,a,m), b>>=1;} return res%m;}
template<typename t> vc(t) num_vec(t num) {t res; while (num) res.pb(num%10), num/=10; return res;}
template<typename t> t vec_num(t vec) {t res=0; ll mul=1; repa(i,sz(vec)) res=vec[i]*mul, mul*=10; return res;}
 

int32_t main(int argc,char** argv){
	fastio();
	auto tstart= clock();

    int n; cin >> n;
    vl a(n), cnt(n), c2(n); 
    repa(i, n) cin >> a[i], cnt[a[i] - 1]++;
    
    ll s = 0;
    repa(i, n){
       c2[i] = (cnt[i] * (cnt[i] - 1)) >> 1;
       s += c2[i];
    }

    repa(i, n) {
      cout << (s - cnt[a[i] -  1] + 1) << endl;
    }

    cerr<<setprecision(2)<<fixed<<"Time elapsed: "<<(double)(clock() - tstart)/CLOCKS_PER_SEC<<endl; 
    return 0; 
}

Measured memory_bytes: 7296
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a>=-1000 && b<=1000){
        if(a>b){
            printf("a > b\n");
        }
        else if(a<b){
            printf("a < b\n");
        }
        else if(a==b){
            printf("a == b\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2040
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#define N 4001
typedef struct {
	int num,
		sum,
		index;
}DATA;
void Initialization(DATA[], int *);
#include<stdio.h>
int main() {
	DATA d[N];
	int flg, n, e, p, q, index = 1, i;
	while (scanf("%d", &n), n != 0) {
		Initialization(d, &flg);
		for (n; n > 0; --n) {
			scanf("%d%d%d", &e, &p, &q);
			d[e].num = e;
			d[e].sum += p*q;
			if (d[e].index == 0)d[e].index = index++;
			flg = d[e].sum >= 1000000;
		}
		if (!flg) puts("NA");
		else {
			for (n = 1; n < index; n++) {
				for (i = 1; i < N; i++) if (d[i].index == n&&d[i].sum >= 1000000) printf("%d\n", d[i].num);
			}
		}
	}
	return 0;
}

void Initialization(DATA d[], int *flg) {
	int i;
	for (i = 1; i < N; i++) d[i].num = d[i].sum = d[i].index = 0;
	flg = 0;
}

Measured memory_bytes: 660
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
using namespace std;
int main() {
	int N;
	double cnt = 0;
	cin >> N;
	for (int i = 0; i < N; i++) { if ((i+1) % 2 == 1) { cnt += 1; } }
	//cout << cnt << endl;
	cout << cnt / N << endl;
		return 0;
}


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

#define pb push_back
#define ll long long

ll M= 1000000007;
ll pf[1000005];

int main() {

    ll n;
    cin>>n;
    vector<ll> v(n);
    memset(pf,0,sizeof(pf));
    for(ll i=0;i<n;i++) {
        cin>>v[i];
    }
    ll g=v[0];
    bool flag1=true;
    
    for(ll i=0;i<n;i++) {
        g = __gcd(g,v[i]);
        for(ll j=2;j*j<=v[i];j++) {
            if(v[i]%j==0) {
                pf[j]++;
                if(pf[j]>1) {
                    flag1=false;
                    break;
                }
                while(v[i]%j==0) {
                    v[i]=v[i]/j;
                }
            }
        }
        if(v[i]!=1) {
            pf[v[i]]++;
            if(pf[v[i]]>1)
            flag1=false;
        }
    }

    if(flag1) {
        cout<<"pairwise coprime"<<endl;
    } else if(g==1) {
        cout<<"setwise coprime"<<endl;
    } else {
        cout<<"not coprime"<<endl;
    }

    return 0;

}

Measured memory_bytes: 18816
S = list(input())
K = int(input())
R = []
hoge = 1
for i in range(1,len(S)):
    if S[i] == S[i-1]:
        hoge += 1
    else:
        R.append(hoge)
        hoge = 1
R.append(hoge)
ans = 0
if len(R) == 1:
    print((R[0]*K)//2)
    exit()
if S[0] == S[-1]:
    ans += (K-1)*((R[0]+R[-1])//2) + R[0]//2 + R[-1]//2
    R[0],R[-1] = 0,0
for i in R:
    ans += (i//2)*K 
print(ans)


Measured memory_bytes: 3064
var output;
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//1:数値へ変換 2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字に分割 7:1文字に分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
  var H = myconv(next(),1);
  var output = 1;
  while(H > 0){
    H = Math.floor(H / 2);
    output += output;
  }
  myout(output-1);
}

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF LLONG_MAX/10
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007
//最大公約数
int gcd(int s,int t){
    if(t==0)return s;
    return gcd(t,s%t);
}
signed main(){
    int n;
    cin>>n;
    int m[100001];
    int a[n];
    int wkey=0;
    rep(i,100001){
        m[i]=0;
    }
    rep(i,n){
        cin>>a[i];
        m[a[i]]++;
        wkey+=a[i];
    }
    int w;
    cin>>w;
    int b[w],c[w];
    rep(i,w){
        cin>>b[i]>>c[i];
    }
    int ans;
    rep(i,w){
        wkey+=(c[i]-b[i])*m[b[i]];
        ans=m[b[i]];
        m[c[i]]+=ans;
        m[b[i]]=0;
        cout<<wkey<<endl;
    }
}


Measured memory_bytes: 6700
/+ dub.sdl:
    name "B"
    dependency "dcomp" version=">=0.4.0"
+/

import std.stdio, std.algorithm, std.conv, std.range;
import std.container;

// import dcomp.scanner;

int main() {
    auto sc = new Scanner(stdin);
    int n;
    long a, b;
    long[] x;
    sc.read(n, a, b, x);

    long ans = 0;
    writeln(iota(0, n-1).map!(i => min(b, a * (x[i+1]-x[i]))).sum);
    return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray; 
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    string[] buf;
    private bool succ() {
        while (!buf.length) {
            if (f.eof) return false;
            buf = f.readln.split;
        }
        return true;
    }
    private bool readSingle(T)(ref T x) {
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {
                //string or char[10] etc
                x = buf.front;
                buf.popFront;
            } else {
                static if (isStaticArray!T) {
                    //static
                    assert(buf.length == T.length);
                }
                x = buf.map!(to!E).array;
                buf.length = 0;                
            }
        } else {
            x = buf.front.to!T;
            buf.popFront;            
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}

unittest {
    import std.path : buildPath;
    import std.file : tempDir;
    import std.algorithm : equal;
    import std.stdio : File;
    string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
    auto fout = File(fileName, "w");
    fout.writeln("1 2 3");
    fout.writeln("ab cde");
    fout.writeln("1.0 1.0 2.0");
    fout.close;
    Scanner sc = new Scanner(File(fileName, "r"));
    int a;
    int[2] b;
    char[2] c;
    string d;
    double e;
    double[] f;
    sc.read(a, b, c, d, e, f);
    assert(a == 1);
    assert(equal(b[], [2, 3]));
    assert(equal(c[], "ab"));
    assert(equal(d, "cde"));
    assert(e == 1.0);
    assert(equal(f, [1.0, 2.0]));
}


Measured memory_bytes: 3764
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7

ll mi(ll x, ll y){
    if(x<y)return x;
    return y;
}
int main(void){
    int p, q, r;
    scanf("%d %d %d", &p, &q, &r);
    int pq = p + q;
    int qr = q + r;
    int rp = r + p;
    int ans = mi(pq, mi(qr, rp));
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
<?php
define("MOD", 10**9+7);
$str = str();
$n = strlen($str);
for($j = 0; $j < 13; $j++){
  $dp[$n-1][$j] = 0;
}
if($str[$n-1] == "?"){
  for($i = 0; $i < 10; $i++){
    $dp[$n-1][$i] = 1;
  }
}else{
  $dp[$n-1][$str[$n-1]] = 1;
}
$c = 0;
$m = 1;
for($i = $n-2; $i>=0; $i--){
  $m*=10;
  $m%=13;
  for($j = 0; $j < 13; $j++){
    $dp[$i][$j] = 0;
  }
  if($str[$i] != "?"){
    $diff = $m*intval($str[$i])%13;
    for($j = 0; $j < 13; $j++){
      $dp[$i][($j+$diff)%13] = $dp[$i+1][$j];
    }
  }else{
    for($k = 0; $k < 10; $k++){
      $diff = $m*intval($k)%13;
      for($j = 0; $j < 13; $j++){
        $dp[$i][($j+$diff)%13] += $dp[$i+1][$j];
        $c+=$dp[$i+1][$j];
      }
    }
  }
  for($j = 0; $j < 13; $j++){
    $dp[$i][$j] = $dp[$i][$j] % MOD;
  }
}
echo $dp[0][5];


function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}

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

using namespace std;

class UnionFindCnt {
    private :
        std::vector<int> par;
        std::vector<int> cnt;
    public :
        UnionFindCnt(int n) {
            par.resize(n);
            cnt.resize(n);
            for (int i=0; i<n; i++) {
                par.at(i) = i;
                cnt.at(i) = 1;
            }
        }
        void unite(int x, int y) {
            const int x_par = find(x);
            const int y_par = find(y);
            if (x_par == y_par) return;

            par.at(x_par) = y_par;
            cnt.at(y_par) += cnt.at(x_par);
            cnt.at(x_par) = 0;
        }
        int find(int x) {
            if (par.at(x) == x) return x;
            else return par.at(x) = find(par.at(x));
        }
        bool same(int x, int y) { return find(x) == find(y); }
        int size(int x) { return cnt.at(find(x)); }
};

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  UnionFindCnt uf(n);
  vector<int> res(n);
  
  for (int i=0; i<m; i++) {
    int a, b;
    cin >> a >> b;
    res.at(a-1)--;
    res.at(b-1)--;
    uf.unite(a-1, b-1);
  }
  
  for (int i=0; i<k; i++) {
    int a, b;
    cin >> a >> b;
    if (uf.same(a-1, b-1)) {
      res.at(a-1)--;
      res.at(b-1)--;
    }
  }
  
  for (int i=0; i<n; i++) {
    cout << res.at(i) + uf.size(i) - 1;
    if (i == n-1) cout << endl;
    else cout << ' ';
  }
  
  return 0;
}


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <sys/time.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    int K;
    cin >> K;
    queue<long long> que;
    for (int i = 1; i < 10; ++i) que.push(i);
    for (int i = 0; i < K-1; ++i) {
        long long s = que.front();
        que.pop();
        for (int j = -1; j <= 1; ++j) {
            long long add = (s % 10) + j;
            if (add >= 0 && add <= 9) que.push(s * 10 + add);
        }
    }
    cout << que.front() << endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int bit = 0;
		for(int i = 0; i < n; i++) {
			a[i] = bit|sc.nextInt();
		}
		int maxBit = 0;
		for(int i = 0;i < n; i++) {
			maxBit += Integer.numberOfTrailingZeros(a[i]);
			}
		System.out.println(maxBit);
		}
	}

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

int main(){
	int N, M;
	cin >> N >> M;
	int L[M], R[M];
	rep(i,M) cin >> L[i] >> R[i];

	int pass[N+1];
	rep(i,N+1) pass[i] = 0;
	
	rep(i,M) {
		pass[L[i]-1] += 1;
		pass[R[i]] -= 1;
	}

			
	for (int i = 1; i <= N; i++) {
		pass[i] += pass[i-1];
	}

	int ans = 0;
	rep(i,N) if (pass[i] == M) ans++;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4752
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	string S;
	cin >> S;



	REP(i, S.size())cout << "x";
	cout << endl;
	return 0;
}



Measured memory_bytes: 256
/////////// <----------------------  Quicksilver_ ---------------------> ///////////

#include <iostream>
#include <bits/stdc++.h>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <map>
#include <iterator>
#include <iomanip>
#include <queue>
#include <utility>
#include <set>
#include <cstring>

using namespace std;
#define ll long long int
#define endl "\n"
#define c(x) ll x;cin>>x
#define cc(x,y) ll x,y;cin>>x>>y
#define ccc(x,y,z) ll x,y,z; cin>>x>>y>>z
#define db long double
#define fast cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false)
#define inf 200000000000000
#define mod 1000000007
#define eps 1e-7
#define PI 3.1415926535897932385
#define pb push_back
#define bitc  __builtin_popcountll
#define mp make_pair
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define len(x) (ll)(x).size()
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define foreach(it,ar) for (auto it = ar.begin(); it != ar.end(); it++)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define print(arr,n) rep(i,n) cout<<arr[i]<<" "; cout<<endl
#define print2(arr,n,m) rep(i,n){ rep(j,m) cout<<arr[i][j]<<" "; cout<<endl; }
#define dyn1(arr,n) ll* arr=new ll[n]; rep(i,n) arr[i]=0;
#define dyn2(arr,n,m) ll** arr=new ll*[(n)]; rep(i,n) arr[i]=new ll[m]; rep(i,n) rep(j,m) arr[i][j]=0
#define carr(arr,n) rep(i,n) cin>>arr[i]
#define carr2(arr,n,m) rep(i,n) rep(j,m) cin>>arr[i][j]
#define debug(a) cout<<" :: "<<#a<<" == "<<a<<endl
#define debug2(a,b) cout<<" :: "<<#a<<" == "<<a<<" :: "<<#b<<" == "<<b<<endl
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;

inline ll maxim(ll a,ll b) {if(a>b) return a; else return b;}
inline ll minim(ll a,ll b) {if(a<b) return a; else return b;}
inline bool equals(double a, double b){ return fabs(a - b) < 1e-9; }
ll gcd(ll a, ll b){ return b==0 ? a : gcd(b, a%b); }


ll binpow(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1) res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return res;
}


ll arr[1000010][2];
ll temp[1000010];
ll cost[1000010]={0};
ll mat[150][150]={0};

vector<ll> love;
map<pair<db,db> ,ll> centres;


int main()
{
  fast;
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  cout<<setprecision(10)<<fixed;
  c(k);
  ll total=0;
  fr(a,1,k)
  {
    fr(b,1,k)
    {
      fr(c,1,k)
      {
        total+=gcd(gcd(a,b),c);
      }
    }
  }
  cout<<total<<endl;

  return 0;
}


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


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int d;
	cin >> d;
	if (d == 25) cout << "Christmas" << endl;
	else if (d == 24) cout << "Christmas Eve" << endl;
	else if (d == 23) cout << "Christmas Eve Eve" << endl;
	else cout << "Christmas Eve Eve Eve" << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque

n = int(input())
a = deque(map(int, input().split()))
a.appendleft(0)
a.append(0)

lis = [a[0], a[1], a[2]]
S = abs(a[2])+sum([abs(a[k]-a[k+1]) for k in range(2, n+1)])
print(S)

for k in range(2, n+1):
    S += abs(lis[0]-lis[1])+abs(lis[1]-lis[2])-abs(lis[0]-lis[2])
    lis.pop(0)
    lis.append(a[k+1])
    S -= abs(lis[0]-lis[1])+abs(lis[1]-lis[2])-abs(lis[0]-lis[2])
    print(S)


Measured memory_bytes: 13536
#include <iostream>

using namespace std;

int main(){
	int sx, sy, tx, ty;

	cin >> sx >> sy >> tx >> ty;

	for(int i=0; i<(ty-sy); i++){
		cout << "U";
	}
	for(int i=0; i<(tx-sx); i++){
		cout << "R";
	}
	for(int i=0; i<(ty-sy); i++){
		cout << "D";
	}
	for(int i=0; i<(tx-sx); i++){
		cout << "L";
	}
	cout << "LU";
	for(int i=0; i<(ty-sy); i++){
		cout << "U";
	}
	for(int i=0; i<(tx-sx); i++){
		cout << "R";
	}
	cout << "RDRD";
	for(int i=0; i<(ty-sy); i++){
		cout << "D";
	}
	for(int i=0; i<(tx-sx); i++){
		cout << "L";
	}
	cout << "LU" << endl;

	return 0;

}





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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

const int MOD = 1000000007;

void Main()
{
    string ss;
    cin >> ss;
    int n = ss.size();
    vector<int> s(n);

    vector<vector<int>> dp(n);

    REP(i,n){
        if(ss[i] == '?'){
            s[i] = -1;
        }
        else{
            s[i] = ss[i] - '0';
        }
        //dump(s[i])
        dp[i].resize(13);
    }

    if(s[0] == -1){
        REP(i,10){
            dp[0][i] = 1;
        }
    }
    else{
        dp[0][s[0]] = 1;
    }

    for(int i=1;i<n;i++){
        if(s[i] != -1){
            REP(j,13){
                int next = (j*10+s[i])%13;
                dp[i][next] = (dp[i][next] + dp[i-1][j])%MOD;
            }
        }
        else{
            REP(j,13){
                REP(k,10){
                    int next = (j*10+k)%13;
                    dp[i][next] = (dp[i][next] + dp[i-1][j])%MOD;
                }
            }
        }
    }

    cout << dp[n-1][5] << endl;


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

    return 0;
}

Measured memory_bytes: 9424
N, K = map(int, input().split())
S = input()

s = []
cnt = 1
for i in range(N-1):
    if S[i] == S[i+1]:
        cnt += 1
    else:
        s.append(cnt)
        cnt = 1
s.append(cnt)

ans = 0
if S[0] == '0':
    s = [0] + s
if S[-1] == '0':
    s = s + [0]

if 2*K + 1 > len(s):
    print(sum(s))
    exit()

s_cumsum = [s[0]] * len(s)
for i in range(1, len(s)):
    s_cumsum[i] = s_cumsum[i-1] + s[i]
    
for i in range(0, len(s), 2):
    if i + 2*K >= len(s):
        break
    if i < 1:
        ans = s_cumsum[i+2*K]
    ans = max(ans, s_cumsum[i+2*K]-s_cumsum[i-1])
    #ans = max(ans, sum(s[i:i+2*K+1]))

print(ans)

Measured memory_bytes: 13732
#include <stdio.h>

long pow(long n, long m){
    long ret = 1;
    for(long i=0;i<m;i++){
        ret *= n;
    }
    return ret;
}

int main(void){

    long n, m;
    scanf("%ld %ld", &n, &m);

    long s[m], c[m];
    for(long i=0;i<m;i++){
        scanf("%ld %ld", &s[i], &c[i]);
    }

    long min, max;
    min = pow(10, n-1);
    max = pow(10, n)-1;
    if(n==1) min=0;
    long dig[n];
    for(long i=min;i<=max;i++){
        for(long j=0;j<n;j++){
            dig[j] = (i/pow(10, n-1-j))%10;
        }
        long cnt = 0;
        for(long j=0;j<m;j++){
            if(dig[s[j]-1] == c[j]){
                cnt++;
            }
        }
        if(cnt == m){
            printf("%ld\n", i);
            return 0;
        }
    }
    printf("-1\n");

    return 0;
}

Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

int main() {
    int N;
    cin >> N;
    vector<bool>sieve(1000011);

    vector<int>As(N);
    for (int i=0; i<N; i++){
        cin >> As[i];
        sieve[As[i]] = true;
    }
    int ans = 0;
    //0, 4, 6, 7, 9
    sort(all(As));
    for (int i=0; i<N; i++){
        int ai = As[i];
        if (sieve[ai]){
            int j=1;
            while (j*ai < 1000001){
                sieve[ai*j] = false;
                j++;
            }
            if ( i == N-1  ||  As[i] % As[i+1] != 0){
                ans++;
                //cout << i << endl;
            }
        }
    }
    
    cout << ans << endl;

}

Measured memory_bytes: 4320
//M(int*a){return*a-*1[&a];}
M(int*a,int*b){return*a-*b;}
n,T[1000000][2];
i,j,m,s;
main(){
	for(;scanf("%d",&n),n;){
		for(i=n;i--;){
			scanf("%d",T[i]+1);
			*T[i]=0;
			for(j=4;j--;){
				scanf("%d%d",&m,&s);
				*T[i]+=m*60+s;
			}
		}
		qsort(T,n,8,M);
		printf("%d\n%d\n%d\n",T[0][1],T[1][1],T[n-2][1]);
	}
	exit(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <map>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;
#define ALL(V) (V).begin(),(V).end()

struct res_t {
    string name;
    int point;
    int no;
    res_t(string n="", int p=0, int nn=0):name(n),point(p),no(nn){}
    friend bool operator<(const res_t& a,const res_t& b){
        if (a.name != b.name) return a.name < b.name;
        return a.point > b.point;
    }
};

int main() {
    int n;
    cin >> n;
    vector<res_t> vec(n);
    for (int i=0;i<n;i++) {
        cin >> vec[i].name >> vec[i].point;
        vec[i].no = (i+1);
    }
    sort(ALL(vec));

        
    for (int i=0;i<n;i++)
        cout << vec[i].no << endl;

    return 0;
}


Measured memory_bytes: 256