akhauriyash/Code-Regression huggingface dataset:
//うんち解！！ｗ
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
using namespace std;

typedef struct st{
	int i;
	string s;
	int p;
}data_t;

void print(vector<data_t> data,int n){
	for (int i = 0; i < n; i++) {
		cout<<data[i].i;
		printf(" ");
		cout<<data[i].s;
		printf(" ");
		cout<<data[i].p;
		printf("\n");
	}
	return;
}

int main(){
	int n;
	
	vector<data_t> data;

	scanf("%d",&n);

	int pi;
	string si;
	for(int i=0;i<n;i++){
		cin>>si;
		cin>>pi;
		st in;
		in.i=i;
		in.s=si;
		in.p=pi;
		data.push_back(in);
	}


	for(int i=0;i<n-1;i++){
		for(int j=n-1;j>i;j--){
			if(data[j-1].p<data[j].p){
				data_t tmp;
				tmp=data[j-1];
				data[j-1]=data[j];
				data[j]=tmp;
			}
		}
	}

	for(int i=0;i<n-1;i++){
		for(int j=n-1;j>i;j--){
			if(data[j-1].s>data[j].s){
				data_t tmp;
				tmp=data[j-1];
				data[j-1]=data[j];
				data[j]=tmp;
			}
		}
	}

	for(int i=0;i<n;i++)cout<<(data[i].i+1)<<endl;
	//print(data,n);
	
	return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char[] S = sc.next().toCharArray();
    int ans = 0;
    for (int i = 0; i < 4; i++) ans += (S[i] == '+') ? 1 : -1;
    System.out.println(ans);
  }
}

Measured memory_bytes: 23892
import numpy as np

K, N = map(int, input().split(" "))
loc = list(map(int, input().split(" ")))
loc = np.array(loc)

dist = np.diff(loc)
dist = np.append(dist, K - loc[N - 1] + loc[0])

most_far = np.max(dist)
print(K - most_far)


Measured memory_bytes: 34168
#include <cstdio>
#include <stack>
#include <queue>
using namespace std;
int main() {
    int n, r;
    while (scanf("%d%d",&n,&r)) {
        if (!n&&!r) break;
        deque<int> deq;
        for (int i=n; i>=1; i--) deq.push_back(i);
        for (int i=0; i<r; i++) {
            int p, c; scanf("%d%d",&p,&c);
            stack<int> ue, shita;
            for (int j=0; j<p-1; j++) {
                ue.push(deq[0]);
                deq.pop_front();
            }
            for (int j=0; j<c; j++) {
                shita.push(deq[0]);
                deq.pop_front();
            }
            while (!ue.empty()) {
                deq.push_front(ue.top());
                ue.pop();
            }
            while (!shita.empty()) {
                deq.push_front(shita.top());
                shita.pop();
            }
//            for (int i=0; i<n; i++) printf("%d%c",deq[i],i==n-1?'\n':' ');
//            puts("");
        }
        printf("%d\n",deq[0]);
    }
}

Measured memory_bytes: 0
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  println!("{}", read::<usize>() + read::<usize>()/2);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

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; }

ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}

