akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

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

#pragma region mod
const int p = 998244353; //10^9 + 7
struct mint
{
    ll x;
    mint(ll xx = 0) : x(xx % p) {}
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= p)
            x -= p;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += p - a.x) >= p)
            x -= p;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= p;
        return *this;
    }

    mint operator+(const mint a) const
    {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const
    {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const
    {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const
    {
        mint r = 1;
        mint a = *this;
        while (true)
        {
            if (t & 1)
            {
                r *= a;
            }
            t >>= 1;
            if (t == 0)
                break;
            a *= a;
        }

        return r;
    }

    mint inv() const
    {
        return pow(p - 2);
    }

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

struct comb
{
    vector<mint> fact, invs;
    comb(int n) : fact(n + 1), invs(n + 1)
    {
        assert(n < p);

        fact[0] = 1;
        for (int i = 1; i <= n; ++i)
            fact[i] = fact[i - 1] * i;

        invs[n] = fact[n].inv();
        for (int i = n; i >= 1; --i)
            invs[i - 1] = invs[i] * i;
    }
    mint operator()(int n, int k)
    {
        if (k < 0 || k > n)
            return 0;
        return fact[n] * invs[n - k] * invs[k];
    }
};
#pragma endregion

int main()
{
    mint n, m, k;
    cin >> n >> m >> k;
    mint ans = 0;
    comb ncr(n.x);
    rep(i, k.x + 1)
    {
        
        ans += m * (m - 1).pow(n.x - 1 - i) * ncr(n.x - 1, i);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6428
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=1e5;
typedef int fuko[yuzu|10];

int main(){
int i,j,a=read(),b=read();
write(max(max(a+b,a-b),a*b));
}

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

using namespace std;
typedef long long int ll;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

const int INF = 7368791;

int main() {
  while (true) {
    int M, N; scanf("%d %d", &M, &N);
    if (N == 0 and M == 0) break;
    vector<bool> P(INF + 1, false);

    for (int i = M, cnt = 0; ; i++) {
      if (not P[i]) {
        if (cnt == N) {
          printf("%d\n", i);
          break;
        }
        for (int j = i; j <= INF; j += i) P[j] = 1;
        cnt++;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 4048
#include <stdio.h>

int a[4][13];
int cnt=0;
int i,j;
int main(){
  for(i=0; i<4;i++){
    for(j=0; j<13;j++){
      a[i][j]=0;
    }
  }
  scanf("%d" ,&cnt);

  for(i=0; i<cnt; i++){
    char c;
    int k;
    scanf(" %c %d" ,&c,&k);
    switch(c){
    case 'S':
      a[0][k-1]=1;
      break;
    case 'H':
      a[1][k-1]=1;
      break;
    case 'C':
      a[2][k-1]=1;
      break;
    case'D':
      a[3][k-1]=1;
      break;
    }
  }
  for(i=0;i<4;i++){
    for(j=0;j<13;j++){
      if(a[i][j]==0){
	int jj=j+1;
	switch(i){
	case 0:
	printf("S %d" ,jj);
	break;
	case 1:
	  printf("H %d",jj);
	break;
	case 2:
	  printf("C %d" ,jj);
	  break;
	case 3:
	  printf ("D %d" ,jj);
	  break;
	}
	printf("\n");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=1<<18,INF=1<<30;

int main(){
    
    int A,B,C,D,P;cin>>A>>B>>C>>D>>P;
    cout<<min(A*P,B+(P<=C ? 0 : (P-C)*D))<<endl;
}



Measured memory_bytes: 3100
N=int(input())
Primes=[2]
flag=0
for i in range(2,27778):
  for p in Primes:
    if i%p==0:
      flag=1
      break
    elif p**2>i:
      break
  if flag==0:
    Primes.append(i)
  flag=0
n=0
ans=[]
for p in Primes:
  if p%5==1:
    ans.append(str(p))
    n+=1
  if n>=N:
    break
print(" ".join(ans))
    
  

Measured memory_bytes: 39664
from sys import stdin

N = stdin.readline().rstrip().split()
N = int(N[0])

int_list = list(map(int, stdin.readline().rstrip().split()))
cnt_list = [0] * N

for i in int_list:
    cnt_list[i-1] += 1

ret_list = [0] * N

# これはO(N)でいける

tmp_ans = 0
for i in range(N):
    if cnt_list[i] > 1:
        tmp_ans += cnt_list[i]*(cnt_list[i]-1) // 2


for i in range(N):
    if cnt_list[i] < 1:
        tmp_ret = 0
    else:
        tmp_ret = tmp_ans - cnt_list[i]*(cnt_list[i]-1) // 2 + (cnt_list[i]-1)*(cnt_list[i]-2) // 2
    ret_list[i] = tmp_ret

for i in int_list:
    print(ret_list[i-1])

Measured memory_bytes: 26140
import numpy as np
import math

a, b, x = map(int, input().split())

h = x / (a * a)

h2 = (b - h) * 2

if h2 <= b:
    deg = math.degrees(math.atan(h2 / a))
else:
    h3 = ((x / a) / b) * 2
    deg = math.degrees(math.atan(b / h3))

print(deg)


"""

"""

Measured memory_bytes: 12508
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

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

    vector<int> a(N);
    vector<int> frag(N, 0);

    rep2(i, 0, N){
        cin >> a.at(i);
    }

    int index = 0, num = 0;

    while(index != 1 && frag.at(index) != 1){
        frag.at(index) = 1;
        index = a.at(index) - 1;
        num++;
    }

    if(index == 1) cout << num << endl;

    if(frag.at(index) == 1) cout << -1 << endl;
}


Measured memory_bytes: 4056
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		int[]H = new int[N];
		string[] str2 = Console.ReadLine().Split();
		for(var i=0;i<N;i++){
			H[i] = int.Parse(str2[i]);
		}
		int[]A = new int[N];
		for(var i=0;i<M;i++){
			string[] str3 = Console.ReadLine().Split();
			int A1 = int.Parse(str3[0]);
			int B1 = int.Parse(str3[1]);
			if(H[A1-1]<=H[B1-1]){
				A[A1-1]++;
			}
			if(H[A1-1]>=H[B1-1]){
				A[B1-1]++;
			}
		}
		int ans = 0;
		for(var i=0;i<N;i++){
			if(A[i]==0){
				ans++;
			}
		}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 32456
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;

const int MAX = 1e3 + 1;

string s[MAX];
pii p[MAX][MAX];
set <pii> adj[MAX][MAX];
int m[MAX][MAX];
int d[4][2] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1} };
int h, w, cx, cy, dx, dy;

void build() {
	cin >> h >> w >> cx >> cy >> dx >> dy;
	for (int i = 0; i < h; i++)
		cin >> s[i];

	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			p[i][j] = { -1, -1 };
}

void dfs(int sx, int sy) {
	queue<pair<int, int>> q;
	q.push({ sx, sy });
	p[sx][sy] = { sx, sy };
	while (!q.empty()) {
		int nx = q.front().first, ny = q.front().second;
		q.pop();

		for (int i = 0; i < 4; i++) {
			int x = nx + d[i][0], y = ny + d[i][1];
			if (x >= 0 && x < h && y >= 0 && y < w && p[x][y].first == -1 && s[x][y] != '#')
				p[x][y] = { sx, sy }, q.push({ x,y });
		}
	}
}

void solve() {
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			if (s[i][j] == '.' && p[i][j].first == -1) dfs(i, j);

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '#') continue;

			for (int ii = -2; ii < 3; ii++) {
				for (int jj = -2; jj < 3; jj++) {
					if (i + ii >= 0 && i + ii < h && j + jj >= 0 && j + jj < w && s[i + ii][j + jj] != '#' && p[i][j] != p[i + ii][j + jj]) {
						adj[p[i][j].first][p[i][j].second].insert(p[i + ii][j + jj]);
						adj[p[i + ii][j + jj].first][p[i + ii][j + jj].second].insert(p[i][j]);
					}

				}
			}
		}
	}

	memset(m, -1, sizeof(m));

	queue<pii> q;
	q.push(p[cx - 1][cy - 1]);
	m[p[cx - 1][cy - 1].first][p[cx - 1][cy - 1].second] = 0;

	while (!q.empty()) {
		pii now = q.front();
		q.pop();

		for (pii next : adj[now.first][now.second]) {
			if (m[next.first][next.second] == -1) {
				m[next.first][next.second] = m[now.first][now.second] + 1;
				q.push(next);
			}
		}
	}

	printf("%d", m[p[dx - 1][dy - 1].first][p[dx - 1][dy - 1].second]);
}

int main() {
	cin.sync_with_stdio(0);
	build();
	solve();
	return 0;
}

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

int main() {
  int N,M;
  cin>>N>>M;
  dsu d(N);
  int a,b;
  for(int i=0;i<M;i++){
    cin>>a>>b;
    d.merge(a-1,b-1);
  }
  cout<<d.groups().size() - 1<<endl;
  return 0;
}


Measured memory_bytes: 8840
# coding: utf-8

def main():
    S = list(input())

    for i in range(8):
        s = S[0]
        tmp = int(s)

        for j in range(3, 0, -1):
            t = S[4-j]
            if i & 1 << j - 1:
                tmp += int(t)
                s += '+' + t
            else:
                tmp -= int(t)
                s += '-' + t

        if tmp == 7:
            print(s, '=7', sep='')
            break

if __name__ == "__main__":
    main()


Measured memory_bytes: 9136
def mod_rep_pow(a, n, mod=(10 ** 9 + 7)):
    res = 1
    while 0 < n:
        if n & 1:
            res = (res * a) % mod
            n -= 1
        else:
            a = (a ** 2) % mod
            n //= 2
    return (res % mod)


def mod_inverse(a, mod=(10 ** 9 + 7)):
    return mod_rep_pow(a, (mod - 2))


def mod_comb(facts, facts_inverse, n, k, mod=(10 ** 9 + 7)):
    return (facts[n] * facts_inverse[k] * facts_inverse[n - k])


n = int(input().strip())
a = list(map(int, input().split()))
not_unique = sum(a) - sum([i for i in range(1, n + 1)])
b = []
for i in range(n + 1):
    if a[i] == not_unique:
        b.append(i)
x = n - (b[1] - b[0])
mod = 10 ** 9 + 7
facts = [1] * (n + 2)
for i in range(0, n + 1):
    facts[i + 1] = (facts[i] * (i + 1) % mod)

facts_inverse = [1] * (n + 2)
facts_inverse[n + 1] = mod_inverse(facts[n + 1])
for i in range(n + 1, 0, -1):
    facts_inverse[i - 1] = (facts_inverse[i] * (i)) % mod

for i in range(1, n + 2):
    if x < (i - 1):
        print(mod_comb(facts, facts_inverse, (n + 1), i) % mod)
    else:
        print((mod_comb(facts, facts_inverse, (n + 1), i) - (mod_comb(facts, facts_inverse, x, (i - 1)))) % mod)


Measured memory_bytes: 58220
#include <stdio.h>
long long a, b, c, x, y;
int main() {
	scanf("%lld%lld%lld", &a, &b, &c);
	if (c - a - b <= 0) {
		printf("No\n");
		return 0;
	}
	x = 4 * a * b;
	y = c - a - b;
	y = y * y;
	if (x < y)printf("Yes\n");
	else printf("No\n");
}

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

int main()
{
    char x,y;
    cin >> x >> y;
    if (x < y)
        cout << "<" << endl;
    else if (x > y)
        cout << ">" << endl;
    else
        cout << "=" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,l,r) for(int i=l;i<=r;i++)
int main()
{   //freopen("input.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int h[n+1];
    int dp[n+1];
    for(int i=1;i<=n;i++)cin>>h[i];

        h[0]=h[1];
    dp[0]=0;
    dp[1]=0;
    for(int i=2;i<=n;i++)
    {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));

    }
   cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
  char s[4];
  scanf("%3s", s);
  int n = 0;
  for (int i = 0; i < 3; i++) {
    n += (s[i] == 'R') << i;
  }
  int ans[] = {0, 1, 1, 2, 1, 1, 2, 3};
  printf("%d\n", ans[n]);
}


Measured memory_bytes: 1720
//    _____ _     _                _           _     _ _     _     
//    \_   \ |_  (_)___  __      _| |__   __ _| |_  (_) |_  (_)___ 
//     / /\/ __| | / __| \ \ /\ / / '_ \ / _` | __| | | __| | / __|
//  /\/ /_ | |_  | \__ \  \ V  V /| | | | (_| | |_  | | |_  | \__ \
//  \____/  \__| |_|___/   \_/\_/ |_| |_|\__,_|\__| |_|\__| |_|___/
//                                                                 
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int sz=1e6+9;
int k,n;
int a[sz];

int add(int a,int b){
	return ((a%k+b%k)%k+k)%k;
}

int main(){
	cin>>k>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}	
	int ans=add(a[0],-a[n-1]);
	for(int i=0;i<n-1;i++){
		int tmp=add(a[i+1],-a[i]);
		ans=max(ans,tmp);
	}
	cout<<k-ans;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

char ss[101];

int main()
{
  int n;
  while (scanf("%d", &n) != EOF)
  {
    set<string> items;
    for (int i = 0; i < n; i++)
    {
      scanf(" %s", ss);
      items.insert(string(ss));
    }
    printf("%d\n", (int)items.size());
  }
  return 0;
}

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

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

int main() {
    string S;
    cin >> S;
    for(int i = 0; i < S.length(); i++) {
        if(i % 2 == 1) {
            if(S[i] == 'R') {
                cout << "No" << endl;
                return 0;
            }
        } else {
            if(S[i] == 'L') {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
//https://atcoder.jp/contests/abc122/tasks/abc122_c
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main(int argc, char const *argv[]) {
  int N,Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  int t[N+1];
  t[0] = 0;
  for(int i=0; i<N; i++){
    t[i+1] = t[i] + ((S[i] == 'A'&&S[i+1]=='C') ? 1:0);
  }

  for (int i=0; i<Q; i++){
    int l,r;
    cin >> l >> r;
    cout << t[r-1]-t[l-1] << endl;
  }

  return 0;
}



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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n;
  std::cin >> n;

  std::map<std::string, int64_t> s;

  for (int64_t i = 0; i < n; i++) {
    std::string ss;
    std::cin >> ss;
    if (s.count(ss) != 0) {
      s[ss]++;
    } else {
      s[ss] = 1;
    }
  }

  int64_t max_n = 0;

  for (const auto &v : s) {
    max_n = std::max(max_n, v.second);
  }

  for (const auto &v : s) {
    if (v.second == max_n) {
      std::cout << v.first << std::endl;
    }
  }

  return 0;
}

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

const int MAXN = 2.1E5;
int64 V1[MAXN];
int64 V2[MAXN];
int64 V3[MAXN];
int64 O[MAXN];
int A, B, C, X, Y, t1 = 1, t2 = 1;
int64 ans;
int gg = 1;
int64 tmp;
int top;

bool cmp(int x, int y) { return x > y; }

inline void solve(int last)
{
	while (last)
	{
		--last;
		if (t1 - 1 == X)
		{
			tmp += V2[t2];
			O[++top] = V2[t2++];
			continue;
		}
		if (t2 - 1 == Y)
		{
			tmp += V1[t1];
			O[++top] = V1[t1++];
			continue;
		}
		if (V1[t1] > V2[t2])
		{
			tmp += V1[t1];
			O[++top] = V1[t1++];
		}
		else
			tmp += V2[t2],
			O[++top] = V2[t2++];
	}
}

int main(void)
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	cin >> X >> Y >> A >> B >> C;
	
	for (int i = 1;i <= A; ++i)
		cin >> V1[i];
	for (int i = 1;i <= B; ++i)
		cin >> V2[i];
	for (int i = 1;i <= C; ++i)
		cin >> V3[i];
	sort(V1 + 1, V1 + 1 + A, cmp);
	sort(V2 + 1, V2 + 1 + B, cmp);
	sort(V3 + 1, V3 + 1 + C, cmp);
	
	solve(X + Y);
	ans = tmp;
	for (int i = 1;i <= X + Y; ++i)
	{
		if (i > C)
			break;
		tmp += V3[i];
		tmp -= O[top--];
		ans = max(ans, tmp);
	}
	
	cout << ans << '\n';	
	return 0;
}

Measured memory_bytes: 6144
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        //3つの配列を宣言
        int[] a = new int[3];
        //3つの配列に値を代入する
        for(int i = 0; i < 3; i++) a[i] = sc.nextInt();
        //Arrays.sortを用いて並べ替え
        Arrays.sort(a);
        //結果を表示させる
        System.out.println(a[0] + " " + a[1] + " " + a[2]);
    }
}


Measured memory_bytes: 26196
def gcd(x,y)
  if x<y
    x,y = y,x
  end
  x = x%y
  if x==0
    printf("%d\n",y)
  else
    gcd(y,x)
  end
end

x,y = gets.chomp.split(" ").map{|z| z.to_i}
gcd(x,y)


Measured memory_bytes: 6872
#include<stdio.h>
#define N 501
static const int INFTY = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
int n, M[N][N];
int color[N], p[N], y[N], tt;
void dfs_visit(int u){
  int v;
  color[u] = GRAY;
  tt++;
  p[u] = tt;
  for ( v = 0; v < n; v++ ){
    if ( M[u][v] == 0 ) continue;
    if ( color[v] == WHITE ){
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  y[u] = ++tt;
}
void dfs(){
  int i, k;
  for ( i = 0; i < n; i++ ) color[i] = WHITE;
  tt = 0;
  for ( k = 0; k < n; k++ ){
    if ( color[k] == WHITE ) dfs_visit(k);
  }
  for ( i = 0; i < n; i++ ){
    printf("%d %d %d\n", i+1, p[i], y[i]);
  }
}
int main(){
  int u, k, v; 
  int i, e;
  scanf("%d", &n);
  for ( i = 0; i <n; i++ ){
    for ( e = 0; e <n; e++ ) M[i][e] = 0;
  } 
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    u--;
    for ( e = 0; e < k; e++ ){
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }  
  dfs();
  return 0;
}



Measured memory_bytes: 2128
import java.util.Scanner;

public class Main {

    private static Scanner sc;

    public Main() {
    }

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

    private void solve() {
        int n = sc.nextInt();
        int[] R = new int[n];

        for (int i = 0; i < n; i++) {
            R[i] = sc.nextInt();
        }

        int ans = Integer.MIN_VALUE;
        int min = R[0];
        for (int i = 1; i < n; i++) {
            ans = Math.max(ans, R[i] - min);
            min = Math.min(min, R[i]);
        }

        System.out.println(ans);
    }
}

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

int main() {
    int n; scanf("%d", &n);
    int a[n]; for (int i = 0; i < n; ++i) scanf("%d", a + i);
    int num_query; scanf("%d", &num_query);
    int begin, end;
    for (int i = 0; i < num_query; ++i) {
        scanf("%d%d", &begin, &end);
        reverse(a + begin, a + end);
    }
    
    printf("%d", a[0]);
    for (int a_i = 1; a_i < n; ++a_i) printf(" %d", a[a_i]);
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 3232
#include <iostream>

using namespace std;

int f(int n){
	static int dp[3000];
	for(int i=0;i<=n;i++){
	if(i==0|| i==1) dp[i] = 1;
	else dp[i] = dp[i-1] + dp[i-2];
	}
	return dp[n];
}
int main(){
	int n;
	cin>>n;
	cout<<f(n)<<endl;
}



Measured memory_bytes: 3108
#include<stdio.h>
int main(){
  int n,k,q,a[100010],i,b;
  scanf("%d %d %d\n",&n,&k,&q);
  for(i=1;i<=n;i++){
    a[i]=0;
  }
  for(i=0;i<q;i++){
    scanf("%d\n",&b);
    a[b]++;
  }
  b=q-k;
  for(i=1;i<=n;i++){
    if(a[i]>b){
      printf("Yes\n");
    }
    else{
      printf("No\n");
    }
  }
  return 0;
}

Measured memory_bytes: 896
N = int(input())
S = list( input("") )
A =  set(S)
count = 0
for i in A:
    b = S.index(i) + 1
    B = set(S[b:])
    for j in B:
        c = S[b:].index(j) + 1
        C = set(S[b:][c:])
        count += len(C)
print(count)

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

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

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n;
	cin >> n;
	ll primeFactors[n+1];
	FOR(i,0,n+1)primeFactors[i] = 0;
	for(int i = 2; i <= n; i++){
		int icpy = i;
		int factor = 2;
		while(icpy > 1){
			if(icpy % factor == 0){
				icpy /= factor;
				primeFactors[factor]++;
			}else{
				factor++;
			}
		}
	}
	ll ans = 1;
	FOR(i,2,n+1)
		ans = ans * (primeFactors[i] + 1) % MOD;
	ANS(ans);
	return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "1 6" ].parse.expand.solve == 2 );
	assert( [ "12345 678901" ].parse.expand.solve == 175897 );

	assert( [ "1 1" ].parse.expand.solve == 0 );		// 追加ケース
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	return tuple( nm[ 0 ], nm[ 1 ] );
}

auto solve( long n, long m )
{
	if( m <= n * 2 ) return m / 2;						// Sピースのほうが余る場合
	else             return n + ( m - n * 2 ) / 4;		// Cピースのほうが余る場合（余ったCピース4つで1組作れる）
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1e9+7;

ll dp[200010];
vector<int> p[200010];

int main(){
  int n;
  cin >> n;
  vector<int> c(n);
  rep(i,n) cin >> c[i];

  // p[i] := (c[j] = i となるｊの集まり)
  rep(i,n) p[c[i]].push_back(i);
  
  //DP
  dp[0] = 1;
  for (int i = 1; i <= n; i++) {
    // 操作しない
    (dp[i] += dp[i-1]) %= mod;

    // 操作する
    int color = c[i-1];
    int itr = lower_bound(p[color].begin(), p[color].end(),i-1) - p[color].begin();

    if (itr > 0) {
      int j = p[color][itr-1]; //c[j] = c[i] となるi
      if((i-1) - j > 1) (dp[i] += dp[j+1]) %= mod;
    }
  }
  cout << dp[n] << endl;
  return 0;
}

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

int main() {
  int a, b, k;
  std::cin >> a >> b >> k;

  std::vector<int> common_divisor;
  for (int i = 1; i <= std::max(a, b); ++i) {
    if (a % i == 0 && b % i == 0) {
      common_divisor.push_back(i);
    }
  }
  std::reverse(common_divisor.begin(), common_divisor.end());
  std::cout << common_divisor.at(k - 1) << std::endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
a = [0] * m
b = [0] * m
maxx = [0] * n
for i in range(m):
    a[i], b[i] = map(int, input().split())
    maxx[a[i] - 1] = max(h[b[i] - 1], maxx[a[i] - 1])
    maxx[b[i] - 1] = max(h[a[i] - 1], maxx[b[i] - 1])
ans = 0
for i in range(n):
    if h[i] > maxx[i]:
        ans += 1

print (ans)

Measured memory_bytes: 21744
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
bool used[410][410];
string ma[410];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int h,w;lint a,b;
void dfs(int x,int y){
	if(used[x][y]) return;
	used[x][y]=true;
	if(ma[x][y]=='.') a++;else b++;
	rep(i,4){
		int nx=x+dx[i],ny=y+dy[i];
		if(nx<0 || ny<0 || nx>=h || ny>=w) continue;
		if(ma[x][y]==ma[nx][ny]) continue;
		dfs(nx,ny);
	}
}
int main()
{
	cin>>h>>w;memset(used,false,sizeof(used));
	lint out=0;
	rep(i,h) cin>>ma[i];
	rep(i,h) rep(j,w){
		if(used[i][j]) continue;
		a=b=0;
		dfs(i,j);
		out+=a*b;
	}
	cout<<out<<endl;
}

Measured memory_bytes: 18176
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
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;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	long long int  x;
	cin >> x;
	long long int sum = 100;
	long long int yer = 0;
	while (sum < x) {
		sum = sum + sum / 100;
		yer++;
	}
	cout << yer;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;


class Program
{

    static void Main(string[] args)
    {
        int x = crI();
        if (x == 0) Console.WriteLine(1);
        else Console.WriteLine(0);


    }

    





    //入力受け取り用
    static string crS() { return Console.ReadLine(); }
    static int crI() { return int.Parse(Console.ReadLine()); }
    static int[] arrInt() { return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray(); }
    static long[] arrLong() { return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray(); }
    static string[] arrStr() { return Console.ReadLine().Split(' ').ToArray(); }
    static List<int[]> mapInt(int h)
    {
        List<int[]> mapInt = new List<int[]>();
        for (int i = 0; i < h; i++)
        {
            mapInt.Add(arrInt());
        }
        return mapInt;
    }

    static List<long[]> mapLong(long h)
    {
        List<long[]> mapLong = new List<long[]>();
        for (int i = 0; i < h; i++)
        {
            mapLong.Add(arrLong());
        }
        return mapLong;
    }


    static List<string[]> mapStr(int h)
    {
        List<string[]> mapStr = new List<string[]>();
        for (int i = 0; i < h; i++)
        {
            mapStr.Add(arrStr());
        }
        return mapStr;
    }

    static List<char[]> mapChar(int h)
    {
        List<char[]> mapChar = new List<char[]>();
        for (int i = 0; i < h; i++)
        {
            string s = crS();
            mapChar.Add(s.ToCharArray());
        }
        return mapChar;
    }

    static List<char[]> mapCharCopy(List<char[]> map)
    {
        List<char[]> copyMap = new List<char[]>();
        foreach (var arr in map)
        {
            List<char> list = new List<char>();
            foreach (var ele in arr)
            {
                list.Add(ele);
            }
            copyMap.Add(list.ToArray());
        }
        return copyMap;
    }

    //二次元配列出力用
    static void output2DArray(int h , int w , int[,] map)
    {
        for (int i = 0; i < h; i++)
        {
            for (int j = 0; j < w; j++)
            {
                if (j == w - 1) Console.WriteLine(map[i, j]);
                else Console.Write(map[i, j] + " ");
            }
        }
    }
}

Measured memory_bytes: 27528
n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t=[input() for _ in range(m)]
d={a:0 for a in s+t}
for a in s:
    d[a] += 1
for a in t:
    d[a] -= 1
print(max(max(d.values()),0))

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
//#define int long long

signed main(){
    int k, x;
    cin >> k >> x;
    cout << x-k+1;
    reps(i,x-k+2,x+k-1){
        cout << " " << i;
    }
    cout << endl;
}

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

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

int main () {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  bool in = false;
  rep(i,n) {
    cin >> a[i];
    if(a[i] == k) in = true;
  }
  sort(a.begin(), a.end());

  int res = a[0];
  for(int i = 1; i < n; i++) {
    res = gcd(res, a[i]);
  }

  if(in || (a[n-1] > k && k % res == 0)) {
    printf("POSSIBLE\n");
  } else  {
    printf("IMPOSSIBLE\n");
  }
  return 0;
}


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

using namespace std;

void hawawa()
{
	int n, ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		long long num;
		cin >> num;
		while (!(num % 2)) {
			ans++;
			num /= 2;
		}
	}
	cout << ans << "\n";
}

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


Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a, b, h;
	cin >> a >> b >> h;
	cout << (a + b) * h / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    H, W = map(int, readline().split())
    f = ".X".index
    S = [list(map(f, readline().strip())) for i in range(H)]
    memo = {}
    def dfs(px, py, qx, qy):
        key = (px, py, qx, qy)
        if key in memo:
            return memo[key]
        res = set()
        for y in range(py, qy):
            for x in range(px, qx):
                if S[y][x]:
                    continue
                r1 = dfs(px, py, x, y)
                r2 = dfs(x+1, py, qx, y)
                r3 = dfs(px, y+1, x, qy)
                r4 = dfs(x+1, y+1, qx, qy)
                res.add(r1 ^ r2 ^ r3 ^ r4)
        k = 0
        while k in res:
            k += 1
        memo[key] = k
        return k
    if dfs(0, 0, W, H):
        write("First\n")
    else:
        write("Second\n")
solve()


Measured memory_bytes: 13016
/** Minimum Spanning Tree */

/* include */
#include <stdio.h>
#include <stdlib.h>
/* define */
#define MAX 10000
#define INFTY 10000000
#define WHITE 0
#define GRAY 1
#define BLACK 2
/* global */
int n, MATRIX[MAX][MAX]; //0??§??????????????????
/* prototype */
int prim();
void dijkstra();

int main() {
  int i, j, k, c, from, to;
  /* number of size */
  scanf("%d", &n);

  /* initialize */
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      MATRIX[i][j] = INFTY;
    }
  }
  
  /* ????????\??? */
  for(i=0;i<n;i++){
    /* k:????¬???°, c:?????? */
    scanf("%d %d", &from, &k);
    for(j=0;j<k;j++){ //????¬???°??????
      scanf("%d %d", &to, &c);
        MATRIX[from][to] = c; //??????????´?
    }
  }

  /* ??¢?´¢ */
  dijkstra();
  
  return 0;
}

void dijkstra(){
  int from, to, min, i, j, sum;
  int PATH[MAX], PARENT[MAX], VISIT[MAX]; //????°??????????, ?????????, ?¨??????¶???
  
  for(i=0;i<n;i++){
    PATH[i] = INFTY;
    VISIT[i] = WHITE; //visited
  }
  
  PATH[0] = 0;
  VISIT[0] = GRAY;
  while(1){
    min = INFTY;
    from = -1;
    for(i=0;i<n;i++){
      if(min>PATH[i] && VISIT[i]!=BLACK){
        from = i;
        min = PATH[i];
      }
    }
    /* ?????????????????? */
    if(from==-1) {
      break;
    }
    VISIT[from] = BLACK;
    for(to=0;to<n;to++){
      if(VISIT[to]!=BLACK && MATRIX[from][to] != INFTY){
        if(PATH[to]>PATH[from] + MATRIX[from][to]){
          PATH[to] = PATH[from] + MATRIX[from][to];
          VISIT[to] = GRAY;
        }
      }
    }
  }
  /* while end */
  
  for(i=0;i<n;i++){
    printf("%d ", i);
    if(PATH[i] == INFTY){
      printf("-1");
    }else{
      printf("%d", PATH[i]);
    }
    printf("\n");
  }
}


//int prim(){
//  int from, to, min, i, j, sum;
//  int PATH[MAX], PARENT[MAX], VISIT[MAX]; //????°??????????, ?????????, ?¨??????¶???
//  
//  /* create matrix */
//  for(i=0;i<n;i++){
//    PATH[i] = INFTY;
//    PARENT[i] = -1;
//    VISIT[i] = WHITE;
//  }
//  PATH[0] = 0;
//
//  /* ??????????¨???? */
//  while(1){
//    min = INFTY;
//    from = -1;
//    for(i=0;i<n;i++){
//      if(min>PATH[i] && VISIT[i]!=BLACK){
//        from = i;
//        min = PATH[i];
//      }
//    }
//    if(from==-1) {
//      break;
//    }
//    VISIT[from] = BLACK;
//    for(to=0;to<n;to++){
//      if(VISIT[to]!=BLACK && MATRIX[from][to]!=INFTY) {
//        if(PATH[to]>MATRIX[from][to]){
//          PATH[to] = MATRIX[from][to];
//          PARENT[to] = from;
//          VISIT[to] = GRAY;
//        }
//      }
//    }
//    sum = 0;
//    for(i=0;i<n;i++){
//      if(PARENT[i]!=-1){
//        sum += MATRIX[i][PARENT[i]];
//      }
//    }
//  }
//  return sum;
//}

Measured memory_bytes: 2892
#include <bits/stdc++.h>
#include <string.h>
#define ll long long
#define pb push_back
#define vi vector<int>
#define nl endl
#define tc    \
    ll t;     \
    cin >> t; \
    while (t--)
#define fastio                       \
    ios_base::sync_with_stdio(NULL); \
    cin.tie(NULL);                   \
    cout.tie(NULL);
using namespace std;
int main()
{
    fastio;
    int n,s=0;
    cin >> n;
    int c[n], v[n];
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
    }
     for (int i = 0; i < n; i++)
    {
        if(v[i]-c[i]>0) s+=v[i]-c[i];
    }
    cout<<s;
}

Measured memory_bytes: 3624
n = gets.to_i

inputs = []
ans = []
n.times do
  x, y, h = gets.split(" ").map(&:to_i)
  if h == 100
    ans << [x,y,h]
  end
  inputs << [x, y, h]
end

if !ans.empty?
  puts ans.join(" ")
  exit
end

first_input = inputs.select{|i| i[2] > 0}.first
(0..100).each do |x|
  (0..100).each do |y|
    h = (first_input[2] + (first_input[0] - x).abs + (first_input[1] - y).abs)
    if inputs.all?{|t| t[2] == [(h - (t[0] - x).abs - (t[1] - y).abs),0].max }
      puts "#{x} #{y} #{h}"
      exit
    end
  end
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define all(x) (x).begin(), (x).end()
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    vector<ll>arr(n+5,0);
    for(int i=1;i<=n;i++)
    {
        for(int j=i;j<=n;j+=i)
        {
            arr[j]++;
        }
    }
    ll sum=0;
    for(ll i=1;i<=n;i++)
    {
        sum+=(i*arr[i]);
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 81340
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100005
#define inf 0x3f3f3f3f
int a[maxn];
using namespace std;
int main()
   {
       int n,t;
       scanf("%d%d",&n,&t);
       for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);

        int maxx=0;
        int maxl=0;
        for(int i=n;i>=1;i--)
        {maxx=max(maxx,a[i]);
        maxl=max(maxl,maxx-a[i]);

        }

maxx=0;
int ans=0;

for(int i=n;i>=1;i--)
    {
        maxx=max(maxx,a[i]);
        if(maxx-a[i]==maxl)
           ans++;
   }
   printf("%d\n",ans);
   return 0;
   }



Measured memory_bytes: 640
def main():
    MOD = 10**9 + 7
    N = int(input())
    S = [input() for _ in range(2)]
    # pattern 0 | pattern 1
    #     X     |    XX
    #     X     |    YY
    # before | current
    #    0   |    0    -> 2
    #    0   |    1    -> 2
    #    1   |    0    -> 1
    #    1   |    1    -> 3
    before_pattern = 0 if S[0][0] == S[1][0] else 1
    ans = 3 if before_pattern == 0 else 3 * 2
    i = 1 if before_pattern == 0 else 2
    while i < N:
        pattern = 0 if S[0][i] == S[1][i] else 1
        if pattern == 0:
            if before_pattern == 0:
                ans *= 2
            i += 1
        else:
            if before_pattern == 0:
                ans *= 2
            else:
                ans *= 3
            i += 2
        before_pattern = pattern
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>

int main()
{
	long long n, i, j, pivot, d, s;
	scanf("%lld", &n);

	s = 0;
	for (i = 32; i >= 1; i --) {
		pivot = 0;
		for (j = 1; j < i; j ++) {
			pivot -= (long long)pow(-2, j) - (long long)pow(-1, j);
		}

		if (i % 2 == 0) {
			if (pivot >= n) {
				d = (pivot - n) % (long long)pow(2,i) >= (long long)pow(2,i-1) ? 1 : 0;
			} else {
				d = (n - (pivot + 1)) % (long long)pow(2,i) >= (long long)pow(2,i-1) ? 0 : 1;
			}
		} else {
			if (pivot <= n) {
				d = (n - pivot) % (long long)pow(2,i) >= (long long)pow(2,i-1) ? 1 : 0;
			} else {
				d = ((pivot - 1) - n) % (long long)pow(2,i) >= (long long)pow(2,i-1) ? 0 : 1;
			}
		}

		if (d == 1) {
			s = 1;
		}

		if (s == 1) {
			printf ("%d", d);
		}
	}
	if (s == 0) {
		printf ("0");
	}
	return 0;
}


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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long A, long long B){
    cout << A * B << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

vector<pair<int,double>> G[1004];
int cc[1004][3];
double d[1004];
bitset<1004> v;

int main(){
    int sx,sy,tx,ty; cin>>sx>>sy>>tx>>ty;
    int n; cin>>n;
    for(int i=1;i<=n;++i)cin>>cc[i][0]>>cc[i][1]>>cc[i][2];
    tie(cc[0][0],cc[0][1])=make_pair(sx,sy);
    tie(cc[n+1][0],cc[n+1][1])=make_pair(tx,ty);
    for(int i=0;i<=n+1;++i){
        for(int j=0;j<i;++j){
            double d=sqrt(pow(cc[i][0]-cc[j][0],2)+pow(cc[i][1]-cc[j][1],2));
            d-=cc[i][2]+cc[j][2]; if(d<0)d=0;
            G[i].emplace_back(j,d);
            G[j].emplace_back(i,d);
            // cout<<i<<" "<<j<<" "<<d<<endl;
        }
    }
    priority_queue<pair<double,int>,vector<pair<double,int>>,greater<pair<double,int>>> pq;
    for(int i=1;i<=n+1;++i)d[i]=1e12;
    pq.emplace(0,0);
    while(pq.size()){
        while(pq.size() && v[pq.top().second])pq.pop();
        if(pq.empty())break;
        int now=pq.top().second; pq.pop();
        v[now]=1;
        for(auto &p:G[now]){
            if(d[p.first]>d[now]+p.second+1e-10){
                d[p.first]=d[now]+p.second;
                pq.emplace(d[p.first],p.first);
            }
        }
    }
    cout<<fixed<<setprecision(12)<<d[n+1]<<endl;
}


Measured memory_bytes: 22640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


class Main{
	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String str=br.readLine();
			if(str.equals("0"))break;
			int t=0;
			for(int i=0;i<str.length();i++){
				t+=Character.getNumericValue(str.charAt(i));
			}System.out.println(t);
		}
		}}

Measured memory_bytes: 17024
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC pop_options
//#pragma GCC target("popcnt")
//#pragma GCC target("sse4")
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(),a.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i > -1; i--)
#define rer(i, x, n) for (int i = x; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef long double ld;















