akhauriyash/Code-Regression huggingface dataset:
use std::collections::HashMap;

fn main() {
    let n: usize = read_line().unwrap().parse().unwrap();
    let mut scores: HashMap<String, u32> = HashMap::with_capacity(n);

    let mut max_count = 0;

    while let Some(s) = read_line() {
        let count = scores.entry(s).or_insert(0);
        *count += 1;
        max_count = std::cmp::max(max_count, *count);
    }

    let mut scores: Vec<(&String, &u32)> = scores.iter().filter(|a| {a.1 == &max_count}).collect();
    scores.sort_by_key(|x| {x.0});
    for (s, _) in scores {
        println!("{}", s);
    }
}

fn read_line() -> Option<String> {
    let stdin = std::io::stdin();
    let mut buf = String::new();
    match stdin.read_line(&mut buf) {
        Ok(_) => {
            let s = buf.trim();
            if s == "" {None} else {Some(String::from(s))}
        },
        Err(_) => None
    }
}


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

#define INF INT_MAX
#define UINF UINT_MAX
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef std::pair<int,int> pii;

using namespace std;

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

    ll n,a,b;
    cin >> n >> a >> b;

    ll ans = (n/(a+b))*a;
    ans += (n%(a+b)) > a ? a:(n%(a+b));

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

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	for (int i=1;;i++)
	{
		if(a*i%b==c)
		{
			cout<<"YES";
			return 0;
		}
		if(i>1000)
		{
			cout<<"NO";
			return 0;
		}
	}
}

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

int main(){
    int N,sum=0,ans1=0,ans2=0,ave1,ave2;
    cin>>N;
    vector<int> X(N);
    for(int i=0;i<N;i++){
        cin>>X.at(i);
        sum += X.at(i);
    }
    
    ave1 = (sum+N-1)/N ;
    ave2 = sum/N;
    for (int i=0;i<N;i++){
        ans1 += (ave1-X.at(i))*(ave1-X.at(i));
    }
    for (int i=0;i<N;i++){
        ans2 += (ave2-X.at(i))*(ave2-X.at(i));
    }
    cout<<min(ans1,ans2)<<endl;
}

