akhauriyash/Code-Regression huggingface dataset:
import numpy as np
n = int(input())
takahashi_u = []
aoki_u = []
sum_u = []
takahashi_eat = []
aoki_eat = []
for i in range(n):
  a, b = map(int, input().split())
  takahashi_u.append(a)
  aoki_u.append(b)
  sum_u.append(a+b)
arr = np.array([sum_u, takahashi_u, aoki_u])
sort_index = np.argsort(arr[0])[::-1]
sort_arr = arr[:, sort_index]
takahashi_arr = sort_arr[1, 0::2]
aoki_arr = sort_arr[2, 1::2]
print(sum(takahashi_arr) - sum(aoki_arr))

Measured memory_bytes: 29508
from collections import deque
H,W = [int(x) for x in input().split()]
maze = []
for i in range(H):
    maze.append(list(input()))
#隣接リスト表記にする
#i行目j列目をi*W+jで表現
l = [[] for i in range(H*W)]
for i in range(H-1):
    for j in range(W-1):
        if maze[i][j] == "." and maze[i+1][j] == ".":
            l[j+W*i].append(j+W*(i+1))
            l[j+W*(i+1)].append(j+W*i)
        if maze[i][j] == "." and maze[i][j+1] == ".":
            l[j+W*i].append(j+W*i+1)
            l[j+W*i+1].append(j+W*i)
#右端を追加
for i in range(H-1):
    if maze[i][W-1] == "." and maze[i+1][W-1] == ".":
            l[W*i+W-1].append(W*i+2*W-1)
            l[W*i+2*W-1].append(W*i+W-1)
#下端を追加
for j in range(W-1):
    if maze[H-1][j] == "." and maze[H-1][j+1] == ".":
            l[j+W*(H-1)].append(W*(H-1)+j+1)
            l[j+W*(H-1)+1].append(j+W*(H-1))
#ここまでで隣接リスト表記できた
kosuu = H*W
ans = 0
for i in range(kosuu):
    dist = [-1]*kosuu
    d = deque()
    dist[i] = 0
    d.appendleft(i)
    while d:
        v = d.popleft()
        for j in l[v]:
            if dist[j] == -1:
                dist[j] = dist[v] + 1
                d.append(j)
    ans = max(ans,max(dist))
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
#define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          998244353
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
   
    #endif
}

  
void solve()
{
 
 int n,m;
 cin >> n >> m;
 int a[m],s=0;
 forf(i,0,m) cin >> a[i],s+=a[i];
 
 if(s>n)
 {
  cout<<"-1\n";
  return ;
 }
 cout<<n-s<<endl;

}

int32_t main()
{
  pr_init();
  fastio;
  solve();

 }
      

Measured memory_bytes: 3688
h,w,K=map(int,input().split())
data=[[0 for i in range(w+1)]]
for i in range(h):
    x=list(input())
    x.insert(0,0)
    for j in range(w+1):
        x[j]=int(x[j])
    data.append(x)
    
for i in range(h+1):
    for j in range(1,w+1):
        data[i][j]+=data[i][j-1]
        
for i in range(w+1):
    for j in range(1,h+1):
        data[j][i]+=data[j-1][i]
        


ans=10**10
for _ in range(2**(h-1)):
    st=choice=format(_,"0%ib"%(h-1))
    div=[0]
    sub=0
    for j in range(h-1):
        if st[j]=="1":
            div.append(j+1)
            sub+=1
    div.append(h)
    cnt=0
    nowindex=0
    for j in range(1,w+1):
        flag=True
        if nowindex==0:
            for k in range(1,len(div)):
                if data[div[k]][j]-data[div[k-1]][j]>K:
                    flag=False
                    break
            if flag is False:
                nowindex=j-1
                cnt+=1
                 
        else:
            for k in range(1,len(div)):
                if (data[div[k]][j]-data[div[k]][nowindex])-(data[div[k-1]][j]-data[div[k-1]][nowindex])>K:
                    flag=False
                    break
            if flag is False:
                nowindex=j-1
                cnt+=1
    subflag=True
    for k in range(1,len(div)):
        if (data[div[k]][w]-data[div[k]][nowindex])-(data[div[k-1]][w]-data[div[k-1]][nowindex])>K:
            subflag=False
    if subflag is True:
        ans=min(ans,sub+cnt)
print(ans)
                    
    

    
        
    
    


Measured memory_bytes: 3444
use std::cmp;

