akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <map>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> us(N, 0);
    vector<int> ds(N, 0);
    rep(i, N){
        int tmp;
        cin >> tmp;
        if(i == 0){
            us[i] = tmp;
            continue;
        }
        us[i] = us[i - 1] + tmp;
    }

    rep(i, N){
        int tmp;
        cin >> tmp;
        if(i == 0){
            ds[i] = tmp;
            continue;
        }
        ds[i] = ds[i - 1] + tmp;
    }

    ll ans = 0;

    rep(i, N){
        ll tmp = us[i] + ds[N - 1] - ds[i];
        if(i == 0){
            tmp += ds[0];
        }else{
            tmp += ds[i] - ds[i - 1];
        }
        if(tmp > ans){
            ans = tmp;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
def abc083b():    
    n, a, b = map(int,input().split())

    cnt = 0
    for num in range(n + 1):    
        if a <=sum([int(i) for i in str(num)]) <= b:
            cnt += num
    print(cnt)

if __name__ == '__main__':
    abc083b()

Measured memory_bytes: 2940
import sys



table = [0]*26

letters = "abcdefghijklmnopqrstuvwxyz"
input_str = sys.stdin.read()

for A in input_str:
    index = 0
    for B in letters:
        if A == B or A == B.upper():
            table[index] += 1
            break
        index += 1

for i in range(len(letters)):
    print("%s : %d"%(letters[i],table[i]))


Measured memory_bytes: 5564
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main(){
	int n,a[5000],s,ans;
	
	while(1){
		cin >> n;
		for(int i=0;i<n;i++){
			cin >> a[i] ;
		}
			if(n==0){
				break;
			}
		ans=0;
		for(int i=1;i<=n;i++){
			for(int j=0;j<=n-i;j++){
				s=0;
				if((a[j]<=0)||(a[j+i-1]<=0)){
					goto A;
				}
				for(int k=j;k<j+i;k++){
					s+=a[k];
				}
				if(ans<s){
					ans=s;
				}
					A:;
			}
		}
		if(ans==0){
			for(int i=1;i<n;i++){
				for(int j=0;j<n-i;j++){
					if(a[j]<a[j+1]){
						s=a[j]; a[j]=a[j+1]; a[j+1]=s;
					}
				}
			}
			ans=a[0];
		}
	cout << ans << "\n" ;
	}
return 0;
}

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

int main() {
  int32_t n;
  std::cin >> n;
  std::vector<uint64_t> x(n);
  for (auto &i : x) {
    std::cin >> i;
  }
  const auto y = x;
  std::sort(x.begin(), x.end());
  const auto right = x[x.size() / 2];
  const auto left = x[x.size() / 2 - 1];

  for (const auto i : y) {
    if (i <= left) {
      std::cout << right << std::endl;
    } else {
      std::cout << left << std::endl;
    }
  }

  return 0;
}

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

int main() {
  int N;
  cin >> N;
  int a = N/100;
  int b = N%100;
  int A = 0;
  int B = 0;
  if (1 <= a && 12 >= a)
    A++;
  if (1 <= b && 12 >= b)
    B++;
  
  if (B == 0 && A == 0)
    cout << "NA" << endl;
  if (A == 1 && B == 1)
    cout << "AMBIGUOUS" << endl;
  if (A == 1 && B == 0)
    cout << "MMYY" << endl;
  if (A == 0 && B == 1) 
    cout << "YYMM" << endl;
  
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (signed)(a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define MOD 1000000007
#define pb push_back
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
#define tp(a, b, c) make_tuple(a, b, c)
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
#define bitcnt(a) (ll) __builtin_popcount((a))
using namespace std;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef pair<ll, P> TP;
template <typename T> void fill_all(T &arr, const T &v) { arr = v; }
template <typename T, typename ARR> void fill_all(ARR &arr, const T &v) {
  for (auto &i : arr) {
    fill_all(i, v);
  }
}
//------------------変数-----------------------//
ll n, k, a[114], calc[1145];
//-------------------関数----------------------//

ll dp[114][300][114];

ll DP(ll num, ll x, ll how) {
  if (dp[num][x][how])
    return dp[num][x][how];
  ll cnt = 0;
  if (num == n)
    return (x == k ? calc[how] : 0);
  cnt += DP(num + 1, x ^ a[num], how + 1) + DP(num + 1, x, how);
  return dp[num][x][how] = cnt % MOD;
}

int main() {
  cin >> n >> k;
  REP(i, n) { cin >> a[i]; }
  ll h = 1;
  FOR(i, 1, 114) {
    calc[i] = (h * (i)) % MOD;
    h *= (i);
    h %= MOD;
  }
  cout << DP(0, 0, 0) << endl;
}


Measured memory_bytes: 27520
import java.util.*;

public class Main {
    public static void main(String[] args){
 
	Scanner sc = new Scanner(System.in);
    String a = sc.next();
   
      if(a.charAt(2) ==a.charAt(3) && a.charAt(4)==a.charAt(5)){
	    System.out.println("Yes");
      }else {
  		System.out.println("No");      
      }
}
}

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

int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    
    if(a[0] == a[1] && a[1] == a[2]){
        cout << 0 << endl;
    }
    else if(a[0] == a[1]){
        int p = max(a[0], a[2]);
        int k = min(a[0], a[2]);
        if(p == a[0]){
            int d = p - k;
            if(d % 2 == 0)cout << d / 2 << endl;
            else cout << d / 2 + 2 << endl;
        }
        else{
            cout << p - k;
        }
    }
    else if(a[1] == a[2]){
        int p = max(a[0], a[2]);
        int k = min(a[0], a[2]);
        if(p == a[2]){
            int d = p - k;
            if(d % 2 == 0)cout << d / 2 << endl;
            else cout << d / 2 + 2 << endl;
        }
        else{
            cout << p - k;
        }
    }
    else if(a[2] == a[0]){
        int p = max(a[0], a[1]);
        int k = min(a[0], a[1]);
        if(p == a[0]){
            int d = p - k;
            if(d % 2 == 0)cout << d / 2 << endl;
            else cout << d / 2 + 2 << endl;
        }
        else{
            cout << p - k;
        }
    }
    else{
        int big = max(max(a[0], a[1]), max(a[1], a[2]));
        int small = min(min(a[0], a[1]), min(a[1], a[2]));
        int mid;
        if(a[0] != big && a[0] != small)mid = a[0];
        if(a[1] != big && a[1] != small)mid = a[1];
        if(a[2] != big && a[2] != small)mid = a[2];

        int deg1 = big - mid;
        int deg2 = mid - small;
        if(deg2 % 2 == 0){
            deg1 += deg2 / 2;
        }
        else{
            deg1 += deg2 / 2 + 2;
        }
        cout << deg1 << endl;
    }

    return 0;
}

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

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

    for (int i = 0;i < s.length();i++) {
        s[i] == '1' ? s[i] = '9' : s[i] = '1';
    }

    cout << s << endl;
}


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

const int N = 2005;
const int md = 924844033;

int n, k;
int c[N];
int f[N][N][2][2];

void add(int &x, int y) { x += y; while(x >= md) x -= md; if (x < 0) x += md; }

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> k;
	for (int i = 0; i < k; ++i) c[i] = (n - 1) / k;
	for (int i = 0; i <= (n - 1) % k; ++i) ++c[i];

	int pos = 1;
	int cmd = 0;
	f[0][0][0][0] = 1;
	for (int i = 0; i < n; ++i) {
		for (int rem = 0; rem <= i; ++rem) for (int rem_i = 0; rem_i < 2; ++rem_i) for (int rem_pi = 0; rem_pi < 2; ++rem_pi) {
			if (!f[i][rem][rem_i][rem_pi]) continue;

			int r0 = rem_i, r1 = rem_pi;
			if (i + 1 == pos) r0 = 0, r1 = 0;

			add(f[i + 1][rem][0][1], 1ll * (rem - r1) * f[i][rem][rem_i][rem_pi] % md);
			add(f[i + 1][rem][1][0], 1ll * (rem - r0) * f[i][rem][rem_i][rem_pi] % md);
			add(f[i + 1][rem][0][0], f[i][rem][rem_i][rem_pi] % md);
			add(f[i + 1][rem + 1][1][1], f[i][rem][rem_i][rem_pi] % md);
			if (rem > 0) add(f[i + 1][rem - 1][0][0], 1ll * (rem - r0) * (rem - r1) * f[i][rem][rem_i][rem_pi] % md);
		}
		if (i + 1 == pos) {
			pos += c[cmd]; ++cmd;
		}
	}

	int ans = 0;
	for (int r0 = 0; r0 < 2; ++r0) for (int r1 = 0; r1 < 2; ++r1) {
		add(ans, f[n][0][r0][r1]);
	}

	cout << ans << endl;
}

Measured memory_bytes: 61184
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define BP(x) __builtin_popcountll(x)
#define PQS priority_queue <int, vector<int>, greater<int> > 
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int getRand(int l, int r) {
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}

const int INF = 1e18 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;

void solve() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = max({b*d, a*c, a*d, b*c});
  cout << ans << '\n';
}

