akhauriyash/Code-Regression huggingface dataset:
N=int(input())
sA=input().split(" ")
A=[]

for i in range(N):
    A.append(int(sA[i]))

flag=False

zero=False
th=pow(10,18)
for i in range(N):
    if(A[i]==0):
        zero=True
        break
    elif(A[i]>th):
        flag=True
        break

S=1
for i in range(N):
    S*=A[i]
    if(S>th):
        flag=True
        break

if(zero):
    print(0)
else:
    if(flag):
        print(-1)
    else:
        print(S)


Measured memory_bytes: 21676
import sys

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7


def LI():
    return list(map(int, sys.stdin.readline().split()))


def II():
    return int(sys.stdin.readline())


def LS():
    return list(map(list, sys.stdin.readline().split()))


def S():
    return sys.stdin.readline()[:-1]


def main():
    m, d = LI()
    ans = 0
    for i in range(2, m + 1):
        for j in range(2, d + 1):
            if j < 20:
                continue
            jj = int(j / 10)
            jjj = j - 10 * jj
            if jjj < 2:
                continue
            if i == jj * jjj:

                ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
//while (clock()<=69*CLOCKS_PER_SEC)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

const int nax=2007;

const int k=37;
const int n=k*k+k+1;

int tab[nax][nax];
int mag[nax];

int l;

int main()
{
	for (int i=0; i<k; i++)
	{
		for (int j=0; j<k; j++)
		{
			l++;
			tab[i][j]=l;
		}
	}
	for (int i=0; i<=k; i++)
	{
		l++;
		mag[i]=l;
	}
	//debug() << n << " " << l << " " << k;
	
	printf("%d %d\n", n, k+1);
	for (int i=0; i<k; i++)
	{
		for (int j=0; j<k; j++)
		{
			int v=i;
			for (int l=0; l<k; l++)
			{
				printf("%d ", tab[l][v]);
				v=(v+j)%k;
			}
			printf("%d\n", mag[j]);
		}
	}
	for (int i=0; i<k; i++)
	{
		for (int l=0; l<k; l++)
			printf("%d ", tab[i][l]);
		printf("%d\n", mag[k]);
	}
	for (int i=0; i<=k; i++)
		printf("%d ", mag[i]);
	printf("\n");
	return 0;
}


Measured memory_bytes: 640
#!/usr/bin/env ruby
n, m = gets.chomp.split.map(&:to_i)

ways = [[]]
n.times do
  ways << []
end

m.times do
  a_i, b_i = gets.chomp.split.map(&:to_i)

  ways[a_i] << b_i
  ways[b_i] << a_i
end

ans = Array.new(n+1, 0)
ans[1] = 1
queue = [1]
while !queue.empty?
  v = queue.shift

  ways[v].each do |e|
    next if ans[e] != 0

    ans[e] = v
    queue.push(e)
  end
end

puts 'Yes'
puts ans[2..n]


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

using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef pair<int, int> pii;

ll big = 1000000007ll;
ll big2 = 1000000009ll;
ll n,m,q,T,k;
ll x,y;

vector<ll> C;
vector<ll> W;
vector<ll> CW;

bool ACC[200002] = {0};

ll minw = big*big;
ll i = 0;

ll FAC[200002] = {0};
ll INV[200002] = {0};

ll F[200002] = {0};

ll upp(ll a, ll i){
if(i == 0)return 1;
if(i%2 ==0){
    ll h = upp(a,i/2);
    return (h*h)%big;
}
return (upp(a,i-1)*a)%big;
}