Measured memory_bytes: 256
def resolve():
    import sys
    input = sys.stdin.readline
    n=int(input())
    a=sorted(list(map(int,input().split())))
    ma=a[-1]
    pn=[i for i in range(ma+1)]
    for i in range(2,ma//2+1):
      j=2
      while j*i<=ma:
        pn[j*i]=min(pn[j*i],i)
        j+=1
    chk=[0]*(ma+1)
    for i in a:
      if i==1:
        continue
      x=pn[i]
      chk[x]+=1
      while x!=i:
        while i%x==0:
          i//=x
        x=pn[i]
        chk[x]+=1
    ans=2
    for i in chk[2:]:
      if i==n:
        ans=0
        break
      if i>=2:
        ans=1
    if ans==2:
      print('pairwise coprime')
    elif ans==1:
      print('setwise coprime')
    else:
      print('not coprime')

if __name__ == '__main__':
    resolve()

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

int f(int a){
	if (a % 2 == 0)
	{
		return a / 2;
	} else {
		return 3*a + 1;
	}
}

int main(){
	int s; cin >> s;
	bool found_once = false;
	int count = 1;	

	if (s==1){
		cout << 4 << endl;
		return 0;
	} else if(s==2 ){
		cout << 4 << endl;
		return 0;
	}

	while(true){
		if (s==4){
			if (found_once)
			{
				break;
			} else {
				found_once = true;
			}
		}
		s = f(s);
		++count;
	}
	cout << count << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[100000][3];
int main()
{
	int f=1,i, j, n;
	cin >> n;
	for(i=0;i<n;i++)
	{
		cin >> a[i][0]>>a[i][1]>>a[i][2];
		if((a[i][2]+a[i][1]>a[i][0])||a[i][0]%2!=(a[i][1]+a[i][2])%2)
		{
			f=0;
		}
	}
	if(f==1)
	{
		cout <<"Yes"<<endl;
		return 0;
	}
	else
	{
		cout <<"No"<<endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 1408
N = int(input())
def ans(N):
  count = 0
  for i in range(1,N):
    for j in range(i,int(N/i)+1):
      if N-i*j>=1 and i!=j:
        count += 2
      elif N-i*j>=1 and i==j:
        count += 1
  return count

print(ans(N))

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


void solve(long long X, long long Y, long long Z){
    cout << Z << " " << X << " " << Y << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    long long Z;
    scanf("%lld",&Z);
    solve(X, Y, Z);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int q;
    cin >> q;
    vector<ll> p(31, 1);
    for (int i = 0; i < 30; i++) {
        p[i + 1] = p[i] * 3;
    }
    while (q--) {
        ll a, b, c, d;
        cin >> a >> b >> c >> d;
        a--, b--, c--, d--;
        if (abs(b - d) < abs(a - c)) {
            swap(a, b);
            swap(c, d);
        }
        ll ans = abs(a - c) + abs(b - d);
        for (int i = 29; i >= 0; i--) {
            if (a / p[i] % 3 != 1 || c / p[i] % 3 != 1) {
                continue;
            }
            if (a / p[i] != c / p[i]) {
                continue;
            }
            if ((b / p[i] + 2) / 3 == (d / p[i] + 2) / 3) {
                continue;
            }
            ans = abs(b - d);
            ans += min(a % p[i + 1] - p[i] + 1 + c % p[i + 1] - p[i] + 1, p[i] * 2 - a % p[i + 1] + p[i] * 2 - c % p[i + 1]);
            break;
        }
        cout << ans << '\n';
    }
    return 0;
}


Measured memory_bytes: 384
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	stack<double> S;
	char buf[128];

	while(fgets(buf, 128, stdin) != NULL)
	{
		istringstream is( buf );
		string str;
		double a, b;
		while(is >> str)
		{
			if(str == "+")
			{
				a = S.top(); S.pop();
				b = S.top(); S.pop();
				S.push(b+a);
			}
			else if(str == "-")
			{
				a = S.top(); S.pop();
				b = S.top(); S.pop();
				S.push(b-a);
			}
			else if(str == "*")
			{
				a = S.top(); S.pop();
				b = S.top(); S.pop();
				S.push(b*a);
			}
			else if(str == "/")
			{
				a = S.top(); S.pop();
				b = S.top(); S.pop();
				S.push(b/a);
			}
			else
			{
				S.push( (double)( to_int(str) ) );
			}
		}
		printf("%f\n",S.top());
	}
}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl '\n'
#define minimum(a,b) if(a>b) a=b;
#define what_is(x) cerr << #x << ": " << x << endl;
typedef vector<vector<ll>> matrix;
const ll INF = 1e9+5;
const int MAX = 2e5+4;
const int MOD = 1e9+7;
const int BIG = 100000005;
//vector<vector<ll>> dp(MAX,vector<ll>(3));
//vector<ll> dp(MAX);
template <typename T> void max_self(T& a,T b)
{
	a=max(a,b);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n,d;
	cin >> n >> d;
	int a[n][d];
	vector<int> dp;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<d;j++)
		{
			cin >> a[i][j];
		}
	}
	double c=0;
	int ans=0;
	for(int i=0;i<n;i++)
	{
		for(int k=i+1;k<n;k++)
		{
			for(int j=0;j<d;j++)
			{
				c+=pow(abs(a[i][j]-a[k][j]),2);
			}
			c=sqrt(c);
			if(c==int(c)) ans++;
			c=0;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lli         long long int
#define pb          push_back
#define pll         pair<lli,lli>
#define vl          vector<lli>
#define mp          make_pair
#define vll         vector<pll>
#define mll          map<lli,lli>
#define mpl         map<pii,lli>
#define endl        '\n'
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)  for(i=a;i<b;i++)
#define it(b)       for(__typeof(b.begin())it=b.begin();it!=b.end();it++)

using namespace std;


//binary search 
lli b_s(lli a[],lli l,lli r,lli result)
{ lli m;
    while(r>=l)
    {
        m=l+(r-l)/2;
        if(a[m]==result)
        return m;
        else if(a[m]>result)
        r=m-1;
        else
        l=m+1;
    }
    return -1;
}

/*


//dfs

void initialize() {
    for(int i = 0;i < nodes;++i)
     visited[i] = false;
}

lli nodes;
vector <lli> adj[nodes];
bool visited[nodes];
void dfs(int s) 
{
    visited[s] = true;
    for(int i = 0;i < adj[s].size();++i)  
    {
     if(visited[adj[s][i]] == false)
         dfs(adj[s][i]);
    }
}

*/


//bfs




//mastermind
void solve ()
{   lli n,m,i,s=0;
    cin>>n;
    lli f[n];lli h[n];
    rep(i,0,n) cin>>h[i];
    f[0]=0;
    f[1]=abs(h[1]-h[0]);
    rep(i,2,n)
    {
        f[i]=min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]));
       // cout<<f[i]<<" ";
    }
    cout<<f[n-1];

}



//driver code
int main ()
{
  ios::sync_with_stdio (false);
  cin.tie (0);
  cout.tie (0);

  lli t=1;
// cin >> t;
  while (t--)
    {
      solve ();
    }
  return 0;
}



Measured memory_bytes: 5160
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int 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; }
signed main(void){
    int a,b,c,d; cin>>a>>b>>c>>d;
    if(a != c) cout<<1<<endl;
    else cout<<0<<endl;
}