/*
  * overflow, array bounds
  * do smth instead of nothing and stay organized
*/
signed main() {   
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

  #ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
  #endif
   int t = 1; // cin >> t;
   for(int i = 1; i <= t; i++) {
   //  cout << "Case #" << i << ": ";
     solve();
  }
}    

/*

*/

Measured memory_bytes: 3652
N, M = list(map(int, input().split()))

a, b = [0] * N, [0] * N
for i in range(N):
    a[i], b[i] = list(map(int, input().split()))

c, d = [0] * M, [0] * M
for i in range(M):
    c[i], d[i] = list(map(int, input().split()))

def calc_dst(n, m):
    return abs(a[n]-c[m]) + abs(b[n]-d[m])

for n in range(N):
    nearest_id = 0
    nearest_dst = calc_dst(n, 0)
    for m in range(1, M):
        dst = calc_dst(n, m)
        if nearest_dst > dst:
            nearest_id = m
            nearest_dst = dst

    print(nearest_id + 1)



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

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

int main(){
    char s[3];
    cin >> s;
    if(s[0] != s[1] || s[0] != s[2] || s[1] != s[2]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 888
// AOJ 1216: Lost in Space
// 2017.10.15

#include <stdio.h>
#include <math.h>

typedef struct { double x, y, z; } PP;
PP pp[33];

double qr0, rp0, pq0;

double dist(PP a, PP b)
{
	double dx, dy, dz;
	dx = a.x - b.x, dy = a.y - b.y, dz = a.z - b.z;
	return sqrt(dx*dx + dy*dy + dz*dz);
}

int check(double a, double b) { return fabs(a-b) < 0.1; }

int main()
{
	int t, n, i, p, q, r;
	double pq, qr, rp;

	scanf("%d", &t);
	while (t-- > 0) {
		scanf("%lf%lf%lf", &qr0, &rp0, &pq0);
		scanf("%d", &n);
		for (i = 0; i < n; i++) scanf("%lf%lf%lf", &pp[i].x, &pp[i].y, &pp[i].z);

		for (p = 0; p < n; p++) for (q = 0; q < n; q++) if (p != q) for (r = 0; r < n; r++) {
			if (r == p || r == q) continue;
			pq = dist(pp[p], pp[q]);
			qr = dist(pp[q], pp[r]);
			rp = dist(pp[r], pp[p]);
			if (check(qr/qr0, rp/rp0) && check(rp/rp0, pq/pq0) && check(pq/pq0, qr/qr0)) {
				printf("%d %d %d\n", p+1, q+1, r+1);
                goto Done;
			}
		}
		Done:;
	}
	return 0;
}

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

using namespace std;

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

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

int tab[10][10];
int dx[] = {-1,0,1,-1,1,-1,0,1};
int dy[] = {-1,-1,-1,0,0,1,1,1};
int calc(int px, int py, int turn, bool flag = false){
  int res = 0;
  int opp = 3 - turn;
  REP(i,8){
	int x = px+dx[i], y = py+dy[i], cnt = 0;
	while(tab[y][x] == opp)
	  x += dx[i], y += dy[i], ++cnt;
  
	if(tab[y][x] == turn){
	  res += cnt;
	  if(flag){
		while(px != x || py != y){
		  tab[y][x] = turn;
		  x -= dx[i], y -= dy[i];
		}
	  }
	}
  }
  return res;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  fill((int*)tab, (int*)tab+10*10, 0);
  REP(y,8){
	string line;
	cin >> line;
	REP(x,8)
	  switch(line[x]){
	  case 'o':
		tab[y+1][x+1] = 1; break;
	  case 'x':
		tab[y+1][x+1] = 2; break;
	  case '.':
		tab[y+1][x+1] = 0; break;
	  }
  }

  bool finish = false;
  while(!finish){
	finish = true;
	int tx = -1, ty, M = 0;
	for(int y=1;y<=8;++y){
	  for(int x=1;x<=8;++x){
		if(tab[y][x] != 0) continue;
		int res = calc(x,y,1);
		if(M < res){
		  M = res;
		  ty = y;
		  tx = x;
		}
	  }
	}
	if(M > 0){
	  tab[ty][tx] = 1;
	  finish = false, calc(tx,ty,1,true);
	}
	  
	tx = -1, ty = -1, M = 0;
	for(int y=8;y>=1;--y){
	  for(int x=8;x>=1;--x){
		if(tab[y][x] != 0) continue;
		int res = calc(x,y,2);
		if(M < res){
		  M = res;
		  ty = y;
		  tx = x;
		}
	  }
	}
	if(M > 0){
	  tab[ty][tx] = 2;
	  finish = false, calc(tx,ty,2,true);
	}
  }

  REP(y,8){
	REP(x,8)
	  switch(tab[y+1][x+1]){
	  case 1:
		cout << 'o'; break;
	  case 2:
		cout << 'x'; break;
	  case 0:
		cout << '.';
	  }
	cout << endl;
  }
  
  return 0;
}

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

int main(){int n,m=0;
          cin>>n;
          if(n/100==9)
            m+=100;
         else if(n/100==1)
            m+=900;
           else
             m+=n/100*100;
          if(n/10%10==1)
            m+=90;
         else if(n/10%10==9)
            m+=10;
          else m+=n/10%10;
          if(n%10==1)
            m+=9;
          else if(n%10==9)
            m+=1;
           else
             m+=n%10;
          cout<<m;
          }


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

template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod = 1e9+7;
const int maxn = 1000005;
const lli inf = 1e18;

int main(){__
	int n;
	cin >> n;
	lli mini = inf,maxi = -inf;
	lli mini2 = inf, maxi2 = -inf;
	for(int i=1; i <=n; i++){
		lli x,y;
		cin >> x >> y;
		mini = min(mini,x+y);
		maxi = max(maxi,x+y);
		mini2 = min(mini2,x-y);
		maxi2 = max(maxi2,x-y);
	}

	cout << max(abs(mini - maxi),abs(maxi2-mini2)) << endl;
	return 0;
}



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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll D, T, S;
    cin >> D >> T >> S;
    if(D <= S * T) cout << "Yes";
    else cout << "No";
    cout << endl;
    return 0;
}


Measured memory_bytes: 3632
public class Main {

    public static void main(String[] args) {
      
        int a , b,c;
        for(a=1;a<=9;a++){
        for(b=1;b<=9;b++){
        c=a*b;
        System.out.println(a+"x"+b+"="+c);
        }
        }
    }
}

Measured memory_bytes: 16852
#include <iostream>
#include <vector>

using namespace std;

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

    int ans = 0;

    int prev;
    cin >> prev;

    for (int i = 1; i < n; i++) {
        int a;
        cin >> a;

        if (a == prev) {
            ans++;

            prev = -1;
        } else {
            prev = a;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;




int main(void) {
    
    int n;
    cin>>n;
    if(n<8) {
        vi v(n),res;
        int m=0;
        rep(i,n)cin>>v[i];
        Sort(v);
        do{
            int diff=0;
            rep(i,n-1){
                diff+=abs(v[i]-v[i+1]);
            }
            if(diff>m){
                m=diff;
                res.clear();
                rep(i,n){
                    res.pb(v[i]);
                }
            }
        }while(next_permutation(all(v)));
        fin(m);
    } else {
        ll p1=0,p2=0;
        vi v(n);
        rep(i,n)cin>>v[i];
        Sort(v);
        if(n%2==1){
            rep(i,n/2)p1-=2*v[i];
            for(int i=n/2;i<n/2+2;i++)p1+=v[i];
            for(int i=n/2+2;i<n;i++)p1+=2*v[i];

            rep(i,n/2-1)p2-=2*v[i];
            for(int i=n/2-1;i<n/2+1;i++)p2-=v[i];
            for(int i=n/2+1;i<n;i++)p2+=2*v[i];
        } else {
            p1+=v[n/2]-v[n/2-1];
            rep(i,n/2-1)p1-=2*v[i];
            for(int i=n/2+1;i<n;i++)p1+=2*v[i];
        }
        fin(max(p1,p2));
    }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1000000007;
const int INF=1001001001;


int main() {
  int64_t N,K;
  cin>>N>>K;
  vector<int>A(N+1);
  for(int i=1;i<=N;i++){
    cin>>A[i];
  }
  vector<int>num(N+1,-1);
  vector<int>q;
  int now=1;
  while(true){
    now=A[now];//cout<<now<<endl;
    q.push_back(now);
    if(q.size()==K){cout<<now<<endl;return 0;}
    if(num[now]!=-1){
      int x=(K-num[now])%(q.size()-num[now]);
      cout<<q[num[now]+x-1]<<endl;return 0; 
    }
    num[now]=q.size();
  }
  return 0;  
}

Measured memory_bytes: 5780
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	ll ans = -1 ;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			ans = i+n/i-2 ;
		}
	}
	cout << ans << endl ;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

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

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  
  cout << z << " " << x << " " << y << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main()
{
	cin>>a>>b;
	if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0])cout<<"YES"<<endl;
    else cout<<"NO"<<endl;//直接判断
    return 0;//完美结束
}
 

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;

