akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
int N, M;
map<string, int> ms, mt;
/*==================================================*/
/*function*/

/*==================================================*/

int main() {
    cin>>N;
    REP(i,0,N){
        string s;
        cin>>s;
        ms[s]++;
    }
    cin>>M;
    REP(i,0,M){
        string s;
        cin>>s;
        mt[s]++;
    }

    int ans = 0;

    auto it = ms.begin();
    while(it != ms.end()){
        ans = max(ans, ms[(*it).first] - mt[(*it).first]);
        it++;

    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 888
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int n, x[110];
int cost(int p) {
	int s = 0;
	for (int i = 0; i < n; i++)
		s += (x[i] - p) * (x[i] - p);
	return s;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d",  x + i);
	int minc = 1e9;
	for (int i = 1; i <= 100; i++)
		minc = min(minc, cost(i));
	printf("%d\n", minc);
}

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

def sieve1(n):
    isPrime = [True] * (n+1)
    isPrime[0] = False
    isPrime[1] = False
    for i in range(2*2, n+1, 2):
        isPrime[i] = False
    for i in range(3, n+1):
        if isPrime[i]:
            for j in range(i+i, n+1, i):
                isPrime[j] = False
    return isPrime
numOfDivisors = [2] * (n+1)
numOfDivisors[1] = 1
numOfDivisors[0] = 0
isPrime = sieve1(n)
for i in range(2, n+1):
    if isPrime[i]:
        for j in range(2*i, n+1, i):
            x = j // i
            numOfDivisors[j] += numOfDivisors[x] - 1
ans = 0
for k in range(1, n+1):
    ans += numOfDivisors[k] * k
print (ans)

Measured memory_bytes: 229960
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll ar[500009],br[500009];
int main()
{
    ll a,b,c,i,j,k=0;
    string s,d;
    char q,w;
    cin>>a>>b;
    for(i=1;i<=a;i++)
    {
        cin>>ar[i];
        k=k+ar[i];
    }
    sort(ar+1,ar+a+1);
    c=0;
    for(i=a;i>0;i--)
    {
        if(b==0)break;
        c=c+ar[i];
        b--;
    }
    cout<<max((k-c),0ll)<<endl;

}



Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long int lli;

int main() {
  lli n;
  cin >> n;
  vector<lli> lines;
  lli currMin = 0;
  for (int i=0; i < n;i++) {
    lli curr;
    cin >> curr;
    int lineMax = -1;
    int insertIndex = -1;
    if ( currMin < curr )
    for (size_t idx=0; idx < lines.size(); idx++) {
      lli lineA = lines[idx];
      if(lineA < curr){
      	if(lineMax < lineA) {
          lineMax = lineA;
          insertIndex = idx;
        }
      }
    }
    if (insertIndex < 0){
      lines.push_back(curr);
      currMin = curr;
    } else {
      lines[insertIndex] = curr;
    }
  }
  std::cout << (lines.size()) << std::endl;
}

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

int main(void){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(abs(a-b)==c||a+b==c){
    printf("Yes\n");
  }
   else{
     printf("No\n");
   }
  
  return 0;
}

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


#define li          long long int
#define uli         unsigned long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


li a[200200];

int main() {
    li n;
    cin >> n;
    li res = 0;
    li sum = 0;
    rin{
        cin >> a[i];
        res = (res + sum*a[i] % MOD) % MOD;
        sum = (sum + a[i]) % MOD;
    }
    cout << res << endl;


    return 0;
}


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


Measured memory_bytes: 2096
#include<stdio.h>
#define M 200000
int main(){
  int i,n,R[M];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&R[i]);
  }
  int maxv=-2000000000;
  int minv=R[0];
  for(i=1;i<n;i++){
    if(maxv<R[i]-minv){
      maxv=R[i]-minv;
    }
    if(minv>R[i]){
      minv=R[i];
    }
  }
  printf("%d\n",maxv);
  return 0;
}



Measured memory_bytes: 2560
# coding: utf-8
# Your code here!
N=int(input())
ans=0
cnt=[0,0,0,0,0]

for i in range(N):
    name=input()
    if name[0]=="M":
        cnt[0]+=1
    elif name[0]=="A":
        cnt[1]+=1
    elif name[0]=="R":
        cnt[2]+=1
    elif name[0]=="C":
        cnt[3]+=1
    elif name[0]=="H":
        cnt[4]+=1

if cnt.count(0)<=2:
    for i in range(5):
        for j in range(i+1,5):
            for k in range(j+1,5):
                ans+=cnt[i]*cnt[j]*cnt[k]