Measured memory_bytes: 256
(let ((n (read))
      (ht (make-hash-table :test #'equal))
      (temp)
      (ans 0))
     (dotimes (i n)
       (setf temp (read-line))
       (sort temp #'char-lessp)
       (if (gethash temp ht) (setf (gethash temp ht) (1+ (gethash temp ht)))
                             (setf (gethash temp ht) 1)))
     (maphash (lambda (key val)
                      (incf ans (/ (* val (1- val)) 2)))
              ht)
     (princ ans))

Measured memory_bytes: 51560
import math
n,m = input().split()
n = int(n)
m = int(m)
if n - m > 1 or m - n > 1:
    print(0)
elif n == m:
    print(2*math.factorial(n)*math.factorial(m)%1000000007)
else:
    print(math.factorial(n)*math.factorial(m)%1000000007)

Measured memory_bytes: 5184
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <climits>
#include <cfloat>

using namespace std;

const double PI = 4*atan(1.0);

int main()
{
	while (true)
	{
		int n;
		scanf("%d", &n);
		if (n == -1)
			break;

		double x = 1;
		double y = 0;
		for (int i = 1; i < n; ++i)
		{
			double angle = atan(y/x) + (x >= 0 ? 1 : -1)*PI/2;
			x += cos(angle);
			y += sin(angle);
		}
		printf("%.2f\n%.2f\n", x, y);
	}

	return 0;
}

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

int bubble(vector<string> &v) {
  int n = 0;
  for (int i = 0; i < v.size(); i++) {
    for (int j = v.size() - 1; j > i; j--) {
      if (v[j].at(1) < v[j - 1].at(1)) {
        swap(v[j], v[j-1]);
        n++;
      }
    }
  }
  return n;
}

int selection(vector<string> &v) {
  int n = 0;
  for (int i = 0; i < v.size(); i++) {
    int mini = i;
    for (int j = i; j < v.size(); j++) {
      if (v[j].at(1) < v[mini].at(1)) {
        mini = j;
      }
    }
    if (i != mini) {
      swap(v[i], v[mini]);
      n++;
    }
  }
  return n;
}

void print_array(vector<string> v) {
  int N = v.size();
  for (int i = 0; i < N; i++) {
    cout << v.at(i);
    if (i != N-1) cout << " ";
  }
  cout << endl;
}

int main() {
  int N;
  cin >> N;
  vector<string> v1(N);
  vector<string> v2(N);
  for (int i = 0; i < N; i++) {
    string s;
    cin >> v1.at(i);
    v2.at(i) = v1.at(i);
  }
  int num = bubble(v1);
  print_array(v1);
  cout << "Stable" << endl;
  num = selection(v2);
  print_array(v2);
  if (v1 == v2) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }
}


Measured memory_bytes: 3184
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		char c[] = s.toCharArray();
		int n = 1;
		for (int i = 0; i < s.length() - 1; i++) {
			if (c[i] != c[i + 1]) {
				n++;
			}
		}
		int x[] = new int[n];
		Renzoku(c, x);
int y[]=new int[x.length/2];
y[0]=x[0]-1;
for(int i=1;i<y.length;i++){
	y[i]=y[i-1]+x[2*i]+x[2*i-1];
}

int mark=0;
for(int i=0;i<c.length;i++){
if(i!=y[mark]){
	System.out.print(0+" ");
}else{
	int ans=(x[mark*2]/2)+(x[mark*2]%2)+(x[mark*2+1]/2);
	int ans2=(x[mark*2]/2)+(x[mark*2+1]%2)+(x[mark*2+1]/2);
	System.out.print(ans+" ");
	System.out.print(ans2+" ");
	mark++;
	if(mark>=y.length){
		mark--;
	}
	i++;
}
}

System.out.println();
	}

	public static int Renzoku(char c[], int x[]) {

		int mode = 0;
		int val = 0;

		for (int i = 0; i <= c.length - 2; i++) {
			if ((c[i] == c[i + 1]) && i != c.length - 2) {
				val++;
			} else {
				if ((c[i] == c[i + 1]) && i == c.length - 2) {
					val++;
				}
				val++;
				x[mode] = val;
				mode++;

				if ((c[i] != c[i + 1]) && i == c.length - 2) {
					x[mode] = 1;
					mode++;
				}

				val = 0;
			}

		}
		return mode;

	}
	static void show(int x[]){
		for(int i=0;i<x.length;i++){
			System.out.print(x[i]+" ");
		}
		System.out.println();
	}
}


Measured memory_bytes: 52796
house = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for z in range(n):
    a,b,c,d = map(int,input().split())
    house[a-1][b-1][c-1] += d
for e in range(4):
    for f in range(3):
        for g in range(10):
            print(" "+str(house[e][f][g]),end = "")
        print()
    if e != 3:
        print("#"*20)


Measured memory_bytes: 5624
while true
    n, k = gets.chomp.split.map(&:to_i)
    break if [n, k] == [0, 0]
    arr = []
    k.times{arr << gets.to_i}
    arr.sort!
    max = 1
    if arr.length == 1
        puts max
    else
        blank = arr[0] == 0
        arr.delete 0
        arr2, prev = [[arr[0], arr[0]]], arr[0]
        arr[1..-1].each{|x|
            if x == prev + 1
                arr2[-1][1] = x
            else
                arr2 << [x, x]
            end
            prev = x
        }
        if blank
            max = arr2[0][1] - arr2[0][0] + 2
            arr2.each_cons(2){|left, right|
                l = right[1] - right[0] + 2
                l += left[1] - left[0] + 1 if left[1] + 2 == right[0]
                max = l if max < l
            }
        else
            arr2.each{|a, b| max = b - a + 1 if max < b - a + 1}
        end
        puts max
    end