fn main(){
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).expect("failed to read");
    let vs: Vec<char> = buf.trim().chars().collect();
    
    buf.clear();
    std::io::stdin().read_line(&mut buf).expect("failed to read");
    let vt: Vec<char> = buf.trim().chars().collect();

    let ls: usize = vs.len();
    let lt: usize = vt.len();
    
    let mut ec: usize = lt;
    
    for s in 0 ..= ls - lt {
        let mut c: usize = 0;
        
        for t in 0 .. lt {
            if vs[s+t] != vt[t] { c += 1 }
        }
        
        ec = cmp::min(ec, c);
    }
    
    println!("{}", ec)
}


Measured memory_bytes: 2124
def INT():
    return int(input())

def LI():
    return list(map(int, input().split()))

def MI():
    return map(int, input().split())

N, M = MI()
X = LI()
X.sort()

if N >= M:
    print(0)
    exit()

dist = []
for i in range(M - 1):
    d = X[i + 1] - X[i]
    dist.append(d)

dist.sort()
print(sum(dist[ : M - N]))

Measured memory_bytes: 90872
import java.util.Scanner;

public class Main {

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

		String S = sc.next();
		String S1 = S.substring(0, 2);
		String S2 = S.substring(2, 4);

		if (01 <= Integer.parseInt(S1) && Integer.parseInt(S1) <= 12
				&& 01 <= Integer.parseInt(S2) && Integer.parseInt(S2) <= 12) {
			System.out.println("AMBIGUOUS");
		} else if (00 <= Integer.parseInt(S1) && Integer.parseInt(S1) <= 99
				&& 01 <= Integer.parseInt(S2) && Integer.parseInt(S2) <= 12) {
			System.out.println("YYMM");
		} else if (00 <= Integer.parseInt(S2) && Integer.parseInt(S2) <= 99
				&& 01 <= Integer.parseInt(S1) && Integer.parseInt(S1) <= 12) {
			System.out.println("MMYY");
		} else {
			System.out.println("NA");
		}
	}

}

Measured memory_bytes: 23764
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

void run (void) {
  i32 n, k;
  scanf ("%" SCNi32 "%" SCNi32, &n, &k);
  i32 *a = ALLOC (n, i32);
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32, a + i);
  }
  uint8_t *dp = ALLOC (k + 1, uint8_t);
  for (i32 i = 0; i < k; ++i) {
    if (dp[i]) continue;
    for (i32 j = 0; j < n && a[j] <= k - i; ++j) {
      dp[i + a[j]] = 1;
    }
  }
  puts (dp[k] ? "First" : "Second");
}

