akhauriyash/Code-Regression huggingface dataset:
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#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 <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//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 EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#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)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int gcd(int a, int b) {
	if (b == 0)return a;

	return gcd(b, a%b);
}

int main() {

	int a, b; cin >> a >> b;

	cout << gcd(a, b) << endl;
	
	return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
/////////////////////////////////////////////////////////////////////
ll value(ll a,ll b,ll x)
{
	return floor(a*x/b)-a*floor(x/b);
}
int main()
{ll a,b,n,l,u,mid;

	cin>>a>>b>>n;
	 // x =n-1;
l =1 ;
u = n;


if(n<b)
{
	cout<<value(a,b,n);
	return 0;
}
	
else
	cout<<value(a,b,b-1);

return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		Random r = new Random();
		
		long startMilli = System.currentTimeMillis();
		
		final int N = 26;

		int D = sc.nextInt();
		int[] c = new int[N];
		for(int i=0; i<N; i++)
			c[i] = sc.nextInt();
		
		int[][] s = new int[D][N];
		for(int i=0; i<D; i++)
			for(int j=0; j<N; j++)
				s[i][j] = sc.nextInt();
		
		int[] t = new int[D];
		for(int i=0; i<D; i++)
			t[i] = r.nextInt(N);
		
//		int score = 0;
//		int[] last = new int[N];
//		for(int i=0; i<D; i++) {
//			score += s[i][t[i]];
//			last[t[i]]=i+1;
//			for(int j=0; j<N; j++)
//				score -= c[j]*(i+1-last[j]);
//		}
		
		long currentMilli = System.currentTimeMillis();

		while(currentMilli - startMilli < 1900) {
			for(int i=0; i<10000; i++) {
				int d = r.nextInt(D)+1;
				int to = r.nextInt(N);
				int from = t[d-1];
				if(from==to)
					continue;
	
				int scoreDiff = s[d-1][to] + c[to]*(d-getIndex(t, to, d, false))*(getIndex(t, to, d, true)-d);
				scoreDiff -= s[d-1][from] + c[from]*(d-getIndex(t, from, d, false))*(getIndex(t, from, d, true)-d);
				if(scoreDiff>0)
					t[d-1] = to;
			}
			currentMilli = System.currentTimeMillis();
		}
		for(int i=0; i<D; i++)
			pw.println(t[i]+1);

		sc.close();
		pw.close();
	}
	
	static int getIndex(int[] t, int type, int base, boolean isForward) {
		int ans = base;
		int diff = isForward ? 1 : -1;
		ans += diff;
		while(1 <= ans && ans <= t.length) {
			if(t[ans-1]==type)
				return ans;
			ans += diff;
		}
		return ans;
	}
}


Measured memory_bytes: 37884
n = int(input())
a = list(map(int, input().split()))
a.sort()

i = 0
ans = 1
while True:
    cnt1 = 0
    cnt2 = 0
    while a[i + cnt1] == a[i]:
        cnt1 += 1
        cnt2 += 1
        if i + cnt1 == n:
            ans = max(ans, cnt1)
            break
    if i + cnt1 == n:
        break
    while a[i + cnt2] <= a[i] + 2:
        cnt2 += 1
        if i + cnt2 == n:
            break
    ans = max(ans, cnt2)
    i += cnt1

print(ans)

Measured memory_bytes: 84544
#include<bits/stdc++.h>
using namespace std;
main(){
int i,j,k,l,m,n;
char s[200000];
while(cin>>s){
    n=strlen(s);j=0;k=0;
    for(i=0;i<n;i++) {
        if(s[i]=='1') j++;
        else k++;
    }
    if(j>k) swap(j,k);
    cout<<j*2<<endl;
} return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

/////////////////////////////////////////////////////////

void Main() {
  int N; cin >> N;
  vector<int> A(N);
  rep(i, 0, N) cin >> A[i];

  int res = 1;
  int mode = 0;
  rep(i, 1, N){
    if(mode == 0){
      if(A[i] > A[i - 1]) mode = 1;
      else if(A[i] < A[i - 1]) mode = -1;
    }
    else if(mode == 1){
      if(A[i] < A[i - 1]){
        mode = 0;
        res++;
      }
    }
    else if(mode == -1){
      if(A[i] > A[i - 1]){
        mode = 0;
        res++;
      }
    }
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

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

  Main();
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	for(int n,m;cin>>n>>m;){
		bool valid=true;
		int res=m;
		while(n--){
			int a,b; cin>>a>>b;
			m+=a-b;
			res=max(res,m);
			valid&=m>=0;
		}
		cout<<(valid?res:0)<<endl;
	}
	
	return 0;
}

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

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

  int A, B, C;
  cin >> A >> B >> C;
  int sum = 0;
  bool ans = false;
  for(int i=0;i<B;i++){
    sum += A;
    if(sum % B == C){
      ans = true;
      break;
    }
  }
  if(ans) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
package main

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) gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b > 0 {
		a, b = b, a%b
	}
	return a
}