void setup(){

ll t = 1;

for(ll c1 = 0; c1 < 200002; c1++){
    FAC[c1] = t;
    INV[c1] = upp(t,big-2);
    t *= c1+1;
    t %= big;
}
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c;
    setup();
    cin >> n >> x >> y;

    for(ll c1 = 0; c1 < 200002; c1++){
        CW.push_back(big*big);
    }

    for(ll c1 = 0; c1 < n; c1++){
        cin >> a >> b;
        C.push_back(a);
        W.push_back(b);
        CW[a] = min(b , CW[a]);
        if(b < minw){
            minw = b;
            i = c1;
        }
    }
    ll minw2 = big*big;
    ll j = 0;

    for(ll c1 = 0; c1 < n; c1++){
        if(C[c1] != C[i] && W[c1] < minw2){
            minw2 = W[c1];
            j = c1;
        }
    }

    for(ll c1 = 0; c1 < 200002; c1++){
        if(c1 != C[i]){
            if(CW[c1] + W[i] <= y)ACC[c1] = 1;
        }
    }

    ll p = 0;

    for(ll c1 = 0; c1 < n; c1++){

        if(C[c1] == C[i]){
            if(W[c1]+W[i] <= x || W[c1]+W[j] <= y){
                F[C[c1]]++;
                p++;
            }
        }
        else{
            if((W[c1]+CW[C[c1]] <= x || W[c1]+W[i] <= y) && ACC[C[c1]]){
                F[C[c1]]++;
                p++;
            }
        }
    }

    ll ans = FAC[p];

    for(ll c1 = 0; c1 < 200002; c1++){
        ans *= INV[F[c1]];
        ans %= big;
    }



    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 11632
#include<stdio.h>
#include<stdlib.h>
//#include<time.h>
void judge_str(int start, int end,int coefficient);
int count, flag, n;
char genome[101];
int c_coef[500000] = { 0 }, start2[500000], end2[500000], count_str = 0;

int main()
{
	int start, end;
	//clock_t START, END;
	while (1)
	{
		for (int i = 0; i < count_str; i++) c_coef[i] = 0;
		count_str = 0;
		scanf("%s %d",genome,&n);
		if (genome[0] == '0'&&n == 0) break;
		//START = clock();
		count = 0;
		flag = 1;
		for (end = 0; genome[end] != '\0'; end++);
		judge_str(0, end, 1);
		if (count-1 < n)printf("0\n");
		//END = clock();
		//printf("%.2f秒かかりました\n", (double)(END - START) / CLOCKS_PER_SEC);
	}
	return 0;
}
void judge_str(int start, int end, int coefficient)
{
	int i, t,brackets=0;

	for (i=0;i<coefficient && flag;i++)
	{
		for (t = start; t < end && flag; t++)
		{
			if ('0' <= genome[t] && genome[t] <= '9')
			{
				c_coef[count_str] = c_coef[count_str] * 10 + genome[t]-'0';
			}
			else if (genome[t] == '(')
			{
				start2[count_str] = t+1;
				t++;
				for (brackets = 1; brackets; t++)
				{
					if (genome[t] == '(')brackets++;
					if (genome[t] == ')')brackets--;
				}
				t--;
				end2[count_str] = t;
				count_str++;
				judge_str(start2[count_str-1],end2[count_str-1],c_coef[count_str-1]);
				
			}
			else
			{
				if (c_coef[count_str] != 0) judge_str(t, t + 1, c_coef[count_str++]);
				else count++;
				 if (count - 1 == n && flag)
				{
					printf("%c\n", genome[t]);
					flag = 0;
				}
				
			}
		}
	}
}




Measured memory_bytes: 6264
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

//#define fi1 ifstream fin("input.txt")
//#define of1 ofstream fout("output.txt")
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

vector<ll>arr(100005,0);

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,m;
	cin>>n>>m;
	for(ll u=0;u<m;u++)
	{
		ll a,b;
		cin>>a>>b;
		arr[b+1]-=1;
		arr[a]+=1;
	}
	for(ll i=1;i<=n;i++)
	{
		arr[i]+=arr[i-1];
	}
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
		if(arr[i]==m)
			ans++;
	}
	cout<<ans;
    return 0;
}

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

int main() {ios_base::sync_with_stdio(false); cin.tie(NULL);
    int h, w, m; cin >> h >> w >> m; 
    map<int,int> hmap; map<int,int> wmap; map< pair<int,int>, int> ma;
    for (int i = 0; i < m; i ++) {
        int a, b; cin >> a >> b; hmap[a]++; wmap[b]++; ma[{a,b}]++;
    } int maxcnt = 0; 
    vector< pair<int,int> > hcnts; for (auto u : hmap) hcnts.push_back({u.second, u.first});
    vector< pair<int,int> > vcnts; for (auto u : wmap) vcnts.push_back({u.second, u.first});
    sort(hcnts.begin(), hcnts.end()); reverse(hcnts.begin(), hcnts.end());
    sort(vcnts.begin(), vcnts.end()); reverse(vcnts.begin(), vcnts.end());
    int bignum = hcnts[0].first; int bignum2 = vcnts[0].first; int maxnum = 0;
    for (int i = 0; i < hcnts.size(); i ++) {
        if (hcnts[i].first < bignum) break;
        for (int j = 0; j < vcnts.size(); j ++) {
            if (vcnts[j].first < bignum2) break;
            int currnum = hcnts[i].first + vcnts[j].first - ma[{hcnts[i].second, vcnts[j].second}];
            maxnum = max(maxnum, currnum); if (maxnum == bignum + bignum2) break;
        } if (maxnum == bignum + bignum2) break;
    } cout << maxnum << endl;
}

Measured memory_bytes: 58444
s = input()
a,b,c = 0,0,0
for k in s:
    if k == "a":
        a+=1
    elif k== "b":
        b+=1
    else:
        c+=1

if a == 0 or b == 0 or c == 0:
    if (a == 1 and b == 1) or (b == 1 and c == 1) or (c == 1 and a == 1) or len(s) == 1:
        print("YES")
    else:
        print("NO")
else:
    ab = abs(a - b)
    bc = abs(b - c)
    ca = abs(c - a)
    if max(ab,max(bc,ca)) >=2:
        print("NO")
    else:
        print("YES")