int main (void) {
  run();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

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

  ll l = 0, r = n - 1, ans = 0;
  while (r > 0 && s[r] == 'W') {
    r--;
  }

  while (l < r) {
    if (s[l] == 'R') {
      l++;
      continue;
    }
    l++;
    ans++;
    r--;
    while (r > 0 && s[r] == 'W') {
      r--;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp(a, b) make_pair(a, b)
#define ls (rt << 1)
#define rs (rt << 1 | 1) 
typedef pair<int, int> pii; 
const ll mod = 1e9 + 7;
template <class T> T lowbit(T x){return ((x)&(-(x)));}
const int maxn = 2e5 + 10;
int n, m, ans;
int h[maxn], a[maxn];
int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) 
	{
		scanf("%d", &h[i]);
		a[i] = 1;
	}
	for(int i = 1; i <= m; ++i)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		if(h[u] <= h[v]) a[u] = 0;
		if(h[v] <= h[u]) a[v] = 0;
	}
	for(int i = 1; i <= n; ++i) ans += a[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4544
#include<stdio.h>

int main(){

  int n, cnt=0, i, j, k, tmp;

  scanf("%d", &n);

  int a[n];

  for(i=0;i<n;i++) scanf("%d", &a[i]);

  for(i=0;i<n;i++){

    for(j=n-1;j>i;j--){

      if(a[j]<a[j-1]){

	tmp=a[j];

	a[j]=a[j-1];

	a[j-1]=tmp;

	cnt++;

      }

    }
    
  }

  for(i=0;i<n;i++){

    if(i==0) printf("%d", a[i]);

    else printf(" %d", a[i]);

  }

  printf("\n%d\n", cnt);

  return 0;

}



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

int main() {
  int K , S;
  cin >> K >> S;
  int result = 0;
  for(int i = 0; i <= K; i++){
    for(int j = 0; j <= K; j++){
      int z = S-(i+j);
      if(z >= 0 and z <= K) result++;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int count=0;
		int atai = -1;
		int[] a = new int[101];
		for(int i=0;i<N;i++){
			a[i] = sc.nextInt();
		}
		for(int i=1;i<N;i++){
			if(a[i]==a[i-1]){
				count++;
				a[i] = atai;
				atai--;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 23252
#pragma region

#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;
using vvb = vector<vector<bool>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  int N;
  cin >> N;
  vector<string> S(N);
  cin >> S;

  constexpr char C[5] = {'M', 'A', 'R', 'C', 'H'};
  vector<ll> cnt(5, 0);
  rep(i, N) {
    rep(j, 5) {
      if (S[i][0] == C[j]) cnt[j]++;
    }
  }

  ll ans = 0;
  ans += cnt[0] * cnt[1] * cnt[2];
  ans += cnt[0] * cnt[1] * cnt[3];
  ans += cnt[0] * cnt[1] * cnt[4];
  ans += cnt[0] * cnt[2] * cnt[3];
  ans += cnt[0] * cnt[2] * cnt[4];
  ans += cnt[0] * cnt[3] * cnt[4];
  ans += cnt[1] * cnt[2] * cnt[3];
  ans += cnt[1] * cnt[2] * cnt[4];
  ans += cnt[1] * cnt[3] * cnt[4];
  ans += cnt[2] * cnt[3] * cnt[4];
  out(ans);
}


Measured memory_bytes: 5760
from collections import deque
n=int(input())
E=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  a=a-1
  b=b-1
  E[a].append(b)
  E[b].append(a)
D=deque([0])
V=[0]*n
V[0]=1
A=[0]*n
k=1
while len(D)>0:
  x=D[0]
  D.popleft()
  for i in range(len(E[x])):
    if V[E[x][i]]==0:
      V[E[x][i]]=1
      D.append(E[x][i])
      A[E[x][i]]=A[x]^1
f=0
if n-sum(A)>sum(A):
  f=1
g=max(n-sum(A),sum(A))
a=(n+2)//3
b=n//3
if g>a+b:
  Ans=[0]*n
  s=1
  t=2
  u=3
  if f==0:
    for i in range(n):
      if A[i]==0:
        Ans[i]=u
        u=u+3
      else:
        if s<=n:
          Ans[i]=s
          s=s+3
        elif t<=n:
          Ans[i]=t
          t=t+3
        else:
          Ans[i]=u
          u=u+3
  else:
    for i in range(n):
      if A[i]==1:
        Ans[i]=u
        u=u+3
      else:
        if s<=n:
          Ans[i]=s
          s=s+3
        elif t<=n:
          Ans[i]=t
          t=t+3
        else:
          Ans[i]=u
          u=u+3
else:
  Ans=[0]*n
  s=1
  t=2
  u=3
  if f==1:
    for i in range(n):
      if A[i]==0 and s<=n:
        Ans[i]=s
        s=s+3
      elif A[i]==0 and s>n:
        Ans[i]=u
        u=u+3
      elif A[i]==1 and t<=n:
        Ans[i]=t
        t=t+3
      else:
        Ans[i]=u
        u=u+3
  else:
    for i in range(n):
      if A[i]==1 and s<=n:
        Ans[i]=s
        s=s+3
      elif A[i]==1 and s>n:
        Ans[i]=u
        u=u+3
      elif A[i]==0 and t<=n:
        Ans[i]=t
        t=t+3
      else:
        Ans[i]=u
        u=u+3
print(*Ans)

Measured memory_bytes: 57400
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI=acos(-1.0);
#define t1(x)             cerr<<#x<<"="<<x<<endl
#define t2(x, y)          cerr<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define t3(x, y, z)       cerr<<#x<<"=" <<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define t4(a,b,c,d)       cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<endl
#define t5(a,b,c,d,e)     cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<endl
#define t6(a,b,c,d,e,f)   cerr<<#a<<"="<<a<<" "<<#b<<"="<<b<<" "<<#c<<"="<<c<<" "<<#d<<"="<<d<<" "<<#e<<"="<<e<<" "<<#f<<"="<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define tr(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define MEMS(x,t) memset(x,t,sizeof(x));
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*-------------------------------------------------------------------------------------------------------------------------------------*/
#define MOD 998244353
#define endl "\n" 
#define int long long
#define inf 1e18
#define ld long double
/*-------------------------------------------------------------------------------------------------------------------------------------*/

ll poww(long long a, long long n, long long m)
{
        long long ans = 1;
        long long mul = a;
        while (n != 0)
        {
                if (n % 2)
                {
                        ans = (ans * mul) % m;
                }
                mul = (mul * mul) % m;
                n /= 2;
        }
        return ans;
}
/* 
Fermat's little theorem: 
1) (a/b)%mod= (a*(poww(b,mod-2,mod)))%mod iff a%b==0
2) (a^b)%mod= (a^(b%(mod-1)))%mod iff mod is prime
*/
const int SZ=2e5+100;
ll factorial[SZ];
ll iv[SZ];
void precompute()
{
	factorial[0]=1;
    iv[0]=1;
	for(int i=1;i<SZ;i++)
	{
		factorial[i]=(factorial[i-1]*i)%MOD;
	   iv[i]=poww(factorial[i],MOD-2,MOD);
    }
}
ll InverseEuler(ll n, ll m)
{
    return poww(n, m - 2, m);
}
ll C(ll n, ll r, ll m)
{

    return (factorial[n] * ((iv[r] * iv[n-r]) % m)) % m;
}
const int N=1e6+10;
int cnt[N];
int f[N];
int c2(int n)
{
	int ans=n*(n-1)/2;	
	return ans%MOD;
}
int32_t main()
{
	fastio();	
	int n;
	cin>>n;
	int ans=0;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		cnt[x]++;
	}
	for(int i=N-1;i>0;i--)
	{
		int s=0;
		for(int j=i;j<N;j+=i)
		{
			f[i]+=MOD-f[j];
			if(f[i]>MOD)f[i]-=MOD;
			f[i]+=(s*((cnt[j]*j)%MOD))%MOD;
			f[i]%=MOD;
			f[i]+=(((j*j)%MOD)*c2(cnt[j]))%MOD;
			f[i]%=MOD;
			s+=(cnt[j]*j)%MOD;
			s%=MOD;
		}
		ans+=(f[i]*InverseEuler(i,MOD))%MOD;
		ans%=MOD;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 16640
#include<cstdio>

int main(){
	int num;
	scanf("%d",&num);
	
	int sum=0;
	for(int i=0;i<num;++i){
		int num1,num2;
		scanf("%d %d",&num1,&num2);
		sum+=num2+1-num1;
	}
	
	printf("%d\n",sum);
	
	return 0;
}


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


int main(void){


	long long int n;
	long long int a[100001];
	long long int i,j;
	long long int b;

	long long int ret;

	long long int c[3]={};

	long long int mod;

	mod = 1000000007;

	scanf("%lld",&n);

	//R,G,Bいずれかの色

	for(i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}

//	c[0] = 1;
	ret = 1;

	for(i=0;i<n;i++){

		b = 0;

		for(j=0;j<3;j++){
			if(c[j] == a[i]){
				if(b == 0){ c[j]++;	}
				b++;
			}
		}

		ret = ( ret * b ) % mod;
//		printf("n:%d %d(b=%d)\n",i,ret,b);

	}

	printf("%lld\n",ret);


	return 0;
}



Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
int main() {
    long long int a,b;
    cin >> a >> b;
    
    long long int ans = 2019;
    for(long long int i=a; i <= min(b, a+2019);i++) {

        for(long long int j=a; j <= min(b,a+2019);j++) {

            if(i==j) continue;
            ans = min(ans, (i*j)%2019);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>


#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...)
#define showlr(n,l,r)
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

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

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;
/*------------end of definitions------------*/

string S;

bool MY=false,YM=false;

signed main(){

    in(S);
    if(0<stoi(S.substr(0,2))&&stoi(S.substr(0,2))<=12){
        MY=true;
    }
    if(0<stoi(S.substr(2,4))&&stoi(S.substr(2,4))<=12){
        YM=true;
    }

    if(MY&&YM){
        out("AMBIGUOUS");
    }else if(MY){
        out("MMYY");
    }else if(YM){
        out("YYMM");
    }else{
        out("NA");
    }

    return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
//using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;

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

#define INF 999999999;

#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

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

	lli A, B, K;
	lli eu, swap,cnt=0;
	cin >> A >> B >> K;
	while(1){
		if(A < B){
			swap = A;
			A = B;
			B = swap;
		}
		if(A%B == 0){
			eu = B;
			break;
		}else{
			A = A%B;
		}
	}

	for(lli k = eu; k >= 1; k--){
		if(eu%k == 0){
			cnt++;
			if(cnt == K){
				cout << k;
				break;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

void solve(){
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    REP(i,N) cin >> p[i];
    sort(p.begin(), p.end());
    int sum = 0;
    REP(i,K) sum += p[i];
    cout << sum << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}

Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<iomanip>
#include<limits>
#include<unordered_set> 
#include<cmath>
using namespace std;
//long long p = 998244353;
long long p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<pin,int>
#define V vector
#define Endl endl
#define veb vector<bool>
#define fcout cout << fixed << setprecision(15)
#define rev(s) reverse(s.begin(),s.end())
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int max_kai = 150000;
vel kai(max_kai, 1);
vel inv_kai;
int rui(int a, int n, int mod) {
    if (n == 0) { return 1 % mod; }
    int x = rui(a, n / 2, mod);
    x *= x; x %= mod;
    if (n % 2 == 1) { x *= a; x %= mod; }
    return x;
}
vel pa;
int root(int x) {
    if (pa[x] == -1) { return x; }
    int ans = root(pa[x]); pa[x] = ans;
    return ans;
}
void marge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) { pa[x] = y; }
}
int gcd(int x, int y) {
    if (x < y) { return gcd(y, x); }
    if (y == 0) { return x; }
    return gcd(y, x % y);
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
vel uni(vel x) {
    if (x.size() == 0) { return x; }
    sor(x);
    int n = x.size();
    vel ans(1, x[0]);
    for (int j = 1; j < n; j++) {
        if (x[j - 1] != x[j]) { ans.push_back(x[j]); }
    }
    x = ans;
    return x;
}
void pr(vel& v) {
    int n = v.size();
    if (n != 0) {
        cout << v[0];
        rep(i, n - 1) {
            cout << " " << v[i + 1];
        }
        cout << endl;
    }
}
int sol(int x, int k) {
    if (x == 0 || k == 0) { return 0; }
    return x + sol(x / 2, k - 1);
}
signed main(){
    int n; cin >> n;
    vel t;
    V<double> a;
    rep(i, n) {
        int t1; double a1;
        cin >> t1;
        cin >> a1;
        if (a1 > 0.5) {
            t.push_back(t1);
            a1 = 1 - 0.1 * a1;
            a.push_back(a1);
        }
    }
    int q; cin >> q;
    rep(i, q){
        int l, r; cin >> l >> r;
        l = lower_bound(t.begin(), t.end(), l)-t.begin();
        r = lower_bound(t.begin(), t.end(), r) - t.begin();
        if (r - l > 500) { cout << 0 << endl; }
        else {
            double ans = 1000000000;
            for (int i = l; i < r; i++) {
                ans *= a[i];
            }
            printf("%9.9lf", ans); cout << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 5788
k,b = gets.split.map(&:to_i)
house = gets.split.map(&:to_i)
dis = []
nhouse = house.size
nhouse.times {|i|
    if i + 1 == nhouse then
        dis << house[0]+k-house[i]
    else
        dis << house[i+1]-house[i]
    end
}
puts k - dis.max


Measured memory_bytes: 17084
S=input()
N=len(S)

b= ''.join(list(reversed(S)))
k=0
if S==''.join(list(reversed(S))):
    S1=S[:(N-1)//2]
    if S1==''.join(list(reversed(S1))):
        S2=S[(N+3)//2-1:]
        if S2==''.join(list(reversed(S2))):
            print("Yes")
            k=1
if k==0:
    print("No")

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

int main() {
#ifdef TEST
    freopen("test.txt", "r", stdin);
#endif // TEST

    int N, M, K;
//    pair<int, int> coord;
    vector<pair<int, int>> red, blue;
    while(cin >> N) {
        K = M = N;
        red.clear();
        blue.clear();
        bool vis[119];
        memset(vis, false, sizeof(vis));
        while(N--) {
            int x, y;
            cin >> x >> y;
            red.push_back(make_pair(x, y));
        }
        while(M--) {
            int x, y;
            cin >> x >> y;
            blue.push_back(make_pair(y, x));
        }
        int cnt = 0;
        sort(red.begin(), red.end());
        sort(blue.begin(), blue.end());
        pair<int, int> a, b;
        for(int i = 0; i < K; i++){
            bool flag = false;
            int tmp;
            for(int j = 0; j < K; j++){
                a = red[j], b = blue[i];
                if(red[j].first < blue[i].second && red[j].second < blue[i].first && !vis[j]){
//                    cnt++;
//                    vis[j] = true;
//                    break;
                    flag = true;
                    tmp = j;
                }
//                break;
            }
            if(flag){
                cnt++;
                vis[tmp] = true;
            }
        }
        cout << cnt << endl;
    }

    return 0;
}



Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);
 
    private void solve(Scanner sc) {
        int N = sc.nextInt();
        sc.nextLine();
        String s = sc.nextLine();
 
        StringBuilder sb = new StringBuilder(s);
        loop:
        while (true) {
            int cnt = 0;
            for (int i = 0; i < sb.length(); ++i) {
                if (sb.charAt(i) == ')') {
                    --cnt;
                } else {
                    ++cnt;
                }
                if (cnt < 0) {
                    sb.insert(0, '(');
                    continue loop;
                }
            }
            while (cnt > 0) {
                sb.append(')');
                --cnt;
            }
            if (cnt == 0) {
                break;
            }
        }
 
        _out.println(sb);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

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

conn = []
for _ in range(n):
    conn.append([False]*n)

visited = [False]*n #訪れたことのあるノード

#入力を元にconnを完成させる
v = []
for i in range(m):
    tmp = list(map(int, input().split()))
    v.append([x-1 for x in tmp])

#vを元にconnを作成
for start, end in v:
    conn[start][end] = conn[end][start] = True

def dfs(now, depth):
    if visited[now]:
        return 0
    if depth == n-1: #最後まで辿り着くことが出来た場合
        return 1

    visited[now] = True
    ret = 0

    for i in range(n):
        if conn[now][i]:
            ret += dfs(i, depth+1)

    visited[now] = False

    return ret

print(dfs(0, 0))


Measured memory_bytes: 3064
//by Top1
#include <bits/stdc++.h>
     
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
 
const int inf = INT_MAX;
const int mod = 1e9 + 7;
const int maxn = 6e5 + 111;
     
using namespace std;

int n, k, a[maxn], b[maxn], c[maxn], dp[5][maxn], q;

void solve(){    
	cin >> n;

	for (int i = 1; i <= n; i++)
		cin >> a[i] >> b[i] >> c[i];

	dp[1][1] = a[1];
	dp[2][1] = b[1];
	dp[3][1] = c[1];

	for (int i = 2; i <= n; i++){
		dp[1][i] = a[i] + max(dp[2][i - 1], dp[3][i - 1]);
		dp[2][i] = b[i] + max(dp[1][i - 1], dp[3][i - 1]);
		dp[3][i] = c[i] + max(dp[2][i - 1], dp[1][i - 1]);
	}

	cout << max(dp[1][n], max(dp[2][n], dp[3][n]));
}

main(){
    boost;
	    
	q = 1;

	while (q--){
		solve();
	}
}

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


int main() {
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3620
def main():
    import numpy as np
    A = np.array([[1, 0, 0, 1, 0, 0],
                  [1, 0, 0, 0, 1, 0],
                  [1, 0, 0, 0, 0, 1],
                  [0, 1, 0, 1, 0, 0],
                  [0, 1, 0, 0, 1, 0],
                  [0, 1, 0, 0, 0, 1],
                  [0, 0, 1, 1, 0, 0],
                  [0, 0, 1, 0, 1, 0],
                  [0, 0, 1, 0, 0, 1]])
    C = [[int(i) for i in input().split()] for j in range(3)]
    C = np.array(C)
    C = C.reshape([9, 1])
    ext_A = np.concatenate([A, C], axis=1)
    A_rank = np.linalg.matrix_rank(A)
    ext_A_rank = np.linalg.matrix_rank(ext_A)
    # 拡大係数行列と係数行列のrankが等しければ解が存在する
    if A_rank == ext_A_rank:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
    cin.tie(NULL);
    ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b and a!=c) or (a==c and a!=b)  or( b==c and b!=a))cout<<"Yes";
    else cout<<"No"; 

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
//#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
//#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<auto>& a,int n);
double PI = 3.14159265358979;
int n;


void P(auto a){
    REP(i,a.size()){
        if(i){
            cout << " ";
        }
        cout << a[i];
    }
    cout << "\n";
}


signed main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    cin >> n;
    vec(a,n);
    input(a,n);
    Sort(a);
    P(a);

    return 0;
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}

//key以上の初めてのitr
int nibul(auto a,auto b){return lower_bound(All(a),b) - a.begin();}
//key以下の最後のitr
int nibuu(auto a,auto b){return upper_bound(All(a),b) - a.begin()-1;}

void input(vector<auto>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}



Measured memory_bytes: 18464
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,res=0,cnt=0;
signed main()
{
	string s;
	cin>>s;
	n=s.length();
	s+='#';
	for(int i=0;i<=n;i++)
	{
		while(1)
		{
			if(s[i]=='A') cnt++,i++;
			else break;
		}
		if(s[i]=='B'&&s[i+1]=='C')
		res+=cnt,i=i+1;
		else cnt=0;
	}
	cout<<res;
}

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

using namespace std;
const int N=2e5+5;
int a[N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    int ans=0;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            for(int k=j+1;k<n;k++)
                if(a[i]!=a[j]&&a[i]!=a[k]&&a[j]!=a[k])
                    if(a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[j]+a[k]>a[i])
                        ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include<cstdio>

int A[1000000], n;

int binarySearch(int key)
{
	int left = 0, right = n, mid;

	while (left < right)
	{
		mid = (left + right) / 2;
		if (key == A[mid])
			return 1;
		else if (key < A[mid])
			right = mid;
		else if (key > A[mid])
			left = mid + 1;
	}

	return 0;
}

int main()
{
	int q, k, sum = 0;

	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &A[i]);

	scanf("%d", &q);
	for (int i = 0; i < q; i++)
	{
		scanf("%d", &k);
		if (binarySearch(k)) sum++;
	}
	printf("%d\n", sum);
}

Measured memory_bytes: 3052
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#include <iomanip>
#define rep(i,x) for(ll i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}/*フィボナッチテンプレ
ll memo[50];
ll fibo(ll n) {
    if (memo[n] != 0)return memo[n];
    if (n <= 1)return memo[n] = n;
    else return memo[n] = fibo(n - 1) + fibo(n - 2);
}
*/
int main() {
    ll N, M;
    cin >> N >> M;
    graph G(N);
    ll a, b;
    rep(i, M) {
        cin >> a >> b;
        G[a - 1].push_back(b - 1);
        G[b - 1].push_back(a - 1);
    }
    bool ok = false;
    for (auto x : G[0]) {
        for (auto y : G[x]) {
            if (y + 1 == N)ok = true;
        }
    }
    if (ok)cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 12776
import math
import fractions

A, B, C, D = map(int, input().split())
lcm = C * D // fractions.gcd(C, D)

count = 0
if A % C == 0:
    div_C = B // C - A // C + 1
else:
    div_C = B // C - A // C

if A % D == 0:
    div_D = B // D - A // D + 1
else:
    div_D = B // D - A // D

if A % lcm == 0:    
    div_C_D = B // lcm - A // lcm + 1
else:
    div_C_D = B // lcm - A // lcm

print(B - A + 1 - div_C - div_D + div_C_D)


Measured memory_bytes: 5052
N = int(input())
import math

ans = []

for i in range(1,round((N-1)**0.5)+1):
  if (N-1)%i == 0:
    ans.append(i)
    if (N-1)//i != i:
      ans.append((N-1)//i)

ans.remove(1)
ans.append(N)
for i in range(2,round(N**0.5)+1):
  if N%i == 0:
    n = N
    while n%i==0:
      n//=i
    if n%i==1:
      ans.append(i)

print(len(ans))


Measured memory_bytes: 64736
#define ENABLE_DEBUG 0
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(lint ngtkana_is_a_genius=0; ngtkana_is_a_genius<(lint)k; ngtkana_is_a_genius++)
using lint=long long;
using ld=long double;
template<class T> using numr=std::numeric_limits<T>;
struct input_t {
    template<class T> operator T() {
        T t;
        std::cin>>t;
        return t;
    }
} input;
#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

auto cmn=[](auto&x,auto y){if(x>y){x=y;return true;}return false;};

void err(){
    std::cout<<"No"<<'\n';
    exit(0);
}
int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    lint n=input;
    std::vector<std::pair<lint,lint>>a(n);
    for(lint i=0;i<n;i++){
        std::string s=input;

        lint now=0,min=0;
        for(char c:s){
            if(c=='(')now++;
            else now--;
            cmn(min, now);
        }
        a.at(i) = { -min, now-min };
    }
    DEBUG(a);

    std::sort(ALL(a), [](auto&&x, auto&&y){
        return std::min(-x.first, -x.first + x.second - y.first)
            >  std::min(-y.first, -y.first + y.second - x.first);
    });
    lint now=0;
    for(auto[x,y]:a){
        now-=x;
        if (now<0) err();
        now+=y;
    }
    if(now!=0)err();
    std::cout<<"Yes"<<'\n';
}


Measured memory_bytes: 19248
#include<cstdio>
#include<cstdlib>
#include<map>
using namespace std;

int a[100005], b[100005], num;

int main(){
	int n;
	map<int, int> d;

	scanf("%d", &n);
	while (n--) {
		int a;
		scanf("%d", &a);
		if (d.count(a) == 0) {
			d[a] = 1;
		} else {
			d[a]++;
		}
	}

	int ans = 0;
	for (auto a: d) {
		if (a.second % 2 == 1) ans++;
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 4864
n, k = map(int,input().split())
s = input()
if s[k-1] == 'A':
    print(s[:k-1] + 'a' + s[k:])
elif s[k-1] == 'B':
    print(s[:k-1] + 'b' + s[k:])
else:
    print(s[:k-1] + 'c' + s[k:])

Measured memory_bytes: 9020
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int n = sc.nextInt();
		int y = sc.nextInt();
		
		for(int i = 0; i <= n; i++) {
			for(int j = 0; j <= n-i; j++) {
				int k = n-i-j;
				
				if(i*10000+j*5000+k*1000 == y) {
					out.println(i + " " + j + " " + k);
					return;
				}
			}
		}
		out.println("-1 -1 -1");
	}

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

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static int lcm(int a, int b) {
		return (a * b) / gcd(a, b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }

    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 22356
# Is it a Right Triangle?

import sys

N = 0
datas = []

for (i, line) in enumerate(sys.stdin):
	if i == 0:
		N = int(line)
	else:
		datas.append([int(line.split()[0]), int(line.split()[1]), int(line.split()[2])])

for data in datas:
	index = data.index(max(data))
	x = data[index] * data[index]
	y = 0
	for i in [0, 1, 2]:
		if index == i:
			continue
		else:
			y += data[i] * data[i]
	if x == y:
		print "YES"
	else:
		print "NO"

Measured memory_bytes: 4300
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    let n: u64 = buf.trim().parse().unwrap();
    let div = (1..((n as f64).sqrt() + 1.0) as u64)
        .rev()
        .find(|x| n % x == 0)
        .unwrap();
    println!("{}", div + n / div - 2);
}


Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<utility>
using namespace std;
int n;
int a=0;
pair<pair<int,int>,int>x[1<<17];
main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x[i].first.first>>x[i].first.second>>x[i].second;
	}
	sort(x,x+n,[](pair<pair<int,int>,int>&a,pair<pair<int,int>,int>&b){
		return a.first.first+a.first.second<b.first.first+b.first.second;
	});
	for(int i=0;i<n;i++)
	{
		int now=0;
		int f=i,l=i;
		for(;f>=0;f--)
		{
			if(abs(x[f].first.first+x[f].first.second-
				x[i].first.first-x[i].first.second)>2)break;
		}
		for(;l<n;l++)
		{
			if(abs(x[l].first.first+x[l].first.second-
				x[i].first.first-x[i].first.second)>2)break;
		}
		for(int j=-1;j<=1;j+=2)for(int k=-1;k<=1;k+=2)
		{
			now=0;
			int lx=min(j,0),ux=max(j,0);
			int ly=min(k,0),uy=max(k,0);
			for(int u=f;u<=l;u++)
			{
				int dx=x[i].first.first-x[u].first.first;
				int dy=x[i].first.second-x[u].first.second;
				if(dx>=lx&&dx<=ux&&dy>=ly&&dy<=uy)now+=x[u].second;
			}
			a=max(a,now);
		}
	}
	cout<<a<<" / "<<1<<endl;
}



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

int cost(int i, int j, int x, int y) {
	return abs(x - i) + abs(y - j);
}

int main() {
	
	int h, w, d; cin >> h >> w >> d;
	vector<pair<int, int>> pa(h * w);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			int a; cin >> a;
			a--;
			pa[a].first = i;
			pa[a].second = j;
		}
	}
	vector<int> accum(h * w + 1, 0);
	for (int i = d + 1; i <= h * w; i++) {
		accum[i] += accum[i - d];
		accum[i] += cost(pa[i - 1].first, pa[i - 1].second, pa[i - 1 - d].first, pa[i - 1 - d].second);
	}
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		int l, r; cin >> l >> r;
		cout << accum[r] - accum[l] << endl;
	}
	return 0;
}

Measured memory_bytes: 4260
n=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
l.append(-1)
i=0
ma=0
while i<n:
    if l[i]==l[i+1] and ma==0:
        ma=l[i]
        i+=2
    elif l[i]==l[i+1] and ma!=0:
        print(ma*l[i])
        exit()
    else:
        i+=1
print(0)

Measured memory_bytes: 14224