func (con *contest) main() error {
	var a, b, c int
	con.Scan(&a, &b, &c)
	if c%con.gcd(a, b) == 0 {
		con.Println("YES")
	} else {
		con.Println("NO")
	}
	return nil
}

// X * A = Y * B + C


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} //最大公約数
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;} //最小公倍数

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll A[100010];
    cin >> N;
    rep(i,0,N) cin >> A[i];
    ll v = A[0];
    rep(i,0,N-1){
        v = gcd(v, A[i+1]);
    }
    print(v);
}


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

// #define multitest 1
// #define Debug 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;

const int nax = 1e5 + 10;
vector<int> Adj[nax];

ll mul(ll a, ll b)
{
	return (a % mod * b % mod) % mod;
}

ll add(ll a, ll b)
{
	return (a + b + mod) % mod;
}

pair<int, int> dfs(int node, int parent)
{
	int all_white = 1;
	int sth_is_black = 0;
	for (int b : Adj[node])
		if (b != parent)
		{
			pair<int, int> p = dfs(b, node);
			int prev = all_white;
			all_white = mul(all_white, p.second);
			sth_is_black = add(mul(prev, p.f), mul(sth_is_black, p.f + p.s));
		}
	return {all_white, add(all_white, sth_is_black)};
}

void solve()
{
	int n, u, v;
	cin >> n;
	for (int i = 1; i < n; ++i)
	{
		cin >> u >> v;
		Adj[u].pb(v);
		Adj[v].pb(u);
	}
	auto ret = dfs(1, -1);
	cout << add(ret.f, ret.s);
}

