akhauriyash/Code-Regression huggingface dataset:
//  यस्य स्मरणमात्रेण जन्मसंसारबन्धनात् ।  विमुच्यते नमस्तस्मै विष्णवे प्रभविष्णवे ॥
 
 
 
/****
*     Author- Indrajeet Mishra
*             MNNIT Allahabad, Prayagraj
*             Chemical Engineering undergraduate
 
 
 
****/
 
#pragma warning(disable:4996)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
 
#include <bits/stdc++.h>
#define ll long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define test(s) if (!(s)) { cout << __LINE__ << " " << #s << endl; exit(-1); }
#define debug(x) do { std::cerr << x; } while (0)
#define endl "\n"
#define pb push_back
#define pf push_front
#define vll vector<ll>
#define dll deque<ll>
#define sll set<ll, greater <ll>>
#define mll map<ll, ll>
#define vii vector<int>
#define dii deque<int>
#define sii set <int, greater <int>>
#define mii map<int, int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mod 1000000007
#define inv2 500000004
#define inv6 166666668
#define N 1000005
#define inf 200000000
#define eps 1e-10
#define PI 3.14159265359
#define all(v) (v).begin(),(v).end()
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
#define gcd(a,b) __gcd(a,b)
 
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n=0,a=0,b=0;cin>>n;
    for(ll i=sqrt(n);i>=1;i--){
        if(n%i==0){
            a=i;
            break;
        }
    }
    b=n/a;
    cout<<(a+b)-2;
    return 0;
}

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

int main(void){
    ll n, a, b;
    cin >> n >> a >> b;
    ll d = abs(a-b);
    if (d % 2 == 0) {
        cout << d/2 << endl;
    } else {
        cout << min({a-1,b-1,n-a,n-b}) + (d-1)/2 + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.*;

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

  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  String str = br.readLine();
  String[] strAry = str.split(" ");
  int a = Integer.parseInt(strAry[0]);
  int b = Integer.parseInt(strAry[1]);
  int c = Integer.parseInt(strAry[2]);  
  int tmp;

  if(a>b){
    tmp = a;   
    a = b; 
    b=tmp;
  }
 
  if(b>c){
    tmp = b;   
    b = c; 
    c = tmp;
  }
  
  if(a>b){
    tmp = a;   
    a = b; 
    b=tmp;
  }

   System.out.println(a+" "+b+" "+c);

 }
}

Measured memory_bytes: 24396
#include <bits/stdc++.h>
/* Karen {{{
  ___  ____
 |_  ||_  _|
   | |_/ /    ,--.   _ .--.  .---.  _ .--.
   |  __'.   `'_\ : [ `/'`\]/ /__\\[ `.-. |
  _| |  \ \_ // | |, | |    | \__., | | | |
 |____||____|\'-;__/[___]    '.__.'[___||__]
}}} */
/* cpp template {{{*/
using namespace std;

#define endl '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define X real()
#define Y imag()
#define EQ(n,m) (abs((n)-(m)) < EPS)

typedef double D;
typedef long long ll;
typedef long double lb;
typedef complex<D> P;
typedef vector<P> VP;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<string, int> psi;

inline bool inside(int y,int x,int H,int W){return(y>=0&&x>=0&&y<H&&x<W);}
inline int in() {int x; std::cin >> x; return x;}

template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T>
void print(T x) {
  std::cout << x << '\n';
}
/* }}} */
/* 定数 {{{*/
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 9;
const D EPS  = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
/* }}} */

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

  int n = in();
  cout << (n + 1) * n / 2 << endl;


  return (0);
}



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

#define ll long long
#define print(x) cout << x << endl
#define prints(x) cout << x << " "
#define printline cout << endl

