akhauriyash/Code-Regression huggingface dataset:
a = int(input())
c = input()
nl = 0
nr = 0
for i in c :
    if i == ')' :
        nr += 1
        if nl > 0 :
            nr -= 1
            nl -= 1
    elif i == '(' :
        nl += 1
c = '('*nr + c + ')'*nl
print(c)


Measured memory_bytes: 2940
mod=10**9+7
n,a,b=[int(x) for x in input().rstrip().split()]

def modpow(a,n):
  if n<1:
    return 1
  ans=modpow(a,n//2)
  ans=(ans*ans)%mod
  if n%2==1:
    ans*=a
  return ans%mod

def conb(n,i):
  inv,ans=1,1
  for j in range(1,i+1):
    ans=ans*(n-j+1)%mod
    inv=inv*j%mod
  return (ans*modpow(inv,mod-2))%mod

ans_n=pow(2,n,mod)-1
ans_a=conb(n,a)
ans_b=conb(n,b)

print((ans_n-ans_a-ans_b)%mod)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
  vector<int >nos(n,0);
  for(int i=0;i<n;i++)cin>>nos[i];
  if(n==1){cout<<1;return 0;}
  int tot=1;
  int dec=0;
  if(nos[0]>nos[1])dec=-1;
  if(nos[1]>nos[0])dec=1;
  for(int i=2;i<n;i++){
      //cout<<nos[i-1]<<' '<<nos[i]<<' '<<dec<<'\n';
  	if(nos[i]>nos[i-1]){
    	if(dec==0){dec=1;continue;}
      if(dec==1)continue;
      if(dec==-1){//cout<<i<<'\n';
      tot++;dec=0;continue;}
    }
    if(nos[i]<nos[i-1]){
       // cout<<"here\n";
      if(dec==0){dec=-1;continue;}
      if(dec==-1)continue;
      if(dec==1){//cout<<i<<'\n';
      tot++;dec=0;continue;}
    }
    if(nos[i]==nos[i-1]){
    continue;
    }
  }
  cout<<tot;
}

Measured memory_bytes: 3760
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int ma[9][9];

void solve(int y, int x, int check[][9]){
    rep(i, 9){
        if(ma[i][x] == ma[y][x]) check[i][x]++;
        if(ma[y][i] == ma[y][x]) check[y][i]++;
    }
    rep(i, 3){
        rep(j, 3){
            if(ma[i + y / 3 * 3][j + x / 3 * 3] == ma[y][x])
                check[i + y / 3 * 3][j + x / 3 * 3]++;
        }
    }
}