int main()
{
#ifndef Debug
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

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

int main() {
  int N,M,X,Y;
  cin >> N >> M >> X >> Y;
  int x_max = -101;
  int y_min = 101;
  for (int i=0; i<N; ++i) {
    int x;
    cin >> x;
    if (x > x_max) x_max = x;
  }
  for (int i=0; i<M; ++i) {
    int y;
    cin >> y;
    if (y < y_min) y_min = y;
  }

  if (x_max >= Y || y_min <= X) {
    cout << "War";
    return 0;
  }

  if (x_max >= y_min) {
    cout << "War";
  } else {
    cout << "No War";
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

inline static void put_int(int x) {
    int s = 0;
    char f[6] = {'0', '0', '0', '0', '0', '0'};
    if (!x) {
        putchar_unlocked('0');
        return;
    }
    while (x) {
        f[s++] += x % 10;
        x /= 10;
    }

    while (s--) putchar_unlocked(f[s]);
}

int main() {
    int flag = 0, l = 0, r = 0, i = 0, tmp;

    for (;(tmp = getchar_unlocked() - 'L') >= 0; i++) {
        if (tmp) {
            // if c is R
            if (flag) {
                flag = 0;

                if ((tmp = r + 1) < l) {
                    if (r) {
                        putchar_unlocked(' ');
                    }
                    putchar_unlocked('0');

                    for (tmp++; tmp < l; tmp++) {
                        putchar_unlocked(' ');
                        putchar_unlocked('0');
                    }
                }

                if (l > 1 || r) {
                    putchar_unlocked(' ');
                }
                tmp = (l - r + 1) / 2 + (i - l) / 2;
                put_int(tmp);
                putchar_unlocked(' ');
                tmp = (i - r) - tmp;
                put_int(tmp);

                for (tmp = l + 1; tmp < i; tmp++) {
                    putchar_unlocked(' ');
                    putchar_unlocked('0');
                }
                r = i;
            }
        } else {
            // if c is L
            if (!flag) {
                flag = 1;
                l = i;
            }
        }
    }

    if ((tmp = r + 1) < l) {
        if (r) {
            putchar_unlocked(' ');
        }
        putchar_unlocked('0');

        for (tmp++; tmp < l; tmp++) {
            putchar_unlocked(' ');
            putchar_unlocked('0');
        }
    }

    if (l > 1 || r) {
        putchar_unlocked(' ');
    }
    tmp = (l - r + 1) / 2 + (i - l) / 2;
    put_int(tmp);
    putchar_unlocked(' ');
    tmp = (i - r) - tmp;
    put_int(tmp);

    for (tmp = l + 1; tmp < i; tmp++) {
        putchar_unlocked(' ');
        putchar_unlocked('0');
    }

    putchar_unlocked('\n');
}


Measured memory_bytes: 1504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
  string s;
  cin >> s;
  vector<string> t = {"dreamer","dream","erase","eraser"};
  string now = "";
  for(int i=s.size()-1;i>=0;i--){
    now = s[i] + now;
    for(auto j:t){
      if(now == j) now = "";
    }
  }
  if(now == "") cout << "YES" << endl;
  else cout << "NO" << endl; 
    
  return 0;
}



Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int x, y;
int m, n;
int dirx, diry;

void process_command(char *buf);
void forward(int k);
void backward(int k);
void right(void);
void left(void);

int main()
{
    char buf[64];
    while(1){
        fgets(buf, sizeof(buf), stdin);
        sscanf(buf, "%d %d", &m, &n);
        if(m == 0) break;
        x = 1; y = 1;
        dirx = 0; diry = 1;
        while(strstr(fgets(buf, sizeof(buf), stdin), "STOP") == NULL){
            process_command(buf);
        }
        printf("%d %d\n", x, y);
    }
    return 0;
}

void process_command(char *buf)
{
    char *p;

    if((p = strstr(buf, "FORWARD")) != NULL)
        forward(atoi(p+strlen("FORWARD")));
    else if((p = strstr(buf, "BACKWARD")) != NULL)
        backward(atoi(p+strlen("BACKWARD")));
    else if(strstr(buf, "RIGHT") != NULL)
        right();
    else if(strstr(buf, "LEFT") != NULL)
        left();
}

void forward(int k)
{
    x += dirx * k;
    y += diry * k;
    if(x < 1) x = 1;
    else if(x > m) x = m;
    else if(y < 1) y = 1;
    else if(y > n) y = n;
}

void backward(int k)
{
    x -= dirx * k;
    y -= diry * k;
    if(x < 1) x = 1;
    else if(x > m) x = m;
    else if(y < 1) y = 1;
    else if(y > n) y = n;
}

void left()
{
    int tmp = diry;
    diry = dirx;
    dirx = -tmp;
}

void right()
{
    int tmp = dirx;
    dirx = diry;
    diry = -tmp;
}



Measured memory_bytes: 2040
#include <iostream>
#include <string>

using namespace std;

int main(void){

  int N;
  long long sum = 0;

  cin >> N;

  for(int i=1; i<=N; i++){
    if(i%3==0 || i%5==0);
    else if(i%3==0);
    else if(i%5==0);
    else sum += i;
 }

  cout << sum;
  
  return 0;
}


Measured memory_bytes: 3632
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];


int main(){
    long long a;
    cin>>a;
    vector<long long> vec(a);
    rep(i,a){
        cin>>vec.at(i);
    }
    long long v;
    rep(i,a){
        v=vec.at(i);
        long long j=i-1;
        while(j>=0&&vec.at(j)>v){
            vec.at(j+1)=vec.at(j);
            j--;
        }
        vec.at(j+1)=v;
        rep(i,a){
            cout<<vec.at(i);
            if(i==a-1){
                cout<<endl;
            }        
            else{
                cout<<" ";
            }
        }
    }
}






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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

intll gcd (intll x, intll y) {
  intll tmp ;
  if( x < y )
    swap(x,y);
  
  while(y>0){
    tmp = x % y ;
    x = y ;
    y = tmp ;
  }
  return x ;
}

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

int main() {
  int n ;
  cin >> n ;
  intll tmp = 1 ;

  rep(i,n){
    intll x ;
    cin >> x ;
    tmp = lcm(x,tmp);
  }
  
 printf("%lld", tmp) ;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

vector<int> g[100001];
deque<int> q;
set<int> st;
int main(){
    int n,m,ai,bi;
    cin>>n>>m;
    rep(i,m){
        cin>>ai>>bi;
        --ai,--bi;
        g[ai].pb(bi);
        g[bi].pb(ai);
    }
    q.push_back(0);st.insert(0);
    q.push_back(g[0][0]);st.insert(g[0][0]);
    bool flag=false;
    while(1){
        flag=false;
        int ft=q.front();
        rep(i,g[ft].size()){
            if(st.count(g[ft][i])==0){
                q.push_front(g[ft][i]);
                st.insert(g[ft][i]);
                break;
            }
            if(i==g[ft].size()-1){
                flag=true;
            }
        }
        int bk=q.back();
        rep(i,g[bk].size()){
            if(st.count(g[bk][i])==0){
                q.push_back(g[bk][i]);
                st.insert(g[bk][i]);
                break;
            }
            if(i==g[bk].size()-1&&flag){
                cout<<q.size()<<endl;
                for(auto it:q){
                    cout<<it+1<<" ";
                }
                cout<<endl;return 0;
            }
        }
    }
    return 0;
}

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


#define M 1000000007
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define mod 998244353
#define sz(v) (int)(v).size()

#define pii pair<int, int>
#define vi vector<int>
#define ll long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)

ll add(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a+b)%M;
	return (p+M)%M;
}

ll mul(ll a,ll b)
{
	a%=M;
	b%=M;
	ll p = (a*b)%M;
	return (p+M)%M;
}


int main()
{
	fastio;
	ll x;
	cin>>x;
	cout<<10-(x/200)<<endl;
    return 0;
}





Measured memory_bytes: 3632
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    string s;
    scan(s);
    writeln(s[0 .. $ - 8]);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256
from operator import itemgetter

n = int(input())
sp = []
for i in range(n):
    row = input().split()
    row[1] = - int(row[1])
    row.append(i+1)
    sp.append(row)

sp.sort(key=itemgetter(0, 1))
for index in sp:
    print(index[2])



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    long long N, Z, W;
    cin >> N >> Z >> W;
    vector<long long> a(N);
    REP(i, N) { cin >> a[i]; }
    long long res = abs(W - a[N - 1]);
    if(N > 1) {
        res = max(res, abs(a[N - 2] - a[N - 1]));
    }
    cout << res << endl;
    return 0;
}

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

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