signed main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> a(n);
    for (int i = 0; i < n; i++) a[i] = s[i] - '0';
        vector<int> b(n - 1);
        for (int i = 0; i < n - 1; i++){
            b[i] = abs(a[i + 1] - a[i]);
        }
        bool fl1 = 1;
            for (int i = 0; i < n - 1; i++) if (b[i] == 1) fl1 = 0;
        if (fl1){
            for (int i = 0; i < n - 1; i++){
            if (b[i] == 2)
                b[i] = 1;
            }
            int sz = n - 1;
            while(true){
                int tr = 1;
                while(tr <= sz) tr *= 2;
                tr /= 2;
                vector<int> c(sz - tr + 1);
                if (tr == 1){
                    cout << b[0] * 2;
                    return 0;
                }
                int xo = 0;
                for (int i = 0; i < tr; i++) xo ^= b[i];
                for (int i = tr; i <= sz; i++){
                    c[i - tr] = xo;
                    if (i < sz)
                    xo ^= b[i - tr] ^ b[i];
                }
             //   for (auto x : c) cout << x << ' ';
            //    cout << endl;
                sz -= tr - 1;
                b = c;
            }
        }
        for (int i = 0; i < n - 1; i++){
            if (b[i] == 2)
                b[i] = 0;
        }
    int sz = n - 1;
    while(true){
        int tr = 1;
        while(tr <= sz) tr *= 2;
        tr /= 2;
        vector<int> c(sz - tr + 1);
        if (tr == 1){
            cout << b[0];
            return 0;
        }
        int xo = 0;
        for (int i = 0; i < tr; i++) xo ^= b[i];
        for (int i = tr; i <= sz; i++){
            c[i - tr] = xo;
            if (i < sz)
            xo ^= b[i - tr] ^ b[i];
        }
     //   for (auto x : c) cout << x << ' ';
    //    cout << endl;
        sz -= tr - 1;
        b = c;
    }


  return 0;
    vector<int> c(n);
    c = a;
    for (int j = 0; j < n - 1; j++){
        for (int i = 0; i < n - j - 1; i++){
            c[i] = abs(a[i + 1] - a[i]);
            if (c[i] == 2) c[i] = 0;
        }
        a = c;
        for (int i = 0; i < n - j - 1; i++){
            cout << c[i] << ' ';
        }cout << endl;
    }
        cout << c[0];
        return 0;
   // }



}