int main(){
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    int ans=0;
    for(int i=a;i<=b;i++){
        int s=i%10, t=(i/10000)%10;
        int u=(i/10)%10, v=(i/1000)%10;
        if(s==t && u==v) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math
from collections import deque

def input(f):
    n, = map(int, f.readline().split())
    k = [None for _ in range(n)]
    c = [[] for _ in range(n)]
    for i in range(n):
        tmp = map(int, f.readline().split())
        k[i] = tmp.pop(0)
        c[i] = tmp[:]
    q, = map(int, f.readline().split())
    u = [None for _ in range(q)]
    v = [None for _ in range(q)]
    for i in range(q):
        u[i], v[i] = map(int, f.readline().split())
    
    return n, k, c, q, u, v

def solve(n, k, c, q, u, v):
    graph = [[] for _ in range(n)]
    for i in range(n):
        for j in range(k[i]):
            graph[i].append(c[i][j])
    
    logn = int(math.log(n, 2))+1
    pa = [[None for _ in range(n)] for _ in range(logn+1)]
    depth = [None for _ in range(n)]
    
    def build():
        que = deque()
        que.append(0)
        depth[0] = 0
        while que:
            cur = que.popleft()
            for child in c[cur]:
                depth[child] = depth[cur] + 1
                que.append(child)
            
        for i in range(n):
            for child in c[i]:
                pa[0][child] = i
        for i in range(logn):
            for j in range(n):
                if pa[i][j] != None:
                    pa[i+1][j] = pa[i][pa[i][j]]
    
    def query(u, v):
        while depth[u] != depth[v]:
            if depth[v] < depth[u]:
                u, v = v, u
            d = depth[v] - depth[u]
            for k in range(logn):
                if d & 1:
                    v = pa[k][v]
                d = d >> 1
        for nk in range(logn):
            k = logn - nk - 1
            if pa[k][u] != pa[k][v]:
                u = pa[k][u]
                v = pa[k][v]
        if u == v:
            return u
        return pa[0][u]
    
    depth[0] = 0
    build()

    for i in range(q):
        yield query(u[i], v[i])
    
with open('/dev/stdin') as f:
    for res in solve(*input(f)):
        print(res)


Measured memory_bytes: 60896
#include<stdio.h>

int main( )
{
  int sec,h,m,s;

  scanf("%d",&sec);

  h = sec / 3600;
  m = (sec % 3600) / 60;
  s = sec % 60;
  
  printf("%d:%d:%d\n",h,m,s);

  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, a[N];
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (a[a[i]] == i && i < a[i]) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 4232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define vt vector
#define pq priority_queue
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __fpb(a, b)
const int MOD = 1e9 + 7;
const int INF = 2e9;
const int N = 1e6 + 5;

int n, fpb, cnt;
int a[N], freq[N];
bool valid;

void sieve() {
    valid = true;
    for(int i = 2; i <= N - 5; i++) {
        cnt = 0;
        for(int j = i; j <= N - 5; j += i) {
            cnt += freq[j];
        }
        if(cnt > 1) valid = false;
    }
}

void solve() {
    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        freq[a[i]]++;
    }
    fpb = a[1];
    for(int i = 2; i <= n; i++) {
        fpb = __gcd(fpb, a[i]);
    }
    if(fpb > 1) {
        cout << "not coprime\n";
        return;
    }
    sieve();
    cout << (!valid ? "setwise coprime\n" : "pairwise coprime\n");
}

int main() {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    solve();
    
}

Measured memory_bytes: 11488
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main(){
  string S;
  cin >> S;
  int ans = 0;
  rep(i, S.size()-1) {
    if(S[i] != S[i+1])
      ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1020
#include "bits/stdc++.h"
using namespace std;

long long A, B, N;

int main()
{
  cin >> A >> B >> N;
  long long MR = 0;

  long long i = min(B - 1, N);
  MR = (A * i) / B - A * (i / B);

  cout << MR << endl;
}


Measured memory_bytes: 3628
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define REP(i, x) for(int i = 0; i < (int)(x); i++)
#define REPS(i,x) for(int i = 1; i <= (int)(x); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x,y) memset(x,y,sizeof(x))
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define PB(a) push_back(a)
#define debug(x) cerr << __LINE__ << ": " << #x << " -> " << x << '\n'
#define INF 999999999
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

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

  int n;
  cin >> n;
  int t[n+1], x[n+1], y[n+1];
  t[0] = 0; x[0] = 0; y[0] = 0;
  debug(n);
  REPS(i, n){
    debug(i);
    cin >> t[i] >> x[i] >> y[i];
  }

  int diff;
  REPS(i, n){
    diff = 0;

    diff += abs(x[i] - x[i-1]);
    diff += abs(y[i] - y[i-1]);
    debug(diff);
    if (diff > abs(t[i]-t[i-1]) or (abs(t[i]-t[i-1])-diff)%2!=0){
      puts("No");
      return 0;
    }
  }
  puts("Yes");

  return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
    char suit;
    int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge (struct Card A[], int n, int left, int mid, int right) {
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for ( i = 0; i < n1; i++) L[i] = A[left + i];
    for ( i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1].value = R[n2].value = SENTINEL;
    i = j = 0;
    for (k = left; k < right; k++) {
        if (L[i].value <= R[j].value) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
        }
    }
}

void mergeSort (struct Card A[], int n, int left, int right) {
    int mid;
    if (left + 1 < right) {
        mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[], int n, int p, int r) {
    int i, j;
    struct Card t, x;
    x = A[r];
    i = p - 1;
    for ( j = p; j < r; j++) {
        if ( A[j].value <= x.value ) {
            i++;
            t = A[i]; A[i] = A[j]; A[j] = t;
        }
    }
    t = A[i + 1]; A[i + 1] = A[r]; A[r] = t;
    return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r) {
    int q;
    if (p < r) {
        q = partition(A, n, p, r);
        quickSort(A, n, p, q - 1);
        quickSort(A, n, q + 1, r);
    }
}

int main(){
    int n, i, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n - 1);

    for (i = 0; i < n; i++) {
        
        if (A[i].suit != B[i].suit) stable = 0;
    }
    
    if (stable == 1) printf("Stable\n");
    else printf("Not stable\n");
    for (i = 0; i < n; i++) {
        printf("%c %d\n", B[i].suit, B[i].value);
    }
    
    return 0;
}



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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int l ,r;
  l = a + b;
  r = c + d;
  if (l < r) {
    cout << "Right" << endl;
  }
  else if (l > r) {
    cout << "Left" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> PLL;

int main() {
    int N, M;
    int c[500], d[500];

    cin >> N >> M;
    for (int j = 0 ; j < M; ++j) {
        cin >> c[j] >> d[j];
    }

    int arr[1010];
    fill(arr, arr+1010, 0);

    for (int j = 0; j < M; ++j) {
        --arr[c[j]];
        ++arr[d[j]];
    }

    for (int j = 1; j < N+1; ++j) {
        arr[j] += arr[j-1];
    }

    int ret = 0;
    for (int j = 1; j <= N+1; ++j) {
        if (arr[j] == 0) {
            ++ret;
        } else {
            ret += 3;
        }            
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3092
#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

class Solution {
public:
    void solve(std::istream& in, std::ostream& out) {
        int a, b;
        in >> a >> b;
        if (a + b >= 10)
        {
            out << "error";
        }
        else
        {
            out << a + b;
        }
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
int n;
pair<pair<int,int>,int > a[100010];
int dp[100010][4];

int recur(int i, int ant){
    if(i == n) return 0;
    if(dp[i][ant] != -1) return dp[i][ant];
    else{
        if(ant == 0){
            return dp[i][ant] = max(recur(i+1,1) + a[i].ff.ff,max(recur(i+1,2) + a[i].ff.ss,recur(i+1,3) + a[i].ss));
        }else if(ant == 1){
            return dp[i][ant] = max(recur(i+1,2) + a[i].ff.ss,recur(i+1,3) + a[i].ss);
        }else if(ant == 2){
            return dp[i][ant] = max(recur(i+1,1) + a[i].ff.ff,recur(i+1,3) + a[i].ss);
        }else{
            return dp[i][ant] = max(recur(i+1,2) + a[i].ff.ss,recur(i+1,1) + a[i].ff.ff);
        }
    }
}

int main(){
    cin>>n;
    for(int i = 0 ; i < n; i++) cin>>a[i].ff.ff>>a[i].ff.ss>>a[i].ss;
    memset(dp,-1,sizeof dp);
    cout<<recur(0,0);
}


Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64


int main(){
    int n;
    cin >> n;
    int i=0;
    while( 1<< (i+1) <=n) i+=1;
    cout << (1<<i) << endl;
}

Measured memory_bytes: 256
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")

// #pragma GCC optimize("O3")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

void solve() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  ll ans = 0ll;
  for (int i = 0; i <= 3000; i++) {
    for (int j = 0; j <= 3000; j++) {
      int rem = N - R * i - G * j;
      if (rem < 0) continue;
      if (rem % B == 0) ans++;
    }
  }
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  //   int t;
  //   cin >> t;
  //   while (t--) solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
d=[]
for i in range(m-1):
    d.append(a[i+1]-a[i])
d.sort()
total=0
for i in range(m-n):
    total+=d[i]
print(total)


Measured memory_bytes: 13968
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

template<typename T>inline void upmin(T &x,T y) { y<x?x=y:0; }
template<typename T>inline void upmax(T &x,T y) { x<y?x=y:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;

const int N=1e5+100;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

int val[N];
int head[N],nxt[N*2],to[N*2];
bool vis[N];
VI w,cur;
inline void dfs(int k) {
	vis[k]=true;
	cur.pb(val[k]);
	for (int i=head[k];i;i=nxt[i])
		if (!vis[to[i]])
			dfs(to[i]);
}
int main()
{
	int n=gi(),m=gi(),i,a,b,tot=0,num=0;LL ans=0;
	for (i=0;i<n;i++) val[i]=gi();
	while (m--) {
		a=gi(),b=gi();
		to[++tot]=b,nxt[tot]=head[a],head[a]=tot;
		to[++tot]=a,nxt[tot]=head[b],head[b]=tot;
	}
	for (i=0;i<n;i++)
		if (!vis[i]) {
			++num;
			cur.clear();
			dfs(i);
			ans+=*min_element(cur.begin(),cur.end());
			cur.erase(min_element(cur.begin(),cur.end()));
			for (int t:cur) w.pb(t);
		}
	if (num==1)
		puts("0");
	else {
		sort(w.begin(),w.end());
		num-=2;
		if (w.size()<num) puts("Impossible");
		else {
			for (i=0;i<num;i++) ans+=w[i];
			cout<<ans<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3832
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>
#include<time.h>
typedef long long int ll;
//#include<bits/stdc++.h>


using namespace std;



int main()
{
   
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int t;
        cin >> t;
        n -= t;
    }
    if (n < 0)cout << -1 << endl;
    else cout << n << endl;

    return 0;

}

Measured memory_bytes: 3608
N,X,M = map(int, input().split())
A = [X]
S = set(A)
cnt = 0
i = 0
for i in range(1, N):
    A.append(A[i-1] ** 2 % M)
    if A[i] in S:
        break
    else:
        S.add(A[i])
roup_cycle = i - A.index(A[i])
before_roup_sums = sum(A[:A.index(A[i])])
roup_sums = sum(A[A.index(A[i]):i])

if roup_cycle != 0:
    roup_amount = (N - A.index(A[i])) // roup_cycle
    roup_mod = (N - A.index(A[i])) % roup_cycle
    print(before_roup_sums + roup_sums * roup_amount + sum(A[A.index(A[i]):(A.index(A[i]) + roup_mod)]))
else:
    print(sum(A))

Measured memory_bytes: 77224
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n=0;
int count=0;
int arr[1000];
cin>>n;
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
for(int i=0;i<n;i=i+2)
{
if(arr[i]%2!=0)
{
count++;
}
}
cout<<count;
}

Measured memory_bytes: 3592
takahashi, aoki, k = map(int, input().split(" "))


if k >= takahashi:
    k -= takahashi
    takahashi = 0
    if k >= aoki:
        k -= aoki
        aoki = 0
    else:
        aoki -= k 
else:
    takahashi -= k
        
print(takahashi, aoki)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[12];
    for(int i=0;i<12;i++){
        cin>>a[i];
    }
    sort(a,a+12);
    for(int i=0;i<12;i+=4){
        if(a[i]!=a[i+3]){
            cout<<"no"<<endl;
            return 0;
        }
    }
    cout<<"yes"<<endl;
    return 0;
}


Measured memory_bytes: 3124
open System

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f

    let readInts() =
        read string
        |> Seq.toArray
        |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<EntryPoint>]
let main _ =
    let N = read int

    seq {
        let mutable acc = 0
        for i in 1 .. N do
            acc <- acc + i
            if acc >= N then yield (i, acc)
    }
    |> Seq.head
    |> fun (i, acc) ->
        let y = acc - N
        for j in 1 .. i do
            if j <> y then printfn "%d" j
    0 // return an integer exit code


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

int main()
{
	long long x;
	scanf("%lld", &x);
	long long A, B;
	for(long long i = -300; i <= 300; i++) {
		for(long long j = -300; j <= 300; j++) {
			if((long long)pow(i, 5) - (long long)pow(j, 5) == x) {
				A = i;
				B = j;
				break;
			}
		}
	}
	printf("%lld %lld\n", A, B);
}

Measured memory_bytes: 4176
def resolve():
    S = input()
    # 色が変わる回数=色を統一するために必要な手数
    prev_color = S[0]
    color_change_count = 0
    for s in S:
        if s != prev_color:
            color_change_count += 1
            prev_color = s
    print(color_change_count)

resolve()

Measured memory_bytes: 9080
N,X=[int(x) for x in str(input()).split()]

num=[1]
for i in range(1,51):
  num.append(2*num[-1]+3)

full=[1]
for i in range(1,51):
  full.append(2*full[-1]+1)



def f(n,x):
  if n==0:
    return(1)
  else:
    if x==1:
      return 0
    elif x<=num[n-1]+1:
      return f(n-1,x-1)
    elif x==num[n-1]+2:
      return 1+full[n-1]
    elif x==num[n]:
      return 1+2*full[n-1]
    else:
      return 1+full[n-1]+f(n-1,x-2-num[n-1])
    

print(f(N,X))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define mp make_pair
#define debug1(a) cout<<"------\n"<<#a<<" = "<<a<<endl<<"------"<<endl
#define debug2(a,b) cout<<"--------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<endl<<"--------------"<<endl
#define debug3(a,b,c) cout<<"----------------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<" ; "<<#c<<" = "<<c<<endl<<"----------------------"<<endl
#define sz(a) (ll)(a.size())
#define debug4(a) cout<<"chu "<<a<<endl
#define endl "\n"

ll a[55];

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll n;
  cin>>n;
  forn(i,1,n+1){
    cin>>a[i];
  }
  bool f=1,f1=1;
  forn(i,1,n+1){
    if(a[i]==i) continue;
    else if(a[a[i]]==i && f1==1) {swap(a[i],a[a[i]]);f1=0;}
    else {f=0;break;}
  }
  if(f){
    cout<<"YES\n";
  }else{
    cout<<"NO\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i,N,K,n1,n2,temp,sum;
  n1 = n2 = temp = 1;
  cin >> N >> K;
  
  for(i=0;i<N;i++){
  	n1 *= 2;
    n2 += K;
    if(n1 < n2){
      temp = n1;
    }else{
      temp = n2;
    }
    n1 = temp;
    n2 = temp;
  }
  cout << temp << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  for (auto it = vc.begin(); it != vc.end(); ++it)
  {
    if (std::next(it) == vc.end())
      os << *it;
    else
      os << *it << ' ';
  }
  return os;
}

template<class T1, class T2>
inline
std::ostream & operator<<(std::ostream & os, const std::pair<T1, T2> & p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  using std::cout;
  ui A{}, B{}, K{}; std::cin >> A >> B >> K;

  ui cnt{}, ans{};
  rep_ui_down(std::min(A, B), 0)
  {
    if(A % i == 0
    && B % i == 0)
    {
      ++cnt;
      if(cnt == K)
      {
        ans = i;
        break;
      }
    }
  }

  assert(ans != 0);
  cout << ans << '\n';
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

int main() {
	long a, b, d, r;
	double f;
	cin >> a >> b;
	d = a / b;
	r = a % b;
	f = double(a) / double(b);
	cout << d << " " << r << " " << fixed << setprecision(10) << f << endl;
}

Measured memory_bytes: 1244
import javax.swing.text.MutableAttributeSet;
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        int[] cost = new int[n];
        for (int i = 1; i < n; i++) {
            int min = Integer.MAX_VALUE;
            for (int j = 1; j <= k; j++) {
                if (i - j < 0) continue;
                min = Math.min(cost[i-j] + Math.abs(h[i-j] - h[i]) , min);
            }
            cost[i] = min;
        }

        System.out.println(cost[n-1]);

    }
}


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

int a,b,c,n,m;
string s;

int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>m;
  vector<int> v(n);
  rep(i,n) cin>>v[i];
  sort(v.begin(), v.end(), greater<int>());
  if(v[m-1] >= accumulate(v.begin(), v.end(), 0)/(4.0*m)) cout<<"Yes";
  else cout<<"No";
	

  return 0;
}



Measured memory_bytes: 256
// g++ -std=gnu++1y -O2 main.cpp

#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <utility>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <climits>

using namespace std;

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; }

bool hasValue (const vector<vector<int>>& A, int b, int& i_, int& j_) {
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			if (A[i][j] == b) {
				i_ = i;
				j_ = j;
				return true;
			}
		}
	}
	return false;
}

int main() {
	vector<vector<int>> A(3, vector<int>(3, -1));
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> A[i][j];
		}
	}

	vector<vector<bool>> result(3, vector<bool>(3, false));

	int N;
	cin >> N;
	for (int n = 0; n < N; n++) {
		int b;
		cin >> b;

		int i, j;
		if (hasValue(A, b, i, j)) {
			result[i][j] = true;
		}
	}

	bool ans = false;
	for (int i = 0; i < 3; i++) {
		if (result[i][0] && result[i][1] && result[i][2]) {
			ans = true;
			break;
		}
	}
	for (int j = 0; j < 3; j++) {
		if (result[0][j] && result[1][j] && result[2][j]) {
			ans = true;
			break;
		}
	}
	
	if (result[0][0] && result[1][1] && result[2][2]) {
		ans = true;
	}

	if (result[2][0] && result[1][1] && result[0][2]) {
		ans = true;
	}

	if (ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

int t[6];

void ra(){
  int tmp=t[0];
  t[0]=t[4];
  t[4]=t[5];
  t[5]=t[1];
  t[1]=tmp;
}

void rb(){
  int tmp=t[0];
  t[0]=t[2];
  t[2]=t[5];
  t[5]=t[3];
  t[3]=tmp;
}

int n;
string str;
int main(){
  while(cin>>n&&n){
    for(int i=0;i<6;i++)t[i]=i+1;
    while(n--){
      cin>>str;
      if(str=="north"){
        ra();
      }else if(str=="south"){
        ra();ra();ra();
      }else if(str=="east"){
        rb();
      }else{
        rb();rb();rb();
      }
    }
    cout<<t[0]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
import java.util.*;
import java.io.*;

public class Main {
 
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
	    int n = in.readInt();
	    char s[] = in.readString().toCharArray();
	    long r = 0, g = 0, b = 0; 
	    
	    for(int i = 0; i<n; i++) {
	    	if(s[i] == 'R') r++; 
	    	if(s[i] == 'G') g++; 
	    	if(s[i] == 'B') b++; 
	    }
	    long total = r*g*b; 
	    int ans = 0; 
	    int rgb = (int)'R' + (int)'G' + (int)'B'; 
	    for(int i = 0; i<n; i++) {
	    	for(int j = i+1; j<n; j++) {
	    		int k = 2*j - i; 
	    		if(k < n) 
	    			if((int)s[i] + (int)s[j] + (int)s[k] == rgb) 
	    				total--;  
	    	}
	    }
	    System.out.println(total); 
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


Measured memory_bytes: 32992
#include "bits/stdc++.h"
using namespace std;
 
int main(){
	string s;
	cin>>s;
	
	for(int i=0;i<s.size()-1;i++){
		if(s[i]=='A'&&s[i+1]=='C'){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	
	cout<<"No"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a, b = 2.times.map { gets.split.map(&:to_i) }

answer = b.each_with_index.reduce(0) do |s, (y, i)|
  if a[i] < y
    tmp = y - a[i]
    if a[i + 1] - tmp >= 0
      a[i + 1] -= tmp
      s += a[i] + tmp
    else
      tmp2 = a[i + 1]
      a[i + 1] = 0
      s += a[i] + tmp2
    end
  else
    s += y
  end
end

puts answer

Measured memory_bytes: 19476
N, M = gets.split.map &:to_i
A = N.times.map{
  gets.chomp.chars
}
B = M.times.map{
  gets.chomp.chars
}
# p A, B

(0..N-M).each{|ay|
  (0..N-M).each{|ax|
    ok = true
    (0...M).each{|by|
      (0...M).each{|bx|
        ok = false if A[ay+by][ax+bx] != B[by][bx]
        break if !ok
      }
      break if !ok
    }
    if ok
      puts :Yes
      exit
    end
  }
}
puts :No

Measured memory_bytes: 1916
N, A, B = map(int, input().split())
MOD = 10**9 + 7


def f(n, a):
    x, y = 1, 1
    for i in range(1, a+1):
        x = x * (n-i+1) % MOD
        y = y * i % MOD
    return x, y


def modpow(a: int, p: int, mod: int) -> int:
    res = 1
    while p > 0:
        if p & 1 > 0:
            res = res * a % mod
        a = a**2 % mod
        p >>= 1
    return res


ans = modpow(2, N, MOD) - 1
a_x, a_y = f(N, A)
b_x, b_y = f(N, B)

a = a_x * modpow(a_y, (MOD-2), MOD) % MOD
b = b_x * modpow(b_y, (MOD-2), MOD) % MOD
print((ans - a - b) % MOD)


Measured memory_bytes: 3064
#if 0
所要時間は15分ぐらいであった。week１の時この授業を選んでいないので、week２からこの授業受け始めるゆえ、week１の課題の提出が遅れてしまった、迷惑をおかけてすみませんでした。
#endif // 0
#include<iostream>
#include<vector>
#include <memory>
using namespace std;

class MinMaxSumSolver {
    vector<int>A;
    int N;
public:
       long int Max(){
        long int m=-1000000;
        for(int i=0;i<A.size();i++)
        {
        if(A[i]>m)
            m=A[i];
        }
        return m;
    }


        long int Min(){
            int m=1000000;
            for(int i=0;i<A.size();i++)
                {
                    if(A[i]<m)
                    m=A[i];
                    }
            return m;
        }

       long long sum()
        {
            long long m=0;
            for(int i=0;i<A.size();i++)
                m+=A[i];
            return m;
        }

        void solve()
        {
            cin>>N;
            for(int i=0;i<N;i++)
                {
                    int x;
                    cin>>x;
                    A.push_back(x);
                }
            cout<<Min()<<' '<<Max()<<' '<<sum()<<endl;
        }
};

int main()
{
    auto_ptr<MinMaxSumSolver>solver(new MinMaxSumSolver());
    solver->solve();
}




Measured memory_bytes: 3272
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define acc(v) accumulate(v.begin(), v.end(), 0)

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

int main()
{
	int n;
	cin >> n;
	string a, b;
	cin >> a >> b;
	rep(i,n){
		cout << a[i] << b[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  int n;
  cin >> n;
  if(n <= 999) cout << "ABC" << endl;
  else cout << "ABD" << endl;
  return 0;
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  set<string> st;
  for (int i = 0; i < N; i++)
  {
    string S;
    cin >> S;
    st.insert(S);
  }
  cout << st.size() << endl;
  return 0;
}


Measured memory_bytes: 19140
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

satisfy = 0
for i in range(N):
    if A[i] == A[i - 1] + 1 and i >= 1:
        satisfy += C[A[i - 1] - 1]
    satisfy += B[A[i] - 1]
print(satisfy)

Measured memory_bytes: 38256
import java.util.*;
import static java.lang.System.*;
public class Main {
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    int K = sc.nextInt();
    StringBuilder SB = new StringBuilder();
    String x = S.substring(K-1,K);
    for (int i=0; i<N; i++) {
      if (S.substring(i,i+1).equals(x))
        SB.append(x);
      else
        SB.append("*");
    }
    out.println(SB);
  }
}

Measured memory_bytes: 35496
#include <stdio.h>
#define N 1000

int main(void){
  int n,u,k,i,j,x;
  int Adj[N][N];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&x);
      Adj[u-1][x-1] = 1;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n-1;j++){
      printf("%d ",Adj[i][j]);
    }
    printf("%d\n",Adj[i][j]);
  }

  return 0;
}

Measured memory_bytes: 992
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  ll a,b,c,d,e,f;
  cin >> a >> b>> c >> d >> e >> f;
  int flag = 1;
  ll sum = 0;
  vector <ll> A;
  REP(i,f/a+1){
    REP(j,f/b+1){
      sum = a*100*i+ b*100*j;
      if(sum <= f){
	A.pb(sum);
      }
      else
	break;
    }

  }
  vector <ll> B;
  REP(i,f){
    REP(j,f){
      sum = c*i+ d*j;
      if(sum <= f){
	B.pb(sum);
      }
      else
	break;
    }

  }
  //cout << "sfgsf" << endl; 
  /*REP(i,A.size()){
    cout << A[i] << "  ";
  }
  cout << endl;
  sort(B.begin(),B.end());
  REP(i,B.size()){
    cout << B[i] << "  ";
  }
  cout << endl;*/
  double res,E,bres = 0;
  ll sum1=0,sum2=0;
  
  REP(i,A.size()){
    REP(j,B.size()){
      
      if(A[i] != 0){
	res = (double)B[j]/(A[i]+B[j])*100;
	E = (double)e/(100+e)*100;
	//cout << res  << "  " << E << endl;
	if(A[i]+B[j] <= f && res <= E){
	  if(res >= bres){
	    sum1 = A[i]+B[j];
	    sum2 = B[j];
	    bres = res;
	  }
	}
      }
    }
  }
  if(sum1 == 0)
    sum1 = A[2];
  cout << sum1 << " " << sum2 << endl;
  return 0;
}


Measured memory_bytes: 2420
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;
static large mod;

static int digitcount(large x) {
    auto cnt = 1;
    while (x > 9) {
        ++cnt;
        x /= 10;
    }
    return cnt;
}

struct mat3x3 {
    large a[3][3];
    static const mat3x3 identity;
};

const mat3x3 mat3x3::identity{{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}};

mat3x3 operator+(mat3x3 x, mat3x3 y) {
    for (auto i = 0; i < 3; ++i)
        for (auto j = 0; j < 3; ++j)
            x.a[i][j] += y.a[i][j];
    return x;
}

mat3x3 operator-(mat3x3 x, mat3x3 y) {
    for (auto i = 0; i < 3; ++i)
        for (auto j = 0; j < 3; ++j)
            x.a[i][j] -= y.a[i][j];
    return x;
}

mat3x3 operator*(mat3x3 x, mat3x3 y) {
    auto m = mat3x3{};
    for (auto i = 0; i < 3; ++i)
        for (auto j = 0; j < 3; ++j)
            for (auto k = 0; k < 3; ++k)
                m.a[i][j] += x.a[i][k] * y.a[k][j];
    return m;
}

mat3x3 operator%(mat3x3 x, large y) {
    for (auto&& row : x.a)
        for (auto&& elem : row)
            elem %= y;
    return x;
}

mat3x3 power_mod(mat3x3 m, large e, large mod) {
    assert(e >= 0);
    m = m % mod;
    if (e == 0)
        return mat3x3::identity;
    if (e == 1)
        return m;

    auto p = (e % 2 == 0 ? mat3x3::identity : m);
    return p * power_mod(m * m % mod, e / 2, mod) % mod;
}

int main() {
    large l, a, b, m;
    cin >> l >> a >> b >> m;
    mod = m;

    // s_i = A + B * i

    auto last_i_for_len = vector<large>(18 + 1, -1'000'000);
    auto upper = 9LL;
    for (int declen = 1; declen <= 18; declen++, upper = (upper * 10 + 9)) {
        if (a > upper) {
            last_i_for_len[declen] = -1;
            continue;
        }

        last_i_for_len[declen] = (upper - a) / b;
    }

    auto cnt_for_len = vector<large>(18 + 1, 0);
    auto i = 0LL;
    for (int declen = 1; declen <= 18; declen++) {
        if (last_i_for_len[declen] < 0) {
            cnt_for_len[declen] = 0;
            continue;
        }
        if (i >= l) {
            cnt_for_len[declen] = 0;
            continue;
        }

        auto last_i = last_i_for_len[declen];
        if (last_i > l - 1)
            last_i = l - 1;
        if (i <= last_i) {
            cnt_for_len[declen] = last_i - i + 1;
        }
        i = last_i + 1;
    }

    auto tens = 10LL;
    auto matrix = mat3x3::identity;
    for (int declen = 1; declen <= 18; declen++, tens *= 10) {
        const auto cnt = cnt_for_len[declen];
        if (cnt <= 0)
            continue;

        auto mat = mat3x3{tens, 0, 0, 1, 1, 0, 0, b, 1} % mod;
        mat = power_mod(mat, cnt, m) % mod;
        matrix = matrix * mat % mod;
    }

    auto r = mat3x3{0, a, 1, 0, a, 1, 0, a, 1} % mod;
    r = r * matrix % mod;
    cout << r.a[0][0] << endl;
    return 0;
}


Measured memory_bytes: 3624
n = int(input())
R = [int(input()) for i in range(n)]
maxv = R[1] - R[0]
minv = R[0]

for j in range(1, n):
    maxv = R[j] - minv if R[j] - minv > maxv else maxv
    minv = R[j] if R[j] < minv else minv

print(maxv)

Measured memory_bytes: 15644
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define scanVec(vec , n) for(int i = 0; i < n ; i++){ cin>>vec[i];}
#define printVec(vec , n) for(int i = 0; i < n ; i++){ cout<<vec[i]<<" ";}
#define S second
#define F first
const int  MOD = 1e9 + 7;
const int  N = 1e5 + 7;
int dp[N];

//  a d f j k  l  ;
int main(){
    ios::sync_with_stdio(0);  cin.tie(0);
    int n;
    cin>>n;
    vector<int> v(n);
    scanVec(v , n);
    for(int i = 0 ; i < n ; i++){
        if(i >= 2){
            dp[i] = min(dp[i-1] + abs(v[i] - v[i-1]) , dp[i-2] + abs(v[i] - v[i-2]));
        }else if(i == 1){
            dp[i] = dp[i-1] + abs(v[i] - v[i-1]);
        }else dp[i] = 0;
    }
    cout<<dp[n-1]<<endl;

    return 0;
}

Measured memory_bytes: 1024
//INCLUDE
//------------------------------------------
#include <iostream>
#include <functional>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <string>
#include <cstring>
#include <vector>
//DEFINE
//------------------------------------------
#define ll long long
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
using namespace std;
//-------------------------------------------
int main(void){
  ll N;cin>>N;
  ll a[N+1][3];REPS(i,N)REP(j,3)cin>>a[i][j];
  vector<vi> dp(N+1,vi(3,-1));REP(i,3)dp[0][i]=0;
  REP(i,N){
    REP(j,3){
    	dp[i+1][(j+1)%3]=max(dp[i+1][(j+1)%3],dp[i][j]+a[i+1][j]);
        dp[i+1][(j+2)%3]=max(dp[i+1][(j+2)%3],dp[i][j]+a[i+1][j]);
    }
  }
  cout<<max(dp[N][0],max(dp[N][1],dp[N][2]));
  return 0;
}


Measured memory_bytes: 8064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		if(n < 1000) {
			System.out.println("ABC");
		} else {
			System.out.println("ABD");
		}
	}
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9+7;

int main(void) {

    ll A,B; cin>>A>>B;
    ll Gcd = __gcd(A,B);
    int cnt=1;

    for (ll i = 2; i*i <= Gcd; ++i) {
        if(Gcd % i ==0){
            cnt++;
            while(Gcd % i == 0){
                Gcd /= i;
            }
        }
    }

    if(Gcd>1) cnt++;
    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LLI long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int main(){
    const int t=100001;
    LLI a[t]={},b[t]={},c[t]={},d[t]={};
    int n,k; cin>>n>>k;
    LLI z=0;
    n++;
    FOR(i,1,n){
        cin>>a[i];
        c[i]=max(a[i],z);
    }
    FOR(i,1,n){
        b[i]=b[i-1]+a[i];
        d[i]=d[i-1]+c[i];
    }
    LLI M=-INF;
    n--;
    FOR(i,0,n-k+1){
        M=max(M,d[i]-d[0]+d[n]-d[i+k]+max(z,b[i+k]-b[i]));
    }
    co(M);

}


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

int main(){
  int N, K;
  cin>>N>>K;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  int sum=0;
  for(int i=0;i<N;i++){
    if(vec.at(i)<=K/2){
      sum+=vec.at(i)*2;
    }
    else{
      sum+=(K-vec.at(i))*2;
    }
  }
  cout<<sum<<endl;
}

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n, k, x, y; cin >> n >> k >> x >> y;

    if (n <= k) cout << x * n << endl;
    else cout << x * k + y * (n - k) << endl;
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  
  if (S[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }
  
  int C_num = 0;
  int N = S.size();
  for (int i = 2; i < N-1; i++) {
    if (S[i] - 'A' == 2) {
      C_num++;
    }
  }
  
  if (C_num != 1) {
    cout << "WA" << endl;
    return 0;
  }
  

  
  for (int i = 1; i < N; i++) {
    if (S[1] == 'C') {
      cout << "WA" << endl;
      return 0;
    }
    
    if (S[i] != 'C' && S[i] - 'A' <= 25) {
      cout << "WA" << endl;
      return 0;
    }
     
  }
  if (S[N-1] - 'A' <= 25) {
    cout << "WA" << endl;
    return 0;
  }
  
  cout << "AC" << endl;
  
}

Measured memory_bytes: 3632
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

K, N, *A = map(int, read().split())
A += [A[0] + K]
max_gap = max(y - x for x, y in zip(A, A[1:]))
print(K - max_gap)


Measured memory_bytes: 20348