akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef std::vector<vector<int> > vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pi> vpi;
#define debugone(x) cerr << #x << " " << x << "\n"; cerr.flush();
#define debugtwo(x) cerr << #x << "-------------" << "\n";for(auto &it: x) cerr << it << " ";cerr << "\n"; cerr.flush();
#define debugthree(x, i, j) cerr << #x << "------------" << "\n";cerr << "from " << i << " to " << j << "\n";for(ll k=i; k<=j; k++) cerr << x[k] << " ";cerr << "\n"; cerr.flush();
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
 
const ll mod = 1e9 + 7;
const ll inf = 1e11 + 5;
const int MaxN = 2e5 + 5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	ll n, m;
	cin >> n >> m;
	string s, t;
	cin >> s >> t;
	ll ans = (n * m) / __gcd(n, m);
	ll n1 = n / __gcd(n, m), m1 = m / __gcd(n, m);
	for(ll k = 0; k < n; k++){
		ll temp = m1 * k;
		if(temp % n1 == 0){
			ll l = temp / n1;
			if(l < m){
				if(s[k] != t[l]){
					cout << -1 << endl;
					return 0;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
export default solve;

// =================================================
// ABC086C
// =================================================

// reader
readline();

// main
function main(lines) {
  console.log(solve(lines));
}

// solver
function solve(lines: string[]): string {
  const { destinations } = parseLines(lines);

  let canArrive = true;
  loop: for (let i = 0; i < destinations.length; i++) {
    const [step, x, y] = destinations[i];
    const [previousStep, previousX, previousY] = destinations[i - 1] || [0, 0, 0];
    const distance = step - previousStep;
    const stepsToArrive = Math.abs(x - previousX) + Math.abs(y - previousY);
    if (distance % 2 !== stepsToArrive % 2 || distance < stepsToArrive) {
      canArrive = false;
      break loop;
    }
  }
  return canArrive ? 'Yes' : 'No';
}

// helpers
function parseLines(lines: string[]) {
  const N = +lines[0];
  const destinations = lines.slice(1, 1 + N).map(line => line.split(' ').map(s => +s));
  const obj = { N, destinations };
  debug(obj);
  return obj;
}

// general helpers
function debug(message?: any, ...optionalParams: any[]) {
  if (!!process.env.LOCAL_DEBUG) console.log(message, ...optionalParams);
}

function readline() {
  if (!process.env.LOCAL_DEBUG) {
    process.stdin.resume();
    process.stdin.setEncoding('utf8');
    const lines = [];
    require('readline')
      .createInterface({
        input: process.stdin,
        output: process.stdout,
      })
      .on('line', line => lines.push(line))
      .on('close', () => main(lines));
  }
}


Measured memory_bytes: 56196
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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


signed main(void) {
    int n;
    cin >> n;
    cout << n*(n-1)/2 << endl;
}


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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();


signed main()
{
	init();
	solve();
}

int N;

void init()
{
	cin >> N;
}


void solve()
{
	rep(i, N) {
		int t;
		cin >> t;
		if (t % 2) {
			cout << "first" << endl;
			return;
		}
	}
	cout << "second" << endl;
	
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 510000;
const double pi=acos(-1);

int main(){
  int n;
  cin >> n;
  int taro=0,hanako=0;
  rep(i,n){
    string s,t;
    cin >> s >> t;
    if(s>t)taro+=3;
    if(s<t)hanako+=3;
    if(s==t){
      taro++;
      hanako++;
    }
  }
  cout << taro << " " << hanako << endl;
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];
int32_t main(){_

   cin>>n;

   cout<<(n* (n-1)) / 2;

   // vector<int> a(n);
   // for (int i = 0; i < n; ++i)
   // {
   //    a[i] = i + 1;
   // }

   // int vals = 0;
   // vector<int> ans;
   // do{

   //    int sum = 0;
   //    for (int i = 0; i < n; ++i)
   //    {
   //       sum += (i+1) % a[i];
   //    }

   //    if(sum > vals){
   //       vals = sum;
   //       ans = a;
   //    }

   // }while(next_permutation(a.begin(), a.end()));
   
   // tr(vals, a);

   return 0;
}


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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, m, n) for (ll i = (m); i < (n); i++)
#define FORR(i, m, n) for (ll i = (m); i >= (n); i--)
#define INF 1e9
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((ll)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<ll> a(n), b(n), c(n);
    ll res = 0;
    REP(i, n)
    {
        cin >> a[i];
    }
    REP(i, n)
    {
        cin >> b[i];
        res += b[i];
    }
    REP(i, n - 1)
    {
        cin >> c[i];
    }
    FOR(i, 0, n - 1)
    {
        if (a[i] == a[i + 1] - 1)
        {
            res += c[a[i] - 1];
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
//import java.util.Map.Entry;
//import java.util.stream.*;
//import java.math.*;

public class Main {

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

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner sc = new Scanner(System.in);
        long MOD = (long) (Math.pow(10, 9) + 7);
        int n = sc.nextInt();
        long max = Integer.MAX_VALUE;
        int array[] = new int[n];
        long sum = 0, s = 0;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
            sum += array[i];
        }
        for (int i = 0; i < n; i++) {
            s += array[i];
            if (i + 1 < n) {
                max = Math.min(max, Math.abs(sum - 2 * s));
            }
        }
        System.out.println(max);
        bw.flush();
    }
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//
//==============================================//

    static class Pair implements Comparable<Pair> {

        int a, b;

        public Pair(int x, int y) {
            a = x;
            b = y;
        }

        @Override
        public int compareTo(Pair p) {
            return a - p.a;
        }
    }

    static void forl_0(int n, int[] array, Scanner sc) {
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
    }

    static void forl_1(int n, int[] array, Scanner sc) {
        for (int i = 1; i <= n; i++) {
            array[i] = sc.nextInt();
        }
    }

    static void two_d(int n, int m, int[][] array, Scanner sc) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                array[i][j] = sc.nextInt();
            }
        }
    }

    static boolean isPrime(long n) {
        if (n < 2) {
            return false;
        } else if (n == 2 || n == 3) {
            return true;
        } else if (n % 2 == 0 || n % 3 == 0) {
            return false;
        }
        long sqrtN = (long) Math.sqrt(n) + 1;
        for (long i = 6L; i <= sqrtN; i += 6) {
            if (n % (i - 1) == 0 || n % (i + 1) == 0) {
                return false;
            }
        }
        return true;
    }

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

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


Measured memory_bytes: 50164
N = int(input())
row1 = list(map(int,input().split()))
row2 = list(map(int,input().split()))
res = 0
for i in range(N):
    now_res = sum(row1[:N-i])+sum(row2[N-i-1:])
    res = max(now_res, res)
print(res)

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

int main(){
    int s;
    cin >> s;
    int h;
    int m;
    h=s/3600;
    m=(s%3600)/60;
    s=(s%3600)%60;

    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
const int MOD = 1000000007;


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

    vector<vector<ll>> wv(4, vector<ll>());
    ll w0;
    rep(i,N){
        ll w, v; cin >> w >> v;
        if (i==0) {
            wv[0].push_back(v);
            w0 = w;
        }
        else {
            wv[w-w0].push_back(v);
        }
    }

    rep(i,4){
        sort(wv[i].begin(), wv[i].end(), greater<ll>());
    }

    vector<vector<ll>> s(4, vector<ll>(N+1,0));
    rep(i, 4){
        rep(j, wv[i].size()){
            s[i][j+1] = s[i][j] + wv[i][j];
        }
    }
 
    ll ans = 0;
    for(int i = 0; i <= wv[0].size(); i++){
        for (int j = 0; j <= wv[1].size(); j++){
            for (int k = 0; k <= wv[2].size(); k++){
                for (int l = 0; l <= wv[3].size(); l++){
                    ll value = s[0][i] + s[1][j] + s[2][k] + s[3][l];
                    ll weight = i*w0 + j*(w0+1) + k*(w0+2) + l*(w0+3);
                    if (weight <= W){
                        ans = max(ans, value);
                    }
                }
            }
        }
    }
    cout << ans << endl;

}

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

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

    int n, m;
    cin >> n >> m;
    vector<vector<int> > graph(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    vector<int> dist(n, -1);
    queue<int> que;
    vector<int> pre(n, -1);

    dist[0] = 0;
    que.push(0);

    while(!que.empty()) {
        int v = que.front();
        que.pop();
        for (int u : graph[v]) {
            if (dist[u] != -1)
                continue ;
            dist[u] = dist[v] + 1;
            que.push(u);
            pre[u] = v;
        }
    }

    cout << "Yes" << endl;
    for (int i = 1; i < n; ++i)
        cout << pre[i] + 1 << '\n';
    return 0;
}

Measured memory_bytes: 10656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

template <class T>
T inf = numeric_limits<T>::max();

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

  ll N,P;
  ll ans = 0;
  cin >> N >> P;
  string S;
  cin >> S;

  if (P == 2) {
    for (int i = 1; i <= N; ++i) {
      int num = S[i-1] - '0';
      if (num % 2 == 0) {
        ans += i;
      }
    }
  } else if (P == 5) {
    for (int i = 1; i <= N; ++i) {
      int num = S[i-1] - '0';
      if (num == 0 || num == 5) {
        ans += i;
      }
    }
  } else {
    vector<ll> val(P+1, 0);
    val[0] ++;
    ll cur = 0;
    ll fac = 1;
    reverse(S.begin(), S.end());
    for (int i = 0; i < N; ++i) {
      ll num = S[i] - '0';
      cur = (cur + num * fac) % P;
      fac = (fac * 10) % P;
      val[cur] += 1;
    }
    for (auto itr : val) {
      ans += itr * (itr - 1) / 2;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3756
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

std::vector<int> divisorList(int n) {
	assert(1 <= n);
	std::vector<int> result;
	result.emplace_back(1);
	result.emplace_back(n);
	int a = 2;
	while(a * a <= n) {
		if(n % a == 0) {
			result.emplace_back(a);
			result.emplace_back(n / a);
		}
		a++;
	}
	int size = result.size();
	if(result[size - 2] == result[size - 1]) {
		result.pop_back();
	}
	return result;
}

int main() {
	int N, X;
	std::cin >> N >> X;

	std::vector<int> disList(N);
	int min = std::numeric_limits<int>::max();
	for(int i = 0; i < N; i++) {
		int x;
		std::cin >> x;
		disList[i] = std::abs(x - X);
		if(disList[i] < min) {
			min = disList[i];
		}
	}

	auto list = divisorList(min);
	std::sort(list.begin(), list.end(), [](const int a, const int b) {
		return a > b;
	});

	for(const auto n : list) {
		const bool ok = std::all_of(disList.begin(), disList.end(), [&](const int dis) {
			return dis % n == 0;
		});
		if(ok) {
			std::cout << n << std::endl;
			break;
		}
	}

	return 0;
}

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

bool w[35], ss[3005];
vector<int> s;

int main() {
  int a,b,c,d,e,f;
  scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
  for(int i=0;i<=f;i+=100*a) w[i/100] = true;
  for(int i=0;i<=f;i+=100*b) w[i/100] = true;
  for(int i=0;i<=f;i+=c) ss[i] = true;
  for(int i=f;i>=0;i--) {
    if(!ss[i]) continue;
    for(int j=i;j<=f;j+=d) ss[j] = true;
  }
  for(int i=0;i<=f;i++)
    if(ss[i]) s.push_back(i);
  int ai=100*a, aj = 0;
  for(int i=1;i*100<=f;i++) {
    if(!w[i]) continue;
    for(int j : s) {
      if(j > i*e || i*100+j > f) break;
      int ii = i*100;
      if(aj*(ii+j) < j*(ai+aj)) {
        ai = ii;
        aj = j;
      }
    }
  }
  printf("%d %d\n",ai+aj, aj);
}


Measured memory_bytes: 256
const main = (input: string) => {
  const lines = input.trim().split("\n")
  const N = parseInt(lines[0])
  const A = lines[1].split(" ").map(str => parseInt(str))
  A.sort((a, b) => a - b)

  for (let i = 1; i < N; i++) {
    if(A[i] === A[i - 1]) {
      console.log("NO")
      process.exit(0)
    }
  }

  console.log("YES")  
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 34460
import heapq

N = int(input())

es = [[] for _ in range(N)]
for _ in range(N-1):
    a,b = map(int, input().split())
    es[a-1].append(b-1)
    es[b-1].append(a-1)

INF = float("inf")


# ダイクストラでフェネック君の開始地点からの距離を探索
dist_f = [INF] * N
dist_f[0] = 0
q = [(0,0)]
while q:
    cost, curr = heapq.heappop(q)
    if dist_f[curr] < cost:
        continue
    for nxt in es[curr]:
        if dist_f[nxt] < dist_f[curr] + 1:
            continue
        dist_f[nxt] = dist_f[curr] + 1
        heapq.heappush(q, (dist_f[nxt], nxt))

# ダイクストラですぬけ君の開始地点からの距離を探索
dist_s = [INF] * N
dist_s[N-1] = 0
q = [(0,N-1)]
while q:
    cost, curr = heapq.heappop(q)
    if dist_s[curr] < cost:
        continue
    for nxt in es[curr]:
        if dist_s[nxt] < dist_s[curr] + 1:
            continue
        dist_s[nxt] = dist_s[curr] + 1
        heapq.heappush(q, (dist_s[nxt], nxt))

cnt_f = 0
cnt_s = 0
for i in range(1,N-1):
    if dist_f[i] <= dist_s[i]:
        cnt_f += 1
    else:
        cnt_s += 1

if cnt_f > cnt_s:
    print("Fennec")
else:
    print("Snuke")



Measured memory_bytes: 98412
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<limits.h>

int main(){
	
	char s[25];
	scanf("%s",s);
	
	s[5]=' ';
	s[13]=' ';
	
	printf("%s\n",s);
	
	
	return 0;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

const string YES = "Yes";
const string NO = "No";

typedef struct UnionFind{
    vector<lli> par; //par[i]:iの親番号 par[3] = 2 : 3の親が2
    vector<lli> size;//size[i]:iの大きさ 自分のみのときは1,根っこにsizeを持たせる*/

    UnionFind(int N){/*最初はすべてが根であると初期化*/
        REP(i,0,N){
            par.push_back(i);
            size.push_back(1);
        }
    }

    lli root(lli x){/*データxが属する木の根を再起で得る root(x) = {xの木の根}}*/
        if(par[x] == x)return x;
        return par[x] = root(par[x]);
    }

    void unite(lli x,lli y){/*xとyの併合*/
        lli rx = root(x);
        lli ry = root(y);
        if(rx == ry)return;
        par[rx] = ry; /*xとyの根が同じじゃない: xの根をrxをyの根ryに変更する */
        lli resize = size[rx] + size[ry];
        size[rx] = resize;
        size[ry] = resize;
    }

    bool same(lli x,lli y){
        lli rx = root(x);
        lli ry = root(y);
        return rx == ry;
    }

    lli getSize(lli x){
        lli rx = root(x);
        return size[rx];
    }
};

map<lli,queue<lli>> d;

void func(long long N, std::vector<long long> A, std::vector<long long> B){

    vector<pair<lli,lli>> v;
    REP(i,0,N)v.push_back({B[i],A[i]});

    SORT(v);
    SORT(A);

    bool ok = true;
    lli cnt = 0;
    REP(i,0,N){
        if(A[i] > v[i].first)ok = false;
    }

    if(!ok){
        cout<<NO<<endl;
        return;
    }

    REP(i,0,N-1){
        if(A[i+1] <= v[i].first){
            cout<<YES<<endl;
            return;
        }
    }

    REP(i,0,N){
        d[A[i]].push(i);
    }
    UnionFind uf(N);

    REP(i,0,N){
        lli nex = d[v[i].second].front();
        d[v[i].second].pop();
        uf.unite(i,nex);
    }
    set<lli> roots;
    REP(i,0,N){
        roots.insert(uf.root(i));
    }
    if(roots.size()==1){
        cout<<NO<<endl;
    }
    else{
        cout<<YES<<endl;
    }
}

int main(){
    // cout << fixed << setprecision(5);

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


Measured memory_bytes: 78832
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
int main(){
  string s;
  cin>>s;
  stack<int> data;
  int cnt=0;
  for(int i=0;i<s.size();i++){
    int num=s.at(i)-48;
    //cout<<num<<endl;
    data.push(num);
    if(data.size()>=2){
      int v=data.top();
      data.pop();
      int u=data.top();
      data.pop();
      if(v*u==0&&(v==1||u==1)){
        cnt++;
      }else{
        data.push(u);
        data.push(v);
      }
    }
  }
  cout<<cnt*2<<endl;
}

Measured memory_bytes: 768
#include <iostream>
using namespace std;
#define N 100
static const int infinity =(1<<21);
static const int white =0;
static const int gray = 1;
static const int black =2;

int n,M[N][N];

void dijkstra(){
    int min,u;
    int color[N],d[N];
    
    for(int i=0;i<n;i++){
        color[i]=white;
        d[i]=infinity;
    }
    
    d[0]=0;
    
    while(1){
        min=infinity;
        int u=-1;
        for(int i=0;i<n;i++){
            if(color[i]!=black&&d[i]<min){
                min=d[i];
                u=i;
            }
        }
        if(min==infinity)break;
        
        color[u]=black;
        
        for(int v=0;v<n;v++){
            if(color[v]!=black&&M[u][v]!=infinity){
                if(d[u]+M[u][v]<d[v]){
                    d[v]=d[u]+M[u][v];
                    color[v]=gray;
                }
            }
        }
    }
    for(int i=0;i<n;i++)cout<<i<<" "<<d[i]<<endl;
}

int main(){
    cin>>n;
    int u,k,v,c;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++)M[i][j]=infinity;
    }
    for(int i=0;i<n;i++){
        cin>>u>>k;
        for(int j=0;j<k;j++){
            cin>>v>>c;
            M[u][v]=c;
        }
    }
    
    dijkstra();
    
}


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

int main()
{
	int N, K;
	scanf("%d%d", &N, &K);
	std::vector<int64_t> a(N);
	for (auto& e: a) scanf("%lld", &e);
	std::vector<int64_t> beauty;
	beauty.reserve(N * N);
	for (int i{}; i < N; i++)
	{
		int64_t sum{};
		for (int j{i}; j < N; j++)
		{
			sum += a[j];
			beauty.push_back(sum);
		}
	}
	
	int64_t ans{};
	for (int i{40}; i >= 0; i--)
	{
		std::sort(beauty.rbegin(), beauty.rend());
		if (beauty[K - 1] >> i & 1)
		{
			ans += 1ll << i;
			while (~beauty.back() >> i & 1) beauty.pop_back();
		}
		for (auto& e: beauty)
			e &= -1 ^ (1ll << i);
	}
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 5632
#include <cstdio>
#include <cstring>

int main()
{
	int d;
	scanf("%d", &d);
	
	switch (d)
	{
	case 22:
		printf("Christmas Eve Eve Eve\n");
		
		break;
		
	case 23:
		printf("Christmas Eve Eve\n");
		break;
	case 24:
		printf("Christmas Eve\n");
		break;
	case 25:
		printf("Christmas\n");
		break;
	}
	return 0;
}

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

#define ll long long
#define ld long double
#define pb push_back
#define popb pop_back
#define beg begin()
#define en end()
#define sz(v) (int)((v).size())
#define all(v) (v).begin(),(v).end()
#define ff first
#define ss second
#define endl "\n"
#define forn(i,a,n) for(int i=a;i<int(n);++i)
#define forb(i,a,n) for(int i=int(n)-1;i>=a;--i)
#define cout(ans) cout<< ans << "\n"
void speed()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    cout.tie(NULL);
}

vector<int>adj[200005];
int in_degree[200005],d[200005],vis[200005];

void dfs(int v)
{
	vis[v]=1;
	for(auto u:adj[v])
	{
		d[u]=max(d[u],d[v]+1);
		in_degree[u]--;
		if(in_degree[u]==0)
		{
			dfs(u);
		}
	}
}

void solve()
{
	int n,m;cin>>n>>m;
	int x,y;
	forn(i,0,m)
	{
		cin>>x>>y;
		x--;y--;
		adj[x].pb(y);
		in_degree[y]++;
	}
	forn(i,0,n)
	{
		if(!vis[i] && in_degree[i]==0)
		{
			dfs(i);
		}
	}
	int ans=0;
	forn(i,0,n)
	{
		ans=max(ans,d[i]);
	}
	cout(ans);

}


int main()
{   
    speed();
    //int tc;cin>>tc;
    //while(tc--)
    {
        solve();
    }
}

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

using namespace std;

#define ll long long
#define ar array

ll K;

void solve(){

    cin >> K; 

    ll mod = 7;
    int ans = -1;
    for (int i = 1; i < K+1; i++)
    {
        mod = mod % K;
        if(mod == 0){
            ans = i;
            break;
        }
        mod = mod*10+7;
    }
    
    cout << ans << endl;
}





int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}

Measured memory_bytes: 3652
from collections import defaultdict
n=int(input())
ans=defaultdict(int)
for _ in range(n):
  s=str(input())
  c=ans.get(s)
  if c:
  	ans.update({s:c+1})
  else:
    ans.update({s:1})
print("AC x ",ans["AC"])
print("WA x ",ans["WA"])
print("TLE x ",ans["TLE"])
print("RE x ",ans["RE"])

Measured memory_bytes: 9480
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for(int i = a; i < n; ++i)
#define pb push_back
#define mp make_pair
#define f first
//#define sex second

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <set>
#include <ostream>
#include <queue>
#include <functional>
#include <sstream>
#include <map>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
#pragma comment(linker, "/STACK:228228000")
const ll mod = 9982443530;

ll a, b;

int main()
{
	/*

	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	*/

	cin >> a >> b;
	ll res = 1;
	forn(i, 0, a)
	{
		res *= 100;
	}
	
	if (b == 100)
		res = res + res*b;
	else
		res *= b;
	cout << res;


	return 0;
}


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

using namespace std;

inline void quit(){ exit(0); }

typedef long long ll;

ll mpow(ll _x, ll _y, ll _mod){
    if(_y==0) return 1;
    if(_y==1) return _x%_mod;
    if(_y&1) return (mpow(_x, _y-1, _mod)*_x)%_mod;
    ll _tmp = mpow(_x, _y>>1, _mod);
    return (_tmp*_tmp)%_mod;
}

int n;

int main(){
    cin>>n;
    cout<<(n*n*n);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<climits>
using namespace std;

int main() {
  int cnt=0;
  string S;
  string tmp;

  cin >> S;

  tmp=S;
  while(tmp.size()>=5){
    if(tmp.substr(0,5)=="dream"){
      tmp=tmp.substr(5);
      if(tmp.substr(0,2)=="er"  && tmp.substr(0,5) != "erase"){
        tmp=tmp.substr(2);
      }

      if(tmp.size()==0){
        cout << "YES"<< endl;
      }
      
    }
    else if(tmp.substr(0,5)=="erase" ){
      tmp=tmp.substr(5);
      
      if(tmp.substr(0,1)=="r"  && tmp.substr(0,4) != "rase"){
        tmp=tmp.substr(1);
      }

      if(tmp.size()==0){
        cout << "YES"<< endl;
      }
    }
    else{
      cout << "NO" << endl;
      break;
    }

  }
  if(tmp.size()<5 && tmp.size()!=0){
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 640
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    String ans = "No";
    for(int i = 1; i < 10; i++){
      if(A%i == 0 && A/i < 10){
        ans = "Yes";
      }
    }
    System.out.println(ans);
  }
}

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

using namespace std;

template<typename S, typename T>
ostream& operator<<(ostream& out, const pair<S, T> p) {
    out << "(" << p.first << "," << p.second << ")";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
    for (auto a: v)
        out << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const set<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename T>
ostream& operator<<(ostream& out, const multiset<T>& S) {
    for (auto a: S)
        cout << a << " ";
    return out;
}

template<typename S, typename T>
ostream& operator<<(ostream& out, const map<S, T>& M) {
    for (auto m: M)
        cout << "(" << m.first << "->" << m.second << ") ";
    return out;
}

template<typename S, typename T>
pair<S, T> operator+(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename S, typename T>
pair<S, T> operator-(pair<S, T> a, pair<S, T> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m;
    string str;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> str;
        cout << str << '\n';
        cout << str << '\n';
    }
    return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

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

    int N;
    std::cin >> N;

    int H[30];
    int c = 0;

    for(int i=0;i<N;++i){
        std::cin >> H[i];

        if(*std::max_element(H, H + i + 1) == H[i]){
            c += 1;
        }
    }

    std::cout << c << std::endl;
}


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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;
constexpr ll mo2 = 998244353;
vector<int> E[100050];
vector<bool> t(100050,true);
vector<ll> h(100050);
void dfs(int u,int pre){
    if(!t[u])return;
    for(auto v : E[u])if(pre != v){
        if(h[u] > h[v]) t[v] = false;
        else t[u] = false;
        dfs(v,u);
    }
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;++i) cin>>h[i];
    for(int i=0;i<m;++i){
        int x,y;
        cin>>x>>y;
        x--;y--;
        E[x].push_back(y);
        E[y].push_back(x);
    }
    for(int i=0;i<n;++i)dfs(i,-1);
    int count = 0;
    for(int i=0;i<n;++i)if(t[i])count++;
    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 9272
#include<stdio.h>
int main()
{
    int a;
    char s[101];
    // 整数の入力
    scanf("%d", &a);
    // 文字列の入力
    scanf("%s",s);
    // 出力
  	if (a >= 3200){
	    printf("%s",s);
    }else{
        printf("red");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<ll,int> pli;
typedef pair<int,int> ii;
typedef pair<int,ll> pil;
typedef vector<pil> vpil;
typedef pair<ii,ll> piil;
vector<vpil> graph;
vector<piil> edge;
int n,m;
int s,t;
vector<ll> ds,dt;
vector<ll> cnts,cntt;
const ll mod = 1e9 + 7;
void dijkstra(int start,vector<ll> &d,vector<ll> &cnt)
{
	cnt.assign(n+1,0ll);
	d.assign(n+1,-1);
	d[start] = 0ll;
	cnt[start] = 1ll;
	priority_queue<pli,vector<pli>,greater<pli> > pq;
	pq.push(pli(0ll,start));
	while(!pq.empty())
	{
		pli p = pq.top();pq.pop();
		ll x = p.first;
		int y = p.second;
		if(x==d[y])
		{
			for(int i=0;i<graph[y].size();++i)
			{
				pil q = graph[y][i];
				if(d[q.first]==-1 || d[q.first] > d[y] + q.second)
				{
					cnt[q.first] = cnt[y];
					d[q.first] = d[y] + q.second;
					pq.push(pli(d[q.first],q.first));
				}
				else if(d[q.first]==d[y]+q.second)
				{
					cnt[q.first] = (cnt[q.first] + cnt[y])%mod;
				}
			}
		}
	}
} 
int main()
{
	int i,x,y;
	ll w;
	scanf("%d %d",&n,&m);
	scanf("%d %d",&s,&t);
	graph.assign(n+1,vpil());
	for(i=0;i<m;++i)
	{
		scanf("%d %d %lld",&x,&y,&w);
		graph[x].push_back(pil(y,w));
		graph[y].push_back(pil(x,w));
		edge.push_back(piil(ii(x,y),w));
	}
	dijkstra(s,ds,cnts);
	dijkstra(t,dt,cntt);
	ll dist = ds[t];
	ll ans = cntt[s] * cntt[s] % mod;
	for(i=0;i<m;++i)
	{
		piil k = edge[i];
		x = k.first.first;
		y = k.first.second;
		w = k.second;
		if(dt[x]*2 < dist && ds[y] *2 < dist && dt[x] + ds[y] + w == dist)
		{
			ans = (ans - cntt[x] * cntt[x] % mod * cnts[y] %mod * cnts[y] % mod + mod) % mod; 
		}
		if(dt[y]*2 < dist && ds[x] *2 < dist && dt[y] + ds[x] + w == dist)
		{
			ans = (ans - cntt[y] * cntt[y] % mod * cnts[x] %mod * cnts[x] % mod + mod) % mod; 
		}
	}
	for(i=1;i<=n;++i)
	{
		if(dt[i]*2==dist && ds[i]*2==dist)
		{
			ans = (ans - cntt[i] * cntt[i] % mod * cnts[i] %mod * cnts[i] % mod + mod) % mod;
		}
	}
	printf("%lld",ans);
}
/*
4 5
1 4
1 2 1
1 3 1
2 3 1
2 4 1
3 4 1
*/
/*
4 4
1 4
1 2 3
1 3 1
2 3 2
2 4 10
*/




Measured memory_bytes: 24804
#!usr/bin/env python3
 
import sys
 
 
def main():
    WINNING_HANDS = [
                '111', '222', '333', '444', '555', '666', '777', '888', '999',
                '123', '234', '345', '456', '567', '678', '789'
            ]
 
    num_of_datasets = int(sys.stdin.readline().strip('\n'))
    datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
    results = list()
 
    for dataset in range(num_of_datasets):
        n_set = [num for num in sys.stdin.readline().strip('\n').split()]
        c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
        for idx, colour in enumerate(c_set):
            if colour == 'R':
                datasets[dataset]['R'].append(n_set[idx])
            elif colour == 'G':
                datasets[dataset]['G'].append(n_set[idx])
            elif colour == 'B':
                datasets[dataset]['B'].append(n_set[idx])
 
        match_count = int()
 
        for rgb_key in datasets[dataset]:
            nums = sorted(datasets[dataset][rgb_key])
 
            for hand in WINNING_HANDS:
                while hand[0] in nums and hand[1] in nums and hand[2] in nums:
                    tmp = nums.copy()
                    if hand[0] in tmp:
                        tmp.pop(tmp.index(hand[0]))
                        if hand[1] in tmp:
                            tmp.pop(tmp.index(hand[1]))
                            if hand[2] in tmp:
                                tmp.pop(tmp.index(hand[2]))
                                match_count += 1
                                nums = tmp
                            else:
                                break
                        else:
                            break
                    else:
                        break
 
                    if match_count == 3:
                        results.append(1)
                        continue
 
        if dataset < num_of_datasets and match_count != 3:
            results.append(0)
 
    for result in results:
        print(result)
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 7740
while 1:
    r, c = map(int, raw_input().split())
    if r == 0: break
    old = [raw_input().split() for i in range(r)]
    old = map(list, zip(*old))
    new = [int("".join(lst),2) for lst in old]
    ans = 0
    for i in range(1<<(r-1)):
        ret = 0
        for j in new:
            cnt = bin(i^j).count('1')
            ret += cnt if cnt > r/2 else r-cnt
        ans = max(ans, ret)
    print ans

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

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a, b)      (a * (b / __gcd(a,b)))  
#define inf           (long long )(1e18+1)
#define endl          '\n'
#define mp            make_pair
#define time(s)       (double(clock()-s)/double(CLOCKS_PER_SEC))
#define debug(args...)    _F(#args, args)
#define vi            std::vector<int>
#define pii           pair<int, int> 
#define vpi           vector<pii >

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

template<typename T> void _F(const char *name, T arg1){
    cerr << name << " = " << arg1 << endl;
}
template<typename T, typename... Args> void _F(const char *names, T arg1, Args... args){
    const char *name = strchr(names, ',');cerr.write(names, name-names) << " = " << arg1 << endl;_F(name+2, args...);
}
template<typename T1, typename T2> istream& operator>>(istream& in, pair<T1, T2> &q){ 
    in >> q.F >> q.S; return in;
}
template<typename T1, typename T2> ostream& operator<<(ostream& out, pair<T1, T2> &q){
    out << q.F << " " << q.S; return out;
}
template< typename T1, typename T2> pair<T1, T2> operator+(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F+p2.F, p1.S+p2.S};
}
template< typename T1, typename T2> pair<T1, T2> operator-(pair<T1, T2> p1, pair<T1, T2> p2){
    return {p1.F-p2.F, p1.S-p2.S};
}

void solve() {
    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i]--;
    }
    int st = 0;
    vi v;
    int pos[n];
    memset(pos, -1, sizeof(pos));
    int cur = 0;
    while(true){
        if(k == 0){
            cout << st+1 << endl;
            return;
        }
        if(pos[st] != -1){
            break;
        }
        //cout << st << " s " << k << endl;
        v.pb(st);
        pos[st] = cur;
        st = a[st];
        k--;
        cur++;
         //cout << st << " e " << k << endl;
    }
    vi tmp;
    for(int i = pos[st]; i < si(v); i++){
        tmp.pb(v[i]);
    }
    cout << tmp[k%si(tmp)]+1 << endl;
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   

    int t = 1;
    start = clock(); 

    cout << fixed << setprecision(20);

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin); 
    // freopen("output.txt", "w", stdout);
    // freopen("error.txt", "w", stderr);
    // #endif
   
    //cin >> t;
    
    for(int i = 1; i <= t; ++i){
        //cout << "Case #" << i << ": "; 
        solve();
        //cout << endl;
    }
    //cerr << time(start);
    return 0;
}

Measured memory_bytes: 9384
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var scaner = new Scanner();

        var n = scaner.ReadInt();
        var s = scaner.ReadStrArray(n);

        for (int i = 0; i < s.Length; i++)
        {
            s[i] = new string(s[i].OrderBy(c => c).ToArray());
        }

        var l = s.GroupBy(x => x);
        ulong ans = 0;
        foreach (var g in l)
        {
            var count = Convert.ToUInt64(g.Count());
            ans += count * (count - 1) / 2;
        }

        Console.WriteLine(ans);
    }
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }

    public string ReadStr()
    {
        return this.Next();
    }

    public char ReadChar()
    {
        return this.Next()[0];
    }

    public int ReadInt()
    {
        return int.Parse(this.Next());
    }

    public long ReadLong()
    {
        return long.Parse(this.Next());
    }

    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }

    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }

    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }

    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}

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

