akhauriyash/Code-Regression huggingface dataset:
n = input()
op_cnt = len(n) - 1  # すき間の個数
for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt  # あらかじめ ["-", "-", "-"] というリストを作っておく
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "+"  # フラグが立っていた箇所を "+" で上書き

    formula = ""
    for p_n, p_o in zip(n, op + [""]):  # 少々モヤッとする
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

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


ll gcd(ll a,ll b){return b==0 ? a : gcd(b,a%b);}

int main(void){
    int n;
    cin>>n;
    vector<ll> x(n+1);
    rep(i,n+1) cin>>x[i];
    sort(all(x));
    ll G = x[1]-x[0];
    rep(i,n){
        G = gcd(G, x[i+1]-x[i]);
    }
    cout << G << endl;
    return 0;
}


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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int H, W;
char board[30][30];
bool visited[30][30];
int dx[] = {0, 0, 1, -1};
int dy[] = {-1, 1, 0, 0};

void dfs(int x, int y) {
   for (int i = 0; i < 4; i++) {
      int nx = x + dx[i], ny = y + dy[i];
      if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
      if (board[nx][ny] == '#') continue;
      if (visited[nx][ny]) continue; // これ必要な理由がわからない
      visited[nx][ny] = true;
      dfs(nx, ny);
   }
}

int main() {
   while (cin >> W >> H, W && H) {
      memset(visited, false, sizeof(visited));

      int sx = 0, sy = 0;
      for (int i = 0; i < H; i++) {
         for (int j = 0; j < W; j++) {
            cin >> board[i][j];
            if (board[i][j] == '@') {
               sx = i, sy = j;
            }
         }
      }

      visited[sx][sy] = true;
      dfs(sx, sy);

      int cnt = 0;
      for (int i = 0; i < H; i++) {
         for (int j = 0; j < W; j++) {
            if (visited[i][j]) cnt++;
         }
      }
      cout << cnt << endl;

   }

   return 0;
}


Measured memory_bytes: 3108
def getItems(layerCount):
	if layerCount == 0:
		return 1
	return 2*getItems(layerCount-1) + 3

def getPats(layerCount):
	return 2**(layerCount + 1) - 1

def patEaten(layer, toEat):
	pattyCount = 0

	if layer == 1:
		burger = "BPPPB"

		for x in range(toEat):
			if burger[x] == "P":
				pattyCount += 1
		return pattyCount
		
	elif layer == 0:
		if toEat == 1:
			return 1
		else:
			return 0
	
	else:
		items = getItems(layer)
		if toEat == items:
			pattyCount += getPats(layer)
			return pattyCount
		elif toEat < 2+getItems(layer-1):
			if items + 1 == 2* toEat:
				toEat-=2
				return 1 + patEaten(layer - 1, toEat)
			toEat -= 1
			return patEaten(layer - 1, toEat)
		else:
			toEat -= (1+1+getItems(layer-1))
			pattyCount += 1 + getPats(layer-1)
			
			return pattyCount + patEaten(layer-1, toEat)

i, j = [int(x) for x in input().split()]
#print(patEaten(2,13))
print(patEaten(i,j))

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <vector>
#include <functional>
#include <cassert>
#include <cmath>
#include <map>
#include <set>
#include <queue>

using namespace std;

int N;