end



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

int main()
{
    ll A, B;
    cin >> A >> B;
    if (A == 1)
    {
        cout << B;
        return 0;
    }
    else if (B == 1)
    {
        cout << A;
        return 0;
    }

    if (A < B)
    {
        swap(A, B);
    }
    ll x = A * B;
    /* ユークリッドの互除法 */
    ll r = A % B;
    while (r != 0)
    {
        A = B;
        B = r;
        r = A % B;
    }
    cout << x / B << endl;
}

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

using namespace std;

int main(){
  int n;
  cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++){
	cin>>v[i];
  }
  
  sort(v.begin(),v.end());
  long long sum=0;
  for(int i=1;i<n;i++){
      sum+=v[n-1-i/2];
  }
	cout<<sum;
  return 0;
}

Measured memory_bytes: 4016
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  int n;cin >> n;
  cout << n/3 << endl;
}


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

int n,p1=0,p2=0;
string str1 ,str2;

int solve(int n) {
	
}
int main() {
	cin >> n ;
	for (int i = 0; i < n; i++) {
		cin >> str1 >> str2;
		if (str1==str2) {
			p1++;
			p2++;
		}
		else if(str1>str2) p1+=3;
		else p2+=3;
	}
	cout << p1 << " " << p2 << endl;
}


Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

const int Inf = 1e9;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector <vector <int>> g(n);
  for (int i = 0; i + 1 < n; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int ans = Inf; 
  for (int root = 0; root < n; ++root) {
    vector <int> cnt(n);
    vector <int> pot(n);
    vector <int> mn(n);
    function <void(int, int)> dfs = [&] (int u, int p) {
      cnt[u] = s[u] - '0';
      vector <int> gs;
      for (auto v : g[u]) {
        if (v != p) {
          gs.push_back(v);
          dfs(v, u);
          pot[u] += pot[v];
          pot[u] += cnt[v];
          cnt[u] += cnt[v];
        }
      }
      int sum = 0;
      int mx = 0;
      for (auto v : gs) {
        sum += pot[v] + cnt[v];
        mx = max(mx, pot[v] + cnt[v]);
      }
      mn[u] = sum;
      mn[u] = min(mn[u], max(0, 2 * mx - sum));
      for (auto v : gs) {
        int od = pot[v] + cnt[v];
        int nw = mn[v] + cnt[v];
        if (od == mx) {
          int nsum = sum - od + nw; 
          mn[u] = min(mn[u], max(0, 2 * nw - nsum));
        }
      }
      mn[u] = max(mn[u], sum % 2);
    };
    dfs(root, -1);
    if (mn[root] == 0) ans = min(ans, pot[root] / 2);
  } 
  cout << (ans == Inf ? -1 : ans) << '\n';
}



Measured memory_bytes: 4088
N = int(input())
A = [int(_) for _ in input().split()]

ans = 0
MOD = 10**9+7
for i in range(60):
    b = 1 << i
    cnt_1 = sum([a & b for a in A]) >> i
    cnt_0 = N - cnt_1
    b_sum = cnt_1 * cnt_0
    ans += (b_sum << i) % MOD
print(ans%MOD)


Measured memory_bytes: 42156
#include <bits/stdc++.h> 
// #include <atcoder/all>

using namespace std;
// using namespace atcoder;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}

const int mod = 1000000007;
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
void printVec(std::vector<char> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}


int main() {
    int n;
    cin >>n;
    vector <ll> a(n);
    rep(i,0,n) {
        cin >> a[i];
    }
    ll count = 0;
    ll ma = 0;
    rep(i,0,n) {
        while(a[i]%2 == 0) {
            ++count;
            a[i]/= 2;
            ma = max(ma,count);
        }
    }
    cout << ma << endl;
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

class Eratosthenes {
    vector<int> plist;

public:
    Eratosthenes(int sz)
        : plist(sz, -1) {
        for (int i = 2; i < sz; i++) {
            if (plist[i] == -1) {
                for (int j = i; j < sz; j += i) {
                    if (plist[j] == -1) {
                        plist[j] = i;
                    }
                }
            }
        }
    }
    bool isPrime(int n) {
        return plist[n] == n;
    }
    vector<int> factor(int n) {
        vector<int> res;
        while (n > 1) {
            res.push_back(plist[n]);
            n /= plist[n];
        }
        return res;
    }
};

#include <map>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin, n;
    Eratosthenes primes(n + 10);
    ll ans = 0;
    REP(i, 1, n) {
        int c = n - i;
        auto v = primes.factor(c);
        map<int, int> s;
        for (auto vv : v) {
            s[vv]++;
        }
        ll d = 1;
        for (auto [a, b] : s) {
            d *= (b + 1);
        }
        ans += d;
    }
    print(ans);
    return 0;
}