int main(){
    int n;
    while(cin >> n){
        rep(i, n){
            if(i) cout << endl;
            int check[9][9] = {0};
            rep(i, 9){
                rep(j, 9){
                    cin >> ma[i][j];
                }
            }
            rep(i, 9){
                rep(j, 9){
                    solve(i, j, check);
                }
            }
            rep(i,9){
                rep(j,9){
                    if(check[i][j] > 3)
                        cout << '*';
                    else
                        cout << ' ';
                    cout << ma[i][j];
                }
                cout << endl;
            }
        }
    }
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
const lli mod = 1e9+7;

int main(){
    lli n,m;
    cin >> n >> m;
    if(n==1){
        cout << (m+1)%mod << endl;
        return 0;
    }
    lli dmax = m/(n-1) %mod;
    lli ans = (m+1) %mod *dmax %mod;
    ans -= dmax*(dmax+1)/2 %mod *((n-1)%mod) %mod;
    ans = (ans +mod) %mod;
    ans = 2*ans +m+1;
    ans %= mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3104
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; ++i)
#define FOR(i,n,m) for(long long i=n; i<m; ++i)
#define DUMP(n,a) for(long long dump=0; dump<n; ++dump) { cout<<a[dump]; if(dump!=n-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll h,w;
	cin>>h>>w;
	vector<ll> cnt(26,0);
	REP(i,h) {
		REP(j,w) {
			char a;
			cin>>a;
			cnt[a-'a']++;
		}
	}
	vector<ll> mod4(4,0);
	REP(i,26) {
		mod4[cnt[i]%4]++;
	}
	mod4[2]+=mod4[3];
	mod4[1]+=mod4[3];
	bool d=false;
	if(h%2==0) {
		if(w%2==0) {
			if(mod4[1]==0&&mod4[2]==0) d=true;
		} else {
			if(mod4[1]==0&&mod4[2]<=h/2) d=true;
		}
	} else {
		if(w%2==0) {
			if(mod4[1]==0&&mod4[2]<=w/2) d=true;
		} else {
			if(mod4[1]==1&&mod4[2]<=w/2+h/2) d=true;
		}
	}
	if(d) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 400020
#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define fore(i,x)for (register int i = head[x] ; i ; i = e[i].next)
#define pb push_back
#define prev prev_
#define stack stack_
#define mp make_pair
#define fi first
#define se second
#define inf 1e18
#define lowbit(x) (x&(-x))
typedef long long ll;
typedef pair<ll,int> pr;

struct node{
	int x,y; ll w;
	bool operator < (node a)const{
		return w < a.w;
	}
}dt[maxn];
int fa[maxn],n,a[maxn],rec[maxn],D,tot;
ll b[maxn],c[maxn],ans;
pr mn[maxn];

inline pr query(int id){
	pr res (inf,0);
	for (int i = id ; i ; i -= lowbit(i)){
		if ( mn[i].fi < res.fi ) res = mn[i];
	}
	return res;
}
inline void modify(int id,pr cur){
	for (int i = id ; i <= n ; i += lowbit(i)){
		if ( mn[i].fi > cur.fi ) mn[i] = cur;
	}
}
void init(){
	sort(rec + 1,rec + n + 1);
	rep(i,1,n) a[i] = lower_bound(rec + 1,rec + n + 1,a[i]) - rec;
	rep(i,1,n) mn[i] = mp(inf,0);
	rep(i,1,n){
		pr cur = query(a[i] - 1);
		if ( cur.se ) dt[++tot] = (node){i,cur.se,(ll)D * i + rec[a[i]] + cur.fi};
		modify(a[i],mp((ll)-D * i + rec[a[i]],i));
	}
	rep(i,1,n) mn[i] = mp(inf,0);
	repd(i,n,1){
		pr cur = query(a[i]);
		if ( cur.se ) dt[++tot] = (node){i,cur.se,(ll)-D * i + rec[a[i]] + cur.fi};
		modify(a[i],mp((ll)D * i + rec[a[i]],i));
	}
}
int getfa(int x){ return x == fa[x] ? x : fa[x] = getfa(fa[x]); }
int main(){
	scanf("%d %d",&n,&D);
	rep(i,1,n) scanf("%d",&a[i]) , rec[i] = a[i] ,  b[i] = (ll)a[i] + (ll)D * i , c[i] = (ll)a[i] - (ll)D * i;
	init();
	sort(dt + 1,dt + tot + 1);
	for (int i = 1 ; i <= n ; i++) fa[i] = i;
	rep(i,1,tot){
		int x = dt[i].x , y = dt[i].y;
		int p = getfa(x) , q = getfa(y);
		if ( p != q ){
			ans += dt[i].w;
			fa[p] =q;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 21760
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	int n,x=0,ma=0;
	cin>>n;
	cin>>s;
	for(int t=0;t<n;t++)
	{
		if(s[t]=='I')
		{
			x++;
		}
		else if(s[t]=='D')
		{
			x--;
		}
		ma=max(ma,x);
	}
	cout<<ma;
	return 0;
}


Measured memory_bytes: 256
S = input()
N = S.__len__()
li = [0]*N

j = S.find("RL")
li[j] = j // 2 + 1 
li[j+1] = (j+1) // 2 + 1

i = j + 1
j = S.find("RL", i)
while(j > 0):
    ct_l = S.find("LR", i)
    li[i-1] += (ct_l-i+1) // 2
    li[i] += (ct_l-i) // 2
    li[j] += (j-1-ct_l) // 2 + 1
    li[j+1] += (j-ct_l) // 2 + 1
    i = j+1
    j = S.find("RL", i)

li[i-1] += (N-i) // 2
li[i] += (N-i-1) // 2

print(*li)


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())

using namespace std;
using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

void ioinit() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); }
i64 gcd(i64 a, i64 b) { if (a % b == 0) return b; else return gcd(b, a % b); }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
template <class T> bool amax(T &x, T y) { if (x < y) { x = y; return 1; } else return 0; }
template <class T> bool amin(T &x, T y) { if (x > y) { x = y; return 1; } else return 0; }
template <class T> i64 lbi(vector<T> &v, T e) { return lower_bound(all(v), e) - v.begin(); }
template <class T> i64 ubi(vector<T> &v, T e) { return upper_bound(all(v), e) - v.begin(); }