int main(int argc, char* argv[]) {
	int n,m;
	scanf("%d %d",&n,&m);
	long long c;
	if (n>2&&m>2) c=((long long)n-2)*(m-2);
	else if (n==2||m==2) c=0;
	else if (n==1&&m==1) c=1;
	else c=n+m-3;
	printf("%lld\n",c);
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

int main(void) {
  ll a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  ll res = 1e18;
  REP(i, x+1) {
    ll cur = 0;
    cur += i * a;
    cur += (x-i) * 2 * c;
    cur += max(y-(x-i), 0LL) * b;
    res = min(res, cur);
  }
  REP(i, y+1) {
    ll cur = 0;
    cur += i * b;
    cur += (y-i) * 2 * c;
    cur += max(x-(y-i), 0LL) * a;
    res = min(res, cur);
  }
  cout << res << endl;
  return 0;
}



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

using namespace std;

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i =0;i<t;i++)
#define bs(a,x) binary_search(a.begin(),a.end(),x)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int,int> 
#define umpl unordered_map<ll,ll> 
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mod 998244353 
#define N 10000000
#define all(a) a.begin(),a.end()
#define point pair<ll,ll>

const int inf = 100000007;
const ll linf = 1ll * inf * inf;
const ll MAXIMUM =100005;

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll min(ll a, ll b){return a<b?a:b;}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};
string to_string(char x){
	string s(1,x);
	return s;
}

int main()
{
    fio;
    ll k,n;cin>>k>>n;
    vl a(n);
    f(n)cin>>a[i];
    ll min1=k-1,max1=0,min2=k-1,max2=0;
    bool flag1=false,flag2=false;
    ll temp=k-1;
    f(n){
    	if(a[i]>=0 && a[i]<(k/2)){
    		min1=min(min1,a[i]);
    		max1=max(max1,a[i]);
    		flag1=true;
    	}
    	if(a[i]>=(k/2) && a[i]<k){
    		min2=min(min2,a[i]);
    		max2=max(max2,a[i]);
    		flag2=true;
    	}
    	if(i<n-1)temp=min(temp,k-a[i+1]+a[i]);
    }
    if(flag1 && flag2)
    {
	    ll ans=max1-min1+max2-min2;
	    ans+=min(min2-max1,k-max2+min1);
	    cout<<min(ans,temp)<<"\n";
    }
    else if(flag1){
    	cout<<min(temp,max1-min1)<<"\n";
    }else{
    	cout<<min(temp,max2-min2)<<"\n";
    }
}



Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<cassert>
#include<iomanip>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define eps (1e-8)
#define equals(a,b) (fabs((a)-(b)) < eps)
#define MAX 2000000
#define all(n) (n).begin(),(n).end()
using namespace std;
struct Circle
{
  double x,y,r;
  Circle(double x=inf,double y=inf,double r=inf):x(x),y(y),r(r){}
  bool operator < (const Circle& c)const
  {
    if(!equals(x,c.x))return x < c.x;
    return y < c.y;
  }
};