Measured memory_bytes: 11012
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;

void solve(){
  ll n, q;
  string s;
  cin >> n >> s >> q;
  vector<set<ll> > st(26);
  for(int i = 0; i < n; i++){
    int x = s[i] - 'a';
    st[x].insert(i);
  }
  cout << endl;
  for(int i= 0; i < q; i++){
    int x; cin >> x;
    if(x == 1){
      int y;
      char c1, c2;
      cin >> y >> c2;
      c1 = s[y - 1];
      st[c1 - 'a'].erase(y - 1);
      st[c2 - 'a'].insert(y - 1);
      s[y - 1] = c2;
    }
    else{
      int l, r, sum = 0; cin >> l >> r;
      for(int j = 0; j < 26; j++){
        if(st[j].lower_bound(l - 1) != st[j].end()){
          int y = *(st[j].lower_bound(l - 1));
          if(y <= r - 1) sum++;
        }
      }
      cout << sum << endl;
    }
  }

  return;
}

int main(){
  solve();
  return 0;
}


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

int a[12], f = 0;
int main(){
	for(int i = 0;i < 12;i++)scanf("%d", &a[i]);
	sort(a, a+12);
	for(int i = 0;i < 3;i++){
		for(int j = 0;j < 3;j++)if(a[i*4+j] == a[i*4+j+1])f++;
	}
	if(f == 9)printf("yes\n");
	else printf("no\n");
	return 0;
}


Measured memory_bytes: 3192