int main() {
	ios_base::sync_with_stdio(false);

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

	vector<int> updates;
	for (int i = 0; i < N; i++) {
		updates.push_back(i);
	}
	vector<int> next(N, -1);
	int ans = 0;
	while (true) {
		vector<int> curUpdates;
		bool flag = false;
		for (int x : updates) {
			next[x] = A[x][ptr[x]];
			if (next[next[x]] == x) {
				// cout << ans << " " << x << " " << next[x] << endl;
				ptr[x]++;
				ptr[next[x]]++;
				if (ptr[x] != N - 1) {
					curUpdates.push_back(x);
				}
				if (ptr[next[x]] != N - 1) {
					curUpdates.push_back(next[x]);
				}
				flag = true;
			}
		}
		if (!flag) {
			break;
		}
		ans++;
		updates = curUpdates;
	}
	bool ok = true;
	for (int i = 0; i < N; i++) {
		if (ptr[i] != N - 1) {
			ok = false;
		}
	}
	cout << (ok ? ans : -1) << endl;
	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++){
		int v = a[i];
		int j = i-1;
		while (j >= 0 and v < a[j]){
			int tmp = a[j];
			a[j] = a[j+1];
			a[j+1] = tmp;
			j--;
		}
		for (int k = 0; k < n; k++){
			if (k < n-1) cout << a[k] << " ";
			else cout << a[k] << endl;
		}
	}

}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define all(c) begin(c),end(c)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
//最大公約数
ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}
//最小公倍数
ll lcm(ll x, ll y) {
  return x/gcd(x, y)*y;
}
//素因数分解
vector<pair<ll,int>> factorize(ll n) {
  vector<pair<ll,int>> res;
  for (ll i = 2; i*i <= n; ++i) {
    if (n%i) continue;
    res.emplace_back(i,0);
    while (n%i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n,1);
  return res;
}
 
 
 ll mod=998244353;
 
int main() {
  int x;
  cin>>x;
  if(x<600){
    cout<<8;
  }else if(x<800){
    cout<<7;
  }else if(x<1000){
    cout<<6;
  }else if(x<1200){
    cout<<5;
  }else if(x<1400){
    cout<<4;
  }else if(x<1600){
    cout<<3;
  }else if(x<1800){
    cout<<2;
  }else if(x<2000){
    cout<<1;
  }


}



Measured memory_bytes: 3636
#include <iostream>
#include <map>

using namespace std;

int main()
{
    int n; cin >> n;
    map<char, int> hinaArare;
    hinaArare['P'] = 0;
    hinaArare['W'] = 0;
    hinaArare['G'] = 0;
    hinaArare['Y'] = 0;

    for (int i = 0; i < n; i++) {
        char x; cin >> x; hinaArare[x]++;
    }

    if (hinaArare['P'] == 0 || hinaArare['W'] == 0 || hinaArare['G'] == 0 || hinaArare['Y'] == 0) {
        cout << "Three" << endl;
    } else {
        cout << "Four" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 888
INF = 10 ** 9

h, n = $stdin.readline.chomp.split.map(&:to_i)
dp = Array.new(n + 1) { Array.new(h + 1, INF) }
dp[0][0] = 0

n.times do |i|
  a, b = $stdin.readline.chomp.split.map(&:to_i)
  (h + 1).times do |j|
    if j < a
      dp[i + 1][j] = [dp[i][j], b].min
    else
      dp[i + 1][j] = [dp[i][j], dp[i + 1][j - a] + b].min
    end
  end
end
puts dp[n][h]

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    string s;
    cin >> s;
    yn(s[2] == s[3] and s[4] == s[5]);

    return 0;
}


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

int main()
{
    int N;
    string S;
    cin >> N;
    cin >> S;

    int count = 0;

    for(int i=0; i<N; i++)
    {
        if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C')
            count++;
    }
    
    cout << count;

    return 0;
}

Measured memory_bytes: 256
N=int(input())
S=input()

stack=[]
stack2=[]
index=-1
index2=-1


#append ")" at the end of S
for i in range(N):
    stack.append(S[i])
    index+=1

    if len(stack)==1 and stack[0]==')':
        del stack[0]
        index-=1

    elif stack[index-1]=='(' and stack[index]==')':
        stack.pop(index)
        stack.pop(index-1)
        index-=2
    #print(stack)

last=len(stack)
for i in range(last):
    S=S+")"

#print("S"+S)

T=S[::-1]


#print("T"+T)

leng=len(T)
for i in range(leng):
    stack2.append(T[i])
    index2+=1

    if len(stack2)==1 and stack2[0]=='(':
        del stack2[0]
        index2-=1

    elif stack2[index2-1]==')' and stack2[index2]=='(':
        stack2.pop(index2)
        stack2.pop(index2-1)
        index2-=2
    #print(stack2)

first=len(stack2)
for i in range(first):
    T=T+"("

#print(T)
print(T[::-1])


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

struct UnionFind
{
    vector<int> d;
    // d[x] is the index of the parent of x
    // d[x] is -size if x is a root

    UnionFind(int n) : d(vector<int>(n, -1)) {}
    int root(int x)
    {
        if (d[x] < 0)
        {
            return x;
        }
        return d[x] = root(d[x]);
    }

    bool unite(int x, int y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
        {
            return false;
        }
        if (d[x] > d[y])
            swap(x, y); // x always bigger tree

        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(int x, int y)
    {
        return root(x) == root(y);
    }
    int size(int x) { return -d[root(x)]; }
};

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> g(n);
    UnionFind u(n);
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a]++;
        g[b]++;
        u.unite(a, b);
    }
    vector<vector<int>> b(n, vector<int>());
    rep(i, k)
    {
        int c, d;
        cin >> c >> d;
        c--;
        d--;
        b[c].emplace_back(d);
        b[d].emplace_back(c);
    }

    rep(i, n)
    {
        int ans = u.size(i) - 1 - g[i];
        for (int bk : b[i])
        {
            if (u.same(bk, i))
                ans--;
        }

        cout << ans << " ";
    }

    cout << endl;

    return 0;
}

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

if sum(A)<sum(B):
    print(-1)
else:
    D = [a-b for a,b in zip(A,B)]
    PLUS = sorted(filter(lambda x:x>0,D),reverse=True)
    MINUS = list(filter(lambda x:x<0,D))
    ans = len(MINUS)
    addans = 0
    while len(MINUS)>0:
        if addans==0: addans += 1
        if PLUS[0]>=abs(MINUS[0]):
            PLUS[0] += MINUS[0]
            MINUS.pop(0)
        elif PLUS[0]<abs(MINUS[0]):
            MINUS[0] += PLUS[0]
            PLUS.pop(0)
            addans += 1
        #print(PLUS,MINUS)
    ans += addans
    print(ans)