typedef long long ll;
ll n, m, ans, i;

int main(){
	int a[3];
	while(~scanf("%d %d %d", &a[0], &a[1], &a[2])){
		int b[2] = {0};
		for(i = 0; i < 3; i++){
			if(a[i] == 5) b[0]++;
			if(a[i] == 7) b[1]++;
		}
		if(b[0] == 2 && b[1] == 1)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

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

int N;
set<int> st;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a;  cin >> a;
		if (st.erase(a)==0) {
			st.insert(a);
		}
	}

	cout << st.size() << endl;
}


Measured memory_bytes: 6272
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include <array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
//AtCoderC++.cpp

using namespace std;

vector<string> split(string& content, char delim) {
	auto ss = vector<string>();
	string s = "";
	for (size_t i = 0; i < content.length(); i++) {
		if (content[i] == delim) {
			ss.push_back(s);
			s = "";
			continue;
		}
		s += content[i];
	}
	if (s != "")ss.push_back(s);
	return ss;
}
vector<bool> available;

int wfs(queue<int> q, int price) {
	auto que = queue<int>();
	while (!q.empty()) {
		auto n = q.front();
		if (price <= n)return n;
		q.pop();
		for (size_t i = 0; i < 10; i++) {
			if (available[i])que.push(n * 10 + i);
		}
	}
	return wfs(que, price);
}