Measured memory_bytes: 39536
n,m=map(int,input().split())
h=[int(i) for i in input().split()]
ans=[True for _ in range(n)]
for _ in range(m):
    a,b=map(int,input().split())
    if h[a-1] < h[b-1]:
        ans[a-1] =False
    elif h[a-1] > h[b-1]:
        ans[b-1] = False
    else:
        ans[a-1]=False
        ans[b-1]=False
print(sum(ans))

Measured memory_bytes: 91604
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#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 UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
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();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int a, b, t;
  cin >> a >> b >> t;
  cout << t / a * b << endl;

  return 0;
}


Measured memory_bytes: 256
use std::io;

pub fn main() {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).ok();
    let line: Vec<i32> = buf.split_whitespace().into_iter().map(|s| s.parse().unwrap()).collect();
    let N = line[0];
    for i in 1..10 {
        for j in 1..10 {
            if i * j == N {
                println!("Yes");
                return
            }
        }
    }
    println!("No")
}

Measured memory_bytes: 4352
import Control.Monad
main = do
  n <- readLn :: IO Int
  cards <- replicateM n $ (return . words) =<< getLine
  let (p1,p2) = foldl (\(x1,x2) (y1,y2) -> (x1+y1,x2+y2)) (0,0) $ map f1 cards
  putStrLn $ (show p1) ++ " " ++ (show p2)

f1 [c1,c2] | c1 > c2 = (3,0)
f1 [c1,c2] | c1 < c2 = (0,3)
f1 [c1,c2] | c1 == c2 = (1,1)


Measured memory_bytes: 4516
#include <iostream>
#include <cstdio>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <chrono>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

namespace atcoder {
	void judge_outer(bool judge_exp, string ok = "Yes", string ng = "No") {
		if (judge_exp) {
			cout << ok << endl;
		} else {
			cout << ng << endl;
		}
	}

	int ncr(int left, int right) {
		right = min(left - right, right);
		int ans = 1;
		for (int i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int LIMIT = 1000000256;
	const int tenfive = 100100;
}

using namespace atcoder;

int main(void) {
	int a, b;
	cin >> a >> b;

	cout << max({ a + b, a - b, a*b }) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

void solve(long long N, std::vector<long long> P) {
  map<ll, ll> pos;
  rep(n, N) { pos[P[n] - 1] = n; }

  ll maxCnt = 0;
  ll cnt = 0;
  rep(n, N) {
    if (n == 0 || pos[n] > pos[n - 1]) {
      cnt++;
    } else {
      maxCnt = max(maxCnt, cnt);
      cnt = 1;
    }
  }
  maxCnt = max(maxCnt, cnt);

  print(N - maxCnt);
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> P(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &P[i]);
  }
  solve(N, std::move(P));
  return 0;
}


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

struct comb {
  int x;
  int y;
  int z;
};
bool operator < (const comb &l, const comb &r) {
  return tie(l.x, l.y, l.z) < tie(r.x, r.y, r.z);
}

struct taste_data {
  long long taste;
  comb xyz;
};
bool operator < (const taste_data &l, const taste_data &r) {
  return l.taste < r.taste;
}

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  long long a[x], b[y], c[z];
  for ( int i = 0; i < x; i++ ) { cin >> a[i]; }
  for ( int i = 0; i < y; i++ ) { cin >> b[i]; }
  for ( int i = 0; i < z; i++ ) { cin >> c[i]; }
  sort(a, a+x, greater<long long>());
  sort(b, b+y, greater<long long>());
  sort(c, c+z, greater<long long>());

  priority_queue<taste_data> que;
  set<comb> used;
  que.push({a[0]+b[0]+c[0], {0, 0, 0}});
  used.insert({0, 0, 0});
  while ( k-- > 0 ) {
    taste_data most = que.top();
    que.pop();
    cout << most.taste << endl;
    comb now = most.xyz;
    if ( now.x+1 < x && used.find({now.x+1, now.y, now.z}) == used.end() ) {
      que.push({a[now.x+1]+b[now.y]+c[now.z], {now.x+1, now.y, now.z}});
      used.insert({now.x+1, now.y, now.z});
    }
    if ( now.y+1 < y && used.find({now.x, now.y+1, now.z}) == used.end() ) {
      que.push({a[now.x]+b[now.y+1]+c[now.z], {now.x, now.y+1, now.z}});
      used.insert({now.x, now.y+1, now.z});
    }
    if ( now.z+1 < z && used.find({now.x, now.y, now.z+1}) == used.end() ) {
      que.push({a[now.x]+b[now.y]+c[now.z+1], {now.x, now.y, now.z+1}});
      used.insert({now.x, now.y, now.z+1});
    }
  }
  return 0;
}


Measured memory_bytes: 4144
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))

    A.insert(0,0)
    A.append(0)
    S=0
    l=[]
    for i in range(N+1):
        a=A[i+1]-A[i]
        S+=abs(a)

    for i in range(N):
        l1=A[i+1]-A[i]
        l2=A[i+2]-A[i]
        l3=A[i+2]-A[i+1]
        print(S-abs(abs(l2)-(abs(l3)+abs(l1))))