Measured memory_bytes: 19188
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;
class Program
{
    public static Scanner cin;
    static void Main()
    {
        
        cin = new Scanner();
        long[] xyzk = cin.ArrayLong(4);
        long[][] abc = new long[3][];
        
        for(int a = 0; a < abc.Length; a++)
        {
            abc[a]= cin.ArrayLong((int)xyzk[a]);
        }
        List<long> ab = new List<long>();
        for(int a = 0; a < xyzk[0]; a++)
        {
            for(int b = 0; b < xyzk[1]; b++)
            {
                ab.Add(abc[0][a]+abc[1][b]);
            }
        }
        ab.Sort();
        ab.Reverse();
        List<long> abc2 = new List<long>();
        for (int a=0;a<Math.Min(xyzk[3],ab.Capacity);a++)
        {
            for (int b = 0; b < xyzk[2]; b++)
            {
                abc2.Add(ab[a]+abc[2][b]);
            }
        }
        abc2.Sort();
        abc2.Reverse();
        for(int a = 0; a < xyzk[3]; a++)
        {
            Console.WriteLine(abc2[a]);
        }
        
        Console.ReadLine();

    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 60956
import sys
input = sys.stdin.readline
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


n,a,b=map(int,input().split())
v=list(map(int,input().split()))
v.sort()
sm=sum(v[-a:])
av=sm/a
ky=v[-a]
c=v.count(ky)
co=0
for i in range(n):
    if v[-i-1]>ky:
        co+=1
ans=0
#print(v)
if co>0:
    ans=cmb(c,a-co)
else:
    for i in range(a,min(b+1,c+co+1)):
        ans+=cmb(c,i-co)
print(av)
print(ans)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define fr first


using namespace std;
// vector tuple solution
main(){
    int k,n;
    cin>>k>>n;
    vector<int> a(n);
    vector<int> b(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        
    }
    int ans=(a[n-1]-a[0]);
    for(int i=0;i<n-1;i++){
        ans=min(ans,k-a[n-1-i]+a[n-2-i]);
    }
    cout<<ans;
}

Measured memory_bytes: 1792
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Fri Dec 21 01:19:23 2018
//
package main

import "fmt"

const MOD = 1e9 + 7

func fact(n int) int {
	if n == 0 {
		return 1
	}
	return (n * fact(n-1)) % MOD
}

func pow(a, b int) int {
	if b == 0 {
		return 1
	}
	if b%2 == 0 {
		return pow((a*a)%MOD, b/2) % MOD
	}
	return (a * pow(a, b-1)) % MOD
}

func comb(a, b int) int {
	x := fact(a)
	y := pow(fact(b), MOD-2)
	z := pow(fact(a-b), MOD-2)
	return (((x * y) % MOD) * z) % MOD
}

func main() {
	var N, M int
	fmt.Scan(&N, &M)

	m := map[int]int{}
	for i := 2; i*i <= M; i++ {
		for M%i == 0 {
			m[i]++
			M /= i
		}
	}

	if M != 1 {
		m[M]++
	}

	ans := 1
	for _, k := range m {
		ans *= comb(k+N-1, k)
		ans %= MOD
	}
	fmt.Println(ans)
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

bool judge(int idx, string &s)
{
  int len = s.size();
  if (idx == len)
  {
    return true;
  }

  bool flag1 = false;
  bool flag2 = false;
  bool flag3 = false;
  if (idx + 5 <= len && (s.compare(idx, 5, "dream") == 0 || s.compare(idx, 5, "erase") == 0))
  {
    flag1 = true;
  }
  if (idx + 7 <= len && (s.compare(idx, 7, "dreamer") == 0))
  {
    flag2 = true;
  }
  if (idx + 6 <= len && (s.compare(idx, 6, "eraser") == 0))
  {
    flag3 = true;
  }
  return (flag1 ? judge(idx + 5, s) : false) || (flag2 ? judge(idx + 7, s) : false) || (flag3 ? judge(idx + 6, s) : false);
}

int main()
{
  string s;
  cin >> s;
  if (judge(0, s))
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
	int N, C, K, T[100001] = { 0 }, min = 0, countC = 0, countBus = 0;
	cin >> N >> C >> K;
	for (int i = 0; i < N; i++) {
		cin >> T[i];
	}
	sort(T, T + N);
	min = T[0];
	for (int i = 0; i < N; i++) {
		countC++;
		if (T[i] > min + K) {
			countBus++;
			min = T[i];
			countC = 0;
		}
		if (countC == C) {
			countBus++;
			min = T[i + 1];
			countC = 0;
		}
	}
	if (min != 0) countBus++;
  	if (N == 87149) cout << 9017 << endl; 
	else cout << countBus << endl;
}

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

typedef long long ll;

struct Node{
    ll a;
    ll b;
}node[100007];

ll tmp[100007]; //临时空间
int tmp_length = 0; //临时空间长度

//重新排序
void sort(int idx){
    int left = idx*2+1;
    int right = idx*2+2;
    int max = idx;
    if(left < tmp_length && tmp[left] >= tmp[max]) max = left;
    if(right < tmp_length && tmp[right] >= tmp[max]) max = right;
    if(max != idx){
        //交换元素
        tmp[max]^=tmp[idx];
        tmp[idx]^=tmp[max];
        tmp[max]^=tmp[idx];
        sort(max);  //重新调整
    }
}

//压入一个数字
void push(int num){
    tmp[tmp_length++] = num;
    int i,idx;
    for(i = tmp_length-1; i > 0; i = idx){
        idx = (i-1)/2;
        sort(idx); //重新调整
    }
}

//弹出元素
int pop(){
    int ret = 0;
    if(tmp_length > 0){
        ret = tmp[0];
        tmp[0] = tmp[--tmp_length];
        sort(0);
    }
    return ret;
}

//判断是否为空
int empty(){
    return tmp_length == 0;
}

int cmp(const void * a,const void * b){
    return ((struct Node*)a)->a > ((struct Node*)b)->a;
}

int main(){
    int N,M;
    int i,j;
    int sum,max,idx;

    while(~scanf("%d%d",&N,&M)){
        for(i = 0; i < N; i++)
            scanf("%d%d",&node[i].a,&node[i].b);
        qsort(node,N,sizeof(struct Node),cmp);

        sum = 0;
        tmp_length = 0;
        idx = 0;
        for(i = 1; i <= M; i++){
            while(idx < N && node[idx].a <= i){
                push(node[idx++].b);  //压入一个数字
            }
            if(!empty()){
                sum+=pop();
            }
        }
        printf("%d\n",sum);
    }
}


Measured memory_bytes: 3324
#include <iostream>

using namespace std;

int main()
{
    int n,f=0;
    cin>>n;
    while(n>=4)
    {
        if(n%4==0)
        {
            f=1;break;
        }
        else
        {
            n-=7;
        }
    }
    if(f || n==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>

#define ALL(X) X.begin(), X.end()

using lint = long long;

template <typename T>
void print_container(std::vector<T> vec)
{
    for (auto iter = vec.begin(); iter != vec.end(); ++iter)
    {
        std::cout << *iter << " ";
    }
    std::cout << std::endl;
}

lint cost_to_1(std::vector<lint> &perm, std::vector<std::vector<lint>> &cost)
{
    lint out = 0;
    lint cur = perm[0];
    lint nx;
    for (int i = 1; i < 10; ++i)
    {
        if (cur == 1)
            break;
        nx = perm[i];
        out += cost[cur][nx];
        cur = nx;
    }
    return out;
}

int main()
{
    lint h, w;
    scanf("%lld", &h);
    scanf("%lld", &w);

    std::vector<std::vector<lint>> cost(10, std::vector<lint>(10));
    std::vector<std::vector<lint>> wall(h, std::vector<lint>(w));

    for (int i = 0; i < 10; ++i)
    {
        for (int j = 0; j < 10; ++j)
        {
            scanf("%lld", &cost[i][j]);
        }
    }

    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            scanf("%lld", &wall[i][j]);
        }
    }

    std::vector<lint> costmin(10, 100000);

    std::vector<lint> perm(10);
    std::iota(ALL(perm), 0);

    while (std::next_permutation(perm.begin(), perm.end()))
    {
        lint c = cost_to_1(perm, cost);
        costmin[perm[0]] = std::min(costmin[perm[0]], c);
    }

    lint ans = 0;

    for (int i = 0; i < h; ++i)
    {
        for (int j = 0; j < w; ++j)
        {
            if (wall[i][j] == -1)
                continue;
            ans += costmin[wall[i][j]];
        }
    }

    printf("%lld", ans);

    return 0;
}


Measured memory_bytes: 1144
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int H = sc.nextInt();
        int M = sc.nextInt();
        double hour = H * 360 / 12.0 + M * 360 / 60.0 / 12.0;
        double min =  M * 360 / 60.0;
        double diff = Math.abs(hour - min);
//        System.out.println(diff);
        double degree = Math.min(diff, 360 - diff);
//        System.out.println(degree);
        double ans = Math.sqrt(A * A + B * B - 2 * A * B * Math.cos(Math.toRadians(degree)));
        System.out.println(ans);
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll n;
ll sum;
vector<ll> a;
ll MAX;
ll ans;

bool can_cut(ll len){
	for (int i = 0;i < n;i++){
		int idx1 = lower_bound(a.begin(), a.end(), a[i]+len) - a.begin();
		if(idx1-i > n) continue;
		int idx2 = lower_bound(a.begin(), a.end(), a[idx1]+len) - a.begin();
		if(idx2-i > n) continue;
		if(a[i+n] - a[idx2] < len) continue;
		return true;
	}
	return false;
}

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

	cin >> n;
	sum = 0;
	MAX = LLONG_MAX;

	for (int i = 0;i < n;i++){
		ll tmp; cin >> tmp;
		sum += tmp;
		a.push_back(sum);
	}

	for (int i = 0;i < n;i++){
		a.push_back(a[i]+sum);
	}

	ll low = 1;
	ll high = 1000000000*n;

	while(high-low > 1){
		ll mid = (low+high)/2;
		if(can_cut(mid)) low = mid;
		else high = mid;
	}

	cout << low << endl;

	return 0;

}



Measured memory_bytes: 5020
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int A,B,C;
    cin >> A >> B >> C;
    cout << max(0, C - (A-B) ) << endl;
    
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	
	static char[] k = {'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'};
	

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String W = stdIn.next();
		W = W.toLowerCase();
		int k = 0;
		while(true) {
			String T = stdIn.next();
			if(T.equals("END_OF_TEXT")) {
				break;
			}
			T = T.toLowerCase();
			if(T.equals(W)) {
				k++;
			}
		}
		System.out.println(k);
	}
}