Measured memory_bytes: 7156
#include<iostream>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>

using namespace std;
int n;
int a,b;
void init()
{
cin>>a>>b;
cout<<a+b/2<<endl;
}
void work()
{

}

int main()
{
    init();
    work();
    return 0;
}




Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<ctime>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		return F?n:-n;
	}
}
int a[111111];
int mem[33333];
int* cnt=mem+11111;
int main()
{
	int n=io::F();
	for(register int i=1;i<=n;++i)a[i]=io::F();
	int ans=0;
	for(register int i=0;i<=n;++i)
		ans+=abs(a[i+1]-a[i]);
	for(register int i=1;i<=n;++i)
		printf("%d\n",ans-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1]));
	return 0;
}

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


int main(){
	string s;
	cin>>s;
	
	int flag=1;
	int tmp;
	
	if(s.size()<6)flag=0;
	
	tmp=1;
	for(int i=0;i<s.size();i++){
		if('0'<=s[i] && s[i]<='9')tmp=0;
	}
	if(tmp)flag=0;
	
	tmp=1;
	for(int i=0;i<s.size();i++){
		if('a'<=s[i] && s[i]<='z')tmp=0;
	}
	if(tmp)flag=0;
	
	tmp=1;
	for(int i=0;i<s.size();i++){
		if('A'<=s[i] && s[i]<='Z')tmp=0;
	}
	if(tmp)flag=0;
	
	
	if(flag)cout<<"VALID\n";
	else cout<<"INVALID\n";
	
	
	return 0;
}


Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=2147483647;
const double pi=3.1415926535897932384626;
inline ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
const ll mod=998244353;
const int maxn=3e3+5;
ll n,s,x,f[maxn];
int main(){
	n=read(),s=read();
	f[0]=1;
	for(int i=1;i<=n;i++){
		x=read();
		for(int j=s;j>=0;j--){
			if(f[j]){
				if(j+x<=s) f[j+x]=(f[j+x]+f[j])%mod;
				f[j]=f[j]*2%mod;
			}
		}
	}
	printf("%lld\n",f[s]);
	return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  bool ans = false;
  rep(i, n){
    char in;
    cin >> in;
    if(in == 'Y') ans = true;
  }
  if(ans == true) cout << "Four" << endl;
  else cout << "Three" << endl;
  return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x)end()
#define sz(x) (int)(x).size
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const int INF = 2000000000;
const int maxn = 0;