const int MAX = 500, INF = 1e8;

int dp[MAX][MAX];

int main(){
  int N, Ma, Mb; cin >> N >> Ma >> Mb;
  for(int i = 0; i < MAX; i++){
    for(int j = 0; j < MAX; j++){
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;
  
  int am = 0, bm = 0;
  for(int i = 0; i < N; i++){
    int a, b, c; cin >> a >> b >> c;
    for(int j = am; j >= 0; j--){
      for(int k = bm; k >= 0; k--){
        if(dp[j][k] < INF)
          dp[j + a][k + b] = min(dp[j + a][k + b], dp[j][k] + c);
      }
    }
    am += a; bm += b;
  }
  
  int mul = 1, ans = INF;
  while(Ma * mul <= am && Mb * mul <= bm){
    ans = min(ans, dp[Ma*mul][Mb*mul]);
    mul++;
  }
  cout << (ans < INF?ans:-1) << endl;
}

Measured memory_bytes: 1280
# -*- coding: utf-8 -*-

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

B = [0] * N
for i in range(N):
    B[i] = A[i] - i
C = Counter(B)
offset = 0
ans = 0
for i in range(N-1):
    C[B[i]] -= 1
    ans += C[-A[i]+offset]
    offset -= 1
print(ans)


Measured memory_bytes: 42672
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //99844353;
const int N = 3e3+1;
int n;
map<string, int> m;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  int d = 0;
  FOR(i, 0, n){
    string s;
    int a;
    cin >> s >> a;
    d += a;
    m[s] = d;
  }
  string s;
  cin >> s;
  cout << d-m[s] << endl;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
a = np.array(LIST())
a = np.bincount(a)
b = a.copy()
b[1:] += a[:-1]
b[:-1] += a[1:]
print(b.max())


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

int main() {
    int n;
    double x1, y1, x2, y2, x3, y3;
    double px, py, r;
    
    cin >> n;
    while(n){
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        px = ((y1 - y3) * (y1 * y1 - y2 * y2 + x1 * x1 - x2 * x2) - (y1 - y2) * (y1 * y1 - y3 * y3 + x1 * x1 - x3 * x3)) / (2 * (y1 - y3) * (x1 - x2) - 2 * (y1 - y2) * (x1 - x3));
        py = ((x1 - x3) * (x1 * x1 - x2 * x2 + y1 * y1 - y2 * y2) - (x1 - x2) * (x1 * x1 - x3 * x3 + y1 * y1 - y3 * y3)) / (2 * (x1 - x3) * (y1 - y2) - 2 * (x1 - x2) * (y1 - y3));
        r = sqrt((x1 - px) * (x1 - px) + (y1 - py) * (y1 - py));
        
        n--;

        printf("%.3f %.3f %.3f\n", px, py, r);
    }
    return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 2e5 + 11;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


ll n, a, b, ans;

main () {
	cin >> n >> a >> b;
	if ((a & 1) == (b & 1)) {
		cout << (b - a) / 2;
		return 0;
	}			

	//
	int ans = INF*5;
	int x = a - 1;
	ans = min(ans, x + ((b - x) - 1) / 2);	
	x = n - b;
	ans = min(ans, x + (n - (a + x)) / 2);
	cout << ans + 1 << endl;
}


Measured memory_bytes: 256