int main() {
	int price, num;
	cin >> price >> num;
	int n;
	available = vector<bool>(10, true);
	for (size_t i = 0; i < num; i++) {
		cin >> n;
		available[n] = false;
	}
	auto que = queue<int>();
	for (size_t i = 1; i < 10; i++) {
		if (available[i]) {
			que.push(i);
		}
	}
	cout << wfs(que, price) << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};

const int N=228,B=60;
int a[N];
int b[2][B];
int ad(int x,int t){
    forn(i,B){
        if(x>>i&1){
            if(b[t][i]==-1){
                b[t][i]=x;
                return 1;
            }else{
                x^=b[t][i];
            }
        }
    }
    return 0;
}
int ch(int x){
    forn(i,B){
        if(x>>i&1){
            if(b[0][i]==-1)return 1;
            x^=b[0][i];
        }
    }
    return 0;
}
int32_t main(){

    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        forn(j,B)b[0][j]=b[1][j]=-1;
        forn(i,n)cin>>a[i];
        string s;
        cin>>s;
        int kek=0;
        for(int i=n-1;i>=0;--i){
            if(s[i]=='0'){
                ad(a[i],0);
            }else{
                if(ad(a[i],1)){
                    kek|=ch(a[i]);
                }
            }
        }
        cout<<kek<<'\n';
    }

    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <cstdlib>