print(ans)

Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	ans := 1
	for i := 1; i*i <= m; i++ {
		if m%i == 0 {
			v := m / i
			if n <= i {
				if ans < v {
					ans = v
				}
			}
			if n <= v {
				if ans < i {
					ans = i
				}
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

a,b,k = iim()
ans = []
for i in range(1,min(a,b)+1):
    if a%i == 0 and b%i == 0:
        ans.append(i)

print(ans[-k])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using ll = long long;
//#define int ll
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)

std::string highlight(std::string s) {
#ifdef _MSC_VER
    return s;
#else
    return "\033[33m" + s + "\033[0m";
#endif
}

#ifdef LOCAL
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        print_to(os, ", ", "\n", __VA_ARGS__);            \
        std::cerr << highlight(os.str());                 \
    } while (0)
#define dump_(a)                                          \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #a << " = [";          \
        print_to_(os, ", ", "]\n", all(a));               \
        std::cerr << highlight(os.str());                 \
    } while (0)
#else
#define dump(...)
#define dump_(...)
#endif

template <typename T>
void print_to(std::ostream &os, const char *, const char *tail, const T &fst) {
    os << fst << tail;
}
template <typename Fst, typename... Rst>
void print_to(std::ostream &os, const char *del, const char *tail, const Fst &fst, const Rst &... rst) {
    os << fst << del;
    print_to(os, del, tail, rst...);
}
template <typename Iter>
void print_to_(std::ostream &os, const char *del, const char *tail, Iter bgn, Iter end) {
    for (Iter it = bgn; it != end;) {
        os << *it;
        if (++it != end) {
            os << del;
        } else {
            os << tail;
        }
    }
}
template <typename Fst, typename... Rst>
void println(const Fst &fst, const Rst &... rst) {
    print_to(std::cout, "\n", "\n", fst, rst...);
}
template <typename Fst, typename... Rst>
void print(const Fst &fst, const Rst &... rst) {
    print_to(std::cout, " ", "\n", fst, rst...);
}
template <typename Iter>
void println_(Iter bgn, Iter end) {
    print_to_(std::cout, "\n", "\n", bgn, end);
}
template <typename Iter>
void print_(Iter bgn, Iter end) {
    print_to_(std::cout, " ", "\n", bgn, end);
}

// const int MOD = 1000000007;
namespace trush {
    int _ = (std::cout.precision(10), std::cout.setf(std::ios::fixed), std::cin.tie(0),
             std::ios::sync_with_stdio(0), 0);
}

using namespace std;

int main() {
    ll x, y;
    while (cin >> x >> y) {
        int cnt = 0;
        while (x <= y) {
            cnt ++;
            x *= 2;
        }
        cout << cnt << endl;
    }
}

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

int main() {
  string s;
  cin>>s;

  vector<int> i_rl;
  int n = s.length();
  for (int i=0; i<n-1; i++) {
    if (s[i] == 'R' && s[i+1] == 'L') {
      i_rl.push_back(i);
    }
  }
  vector<int> nums(n);
  for (int i=0; i<n; i++) nums[i] = 0;
  for (int i=0; i<n; i++) {
    if (binary_search(i_rl.begin(), i_rl.end(), i)) {
      ++nums[i];
      continue;
    }
    auto it = lower_bound(i_rl.begin(), i_rl.end(), i);
    if (s[i] == 'R') {
      int x = *it;
      int y = x - i;
      if (y % 2 == 0) {
        ++nums[x];
      } else {
        ++nums[x+1];
      }
    } else {
      --it;
      int x = *it;
      int y = x - i;
      if (y % 2 == 0) {
        ++nums[x];
      } else {
        ++nums[x+1];
      }
    }
  }
  cout<<nums[0];
  for (int i=1; i<n; i++) {
    cout<<" "<<nums[i];
  }
  cout<<endl;
}

Measured memory_bytes: 1280
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var ab = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
            Console.WriteLine(LCM(ab[0], ab[1]));
        }

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


Measured memory_bytes: 13396
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 1999999999
#define ALL(x) (x).begin(), (x).end()
#define LBi(x, n) lower_bound(ALL(x), n) - (x).begin()
#define ZIP(x) (x).erase(unique(ALL(x)), (x).end())
#define Pi pair<int, int>
#define Vi vector<int>

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

string s = "";
char ch[10];
int n, a, b, c, d, x, m[5];

int main() {
	cin >> s;
	s[3] = '8';
	cout << s << endl;
	return 0;
}


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

int main() {

	// *******
	//   azzel : a -> 1, z -> 2, e -> 1, l -> 1
	//   apple : a -> 1, p -> 2, l -> 1, e -> 1
	//    ※数値はアルファベットの個数
	// のように「各アルファベットの登場数」が一致しているときのみYesとなる
	// このとき、登場するアルファベット自体は何でも良い
	//
	//  chokudai : c -> 1, h -> 1, o -> 1, k -> 1, u -> 1, d -> 1, a -> 1, i -> 1
	//  redcoder : r -> 2, e -> 2, d -> 2, c -> 1, o -> 1
	// のような場合はNo
	// *******

	string S, T;
	cin >> S >> T;
		
	//各アルファベットが何文字ずつ登場したのかをカウントする
	vector<int> s(256, 0);
	vector<int> t(256, 0);
	for (int i = 0; i < (int)S.size(); i++)
	{
		int index_s = S[i] - '0';
		int index_t = T[i] - '0';

		s[index_s]++;
		t[index_t]++;
	}


	//ソートしているので、SからTへ変形可能なときは全て一致する
	//1つでも一致しないときは変形不可
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != t[i]) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;


	return 0;
}