int main ()
{
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    if (b < c || d < a) printf("0\n");
    else printf("%d\n",min(b,d) - max(a,c));

    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

vector<string> get_ptn() {
  string a = "ACGT";
  vector<string> ans(64, "***");
  rep(i, 4 * 4 * 4) {
    ans[i][0] = a[i / 16];
    ans[i][1] = a[(i / 4) % 4];
    ans[i][2] = a[i % 4];
  }

  ans.erase(find(all(ans), "AGC"));
  ans.erase(find(all(ans), "ACG"));
  ans.erase(find(all(ans), "GAC"));
  return ans;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n;
  cin >> n;

  const auto keys = get_ptn();

  vector<map<string, ll>> dp(n + 1);
  FORm(it, keys) {
    dp[3][*it] = 1;
  }

  for (int i = 4; i <= n; i++) {
    FORm(it, keys) {
      FORm(pv, dp[i - 1]) {
        if ((*it)[0] != pv->first[1] || (*it)[1] != pv->first[2]) {
          continue;
        }
        if (pv->first[0] == 'A' && (*it)[2] == 'C') {
          if ((*it)[0] == 'G') {
            continue;
          }
          if ((*it)[1] == 'G') {
            continue;
          }
        }
        dp[i][*it] += pv->second;
        dp[i][*it] %= mod;
      }
    }
  }

  ll ans = 0;
  FORm(it, dp[n]) {
    ans = (ans + it->second) % mod;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--) 
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    ll N,D;
    cin >> N >> D;

    ll X[N][D];
    rep(i,0,N){
        rep(j,0,D){
            cin >> X[i][j];
        }
    }
    ll cnt =0;
    rep(i,0,N-1){
        rep(j,i+1,N){
            ll NN=0;
            rep(k,0,D){
                NN+=(X[i][k]-X[j][k])*(X[i][k]-X[j][k]);
            }
            ll jd =0;
            while(NN>=(jd*jd)){
                if(NN==jd*jd){
                    cnt++;
                }
                jd++;
            }
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
/*??????????????????????????¨?????????????????¨?????????*/
typedef struct{
	long long int prev;
	long long int next;
	long long int data;
} list;
list L[2000000];
long long int ff = -1,bb = -1;//ff ?????? bb ??????
long long int num = 0,usecnt = -1;//????????????????????¨???????????????


int main(){
	int i,j,k;
	long long int n;
	scanf("%lld",&n);
	for(i=0; i<n; i++){
		char op[20];
		scanf("%s",op);
		if(strcmp(op,"insert")==0){
			long long int p;
			scanf("%lld",&p);
			if(num==0){
				L[usecnt+1].data = p;
				ff = usecnt+1;
				bb = usecnt+1;
				usecnt++;
				num++;
			}else{
				L[usecnt+1].data = p;
				L[usecnt+1].next = ff;
				L[ff].prev = usecnt+1;
				ff = usecnt+1;
				usecnt++;
				num++;
			}
		}else if(strcmp(op,"delete")==0){
			long long int p;
			scanf("%lld",&p);
			long long int nowcnt = 0;
			long long int nowpos = ff;
			long long int tg = L[nowpos].data; // target
			while(nowcnt<num){
				if(tg==p){
					if(nowcnt==0){
						ff = L[ff].next;
						num--;
					}else if(nowcnt==num-1){
						bb = L[bb].prev;
						num--;
					}else{
						L[L[nowpos].prev].next = L[nowpos].next;
						L[L[nowpos].next].prev = L[nowpos].prev;
						num--;
					}
					break;
				}
				tg = L[L[nowpos].next].data;
				nowcnt++;
				nowpos = L[nowpos].next;
			}
		}else if(strcmp(op,"deleteFirst")==0){
			ff = L[ff].next;
			num--;
		}else if(strcmp(op,"deleteLast")==0){
			bb = L[bb].prev;
			num--;
		}
		/*long long  int pos = ff;
		while(pos!=bb){
			printf("%lld ",L[pos].data);
			pos = L[pos].next;
		}
		printf("%lld\n",L[pos].data);
		printf("\n");*/
	}
	long long  int pos = ff;
	while(pos!=bb){
		printf("%lld ",L[pos].data);
		pos = L[pos].next;
	}
	printf("%lld\n",L[pos].data);
	return 0;
}

Measured memory_bytes: 27644
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++) 

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

   
        for (int k = A; k <= B; k++) {
            if (k < A+K || k > B-K) {
                if (k != A) cout << " ";
                cout << k; 
            }
        }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    int k = 0;
    for(int t=1; t<n; ++t){
        k = a[k];
        if(k == 1){
            cout << t << endl;
            return 0;
        }
    }

    cout << -1 << endl;
    return 0;
}


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

int gcd(int x, int y);

const int INF = 1001001001;

/*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 { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/


int main() {
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    rep(i, n) cin >> s[i];
    sort(s.begin(), s.end());

    string ans = "";
    rep(i, n) {
        ans += s[i];
    }

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

template<class T> map<T, int> factor(T n) {
  map<T, int> res;
  for (T i = 2; i * i <= n; i++) while (n % i == 0) res[i]++, n /= i;
  if (n != 1) res[n]++;
  return res;
}

const lint mod = 1e9 + 7;
inline lint emod(lint a, lint p = mod) { return (a % p + p) % p; }
inline lint invm(lint a, lint p = mod) { a %= p; return a == 1 ? 1 : -p / a * invm(p % a) % p; }

V<lint> fact, ifact;
void init_table(int n) {
  fact.assign(n + 1, 1), ifact.assign(n + 1, 1);
  for (int i = 2; i < n + 1; i++) fact[i] = i * fact[i - 1] % mod;
  ifact[n] = invm(fact[n]);
  for (int i = n; i > 2; i--) ifact[i - 1] = i * ifact[i] % mod;
}

lint comb(lint n, lint r) {
  if (n < 0 or r < 0 or r > n) return 0;
  return fact[n] * ifact[r] % mod * ifact[n - r] % mod;
}

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  init_table(n + 100);
  auto mp = factor(m);
  lint res = 1;
  for (auto&& e : mp) {
    (res *= comb(n + e.second - 1, n - 1)) %= mod;
  }
  cout << emod(res) << '\n';
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define THE using
#define DARK namespace
#define ONE std
#define dbg(x) cout << #x << " = " << x << endl

THE DARK ONE;
int64_t N, c;
void dfs(uint64_t n){
    if(n > N){
        return;
    }
    dfs(n * 10 + 7);
    dfs(n * 10 + 5);
    dfs(n * 10 + 3);
    string num = to_string(n);
    int cnt7 = 0, cnt5 = 0, cnt3 = 0;
    for(char c: num){
        switch(c){
            case '7':{
                cnt7++;
                break;
            }
            case '5':{
                cnt5++;
                break;
            }
            case '3':{
                cnt3++;
                break;
            }
        }
    }
    if(cnt7 > 0 && cnt5 > 0 && cnt3 > 0){
        c++;
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//    freopen("out.txt", "w", stdout);
//    freopen("input.txt", "r", stdin);
    cin >> N;
    dfs(7);
    dfs(5);
    dfs(3);
    cout << c << endl;
    return 0;
}



Measured memory_bytes: 256
H,W = map(int, input().split())
ats = []
for i in range(W+2):
  ats.append('@')
grid = [ats]
for i in range(H):
  S_i = ['@']
  S_i_raw = input()
  for j in range(W):
    S_i.append(S_i_raw[j])
  S_i.append('@')
  grid.append(S_i)
grid.append(ats)

for h in range(H):
  for w in range(W):
    counter = 0
    if grid[h+1][w+1] == '.':
      if grid[h][w] == '#':
        counter += 1
      if grid[h][w+1] == '#':
        counter += 1
      if grid[h][w+2] == '#':
        counter += 1
      if grid[h+1][w] == '#':
        counter += 1
      if grid[h+1][w+2] == '#':
        counter += 1
      if grid[h+2][w] == '#':
        counter += 1
      if grid[h+2][w+1] == '#':
        counter += 1
      if grid[h+2][w+2] == '#':
        counter += 1
      grid[h+1][w+1] = str(counter)
      
for i in range(H):
  ans=''
  for j in range(W):
    ans = ans + grid[i+1][j+1]
  print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int N=2e6+10;
int n,a,f;
int t[N],maxn=-N;
void hs(int x){
    for(int i=2;i<=sqrt(x);){
        if(x%i==0){
            t[i]++;
            while(x%i==0) x/=i;
        }
        else i++;
    }
    if(x>1) t[x]++;
}
int main(){
    scanf("%d%d",&n,&a);
    f=a;
    for(int i=2;i<=n;i++){
		scanf("%d",&a);
        if(maxn<a) maxn=a;
        f=__gcd(f,a);
        hs(a);
    }
    if(f==1){
        for(int i=2;i<=maxn;i++){
        	if(t[i]>1){
				printf("setwise coprime\n");
				return 0;
			}
		}
        printf("pairwise coprime\n");
        return 0;
    }
    else{
    	printf("not coprime\n");
    	return 0;
	}
    return 0;
}

Measured memory_bytes: 7660
A,B,C,K = map(int, input().split())

max_val = 0
if K <= A:
  max_val = K
elif K <= A+B:
  max_val = A
else:
  max_val = A
  diff = K-(A+B)
  max_val = A-diff
  
print(max_val)
    

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

int main() {
  ll k; cin >> k;
  rep(i,k){
    cout << "ACL";
  }
  
  return 0;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  int a[m],b[m];
  for(int i=0;i<m;i++) cin >> a[i] >> b[i];
  int l=0,r=n+2;
  for(int i=0;i<m;i++){
    l=max(l,a[i]);
    r=min(r,b[i]);
  }
  cout << max(0,r-l+1) << endl;
}

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

char n[200005];
int ans;

int main() {
	scanf(" %s", n);
	int sze = (int) strlen(n);
	for (int i = 0; i < sze; i++) {
		ans += n[i] - '0';
	}
	if (ans % 9 == 0) printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 3816
#include <bits/stdc++.h>
using namespace std;
 
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)
#define REP(i, n) FOR(i, 0, (int)n - 1)
#define pb push_back
#define pi 3.141592653589793
#define sll signed long long int // -10^9 to 10^9
#define ll long long int// for 0 to 10^18
#define ull unsigned long long int // for 0 to 10^18
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) x.begin(),x.end()
#define MOD 1000000007
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
template<typename T> T power(T x,T y,ll m=MOD){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}
typedef vector<int> vi;
/* 
ll sum_ofGP_modM(ll a , ll n, ll mod)  //// (1 + A^1 +A^2 + A^3 + A^4 + -------+ A^N) % M  usually here n= Total terms in series-1
////and  if series is something for eg 3^2 + 3^4 here a= 9,r=9  our ans can be found out as 
// let a1= first term 3^2 just do ans = a1*sum_ofGP_modM(9 , N-1, ull mod)
	if(n == 0) return 1;
	if(n == 1) return (1 + a) % mod;
	ll res;
	if(n % 2)
		res = (a + 1) * GPSumWithMod((a*a) % mod , (n-1)/2);
	else{ res = (a + 1) * GPSumWithMod((a*a) % mod , n/2 - 1);res %= mod;res = (res * a) + 1;}
    return res % mod;
}
//Whenever we have (a/b)%P == (a * fast_pow(b,P-2))%P
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
} */



int main() {
  int N, Y;cin >> N >> Y;
  
  int c = Y/1000 - N;
  for (int x=0; 9*x<=c; x++) {
    if ( (c-9*x)%4 == 0 ) {
      int y = (c-9*x)/4;
      int z = N - x - y;
      if (y<0 or z<0) continue;
      std::cout << x << " " << y << " " << z;
      return 0;
    }
  }
  cout << "-1 -1 -1";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
pair<pair<string,int>, int> D[105];
int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i=0; i<N; i++) {
    string s;
    int p;
    cin >> s >> p;
    D[i].first.first = s;
    D[i].first.second = -p;
    D[i].second = i+1;
  }
  sort(D, D+N);
  for (int i=0; i<N; i++) {
    cout << D[i].second << endl;
  }
}

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

using namespace std;

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

  int64_t a, b, c;
  cin >> a >> b >> c;

  int64_t a0 = a, b0 = b, c0 = c;
  int i = 0;
  while (a % 2 != 1 && b % 2 != 1 && c % 2 != 1) {
    ++i;
    int64_t bc = (b + c) / 2, ca = (c + a) / 2, ab = (a + b) / 2;
    a = bc;
    b = ca;
    c = ab;
    if (a == a0 && b == b0 && c == c0) {
      cout << -1 << '\n';
      return 0;
    }
  }
  cout << i << '\n';

  return 0;
}


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

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

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

