akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

struct Node{
  int key;
  struct Node *ri, *le, *pa;
};

struct Node *ro, *Nu;

void insert(int k){
  struct Node *y=Nu;
  struct Node *x=ro;
  struct Node *z;

  z=(struct Node*)malloc(sizeof(struct Node));
  z->key=k;
  z->le=Nu;
  z->ri=Nu;

  while(x!=Nu){
    y=x;
    if(z->key < x->key){
      x=x->le;
    }
    else{
      x=x->ri;
    }
  }

  z->pa=y;
  if(y==Nu){
    ro=z;
  }
  else{
    if(z->key < y->key){
      y->le=z;
    }
    else{
      y->ri=z;
    }
  }
}

void inorder(struct Node *u){
  if(u==Nu){
    return;
  }
  inorder(u->le);
  printf(" %d",u->key);
  inorder(u->ri);
}

void preorder(struct Node *u){
  if(u==Nu){
    return;
  }
  printf(" %d",u->key);
  preorder(u->le);
  preorder(u->ri);
}

int main(){
  int n,i,x;
  char com[20];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(com[0]=='p'){
      inorder(ro);
      printf("\n");
      preorder(ro);
      printf("\n");
    }
  }

  return 0;
}


Measured memory_bytes: 25160
#include <stdio.h>
#include <string.h>