#include <string>
using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	if (a + b >= 24) {
		cout << a + b - 24 << endl;
	}
	else cout << a + b << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static String dream = "dream";
	public static String dreamer = "dreamer";
	public static String erase = "erase";
	public static String eraser = "eraser";

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();

		int pointer = s.length();
		while(true) {
			if (isMatchedString(pointer, s, dream)) {
				pointer -= dream.length();
			} else if (isMatchedString(pointer, s, dreamer)) {
				pointer -= dreamer.length();
			} else if (isMatchedString(pointer, s, erase)) {
				pointer -= erase.length();
			} else if (isMatchedString(pointer, s, eraser)) {
				pointer -= eraser.length();
			} else {
				System.out.println("NO");
				break;
			}
			if (isFinished(pointer, s)) {
				System.out.println("YES");
				break;
			}
		}
	}


	public static boolean isMatchedString(int endIndex, String s, String d) {
		return 0 <= endIndex - d.length() && s.substring(endIndex - d.length(), endIndex).equals(d);
	}

	public static boolean isFinished(int index, String s) {
		return index == 0;
	}

}


Measured memory_bytes: 27632
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    long long n, k;
    cin>>n>>k;
    if (k>=n){cout<<0<<endl;}
    else {
        int h[n];
        for (long long i=0; i<n; i++){
            cin>>h[i];    
        }
        sort(h, h+n);
        long long sum=0;
        for (int i=0; i<n-k; i++){
            sum+=h[i];
        }
        cout<<sum<<endl;
    }
}

Measured memory_bytes: 1024
S = input()
K = int(input())

ccc = 0
for i in range(len(S)):
    if S[i]==S[0]:
        ccc+=1