bool comp(const pair<ll, ll> a, const pair<ll, ll> b)
{
    return a.second > b.second;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    ll h, w, m;
    cin >> h >> w >> m;
    set<pair<ll, ll>> s;
    vector<ll> H(3e5, 0);
    vector<ll> W(3e5, 0);
    for (ll i = 0; i < m; i++)
    {
        ll r, c;
        cin >> r >> c;
        r--;
        c--;
        H[r]++;
        W[c]++;
        s.insert({r, c});
    }

    ll ans = 0;
    vector<pair<ll, ll>> hp;
    vector<pair<ll, ll>> wp;
    for (ll i = 0; i < 3e5; i++)
    {
        if (H[i])
            hp.push_back({i, H[i]});
        if (W[i])
            wp.push_back({i, W[i]});
    }
    sort(hp.begin(), hp.end(), comp);
    sort(wp.begin(), wp.end(), comp);
    // for (ll i = 0; i < hp.size(); i++)
    // {
    //     prints(hp[i].second);
    // }printline;
    // for (ll i = 0; i < wp.size(); i++)
    // {
    //     prints(wp[i].second);
    // }printline;
    ll mh = hp[0].second;
    ll mw = wp[0].second;
    ans = mh + mw - 1;
    for (ll i = 0; i < (ll)hp.size(); i++)
    {
        if (hp[i].second != mh)
            break;
        int found=0;
        for (ll j = 0; j < (ll)wp.size(); j++)
        {
            if (wp[j].second != mw)
                break;
            ll temp = hp[i].second + wp[j].second;
            if (s.find({hp[i].first, wp[j].first}) != s.end())
            {
                temp--;
            }
            else
            {
                ans++;
                found=1;
                break;
            }

            ans = max(ans, temp);
        }
        if(found)break;
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 39296
#include<iostream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

int main() {
	
  int a,b ;    
  cin >> a >> b ;
  int tmp = 0 ;
  for(int i=1;i<(b-a);i++){
    tmp += i ;
  }
  cout << tmp-a << endl ;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(a) cout<<#a<<":"<<a<<endl;
const int INF=0x3f3f3f3f;
const int N=1e6+7;
const int mod=1e9+7;
int maxn,minn;
int T,n;
string s1,s2;
int len1,len2;
int dp[4010][4010];

int main(){
	cin>>s1>>s2;
	len1=s1.size();
	len2=s2.size();
	for(int i=1;i<=len1;i++){
		for(int j=1;j<=len2;j++){
			if(dp[i-1][j-1]+1<dp[i][j-1]||dp[i-1][j-1]+1<dp[i-1][j]){
				puts("zz");
			}
			if(s1[i-1]==s2[j-1]){
				dp[i][j]=dp[i-1][j-1]+1;
			}
			else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	string s="";
	int i=len1,j=len2;
	while(i!=0&&j!=0){
		if(s1[i-1]==s2[j-1]){
			s+=s1[i-1];
			i--,j--;
		}
		else{
			if(dp[i][j]==dp[i-1][j]){
				i--;
			}
			else{
				j--;
			}
		}
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
	
	

	return 0;
}





Measured memory_bytes: 47360
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int main(int argc, const char * argv[]) {

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

    int k, x; cin >> k >> x;
    
    for (int i = 0; i < 2 * k - 1; i++) {
        if (i != 2 * k - 2) cout << x - k + i + 1 << ' ';
        else cout << x - k + i + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>

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

    std::vector<long long> dams(n);
    for (int i = 0; i < n; ++i) {
        long long a;
        std::cin >> a;
        dams[i] = a;
    }

    long long s = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            s += dams[i];
        } else {
            s -= dams[i];
        }
    }
    auto x1 = (long long)(s / 2);
    std::cout << 2 * x1 << " ";

    auto x = x1;
    for (int i = 0; i + 1 < n; i++) {
        x = dams[i] - x;
        std::cout << 2 * x << " ";
    }

    return 0;
}


Measured memory_bytes: 2048
//naveen mall
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb               push_back
#define sz(c)            (int)c.size()
#define len(c)           (int)c.length()
#define vec              vector
#define int              long long int
#define all(c)           c.begin(), c.end()
#define rall(c)          c.rbegin(), c.rend()
#define trav(a,i)        for(auto& i: a)
#define fl(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define rfl(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define invect(v,n)       for(int i=0;i<n;i++ ){int arb;cin>>arb;v.pb(arb);}
#define inset(s,n)        forloop(n){int aset;cin>>aset;s.insert(aset);}
#define display(c)        trav(c,i) cout<<i<<" ";cout<<"\n";
#define F                 first
#define S                 second
#define pii               pair<int,int>
#define PB                pop_back
#define endl              "\n"
#define copy(a,b)         copy(all(a),back_inserter(b));
#define section(a,b,w)    set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w)      set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define diff(a,b,w)       set_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define symdiff(a,b,w)    set_symmetric_difference(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));

const long long INF64 = 1e18;





void solve()
 { 

int n,k;
cin>>n>>k;
vec<int> v;
invect(v,n)
int dp[n];
for(int i=0;i<n;i++)
	  dp[i]=INF64;
dp[0]=0;
dp[1]=abs(v[1]-v[0]);
for(int i=2;i<n;i++)
   {  int m=INF64;
   	for(int j=i-1;j>=max(0LL,i-k);j--)
   		  {  
   		  	 if(dp[j]+abs(v[i]-v[j])<m)
   		  	 	  m=dp[j]+abs(v[i]-v[j]);

   		  }

dp[i]=m;

   }
cout<<dp[n-1];


  }



  








 



signed main()
{fast
	int t;
   //cin>>t;
	t=1;

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












Measured memory_bytes: 1908
#include<stdio.h>
  
int main()
{
  int t[4][14];
  int n, i,j,c;
  char m, d;
  for(i=0; i < 4; i++){
    for(j=0; j < 14; j++){
      t[i][j]=0;
    }
  }
 scanf("%d", &c);
  for(i = 0; i < c; i++){
    scanf("%c", &d);
    scanf("%c %d", &m, &n);
    if(m == 'S'){
      t[0][n] = 1;
    }
    else if(m == 'H'){
      t[1][n] = 1;
    }
    else if(m == 'C'){
      t[2][n] = 1;
    }
    else if(m == 'D'){
      t[3][n] = 1;
    }
  }
  for(j=1; j < 14; j++){
    if(t[0][j] != 1){
      printf("S %d\n", j);
    }
  }
  
 for(j=1; j < 14; j++){
    if(t[1][j] != 1){
      printf("H %d\n", j);
    }
  }
  
 for(j=1; j < 14; j++){
    if(t[2][j] != 1){
      printf("C %d\n", j);
    }
  }
  
 for(j=1; j < 14; j++){
    if(t[3][j] != 1){
      printf("D %d\n", j);
    }
  }
 return 0;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i32 n; cin >> n;
    vi a(n+1); rep(i,n+1) cin >> a[i];
    vi upper(n+1), lower(n+1);
    upper[n] = lower[n] = a[n];
    rrep(i,n) {
        upper[i] = upper[i+1] + a[i];
        lower[i] = (lower[i+1]+1)/2 + a[i];
    }
//    rep(i, n+1) {  // ok
//        debug(upper[i]);
//        debug(lower[i]);
//    }

    if(1 < lower[0]) {
        cout << -1 << '\n';
        return 0;
    }

    i32 ans = 1, past_ParentNodes = 1;
    rep1(i,n) {
        ans += min(upper[i], past_ParentNodes*2);
        past_ParentNodes = min(upper[i], past_ParentNodes*2) - a[i];
    }

    cout << ans << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 5588
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    double a[2];
    while(cin>>a[0]){
        int co=1;
        double ans=0;
        while(co<11){
            if(co%2)a[co%2]=a[(co%2+1)%2]*2;
            else a[co%2]=a[(co%2+1)%2]/3;
            ans+=a[(++co)%2];
        }
        printf("%.7f\n",ans);
    }
}

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

const int maxn = 550000;
const int unit = 29;
const int mod = 1e9 + 7;

char w[maxn];
long long state[maxn];
long long pw[maxn];
bool f[maxn], g[maxn];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> w;
	int n = strlen(w);
	pw[0] = 1;
	for(int i = 1; i < maxn; ++ i) pw[i] = pw[i - 1] * unit % mod;
	for(int i = 0; i < n; ++ i) {
		state[i] = ((i == 0 ? 0 : state[i - 1]) + (w[i] - 'a' + 1) * pw[i]) % mod;
	}
	for(int i = 1; i <= n; ++ i) f[i] = true;
	int len = n;
	for(int i = 1; i < n; ++ i) {
		long long cs = state[i - 1];
		for(int j = i + i; j <= n; j += i) {
			long long ns = (state[j - 1] - state[j - i - 1] + mod) % mod;
			cs = (cs * pw[i]) % mod;
			if(ns == cs) f[j] = false;
			else break;
		}
		if(n % i == 0) {
			long long ns = (state[n - i - 1] * pw[i]) % mod;
			long long cs = (state[n - 1] - state[i - 1] + mod) % mod;
			if(ns == cs) {
				if(len > i) len = i;
			}
		}
	}
	reverse(w, w + n);
	for(int i = 0; i < n; ++ i) {
		state[i] = ((i == 0 ? 0 : state[i - 1]) + (w[i] - 'a' + 1) * pw[i]) % mod;
	}
	for(int i = 1; i <= n; ++ i) g[i] = true;
	for(int i = 1; i < n; ++ i) {
		long long cs = state[i - 1];
		for(int j = i + i; j <= n; j += i) {
			long long ns = (state[j - 1] - state[j - i - 1] + mod) % mod;
			cs = (pw[i] * cs) % mod;
			if(ns == cs) g[j] = false;
			else break;
		}
	}
	if(len == 1) {
		cout << n << "\n" << 1 << "\n";
		return 0;
	}
	if(len == n) {
		cout << 1 << "\n" << 1 << "\n";
		return 0;
	}
	cout << 2 << "\n";
	int pos = 0;
	for(int i = 1; i < n; ++ i) {
		if(f[i] && g[n - i]) ++ pos;
	}
	cout << pos << "\n";
	return 0;
}

Measured memory_bytes: 9984
c_list=[]
for i in range(3):
    c_list.append([int(i) for i in input().split()])
#print(c_list)

#c11
c_11=c_list[0][0]
ans=0
for a_1 in range(c_11+1):
    b_1=c_11-a_1
    b_2=c_list[0][1]-a_1
    b_3=c_list[0][2]-a_1
    if c_list[1][0]-b_1==c_list[1][1]-b_2==c_list[1][2]-b_3 and c_list[2][0]-b_1==c_list[2][1]-b_2==c_list[2][2]-b_3:
        print("Yes")
        ans=1
        exit()

if ans==0:
    print("No")

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

struct node{
    int color = -1;
    vector<int> child, d;
};

node g[100001];

void dfs(int a){
    int pc = g[a].color;
    int i;
    for(i = 0; i < g[a].child.size(); i++){
        int b = g[a].child[i];
        if(g[b].color == -1){
            if(g[a].d[i] % 2 == 1)
                g[b].color = (pc - 1) * -1;
            else
                g[b].color = pc;
            dfs(b);
        }
    }
}

int main(){
    int n, i;
    cin >> n;
    for(i = 0; i < n-1; i++){
        int u, v, w;
        cin >> u >> v >> w;
        g[u].child.push_back(v);
        g[u].d.push_back(w);
        g[v].child.push_back(u);
        g[v].d.push_back(w);
    }
    g[1].color = 0;
    dfs(1);
    for(i = 1; i <= n; i++){
        cout << g[i].color << endl;
    }
}

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

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

    vector<int> vec(n);

    rep(i,n){
        cin >> vec[i];
    }
    int ans;
    
    rep(j,100){
        int tmp_sum = 0;
        rep(k,n){
            tmp_sum += abs(j - vec[k])*abs(j - vec[k]);
        }
        if(j==0){
            ans = tmp_sum;
        }
        else{
            ans = min(ans, tmp_sum);
        }
    }


    cout << ans << endl;
}

Measured memory_bytes: 256
N = input()



if len(N) == 3:
    if int(N[2]) == 2 or int(N[2]) == 4 or int(N[2]) == 5 or int(N[2]) == 7 or int(N[2]) == 9:
        print('hon')
    elif int(N[2]) == 0 or int(N[2]) == 1 or int(N[2]) == 6 or int(N[2]) == 8:
        print('pon')
    elif int(N[2]) == 3:
        print('bon')

elif len(N) == 2:
    if int(N[1]) == 2 or int(N[1]) == 4 or int(N[1]) == 5 or int(N[1]) == 7 or int(N[1]) == 9:
        print('hon')
    elif int(N[1]) == 0 or int(N[1]) == 1 or int(N[1]) == 6 or int(N[1]) == 8:
        print('pon')
    elif int(N[1]) == 3:
        print('bon') 

elif len(N) == 1:
    if int(N[0]) == 2 or int(N[0]) == 4 or int(N[0]) == 5 or int(N[0]) == 7 or int(N[0]) == 9:
        print('hon')
    elif int(N[0]) == 0 or int(N[0]) == 1 or int(N[0]) == 6 or int(N[0]) == 8:
        print('pon')
    elif int(N[0]) == 3:
        print('bon') 

Measured memory_bytes: 61928
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 
using namespace std;

int main()
{
    long long n;
    while (~scanf("%lld", &n)) {
        long long ans = 0;
        long long i=1, j=0, r, d;
        while (i<=n) {
            r = n/i;
            j = n/r;
            if (i!=j) {
                d = ((n%i) - (n%j)) / (j-i);
                if (n%i%d == r%d) {
                    ans += i + (n%i - r)/d;
                }
            } else if (i==j && r==n%i) {
                ans += i;
            }
            i = j+1;
        }
        printf("%lld\n", ans);
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <list>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;
int main() 
{
    vector<char> v;
    vector<char>::iterator it;
    string s;
    int q;
    int t,f;
    char c;
    bool state_s=true;//trueのときそのまま、falseのとき反転
    bool state_f;

    cin >> s >> q;
    for(int i=0;i<s.length();i++){
        v.push_back(s.at(i));
    }
    
    rep(i,q){
        cin >> t;
        if(t==1) {
            state_s=!state_s;
        }else{
            cin >> f >> c;
            if(f==1)state_f=true;
            else state_f=false;
            if(state_s^state_f){
                v.push_back(c);
            }else{
                it=v.begin();
                it=v.insert(it,c);
            }
        }
    }

    if(state_s){
        for(it=v.begin();it!=v.end();it++){
            cout << *it;
        }
    }else{
        while(!v.empty()){
            cout << *(v.end()-1);
            v.pop_back();
        }
    }
}

Measured memory_bytes: 1144
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

typedef pair<int, int> P;

int mod = 1e9 + 7;

void add(int& a, int b) {
    a += b;
    if (a >= mod)
        a -= mod;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int N;
    cin >> N;
    vector<vector<int>> a(N, vector<int>(N));
    REP(i, N) {
        REP(j, N) {
            cin >> a[i][j];
        }
    }

    vector<vector<int>> dp(N+1, vector<int>(1 << N));
    dp[0][0] = 1;
    REP(i, N) {
        REP(k, 1 << N) {
            if (dp[i][k] == 0) continue;

            bitset<25> bs(k);
            if (bs.count() != i) continue;

            REP(j, N) {
                if (a[i][j] == 0) continue;
                if (bs[j]) continue;
                add(dp[i + 1][k | (1 << j)], dp[i][k]);
            }
        }
    }
    cout << dp[N][(1 << N) - 1] << endl;

    return 0;
}


Measured memory_bytes: 377216
#include <iostream>
using namespace std;
#define NIL -1
const int maxn = 30;
struct Node{int p,l,r;};
Node T[maxn];
int n;
void preParse(int u){
	if(u==NIL) return; 
	printf(" %d",u);
	preParse(T[u].l);
	preParse(T[u].r);
}
void inParse(int u){
	if(u==NIL) return;
	inParse(T[u].l);
	printf(" %d",u);
	inParse(T[u].r);
}
void postParse(int u){
	if(u==NIL) return;
	postParse(T[u].l);
	postParse(T[u].r);
	printf(" %d",u);
}
void init(){
	for(int i=0;i<n;i++)
		T[i].p=T[i].l=T[i].r=NIL;
}
int main() {
	int m,k,c,i,prt,left,right;
	scanf("%d",&n);
	m = n;
	init();
	while(n--){
		scanf("%d %d %d",&prt,&left,&right);
		T[prt].l = left;
		T[prt].r = right;
		if(left!=NIL) T[left].p = prt;
		if(right!=NIL) T[right].p = prt;
	}
	i=0;
	while(T[i].p!=NIL)
		i++;
	printf("Preorder\n");
	preParse(i);
	printf("\nInorder\n");
	inParse(i);
	printf("\nPostorder\n");
	postParse(i);
	printf("\n");
	return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#include <math.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++)
#define MAX_V 2010

typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int n, x, y;
    cin >> n >> x >> y;
    x--, y--;

    map<int, int> dic;

    for (int start = 0; start < n; start++) {
        queue<int> q;
        int dist[n];
        fill(dist, dist + n, INF_32);
        q.push(start);
        dist[start] = 0;

        while (!q.empty()) {
            int v = q.front();
            q.pop();
            for (int i = -1; i <= 1; i++) {
                if (v + i < 0 || v + i >= n)
                    continue;
                if (dist[v + i] != INF_32)
                    continue;
                dist[v + i] = dist[v] + 1;
                dic[dist[v + i]]++;
                q.push(v + i);
            }
            if (v == x) {
                if (dist[y] == INF_32) {
                    dist[y] = dist[v] + 1;
                    dic[dist[y]]++;
                    q.push(y);
                }
            }
            if (v == y) {
                if (dist[x] == INF_32) {
                    dist[x] = dist[y] + 1;
                    dic[dist[x]]++;
                    q.push(x);
                }
            }
        }
    }

    for (int k = 1; k <= n - 1; k++) {
        cout << dic[k] / 2 << endl;
    }
}


Measured memory_bytes: 384
import itertools

n = int(input())
path = list(itertools.permutations(set(range(n))))

total = 0
town = []
for i in range(n):
    town.append(list(map(int, input().split())))


def dist(x, y):
    return (x ** 2 + y ** 2) ** 0.5


check = list()
for p in path:
    for i in range(len(p) - 1):
        total += dist(town[p[i]][0] - town[p[i + 1]][0], town[p[i]][1] - town[p[i + 1]][1])

print(total / len(path))

Measured memory_bytes: 8052
#include <stdio.h>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <functional>
#include <stdlib.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, m, h, w, a, b, now;
  scanf("%lld%lld", &n, &m);
  ll ans[n], cnt[n];
  vector<ll> in[n], out[n];
  bool flg[n];
  for(i = 0; i < n; ++i) flg[i] = false, cnt[i] = 0, ans[i] = -1;
  for(i = 0; i < n + m - 1; ++i) {
    scanf("%lld%lld", &a, &b);
    in[--b].push_back(--a);
    out[a].push_back(b);
    cnt[b]++;
  }
  for(i = 0; i < n; ++i) {
    if(!in[i].size()) {
      ans[i] = -1;
      now = i;
      for(j = 0; j < out[i].size(); ++j) {
        cnt[out[i][j]]--;
        if(!cnt[out[i][j]]) ans[out[i][j]] = i;
      }
      break;
    }
  }
  set< pair<ll, ll> > s;
  for(i = 0; i < n; ++i) if(i != now) {
    s.insert(make_pair(cnt[i], i));
  }
  while(s.size()) {
    now = (*s.begin()).second;
    for(i = 0; i < out[now].size(); ++i) {
      s.erase(s.find(make_pair(cnt[out[now][i]], out[now][i])));
      cnt[out[now][i]]--;
      if(!cnt[out[now][i]]) ans[out[now][i]] = now;
      s.insert(make_pair(cnt[out[now][i]], out[now][i]));
    }
    s.erase(make_pair(0, now));
  }
  for(i = 0; i < n; ++i) printf("%lld\n", ans[i] + 1);
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    int now, count;
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    now = 0;
    count = 0;

    for (int i = 0; i < N; i++) {
        now = vec.at(now) - 1;
        count++;
        if (now == 1) {
            cout << count << endl;
            break;
        }
        if (i == N - 1) {
            cout << -1 << endl;
        }
    }
}

Measured memory_bytes: 3804
/*Arnab's Code
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define vll vector<ll>
#define vii vector<int>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define take(a,n) for(ll i=0;i<n;i++)cin>>a[i]
#define takes(a,n,st) for(ll i=st;i<n+st;i++)cin>>a[i]
ll sum(ll a[],ll n,ll s){ for(ll i=0;i<n;i++)s+=a[i]; return s;}
#define mod 1000000009
ll power(ll x, ll y, ll p)  {  
    ll res = 1;  
    x = x % p;   
    if (x == 0) return 0;  
    while (y > 0){  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
ll a[200017],b[200017],p[200017],q[200017];
void solve(){
	ll n,m,k,i,sm,cn,maxi;
	cin>>n>>m>>k;
	p[0]=0;
	q[0]=0;
	for(i=0;i<n;i++){
		cin>>a[i];
		p[i+1]=p[i]+a[i];
	}
	for(i=0;i<m;i++){
		cin>>b[i];
		q[i+1]=q[i]+b[i];
	}
	sm=m;
	maxi=0;
	for(i=0;i<=n;i++){
		cn=p[i];
		while(q[sm]+cn > k){
			sm--;
			if(sm<0)
				break;
		}
		if(sm<0){
			sm=0;
			continue;
		}
		if(i+sm > maxi)
			maxi=i+sm;
	}
	cout<<maxi;
	return;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ll t,T;
//	cin>>T;
	T=1;
	for(t=1;t<=T;t++){
//		cout<<"Case #"<<t<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 9872
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,k,n)       for(i=k;k<=n?i<=n:i>=n;k<=n?i++:i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define vpii            vector<pii>
#define vvi             vector<vi>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
const int inf =         1e18;
const int mod =         1e9+7;
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
void _p() {cout << "]\n";}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p,int m = inf) {int ans=1;x%=m;while(p>0){if(p&1)ans=(ans*x)%m;p=p>>1;x=(x*x)%m;}return ans;}
int inv(int x,int m=mod){return po(x,m-2,m)%m;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
//=================================================================================




const int N=1e6+6;
int n,m,k,x,y,z,a,b,c,d,i,j,l,r,f;








void sol()
{   
    cin>>n>>a>>b;
    x=n/(a+b);
    
    
    
    cout<< x*a+min(n-(a+b)*x,a) <<endl;
}





int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //sp(10);
    // w(t)
    sol();
    return 0;
}

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

int main() {
	int cnt = 0;
	int n; scanf("%d", &n);
	rep(i, n) {
		char c; int x; cin >> c >> x;
		if (c == '(')cnt += x;
		else cnt -= x;
		if (cnt < 0)break;
	}
	puts(cnt ? "NO" : "YES");
}

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

#define int long long
#define pii pair<int,int>
#define fi first
#define se second
#define all(v) v.begin(),v.end()
const int MOD =1e9+7;

const int MAXA = 1e6;

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie();
    //If you hack my code , You are gay;
    int n;
    cin>>n;
    vector<int> v(n),cnt(MAXA+7),mark(MAXA+7);
    for(int i=0;i<n;i++){
        cin>>v[i];
        cnt[v[i]]++;
    }
    sort(all(v));
    int ans=0;
    for(int i=0;i<n;i++)if(!mark[v[i]]){
        if(cnt[v[i]]==1) ans++;
        for(int j=v[i];j<=MAXA;j+=v[i]){
            mark[j]=1;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 20396
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = (long) 1e9 + 7;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        int n = sc.nextInt();
        String[] kk = new String[n];
        for (int i = 0; i < n; i++) {
            kk[i] = sc.next();
        }

        Pair[] ps = new Pair[n];
        for (int i = 0; i < n; i++) {
            int l = kk[i].length();
            int cl = 0, ml = 0, cr = 0, mr = 0;
            for (int j = 0; j < l; j++) {
                cl += kk[i].charAt(j) == '(' ? 1 : -1;
                ml = Math.min(ml, cl);
                cr += kk[i].charAt(l - j - 1) == ')' ? 1 : -1;
                mr = Math.min(mr, cr);
            }
            ps[i] = new Pair(-mr, -ml, kk[i]);
        }

        Arrays.sort(ps);
        debug(ps);

        int c = 0;
        boolean ok = true;
        for (Pair p : ps) {
            if (c - p.m < 0) {
                ok = false;
                break;
            }
            c -= p.m;
            c += p.p;
        }

        ok &= c == 0;
        out.println(ok ? "Yes" : "No");

        out.flush();
    }

    class Pair implements Comparable<Pair> {
        int p, m;
        String s;
        Pair(int p, int m, String s) {
            this.p = p;
            this.m = m;
            this.s = s;
        }

        @Override
        public int compareTo(Pair o) {
            if (p - m > 0 && o.p - o.m > 0) {
                return m - o.m;
            } else if (p - m > 0) {
                return -1;
            } else if (o.p - o.m > 0) {
                return 1;
            } else {
                return o.p - p;
            }
        }

        @Override
        public String toString() {
            return "(" + p + ", " + m + ")";
        }
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 204376
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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 namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll n, k;
    cin >> n >> k;

    if (n % k == 0) {
        cout << 0 << endl;
        return 0;
    }

    cout << min(n%k, k-n%k) << endl;

    //cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  if(n%2) n*=2;
  cout << n << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数
        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        // その結果を push
        res.push_back({a, ex});
    }
    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

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

	long long N;
    cin >> N;
    auto res = prime_factorize(N);
    // for(auto p : res){
    //     cout << "num:" << p.first << " cnt:" << p.second << endl;
    // }

    int ans = 0;
    for(auto p : res){
    	int num = p.first;
    	int cnt = p.second;

    	int total = 0;
    	int now=0;
    	int count=0;
    	while(1){
    		total += (++now);
    		//cout << total << endl;
    		if(total>cnt) break;
    		count++;
    	}
    	ans+=count;
    }

    cout <<  ans << endl;

}

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define fst first
#define snd second
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e20;
const int INF = 1e9;
const double EPS = 0.000000001;
struct edge {ll to, cost; };
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool pC(const P& pair1, const P& pair2) {
    return pair1.second > pair2.second;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  VI a(n), b(n);
  unordered_map<int, ll> hash;
  REP(i, n){
    cin >> a[i];
  }
  b[0] = a[0] % m;
  hash[b[0]] = 1;
  REP(i, n-1){
    b[i+1] = (b[i] % m + a[i+1] % m) % m;
    b[i+1] = b[i+1] % m;
    auto itr = hash.find(b[i+1]);
    if(itr != hash.end()) itr->second++;
    else hash[b[i+1]] = 1;
  }
  ll ans = 0;
  for(auto itr = hash.begin(); itr != hash.end(); ++itr) {
    if(itr->first == 0) ans += itr->second;
    ans += (itr->second) * (itr->second - 1) / 2;
  }
  out(ans);
  return 0;
}


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

using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b;
    int sum=0;
    int count=1;
    while(a-->0){
        cin>>c;
            
        sum=sum+c;
        if(sum<=b){
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}


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 M = sc.nextInt();
    //みんなの好きなもの
    int[][] like = new int[N][M+1];
    for(int i = 0; i < N; ++i){
      like[i][0] = sc.nextInt();
      for(int j = 1; j <= like[i][0]; ++j){
          like[i][j] = sc.nextInt();
      }
    }
    
    //みんなが好きなもの数える用
    int count[] = new int[M];
    for(int i = 0; i < M; ++i){
      count[i] = 0;
    }
    
    //数えよう
    for(int i = 0; i < N; ++i){
      for(int j = 1; j < M+1; ++j){
        for(int k = 1; k <= M; ++k){
          if(k == like[i][j]){
            count[k-1] ++;
          }
        }
      }
    }
    
    int ans = 0;
    
    for(int i = 0; i < M; ++i){
      if(count[i] == N){       
        ans++;        
      }
    }
    
    System.out.println(ans);
        
  } 
}

Measured memory_bytes: 38564
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// clang-format off
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
// clang-format on

void solve(long long A, long long B) {
  if (A <= 9 && B <= 9)
    cout << A * B << endl;
  else
    cout << -1 << endl;
}

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


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(x: "List[int]"):
    for idx,a in enumerate(x):
        if(a == 0):
            print(idx+1)



# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = [int(next(tokens)) for _ in range(5)]  # type: "List[int]"
    solve(x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 61692
L,R = [int(i) for i in input().split()]
if R-L >= 2019:
    print(0)
else:
    minimum = 2020
    for x in range(L, R):
        for y in range(L+1, R+1):
            minimum = min(minimum, (x*y)%2019)
    print(minimum)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int a,b,x;
  cin>>a>>b>>x;
  cout << (a<=x && x<=a+b ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N;
  string s[3],t="";
  REP(i,3)
    cin >> s[i];
  REP(i,3)
    t += s[i].substr(i,1);
  cout << t << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



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

using namespace std;

struct sushi_t {
  int d;
  int t;
};

static int n, k;
static std::array<sushi_t, 100000> sushis{};
static std::array<int, 100001> worstSushis{0};
static std::array<int, 100000> replaceables{};
static std::array<int, 100000> replacements{};

int64_t solve() {
  int64_t ret0 = 0;
  int64_t nn = 0;
  int replaceableIdx = 0;
  int i = 0;
  for (; i < k; ++i) {
    const auto& s = sushis[i];
    int const prev = worstSushis[s.t];
    worstSushis[s.t] = i + 1;
    ret0 += int64_t(s.d);
    if (!prev) {
      nn++;
    } else {
      replaceables[replaceableIdx++] = i;
    }
  }
  int64_t ret = ret0 + nn * nn;
  int replacementIdx = 0;
  for (; i < n; ++i) {
    const auto& s = sushis[i];
    int const prev = worstSushis[s.t];
    worstSushis[s.t] = i + 1;
    if (!prev) {
      replacements[replacementIdx++] = i;
    }
  }

  int const replacementSize = replacementIdx;
  replaceableIdx--;
  replacementIdx = 0;
  for (++nn; nn <= k && replaceableIdx >= 0 && replacementIdx < replacementSize;
       ++nn, --replaceableIdx, ++replacementIdx) {
    ret0 -= int64_t(sushis[replaceables[replaceableIdx]].d);
    ret0 += int64_t(sushis[replacements[replacementIdx]].d);
    if (ret0 + int64_t(k) * int64_t(k) <= ret) {
      break;
    }
    ret = std::max(ret0 + nn * nn, ret);
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    auto& s = sushis[i];
    std::cin >> s.t >> s.d;
    s.t--;
  }
  std::sort(sushis.begin(), sushis.begin() + n,
            [](const auto& lhs, const auto& rhs) { return lhs.d > rhs.d; });
  std::cout << solve() << std::endl;
  return 0;
}


Measured memory_bytes: 1664
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
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
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, M = MAP()
print(N*(N-1)//2+M*(M-1)//2)


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

using namespace std;

int main() {
  int H = 0, A = 0;
  int result = 0;
  
  cin >> H >> A;
  
  result = H / A;
  
  if (H % A) {
    result++;
  }
  
  cout << result << endl;
}

Measured memory_bytes: 256
#ABC079C/Train_Ticket
N = input()
n = list(N)
for i in range(len(n)):
    n[i] = int(n[i])

if n[0] + n[1] + n[2] + n[3] == 7:
    print("{}+{}+{}+{}=7".format(n[0], n[1], n[2], n[3]))
elif n[0] + n[1] + n[2] - n[3] == 7:
    print("{}+{}+{}-{}=7".format(n[0], n[1], n[2], n[3]))
elif n[0] + n[1] - n[2] - n[3] == 7:
    print("{}+{}-{}-{}=7".format(n[0], n[1], n[2], n[3]))
elif n[0] + n[1] - n[2] + n[3] == 7:
    print("{}+{}-{}+{}=7".format(n[0], n[1], n[2], n[3]))
elif n[0] - n[1] + n[2] + n[3] == 7:
    print("{}-{}+{}+{}=7".format(n[0], n[1], n[2], n[3]))
elif n[0] - n[1] + n[2] - n[3] == 7:
    print("{}-{}+{}-{}=7".format(n[0], n[1], n[2], n[3]))
elif n[0] - n[1] - n[2] - n[3] == 7:
    print("{}-{}-{}-{}=7".format(n[0], n[1], n[2], n[3]))
elif n[0] - n[1] - n[2] + n[3] == 7:
    print("{}-{}-{}+{}=7".format(n[0], n[1], n[2], n[3]))



Measured memory_bytes: 3064
[print(min(m[i])[0])for h in [__import__('heapq')]for a,d,r,n,x in[(h.heappush,h.heappop,range,lambda:map(int,input().split()),list.append)]for N,M,S in[n()]for g,q in[([[]for _ in r(N)],[(0,S,0)])]for L in[max(A for _ in r(M)for U,V,A,B in[n()]if not(x(g[U-1],(V-1,A,B))or x(g[V-1],(U-1,A,B))))*(N-1)]for m in[[[[2**64]for _ in r(L+1)]for _ in r(N)]]for _ in[[[x(g[i],(i,-C,D))for i in r(N)for C,D in[n()]],[[[_ for s,v,i in[d(q)]for _ in[[a(q,(s+c,j,t))for t,p,c in g[i]for j in[min(L,v-p)]for y in[m[t][j]]if v>=p and s+c<y[0] and not(y.clear()or x(y,s+c))]]if not(x(l,None)if q else l.clear())]]for l in[[None]]for _ in l]]]for i in r(1,N)]


Measured memory_bytes: 78196
#include<cstdio>
#include<cctype>
#define maxn 200005
using namespace std;
int n,a[maxn],f[maxn];
long long ans;
inline int read(){
	int x=0;char ch=getchar();
	while (!isdigit(ch)) ch=getchar();
	while (isdigit(ch)) x=(x<<3)+(x<<1)+ch-48,ch=getchar();
	return x;
}
int main()
{
	n=read();
	for (int i=1;i<=n;++i) a[i]=read();
	if (a[1]) return puts("-1"),0;
	for (int i=1;i<n;++i) if (a[i+1]-a[i]>1){return puts("-1"),0;}
	for (int i=2;i<=n;++i) if (a[i]==a[i-1]+1) f[i]=f[i-1]+1,f[i-1]=0; else f[i]=a[i];
	for (int i=1;i<=n;++i) ans+=f[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) (vec).begin(),(vec).end()
#define int long long
#define f first
#define s second

signed main(){
    int n;cin>>n;
    vector<vector<pair<int,int>>> s(n);
    rep(i,n){
        int a;cin>>a;
        rep(j,a){
            int x,y;cin>>x>>y;
            x--;
            s[i].push_back({x,y});
        }
    }
    int ans=0;
    rep(b,(1<<n)){
        bool ok=true;
        rep(j,n){
            if(b&(1<<j)){
                for(auto z:s[j]){
                    int x,y;
                    tie(x,y)=z;
                    if(!(((b&(1<<x))>0&&y>0)||(b&(1<<x))==0&&y==0))ok=false;
                }
            }
        }
        if(ok){
            int c=0;
            rep(i,n)if(b&(1<<i))c++;
            ans=max(ans,c);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256