bool compare_y(Circle a,Circle b)
{
  return a.y < b.y;
}

int N;
Circle A[MAX];

double compute(Circle *a,int n)
{
  if(n <= 1)return inf;
  int m = n/2;
  double x = a[m].x;
  double y = a[m].y;
  double r = a[m].r;
  double d = min(compute(a,m),compute(a+m,n-m));
  inplace_merge(a,a+m,a+n,compare_y);

  vector<Circle> b;

  rep(i,n)
    {
      double nx = a[i].x - x;
      double ny = a[i].y - y;
      double ndist = sqrt(nx*nx + ny*ny) - a[i].r - r;
      //if(equals(ndist,d) || ndist > d)continue;
      //if(nx >= d)continue;
     
      rep(j,(int)min((int)b.size(),2))
	{
	  int last = b.size()-j-1;
	  double dx = a[i].x - b[last].x;
	  double dy = a[i].y - b[last].y;
	  double dist = sqrt(dx*dx + dy*dy) - a[i].r - b[last].r;

	  if(equals(dist,d) || dist > d)continue;
	  d = min(d,sqrt(dx*dx + dy*dy) - a[i].r - b[last].r);
	}
      b.push_back(a[i]);
    }
  return d;
}



int main()
{
  while(cin >> N,N)
    {
      assert(N < MAX);
      rep(i,N)cin >> A[i].r >> A[i].x >> A[i].y;
      sort(A,A+N);


      cout << setiosflags(ios::fixed) << setprecision(8) << compute(A,N) << endl;
    }
  return 0;
}

Measured memory_bytes: 53580
#include<iostream>
#include<algorithm>
#include <iostream> 
#include <algorithm> 
#include<string>
#include<queue>
#include<utility>
#include<fstream>
#include<queue>
#include<set>
#include<stack>
#include<map>
//#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 
 