if ccc==len(S):
    print(len(S)*K//2)
    exit()

groups = []
char = ''
i=0
j=0
while i<len(S) and j<len(S)-1:
    j+=1
    if S[i]==S[j]:
        char = S[i]
    else:
        if j==i+1:
            i=j
            continue
        groups.append((i,j-1))
        char=''
        i = j
if j!=i:
    groups.append((i,j))



if i==j and i==0:
    print(K//2)
    exit()

ans = 0
temp = 0
temp2 = []
for j in range(len(groups)):
    first = groups[j][0]
    end = groups[j][1]
    if first==0 or end==len(S)-1:
        temp += end-first+1
        temp2.append((first,end))
    else:
        ans += (end-first+1)//2*K

if S[0]==S[-1]:
    for j in range(len(temp2)):
        first = temp2[j][0]
        end = temp2[j][1]
        ans += (end-first+1)//2

    ans += temp//2*(K-1)
else:
    for j in range(len(temp2)):
        first = temp2[j][0]
        end = temp2[j][1]
        ans += (end-first+1)//2*K
print(ans)



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	int n; cin >> n;
	vector<int> c(n);
	rep(i,n) cin >> c[i];
	sort(be(c));
	reverse(be(c));
	int a=0;int b=0;
	rep(i,n) {
		if((i+1)%2==1) {
			a+=c[i];
		}
		else b+= c[i];
	}
	cout << abs(a - b) << endl;
}

Measured memory_bytes: 256
//============================================================================
// Name        : ProjG.cpp
// Author      : Yong Kiat
// Version     :
// Copyright   : By Algotae.
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <limits>

using namespace std;

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

	int nums[N];
	for (int i = 0; i < N; i++) {
		cin >> nums[i];
	}

	int dp[N];
	dp[N - 1] = 0;
	for (int i = N - 2; i >= 0; i--) {
		// int minVal = INT_MAX;
        int minVal = numeric_limits<int>::max();
		for (int j = 1; i + j < N && j <= K; j++) {
			int cur = abs(nums[i] - nums[i + j]) + dp[i + j];
			minVal = min(minVal, cur);
		}
		dp[i] = minVal;
	}

	cout << dp[0];

	return 0;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
N = int(input())
S = input()

R = 0
G = 0
B = 0

for i in range(N):
  if S[i] == 'R':
    R += 1
  elif S[i] == 'G':
    G += 1
  else:
    B += 1

count = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    k = 2*j-i
    if k>=N:
      break
    if S[i]!=S[j] and S[k]!=S[i] and S[k]!=S[j]:
      count += 1

print(R*G*B-count)

Measured memory_bytes: 9108
#include<iostream>
#include<vector>
#include<string>
using namespace std;
#define DBG cout<<"!"<<endl;
vector<int> size;
int fin=0;
void dfs(int flag,int count,int i,int now){
  switch(flag){
  case 0:case 2:
    if(count+size[i]>5)
      return;
    if(count+size[i]==5){
      if(flag==0){	
	flag=1;
      }
      if(flag==2)
	flag=3;
    }
    if(flag==0||flag==2)
      dfs(flag,count+size[i],i+1,now);
    else
      dfs(flag,0,i+1,now);
    break;
  case 1:case 3:
    if(count+size[i]>7)
      return;
    if(count+size[i]==7){
      if(flag==1)
	flag=2;
      if(flag==3)
	flag=4;
    }
    if(flag==1||flag==3)
      dfs(flag,count+size[i],i+1,now);
    else
      dfs(flag,0,i+1,now);
    break;
  case 4:
    if(count+size[i]>7)
      return;
    if(count+size[i]==7){
      fin=1;
      cout<<now<<endl;
      return;
    }
    dfs(flag,count+size[i],i+1,now);
  }
}
int main(){
  int n;
  while(cin>>n,n!=0){
    fin=0;
    string str2;
    for(int i=0;i<n;i++){
      cin>>str2;
      size.push_back(str2.size());
    }
    for(int i=0;i<n;i++){
      int flag;
      int cnt=size[i];
      int now=i+1;
      if(fin==1)
	break;
      if(cnt==5){
	flag=1;
	cnt=0;
      }
      else
	flag=0;
      if(cnt>5)
	continue;
      dfs(flag,cnt,i+1,now);
    }
    size.clear();
  }
  return 0;
}

Measured memory_bytes: 3156
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		String b = "ABC";
		String r = "ARC";
		Scanner sc = new Scanner(System.in);
		String in = sc.nextLine();
		sc.close();
		if (b.equals(in)) {
			System.out.println(r);
		} else {
			System.out.println(b);
		}
	}
}


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