const int MOD = 1000000007;
const char ENDL = '\n';

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

class RMQ{
    int n;
    vector<int>dat;
public:
    RMQ(int n_){
        n=1;
        while(n<n_)n*=2;
        dat.resize(2*n-1);
        for(int i=0;i<2*n-1;i++)dat[i]=INT_MAX;
    }
    void update(int k,int a){
        k+=n-1;
        dat[k]=a;
        while(k>0){
            k=(k-1)/2;
            dat[k]=min(dat[k*2+1],dat[k*2+2]);
        }
    }
    int query(int a,int b,int k=0,int l=0,int r=0){
        if(r<=l)r=n;
        if(r<=a || b<=l)return INT_MAX;
        if(a<=l && r<=b)return dat[k];
        int vl=query(a,b,k*2+1,l,(r+l)/2);
        int vr=query(a,b,k*2+2,(r+l)/2,r);
        return min(vl,vr);
    }
};

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n;
    cin >> n;
    VI a(n);
    REP(i,n){
        cin >> a[i];
    }

    vector<PII> vpii;
    vpii.PB(MP(0,0));
    REP(i,n){
        vpii.PB(MP(a[i],i));
    }
    SORT(vpii);

    RMQ rmq(n);
    REP(i,n){
        rmq.update(i,a[i]);
    }

    int ans=0;
    priority_queue<pair<int,PII>> pq;
    pq.push(MP(-1,MP(0,n-1)));
    while (!pq.empty()){
        int x=-pq.top().FST;
        int b=pq.top().SND.FST;
        int c=vpii[x].second;
        int d=pq.top().SND.SND;

        pq.pop();

        if(b==d){
            ans += x;
            continue;
        }

        ans += x*(c-b+1)*(d-c+1);
        if(b!=c) {
            pq.push(MP(-rmq.query(b, c), MP(b, c - 1)));
        }
        if(c!=d) {
            pq.push(MP(-rmq.query(c + 1, d + 1), MP(c + 1, d)));
        }
    }

    cout << ans << ENDL;
    
    return 0;
}