int main()
{
	char String[100001],OutString[100001];
	scanf("%s",String);
	int StringLen = strlen(String),Pos = 0,Diff = 0;
	for(int i = StringLen - 1;i >= 0;i--)
		OutString[Pos] = String[i],Pos++;
	for(int i = 0;i < StringLen;i++)
	{
		if(OutString[i] == 'b') OutString[i] = 'd';
		else if(OutString[i] == 'd') OutString[i] = 'b';
		else if(OutString[i] == 'p') OutString[i] = 'q';
		else if(OutString[i] == 'q') OutString[i] = 'p';
	}
	for(int i = 0;i < StringLen;i++)
		if(OutString[i] != String[i]) Diff++;
	if(Diff == 0) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(){
	int x, y;
	while(true){
		cin >> x >> y;
		if(x == 0 && y == 0) break;
		if(x < y) cout << x << " " << y << endl;
		else cout << y << " " << x << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#-swank
(unless (member :child-sbcl *features*)
  (quit
   :unix-status
   (process-exit-code
    (run-program *runtime-pathname*
                 `("--control-stack-size" "128MB"
                   "--noinform" "--disable-ldb" "--lose-on-corruption" "--end-runtime-options"
                   "--eval" "(push :child-sbcl *features*)"
                   "--script" ,(namestring *load-pathname*))
                 :output t :error t :input t))))
(defmacro dp (name args memo-size &body body)
  (let ((memo (gensym)))
    `(let ((,memo (make-array ,memo-size :initial-element nil)))
       (defun ,name ,args
         (or (aref ,memo ,@args)
             (setf (aref ,memo ,@args)
                   ,@body))))))

(defun split (x str)
  (let ((pos (search x str))
        (size (length x)))
    (if pos
      (cons (subseq str 0 pos)
            (split x (subseq str (+ pos size))))
      (list str))))

(defmacro collect-times (time body)
  `(loop repeat ,time collect ,body))

(defun read-times (time)
  (collect-times time (read)))

(defun main(line &aux (sorted (sort line #'>)))
  (< (car sorted) (apply #'+ (subseq sorted 1))))

(princ (if (main (read-times (read))) "Yes" "No"))


Measured memory_bytes: 18744
from collections import defaultdict
n = int(input())
s = defaultdict(int)
for i in range(n):
    s[input()] += 1

m = 0
for key,value in s.items():
    if value > m:
        m = value
        ans = [key]
    elif value == m:
        ans.append(key)
ans.sort()
print(*ans,sep='\n')

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

int main() {
  int n; cin >> n;

  typedef pair<int,int> xp;
  vector<xp> v(n);

  for(int i = 0; i < n; ++i){
    cin >> v[i].first >> v[i].second;
  }

  int ans = 0;
  for(int i = 0; i < n-2; ++i){
    if(v[i].first==v[i].second && v[i+1].first==v[i+1].second && v[i+2].first==v[i+2].second)
    {ans++;}
  }
  cout << ((ans>0)? "Yes":"No");
}

Measured memory_bytes: 3624
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

int find_left(const std::string& s, int start, char c)
{
  auto index = s.find(c, start);
  return index == std::string::npos ? -1 : index;
}

int find_right(const std::string& s, int start, char c)
{
  auto index = s.rfind(c, start);
  return index == std::string::npos ? -1 : index;
}

long solve(int n, std::string& stones)
{
  int left = find_left(stones, 0, 'W');
  int right = find_right(stones, n - 1, 'R');

  long result = 0;
  for (; left >= 0 && right >= 1 && left < right; ++result) {
    stones[left] = 'R';
    stones[right] = 'W';
    left = find_left(stones, left + 1, 'W');
    right = find_right(stones, right - 1, 'R');
  }

  return result;
}

int main()
{
  int n;
  std::cin >> n;
  std::string stones;
  std::cin >> stones;

  std::cout << std::setprecision(20);
  std::cout << solve(n, stones) << std::endl;
}


Measured memory_bytes: 3564
// Reverse Polish Notation
#include <string>
#include <stack>
#include <iostream>
#include <cstdlib>
using namespace std; 

stack<int> S;
int main() {
  int temp = 0;
  int temp2 = 0;
  string word;
  while (cin >> word) {
    if (word == "+") {
      temp = S.top();
      S.pop();
      temp += S.top();
      S.pop();
      S.push(temp);
    }
    else if (word == "-") {
      temp = S.top();
      S.pop();
      temp2 = S.top();
      S.pop();
      temp = temp2 - temp;
      S.push(temp);
    }
    else if (word == "*") {
      temp = S.top();
      S.pop();
      temp *= S.top();
      S.pop();
      S.push(temp);
    }
    else {
      temp = atoi(word.c_str());
      S.push(temp);
    }
  }
  cout << temp << endl;
}

Measured memory_bytes: 1204
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#include <climits>
#include <cstdlib>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 100001
#define PLUS 0
#define MINUS 1

using namespace std;

struct ST {
	int city_num;
	int year;
};

bool operator<(ST a, ST b)
{
	return a.year < b.year;
}

int N, M;

string get(int hyun, int order)
{
	string ret;
	string left, right;
	left = to_string(hyun);
	right = to_string(order);

	while (left.size() < 6)
		left = "0" + left;
	while (right.size() < 6)
		right = "0" + right;


	ret = left + right;
	return ret;
}

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	cin >> N >> M;
	vector<vector<ST>> vec(N + 1);
	vector<string> str(M);

	for (int i = 0; i < M; i++)
	{
		int p, y; cin >> p >> y;
		vec[p].push_back(ST{i, y});
	}
	for (int i = 1; i <= N; i++)
		sort(vec[i].begin(), vec[i].end());

	for (int i = 1; i <= N; i++)
	{
		for (int j = 0; j < vec[i].size(); j++)
		{
			auto index = vec[i][j].city_num;
			str[index] = get(i, j + 1);
//			cout << index <<  " " << str[index] << endl;
		}
	}

	for (int i = 0; i < M; i++)
		cout << str[i] << endl;

	return 0;
}

Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s;
    cin>>s;
    int len=s.size();
    ll ans=0,p=1,now=0,cnt[2020]={0};
    cnt[0]=1;
    for(int i=len;i--;)
    {
        now=(now+ll(s[i]-'0')*p)%2019;
        ans+=cnt[now]++;
        p=p*10%2019;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  int n,i;
  cin>>n;
  int p[n];
  for(i=0;i<n;i++)cin>>p[i];
  sort(p,p+n);
  int sum=p[n-1]/2;
  for(i=0;i<n-1;i++){
    sum+=p[i];
  }
  cout<<sum;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        
        int ans = 0;
        
        for(int i = 0; i <= a; i++){
            for(int j = 0; j <= b; j++){
                for(int k = 0; k <= c; k++){
                    if(i*500 + j*100 + k*50 ==x){
                        ans++;
                        break;
                    }else if(i*500 + j*100 + k*50 > x){
                        break;
                    }
                }
            }
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 21972
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>
#include<cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

inline ll read(){
    ll Hashimoto=0;
	bool Kanna=1;
    char I_Love=getchar();
    while(I_Love<'0'||I_Love>'9'){
        if(I_Love=='-')Kanna=0;
        I_Love=getchar();
    }
    while(I_Love>='0'&&I_Love<='9'){
        Hashimoto=Hashimoto*10+I_Love-'0';
        I_Love=getchar();
    }
    return (Kanna?Hashimoto:-Hashimoto);
}
template<typename T1,typename T2> inline void Umax(T1 &a,T2 b){
	if(a<b)a=b;
}
template<typename T1,typename T2> inline void Umin(T1 &a,T2 b){
	if(a>b)a=b;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<(Kanna);++I_Love)cout<<Hashimoto[I_Love]<<(I_Love==(Kanna)-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<(Kanna);++I_Love)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define UNIQUE(Kanna) Kanna.erase(unique(Kanna.begin(),Kanna.end()),Kanna.end());
#define inf (1000000000)
#define linf (1000000000000000000ll)
#define mod (1000000007)

int n,m;
int indegree[111111];
vi g[111111];
queue<int>q;
bool v[111111];
int ans[111111];

int I_Love_Hashimoto_Kanna() {
	//完全想清楚了再开始写。
	//写不顺、不知道怎么写、很乱的时候，停下来好好想想。
	//做得慢总比做不出好。
	fastio;
	n=read();m=read();
	FOR(i,1,n+m){
		int a=read()-1,b=read()-1;
		g[a].push_back(b);
		indegree[b]++;
	}
	int root=-1;
	FOR(i,0,n){
		if(indegree[i]==0)root=i;
	}
	assert(root!=-1);
	ans[root]=-1;
	v[root]=1;
	q.push(root);
	while(!q.empty()){
		int x=q.front();
		q.pop();
		FOR(i,0,g[x].size()){
			int to=g[x][i];
			ans[to]=x;
			indegree[to]--;
			if(indegree[to]!=0)continue;
			q.push(to);
			v[to]=1;
		}
	}
	FOR(i,0,n){
		printf("%d\n",ans[i]+1);
	}
	
	return 0;
}


Measured memory_bytes: 7424
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = [0] + lr()
# 後ろから決める、愚直にやって計算時間はNlogN
for i in range(N, 0, -1):
    result = sum(A[i::i]) % 2
    if A[i] != result:
        A[i] = 1 - A[i]

print(sum(A))
print(*[i for i, x in enumerate(A) if x])


Measured memory_bytes: 11696
import java.util.Scanner;

public class Main {// AtCoderは必ずMainクラスで提出する
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int count  = sc.nextInt();
		int[] num = new int[count];
		int sum = 0;
		for(int i = 0 ;i < count;i++) {
			num[i] = sc.nextInt() - 1;
			sum += num[i];
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 26092
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<int> sum(n);
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < 5; ++j)
			{
				int point;
				cin >> point;
				sum[i] += point;
			}
		}
		sort(sum.begin(), sum.end());
		cout << sum[n - 1] << " " << sum[0] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1216
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var HW = Sarray();
            var H = HW[0];
            var W = HW[1];
            for (var i = 0; i < H; ++i) 
            {
                var C = ReadLine();
                WriteLine(C);
                WriteLine(C);
            }
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>

using namespace std;
const long R = 1000000007;

long find(int N, int M)
{
  int l = N > M ? N : M;
  int s = N < M ? N : M;
  if (l == s) {
    long ans = 2;
    for (int i = 1; i <= l; ++i) {
      ans *= i;
      ans %= R;
      ans *= i;
      ans %= R;
    }
    return ans;
  } else if (l == s + 1) {
    long ans = l;
    for (int i = 1; i <= s; ++i) {
      ans *= i;
      ans %= R;
      ans *= i;
      ans %= R;
    }
    return ans;
  } else {
    return 0;
  }
}

int main()
{
  int N, M;
  cin >> N >> M;
  cout << find(N, M) << endl;
  return 0;
}

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

int n;
vector<vector<int>> g(210);

int main() {

    cin >> n;
    vector<string> S(n);
    rep(i, 0, n) {
        cin >> S[i];
        rep(j, i + 1, n) {
            if (S[i][j] == '1') {
                g[i].emplace_back(j);
                g[j].emplace_back(i);
            }
        }
    }
    queue<int> q;
    set<int> s;
    vector<int> col(n);
    q.push(0);
    s.insert(0);
    col[0] = 1;
    while (!q.empty()) {
        for (int i = q.size(); i > 0; i--) {
            int p = q.front();
            q.pop();
            for (auto e : g[p]) {
                if (col[e] * col[p] == 1) {
                    cout << -1 << endl;
                    return 0;
                }
                if (s.find(e) == s.end()) {
                    s.insert(e);
                    q.push(e);
                    col[e] = -col[p];
                }
            }
        }
    }

    int k = 0;
    rep(i, 0, n) {
        int sum = 0;
        while (!q.empty())
            q.pop();
        s.clear();
        q.push(i);
        s.insert(i);

        while (!q.empty()) {
            sum++;
            for (int j = q.size(); j > 0; j--) {
                int p = q.front();
                q.pop();
                for (auto e : g[p])
                    if (s.find(e) == s.end()) {
                        s.insert(e);
                        q.push(e);
                    }
            }
        }
        k = max(k, sum);
    }
    cout << k << endl;
}

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

using namespace std;


#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 2e6 + 1, MOD = 1e9 + 7, mod = 998244353, INF = 3e17;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

int kol[N];

signed main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);
   int ans = 0, n;
   string s;
   cin >> n >> s;
   for (int i = 0; i < s.size(); i++) {
        int kol1 = 1;
        for (char c = 'a'; c <= 'z'; c++) {
            if (c == s[i]) continue;
            kol1*= (kol[c] + 1);
            kol1%= MOD;
        }
        kol[s[i]]++;
        ans+= kol1;
        ans%= MOD;
   }
   cout << ans;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pint pair<int,int>
#define pll pair<ll,ll>
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  long double a,b,x;
  cin >> a >> b >> x;
  long double ans=atanl((long double)(2.0*a*a*b-2.0*x)/(a*a*a));
  if(2*x<a*a*b){
    ans=atanl((a*b*b)/(2.0*x));
  }
  cout << setprecision(10) << (long double)ans*180.0/(long double)M_PI << endl;
return 0;}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

const int nmax = 200;
const int inf = 1e9;

int cost[nmax][nmax];
int d[nmax][nmax];

void dfs(int now,int sum,vector<int> used);
vector<int> root[8];
int r[8];
vector<int> cs;
int R;

int main(){
	int N,M;
	cin >> N >> M >> R;
	for(int i = 0;i < R;i++) cin >> r[i];
	for(int i = 0;i < R;i++){
		for(int j = 0;j < R;j++){
			if(i != j) root[i].push_back(j);
		}
	}
	
	for(int i = 0;i < N;i++){
		fill(cost[i],cost[i] + N,inf);
		cost[i][i] = 0;
	}
	for(int i = 0;i < M;i++){
		int a,b,c;
		cin >> a >> b >> c;
		a--;b--;
		cost[a][b] = c;
		cost[b][a] = c;
	}
	
	for(int k = 0;k < N;k++){
		for(int i = 0;i < N;i++){
			for(int j = 0;j < N;j++){
				cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j]);
			}
		}
	}
	
	for(int i = 0;i < R;i++){
		vector<int> used;
		dfs(i,0,used);
	}
	
	int ans = inf;
	for(int i = 0;i < cs.size();i++){ans = min(ans,cs[i]);}
	cout << ans << endl;
	return 0;
}

void dfs(int now,int sum,vector<int> used){
	used.push_back(now);
	if(used.size() >= R) cs.push_back(sum);
	for(int i = 0;i < root[now].size();i++){
		if(find(used.begin(),used.end(),root[now][i]) == used.end()){
			dfs(root[now][i],sum+cost[r[now]-1][r[root[now][i]]-1],used);
		}
	}
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
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() {
  int N;
  cin >> N;
  string S;
  cin >> S;

  vector<vector<bool>> dp(4, vector<bool>(1000, false));
  dp[0][0] = true;
  for (int i = 0; i < (int)(N); ++i) for (int j = 2; j >= 0; --j) for (int k = 99; k >= 0; --k) {
    if (!dp[j][k]) continue;
    dp[j + 1][k * 10 + (S[i] - '0')] = true;
  }

  cout << accumulate((dp[3]).begin(), (dp[3]).end(), 0) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<ll> A(N,0);
    map<ll,ll> m;
    ll ans=0;
    for(ll i=1; i<=N; i++){
        ll A;
        cin >> A;
        if(m.count(A-i)){
            ans+=m[A-i];
        }
        m[-A-i]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 17156
#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;

#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define REPR(i, n) for(int i = n - 1; 0 <= i; i--)
#define FOR(i, s, e) for(int i = s; i <= e; i++)
#define FORR(i, s, e) for(int i = s; e <= i; i--)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<LLI> a(X), b(Y), c(Z);
    REP(i, X) { cin >> a[i]; }
    RSORT(a);
    REP(i, Y) { cin >> b[i]; }
    RSORT(b);
    REP(i, Z) { cin >> c[i]; }
    RSORT(c);

    vector<LLI> v;
    vector<LLI> v2;
    for(int i = 0; i < X; i++) {
        for(int j = 0; j < Y; j++) {
            v.push_back(a[i] + b[j]);
            if(K < (i + 1) * (j + 1))
                break;
        }
    }
    RSORT(v);
    for(int i = 0, l = v.size(); i < K && i < l; i++) {
        for(int j = 0; j < Z; j++) {
            v2.push_back(v[i] + c[j]);
            if(K < (i + 1) * (j + 1))
                break;
        }
    }
    RSORT(v2);

    REP(i, K) { cout << v2[i] << endl; }

    return 0;
}

Measured memory_bytes: 768
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        public void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(elem => int.Parse(elem)).ToArray();

            var max = 1000000;
            var check = new bool[max + 1];
            var exist = new bool[max + 1];
            foreach (var i in Enumerable.Range(0, N))
            {
                if (check[A[i]])
                {
                    continue;
                }

                if (exist[A[i]])
                {
                    check[A[i]] = true;
                    continue;
                }
                else
                {
                    exist[A[i]] = true;
                }

                for (var j = 2 * A[i]; j <= max; j += A[i])
                {
                    check[j] = true;
                }
            }

            Console.WriteLine(A.Count(elem => check[elem] == false));
        }
    }
}


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

int main(){
    int a,b;
    cin>>a>>b;
    if(a<10 && b<10){
        cout<<a*b<<endl;
    }
    else{
        cout<<-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*
4 3 2 1
0 4 2 2
5 4 3 2 1
0 5 4 4 3 = 16
6 5 4 3 2 1
0 6 5 5 4 4
7 6 5 4 3 2 1
0 7 6 6 5 5 4
8 7 6 5 4 3 2 1
0 8 7 7 6 6 5 5
*/

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

int32_t main()
{
	int n;
  cin >> n;
  vector<int>arr(n);
  for(int i=0;i<n;i++)
    cin >> arr[i];
  sort(arr.begin(), arr.end());
  reverse(arr.begin(), arr.end());
  int ans = arr[0], cnt= 2, i=0;
  for(i=1;cnt<n;i++)
  {
    ans += 2*arr[i];
    cnt += 2;
  }
  if(n>1 && n&1)
    ans -= arr[i-1];
  cout << ans;
}

Measured memory_bytes: 4828
/*******************************
* BASMILLAHHIR RAHMANNIR RAHIM *
* MD SHAHINUR RAHMAN           *
* DATE: 12/sep/2020            *
* DEPT. OF CSE                 *
* LEADING UNIVERSITY, SYLHET   *
*******************************/
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#include<string>
#include<stdlib.h>
#include<math.h>
#define shahin std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
const int nax=1000*1007;
const int mod = 1e9 + 7;

using namespace std;
char wcz[nax];

bool fu(int a, int b){
    return (a>b);
}
ll power(int x, int y) {
    if (y == 0) return 0;
    if (y == 1) return x;
    ll p = power(x, y >> 1);
    if (y & 1) return p * p % mod * x % mod;
    else return p * p % mod;
}
void fun(){
   ll n;
    cin >> n;
    if(n==1)cout << 0 << endl;
    else{
                ll s = power(10,n) - 2* power(9, n) + power(8, n);
                cout << (s+2*mod)%mod << endl;
    }
    
                   
}

int main()
{
    shahin
  /*  ll tc,i=1;
    cin >> tc;
    while(tc--)
    {
    //cout << "Case " << i << ": ";
        fun();
    //i++;
    }*/ 
    fun();
   
}


Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	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;
	}
}

// 二項係数計算
long long COM(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;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] <= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) left = mid;
		else right = mid;
	}
	/* left は条件を満たす最大の値、right は条件を満たさない最小の値になっている */
	return left;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main() {
	int x, n;
	cin >> x >> n;
	int dp[450] = {};
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		dp[a]++;
	}
	int maxdis = 2000;
	int ans = 0;
	for (int i = 400; i>= 1; i--) {
		if (dp[i] == 0&&abs(x - i) <= maxdis) {
			ans = i;
			maxdis = abs(x-i);
		}
	}
	for (int i = 0; i >= -200; i--) {
		if (abs(x - i) <= maxdis) {
			ans = i;
			maxdis = abs(x - i);
		}
	}
	cout << ans;
}

Measured memory_bytes: 3596
#include<stdio.h>
int main(){
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int aa, ab, ac;
	aa = 10 * a + b + c;
	ab = 10 * b + a + c;
	ac = 10 * c + a + b;
	if (aa >= ab&&aa >= ac){
		printf("%d\n", aa);
	}
	else if (ab >= ac&&ab >= aa){
		printf("%d\n", ab);
	}
	else if (ac >= ab&&ac >= aa){
		printf("%d\n", ac);
	}
	return 0;
}

Measured memory_bytes: 128
s = input()
tmp = 0
max = 0
def check(i):
  if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
    return True
  else:
    return False
for i in range(len(s)):
  if check(i):
    tmp += 1
  else:
    tmp = 0
  if tmp > max:
    max = tmp
print(max)

Measured memory_bytes: 61800
// This code wrote by chtholly_micromaker(MicroMaker)
#include <bits/stdc++.h>
#define reg register
using namespace std;
/*
template <class t> inline void read(t &s)
{
	s=0;
	reg int f=1;
	reg char c=getchar();
	while(!isdigit(c))
	{
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(isdigit(c))
		s=(s<<3)+(s<<1)+(c^48),c=getchar();
	s*=f;
	return;
}
*/
map<string,int> vis;
signed main(void)
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	string s;
	int n;cin>>n;
	for(int i=1;i<=n;++i)
		cin>>s,vis[s]+=1;
	vector<string> ans;
	reg int cnt=0;
	for(reg map<string,int>::iterator iter=vis.begin();iter!=vis.end();++iter)
	{
		if(iter->second>cnt)
		{
			cnt=iter->second;
			ans.clear();
			ans.push_back(iter->first);
		}
		else if(iter->second==cnt)
			ans.push_back(iter->first);
	}
	sort(ans.begin(),ans.end());
	for(int i=0;i<(int)ans.size();++i)
		cout<<ans[i]<<endl;
	return 0;
}



Measured memory_bytes: 27376
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    int N;
    cin >> N;
    vc S(N);
    in(N,S);
    
    int s = 0;
    int t = N-1;
    int ans = 0;
    
    
    while (s < t) {
        
        while (S[s] != 'W') {
            s++;
            if(t <= s) break;
        }
        while (S[t] != 'R') {
            t--;
            if(t <= s) break;
        }
        
        if(s < t){
            swap(S[s],S[t]);
            ans++;
        }else{
            break;
        }
    
    }
    
    cout << ans << endl;
    
    

    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char const *argv[]) {
  int n, l;
  cin >> n >> l;
  vector<string> s(n);
  for (size_t i = 0; i < n; i++) cin >> s[i];

  sort(s.begin(), s.end());
  string ans;
  for (size_t i = 0; i < n; i++) ans += s[i];

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


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

int x,n,a[150];

int main()
{
	cin >> x >> n;
	for(int i=1;i<=n;++i)
	{
		int now;
		cin >> now;
		a[now]=1;
	}
	int minans=100000,ans=0;
	for(int i=-100;i<=200;++i)
	{
		if(i>=1 && i<=100 && a[i])continue;
		if(abs(i-x)<minans)
		{
			minans=abs(i-x);
			ans=i;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 3760
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = Integer.parseInt(sc.next());
        }
        
        int[] b = new int[n];
        for(int i=0; i<n-1; i++){
            b[i+1] = (a[i]<a[i+1])? 1 : 0;
            b[i+1] += b[i];
        }
        
        TreeSet<Integer> set = new TreeSet<>();
        for(int i=0; i<k; i++){
            set.add(a[i]);
        }
        
        int ct = (b[k-1]==k-1)? 1 : 0;
        int ans = ct^1;
        for(int i=k; i<n; i++){
            set.add(a[i]);
            boolean ok = (set.first()!=a[i-k]) || (set.last()!=a[i]);
            set.remove(a[i-k]);
            
            if(b[i] - b[i-k+1] == k-1){
                ct = 1;
            }else if(ok){
                ans++;
            }
        }
        
        System.out.println(ans+ct);
    }
    
}

Measured memory_bytes: 66404
// failed to generate code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
vector<ll> cur(1000);

int main(){	
	ll N;
	cin >> N;
	vector< vector<ll> > A(N, vector<ll>(N));
	rep(i, N) {
		rep(j, N-1) {
			scanf("%lld", &A[i][j]);
			A[i][j]--;
		}
	}
	ll res = 0, mincur = 0;
	queue<ll> que;
	rep(i,N) {
		que.push(i);
	}
	while(mincur < N-1) {
		queue<ll> newque;
		vector<ll> oldcur(N);
		rep(i,N) {
			oldcur[i] = cur[i];
		}

		vector<bool> used(N);
		while(!que.empty()) {
			ll i = que.front();
			que.pop();
			if (!used[i] && !used[A[i][oldcur[i]]] && oldcur[i] < N-1 && oldcur[A[i][oldcur[i]]] < N-1 && i == A[A[i][oldcur[i]]][oldcur[A[i][oldcur[i]]]]) {
				used[i] = true;
				used[A[i][oldcur[i]]] = true;
				cur[A[i][oldcur[i]]]++;
				cur[i]++;
				newque.push(A[i][oldcur[i]]);
				newque.push(i);
			}
		}

		ll now = INF;
		rep(i,N) {
			now = min(now, cur[i]);
		}
		mincur = now;

		bool minus = true;
		rep(i,N) {
			// cout << cur[i];
			if (oldcur[i] != cur[i]) {
				minus = false;	
			}
		}
		// cout << endl;
		if (minus) {
			printf("-1\n");
			return 0;
		}
		res++;
		while(!newque.empty()) {
			que.push(newque.front());
			newque.pop();
		}
	}
	printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 10112
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////
int main() {
	ll N, M; cin >> N >> M;
	string S, T; cin >> S >> T;
	ll g = gcd(N, M);
	ll l = N / g * M;
	for (ll i = 0; i < g; ++i) {
		if (S[N*i / g] != T[M*i / g]) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << l << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
#define int long long
#define MAX 100010
#define MAX_C 31

int n, C;
int s[MAX], t[MAX], c[MAX];
int imos[MAX_C][MAX];

void init_imos() {
  for (int i = 0; i <= C; i++) {
    for (int j = 0; j < MAX; j++) {
      imos[i][j] = 0;
    }
  }
}

void use_imos() {
  for (int i = 1; i <= C; i++) {
    for (int j = 1; j < MAX; j++) {
      imos[i][j] += imos[i][j - 1];
    }
  }
}

int solve() {
  int max_overlap = 0;
  for (int j = 0; j < MAX; j++) {
    int count = 0;
    for (int i = 1; i <= C; i++) {
      if (imos[i][j]) count++;
    }
    max_overlap = max(max_overlap, count);
  }
  return max_overlap;
}

signed main() {
  cin >> n >> C;
  init_imos();
  for (int i = 0; i < n; i++) {
    cin >> s[i] >> t[i] >> c[i];
    imos[c[i]][s[i]]++;
    imos[c[i]][t[i] + 1]--;
  }
  use_imos();
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 26880
# -*- coding: utf-8 -*-
a,b,x = list(map(int,input().split()))
from math import atan2,degrees
w = x/a
if w > a * b / 2:
    print(degrees(atan2(2*b - 2*x/a/a,a)))
else:
    print(degrees(atan2(b,2*x/a/b)))


Measured memory_bytes: 3188
s=int(input())
L=[1,1,1]
if s<3:
  print(0)
elif s<6:
  print(1)
elif 6<=s:
  for i in range(s-5):
    x=(L[-1]+L[-3])%(10**9+7)
    L.append(x)
  print(L[-1])

Measured memory_bytes: 63520
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n,m,x;
    cin>>n>>m>>x;
    vector<int> a(m);
    for(int i=0;i<m;i++){
        cin>>a[i];
    }
    int sum_s=0;
    for(int i=0;i<m;i++){
        if(a[i]<x){
            sum_s++;
        }
    }
    cout<<min(sum_s,m-sum_s)<<endl;
    return 0;
}

Measured memory_bytes: 256
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)

int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    double r;
    cin>>r;
    cout<<fixed<<setprecision(9)<<2*PI*r<<endl;
    return 0;
}



Measured memory_bytes: 3788
#include<iostream>
using namespace std;
int main()
{
	int i,j,n,num;
	cin>>n;
	int flag=0;
	for(i=1;i<=n;i++)
	{
		num=0;
		for(j=1;j<=i;j++)
			if(i%j==0&&j%2==1)
				num++;
		if(num==8)
			flag++;
	}
	cout<<flag<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
s,t  = ["a"]*n,["0"]*n
for i in range(n):
    s[i],t[i] = input().split()
x = str(input())

r = [0]

for i in range(len(s)):
    r.append(int(t[i]) + r[i])

for i in range(len(s)):
    if(s[i] == x):
        v = i+1
        break
print(r[len(r)-1] - r[v])

Measured memory_bytes: 3064
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int t=s.nextInt(),h,w,n,x,y;t-->0;){h=s.nextInt()+2;w=s.nextInt()+2;int[]a=new int[n=h*w],b=new int[n*n];for(h=s.nextInt();h-->0;y=s.nextInt()*w+s.nextInt()+w+1,b[x*n+y]=b[y*n+x]=1)x=s.nextInt()*w+s.nextInt()+w+1;for(a[1]=1,h=w+1;h<n;h+=(h+1)%w<1?2:1)a[h]=(b[(h-w)*n+h]<1?a[h-w]:0)+(b[(h-1)*n+h]<1?a[h-1]:0);System.out.println(a[n-1]>0?a[n-1]:"Miserable Hokusai!");}}}

Measured memory_bytes: 13000
n,x,m=map(int,input().split())
id=[-1 for i in range(m+1)]
s=[]
c=0
while id[x]==-1:
    id[x]=c
    c+=1
    s.append(x)
    x=x*x%m
d=c-id[x]
ans=0
if n<=d:
    for i in range(n):
        ans+=s[i]
else:
    for i in range(id[x]):
        ans+=s[i]
    n-=id[x]
    sum=0
    for i in range(d):
        sum+=s[id[x]+i]
    ans+=(n//d)*sum
    n=n%d
    for i in range(n):
        ans+=s[id[x]+i]
print(ans)

Measured memory_bytes: 13160
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n;
    cin>>n;
    vi a(n);
    cin>>a;
    int ans=INF;
    REPF(i,-100,101) {
        int tmp=0;
        REP(j,n) {
            tmp+=(i-a[j])*(i-a[j]);
        }
        chmin(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int n; cin >> n;
  int count = 0;
  vector<int> a(n); for(int i = 0; i < n; ++i) cin >> a[i];
  int alice = 0, bob = 0;
  sort(a.begin(), a.end());
  for(int it = n-1; it >= 0; --it) {
    if(count % 2 == 0) alice += a[it];
    else bob += a[it];
    ++count;
  }
  cout << alice - bob << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k, n;
    int p[1005];
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    sort(p, p + n);
    int ans = 0;
    for (int i = 0; i < k; i++)
    {
        ans += p[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
 
int main(int argc, char **argv) {
    int n, out, hit, total;
    string s;
    cin >> n;
     
    for (int i = 0; i < n; ++i) {
        out = 0;
        hit = 0;
        total = 0;

        while (out < 3) {
            cin >> s;

            if (s == "HIT") {
                if (hit == 3) total++;
                else hit++;
            } 
            else if (s == "HOMERUN") {
                total += hit + 1;
                hit = 0;
            } 
            else {
                out++;
            }
        }
        cout<<total<<endl;
    }
    return 0;
}

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

int main() {
    int r,b,w,g; cin >> r >> b >> w >> g;
    cout << r+b+w+g << endl;
}


Measured memory_bytes: 3076
s = gets.chomp.split(" ").map(&:to_i)
t = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)

MOD = 1000000007
tmax = t.max
amax = a.max

if t[-1] != a[0]
p 0
else

# At Pos 0
ct = 1

bool = false
book = true
bool = true if s[0]==1

if s[0]==2
  if t[0]==a[0] || t[1] == a[1]
  book = true 
  bool = true
  else
  book = false
  end
end

for i in 1..(s[0]-2)
  if t[i] ==a[i] && (t[i] != tmax || a[i] != amax)
    book = false 
  elsif t[i]==a[i] && t[i] == tmax && a[i] == amax
    bool = true
  end
    #min = (t[i]<a[i]) ? t[i] : a[i]
    #ct = (ct * min) % MOD
  if t[i-1] < t[i] || a[i] > a[i+1]
  elsif t[i-1] > t[i] || a[i] < a[i+1]
    book = false
    #min = t[i]#(t[i]<a[i]) ? t[i] : a[i]
    #ct = (ct *,i min) % MOD
  elsif t[i-1] == t[i] && a[i] == a[i+1]
    min = (t[i]<a[i]) ? t[i] : a[i]
    ct = (ct * min) % MOD
  else
    raise
    #p i
  end

end

if book && bool
  p ct % MOD
else
  p 0
end


end



Measured memory_bytes: 17564
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	public final Scanner sc;
	public final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;this.out = out;this.err = err;
	}
	static public final long pair(int a, int b) {return (((long)a) << 32) + b;}
	static public final int getPair1(long v) {return (int)(v >> 32);}
	static public final int getPari2(long v) {return (int)(v & 0xFFFFFFFF);}

	static public final long quad(long a, long b, long c, long d) {
		return ((a&0xFFFF)<< 48) + ((b&0xFFFF)<< 32) + ((c&0xFFFF)<< 16) +(d&0xFFFF);}
	static public final int getQuad1(long v) {return (int)( v >> 48          );}
	static public final int getQuad2(long v) {return (int)((v >> 32) & 0xFFFF);}
	static public final int getQuad3(long v) {return (int)((v >> 16) & 0xFFFF);}
	static public final int getQuad4(long v) {return (int)( v        & 0xFFFF);}

	static public final long record(int e, int m, int i) {
		return quad(-1, e, m, i);
	}
	static public final int re(long record) {
		return getQuad2(record);
	}
	static public final int rm(long record) {
		return getQuad3(record);
	}
	static public final int ri(long record) {
		return getQuad4(record);
	}

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

	private int p;
	private int[] inv;
	private int[] fact;
	private int[] finv;
	public final int mod(long v) {
		v %= p;
		return (int)(v < 0 ? v+p : v);
	}
	public final int mul(long a, long b) {
		return mod(a*b);
	}
	public final void initFact(double limit, double p) {
		initFact((int)limit, (int)p);
	}
	public final void initFact(int limit, int p) {
		this.p = p;
		this.inv = new int[limit+1];
		this.fact = new int[limit+1];
		this.finv = new int[limit+1];
		fact[1] = finv[1] = inv[0] = inv[1] = 1;
		for(int i=2;i<=limit;i++) {
			int a = p / i;
			int b = p % i;
			inv[i]  = mul(-a, inv[b]);
			fact[i] = mul(fact[i-1], i);
			finv[i] = mul(finv[i-1], inv[i]);
		}
	}
	public final int comb(int m, int n) {
		return mul(mul(fact[m], finv[n]), finv[m-n]);
	}

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

	public void exec() throws Exception{
		final int N = sc.nextInt();
		final String S = sc.next();
		StringBuilder str = new StringBuilder();
		for(int i=0;i<26;i++) {
			str.append((char)('A'+i));
		}
		String str2 = str.toString()+str.toString();

		final StringBuilder ans = new StringBuilder();
		for(int i=0;i<S.length();i++) {
			final int idx = (char)(S.charAt(i)-'A'+N);
			ans.append(str2.charAt(idx));
		}
		out.println(ans.toString());

	}
}


Measured memory_bytes: 22228
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;
int gcd( int a, int b) {
  if ( a < b ) return gcd(b, a);
  int r;
  while ( r = a % b ) {
    a = b;
    b = r;
  }
  return b;
}
int main (void) {
    int N, X, ans;
    cin >> N >> X;
    vector<int> a(N);
    cin >> a.at(0);
    ans = X - a.at(0);
    REP(int,i,1,N){
        cin >> a.at(i);
        ans = abs(gcd(ans,X-a.at(i)));
    }
    cout << abs(ans) << endl;
    return 0;
}


Measured memory_bytes: 640