Measured memory_bytes: 776
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		if(b-a == c-b) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}
	}

}


Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n, k, h;

signed main() {
	int i;
	int ans = 0;
	
	cin >> n >> k;
	rep(i, n) {
		cin >> h;
		if (h >= k) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from queue import Queue

h, w = list(map(int, input().split()))
s = []
for i in range(h):
    s.append(input().strip())

ans = 0
for i in range(h):
    for j in range(w):
        start = s[i][j]
        if start == "#":
            continue
        else:
            visited = [[False for _ in range(w)] for _ in range(h)]
            visited[i][j] = True
            queue = Queue()
            queue.put((i, j, 0))

            while 0 < queue.qsize():
                now = queue.get()
                ans = max(ans, now[2])

                if (now[0] <= (h - 2)) and (s[now[0] + 1][now[1]] == ".") and not visited[now[0] + 1][now[1]]:
                    queue.put(((now[0] + 1), now[1], (now[2] + 1)))
                    visited[now[0] + 1][now[1]] = True
                if (now[1] <= (w - 2)) and (s[now[0]][now[1] + 1] == ".") and not visited[now[0]][now[1] + 1]:
                    queue.put((now[0], (now[1] + 1), (now[2] + 1)))
                    visited[now[0]][now[1] + 1] = True
                if (1 <= now[0]) and (s[now[0] - 1][now[1]] == ".") and not visited[now[0] - 1][now[1]]:
                    queue.put(((now[0] - 1), now[1], (now[2] + 1)))
                    visited[now[0] - 1][now[1]] = True
                if (1 <= now[1]) and (s[now[0]][now[1] - 1] == ".") and not visited[now[0]][now[1] - 1]:
                    queue.put((now[0], (now[1] - 1), (now[2] + 1)))
                    visited[now[0]][now[1] - 1] = True

print(ans)


Measured memory_bytes: 85992
# D
N = int(input())
A_list = list(map(int, input().split()))

# cumsum from left
a = 0
A_left = []
for i in range(N):
    a += A_list[i]
    A_left.append(a)
    
# cumsum from right
a = 0
A_right = []
for i in range(N):
    a += A_list[N-1-i]
    A_right.append(a)

def binary_search_left(s):
    m = 0
    l = 0
    r = N - 1
    
    if A_left[0] > s:
        return 0
    
    while True:
        m = (l + r) // 2
        
        if A_left[m] <= s and A_left[m+1] > s:
            break
        elif A_left[m] <= s:
            l = m
        else:
            r = m
    if s - A_left[m] <= A_left[m+1] - s:
        return m
    else:
        return m+1
    
def binary_search_right(s):
    m = 0
    l = 0
    r = N - 1
    
    if A_right[0] > s:
        return 0
    
    while True:
        m = (l + r) // 2
        
        if A_right[m] <= s and A_right[m+1] > s:
            break
        elif A_right[m] <= s:
            l = m
        else:
            r = m
    if s - A_right[m] <= A_right[m+1] - s:
        return m
    else:
        return m+1
    
# B | C split
res = A_left[N-1]
for s in range(2, N-1):
    
    m_l = binary_search_left(A_left[s-1]/2)
    a, b = A_left[m_l], A_left[s-1] - A_left[m_l]
    r = N - s 
    m_r = binary_search_right(A_right[r-1]/2)
    c, d = A_right[m_r], A_right[r-1] - A_right[m_r]
    
    r = max([a,b,c,d]) - min([a,b,c,d])
    if r < res:
        res = r
if N == 4:
    res = max(A_list) - min(A_list)
print(res)

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

ll temp(ll a, ll b, ll x){
    ll axb = (long double)(a*x)/(long double)b;
    ll bx = (long double)x/(long double)b;
    // cout << axb << " " << a * bx << endl;
    return axb - a * bx;
}

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

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

    ll x = n > b-1 ? b-1 : n;
    ll ans = temp(a,b,x);

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


Measured memory_bytes: 3652
package main

import "fmt"

func main() {
	var m, a, book int
	fmt.Scan(&m, &a, &book)

	if nokori := m - book; nokori < 0 {
		if nokori = nokori + a; nokori < 0 {
			fmt.Println("NA")
		} else {
			fmt.Println(a - nokori)
		}
	} else {
		fmt.Println(0)
	}
}



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

int main()
{
  int h, w;
  string board[50];

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

  cin >> h >> w;

  rep(i, h)
    cin >> board[i];
  
  rep(i, w)
  {
    rep(j, h)
    {

      if(board[j][i] == '#')
        continue;

      int count=0;
      rep(k, 8)
      {
        int t = i+dx[k], t2 = j+dy[k];

        if(t<0 || t>=w)
          continue;
        if(t2<0 || t2>=h)
          continue;

        if(board[t2][t] == '#')
        {
          count++;
        }
      }

      board[j][i] = count + '0';

    }
  }

  rep(i, h)
  {
    cout << board[i] << endl;
  }

}


Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

typedef long long int ll;

// 最大公約数
ll GCD(ll a,ll b){if(a%b==0)return b;return GCD(b,a%b);}

// 最小公倍数
ll LCM(ll a, ll b){ return a*b/GCD(a, b); }

int main(void){

    int n, x; cin >> n >> x;
    int ans = 0;

    vector<int> l(n), dis(n);
    queue<int> a;

    for(int i = 0;i < n;i++){
        cin >> l[i];
        a.push(abs(l[i] - x));
    }
    
    while(a.size() != 1){
        int tmp1 = a.front(); a.pop();
        int tmp2 = a.front(); a.pop();
        a.push(GCD(tmp1, tmp2));
    }

    cout << a.front() << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#include <bitset>
#define M 1000000007
#define M1 998244353

#define tr(container, it) \
for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define fast                        \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

ll power(ll x, ll n)
{
    ll result = 1;
    while (n)
    {
        if (n % 2 == 1)
            result = result * x;
        n = n / 2;
        x = x * x;
    }
    return result;
}

ll gcd(ll a, ll b)
{
    if (!b)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

inline ll mul(ll x, ll y, ll m)
{
    ll z = 1LL * x * y;
    if (z >= m)
    {
        z %= m;
    }
    return z;
}

ll powmod(ll x, ll y, ll m)
{
    ll r = 1;
    while (y)
    {
        if (y & 1)
        {
            r = mul(r, x, m);
        }
        y >>= 1;
        x = mul(x, x, m);
    }
    return r;
}



void start()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
/***********************************************************************************************************/

int main()
{
    start();
    int a, b, k;
    cin>>a>>b>>k;
    unordered_set<int> s;
    for (int i=0;i<min(k, b-a);i++)
    {

        s.insert(a+i);
        cout<<a+i<<"\n";
    }
    for (int i=min(b-a, k-1);i>=0;i--)
    {
        // cout<<b-i<<"\n";
        if (s.find(b-i)!=s.end())
        {
            continue;
        }
        cout<<b-i<<"\n";
    }

    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/

ll d[4][4];


int main() {
    REP(i,3) {
        REP(j,3) {
            cin >> d[i+1][j+1];
        }
    }
    ll a1, a2, a3, b1, b2, b3;
    REP(i,101) {
        a1 = i;
        b1 = d[1][1] - a1;
        if(b1<0){
            continue;
        }
        REP(j,101) {
            a2 = j;
            b2 = d[2][2] - a2;
            if (b2 < 0)
            {
                continue;
            }
            REP(k,101) {
                a3 = k;
                b3 = d[3][3] - a3;
                if (b3 < 0)
                {
                    continue;
                }
                if(a1+b2==d[1][2]&&a1+b3==d[1][3]&&a2+b1==d[2][1]&&a2+b3==d[2][3]&&a3+b1==d[3][1]&&a3+b2==d[3][2]){
                    cout << "Yes" << endl;
                    return 0;
                }
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int X;

ll calc(ll n){
    return n*n*n*n*n;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> X;
    for(ll i = -500; i <= 500; i++){
        for(int j = -500; j <= 500; j++){
            if(calc(i)-calc(j) == X){
                cout << i << ' ' << j << endl;
                return 0;
            }
        }
    }
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 30;

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

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

  ll X = 0;
  for (int i = 60; i >= 0; i--) {
    int a = 0; // 0
    int b = 0; // 1
    ll p = 1LL << i;
    if (X + p > K) continue;

    rep (j, N) {
      if (A[j] & p) b++;
      else a++;
    }

    if (a > b) X += p;
  }

  ll ans = 0;
  rep (i, N) ans += A[i] ^ X;

  cout << ans << endl;
}


Measured memory_bytes: 1024
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    h = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    m_cnt = 0
    for i in range(1, n):
        if h[i] <= h[i-1]:
            cnt += 1
            m_cnt = max(m_cnt, cnt)
        else:
            cnt = 0
    print(m_cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 63984
#include <bits/stdc++.h>
 
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()
 
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }

using lint = long long;

template <size_t LETTER>
struct prefix_tree {
private:

  struct node {
    int index, depth;
    int next[LETTER];
    char letter;
    node (const char& c, const int& d) : letter(c), index(-1), depth(d) {
      std::memset(next, -1, sizeof(next));
    }
  };

  const char base;
  std::vector<node> data;

  int& next(const int& i, const int& j) {
    return data[i].next[j];
  }

public:

  prefix_tree(const char& base = 'a', const char& root = '$')
    : base(base) { data.emplace_back(root, 0); }

  void add(const std::string& str, const int& index) {
    int pos = 0;
    for (int i = 0; i < str.size(); ++i) {
      int k = str[i] - base;
      if (next(pos, k) != -1) {
        pos = next(pos, k);
        continue;
      }
      int pos_new = data.size();
      next(pos, k) = pos_new;
      data.emplace_back(str[i], data[pos].depth + 1);
      pos = pos_new;
    }
    data[pos].index = index;
  }

  int find(const std::string& str) const {
    int pos = 0;
    for (int i = 0; i < str.size(); ++i) {
      int k = str[i] - base;
      if (next(pos, k) == -1) return -1;
      pos = next(pos, k);
    }
    return pos;
  }

  int find(const int& pos, const char& c) const {
    return next(pos, c - base);
  }

  int index(const int& pos) const {
    return pos == -1 ? -1 : data[pos].index;
  }

  lint calc(const lint& D) const {
    lint result = 0;
    for (const node& n : data) {
      if ((n.next[0] == -1) ^ (n.next[1] == -1)) {
        lint tmp = D - n.depth;
        result ^= (tmp & -tmp);
      }
    }
    return result;
  }

};

int main() {

  int N;
  lint L;
  std::cin >> N >> L;
  std::vector<std::string> S(N);
  rep (i, N) std::cin >> S[i];

  prefix_tree<2> trie('0');
  rep (i, N) {
    trie.add(S[i], i);
  }

  lint ans = trie.calc(L);
  std::cout << (ans == 0 ? "Bob" : "Alice") << '\n';
  return 0;

}


Measured memory_bytes: 3092
N = int(input())

def num2alpha(num):
    if num<=26:
        return chr(64+num).lower()
    elif num%26==0:
        return num2alpha(num//26-1)+chr(90).lower()
    else:
        return num2alpha(num//26)+chr(64+num%26).lower()

print(num2alpha(N))

Measured memory_bytes: 9180
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


h, w = MI()
a = [IS() for _ in range(h)]
print('#' * (w + 2))
for i in range(h):
    print('#' + ''.join(a[i]) + '#')
print('#' * (w + 2))


Measured memory_bytes: 65900
def experiment(v):
    n = 1
    k = 4.9
    while True:
        y = 5*n-5
        v_ex = 2*4.9*(y/k)**0.5
        if v_ex >= v:
            return n
            break
        else:
            n += 1

while True:
    try:
        v = float(input())
        print(experiment(v))
    except EOFError:
        break

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

int main() {
  ll k;
  cin >> k;
  ll i = 1;
  ll seven = 7;
  for (int j = 0; j <= k; j++) {
    if (seven%k == 0) {
      cout << i << endl;
      return 0;
    } else {
      ll tmp = seven%k;
      seven = (tmp*10+7)%k;
      i++;
    }
  }

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

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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000001;
using namespace std;
typedef long long ll;

int n,m;
int x[100100];
int l[100100];

int main(int argc, char const *argv[]) {
  std::cin >> n >> m;
  rep(i,1,m+1)std::cin >> x[i];
  if(n>=m){
    std::cout << "0" << '\n';
    return 0;
  }
  sort(x+1, x+m+1);
  rep(i,1,m)l[i]=x[i+1]-x[i];
  sort(l+1,l+m);
  ll ans = 0;
  rep(i,1,m-n+1)ans+=l[i];
  std::cout << ans << '\n';
}



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

int main()
{
    int N = 0, ans = 0, hoge;
    cin >> N;
    hoge = N;

    for (int i = N; i >0;i--){
        if(N>0){
            ans += (N % 10);
            N =N/10;
         //   cout << "ans="<<ans << endl;
         //   cout << "N="<<N << endl;
        }
        else{
            break;
        }
    }

    if((hoge % ans)==0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

}



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

typedef long long ll;
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)


int main()
{
    optimize();

    int n;
    cin>> n;

    string s[n];
    double d[n], ans=0;


    for(int i=0; i<n; i++)
    {
        cin>> d[i]>> s[i];

        if(s[i]=="JPY")
        ans+=d[i];
        else
            ans+=((d[i]* 380000));

    }

   // cout<< fixed<< setprecision<< 5;
    cout<< ans<< endl;


    return 0;
}




Measured memory_bytes: 3752
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

const int MAX = 303030;
const int MOD = 998244353;
ll fac[MAX], finv[MAX], inv[MAX];

void combinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll comb(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

	ll N, A, B, K;
	cin >> N >> A >> B >> K;
	combinit();

	ll ans = 0;
	for (ll x = 0; x <= N; x++) {
		if (K - A * x >= 0 && K - A * x <= B*N && (K - A * x) % B == 0) {
			ll y = (K - A * x) / B;
			ans += comb(N,x)*comb(N,y);
			ans %= MOD;
		}
	}
	puts(ans);
	
	return 0;
}


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

D = []

for i in range(n):
    a, b = map(int, input().split())
    D.append([a+b, a, b])

D.sort(reverse=True)

ans = 0
for i in range(n):
    if i % 2 == 0:
        ans += D[i][1]
    else:
        ans -= D[i][2]

print(ans)


Measured memory_bytes: 23260
def func(n, W, w):  # ナップザック問題の亜種
    _max = 0
    weights = [[] for _ in range(4)]
    for i in range(n):
        weights[w[i][0]-w[0][0]].append(w[i][1])
    for i in range(len(weights)):
        weights[i].sort()
        weights[i].append(0)
        weights[i].reverse()
        for j in range(1, len(weights[i])):
            weights[i][j] += weights[i][j-1]
    # print(weights)
    for i in range(len(weights[0])):
        # print("i:{}".format(i))
        for j in range(len(weights[1])):
            # print("j:{}".format(j))
            for k in range(len(weights[2])):
                for l in range(len(weights[3])):
                    # 「i+j+k+l < n」つ選ぶ
                    if w[0][0]*i\
                            + (w[0][0]+1)*j\
                            + (w[0][0]+2)*k\
                            + (w[0][0]+3)*l <= W:
                        # print("i:{} j:{} k:{} l:{} score:{}".format(i, j, k, l, weights[0][i]+weights[1][
                        # j]+weights[2][k]+weights[3][l]))
                        _max = max(_max, weights[0][i]+weights[1][j]+weights[2][k]+weights[3][l])
    return _max


n, W = [int(i) for i in input().split()]
w = [[0, 0] for _ in range(n)]
for i in range(n):
    w[i] = [int(i) for i in input().split()]
print(func(n, W, w))
"""
# print("print(\" vs \" + str(func({}, {}, {})))".format(n, W, w))
print("11 vs " + str(func(4, 6, [[2, 1], [3, 4], [4, 10], [3, 4]])))
print("13 vs " + str(func(4, 6, [[2, 1], [3, 7], [4, 10], [3, 6]])))
print("400 vs " + str(func(4, 10, [[1, 100], [1, 100], [1, 100], [1, 100]])))
print("0 vs " + str(func(4, 1, [[10, 100], [10, 100], [10, 100], [10, 100]])))
"""


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

#define ll long long
#define ar array

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

	int n, p;
	string s;
	cin >> n >> p >> s;
	ll ans=0;
	if(p==2) {
		for(int i=0; i<n; ++i)
			if((s[i]-'0')%2==0)
				ans+=i+1;
	} else if(p==5) {
		for(int i=0; i<n; ++i)
			if((s[i]-'0')%5==0)
				ans+=i+1;
	} else {
		map<int, int> mp;
		++mp[0];
		int t=0, p2=1;
		for(int i=n-1; i>=0; --i) {
			t=(t+(s[i]-'0')*p2)%p;
			ans+=mp[t];
			mp[t]++;
			p2=p2*10%p;
		}
	}
	cout << ans;
}


Measured memory_bytes: 916
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<complex>
#define mod 1000000007
#define lol(i,n) for(int i=0;i<n;i++)
using namespace std;
int dp[1<<16][15];
pair<int,int> from[1<<16][15];
int w[1<<16],n;
int s[15],d[15],v[15];
int main(){
  cin>>n;
  lol(i,n){
    cin>>s[i]>>d[i]>>v[i];
    lol(j,(1<<n)){
      dp[j][i]=mod;
    }
    dp[(1<<i)][i]=0;
  }
  w[0]=0;
  for(int k=0;k<(1<<n);k++){
    lol(last,n){
      lol(to,n){
	if(k%(1<<(to+1))>=(1<<to))continue;
	int tmp=dp[k][last]+abs(d[to]-d[last])*(7+2*w[k]);
	if(tmp<dp[k+(1<<to)][to]){
	  dp[k+(1<<to)][to]=tmp;
	  from[k+(1<<to)][to]=make_pair(k,last);
	}
	w[k+(1<<to)]=w[k]+v[to];
      }
    }
  }
  vector<int> v;
  pair<int,int> pnt;
  int mini=mod;
  lol(i,n){
    if(mini>dp[(1<<n)-1][i]){
      mini=dp[(1<<n)-1][i];
      pnt=make_pair((1<<n)-1,i);
    }
  }
  while(true){
    int a=pnt.first,b=pnt.second;
    v.push_back(s[b]);
    if(a==(1<<b))break;
    pnt=from[a][b];
  }
  lol(i,v.size()){
    if(i)cout<<" ";
    cout<<v[v.size()-1-i];
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 12816
#include <stdio.h>
#include<vector>
#include<math.h>
#include<string>

typedef long long ll;
typedef unsigned short int unsi;
typedef unsigned int uni;
typedef unsigned long int unli;

using namespace std;





int main(){
	int N, X;
	int L[100];
	int D = 0;
	int count = 1;

	scanf("%d%d", &N, &X);
	
	for (int i = 1; i <= N; i++) {
		scanf("%d", &L[i - 1]);
	}
	
	for (int i = 1; i <= N; i++) {
		D += L[i - 1]; 
		if (D <= X) {
			count++;
		}else {
			break;
		}
	}
	
	printf("%d", count);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define N 100005
#define m 1000000007
#define dd double
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
int32_t main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b;
	cin>>a>>b;
	cout<<a*b;
}

Measured memory_bytes: 3624
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		char[] s = sc.next().toCharArray();
		
		int[] t = new int[N+1];
		int idx = N;
		int turn = 1;
		while(idx>0) {
			boolean ok = false;
			int next = idx;
			for(int i=0; i<M; i++) {
				if(idx-i-1>=0) {
					if(s[idx-i-1]=='0') {
						ok = true;
						t[idx]=turn;
						next = idx-i-1;
					}
				}
			}
			if(!ok) {
				System.out.println(-1);
				sc.close();
				return;
			}
			turn++;
			idx = next;
		}
		turn--;
		
		idx = 0;
		for(int i=0; i<turn; i++) {
			for(int j=1; j<=M; j++) {
				if(t[idx+j]==turn-i) {
					pw.print(j+(i==turn-1 ? "\n" : " "));
					idx += j;
					break;
				}
			}
		}
//		System.out.println(turn);
		sc.close();
		pw.close();
	}
	
}

Measured memory_bytes: 34688
L = int(input())
L2 = bin(L)[2:]
N = len(L2)
L2d = L2[1:]
L2u = int("0b"+L2,0) - int("0b"+L2d,0)
L2u2 = L2u//2
tmp = 1
M = 0
Ans = []
if L2u != 0:
    tmpN = N
    while tmp != L2u:
        Ans.append([tmpN-1,tmpN,0])
        Ans.append([tmpN-1,tmpN,tmp])
        tmp *= 2
        tmpN -= 1
        M += 2
flag = 0
for i in range(len(L2d)):
    if L2d[i] == "1" and flag == 0:
        Ans.append([1, i+2, L2u])
        tmp = 2**(N-i-2)
        M += 1
        flag = 1
        B = L2u
    elif L2d[i] == "1":
        Ans.append([1, i+2, B+tmp])
        B = B+tmp
        tmp = 2**(N-i-2)
        M += 1
print(*[N,M])
for i in range(M):
    print(*Ans[i])

Measured memory_bytes: 38384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;

class program
{
    static public int mod = 1000000007;
    static void Main()
    {
        var z = inta();
        var a = new int[2];
        var b = new int[2];
        a[0] = (int)Ceiling((double)z[0] * 100 / 8);
        a[1] = (int)Ceiling((double)(z[0] + 1) * 100 / 8);
        b[0] = z[1] * 10;
        b[1] = b[0] + 10;
        if(a[1] <= b[0] || b[1] <= a[0])
        {
            Write(-1);            
        }
        else
        {
            Write(Max(a[0], b[0]));
        }
    }

    static int pow(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; }
    static string rstr() { return ReadLine(); }
    static int rint() { return int.Parse(ReadLine()); }
    static long rlong() { return long.Parse(ReadLine()); }
    static string[] stra() { return ReadLine().Split(' '); }
    static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); }
    static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; }
    static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; }
    static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = double.Parse(read_str_array[countup_i]); } return return_double_array; }
    static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } }
    static long LCM(long a, long b) { return a * b / GCD(a, b); }
    static void WriteArray2(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } }
    static void WriteArray(int[] a, int b) { for (int i = 0; i < b; i++) { Write(" "); Write(a[i]); } WriteLine(); }
}


Measured memory_bytes: 27440
import sys
n, x, m = map(int, input().split())
A = [0] * (10**5 + 1)
val = x
val_visited = set()
val_record = []
for i in range(n):
    if val in val_visited:
        break
    val_visited.add(val)
    val_record.append(val)
    val = val**2 % m
else:
    print(sum(val_record))
    sys.exit()

entry_idx = val_record.index(val)
loop_len = len(val_record) - entry_idx
loop_total_val = sum(val_record[entry_idx:])
head_len = len(val_record)

n -= head_len
loop_num = n // loop_len
tail_len = n % loop_len

ans = 0
#head
ans += (sum(val_record))
#loop
ans += loop_total_val * loop_num
#tail
for i in range(tail_len):
    ans += val_record[entry_idx + i]
print(ans)

Measured memory_bytes: 78108
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef ONLINE_JUDGE
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif
#define fu(a,b,c) for(int a=b;a<=(int)c;++a)
#define fd(a,b,c) for(int a=b;a>=(int)c;--a)
#define cu(a,b,c) for(int a=b;a<(int)c;++a)
#define cd(a,b,c) for(int a=(b)-1;a>=(int)c;--a)
#define gcd(a,b) __gcd(a,b) 
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define pf push_front
#define MOD 1000000007 
#define MAXN 52
#define MAXH 20
#define MAXM 52
#define INF 100000000
#define ll long long
#define ull unsigned long long
#define RNG rng mt19937(time(NULL))
#define udist(a,b) uniform_int_distribution<uint32_t> distribution(a,b)
#define max3(a,b,c) max(a, max(b, c))
#define min3(a,b,c) min(a, min(b, c))
#define gmax(a,b) a = max(a, b)
#define gmin(a,b) a = min(a, b)
#define whatis(x) cerr << #x << " is " << x << endl;
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.1415926535897932384626433
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int N = 100005;
ll p[N],size[N];

int find_par(int x){
	return (x == p[x]?x:p[x] = find_par(p[x]));
}

ll unite(int x,int y){
	x = find_par(x);
	y = find_par(y);
	if(x == y)return 0;
	p[x] = y;
	ll res = 1LL * size[x] * size[y];
	size[y] += size[x];
	return res;
}

int main(){
	fast_io();
	int n,m;
	cin >> n >> m;
	vector<pii> op(m);
	cu(i,0,m)cin >> op[i].F >> op[i].S;
	fu(i,1,n){p[i] = i;size[i] = 1;}
	ll tot = 1LL * n * (n-1)/2;
	vector<ll> res(m);
	cd(i,m,0){
		res[i] = tot;
		tot -= unite(op[i].F, op[i].S);
		assert(tot >= 0);
	}
	cu(i,0,m){
		cout << res[i] << '\n';
	}
}


Measured memory_bytes: 4480
#include <cstdio>
#include <algorithm>
typedef long long int ll;
ll solve(ll x,ll y) {
	if(x>y) std::swap(x,y);
	if(y%x==0) return 2*y-x;
	return y/x*x*2+solve(x,y%x);
}
int main() {
	ll n,x;scanf("%lld%lld",&n,&x);
	printf("%lld\n",n+solve(x,n-x));
	return 0;
}


Measured memory_bytes: 128
use proconio::*;
use proconio::marker::*;
use std::collections::*;
use std::ops::Bound::*;


const F: usize = 26;

#[fastout]
fn run() {
    input! {
        d: usize,
        c: [i64; F],
        mut s: [[i64; F]; d],
        mut t: [Usize1; d],
        q: usize,
        query: [(usize, Usize1); q],
    }
    let mut score = 0;
    let mut set = vec![BTreeSet::new(); F];
    for set in set.iter_mut() {
        set.insert(0);
    }
    for (i, (s, &t)) in s.iter().zip(t.iter()).enumerate() {
        let k = i as i64 + 1;
        score += s[t];
        set[t].insert(i + 1);
        for (c, set) in c.iter().zip(set.iter()) {
            let last = *set.iter().rev().next().unwrap() as i64;
            score -= *c * (k - last);
        }
    }
    for set in set.iter_mut() {
        set.insert(d + 1);
    }
    s.insert(0, vec![]);
    t.insert(0, 0);
    let func = |contest: usize, day: usize| -> i64 {
        let day = day as i64;
        c[contest] * day * (day - 1) / 2
    };
    for (d, q) in query {
        let x = t[d];
        assert!(set[x].remove(&d));
        let a = *set[x].range((Unbounded, Included(&d))).rev().next().unwrap();
        let b = *set[x].range((Included(&d), Unbounded)).next().unwrap();
        score -= s[d][x];
        score += func(x, d - a) + func(x, b - d);
        score -= func(x, b - a);
        let x = q;
        t[d] = x;
        let a = *set[x].range((Unbounded, Included(&d))).rev().next().unwrap();
        let b = *set[x].range((Included(&d), Unbounded)).next().unwrap();
        assert!(set[x].insert(d));
        score += s[d][x];
        score += func(x, b - a);
        score -= func(x, d - a) + func(x, b - d);
        println!("{}", score);
    }
}

fn main() {
    run();
}


Measured memory_bytes: 4420
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int inf = INT_MAX / 2;
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; }


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

    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    long long a, b, t;
    long long ans = inf;
    for (int i = 0; i <= max(X, Y) * 2; i += 2) {
        a = (X - i / 2) * A;
        b = (Y - i / 2) * B;
        if (a < 0) a = 0;
        if (b < 0) b = 0;
        t = a + b + C * i;
        chmin(ans, t);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v)  v.begin(), v.end()

signed main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    int n; cin>>n; int a[n];
    for(auto &i : a)    cin>>i;
    ll ans = 0;
    for(int i=1; i<n; i++) {
        if(a[i-1] > a[i]) {
            ans += a[i-1] - a[i];
            a[i] += (a[i-1] - a[i]);
        }
    }

    cout<<ans;
    return 0;
}

Measured memory_bytes: 4360