typedef pair<int,int >P;
//////////////////////////
/////////////////////////
int main(){
    
int n;
I(n);
bool fl = 0;

for(int i = 1;i<=n;i++){
    int x;
    I(x);
    if(x%2==0){
        if(x%3 == 0|| x%5==0){}
        else fl = 1;
    }
}

if(fl)cout<<"DENIED"<<endl;
else cout<<"APPROVED"<<endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
S = np.array(list(input()))
l1 = np.array([str(i%2) for i in range(S.size)])
l2 = np.array([str((i+1)%2) for i in range(len(S))])
a1 = np.array(S == l1)
a2 = np.array(S == l2)
b1 = np.sum(a1)
b2 = np.sum(a2)

if b1 < b2:
    print(b1)
else :
    print(b2)

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

using namespace std;

template <class M, class N>
common_type_t<M, N> gcd(M a, N b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;
  vector<long long> va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  int ans = va.front();
  for (int i = 0; i < n; ++i) {
    ans = gcd(ans, va[i]);
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;
  if(a==b)
  cout<<c<<endl;
  if(b==c)
  cout<<a<<endl;
  if(c==a)
  cout<<b<<endl;
  }

Measured memory_bytes: 384
from sys import stdin
input = stdin.readline

S = int(input())

A = [-1] * (2001)
mod = 10 ** 9 + 7

for i in range(3):
    A[i] = 0

for i in range(3, 6):
    A[i] = 1


def dfs(n):
    if A[n] != -1:
        return A[n]
    else:
        A[n] = (dfs(n - 3) + dfs(n - 1)) % mod
        return A[n]


print(dfs(S))


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

#define IS_DEBUG true

#define DEBUG_OUTPUT(X) if (IS_DEBUG) cout << X << endl
#define RESULT_OUTPUT(X) cout << X << endl

void sortIncrease(vector<int> &array);
void sortDecrease(vector<int> &array);

int main()
{
  string S;
  cin >> S;
  
  int length = S.length();
  string string5, string6, string7, char8;
  while (length >= 5)
  {
  	string5 = S.substr(length - 5, 5);
    if (length >= 7)
      string7 = S.substr(length - 7, 7);
    else
      string7 = "";
    if (length >= 6)
      string6 = S.substr(length - 6, 6);
    else
      string6 = "";
    
    if (string7.compare("dreamer") == 0)
      S.erase(length - 7, 7);
    else if (string5.compare("dream") == 0)
      S.erase(length - 5, 5);
    else if (string6.compare("eraser") == 0)
      S.erase(length - 6, 6);
    else if (string5.compare("erase") == 0)
      S.erase(length - 5, 5);
    else
    {
      RESULT_OUTPUT("NO");
      return 0;
    }
    length = S.length();
  }
  if (length != 0)
    RESULT_OUTPUT("NO");
  else
    RESULT_OUTPUT("YES");
  
  if (IS_DEBUG)
  {
    int end;
    cin >> end;
  }
  return 0;
}

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

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

    vector<int> b(n+1, 0);
    rep(i,m) {
        int t;
        cin >> t;
        b[t] = 1;
    }

    vector<int> dp(n+2);
    dp[n] = 1;
    for (int i = n-1; i >= 0; i--) {
        if (b[i] == 1) {
            dp[i] = 0;
            continue;
        }

        dp[i] = (dp[i+1] + dp[i+2]) % 1000000007;
    }

    cout << dp[0] << endl;

    return 0;
}

Measured memory_bytes: 3988
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() {
    let n: usize = read();

    let ans = (1..10).any(|i| n / i <= 9 && n % i == 0);
    println!("{}", if ans { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
// Problem : B - Multiple of 9
// Contest : AtCoder - AtCoder Beginner Contest 176
// URL : https://atcoder.jp/contests/abc176/tasks/abc176_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

long long sum;
string    str;

int main() {
    cin >> str;
    for ( int i = 0; i < str.size(); i++ ) {
        sum += ( str[ i ] - '0' );
    }
    if ( sum % 9 == 0 )
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3760
# 初期入力
from collections import Counter
from copy import deepcopy
import sys
input = sys.stdin.readline
N,K = (int(x) for x in input().split())
A = list(map(int, input().split()))
connection ={}
for i,v in enumerate(A):
    connection[i+1] =v 

#巡回してるか
passed=[1]
nex =connection[1]
lap =[]
lap_num =0
pass_set =set(passed)
for i in range(1,N+1):
    passed.append(nex)
    if nex not in pass_set:
        pass_set.add(nex)
        nex =connection[nex]
    else:
        #lap =deepcopy(passed)
        break
#巡回している部分の町の数    
indx_s =passed.index(nex) +1
indx_f =len(passed)
lap_num =indx_f -indx_s

if indx_f < K:
    mod =(K -indx_s) % lap_num
    ans =passed[indx_s +mod]
else:
    ans =passed[K]
print(ans)

Measured memory_bytes: 49792
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

// O(N)の解法
int[] calc(int N, int Y) {
    // x + y + z = N
    // 10,000 * x + 5,000 * y + 1,000 * z = Y
    // 上を 10,000 倍して、下から引くと、
    // 5,000 * y + 9,000 * z = 10,000 * N - Y
    // y をループ回して固定化して、z を求める:
    // z = (10,000 * N - Y - 5,000 * y) / 9,000

    for (int y = 0; y <= N; y++) {
        int z = 10000 * N - Y - 5000 * y;
        if (z < 0 || z % 9000 != 0) continue;

        z /= 9000;
        int x = N - (y + z);
        if (x >= 0)
            return [x, y, z];
    }
    return [-1, -1, -1];
}

// O(1)の解法
int[] calc2(int N, int Y) {
    // x + y + z = N
    // 10,000 * x + 5,000 * y + 1,000 * z = Y
    //
    // 5,000 * 9 = 20,000 * 4 + 1,000 * 5 と枚数を変えずに変換できるので
    // 5,000 は 8 枚以下しか使わずに支払い可能。

    for (int y = 0; y <= min(N, 8); y++) {
        // 実装は calc() を同じ
        int z = 10000 * N - Y - 5000 * y;
        if (z < 0 || z % 9000 != 0) continue;

        z /= 9000;
        int x = N - (y + z);
        if (x >= 0)
            return [x, y, z];
    }
    return [-1, -1, -1];
}

void main() {
    int N, Y; scan(N, Y);

    // auto ans = calc(N, Y);
    auto ans = calc2(N, Y);
    writeln(ans.map!(text).join(" "));
}


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

using namespace std;

int main(){
    int  n;
    cin>>n;
vector<vector<vector<int>>>an(4,vector<vector<int>>(3,vector<int>(10,0)));

for(int i=0;i<n;i++){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    an.at(a-1).at(b-1).at(c-1)+=d;
}
for(int i=0;i<4;i++){
    for(int j=0;j<3;j++){
        for(int k=0;k<10;k++){
            cout<<" "<<an.at(i).at(j).at(k);
        }
        cout<<endl;
    }

    if(i!=3)cout<<"####################"<<endl;
}
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0 ; i < int(N);i++)
using namespace std ;
typedef long long ll;
typedef pair <int , int >pi;
typedef vector <int> vi ;
typedef vector <string> si;



int main (){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int ans = 1e9 ;
	string a, b;
	cin  >> a >> b;
	rep(si,a.size()){
		if(si+b.size() > a.size()) break;
		int cnt = 0;
		rep(i,b.size()){
			if(a[si+i] != b[i] ) {
				// cout << a[si+i] << " " << b[i] << endl;
				cnt++;
			}
		}
		ans = min(ans, cnt);
	}
	cout << ans << endl;
	return 0 ;
}

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

// input
string N;


void input() {
    cin >> N;
}


int main() {
    input();
    int c = count(N.begin(), N.end(), '9');
    string ans;
    if (c > 0) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
}


Measured memory_bytes: 3584
using System;

namespace ANOMURA2020A
{
    class Program
    {
        static void Main(string[] args)
        {
            var wo = Console.ReadLine().Split();
            int a1, a2, b1, b2, k,x;
            a1 = int.Parse(wo[0]);
            a2 = int.Parse(wo[1]);
            b1 = int.Parse(wo[2]);
            b2 = int.Parse(wo[3]);
            k = int.Parse(wo[4]);

            x = (b1 - a1) * 60;
            x += b2 - a2;
            x -= k;
            Console.WriteLine(x);
        }
    }
}

Measured memory_bytes: 17752
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<ll> w(N), s(N), v(N), idx(N);
    for(int i=0; i<N; i++){
        cin >> w[i] >> s[i] >> v[i];
        idx[i] = i;
    }
    sort(idx.begin(), idx.end(), [&](int i, int j){
        if(w[i]+s[i]==w[j]+s[j]) return i<j;
        return w[i]+s[i] < w[j]+s[j];
    });

    const int W = 2e4+10;
    vector<ll> dp(W);
    for(int i=0; i<N; i++){
        for(int j=W-1; j>=0; j--){
            int k = idx[i];
            if(j-w[k]>=0 && j<=w[k]+s[k]) dp[j] = max(dp[j], dp[j-w[k]] + v[k]);
        }
    }

    cout << *max_element(dp.begin(), dp.end()) << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//int cnt[100];
//int cnt1[100];
int main () {
//ll t; cin>>t; while(t--)
ll a,b,c,d,e,f,g,h,x,y,z; cin>>a>>b>>c>>d;
e=a*c;
f=a*d;
x=max(e,f);
g=b*c;
h=b*d;
y=max(g,h);
z=max(x,y);
cout<<z<<endl;
return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

const int bits = 35;
int table[100005][bits];
ll sum[100005][bits];

int main() {
    fastio;
    ll ans=0;
    ll N;
    int X, M;
    cin >> N >> X >> M;
    rep(x,M) {
        table[x][0] = x * x % M;
        sum[x][0] = x;
    }
    rep(i,bits-1) rep(x,M) {
        table[x][i+1] = table[table[x][i]][i];
        sum[x][i+1] = sum[x][i] + sum[table[x][i]][i];
    }
    int s = X;
    for (int i=0; i<bits; ++i) {
        if (N & (1LL << i)) {
            ans += sum[s][i];
            s = table[s][i];
        }
    }
    cout << ans << endl;
}


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

using namespace std;

int n;
vector<int> a, b;
map<int, int> p;

int group(int a) {
    if (p.find(a) == p.end() || p[a] == a) {
        return p[a] = a;
    }
    return p[a] = group(p[a]);
}

void merge(int a, int b) {
    a = group(a);
    b = group(b);
    p[a] = b;
}

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

    cin >> n;
    a = b = vector<int>(n+1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[n] ^= a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        b[n] ^= b[i];
    }
    n++;

    if (multiset<int>(a.begin(), a.end()) != multiset<int>(b.begin(), b.end())) {
        cout << -1 << endl;
        return 0;
    }

    int ans = 0;
    for (int i = 0; i < n-1; i++) {
        ans += (a[i] != b[i]);
    }
    if (ans == 0) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 0; i < n; i++) {
        if (i < n-1 && a[i] == b[i]) continue;
        merge(a[i], b[i]);
    }

    for (map<int, int>::iterator it = p.begin(); it != p.end(); it++) {
        int u = it->first;
        if (u == group(u)) ans++;
    }
    ans--;
    cout << ans << endl;
    return 0;
}

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

int main() {
    int N;
    int A;
    int B;
    cin >> N;
    cin >> A;
    cin >> B;
    int s;
    if (A * N < B) {
        s = A * N;
    } else {
        s = B;
    }
    cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-5)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H & b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H & b) const { return x == b.x && y == b.y; }
	bool operator!=(const H & b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T & a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T & a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, m;
int dp[200000];
bool a[200000];
signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		a[read()] = 1;
	}
	dp[0] = 1;
	for (int i = 1; i <= n; i++) {
		if (a[i]) continue;
		dp[i] += dp[i - 1];
		if (i > 1) dp[i] += dp[i - 2];
		dp[i] %= Mod;
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1152
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
VI mar;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n,l;
  cin>>n>>l;
  mar.resize(n);
  forn(i,n)
    cin>>mar[i];
  forn(i,n-1){
    if(mar[i]+mar[i+1]>=l){
      cout<<"Possible\n";
      forn(j,i)
	cout<<j+1<<"\n";
      for(in j=n-2;j>=i+1;--j)
	cout<<j+1<<"\n";
      cout<<i+1<<"\n";
      return 0;
    }
  }
  cout<<"Impossible\n";
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>
#include <random>
#include <cstring>

#define rep(i,n) for(int i=0;i<int(n);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back

using namespace std;
using ll = long long;

const ll mod = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a == b && b == c && c == a) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int a[100005],dp[100005];
int main()
{
    ll n,i;
	cin>>n; 
	for(i=1;i<=n;i++)
	cin>>a[i];
	dp[1]=0;
	dp[2]=abs(a[2]-a[1]);
	for(i=3;i<=n;i++)
	dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
	cout<<dp[n];
	return 0;
}

Measured memory_bytes: 4416
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]

for i in range(3):
    if all(a[i][j] in b for j in range(3)):
        print("Yes")
        quit()
    if all(a[j][i] in b for j in range(3)):
        print("Yes")
        quit()
if all(a[i][i] in b for i in range(3)):
    print("Yes")
    quit()
if all(a[i][2-i] in b for i in range(3)):
    print("Yes")
    quit()

print("No")


Measured memory_bytes: 3064
/*Lower_Rating*/
/*NIKKEI-2 B*/
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<set>
#include<vector>
#include<map>
using namespace std;

#define LL long long
#define MAXN 500000
#define MAXM 2000000
#define MOD 998244353
#define Pr pair<int,int>
#define X first
#define Y second
#define INF 1000000000000000000
#define mem(x,p) memset(x,p,sizeof(x))

LL read(){
  LL x=0,F=1;char c=getchar();
  while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
  while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
  return x*F;
}

int add(int x,int y){return (x+y>=MOD)?x+y-MOD:x+y;}
int dec(int x,int y){return (x-y<0)?x-y+MOD:x-y;}
int mul(int x,int y){return 1LL*x*y%MOD;}

int n,D[MAXN+5];
int ans;
int main()
{
    ans=1;
    n=read();
    for(int i=1;i<=n;i++){
        int x=read();
        if(i==1&&x!=0){printf("0\n");return 0;}
        D[x]++;
    }
    if(D[0]>1){printf("0\n");return 0;}
    for(int i=1;i<=n;i++)
        for(int j=1;j<=D[i];j++)
        ans=mul(ans,D[i-1]);
    printf("%d",ans);
}


Measured memory_bytes: 512
N = int(input())
a = list(map(int, input().split()))
    
A = a[0]
B = sum(a[1:])

min = abs(A - B)

for i in range(N-2):
    A += a[i+1]
    B -= a[i+1]

    if min > abs(A - B):
        min = abs(A - B)


print(min)

Measured memory_bytes: 24812