int main() {
  ioinit();
  i32 n;
  i64 k;
  cin >> n >> k;
  vi64 a(n);
  rep(i, n) cin >> a[i];
  {
    vi32 cnt(50);
    rep(i, n) rep(j, 50) {
      if (a[i] & bit(j)) cnt[j]++;
    }
    i64 x = 0;
    rrep(j, 50) {
      if (cnt[j] > n - cnt[j]) {
      } else {
        if ((x ^ bit(j)) <= k) x ^= bit(j);
      }
    }
    i64 ans = 0;
    rep(i, n) ans += x ^ a[i];
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
a = input()
b = input()
c = input()
sa = []
sb = []
sc = []
for i in a:
    sa.append(i)
for i in b:
    sb.append(i)
for i in c:
    sc.append(i)
cur = sa.pop(0)
ans = ""
while True:
    if cur=="a":
        if not sa:
            ans = "A"
            break
        cur = sa.pop(0)
    if cur=="b":
        if not sb:
            ans = "B"
            break
        cur = sb.pop(0)
    if cur=="c":
        if not sc:
            ans = "C"
            break
        cur = sc.pop(0)
print(ans)

Measured memory_bytes: 80284
//I read the news today, oh boy
//About a lucky man who made the grade
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ll((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define roF(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll N=1e6;
const ll INF = 1e18;

ll A[N], acum[N];

int main(){
	fastio;
	int n; cin>>n;
	For(i,1,n+1) cin>>A[i];
	For(i,1,n+1) acum[i]=A[i]+acum[i-1];
	ll ans = INF;
	For(i,1,n+1){
		ll s1 = acum[i];
		ll s2 = acum[n]-acum[i];
		ans = min(ans, abs(s1-s2));
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3592
s = input()
    
if s[0] != 'A' or s[1].islower() == False or s[-1].islower() == False:
    print('WA')
elif s[2:-1].count('C') != 1:
    print('WA')
else:
    flag = 'AC'
    for i in range(3, len(s)-1):
        if s[i].islower() or s[i] == 'C':
            flag = 'AC'
        else:
            flag = 'WA'
            break
    print(flag)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

int main(void) {
  ll N, K;
  cin >> N >> K;
  vector<pair<ll, ll> > ranges(K);
  vector<ll> diffs(N + 2, 0);
  vector<ll> paths(N + 2, 0);
  paths[1] = 1;
  ll cur = 0;
  for (ll i = 0; i < K; i++) {
    int l, r;
    cin >> l >> r;
    ranges[i] = make_pair(l, r);
  }
  for (ll i = 1; i <= N; i++) {
    cur += diffs[i];
    paths[i] += cur;
    paths[i] = paths[i] % 998244353;
    if (paths[i] > 0) {
      for (ll j = 0; j < K; j++) {
        if (i + ranges[j].first <= N) {
          diffs[i + ranges[j].first] += paths[i];
          diffs[min(N + 1, i + ranges[j].second + 1)] -= paths[i];
        }
      }
    }
  }
  cout << paths[N] << endl;
  return 0;
}

Measured memory_bytes: 5984
x = int(input())

if x <= 599:
    print(8)
elif x <= 799:
    print(7)
elif x <= 999:
    print(6)
elif x <= 1199:
    print(5)
elif x <= 1399:
    print(4)
elif x <= 1599:
    print(3)
elif x <= 1799:
    print(2)
elif x <= 1999:
    print(1)

Measured memory_bytes: 9176
//c++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
#include <fstream>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define len(x) ((int)(x).size())

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
const ll MOD = 1000000007;
//const ll MOD = 998244353;
double EPS = 1e-10;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A){printf("%.9lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


//コンビネーション
const int MAXcomb = 2000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; 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;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}


ll disit(ll s, ll base = 10){
  ll res = 0;
  while(s){
    res++;
    s /= base;
  }
  return res;
}


void solve(){
  ll N;
  cin >> N;
  ll ans = pow_mod(10, N);
  ans += MOD - pow_mod(9, N);
  ans += MOD - pow_mod(9, N);
  ans += pow_mod(8, N);
  ans %= MOD;
  cout << ans << endl;
}

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


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

char chess(int H, int W) {
    if((H+W)%2==0) {
        return '#';
    }
    return '.';
}

int main(void){
    int H,W;
    while(true) {
        cin >> H >> W;
        if (H == 0 && W == 0) {
            break;
        }
        for(int j = 0; j < H; j++){
            for(int i = 0; i < W; i++) {
                cout << chess(i,j);
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3088
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.TreeSet;
 
 
 
public class Main {
  public static void main(String[] args) {
    InputReader sc = new InputReader(System.in);
 
 
    int n = sc.nextInt();
    String[] strs = new String[n];
    for(int i = 0; i < n; i++){
      strs[i] = sc.nextStr();
    }
    Arrays.sort(strs);

    int ans = 1;
    for(int i = 0; i < n - 1; i++){
      if(!strs[i].equals(strs[i+1])){ans++;}
    } 
    
    System.out.println(ans);
 
  }
 
 //ここからテンプレ
  static class InputReader {
      private InputStream stream;
      private byte[] buf = new byte[1024];
      private int curChar;
      private int numChars;
      private SpaceCharFilter filter;
 
      public InputReader(InputStream stream) {
          this.stream = stream;
      }
 
      public int next() {
          if (numChars == -1)
              throw new InputMismatchException();
          if (curChar >= numChars) {
              curChar = 0;
              try {
                  numChars = stream.read(buf);
              } catch (IOException e) {
                  throw new InputMismatchException();
              }
              if (numChars <= 0)
                  return -1;
          }
          return buf[curChar++];
      }
 
      public String nextStr() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        StringBuffer str = new StringBuffer();
        do{
          str.append((char)c);
          c = next();
        }while(!isSpaceChar(c));
        return str.toString();
      }
 
      public char nextChar() {
        int c = next();
        while(isSpaceChar(c)){c = next();}
        char ret;
        do{
          ret = (char)c;
          c = next();
        }while(!isSpaceChar(c));
        return ret;
      }
 
      public int nextInt() {
          int c = next();
          while (isSpaceChar(c))
              c = next();
          int sgn = 1;
          if (c == '-') {
              sgn = -1;
              c = next();
          }
          int res = 0;
          do {
              if (c < '0' || c > '9')
                  throw new InputMismatchException();
              res *= 10;
              res += c - '0';
              c = next();
          } while (!isSpaceChar(c));
          return res * sgn;
      }
 
      public boolean isSpaceChar(int c) {
          if (filter != null)
              return filter.isSpaceChar(c);
          return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
      }
 
      public interface SpaceCharFilter {
          public boolean isSpaceChar(int ch);
      }
  }
}

Measured memory_bytes: 52004
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int d,t,s,D;
    cin>>d>>t>>s;
    D=t*s;
    if(D>=d)
        cout<<"Yes"<<endl;
    else if(D<d)
        cout<<"No"<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;

ll ms(ll a, ll N)
{
    return N / a;
}

ll solve(ll A, ll B, ll C, ll D)
{
    ll ans = B - A + 1;

    ll mmc = lcm(C, D);
    ll cs = ms(C, B) - ms(C, A - 1);
    ll ds = ms(D, B) - ms(D, A - 1);
    ll cds = ms(mmc, B) - ms(mmc, A - 1);
 
#ifdef DEBUG
    cout << "--- A = " << A << ", B = " << B << ", C = " << C << ", D = " << D << endl;
    cout << "--- ns = " << ans << endl;
    cout << "    cs = " << cs << endl;
    cout << "    ds = " << ds << " [1, B] = " << ms(D, B) << ", [1, A - 1] = " << ms(D, A - 1) << endl;
    cout << "    cds = " << cds << endl;
#endif

    ans = ans - cs - ds + cds;

    return ans;
}

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

    ll A, B, C, D;
    cin >> A >> B >> C >> D;

    auto ans = solve(A, B, C, D);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3648
# coding: utf-8
# Your code here!

N, M = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(N)]
dic = set(a[0][1::])
tmp = {}

for i in range(1, N):
    tmp = set(a[i][1::])
    dic = dic & tmp
print(len(dic))

Measured memory_bytes: 3064
#include <bits/stdc++.h>  // This will work only for g++ compiler. 
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")


#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based

//short hand for usual tokens
#define pb push_back
#define fi first
#define se second

// to be used with algorithms that processes a container Eg: find(all(c),42)
#define all(x) (x).begin(), (x).end() //Forward traversal
#define rall(x) (x).rbegin, (x).rend() //reverse traversal

// traversal function to avoid long template definition. Now with C++11 'auto' alleviates the pain.
#define tr(c,i) for(__typeof__((c)).begin() i = (c).begin(); i != (c).end(); i++)

// find if a given value is present in a container. Container version. Runs in log(n) for set and map
#define present(c,x) ((c).find(x) != (c).end())

//find version works for all containers. This is present in std namespace.
#define cpresent(c,x) (find(all(c),x) != (c).end())

// Avoiding wrap around of size()-1 where size is a unsigned int.
#define sz(a) int((a).size())
using namespace std ;

// Shorthand for commonly used types
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;
int __lcm(int a,int b){
    return a*b/__gcd(a,b);
}

int main() {	

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed ;
    int n ;
    cin >> n ;
    vll a ;
    bool zero = false ;
    for(int i = 0 ; i < n ; i++){
      ll x ;
      cin >> x ;
      if(x == 0)
        zero = true ;
      a.push_back(x) ;
    }
    if(zero)
      cout << 0 ;
    else{
      //sort(a.begin(),a.end()) ;
      ll mul = a[0] ;
      bool ok = true ;
      for(int i = 1; i < n ; i++){
        if(mul > ((ll)1e18)/a[i]){
          ok = false ;
          break ;
        }
        mul *= a[i] ;
      }
      if(ok)
        cout << mul ;
      else
        cout << -1 ;
    }
    return 0 ;
}

Measured memory_bytes: 4264
/*


*/

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

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

#define endl '\n'
#define ld long double
#define ll long long
#define PI acos(-1.0)
#define OO 1e17
#define EPS 1e-12
#define MLOG 20
#define MAX 20 * 100 * 100+5
const int mod = 1e9 + 7;

int dcmp(long double x, long double y){
	return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1;
}

void fast(){
#ifndef ONLINE_JUDGE
	freopen("E:\\Competitve\\solving\\input.txt", "r", stdin);
	freopen("E:\\Competitve\\solving\\output.txt", "w", stdout);
#endif

	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
}
int n, k;
int dislike;
int main() {
	//fast();
	cin >> n >> k;
	for (int i = 0; i < k; i++){
		int x; cin >> x;
		dislike |= (1 << x);
	}
	for (int i = n;; i++){
		int x = i;
		bool ok = 1;
		while (x){
			int d = x % 10;
			if (dislike & (1 << d)){
				ok = 0;
				break;
			}
			x /= 10;
		}
		if (ok)
			return cout << i << endl, 0;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 

using namespace std;

//#Rohitpratap311
//#Keep Calm And Stay Happy

typedef long long ll;
typedef long double ld;

int main()
{
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
  //ios::sync_with_stdio(0);
// cin.tie(0);
int n;
cin>>n;
ll ans=0;
for(int c=1;c<n;++c){
    int val=n-c;
    ll no=0;
    for(int i=1;i*i<=val;++i){
        if(val%i==0)
        no+=2;
    }
    if(int(sqrt(val))*int(sqrt(val))==val){
        no-=1;
    }
    ans+=no;


    
}
cout<<ans;
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define M_PI  3.1415926535
#define ll long long
#define ld long double
#define all(a) a.begin(),a.end()
#define Summon_Tourist ios::sync_with_stdio(false);cin.tie(0);
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
ll inf = 1e9 + 7;
ll modexp( ll base ,ll power)
 {
     if( power == 0  ) return 1;
     if( power & 1) return base*modexp( base , power-1 )%inf;
     return modexp(base*base%inf,power/2);
 }

 int main()
{
  Summon_Tourist
  //freopen("input.txt" , "r" , stdin );
  ll t = 1;
  //cin>>t;
   while(t--)
  {
    ll n;
    cin>>n;
    vector<ll> a(n+1,0);
    for( ll i = 1 ; i<=n ; i++ )
    {
        ll j = i ;
        ll k = 1;
        while( j*k <=n ) {
            a[j*k]++;
            k++;
        }
    }
    ll ans = 0 ;
    for( ll i = 1 ; i<=n ; i++ ){
        ans += a[i]*i;
    }

    cout<<ans;
  }
  return 0;

}


Measured memory_bytes: 81312
# coding: utf-8

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

N=int(input())

P=factorization(N)
ans=0
for i in range(len(P)):
    k=P[i][1]
    c=1
    while k>0:
        ans+=1
        k-=c
        c+=1
        if k<0:
            ans-=1

if N==1:
    print(0)
else:
    print(ans)
    
    

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

void factorise(int n){
  int a=2;
  while(sqrt(n)>=a){
    while(n%a==0){
      n/=a;
      cout<<" "<<a;
    }
    a++;
  }
  if(n!=1) cout<<" "<<n;
  return;
}
      

int main(){
  int n;
  cin>>n;
  cout<<n<<":";
  factorise(n);
  cout<<endl;
  return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << 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 pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
#define S set<int>
#define itn int
int T, A[333], B[333], C[333], D[333];
bool dbg = false;
int gcd(int a, int b)
{
    while (1) {
        if (a < b)
            swap(a, b);
        if (!b)
            break;
        a %= b;
    }
    return a;
}
void solve()
{
    FOR(i, 0, T)
    {
        int a = A[i], b = B[i], c = C[i], d = D[i];
        int g = gcd(b, d);
        bool flag = true;
        if (b > d) {
            flag = false;
        } else {
            itn t = ((a - c - 1 + g) % g) + c + 1 - b;
            dump(t);
            if (t < 0) {
                flag = false;
            }
            if (a < b) {
                flag = false;
            }
        }
        if (flag) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> T;
    FOR(i, 0, T)
    {
        cin >> A[i] >> B[i] >> C[i] >> D[i];
    }
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 10000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m,W,t;
string str[101];
int v[8],p[8];

int l[8],x[8],y[8];
int r[8][8],w[8][8];
int dp[1<<8][10001];
int dp2[1<<8][8];
ll dp3[10001];

int main(void){
	scanf("%d%d%d%d",&n,&m,&W,&t);
	for(int i=0;i<m;i++){
		cin >> str[i] >> v[i] >> p[i];
	}
	for(int i=0;i<n;i++){
		scanf("%d%d%d",&l[i],&x[i],&y[i]);
		for(int j=0;j<l[i];j++){
			string s;
			cin >> s >> r[i][j];
			int id;
			for(id=0;id<m;id++){
				if(str[id]==s){
					break;
				}
			}
			r[i][j]=p[id]-r[i][j];
			w[i][j]=v[id];
		}
	}
	for(int bit=1;bit<(1<<n);bit++){
		for(int j=0;j<W;j++){
			dp[bit][j+1]=max(dp[bit][j+1],dp[bit][j]);
			for(int i=0;i<n;i++){
				if(!(bit>>i & 1))continue;
				for(int k=0;k<l[i];k++){
					if(j+w[i][k]<=W){
						dp[bit][j+w[i][k]]=max(dp[bit][j+w[i][k]],dp[bit][j]+r[i][k]);
					}
				}
			}
		}
	}
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<=n;j++){
			dp2[i][j]=INF;
		}
	}
	dp2[0][n]=0;
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<=n;j++){
			if(dp2[i][j]==INF)continue;
			for(int k=0;k<n;k++){
				int dist=abs(x[k]-x[j])+abs(y[k]-y[j]);
				dp2[i|(1<<k)][k]=min(dp2[i|(1<<k)][k],dp2[i][j]+dist);
			}
		}
	}
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<n;j++){
			dp2[i][n]=min(dp2[i][n],dp2[i][j]+abs(x[j])+abs(y[j]));
		}
	}
	for(int i=0;i<t;i++){
		dp3[i+1]=max(dp3[i+1],dp3[i]);
		for(int j=0;j<(1<<n);j++){
			if(dp2[j][n]+i<=t){
				dp3[i+dp2[j][n]]=max(dp3[i+dp2[j][n]],(ll)dp3[i]+dp[j][W]);
			}
		}
	}
	printf("%lld\n",dp3[t]);
	return 0;
}

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

int N;
string s;

int main() {
  cin >> N >> s;
  // 最初の2匹を仮定する
  vector<int> t(N + 1);
  for(int st = 0; st < 4; st++) {
    t[0] = st & 1;
    t[1] = st >> 1 & 1;
    for(int i = 1; i < N; i++) {
      if(t[i]) {
        // w
        if(s[i] == 'x') {
          t[i + 1] = t[i - 1];
        }else{
          t[i + 1] = t[i - 1] ^ 1;
        }
      }else{
        // s
        if(s[i] == 'o') {
          t[i + 1] = t[i - 1];
        }else{
          t[i + 1] = t[i - 1] ^ 1;
        }
      }
    }
    if(t[N] != t[0]) continue;
    if((s[0] == 'o' && t[0] == 0) || (s[0] == 'x' && t[0] == 1)) {
      if(t[1] != t[N - 1]) continue;
    } else {
      if(t[1] == t[N - 1]) continue;
    }
    string ret = "";
    for(int i = 0; i < N; i++) {
      if(t[i])ret.push_back('W'); else ret.push_back('S');
    }
    cout << ret << endl;
    return 0;
  }
  cout << -1 << endl;
  return 0;
}

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

#define MAX 1000000000000000000

int main()
{
    int n;
    cin >> n;
    unsigned long long ans = 1, a[n];

    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i = 0; i < n; i++){
        if(a[i] <= MAX/ans) ans *= a[i];
        else {cout << -1 << endl; return 0;}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4408
#include <iostream>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, s, n) for(int i = s; i < n; i++)
using namespace std;

vector<int> r(100), c(100);
vector<vector<int>> dp(100, vector<int>(100, -1));
int rec(int left, int right){
  if (right - left == 0) return 0;
  if (right - left == 1) return r[left] * r[right] * c[right];
  if (dp[left][right] != -1) return dp[left][right];
  int min;
  rep2(mid, left, right){
    min = rec(left, mid) + rec(mid+1, right) + r[left] * c[mid] * c[right];
    if (dp[left][right] == -1 || dp[left][right] > min) dp[left][right] = min;
  }
  return dp[left][right];
}

int main(){
  int n;
  cin >> n;
  rep(i, n) cin >> r[i] >> c[i];
  int ans = rec(0, n-1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define fori(i, a, b) for(int i = (int) a; i <= (int) b; ++i)
#define rofi(i, b, a) for(int i = (int) b; i >= (int) a; --i)
#define foreach(tt, a) for(auto &tt: a)
#define all(a) begin(a), end(a)
#define csz(a) (int) a.size()
#define pb push_back
#define epb emplace_back
#define mp make_pair
#define load(a, v) fill(begin(a), end(a), v)
#define load_mem(a, v) memset(a, v, sizeof(a));
#define iostream_optimize() ios::sync_with_stdio(false); cin.tie(0);
using ll = long long;
const ll MOD = 1e9+7, LINF = 1e16+1;
const int INF = 1e9+1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const ll P1 = 31, P2 = 37, M1 = 1e9+7, M2 = 1e9+9;

// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<< END TEMPLATE >>>>>>>>>>>>>>>>>>>>>>>>>>> */
const int N = 701;

int n, m, color[N];
bool g[N][N];
int sz[2];
bitset<2*N> ans;

void dfs(int u) {
	++sz[color[u]];
	fori(v, 0, n-1) if(g[u][v]) {
		// cout << u << ' ' << v << ' ' << color[u] << ' ' << color[v] << endl;
		if(color[v] == 2) color[v] = color[u] ^ 1, dfs(v);
		else if(color[v] == color[u]) cout << -1, exit(0);
	}
}

int main() {
	iostream_optimize();
	cin >> n >> m;
	load_mem(g, 1);
	fori(i, 0, m-1) {
		int u, v;
		cin >> u >> v;
		g[u-1][v-1] = g[v-1][u-1] = 0;
	}
	fori(i, 0, n-1) g[i][i] = 0;
	load(color, 2);
	ans[N] = 1;
	fori(i, 0, n-1) if(color[i] == 2) {
		load(sz, 0);
		color[i] = 0;
		dfs(i);
		if(sz[0] > sz[1]) {
			// cout << sz[0] - sz[1] << endl;
			ans = (ans << sz[0] - sz[1]) | (ans >> sz[0] - sz[1]);
		} else {
			// cout << sz[1] - sz[0] << endl;
			ans = (ans << sz[1] - sz[0]) | (ans >> sz[1] - sz[0]);
		}
	}
	int mindiff = INF;
	fori(i, 0, 2*N-1) if(ans[i]) mindiff = min(abs(i - N), mindiff);
	int A = n+mindiff >> 1, B = n - A;
	cout << A * (A - 1) / 2 + B * (B - 1) / 2;
}

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

int main()
{
    string n;
    cin >> n;

    if(n.at(n.size() - 1) == '3'){
        cout << "bon" << endl;
    }
    else if(n.at(n.size() - 1 ) == '0' || n.at(n.size() - 1) == '1' || n.at(n.size() - 1) == '6' || n.at(n.size() - 1) == '8'){
        cout << "pon" << endl;
    }
    else cout << "hon" << endl;

    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> p;
  rep(i, n) {
    int num;
    cin >> num;
    p.push_back(num);
  }
  sort(p.begin(), p.end());
  int sum = 0;
  rep(i, k) { sum += p[i]; }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

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

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

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

	if(a>=13)
		cout << b << endl;
	else if(a>=6)
		cout << b/2 <<endl;
	else cout << 0 << endl;
	return 0;
}

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

#define int long long
#define MOD ((int)1e9+7)

signed  main(){
  string s;
  stack<int> sta;
  
  cin>>s;

  for(int i = 0; i < s.size(); i++){
    if(s[i] == '*'){
      cout<<sta.size()<<endl;

    } else if(s[i] == '('){
      sta.push(1);
    }else {
      sta.pop();
    }
  }
  return 0;
}



Measured memory_bytes: 3216
#include<iostream>
#include<string>
using namespace std;
int main() {
	int a, b;
	int x;
	int i = 0;
	string l[70];
	while (true){
		cin >> a >> b;
		if (a == 0 && b == 0) {
			x = i;
			break;
		}
		if (a == 1 || a == 4 || a == 7){
			b += 4;
		}
		else if (a == 2 || a == 8){
			b += 0;
		}
		else if (a == 3 || a == 11){
			b += 1;
		}
		else if (a == 5){
			b += 6;
		}
		else if (a == 6){
			b += 2;
		}
		else if (a == 9 || a == 12){
			b += 3;
		}
		else if (a == 10){
			b += 5;
		}
		//
		if (b % 7 == 1){
			l[i] = "Sunday";
		}
		else if (b % 7 == 2){
			l[i] = "Monday";
		}
		else if (b % 7 == 3) {
			l[i] = "Tuesday";
		}
		else if (b % 7 == 4) {
			l[i] = "Wednesday";
		}
		else if (b % 7 == 5) {
			l[i] = "Thursday";
		}
		else if (b % 7 == 6) {
			l[i] = "Friday";
		}
		else if (b % 7 == 0) {
			l[i] = "Saturday";
		}
		i++;
	}
	for (int i = 0; i < x; i++){
		cout << l[i] << endl;
	}
	char c;
	cin >> c;
}

Measured memory_bytes: 3024
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String data = sc.nextLine();
        
        String[] array = data.split(" ");
        int s = Integer.parseInt(array[0]);
        int w = Integer.parseInt(array[1]);
        
        String result = "safe";
        
        if(w >= s)
        {
            result = "unsafe";
        }
        
        System.out.println(result);
    }
}


Measured memory_bytes: 35760
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=998244353
input=lambda:sys.stdin.readline().rstrip()

class modfact(object):
    def __init__(self,n):
        fact=[1]*(n+1); invfact=[1]*(n+1)
        for i in range(1,n+1): fact[i]=i*fact[i-1]%MOD
        invfact[n]=pow(fact[n],MOD-2,MOD)
        for i in range(n-1,-1,-1): invfact[i]=invfact[i+1]*(i+1)%MOD
        self.__fact=fact; self.__invfact=invfact

    def inv(self,n):
        assert(n>0)
        return self.__fact[n-1]*self.__invfact[n]%MOD

    def fact(self,n):
        return self.__fact[n]

    def invfact(self,n):
        return self.__invfact[n]

    def comb(self,n,k):
        if(k<0 or n<k): return 0
        return self.__fact[n]*self.__invfact[k]*self.__invfact[n-k]%MOD

    def perm(self,n,k):
        if(k<0 or n<k): return 0
        self.__fact[n]*self.__invfact[k]%MOD

def prime(n):
    if n<=1: return []
    S=[1]*(n+1)
    S[0]=0; S[1]=0
    for i in range(2,n):
        if(S[i]==0): continue
        for j in range(2*i,n+1,i): S[j]=0
    return [p for p in range(n+1) if(S[p])]

def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    V=max(A)
    C=[0]*(V+1)
    for a in A: C[a]+=1

    P=prime(V)
    W=[1]*(V+1)
    for p in P:
        for i in range(p,V+1,p):
            W[i]*=(1-p)
    mf=modfact(V)
    for i in range(1,V+1):
        W[i]=(W[i]*mf.inv(i))%MOD

    ans=0
    for d in range(1,V+1):
        s=0 # 和(後に2乗する)
        t=0 # 2乗の和
        for i in range(d,V+1,d):
            s+=i*C[i]%MOD
            t+=(i**2)*C[i]%MOD
        ans+=W[d]*(s**2-t)*mf.inv(2)
        ans%=MOD
    print(ans)
resolve()

Measured memory_bytes: 116352
#include <bits/stdc++.h>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//#define _debug
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc(x) scanf("%d",&x)
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORd(i,a,b) for(int i=a;i>b;i--)
#define ff first
#define ss second
#define sz(x) x.size()
#define pb push_back
//#define _online_judge

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, //data type
        null_type, //
        less<int>, //
        rb_tree_tag, //red-black tree
        tree_order_statistics_node_update> new_data_set;

typedef pair<int,int> pii;
typedef vector<pii> vii;
const int con = static_cast<const int>(1e6 + 5);
const int MOD = 1000000007;


int main (){
	FASTIO
#ifdef _online_judge
	freopen("input.txt" , "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif

    ll a[2];cin >> a[0] >> a[1];
    sort(a,a+2);
    ll ans = a[1];
    a[1]--;
    ans += max(a[0],a[1]);
    cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD (long long)1e9+7
#define LINF (long long)4e18

int main(){
    vector<int> A(3);
    rep(i,3){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    int ans = 0;
    rep(i,2){
        ans += A[i+1] - A[i];
    }
    cout << ans << endl;
    
}
   

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

//abc158D
int main(void) {

  int q, i, ti, fi, inv=0, top=0, head=0, tail=0;
  //inv=1:反転、top=0:先頭追加
  char t, text[100000];
  scanf(" %s %d", text, &q);

  for(i=0; text[i] != '\0'; ++i)
    ; //textの文字数
  int txln=i;

  char str[2 * q + txln + 2];

  for(i=0; i < sizeof str / sizeof str[0]; i++){
    if(i > q && i <= q + txln) str[i]=text[i - q - 1];
    else str[i]=0;
  }
  head=q, tail=q + txln + 1;

  for(i=0; i < q; i++){
    scanf(" %d", &ti);
    if(ti == 1) inv=!inv;
    else{
      scanf(" %d", &fi);
      if(fi == 1) top=0;
      else top=1;

      scanf(" %c", &t);
      if(inv + top == 0 || inv + top == 2) str[head--]=t;
      else str[tail++]=t;
    }
  }
  if(inv == 0){
    for(i=head + 1; i < tail; i++)
      printf("%c", str[i]);
  }else{
    for(i=tail - 1; i > head; i--)
      printf("%c", str[i]);
  }
}

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

def gcd_base(a, b):
    while b!=0:
        a, b = b, a%b
    return a

def gcd(num_list):
    ans = 0
    for i in num_list:
        ans = gcd_base(ans, i)
    return ans

print(gcd(a))

Measured memory_bytes: 14252
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
using namespace std;
long long mod=1000000007;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int t=1;//cin>>t;
    while(t--)
    {
        ll x,k,d;
        cin>>x>>k>>d;
        x=abs(x);
        if(x/d>=k)
        {
            x=x-(k)*d;
            cout<<x<<endl;
        }
        else
        {
            ll y=x/d;
            x=x-(y)*d;
            k-=y;
            if(k&1)
            cout<<min(abs(x-d),abs(x+d));
            else
            cout<<abs(x)<<endl;
        }
    }
    return 0;
}













Measured memory_bytes: 3644
import heapq

X, Y, Z, K = [int(i) for i in input().split()]
ABCList = [sorted([int(i) for i in input().split()], reverse=True) for _ in range(3)]

pQ = []
heapq.heappush(pQ, [sum(ABC[0] for ABC in ABCList) * (-1), [0, 0, 0]])
QList = [(0, 0, 0)]
for _ in range(K):
    item = heapq.heappop(pQ)
    print(item[0] * (-1))
    abc = item.copy()[1]
    for i, element in enumerate(abc):
        abcTemp = abc.copy()
        abcTemp[i] += 1
        if abcTemp[i] < len(ABCList[i]) and not tuple(abcTemp) in QList:
            newItem = [sum([ABCList[i][abcTemp[i]] for i in range(3)]) * (-1), abcTemp]
            heapq.heappush(pQ, newItem)
            QList.append(tuple(abcTemp))

Measured memory_bytes: 4852
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a[10001],i,j,k,l,m;
	for(i=0;i<10;i++){
		cin>>a[i];
	}
	for(j=1;j<10;j++){
		if(a[0]<a[j]){
			swap(a[0],a[j]);
		}
	}
	for(k=2;k<10;k++){
		if(a[1]<a[k]){
			swap(a[1],a[k]);
		}
	}
	for(l=3;l<10;l++){
		if(a[2]<a[l]){
			swap(a[2],a[l]);
		}
	}
	for(m=0;m<3;m++){
		cout<<a[m]<<endl;
	}
	return 0;
}

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

const Long MX = 2e6 + 10;
const Long MOD = 1e9 + 7;

Long fact[MX];
Long inv_fact[MX];

Long fp(Long a, Long b){
	if(b == 0) return 1;
	Long t = fp(a,b/2);
	t = (t * t) % MOD;
	if(b % 2 == 1) return (t * a) % MOD;
	return t;
}

Long combi(Long n, Long m){
	return (((fact[n] * inv_fact[m]) % MOD) * inv_fact[n - m]) % MOD;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	cout << fixed;

	fact[0] = 1;
	for(Long i = 1; i < MX; i++) fact[i] = (fact[i-1] * i) % MOD;
	
	inv_fact[MX - 1] = fp(fact[MX - 1], MOD - 2);
	for(Long i = MX - 2; i >= 0; i--) inv_fact[i] = (inv_fact[i + 1] * (i + 1)) % MOD;
	

	Long n;
	cin >> n;
	string s;
	cin >> s;
	Long sz = s.size();
	Long ans = 0;
	for(Long i = 0; i <= n; i++){
		ans += ((fp(25,i) * fp(26,n-i)) % MOD) * combi(i + sz - 1, sz - 1);
		ans %= MOD;
	}
	cout << ans << "\n";
	return 0;
}


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

using namespace std;

int main()
{
    string s;
    getline(cin, s);
    transform(s.begin(), s.end(), s.begin(), ::toupper);
    string t = s.substr(s.find(" ") + 1);
  
    cout << s[0] << s[s.find(" ") + 1] << t[t.find(" ") + 1] << endl;
}

Measured memory_bytes: 256
// #define DEBUGGING
using namespace std;
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

int main() {
    ll H, W, K;
    cin >> H >> W >> K;
    V<string> vs(H);
    for(auto &&ele : vs) cin >> ele;
    auto ans = make_v<ll>(-1, H, W);
    ll id = 0;
    for(ll h = 0; h < H; h++) {
        ll pre = -1;
        ll last_id = -1;
        for(ll w = 0; w < W; w++) {
            if(vs[h][w] == '.') continue;
            id++;
            for(ll dh = 0; 0 <= h - dh; dh++) {
                if(ans[h - dh][w] != -1) break;
                for(ll l = pre + 1; l <= w; l++) ans[h - dh][l] = id;
                last_id = id;
            }
            pre = w;
        }
        if(last_id != -1) {
            for(ll dh = h; 0 <= dh; dh--) {
                for(ll w = W - 1; 0 <= w; w--) {
                    if(ans[dh][w] != -1) break;
                    ans[dh][w] = last_id;
                }
            }
        }
    }

    for(ll i = 1; i < H; i++) for(ll j = 0; j < W; j++) {
        if(ans[i][j] != -1) continue;
        ans[i][j] = ans[i - 1][j];
    }
    for(ll j = 0; j < W; j++) if(ans[0][j] == -1) ans[0][j] = ans[1][j];

    for(auto &&v : ans) {
        for(ll i = 0; i < W; i++) cout << v[i] << " \n"[i + 1 == W];
    }

    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int Mod = 998244353;
const int Sz = 3e3 + 1;

int n, k;
int a[Sz];
int f[Sz][Sz];
int dp(int pos, int w){
    if(w > k) return 0;
    if(pos > n && w == k) return 1;
    if(pos > n) return 0;
    int &res = f[pos][w];
    if(res != -1) return res;
    res = (dp(pos + 1, w) * 2 + dp(pos + 1, w + a[pos])) % Mod;
    return res;
}
int32_t main()
{
    memset(f, -1, sizeof(f));
    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];
    cout << dp(1, 0);
    return 0;
}


Measured memory_bytes: 74192
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    fast_io();

    ll n; std::cin>>n;
    std::vector<ll> a(n), v(200001,0);
    for(ll i=0; i<n; i++){
        std::cin >> a[i]; v[a[i]]++;
    }

    std::set<ll> st(a.begin(),a.end());
    ll c = 0;
    for(auto i : st){
        c += v[i]*(v[i]-1)/2;
    }

    for(ll i=0; i<n; i++){
        std::cout << c - (v[a[i]] - 1) << "\n";
    }
    return 0;
}


Measured memory_bytes: 12180
import Prelude hiding (min, max)
import qualified Data.Ord as Ord

solve :: Int -> Int -> Int -> [[Int]] -> Int
solve min max cur [] = if min >= 0 then max else 0
solve min max cur ([a, b] : xs) =
    solve (Ord.min min next) (Ord.max max next) next xs
    where next = cur + a - b

main = do
    str <- getContents
    let [n] : [m] : s' = map ((map read) . words) (lines str) :: [[Int]]
    let s = take n s'
    print $ solve m m m s



Measured memory_bytes: 9228