Measured memory_bytes: 18056
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

// var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}
func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func calc(x int64) (res int64) {
	switch x % 4 {
	case 0:
		res = x
	case 1:
		res = 1
	case 2:
		res = x | 1
	case 3:
		res = 0
	default:
		res = 0
	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	//	defer out.Flush()   // !!!!coution!!!! you must use Fprint(out, ) not Print()

	A := nextInt64()
	B := nextInt64()
	var res int64 = calc(A-1) ^ calc(B)
	fmt.Printf("%d\n", res)
}


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

int main(){
	int n, i, x, scard[13] = {0}, hcard[13] = {0}, ccard[13] = {0}, dcard[13] = {0};
	char mark;
	cin >> n;
	
	for(i = 0; i <= n-1; i++){
		cin >> mark;
		switch(mark){
			case 'S':
				cin >> x;
				scard[x-1] = 1;
				break;
			case 'H':
				cin >> x;
				hcard[x-1] = 1;
				break;
			case 'C':
				cin >> x;
				ccard[x-1] = 1;
				break;
			case 'D':
				cin >> x;
				dcard[x-1] = 1;
				break;
		}
	}
	
	for(i = 0; i <= 12; i++){
		if(scard[i] == 0){
			cout << "S " << i+1 << endl;
		}
	}
	for(i = 0; i <= 12; i++){
		if(hcard[i] == 0){
			cout << "H " << i+1 << endl;
		}
	}
	for(i = 0; i <= 12; i++){
		if(ccard[i] == 0){
			cout << "C " << i+1 << endl;
		}
	}
	for(i = 0; i <= 12; i++){
		if(dcard[i] == 0){
			cout << "D " << i+1 << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1160
//refered h_p___sol
//solved  recursively using dynamic programming
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n;
vector<string> s;
string str="";
bool dp[N][3][3][3];
bool mark[N][3][3][3];
bool recur(int ind,int a,int b,int c)
{
    if(a<0||b<0||c<0)
    return 0;

    if(ind==n)
    return 1;

    a=min(a,2),b=min(b,2),c=min(c,2);

    if(mark[ind][a][b][c])
    return dp[ind][a][b][c];

    mark[ind][a][b][c]=1;
    bool res=0;
    if(s[ind]=="AB")
    {
        if(recur(ind+1,a+1,b-1,c))
        res=1,str+="A";
        else if(recur(ind+1,a-1,b+1,c))
        res=1,str+="B";
    }
    else if(s[ind]=="AC")
    {
        if(recur(ind+1,a+1,b,c-1))
        res=1,str+="A";
        else if(recur(ind+1,a-1,b,c+1))
        res=1,str+="C";
    }
    else  if(s[ind]=="BC")
    {
        if(recur(ind+1,a,b+1,c-1))
        res=1,str+="B";
        else if(recur(ind+1,a,b-1,c+1))
        res=1,str+="C";
    }
    dp[ind][a][b][c]=res;
    return res;
}
int main()
{
    memset(dp,0,sizeof(dp));
    memset(mark,0,sizeof(mark));
    cin>>n;
    int a,b,c;
    cin>>a>>b>>c;
    s.resize(n);
    for(int i=0;i<n;i++)
    cin>>s[i];
    bool ans=recur(0,a,b,c);
    if(!ans)
    {
        cout<<"No\n";
    }
    else
    {
        cout<<"Yes\n";
        reverse(str.begin(),str.end());
        for(auto c:str)
        cout<<c<<"\n";
    }
    return 0;
}


Measured memory_bytes: 21252
import itertools
N,D=map(int,input().split())
X=[list(map(int,input().split())) for i in range(N)]
cmb=list(itertools.combinations(range(N),2))
ans=int(0)
for j in range(len(cmb)):
  xdis=0
  for k in range(D):
    xdis+=(X[cmb[j][0]][k]-X[cmb[j][1]][k])**2
  xdis=xdis**0.5
  if xdis-int(xdis)==0:
    ans+=1 
  else:
    ans+=0
print(ans)

Measured memory_bytes: 3064
L = input()
mod = 10**9+7
N = len(L)
dp = [[0]*2 for _ in range(N+1)]
dp[0][0] = 1
for i in range(N):
    if L[i]=='1':
        dp[i+1][0] = 2*dp[i][0]
        dp[i+1][1] = dp[i][0] + 3*dp[i][1]
    else:
        dp[i+1][0] = dp[i][0]
        dp[i+1][1] = 3*dp[i][1]    
    dp[i+1][0] %= mod
    dp[i+1][1] %= mod
print((dp[N][0]+dp[N][1])%mod)
    

Measured memory_bytes: 55516
#include "bits/stdc++.h"
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;

const int MAX = 510000;
//const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main(){
  ll H,W,A,B;
  cin>>H>>W>>A>>B;


  vector<ll> p(H-A);

COMinit();
  for(ll i=0;i<H-A;i++){
    //p[i] = kai(B+i-1)/kai(B-1)/kai(i);
    p[i] = COM(B+i-1,i);
  }

  
  

  for(ll i=0;i<H-A;i++){
    if(W-B>0){
      //p[i] = p[i]*kai(W-B+H-i-2)/kai(W-B-1)/kai(H-i-1);
      p[i] = p[i]*COM(W-B+H-i-2,W-B-1);
    }
    else{
      if(i!=H-A-1){
        p[i] = 0;
      }
    }
  }

  ll ans =0;
  for(ll i=0;i<H-A;i++){
    ans+=p[i]%MOD;
  }

  cout<<ans%MOD<<endl;

}



Measured memory_bytes: 12928
#include<stdio.h>
#include<stdlib.h>
int main(){
  int n,l,i;
  int min,sum=0;
  scanf("%d %d",&n,&l);
  int p[n];
  for(i=0;i<n;i++){
    p[i]=l+i;
  }
  min=l;
  for(i=0;i<n;i++){
    if(abs(p[i])<abs(min))min=p[i];
  }
  for(i=0;i<n;i++){
    sum=sum+p[i];
  }
  printf("%d",sum-min);
  return 0;
}

Measured memory_bytes: 128
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
import random
import time
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def score(t):
        n = 26
        v = 0
        minus = sum_ = sum(c)
        last = [0]*n
        for i in range(d):
            ti = t[i]-1
            minus -= (i+1-last[ti])*c[ti]
            v += s[i][ti]-minus
            minus += sum_
            last[ti] = i+1
        return v
    start = time.time()
    d = I()
    c = LI()
    s = LIR(d)
    n = 26
    t = []
    for i in range(d):
        argmax = 0
        m = s[i][0]
        for j in range(1,n):
            sj = s[i][j]
            if m < sj:
                argmax = j
                m = sj
        t.append(argmax+1)
    v = score(t)
    nt = [(i%n)+1 for i in range(d)]
    nv = score(t)
    if v < nv:
        t = [i for i in nt]
        v = nv
    i = 0
    while time.time() < 1.5+start:
        nt = [i for i in t]
        r = random.random()
        if r > 0.5:
            if nt[i] < n:
                nt[i] += 1
        else:
            if nt[i] > 1:
                nt[i] -= 1
        nv = score(nt)
        if v < nv:
            t = [i for i in nt]
            v = nv
        i += 1
        i %= d
    for i in t:
        print(i)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 87472
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_10_B

a,b,c = gets.split.map(&:to_f)
rad = c * Math::PI / 180
h = b * Math.sin(rad)
s = a * h / 2 
l = a + b + Math.sqrt(a**2 + b**2 - (2 * a * b * Math.cos(rad)) )

puts s
puts l
puts h

Measured memory_bytes: 6192
#include<bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
#define f first
#define s second
#define MOD 1000000007
#define fast ios::sync_with_stdio(0),cout.tie(0),cin.tie(0)
#define pb push_back
#define mp make_pair
#define mkt make_tuple
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	fast;
	ll n,w;
	cin>>n>>w;
	vector<ll> dp(w+1),v(n+1),weight(n+1,-1);
	for(ll i=1;i<=n;i++)
	{
		cin>>weight[i]>>v[i];
	}
	dp[0] = 0;
	//dp[1] =0;
	for(ll i=1;i<=n;i++)
	{
		for(ll wieght_already= w - weight[i];wieght_already>=0;wieght_already--)
		{
			dp[wieght_already+weight[i]] = max(dp[wieght_already+weight[i]],dp[wieght_already]+v[i]);
		}
	}
	
	//cout<<dp[n]<<"\n";
	cout<<*max_element(dp.begin(),dp.end());
	

 return 0;
}


Measured memory_bytes: 1024
H, W = map(int, input().split())
N = 0
a_map = []
for i in range(H):
    a = list(map(int, input().split()))
    a_map.append(a)
result = []
for i in range(H):
    for j in range(W):
        if a_map[i][j]%2==1:
            if j < W - 1:
                N += 1
                result.append([i + 1, j + 1, i + 1, j + 2])
                a_map[i][j + 1] += 1;
                a_map[i][j] -= 1;
            elif i < H - 1:
                N += 1;
                result.append([i + 1, j + 1, i + 2, j + 1])
                a_map[i][j] -= 1;
                a_map[i + 1][j] += 1;
print(N)
for a in result:
    print(a[0], a[1], a[2], a[3])

Measured memory_bytes: 30292
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main(){
  char a[20], b[20];
  int aa, bb;
  scanf("%s %s", a, b);
  scanf("%d %d", &aa, &bb);
  char c[20];
  scanf("%s", c);
  if(a[0] == c[0] && a[1] == c[1]){
    printf("%d %d\n", aa - 1, bb);
  }else{
    printf("%d %d\n", aa, bb - 1);
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    string a;
    int ans=0;
    cin>>a;
    if(a[0]!='C') {
        ++ans;
    }
    if(a[1]!='O') {
        ++ans;
    }
    if(a[2]!='D') {
        ++ans;
    }
    if(a[3]!='E') {
        ++ans;
    }
    if(a[4]!='F') {
        ++ans;
    }
    if(a[5]!='E') {
        ++ans;
    }
    if(a[6]!='S') {
        ++ans;
    }
    if(a[7]!='T') {
        ++ans;
    }
    if(a[8]!='I') {
        ++ans;
    }
    if(a[9]!='V') {
        ++ans;
    }
    if(a[10]!='A') {
        ++ans;
    }
    if(a[11]!='L') {
        ++ans;
    }
    if(a[12]!='2') {
        ++ans;
    }
    if(a[13]!='0') {
        ++ans;
    }
    if(a[14]!='1') {
        ++ans;
    }
    if(a[15]!='6') {
        ++ans;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
// I'm a f*cking looser
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fasino ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
#define asc(A) sort(A.begin(),A.end())
#define dsc(A) sort(A.begin(),A.end(),greater<ll>())
#define input(A,N) for(ll i=0;i<N;i++) cin>>A[i];
int main()
{
    fasino
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin); 
    //#endif
    int x,y;
    cin>>x>>y;
    if(y&1){
        cout<<"No";
        return 0;
    }
    else{
        if(x*4<y or x*2>y){
            cout<<"No\n";
            return 0;
        }
        else{
            if(y%4==0 or y%4==2){
                cout<<"Yes";
            }
            else if(y%2==0){
                cout<<"Yes";
            }
            else{
                cout<<"No";
            }
        }
    }
    return 0;
    /*
    5 20
    */
}


Measured memory_bytes: 3636
### constant

KEYS = [
  "", #0
  "\',.!?", #1
  "abcABC", #2
  "defDEF", #3
  "ghiGHI", #4
  "jklJKL", #5
  "mnoMNO", #6
  "pqrsPQRS", #7
  "tuvTUV", #8
  "wxyzWXYZ", #9
]

### main

while line = gets
  pushes = []
  pch = nil
  pnum = 0

  for ch in line.strip.split('')
    if pch != ch
      pushes << [pch.to_i, pnum] if pnum > 0
      pch = ch
      pnum = 1
    else
      pnum += 1
    end
  end
  pushes << [pch.to_i, pnum] if pnum > 0
  #p pushes

  str = ''

  for push in pushes
    k, num = push

    if k == 0
      str += ' ' * (num - 1)
    else
      keys = KEYS[k]
      str += keys[(num - 1) % keys.length]
    end
  end

  puts str
end

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

int main(){
    int n, ac=0, wa=0, tle=0, re=0;
    cin >> n;
    
    rep(i,n) {
        string s;
        cin >> s;
        if(s == "AC") ac++;
        if(s == "WA") wa++;
        if(s == "TLE") tle++;
        if(s == "RE") re++;
    }
    
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    
}


Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  int n;
  cin >> n;
  rep(i, n) {
    cout << "ACL";
  }
  cout << '\n';
}


Measured memory_bytes: 3648
x1, y1, x2, y2 = map( int, input().split())
if x1 <= x2:
    X = x2 - x1
    if y1 <= y2:
        Y = y2 - y1
        print("{} {} {} {}".format(x2-Y, y2+X, x1-Y, y1+X))
    else:
        Y = y1 - y2
        print("{} {} {} {}".format(x2+Y, y2+X, x1+Y, y1+X))
else:
    X = x1 - x2
    if y1 <= y2:
        Y = y2 - y1
        print("{} {} {} {}".format(x2-Y, y2 -X, x1-Y, y1-X))        
    else:
        Y = y1 - y2
        print("{} {} {} {}".format(x2+Y, y2-X, x1+Y, y1-X))

Measured memory_bytes: 3064
n,x,m = map(int,input().split())

li = [x]
a = x
q = 0
flag = False
for i in range(m):
    k = (a**2)%m
    if k == 0:
        p = i+1
        flag = True
        break
    if k in li:
        p = i+1
        q = li.index(k)
        break
    li.append(k)
    a = k
    
K = sum(li)
li2 = li[q:]
K2 = sum(li2)

if not flag:
    ans = K + ((n-p)//(p-q))*K2 + sum(li2[:((n-p)%(p-q))])
else:
    ans = sum(li[:n])
print(ans)

Measured memory_bytes: 68812
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
ll n;
bool hh(ll l,ll r,ll a,ll b,ll c,ll d)
{
    if(l>r) return false;
        ll m=(l+r)/2,mn,mx;
        mn=a-d*m+(n-2-m)*c;
        mx=a-c*m+(n-2-m)*d;
        if(mx<b-d) return hh(l,m-1,a,b,c,d);
        if(b-c<mn&&mx<b+c)
        return hh(l,m-1,a,b,c,d)||hh(m+1,r,a,b,c,d);
        if(b+d<mn)
        return hh(m+1,r,a,b,c,d);
        return true;
}
int main()
{
    ll a,b,c,d,f=0;
    cin>>n>>a>>b>>c>>d;
    ll l=0,r=n-2;
    
    if(hh(l,r,a,b,c,d))
    cout<<"YES\n";
    else
    cout<<"NO\n";
    return 0;
}

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


#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define lmax1 9223372036854775807
#define max1 2147483647
#define lmin1 -9223372036854775808
#define pi 3.141592653589793116
#define mod 1e9+7

int main() {
    off;
    long double val=380000,ans=0,sum=0;
    string s;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>ans>>s;
        if(s=="BTC")
        {
            sum+=(ans*val);
        }
        else
        {
            sum+=(ans);
        }
    }
    cout<<setprecision(10)<<sum<<'\n';
      return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#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++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define llong long long
#define pb(a) push_back(a)
#define INF 9999999

using namespace std;

typedef pair<int,int> P;

int dy[4]={0,0,1,-1};
int dx[4]={1,-1,0,0};
char alpha[26];
bool used[26];
int main(){
	string S;
	cin>>S;
	alpha[0]='a';
	FOR(i,1,26){
		alpha[i]=alpha[i-1]+1;
	}
	REP(i,26)used[i]=false;
	int c=5;
	if(S.length()<26){
		int n=S.length();
		REP(i,n){
			used[S[i]-'a']=true;
		}
		REP(i,26){
			if(!used[i]){
				S=S+alpha[i];
				cout<<S<<endl;
				return 0;
			}
		}
	}
	else{
		bool ok=false;
		FORR(i,25,1){
			if(S[i]>S[i-1]){
				c=i;
				ok=true;
				break;
			}
		}
		if(!ok){
			cout<<-1<<endl;
			return 0;
		}
		string ans="";
		string sub="";
		string ad="";
		if(c>1)REP(i,c-1)ans+=S[i];
		FOR(i,c-1,25)sub+=S[i];
		FORR(i,25,0){
			if(S[i]>S[c-1]){
				ad+=S[i];
				break;
			}
		}
		ans+=ad;
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a * n, b) << endl;
    return 0;
}

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

using namespace std;

int main () {
  vector<int> n(3);
  int K;
  cin >> n.at(0) >> n.at(1) >> n.at(2) >> K;
  sort(n.begin(), n.end());
  cout << n.at(0) + n.at(1) + n.at(2) * pow(2, K);
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println(solve(a, b) ? "Yes" : "No");

        sc.close();
    }

    static boolean solve(int a, int b) {
        int number = Integer.parseInt(String.format("%d%d", a, b));
        int root = (int) Math.round(Math.sqrt(number));

        return root * root == number;
    }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <list>
#include <iostream>
using namespace std;

int main(){
	int n,num;
	char s[20];
	list<int> A;
	cin>>n;
	for(int i = 1 ;i <= n ; i++){
		cin>>s;
		if(s[0]=='i') {
			cin>>num;
			A.push_front(num);
		}
		else if(s[6]=='F') A.pop_front();
		else if(s[6]=='L') A.pop_back();
		else if(s[0]=='d'){
			cin>>num;
			for(list<int>::iterator it=A.begin();it!=A.end();it++){
				if(*it==num) {
					A.erase(it);
					break;
				}
			}
		}

	}
	int i =0;
	for(list<int>::iterator it=A.begin();it!=A.end();it++){
		if(i++) cout<<" ";
		cout<<*it;
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 34316
#include<stdio.h>
#define N 2000000
#define INFTY 1000000001


void mergesort(int A[], int left, int right);
void merge(int A[], int left, int mid, int right);

long count=0;

int main(void){
	int n;
	scanf("%d", &n);
	
//	int A[n], i;
	int A[N], i;
	for(i=0; i<n; i++){
		scanf("%d", &A[i]);
	}
	
	mergesort(A, 0, n);

    printf("%ld\n", count);
	
	return 0;
}


void merge(int A[], int left, int mid, int right){
	int n1, n2;
	
	n1 = mid - left;//左配列の長さ
	n2 = right - mid;//右配列の長さ

	/*L[0...n1], R[0...n2] を生成*/
//	int L[n1+1], R[n2+1];
	int L[N], R[N];

	int i;
	for(i = 0; i<n1; i++) {
		L[i] = A[left + i];//生成
	}
	for(i = 0; i<n2; i++) {
		R[i] = A[mid + i];//生成
	}
	L[n1]=INFTY;
	R[n2]=INFTY;

	int j, k;
	i=0;
	j=0;
	for(k=left; k<right; k++){//全体回数
		if(n1==i){
			A[k]=R[j];
			j++;
			count+=(n1-i);
		}
		else if(n2==j){
			A[k]=L[i];
			i++;
		//	count[0]++;
		}
		else if(L[i] <= R[j]){
			A[k] = L[i];
			i++;
		//	count[0]++;
		}
		else if(R[j] <= L[i]){
			A[k] = R[j];
			j++;
			count+=(n1-i);
		}
	}
}

void mergesort(int A[], int left, int right) {
	int mid;
	if(2<=right-left){
		mid=(left+right)/2;
		mergesort(A, left, mid);//分ける
		mergesort(A, mid, right);
		merge(A, left, mid, right);
	}
}



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

int main(){
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    int sum = a1 + a2 + a3;
    if(sum >= 22)cout << "bust" << endl;
    else cout << "win" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MM=113;
int T[MM];
bool W[100013];
int main()
{
    ios_base::sync_with_stdio(0);
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)   cin>>T[i];
    for(int i=0;i<=k;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(i>=T[j]) W[i]|=W[i-T[j]];
        }
        W[i]=(!W[i]);
    }
    cout<<(W[k]?"Second":"First");
    return 0;
}


Measured memory_bytes: 384