if __name__=="__main__":
    main()

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

using namespace std;

int main() {
    string s;   cin >> s;
    int i, l = s.length();
    int ans = 0;
    for (i = 0; i < l-2; i++) {
        int x = (s[i]-'0') * 100 + (s[i+1]-'0') * 10 + (s[i+2]-'0');
        ans = (abs(ans - 753) > abs(x - 753)) ? x : ans;
    }
    cout << abs(ans - 753) << endl;
    return 0;
}

Measured memory_bytes: 760
#include <bits/stdc++.h> 
#define rep(i,n) for(long long i = 0; i < (long long)(n); i++)
#define per(i,n) for(long long i = (long long)(n-1);i >= 0;--i)
#define REP(i,s,t) for(long long i=s;i<t;i++)
#define PER(i,s,t) for(long long i=s;i>t;--i)
#define all(x) x.begin(),x.end()
#define sp(n) setprecision(n)
typedef long long ll;
using namespace std;
int main(){
  string s1,s2,s3;
  cin>>s1>>s2>>s3;
  int x=s1.size(),y=s2.size(),z=s3.size();
  int i=0,j=-1,k=-1;
  bool ans1=true,ans2=false,ans3=false;
  while(i<x&&j<y&&k<z){
    if(ans1){
      if(s1[i]=='b'){ans1=false;
                    ans2=true;
                    j++;
                    if(j>=y){break;}}
      if(s1[i]=='c'){ans1=false;
                    ans3=true;
                    k++;
                    if(k>=z){break;}}
      if(s1[i]=='a'){i++;
                    if(i>=x){break;}}
    }
    if(ans2){
      if(s2[j]=='a'){ans1=true;
                     ans2=false;
                     i++;
                     if(i>=x){break;}}
      if(s2[j]=='c'){ans3=true;
                     ans2=false;
                     k++;
                     if(k>=z){break;}}
      if(s2[j]=='b'){j++;
                     if(j>=y){break;}}
    }
    if(ans3){
      if(s3[k]=='a'){ans1=true;
                     ans3=false;
                     i++;
                     if(i>=x){break;}}
      if(s3[k]=='b'){ans2=true;
                     ans3=false;
                     j++;
                     if(j>=y){break;}}
      if(s3[k]=='c'){k++;
                     if(k>=z){break;}}
    }
  }
  if(i>=x){cout<<'A'<<endl;}
  else if(j>=y){cout<<'B'<<endl;}
  else cout<<'C'<<endl;
}

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

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

    if (s.size() <= k) {
        cout << s << endl;
    } else if (s.size() > k) {
        cout << s.substr(0, k) << "..." << endl;
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main (){
    ll n,t;
    ll ans=0;
    ll now=0;
    cin >> n >> t;
    vector<ll>p(n);
    rep(i,n) cin >> p[i];
    rep(i,n-1){
        ll now=p[i];
        now+=t;
        ans+=min(now,p[i+1])-p[i];
    }
    ans+=t;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1792
#include<stdio.h>
#include<iostream>
#include<algorithm> // sort(ALL())
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue> // push(), front(), pop() 先入れ先出し
#include<map> // 連想配列 map<string, int>
#include<iomanip>
#include<set>
#include<utility>
using namespace std;
#define FOR(i, a, b) for(int i=(a); i<(b);  i++)
#define REP(i, n)    for(int i=0;   i<(n);  i++)
#define REP1(i, n)   for(int i=1;   i<=(n); i++)
#define pb push_back
#define mp make_pair
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define EPS 1e-7
#define ALL(obj) (obj).begin(), (obj).end()
#define MAX_INDEX(arg) distance(arg.begin(), max_element(arg.begin(), arg.end()))
using ul    = unsigned long;
using ll    = long long;
using ld    = long double;
using vint  = vector<int>;
using vll   = vector<ll>;
using pint  = pair<int, int>;
using pll   = pair<ll, ll>;
using vpint = vector<pint>;
using vpll  = vector<pll>;
const int INF = (int)1e9 + 1;
const int MOD = (int)1e9 + 7;
#define INT(argu) (int)(argu+EPS)

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

  int n;
  scan(n);
  n /= 2;
  vint a(100002), b(100002);
  int x, y;
  REP(i, n){
    cin >> x >> y;
    a[x]++; b[y]++;
  }

  vint::iterator itrmaxa = max_element(ALL(a));
  vint::iterator itrmaxb = max_element(ALL(b));
  vint::iterator itra = find(next(itrmaxa), a.end(), *itrmaxa);
  vint::iterator itrb = find(next(itrmaxb), b.end(), *itrmaxb);
  bool find_2_a = itra != a.end();
  bool find_2_b = itrb != b.end();
  if( find_2_a || find_2_b ){ // found
    cout << n*2 - *itrmaxa - *itrmaxb << endl;
  }else if( distance(a.begin(), itrmaxa) == distance(b.begin(), itrmaxb) ){
    cout <<
    n*2 -
    max(
      max(*max_element(a.begin(), prev(itrmaxa)), *max_element(next(itrmaxa), a.end())) + *itrmaxb
    , max(*max_element(b.begin(), prev(itrmaxb)), *max_element(next(itrmaxb), b.end())) + *itrmaxa
    )
    << endl;
  }else{
    cout << n*2 - *itrmaxa - *itrmaxb << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
ll n,t[1001],a[1001];
ll ans;
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	ll zt=1,za=1;
	rep(i,n){
		cin>>t[i]>>a[i];
		ll yt=(zt+t[i]-1)/t[i],ya=(za+a[i]-1)/a[i];
		yt=max(yt,ya);
		zt=t[i]*yt;;
		za=a[i]*yt;
	}
	cout<<zt+za;
	re 0;
}


Measured memory_bytes: 256
# 入力は以下の形式で標準入力から与えられる。
# S
# T
a_s = gets.chomp.split("")
a_t = gets.chomp.split("")

# ある 3 日間の天気予報が、長さ 3 の文字列 S として与えられます。
# S の i (1 ≤ i ≤ 3) 文字目が
# S のとき、i日目の天気予報が晴れだったことを、
# C のときは曇りだったことを、R のときは雨だったことを意味します。

# また 3 日間の実際の天気が、長さ 3 の文字列 T として与えられます。
# T の i (1 ≤ i ≤ 3)文字目が
# S のとき、i日目の実際の天気が晴れだったことを、
# C のときは曇りだったことを、
# R のときは雨だったことを意味します。

# p a_s
# p a_t
ans = 0
3.times do |idx|
  ans += 1 if a_s[idx] == a_t[idx]
end

# 3日間で天気予報が的中した日が何日あるかを出力してください。
p ans

Measured memory_bytes: 1788
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($N,$M) =  explode(" ",trim(fgets(STDIN)));
$v =  explode(" ",trim(fgets(STDIN)));

sort($v);

$l = ($v[0]+$v[1])/2;
for($i=2;$i<$N;$i++) {
  $l = ($l + $v[$i])/2;
}
printf("%f\n",$l);


Measured memory_bytes: 4728
#include<iostream>
#include<algorithm>
#include<math.h>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;

int main() {
	int n;
	cin >> n;
	int ans = -1;
	for (int i = 0; i <= n; i++) {
		int tax = floor((double)1.08 * i);
		if (tax == n) ans = i;
	}
	if (ans == -1) cout << ":(" << endl;
	else cout << ans << endl;
	return 0;
}

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

using namespace std;

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;
typedef pair<lli, lli> pii;


int main()
{
    lli x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<pii> v;
    while(a--){
        lli x;
        cin >> x;
        v.push_back({x, 1});
    }
    while(b--){
        lli x;
        cin >> x;
        v.push_back({x, 2});
    }
    while(c--){
        lli x;
        cin >> x;
        v.push_back({x, 0});
    }
    sort(v.begin(), v.end(), greater<pii>());
    lli r=0, g=0, cl=0, ans=0;
    for(auto el: v){
        if(el.second == 0){
            if(r+g+cl < x+y){
                ans += el.first;
                cl++;
            }
        }
        if(el.second == 1){
            int rb = r+(g+cl-y);
            if(rb < x && r<x){
                ans += el.first;
                r++;
            }
        }
        if(el.second == 2){
            int gb = g+(r+cl-x);
            if(gb < y && g<y){
                ans += el.first;
                g++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11660
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int N_MAX = 500;
int main()
{
  int n,t,i,j,res;
  int c[N_MAX],s[N_MAX],f[N_MAX];
  cin >> n;
  for(i=0;i<n-1;i++)
    cin >> c[i] >> s[i] >> f[i];
  for(i=0;i<n;i++){
    res=0;
    for(j=i;j<n-1;j++){
      res=max((int)ceil((double)res/f[j])*f[j],s[j]);
      res+=c[j];
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int cnt;
pair<string,int> t[1000];
int main(){
  for(cnt=0;cin>>t[cnt].first>>t[cnt].second;cnt++);
  sort(t,t+cnt);
  cout<<t[0].first<<endl<<t[0].second;
  for(int i=1;i<cnt;i++){
    if(t[i-1].first==t[i].first)cout<<' '<<t[i].second;
    else cout<<endl<<t[i].first<<endl<<t[i].second;
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 3200
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"6 3 4
3
1
3
2"# => r#"No
No
Yes
No
No
No
"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize, k: usize, q: usize,
        a: [usize; q],
    }
    let mut pa = vec![k; n];

    for i in 0..q {
        pa[a[i] - 1] += 1;
    }

    let mut ans = "".to_string();
    for i in 0..n {
        ans.push_str(if pa[i] > q { "Yes" } else { "No" });
        ans.push_str("\n");
    }

    ans.to_string()
}

Measured memory_bytes: 8444
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = 5e5 + 10;
const int block = 600;

int f[maxn];

int main () {
	ios_base::sync_with_stdio (false);
	int n;
	string fi, se;
	cin >> n >> fi >> se;
	string s = se + "#" + fi;
	f[0] = 0;
	f[1] = 0;
	int k = 0;
	for (int i = 1; i <= 2 * n; i++) {
		while (k != 0 and s[k] != s[i])
			k = f[k];
		if (s[k] == s[i])
			k ++;
		f[i + 1] = k;
	}
	cout << 2 * n - f[2 * n + 1] << endl;
}


Measured memory_bytes: 256
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  ll n;
  std::cin >> n;
  std::vector<int> v={0}; 

  for(int i=1; i<=n; i++){
    int m; std::cin >> m;
    v.push_back(m);
  }
  v.push_back(0);
  int sum=0;
  for(int i=0; i<=n; i++){
    sum+=abs(v[i]-v[i+1]);
  }
    for(int i=1; i<=n; i++){
      int ans=sum+abs(v[i-1]-v[i+1])-abs(v[i-1]-v[i])-abs(v[i]-v[i+1]);
      std::cout << ans << '\n';
    }
  
  
  return 0;
}

Measured memory_bytes: 1784
#include <iostream>
#include <string>
#include <algorithm>





using namespace std;

char table[][2] = {{'i','i'},
		   {'w','w'},
		   {'(',')'},
		   {')','('},
		   {'{','}'},
		   {'}','{'},
		   {'[',']'},
		   {']','['}};

int memo[15][15];
string str;

char oppose(char c){
  for(int i=0; i<8; i++)
    if(c==table[i][0])
      return table[i][1];
  return 0;
}

int solve(int from,int to){
  if(str[from]=='i' || str[to]=='i')
    return 3;

  if(memo[from][to]!=-1){
    return memo[from][to];
  }else{
    int ans=3;
    for(int f=from; str[f]!='i'; f++){
      char op=oppose(str[f]);

      for(int t=to; str[t]!='i'; t--){
	if(str[t]==op){
	  ans = max(ans,2+solve(f+1,t-1));
	}
      }
    }
    memo[from][to] = ans;
    return ans;
  }
}

int main(){
  for(int i=0; i<15; i++) for(int j=0; j<15; j++) memo[i][j] = -1;

  cin >> str;
  cout << solve(0,str.size()-1) << endl;
}

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

int H;

void maxHeapify(int *A, int i);

int main(int argc, char *argv[])
{
  int i;
  int *A;

  scanf("%d", &H);
  A = (int *)malloc(sizeof(int) * (H + 1));
  for (i = 1; i <= H; i++) scanf("%d", &A[i]);

  for (i = H / 2; i > 0; i--) maxHeapify(A, i);

  for (i = 1; i <= H; i++) printf(" %d", A[i]);
  printf("\n");

  return 0;
}

void maxHeapify(int *A, int i)
{
  int l, r;
  int largest;
  int tmp;

  l = 2 * i;
  r = 2 * i + 1;

  if (l <= H && A[l] > A[i]) largest = l;
  else largest = i;
  if (r <= H && A[r] > A[largest]) largest = r;

  if (largest != i) {
    tmp = A[largest];
    A[largest] = A[i];
    A[i] = tmp;
    maxHeapify(A, largest);
  }
}

Measured memory_bytes: 2556
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=10000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

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


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

using namespace std;

const int INF = 1e9;

bool flag[105];

int main() {
	int x, n;
	scanf("%d%d", &x, &n);
	
	for (int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		flag[x] = 1;
	}
	
	int v = INF;
	int res = -1;
	
	for (int i = 0; i <= 101; i++) {
		if (flag[i]) continue;
		if (abs(x - i) < v) {
			v = abs(x - i);
			res = i;
		}
	}
	
	printf("%d\n", res);
}


Measured memory_bytes: 3828
//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 <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
#define EPS (1e-7)
#define DEF (1e+9 + 7)

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
typedef vector<int> VI;


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





int main() {
	int a, b;
	cin >> a >> b;

	int sum = a + b;
	int sub = a - b;
	int mul = a*b;

	int m = max(sum, sub);
	m = max(m, mul);

	ANS(m);
	return 0;
}



Measured memory_bytes: 256
from bisect import bisect_right

n, m, k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
cnt = 0
a_cum = [0] * (n + 1)
b_cum = [0] * (m + 1)

for i in range(n):
    a_cum[i+1] = a_cum[i] + a[i]
for i in range(m):
    b_cum[i+1] = b_cum[i] + b[i]

for i in range(n+1):
    a_cnt = i
    rest = k - a_cum[i]
    if rest < 0:
        break
    b_cnt = bisect_right(b_cum,rest) - 1    
    cnt = max(cnt, a_cnt + b_cnt)

print(cnt)

Measured memory_bytes: 47516
n=int(input())
 
def make_divisors(n):
    divisors = []
    for i in range(int(n**0.5)+1, 0, -1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
            return divisors
 
    # divisors.sort()
    return divisors
 
 
k = make_divisors(n)
if len(k) == 2:
    print(sum(k)-2)
else:
    print(k.pop()*2-2)

Measured memory_bytes: 3060
<?php
$s[] = 0;
$count = 1;
fscanf(STDIN, "%d %d", $n, $x);
$l = explode(" ", trim(fgets(STDIN)));
for ($i = 1; $i <= $n; $i++) {
  $s[$i] = $s[$i-1] + $l[$i-1];
  if ($s[$i] <= $x) {
    $count++;
  }
}
echo $count;

Measured memory_bytes: 4728
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,k,n) for(int i=k;i<n;i++)
int main (){
    int n,a,b;
    cin >> n >> a >> b;
    int d = abs(a-b);
    if(d%2==1){
        cout << "Borys" << endl;
    }else{
        cout << "Alice" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int N;
    string S;
    cin >> N >> S;
    int left = 0;
    while (left < N) {
        if (S[left] == '#') break;
        ++left;
    }
    int right = N - 1;
    while (right >= 0) {
        if (S[right] == '.') break;
        --right;
    }
    int white = 0;
    FOR(i, left, right + 1) {
        white += (S[i] == '.');
    }
    int i = left;
    int res = white;
    int black = 0;
    while (i < right + 1) {
        while (i < right + 1 && S[i] == '#') {
            ++black;
            ++i;
        }
        while (i < right + 1 && S[i] == '.') {
            --white;
            ++i;
        }
        res = min(res, black + white);
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3692
m, n, k = gets.chomp.split.map(&:to_i)

MOD = 1000000007

def fact(n)
  (1..n).inject(1){ |ans,x| ans*x % MOD }
end

def pow(n,k)
  ans = 1
  while k > 0
    ans = ans*n % MOD if k.odd?
    n = n*n % MOD
    k >>= 1
  end
  ans
end

def comb(n,k)
  fact(n) * pow(fact(n-k),MOD-2) % MOD * pow(fact(k),MOD-2) % MOD
end

puts((m**2 * (n**3 - n) + n**2 * (m**3 - m)) * comb(m*n-2,k-2) / 6 % MOD)

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

count = 0

# table2jou = []
# for mi in range(m + 1):
#     table2jou.append(pow(mi, 2))

# tablef = []
# for mi in range(m + 1):
#     # tablef.append(table2jou[mi] % m)
#     tablef.append(pow(mi, 2, m))

is_used = [0] * (m + 1)

count = x
pre_an = x
his = [x]
for ni in range(2, n + 1):
    # an = tablef[pre_an]
    an = pow(pre_an, 2, m)
    if is_used[an] == 1:
        leftnum = n - ni + 1
        start = his.index(an)
        end = leftnum % (len(his) - start) + start
        loopnum = leftnum // (len(his) - start)
        count = count + sum(his[start: end])
        count = count + sum(his[start:]) * loopnum
        break
    his.append(an)
    is_used[an] = 1
    count = count + an
    pre_an = an

print(count)


Measured memory_bytes: 12144
def main():
    a = list(map(int, input().split()))
    if a[0] == max(a):
        print((a[0] * 10 + a[1] + a[2]))
    elif a[1] == max(a):
        print((a[1] * 10 + a[0] + a[2]))
    else:
        print((a[2] * 10 + a[1] + a[0]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
Min_Num = -100
Max_Num = +100

list_size = gets.to_i
list = gets.split(/\s+/).map{ |str| str.to_i }
min_cost = nil
Min_Num.upto(Max_Num) do |candidate|
  cost = 0
  list_size.times{ |i| cost += (candidate - list[i]) ** 2 }
  min_cost = cost if min_cost == nil || cost <  min_cost
end
puts min_cost


Measured memory_bytes: 1788
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { 1, 0, -1, 0 }; const int dy[] = { 0, 1, 0, -1 };

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n) { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x) { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};
int h, w, n;
bool del(vector<string>& vs) {
	bool changed = false;
	vector<string> b(h);
	b = vs;
	REP(i, h) {
		REP(j, w) {
			REP(k, 2) {
				if (vs[i][j] != '.'){
					int cnt = 1;
					while (0 <= i + dy[k] * cnt&&i + dy[k] * cnt < h && 0 <= j + dx[k] * cnt&&j + dx[k] * cnt < w&&vs[i][j] == vs[i + dy[k] * cnt][j + dx[k] * cnt]){
						cnt++;
					}
					if (cnt >= n){
						REP(l, cnt){
							b[i + dy[k] * l][j + dx[k] * l] = '.';
						}
						changed = true;
					}
				}
			}
		}
	}
	if (changed)
		vs = b;
	return changed;
}
void fall(vector<string>& vs) {
	REP(k, h)
		for (int i = h - 1; i > 0; i--) {
			REP(j, w)
				if (vs[i][j] == '.'&&'A' <= vs[i - 1][j] && vs[i - 1][j] <= 'Z') {
					vs[i][j] = vs[i - 1][j];
					vs[i - 1][j] = '.';
				}
		}
}
int main() {

	cin >> h >> w >> n;
	vector<string> vvc(h);
	string ans = "NO";
	REP(i, h)
		cin >> vvc[i];
	REP(i, h)
		REP(j, w)
		REP(k, 1)
		if (
			0 <= i + dy[k] && i + dy[k] < h &&
			0 <= j + dx[k] && j + dx[k] < w) {
			vector<string> vvc2 = vvc;
			swap(vvc2[i][j], vvc2[i + dy[k]][j + dx[k]]);
			fall(vvc2);
			while (del(vvc2)) {
				fall(vvc2);
			}

			REP(m, h)
				REP(l, w){
				if ('A' <= vvc2[m][l] && vvc2[m][l] <= 'Z')
					goto RE;
			}

			ans = "YES";
			i = h; j = w; k = 2;
		RE:
			continue;
		}
	cout << ans << endl;
}

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

using namespace std;

using int64 = long long;

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

  string s;
  cin >> s;
  vector<char> v;
  for (char c : s) {
    v.push_back(c);
    if (v.size() >= 2 && v[v.size() - 2] == 'S' && v[v.size() - 1] == 'T') {
      v.pop_back();
      v.pop_back();
    }
  }
  cout << v.size() << endl;
}


Measured memory_bytes: 788
#include <stdio.h>
int main(void){
    // Your code here!
    int H,W;
    
    while(1){
    
        scanf("%d %d",&H,&W);
        if(H==0&&W==0){
            break;
        }
        
        for(int i=0;i<H;i++){
            
            for(int j=0;j<W;j++){
                if(i==0||i==H-1||j==0||j==W-1){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        
        putchar('\n');
        
    }
}



Measured memory_bytes: 2140
#include<iostream>
#include<math.h>
#include <algorithm>
#include<float.h>
#include <limits>
#include <vector> 
#include <numeric>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define ll long long

using namespace::std;

int jo(ll int jxo, ll int jyo){
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){
  return (toxbig-0x20);
}
char tolow(char toxlow){
  return (toxlow+0x20);
}
  


int main(){
  int N;
  cin>>N;
  if((N/10==9)||(N%10)==9) cout<<"Yes";
  else cout<<"No";
  
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


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

int a[4][4];
bool ch[4][4];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) cin >> a[i][j];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int A;
		cin >> A;
		for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) if(a[i][j] == A) ch[i][j] = 1;
	}
	for (int i = 0; i < 3; i++) {
		int cnt = 0;
		for (int j = 0; j < 3; j++) cnt += ch[i][j];
		if(cnt == 3) return cout << "Yes", 0;
	}
	for (int i = 0; i < 3; i++) {
		int cnt = 0;
		for (int j = 0; j < 3; j++) cnt += ch[j][i];
		if(cnt == 3) return cout << "Yes", 0;
	}
	int cnt = 0;
	for (int i = 0; i < 3; i++) {
		cnt += ch[i][i];
	}
	if(cnt == 3) return cout << "Yes", 0;
	cnt = 0;
	for (int i = 0; i < n; i++) cnt += ch[2 - i][i];
	if(cnt == 3) return cout << "Yes", 0;
	cout << "No";
	return 0;
}

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

const int mod = 1000000007;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main()
{
  int n;
  cin >> n;
  int z = 0;
  map<pair<ll, ll>, pair<int, int>> mp;
  for (int i = 0; i < n; i++)
  {
    ll a, b, gcd;
    cin >> a >> b;
    gcd = __gcd(a, b);
    if (gcd == 0)
    {
      z++;
    }
    else
    {
      a /= gcd;
      b /= gcd;
      if (b < 0)
      {
        a *= -1;
        b *= -1;
      }
      if (a <= 0)
      {
        mp[{b, -a}].second++;
      }
      else
      {
        mp[{a, b}].first++;
      }
    }
  }

  mint ans = 1;
  for (auto p : mp)
  {
    int s = p.second.first;
    int t = p.second.second;
    mint now = 1;
    now += mint(2).pow(s) - 1;
    now += mint(2).pow(t) - 1;
    ans *= now;
  }
  ans -= 1;
  ans += z;
  cout << ans << endl;
}

Measured memory_bytes: 15972