int main() {
    int l,r,d;
    cin >> l >> r >> d;
    int count = 0;
    for(int i=l;i<=r;i++){
        if(i%d==0){
            count++;
        }
    }
    cout << count;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,K,k=1,ans=0;
  cin >> A >> B >> K;
  for (int i=100;i>=1;i--) {
    if (A%i==0 && B%i==0) {
      if (k==K) ans = i;
      k++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	if(a[0]==b[2] && a[1]==b[1] && a[2]==b[0]){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
}

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

const int MAX = 10020;
int d[MAX + 5];
int a[MAX + 5];

void div(int n, int *d) {
	int val = 1;
	for (int i = 0; i < MAX; i++) {
		d[i] = val / n;
		val %= n;
		val *= 10;
	}
}

void add(int *src, int *dst) {
	for (int i = MAX - 1; i >= 0; i--) {
		dst[i] += src[i];
	}
	for (int i = MAX - 1; i > 0; i--) {
		dst[i - 1] += dst[i] / 10;
		dst[i] %= 10;
	}
}

void fix(int *tmp, int *a) {
	for (int i = 0; i < MAX; i++) tmp[i] = 0;
	tmp[MAX - 5] = 1;
	add(tmp, a);
}

int main() {
	int n, k, m, r;
	while (cin >> n >> k >> m >> r) {
		if (!n) break;
		for (int i = 0; i < MAX; i++) a[i] = 0;
		
		//add 1/n
		div(n, d);
		add(d, a);
		
		if (m == 1) {
			for (int i = n - 1; i > 0; i--) {
				div(n * i, d);
				add(d, a);
			}
		}
		
		fix(d, a);
		
		cout << a[0] << ".";
		for (int i = 1; i <= r; i++) cout << a[i];
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
 
int main() {
    //Recieve the inputs
    int D, T, S;
    cin >> D >> T >> S;
 
    //Calculate the possible distance of Takahashi's travel
    int dist = S * T;
 
    //Output depending on the inequality between D and dist
    if (dist >= D) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3568
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
    return 0;
}

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

if 400 <= n <= 599:
    print('8')
elif 600 <= n <= 799:
    print('7')
elif 800 <= n <= 999:
    print('6')
elif 1000 <= n <= 1199:
    print('5')
elif 1200 <= n <= 1399:
    print('4')
elif 1400 <= n <= 1599:
    print('3')
elif 1600 <= n <= 1799:
    print('2')
else:
    print('1')

Measured memory_bytes: 61852
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  vector<int> ant(5);
  for (int i = 0; i < 5; i++) {
    cin >> ant.at(i);
  }
  int k;
  cin >> k;
  bool ok = true;
  for (int i = 0; i < 5; i++) {
    for (int j = i + 1; j < 5; j++) {
      if (abs(ant.at(i) - ant.at(j)) > k) {
        ok = false;
      }
    }
  }
  if (ok) {
    cout << "Yay!" << endl;
  }
  else {
    cout << ":(" << endl;
  }
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vt<int>>;

int main(){

  ll n,d,ans = 0;
  cin >> n >> d;

  vt<ll> x(n),y(n);
  rep(i,n) cin >> x[i] >> y[i];

  rep(i,n){
    if(d >= sqrt(x[i]*x[i]+y[i]*y[i]))
    ans++;
  }

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


Measured memory_bytes: 6464
package main

// Solution for https://atcoder.jp/contests/abc179/tasks/abc179_e

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var N, X, M int
	con.Scan(&N, &X, &M)
	mods := make([]int, M)
	for i := 0; i < M; i++ {
		mods[i] = -1
	}
	var p, q, r, s int
	for r = X; mods[r] < 0; r = (r * r) % M {
		mods[r] = q
		q++
	}
	aTotal := 0
	aSum := make([]int, M+1)
	for s = X; s != r; s = (s * s) % M {
		aTotal += s
		aSum[p+1] = aSum[p] + s
		p++
	}
	bTotal := 0
	bSum := make([]int, M+1)
	for i := p; i < q; i++ {
		bTotal += s
		bSum[i-p+1] = bSum[i-p] + s
		s = (s * s) % M
	}
	if N < p {
		con.Println(aSum[N])
	} else {
		x := (N - p) / (q - p)
		y := (N - p) % (q - p)
		con.Println(aTotal + bTotal*x + bSum[y])
	}
	return nil
}


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

string FMT_F = "%.10f";

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

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

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

void main()
{
	auto H = RD;
	auto W = RD;
	auto S = new string[](H);
	foreach (i; 0..H)
	{
		S[i] = RD!string;
	}

	long ans;
	auto dp = new long[2][][](H, W);
	foreach (y; 0..H)
	{
		foreach (x; 0..W)
		{
			if (S[y][x] == '#') continue;
			
			if (dp[y][x][0] == 0)
			{
				long cnt;
				foreach (z; x..W)
				{
					if (S[y][z] == '#') break;
					++cnt;
				}
				foreach (z; x..x+cnt)
				{
					dp[y][z][0] = cnt;
				}
			}
			if (dp[y][x][1] == 0)
			{
				long cnt;
				foreach (z; y..H)
				{
					if (S[z][x] == '#') break;
					++cnt;
				}
				foreach (z; y..y+cnt)
				{
					dp[z][x][1] = cnt;
				}
			}
			ans = max(ans, dp[y][x][0] + dp[y][x][1] - 1);
		}
	}

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

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

int main(void)
{
    char str[65536], temp[65536], memo;
    int i, j, n;
    int rep, cnt, len;
    
    while (1){
        scanf("%d", &rep);
        
        if (rep == 0){
            break;
        }
        
        memset(str, '\0', sizeof(str));
        scanf("%s", str);
        
        while (rep--){
            i = len = 0;
            memset(temp, '\0', sizeof(temp));
            while (str[i] != '\0'){
                cnt = 0;
                memo = str[i];
                while (str[i] == memo && memo != '\0' && str[i] != '\0'){
                    cnt++;
                    i++;
                }
                sprintf(&temp[len], "%d%c", cnt, memo);
                len = strlen(temp);
            }
            strcpy(str, temp);
        }
        
        printf("%s\n", str);
    }
    
    return (0);
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int h, w, k; cin >> h >> w >> k;
    vector<string> c(h);
    for (int i = 0; i < h; ++i) {
        cin >> c[i];
    }

    int ans = 0;
    for (int bit_h = 0; bit_h < (1 << h); ++bit_h) {
        for (int bit_w = 0; bit_w < (1 << w); ++bit_w) {
            vector<string> t = c;

            for (int i = 0; i < h; ++i) {
                if (bit_h & (1 << i)) {
                    for (int j = 0; j < w; ++j) {
                        t[i][j] = 'R';
                    }
                }
            }

            for (int i = 0; i < w; ++i) {
                if (bit_w & (1 << i)) {
                    for (int j = 0; j < h; ++j) {
                        t[j][i] = 'R';
                    }
                }
            }

            int sum = 0;
            for (int i = 0; i < h; ++i) {
                for (int j = 0; j < w; ++j) {
                    if (t[i][j] == '#') {
                        sum++;
                    }
                }
            }

            if (sum == k) {
                ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3624
use petgraph::unionfind::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        n: usize,
        xy: [(usize, usize); n],
    }

    let mut x_points = HashMap::new();
    let mut y_points = HashMap::new();
    for i in 0..n {
        let (xi, yi) = xy[i];
        x_points.entry(xi).or_insert(vec![]).push(i);
        y_points.entry(yi).or_insert(vec![]).push(i);
    }
    // eprintln!("{:?}", x_points);
    // eprintln!("{:?}", y_points);

    let mut components = UnionFind::new(n);
    for i in 0..n {
        let (xi, yi) = xy[i];
        if x_points[&xi].len() > 1 && y_points[&yi].len() > 1 {
            // eprintln!("{} {}", xi, yi);
            for &j in &x_points[&xi] {
                components.union(i, j);
            }
            for &j in &y_points[&yi] {
                components.union(i, j);
            }
        }
    }

    let mut points = vec![vec![]; n];
    for i in 0..n {
        points[components.find(i)].push(i);
    }
    let mut result = 0usize;
    for i in 0..n {
        if points[i].len() > 2 {
            let mut xs = HashSet::new();
            let mut ys = HashSet::new();
            for &i in &points[i] {
                let (xi, yi) = xy[i];
                xs.insert(xi);
                ys.insert(yi);
            }
            result += xs.len() * ys.len() - points[i].len();
        }
    }
    println!("{}", result);
}


Measured memory_bytes: 18976
#include <iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
using namespace std;
int main(void){
   
int n,k;
cin>>n>>k;

int ans=1;
while(n--){
    
    ans= min(ans*2, ans+k);
}
  cout<<ans; 
    
}


Measured memory_bytes: 3192
#include <stdio.h>

int a[100000];

int binary_search(int *lb, int *ub, int k) {
	int *m;
	while (ub - lb > 1) {
		m = lb + ((int)(ub - lb) >> 1);
		if (*m <= k) {
			lb = m;
		}
		else {
			ub = m;
		}
	}
	return *lb == k;
}

int main(void)
{
	int n, q, k, i;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", a + i);
	}
	scanf("%d", &q);
	while (q--) {
		scanf("%d", &k);
		puts(binary_search(a, a + n, k) ? "1" : "0");
	}
	return 0;
}



Measured memory_bytes: 2116
N=int(input())
s=input()
flag=False
def check(s,bef,now,nex):
    if s=='o':
        if now=='S':
            if bef==nex:return True
        elif now=='W':
            if bef!=nex:return True
    elif s=='x':
        if now=='S':
            if bef!=nex:return True
        elif now=='W':
            if bef==nex:return True
    return False

for x in ['SS','SW','WS','WW']:
    if flag==True:break
    ans=x
    bef,now=x[0],x[1]
    for i in range(2,N):
        if s[i-1]=='o':
            if bef==now:
                ans+='S'
                bef,now=now,'S'
            elif bef!=now:
                ans+='W'
                bef,now=now,'W'
        elif s[i-1]=='x':
            if bef!=now:
                ans+='S'
                bef,now=now,'S'
            elif bef==now:
                ans+='W'
                bef,now=now,'W'
    if check(s[N-1],ans[N-2],ans[N-1],ans[0])==True and check(s[0],ans[N-1],ans[0],ans[1])==True:
        flag=True
        break
if flag==False:print('-1')
else:print(ans)

Measured memory_bytes: 3444