Measured memory_bytes: 11756
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

signed main() {
    int N; cin >> N;
    vector<int> a(N), b(N);
    for(int i=0; i<N; i++) {
        cin >> a[i];
    }
    for(int i=0; i<N; i++) {
        cin >> b[i];
    }

    int ans = 0;
    for(int k=29; k>=0; k--) {
        int i1 = 0, i2 = 0, i3 = 0;
        int T = 1 << k, ad = 0;
        for(int i=0; i<N; i++) {
            a[i] %= 2*T, b[i] %= 2*T;
        }
        sort(a.begin(), a.end(), greater<int>());
        sort(b.begin(), b.end());
        for(int i=0; i<N; i++) {
            while(i1 < N && a[i] + b[i1] <   T) i1++;
            while(i2 < N && a[i] + b[i2] < 2*T) i2++;
            while(i3 < N && a[i] + b[i3] < 3*T) i3++;
            ad += (i2 - i1) + (N - i3);
            // printf("idx = %lld, i1 = %lld, i2 = %lld, i3 = %lld\n", i, i1, i2, i3);
        }
        // printf("k = %lld, ad = %lld\n", k, ad);
        if(ad % 2) ans += T;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
from functools import lru_cache
import sys
sys.setrecursionlimit(20000000)
INF = float('inf')

N = int(input())
h = list(map(int, input().split()))
n = len(h)-1

@lru_cache(maxsize=None)
def rec(i):
    if i==0:
        return 0
    res = INF
    res = min(res, rec(i-1)+abs(h[i]-h[i-1]))
    if i>1:
        res = min(res, rec(i-2)+abs(h[i]-h[i-2]))
    return res
print(rec(n))

Measured memory_bytes: 265524
use std::io;


/// https://beta.atcoder.jp/contests/abc067/tasks/abc067_b
fn main() {
    let (_n, k) = {
        let i = read::<usize>();
        (i[0], i[1])
    };

    let mut vec = read::<usize>();
    vec.sort();
    vec.reverse();
    println!("{}", vec.iter().take(k).sum::<usize>());
}


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

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

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

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

Measured memory_bytes: 4352
h,w=map(int,input().split())
s=[list(input())for i in range(h)]
dx=[1,1,0,0,1,-1,-1,-1]
dy=[0,1,1,-1,-1,1,0,-1]
for i in range(h):
    for j in range(w):
        cnt=0
        if s[i][j]==".":
            for k in range(8):
                x=i+dx[k]
                y=j+dy[k]
                if 0<=x and x<h and 0<=y and y<w and s[x][y]=="#":
                    cnt+=1
            s[i][j]=str(cnt)
for i in range(h):
    print(*s[i],sep="")

Measured memory_bytes: 3572