akhauriyash/Code-Regression huggingface dataset:
/*
  AUTHOR:SOURABH
  CREATED:03:04:20
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ordered_set tree<pll , null_type, less< pll >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pob pop_back
#define W while
#define fn(i,x) for(i=0;i<x;i++)
#define fs(i,s,x) for(i=s;i<x;i++)
#define fr(i,x) for(i=x;i>=0;i--)
#define fit(it,s) for(it=s.begin();it!=s.end();it++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define mod 998244353
#define MAX 100005
#define M 32

using namespace std;
using namespace __gnu_pbds;

ll sum;

void solve(ll x,ll y)
{
    ll p=y,r;
    W(p%x==0)
    p/=x;
    r=p%x;
    if(r==1)
        sum++;
    
    if(x==y)
        return;
        
    p=x;
    W(p%y==0)
    p/=y;
    r=p%y;
    if(r==1)
        sum++;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    ll t,i,k,v,x,y;
    t=1;
    //cin>>t;
    W(t--)
    {
        cin>>k;
        v=k;
        k--;
        for(i=1;i*i<=k;i++)
        {
            if(k%i==0)
            {
                if(i!=k/i)
                    sum+=2;
                else
                    sum+=1;
            }
        }
        k=v;
        for(i=2;i*i<=k;i++)
        {
            if(k%i==0)
            {
                x=i,y=k/i;
                solve(x,y);
            }
        }
        cout<<sum;
    }
    return 0;
}


















Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100005
#define NIL -1
int n;
struct Node{
	int p; //parent
	int l; //left-child
	int r; //right sibling
};
struct Node T[MAX];
int depth(int u){
	int d=0;
	int tmp=T[u].p;
	while( tmp!=NIL ){ d++; tmp=T[tmp].p; }
	return d;
}
int print(int u){
	int tmp=T[u].l;
	int flg=0;
	printf("node %d: parent = %d, depth = %d, ", u, T[u].p, depth(u));
	if( T[u].p==NIL) printf("root, [");
	else if( T[u].l!=NIL ) printf("internal node, [");
	else printf("leaf, [");
	while( tmp!=NIL ){
		if( flg==0 ){ printf("%d",T[u].l); flg=1;}
		else printf(", %d", tmp);
		tmp=T[tmp].r;
	}
	printf("]\n");
	return 0;

}
int main(void){
  int i, j;
  int d, v, c;
  int tmp;
  scanf("%d", &n);
  for ( i=0; i<n; i++ ) T[i].p=T[i].l=T[i].r=NIL;
  for ( i=0; i<n; i++ ){
    scanf("%d %d", &v, &d);
    for ( j=0; j<d; j++ ){
      scanf("%d", &c);
      T[c].p=v;
      if( j==0 ) T[v].l=c;
      else T[tmp].r=c;
      tmp=c;
    }
  }
  for ( i=0; i<n; i++ ) print(i);
  return 0;
}

Measured memory_bytes: 1784
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>




typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i )
#define rep(i,n) FOR(i,0,n)
#define sz(x) int(x.size())


template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;



int main(){
    int n,k;
    cin>>n>>k;
    int ans=0;
    if (n>=2*k) ans=n-2*k;
    
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

	int w,n,dataw[31],i,one,two,j;

	for(i=1;i<31;i++)
		dataw[i]=i;

	scanf("%d",&w);
	scanf("%d",&n);

	for(i=0;i<n;i++){
		
		scanf("%d,%d",&one,&two);
		j=dataw[one];
		dataw[one]=dataw[two];
		dataw[two]=j;

	}

	for(i=0;i<w;i++)
		printf("%d\n",dataw[i+1]);

	return 0;

}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main() {
    int n;
    long long a;
    long long maxValue = -1000000;
    long long minValue = 1000000;
    long long sum = 0;

    cin>>n;

    for(int i=0;i<n;i++){
        cin>>a;
        if(a < minValue) minValue = a;
        if(a > maxValue) maxValue = a;
        sum += a;
    }

    cout<< minValue <<" "<< maxValue <<" "<< sum << endl;

    return 0;}

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

#define int long long
#define pb push_back
#define ff first
#define ss second

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int n;
    cin>>n;
    
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        
        if(i%2==1 && x%2==1)
            ans++;
    }
    cout<<ans<<"\n";
    
}

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

long long calc(long long n, long long b) {
	if (n < b) return n;
	return calc(n / b, b) + (n % b);
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	long long n, s; cin >> n >> s;
	for (int i = 2; i <= 1000000; i++) {
		if (calc(n, i) == s) {
			cout << i << endl;
			return 0;
		}
	}
	vector<long long> ans;
	for (int i = 1; i <= 1000000; i++) {
		long long rest = s - i;
		long long b = (n - rest) / i;
		if ((n - rest) % i) continue;
		if (rest < b && b >= 2 && calc(n, b) == s) ans.push_back(b);
	}
	if (calc(n, n + 1) == s) ans.push_back(n + 1);
	sort(ans.begin(), ans.end());
	if (ans.size() == 0) cout << "-1" << endl;
	else cout << ans[0] << endl;
	return 0;
}



Measured memory_bytes: 256
import java.io.*;
import java.util.*;

/**
 * Created by Ayushi on 11 Jul 2020.
 * Problem:
 * Round:
 */

public class Main {
    public static void main(String[] args) throws IOException {
        StringTokenizer st;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        st = new StringTokenizer(br.readLine(), " ");
        int l = Integer.parseInt(st.nextToken());
        int r = Integer.parseInt(st.nextToken());
        int d = Integer.parseInt(st.nextToken());
        int ans = 0;
        for (int i = l; i <= r; i++) {
            if (i % d == 0) ans++;
        }
        System.out.println(ans);
        br.close();
    }
}


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

typedef long long ll;

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

ll lcm(ll a, ll b) {
  return a*b / gcd(a, b);
}

int main() {
  ll a, b;
  cin >> a >> b;
  cout << lcm(a, b) << endl;
}



Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

immutable long MOD = 10^^9 + 7;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto K = s[2];
    auto G = new UndirectedGraph(N);
    foreach (_; 0..M) {
        s = readln.split.map!(to!int);
        G.add_edge(s[0]-1, s[1]-1);
    }

    auto bicom = biconnected_decomposition(G);
    long ans = 1;
    //foreach (b; bicom) {
    //    b.map!(a => "(" ~ to!string(a[0]+1) ~ ", " ~ to!string(a[1]+1) ~ ")").join(" ").writeln;
    //}


    foreach (edges; bicom) {
        int[] nodes;
        foreach (e; edges) nodes ~= e[0], nodes ~= e[1];
        nodes = nodes.sort().uniq().array;

        if (edges.length == 1) {
            ans = ans * K % MOD;
        } else if (edges.length == nodes.length) {
            long tmp = 0;
            foreach (i; 0..nodes.length) {
                tmp += powmod(K, gcd(nodes.length.to!long, i.to!long), MOD);
                tmp %= MOD;
            }
            tmp = tmp * powmod(nodes.length.to!long, MOD-2, MOD) % MOD;
            ans = ans * tmp % MOD;
        } else {
            ans = ans * comb(K + edges.length.to!int - 1, edges.length.to!int) % MOD;
        }
    }

    ans.writeln;
}

Tuple!(int, int)[][] biconnected_decomposition(UndirectedGraph g) {
    Tuple!(int, int)[][] ret;

    int cnt = 0;
    Tuple!(int, int)[] stack;
    auto ord = new int[](g.N);
    auto low = new int[](g.N);
    fill(ord, -1);
    fill(low, -1);

    void dfs(int n, int p)  {
        ord[n] = cnt;
        low[n] = cnt;
        cnt += 1;
        foreach (m; g.adj[n]) {
            if (ord[m] == -1) {
                stack ~= tuple(n, m);
                dfs(m, n);
                low[n] = min(low[n], low[m]);
                if (low[m] >= ord[n]) {
                    Tuple!(int, int)[] bicom;
                    while (bicom.empty || bicom.back != tuple(n, m)) {
                        bicom ~= stack.back;
                        stack.popBack;
                    }
                    ret ~= bicom.dup;
                }
            } else if (ord[m] < ord[n] && m != p) {
                stack ~= tuple(n, m);
                low[n] = min(low[n], ord[m]);
            }
        }
    }

    foreach (i; 0..g.N) {
        if (ord[i] == -1) dfs(i, -1);
    }

    return ret;
}

class UndirectedGraph {
    int N;
    int[][] adj;

    this (int N) {
        this.N = N;
        adj = new int[][](N);
    }

    void add_edge(int u, int v) {
        adj[u] ~= v;
        adj[v] ~= u;
    }
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}

long comb(long n, long k) {
    long ret = 1;
    foreach (i; 1..n+1) ret = ret * i % MOD;
    foreach (i; 1..n-k+1) ret = ret * powmod(i, MOD-2, MOD) % MOD;
    foreach (i; 1..k+1) ret = ret * powmod(i, MOD-2, MOD) % MOD;
    return ret;
}


Measured memory_bytes: 380
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next(), b = scan.next();
		int count  = 0;
		
		for(int i = 0; i < a.length(); i++) {
			if(!a.substring(i, i + 1).equals(b.substring(i, i + 1))) {
				count++;
				
			}
			
		}
		
		System.out.println(count);


	}


}

Measured memory_bytes: 55464
#include <bits/stdc++.h>
using namespace std;
char s[20];
int a[20];
long long ans,n;
long long check()
{
	long long t=0,sum=0;
	for(int i=0;i<n-1;i++)
	{
		t=t*10+s[i];
		if(a[i])
		{
			sum+=t;
			t=0;
		}
	}
	t=t*10+s[n-1];
	return t+sum;
}
void dfs(int k)
{
	if(k==n-1)
	{
		ans+=check();
		return;
	}
	a[k]=0;
	dfs(k+1);
	a[k]=1;
	dfs(k+1);
}
int main()
{
	cin>>s;
	n=strlen(s);
	for(int i=0;i<n;i++)
		s[i]-=48;
	dfs(0);
	cout<<ans;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <bitset>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

typedef long long Int;
typedef pair<Int,Int> pii;

int main() {
  const int N = 1050000;
  vector<int> prime(N);
  REP(i,N) prime[i]=i;
  prime[0] = prime[1] = 0;
  for (int i=2; i<N; ++i)
    if (prime[i])
      for (int j=2*i; j<N; j+=i)
        prime[j] = 0;
  prime.erase(remove(ALL(prime), 0), prime.end());
    
  Int n;
  while(cin >> n, n) {
    Int sr = sqrt(n);
    map<int,int> mp;
    for (int i=0; n>1 && prime[i]<=sr; ++i) {
      while(!(n%prime[i])) {
        n /= prime[i];
        mp[prime[i]]++;
      }
    }
    if (n!=1) mp[n]++;

    Int m = mp.size();
    
    vector<pii> v;
    FOR(it, mp) 
      v.push_back(pii(it->first, it->second));
    Int res = 0;
    REP(S, 1<<m) {
      Int tmp = 1;
      REP(i,m) {
        if ((S>>i)&1)
          tmp *= v[i].second + 1;
        else {
          if (v[i].second >= 2) {
            tmp *= v[i].second;
          }
        }
          
      }
//      cout << bitset<10>(S) << " " << tmp<<endl;
      res += tmp;
    }
    cout << (res+1)/2 << endl;
  }
}

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

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  int res = 0;
  for (int i = 1; i < n-1; i++)
  {
    if (min(p[i - 1], min(p[i], p[i + 1])) != p[i] &&
        max(p[i - 1], max(p[i], p[i + 1])) != p[i]){
      res++;
    }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#　解説確認後
#　参考サイト「けんちょんの競プロ精進記録」
#　URL: https://atcoder.jp/contests/abc142/tasks/abc142_d

import math
def prime_factorize(n): # 素因数分解
    p = 2
    res = []
    while p*p <= n:
        if n % p: # 割り切れない
            p += 1
            continue
        num = 0
        while n % p == 0:
            n //= p
            num += 1
        res.append((p,num))
        p += 1
    if n != 1: res.append((n,1))
    return res

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

G = math.gcd(a,b) # 最大公約数

pl = prime_factorize(G)

print(len(pl)+1) # 1+n個なので

Measured memory_bytes: 9100
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  set<string> st;
  string s;char c_back;cin>>s;
  st.insert(s);c_back=s.back();
  bool isok=true;
  rep(i,n-1) {
    cin>>s;
    st.insert(s);
    if(isok&&s[0]==c_back) c_back=s.back();
    else isok=false;
  }
  if(isok) isok=(st.size()==n);
  print(isok?"Yes":"No");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;
typedef unsigned long long BITMASK; typedef long long ll; typedef long double ld;
#define has_bit(bit_mask, x) ((bit_mask) & (1Uint << (x)))
#define turn_on_bit(bit_mask, x) (bit_mask |= (1Uint << (x)))
#define turn_off_bit(bit_mask, x) (bit_mask &= (~(1Uint << (x))))
#define smallest_on_bit(bit_mask) (__builtin_ctzint((bit_mask) & (-(bit_mask))))
#define CLOCK_START clock_t chrono_clk_beg = clock()
#define CLOCK_END clock_t chrono_clk_end = clock(); cerr << (double(chrono_clk_end - chrono_clk_beg) / CLOCKS_PER_SEC) << " sec"
#define bug(args ...) cerr << __LINE__ << ">> ", err(new istringstream(string(#args)), args), cerr << '\n'
#define all(x) x.begin(), x.end()
#define mapfind(mp, x) (mp.find(x) != mp.end())
#define removeDuplicates(vec) sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define int ll
#define double ld
void err(istringstream *iss) {} template<typename T, typename ... Args> void err(istringstream *iss, const T &_val, const Args & ... args) { string _name; *iss >> _name; if (_name.back()==',') _name.pop_back(); cerr << _name << " = " << _val << "; ", err(iss, args ...); }
#define MOD 1000000007

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> DP(n+1, 0);
    map<int, map<int, int>> rec;
    for (int i = 1; i <= n; ++i)
    {
        int first = (int)(to_string(i)[0] - '0');
        int last = i%10;
        DP[i] = (DP[i-1]) + (2 * rec[last][first]);
        if (first == last) DP[i]++;
        rec[first][last]++;
    }
    cout << DP[n] << '\n';
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define fori(a,b,c) for(int i=a;i<=b;i+=c)
#define forj(aa,bb,cc) for(int j=aa;j<=bb;j+=cc)
#define fork(aaa,bbb,ccc) for(int k=aaa;k<=bbb;k+=ccc)
#define forl(aaaa,bbbb,cccc) for(int l=aaaa;l<=bbbb;l+=cccc)
#define ll long long
#define dd cout<<endl//前面都没啥用的宏定义。
using namespace std;
int a,b;
int main()
{
    cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;
    return 0;
}

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

string s, t;

int main() {

    cin >> s >> t;

    string s_d = s + s;

    vector<int> alp[26];

    for (int i = 0; i < s_d.size(); ++i) {
        alp[s_d[i] - 'a'].emplace_back(i);
    }

    function<int(int,int)> nxt = [&](int now, int chr) {
        auto itr = upper_bound(alp[chr].begin(), alp[chr].end(), now);
        return *itr;
    };

    int s_len = s.size();

    long long piv = -1, whole = 0;
    for (int i = 0; i < t.size(); ++i) {
        if (alp[t[i] - 'a'].size() == 0) {
            cout << -1 << endl;
            return 0;
        }
        int n = nxt(piv, t[i] - 'a');
        if (n >= s_len) {
            ++whole;
            n -= s_len;
        }
        piv = n;
    }

    cerr << piv << ' ' << whole << endl;
    cout << whole * s_len + piv + 1 << endl;

}

Measured memory_bytes: 1980
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>
#include <cmath>
#include <map>
#include <utility>
#include <numeric>
#include <set>
#include <map>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999
#define atcoder 1e9+77
#define _USE_MATH_DEFINES

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

int main() {

	int n, cnt = 0, j = 0;
	ll a[100010];
	ll ans[100010] = {0};

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

	sort(a, a + n);

	for (int i = 1; i < n; i++) {
		if (a[i - 1] == a[i]) {
			ans[j] = a[i];
			j++;
			i++;
		}
	}
	if (j == 0)j = 2;

	cout << ans[j - 1] * ans[j - 2] << endl;

	return 0;
}


Measured memory_bytes: 1792
#if 0
#endif
#include <cstdio>
#include <algorithm>
#include <stack>
#define debug(...) // fprintf(stderr, __VA_ARGS__)

inline int input() { int x; scanf("%d", &x); return x; }

struct Tree {
	int L, R;
	Tree *lt, *rt;
	int max, lazy;

	inline void update() {
		max = std::max(lt -> max, rt -> max);
	}

	inline void push_down() {
		lt -> max += lazy;
		lt -> lazy += lazy;
		rt -> max += lazy;
		rt -> lazy += lazy;
		lazy = 0;
	}

	void add(int l, int r, int x) {
		if(r < L or l > R)
			return;
		if(l <= L and R <= r) {
			max += x;
			lazy += x;
		} else {
			push_down();
			lt -> add(l, r, x);
			rt -> add(l, r, x);
			update();
		}
	}

	int query(int l, int r) {
		if(r < L or l > R)
			return 0;
		if(l <= L and R <= r)
			return max;
		push_down();
		return std::max(lt -> query(l, r), rt -> query(l, r));
	}

	Tree(int l, int r): L(l), R(r), max(0), lazy(0) {
		if(l == r)
			return;
		int mid = (l + r) >> 1;
		lt = new Tree(l, mid);
		rt = new Tree(mid + 1, r);
	}
};

struct Dot {
	int x, y;
};

const int maxn = 300005;
Dot dot[maxn];
int x[maxn], up[maxn], down[maxn];

inline bool cmp(Dot x, Dot y) {
	return x.x < y.x;
}

int solve(int n, int w, int h) {
	if(not n) return 0;
	for(int i = 1; i <= n; i ++)
		debug("%d, %d\n", dot[i].x, dot[i].y);

	int mid = h >> 1;
	int i = 1, p = 0;
	int res = 0;
	std::stack<int> stup, stdown;
	Tree T(1, n);

	stup.push(0);
	stdown.push(0);

	while(i <= n) {
		++ p;
		x[p] = dot[i].x;
		up[p] = h - mid;
		down[p] = mid;

		while(i <= n and dot[i].x == x[p]) {
			if(dot[i].y >= mid)
				up[p] = std::min(up[p], dot[i].y - mid);
			if(dot[i].y <= mid)
				down[p] = std::min(down[p], mid - dot[i].y);
			i ++;
		}

		while(up[stup.top()] > up[p]) {
			int tmp = stup.top();
			stup.pop();
			T.add(stup.top() + 1, tmp, up[p] - up[tmp]);
			debug("%d-%d add %d\n", stup.top() + 1, tmp, up[p] - up[tmp]);
		}

		while(down[stdown.top()] > down[p]) {
			int tmp = stdown.top();
			stdown.pop();
			T.add(stdown.top() + 1, tmp, down[p] - down[tmp]);
			debug("%d-%d add %d\n", stdown.top() + 1, tmp, down[p] - down[tmp]);
		}

		stup.push(p);
		stdown.push(p);
		T.add(p, p, w - x[p - 1] + up[p] + down[p]);
		debug("%d-%d add %d\n", p, p, w - x[p - 1] + up[p] + down[p]);
		res = std::max(res, T.query(1, p) - (w - dot[i].x));

		debug("%d: %d, %d ans=%d\n", x[p], up[p], down[p], T.query(1, p) - (w - dot[i].x));
	}

	return res;
}

int main() {
	int w = input(), h = input(), n = input(), ans = 0;

	for(int i = 1; i <= n; i ++) {
		dot[i].x = input();
		dot[i].y = input();
		if(dot[i].x == 0 or dot[i].x == w or dot[i].y == 0 or dot[i].y == h) {
			n --;
			i --;
		}
	}

	std::sort(dot + 1, dot + n + 1, cmp);
	dot[0].x = 0;
	dot[n + 1].x = w;
	for(int i = 1; i <= n + 1; i ++)
		ans = std::max(ans, h + dot[i].x - dot[i - 1].x);
	ans = std::max(ans, solve(n, w, h));

	for(int i = 1; i <= n; i ++)
		std::swap(dot[i].x, dot[i].y);

	std::sort(dot + 1, dot + n + 1, cmp);
	dot[0].x = 0;
	dot[n + 1].x = h;
	for(int i = 1; i <= n + 1; i ++)
		ans = std::max(ans, w + dot[i].x - dot[i - 1].x);
	ans = std::max(ans, solve(n, h, w));

	printf("%d\n", ans << 1);
}

Measured memory_bytes: 62992
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef string str;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define pb(x) pop_back(x)
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define sum(x) accumulate(all(x),0)
#define pc(x) __builtin_popcount(x)
#define gll greater<ll>()





void solve(){
 ll n;
  cin >> n;
  vll a(n);
  rep(i,0,n) cin >> a[i];
  
  ll g=a[0];
  rep(i,1,n) g=__gcd(a[i],g);
  
  map<ll,vll> mp;
  ll f=0;
  rep(j,0,n){
    for(ll i=2;i*i<=a[j];i++){
     if(a[j]%i) continue;
      ll tot=0;
     while(a[j]%i==0){ 
      a[j]/=i;
      tot++; 
     }
      if(mp[i].size()) {
        f=1;
        break;
      }
      mp[i].eb(tot);
    }
    if(f) break;
    if(a[j]!=1) {
    if(mp[a[j]].size()) {
        f=1;
        break;
      }
      mp[a[j]].eb(1);
    }
  }
  
  //for(auto p:mp) if(p.se.size()>1) f=1;
  
  
  if(f==0) cout << "pairwise coprime" << endl;
  else if(f==1&&g==1) cout << "setwise coprime" << endl;
  else cout << "not coprime" << endl;
  
  
  
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}


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

const int N=200005;

int n,m,res;
int p[N],sz[N];

int find(int x)
{
    if(p[x]!=x)p[x]=find(p[x]);
    return p[x];
}

int main()
{
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)p[i]=i,sz[i]=1;
    for(int i=0;i<m;i++)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        a=find(a),b=find(b);
        if(a!=b)p[a]=b,sz[b]+=sz[a];
    }
    for(int i=1;i<=n;i++)
        if(p[i]==i&&res<sz[i])
            res=sz[i];
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 3284
def main():
    w = list(input())
    oklist=[]
    for i in range(len(w)):
        w1 = w.count(w[i])
        if w1 % 2 != 0:
            oklist.append(1)
    if oklist == []:
        print('Yes')
    else:
        print('No')
    
    
if __name__ == '__main__':
  main()

Measured memory_bytes: 9104
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <cstring>

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)

ll n;
vector<char> v;

int main() {
    cin >> n;

    while (n > 0){
        ll alpa = n%26;
        if (alpa == 0) alpa+=26;
        char a = 'a'-1+alpa;

        v.push_back(a);

        n=(n-1)/26;
    }

    while (v.size()){
        cout << v[v.size()-1];
        v.pop_back();
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3584
import sys
from collections import Counter

import numba as nb
import numpy as np

input = sys.stdin.readline
MAX_A = 10 ** 6


@nb.njit("i8(i8[:],i8[:])")
def solve(keys, values):
    divisible = [False] * (MAX_A + 1)
    ans = 0
    for k, v in zip(keys, values):
        if v == 1 and not divisible[k]:
            ans += 1
        for i in range(k, MAX_A + 1, k):
            divisible[i] = True
    return ans


def main():
    N = int(input())
    A = list(map(int, input().split()))

    A.sort()
    c = Counter(A)
    keys = np.array(tuple(c.keys()), dtype=np.int64)
    values = np.array(tuple(c.values()), dtype=np.int64)

    ans = solve(keys, values)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 136416
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<functional>
#include <random>

using namespace std;





int main(void) {
	long long prod;
	long long num;
	long long ans;

	scanf("%lld %lld", &num, &prod);
	if (num == 1) {
		printf("%lld\n", prod);
		return 0;
	}
	if (num > 40) {
		printf("1\n");
		return 0;
	}
	ans = 1;
	for (int i = 1; num*log(i) < log(prod + 1); i++) {
		long long p = prod;
		int a = 1;
		for (int j = 0; j < num; j++) {
			if (p % i != 0) { a = 0; break; }
			p = p / i;
		}
		if (a == 1) { ans = i; }
	}
	printf("%lld\n", ans);

}


Measured memory_bytes: 384
// Parasparopagraho Jīvānām

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std ;
using namespace  __gnu_pbds ;
using namespace __gnu_cxx ;

typedef long long ll ;
typedef long double ld ;

typedef pair<int, int> pii ;
typedef pair<int, ll> pil ;
typedef pair<ll,ll> pll ;

typedef vector<int> vi ;
typedef vector<ll> vll ;
typedef vector<pii> vpi ;
typedef vector<pll> vpl ;
typedef vector<int,pil> edges ;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

#define mp make_pair
#define eb emplace_back
#define pb push_back
#define fi first
#define se second

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int mod1 = 1000000007 ;
const int mod2 = 998244353 ;
const ll  infl = 2e18 ;
const int infi = 2e9 ;
const int maxn = 100005 ;
const int block = 500 ;
const int logn = 30 ;
const int alpha = 27 ;
const ld pi = 3.141592653589793238462643383279 ;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) ;

/* Careful when using long long
__builtin_clz(int x) {} //: the number of zeros at the beginning of the number
__builtin_ctz(int x) {} //: the number of zeros at the end of the number
__builtin_popcount(int x) {} //: the number of ones in the number
__builtin_parity(int x) {} //: the parity (even or odd) of the number of ones*/
ll modpow(ll a, ll b, int MOD) { ll res = 1 ; while(b) { if(b&1) { res = res*a ; res %= MOD ; } a *= a ; a %= MOD ; b >>= 1 ; } return res%MOD ; }
void upmin(int &a, int b) { if(a < b) { a = b ; } }
void relax(int &a, int b) { if(a > b) { a = b ; } }
ll add(ll a, ll b, int MOD) { a += b ; if(a >= MOD) { a -= MOD ; } return  a ; }
ll sub(ll a, ll b, int MOD) { a -= b ; if(a < 0) { a += MOD ; } return a ; }
ll mul(ll a, ll b, int MOD) { b %= MOD ; a *= b ; a %= MOD ; return a ; }
ll inverse(ll a, ll MOD) { a = modpow(a, MOD - 2, MOD) ; return a ; }
ll lcm(ll a, ll b) { ll ret ; ll g = __gcd(a, b) ; ret = a/g ; ret = ret*b ; return ret ; }

int main()
{
    ios::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    string s ;
    cin >> s ;
    int n = sz(s) ;
   // int res = 0 ;
    rep(i,0,n-1)
    {
        if(s[i] == '?') s[i] = 'D' ;
    }
    cout << s << endl ;

    return 0 ;
}


Measured memory_bytes: 3752
// Problem : B - Distance 
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

void solve()
{
	int n,d;cin>>n>>d;
	vp v(n);cin>>v;
	int cnt=0;
	for(auto i:v)
	{
		int dis=i.f*i.f+i.se*i.se;
		if(dis<=d*d)
		cnt++;
	}
	cout<<cnt;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 6344
N = int(input())
p = [int(i) for i in input().split()]
cnt = 0
for i in range(N-1):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        cnt += 1
if p[N-1] == N:
    cnt += 1

print(cnt)

Measured memory_bytes: 13880
from collections import defaultdict
from functools import lru_cache
import sys
input=sys.stdin.readline


class Reroot:
    def __init__(self, N, e, merge, f, g):
        self.G = defaultdict(list)
        self.parents = [-1]*(N+1)
        self.dp = defaultdict(lambda: defaultdict(int))
        self.merge = merge
        self.f = f
        self.g = g
        self.e = e

    def add_edge(self, s, t):
        self.G[s].append(t)

    def build(self):
        self.dfs1(1)
        self.dfs2(1)
        return self.dp

    def dfs1(self, s):
        l = []
        q = [1]
        while q:
            s = q.pop()
            l.append(s)
            for t in self.G[s]:
                if t == self.parents[s]:
                    continue
                self.parents[t] = s
                q.append(t)

        for s in l[::-1]:
            v = self.e
            for t in self.G[s]:
                if t == self.parents[s]:
                    continue
                v = self.merge(v, self.f(self.dp[s][t], s, t))
            self.dp[self.parents[s]][s] = self.g(v, self.parents[s], s)

    def dfs2(self, s):
        q = [(s, self.e)]
        while q:
            s, dp_p = q.pop()
            par = self.parents[s]
            for t in self.G[s]:
                if t == par:
                    self.dp[s][t] = dp_p

            size = len(self.G[s])
            ac_l = [self.e] * (size+1)
            ac_r = [self.e] * (size+1)
            for i, t in enumerate(self.G[s]):
                ac_l[i+1] = self.merge(ac_l[i], self.f(self.dp[s][t], s, t))
            for i, t in enumerate(self.G[s][::-1]):
                ac_r[size-i-1] = self.merge(ac_r[size-i], self.f(self.dp[s][t], s, t))
            self.dp[-1][s] = self.g(ac_l[size], -1, s)

            for i, t in enumerate(self.G[s]):
                if t == par:
                    continue
                q.append((t, self.g(self.merge(ac_l[i], ac_r[i+1]), t, s)))


def solve():
    N = int(input())

    MOD = 10**9+7
    n = N
    fac = [1]*(n+1)
    rev = [1]*(n+1)
    d = defaultdict(list)

    for i in range(1,n+1):
        fac[i] = i*fac[i-1]%MOD
        rev[i] = pow(fac[i], MOD-2, MOD)

    merge1 = lambda x,y:x+y
    f1 = lambda x, par, s:x
    g1 = lambda x, par, s:x+1
    e1 = 0
    tree1 = Reroot(N, e1, merge1, f1, g1)

    merge2 = lambda x,y:(x*y)%MOD
    f2 = lambda x, par, s:(x*rev[tree1.dp[par][s]])%MOD
    g2 = lambda x, par, s:(x*fac[tree1.dp[par][s]-1])%MOD
    e2 = 1
    tree2 = Reroot(N, e2, merge2, f2, g2)

    for _ in range(N-1):
        a, b = map(int, input().split())
        tree2.add_edge(a, b)
        tree2.add_edge(b, a)
        tree1.add_edge(a, b)
        tree1.add_edge(b, a)

    tree1.build()
    ans = tree2.build()

    for i in range(1, N+1):
        print(ans[-1][i])


if __name__ == "__main__":
    solve()


Measured memory_bytes: 368048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
int inf=100000000;
ll INF=5000000000000000000;
ll MOD=1000000007;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    ll ans=0;
    rep(i,n) cin >> a.at(i);
    for(int i=0;i<n-1;i++){
        if (a.at(i)%2==1 && a.at(i+1)!=0) {ans++;a.at(i)--;a.at(i+1)--;}
    }
    rep(i,n) ans+=a.at(i)/2;
    cout << ans << endl;

}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define repd(i, n) for (ll i = (n)-1; i >= 0; --i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    rep(i, 1, n + 1) if (to_string(i).length() % 2 == 1) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3772
import sys


INF = 1 << 32 - 1
S = sys.stdin.readlines()
N, M, L = map(int, S[0].split())

dp = [[INF] * N for _ in range(N)]

for i in range(1, M + 1):
    A, B, C = map(int, S[i].split())
    dp[A - 1][B - 1] = C
    dp[B - 1][A - 1] = C
for i in range(N):
    dp[i][i] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])


dp2 = [[INF] * N for _ in range(N)]
for i in range(N):
    for j in range(N):
        if dp[i][j] <= L:
            dp2[i][j] = 1
for i in range(N):
    dp2[i][i] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            dp2[i][j] = min(dp2[i][j], dp2[i][k] + dp2[k][j])


Q = int(S[M + 1])
for i in range(M + 2, M + 2 + Q):
    s, t = map(int, S[i].split())
    refuel = dp2[s - 1][t - 1]
    if refuel >= 10 ** 3:
        print(-1)
    else:
        print(refuel - 1)


Measured memory_bytes: 72540
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




int main(){
  int n,m,z;
  cin>>n>>m>>z;

  vector<vector<int>> p(n+1,vector<int>(n+1));
  rep(i,m){
    int l,r;
    cin>>l>>r;
    p[l][r]++;
  }

  rep(i,n+1){
    rep(j,n+1){
      if(j+1<=n) p[i][j+1]+=p[i][j];
    }
  }
  rep(j,n+1){
    rep(i,n+1){
      if(i+1<=n) p[i+1][j]+=p[i][j];
    }
  }

  rep(i,z){
    int l,r;
    cin>>l>>r;
    cout << p[r][r]-p[r][l-1]-p[l-1][r]+p[l-1][l-1] << endl;
  }

}

Measured memory_bytes: 4600
using System;
using System.Linq;
using System.Text;
using System.Collections;
using System.Collections.Generic;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = ReadLineInt();
			// double cnt = nC2(n)*2;
			var sur = 1000000007L;
			var ans = longPow(10, n, sur) - longPow(9, n, sur)*2L + longPow(8, n, sur);
			ans += sur*2;
			Console.WriteLine(ans%sur);
		}

		static long longPow(long x, long y, long mod)
		{
			long result = 1;
			for (int i = 0; i < y; i++)
				result = (result * x)%mod;
			return result;
		}

		public static int nCm(int n, int m)
		{
			if (n == 0) return 0;
			if (m == 0) return 1;
			return n * nCm(n - 1, m - 1) / m;
		}

		public static double nC2(double n)
		{
			return (n*(n-1))*0.5;
		}

		public static string ReadLine()
		{
			return Console.ReadLine();
		}

		public static int ReadLineInt()
		{
			return int.Parse(ReadLine());
		}

		public static string[] ReadLineStringSplit(char s = ' ')
		{
			return ReadLine().Split(s).ToArray();
		}

		public static int[] ReadLineIntSplit(char s = ' ')
		{
			return ReadLine().Split(s).Select(x => int.Parse(x)).ToArray();
		}

		public static long[] ReadLineLongSplit(char s = ' ')
		{
			return ReadLine().Split(s).Select(x => long.Parse(x)).ToArray();
		}
	}
}

Measured memory_bytes: 17464
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000000 + 7;

int main(){
    int N; cin >> N;
    string s; cin >> s;
    vector<int> v(27, 0);
    int cnt = 0, acnt = 0;
    for (int i = 0; i < N; i++){
        int m = s[i] - 'a'; 
        if(v[m]==0) cnt++;
        acnt++;
        v[m]++;
    }

    ll ans = 1;
    //cout << cnt << endl;
    for (int i = 0; i < 27; i++) 
    {
        ans *= 1+v[i];
        ans %= mod;
    }
    ans--;    
    cout << ans << endl;
}


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

using namespace std;

const int MX = 100000;

char s[MX + 1];

int main() {
	int k;
	scanf("%s %d", s, &k);
	
	for (int i = 0; s[i] != 0; i++) {
		if (s[i] != 'a' && 'z' - s[i] < k) {
			k -= 'z' - s[i] + 1;
			s[i] = 'a';
		}
	}
	
	int n = strlen(s);
	s[n - 1] = (s[n - 1] + k - 'a') % 26 + 'a';
	
	printf("%s\n", s);
	
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <numeric>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }

    cout << accumulate(v.begin(), v.end(), 0) - n << endl;
    return 0;
}

Measured memory_bytes: 256
def main():

    n = int(input())
    e = [[0]*n for _ in range(n)]

    for i in range(n):
        m = list(map(int,input().split()))
        for j in range(2,len(m)):
            e[m[0]-1][m[j]-1] = 1

    for i in range(n):
        print (' '.join(map(str,e[i])))

if __name__ == '__main__':
    main()




Measured memory_bytes: 5668
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-9)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;
const long long inf = 1e12;



int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
	int n;
	cin >> n;
	vi a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(all(a));
	int dif = a[n / 2] - a[n / 2 - 1];
	cout << dif;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

int main()
{
  int n;
  cin>>n;
  
  int a[n];
  vector<long long int> b(n);
  
  for(int i=0;i<n;i++)
  {
  	cin>>a[i];
  }
  
  b[1]=fabs(a[1]-a[0]);
  
  for(int i=2;i<n;i++)
  {
  	if(b[i-2]+fabs(a[i-2]-a[i]) < b[i-1]+fabs(a[i-1]-a[i]))
  	b[i]=b[i-2]+fabs(a[i-2]-a[i]);
  	else
  	b[i]=b[i-1]+fabs(a[i-1]-a[i]);
  }
  
  cout<<b[n-1];
  
  return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, d; cin >> a >> b >> c >> d;
  if(abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
## coding: UTF-8
from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product
import math


N = int(input())
s = input().split()
p = [int(w) for w in s]
T = p[0]
A = p[1]

t = input().split()
H = [int(w) for w in t]
min_diff = 10000
index = -1
for i in range(N):
    difference = abs(  (T - H[i] * 0.006)     - A)
    if(difference < min_diff):
        min_diff = difference
        index = i

print(index+1)

Measured memory_bytes: 5076
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int X = sc.nextInt();
		int Y = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		long[] aa = new long[A];
		long[] bb = new long[B];
		long[] P = new long[X+Y+C];
		int count = 0;
		for( int i=0; i<A; i++ ){
			aa[i] = sc.nextLong();
		}
		for( int i=0; i<B; i++ ){
			bb[i] = sc.nextLong();
		}
		for( int i=0; i<C; i++ ){
			long cc = sc.nextLong();
			P[count] = cc;
			count++;
		}
		Arrays.sort(aa);
		Arrays.sort(bb);
		for( int i=A-1; i>A-1-X; i-- ){
			P[count] = aa[i];
			count++;	
		}
		for( int i=B-1; i>B-1-Y; i-- ){
			P[count] = bb[i];
			count++;
		}
		Arrays.sort(P);
		long ans = 0;
		for( int i=C; i<X+Y+C; i++ ){
			ans += P[i];
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 97228
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int ans;
        if(n<1){
            ans = m*(m-1)/2;
        } else if(m<1){
            ans = n*(n-1)/2;
        } else {
            ans = n*(n-1)/2+m*(m-1)/2;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35752
#include <iostream>
#include <vector>
#include <algorithm>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<i64> a(n);
    for (auto &e : a) std::cin >> e;

    std::sort(a.begin(), a.end(), std::greater<>());

    i64 ret = a.front();
    for (int i = 2; i < n; i++) ret += a[i / 2];

    std::cout << ret << std::endl;

    return 0;
}


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

typedef struct binaryHeap{
  void *h;
  size_t heapSize;
  size_t maxSize;
  size_t size;
  int (*cmp)(const void *,const void *);
} heap;

heap* newHeap(const size_t size,int (*cmpF)(const void *,const void *)){
  const size_t maxSize=1;
  heap *res=(heap *)malloc(sizeof(heap));
  res->h=malloc(size*(maxSize+1));
  res->heapSize=0;
  res->maxSize=maxSize;
  res->size=size;
  res->cmp=cmpF;
  return res;
}

int isEmpty(const heap *h){
  return h->heapSize==0;
}

void freeHeap(heap *h){
  free(h->h);
  free(h);
  return;
}

void initHeap(heap *h){
  h->heapSize=0;
  return;
}

inline void heapFunc_swap(void * restrict a,void * restrict b,void * restrict tmp,size_t size){
  memcpy(tmp,a,size);
  memcpy(a,b,size);
  memcpy(b,tmp,size);
  return;
}

void push(heap *q,const void *p){
  if(q->heapSize==q->maxSize){
    q->h=realloc(q->h,q->size*(2*q->maxSize+1));
    q->maxSize*=2;
  }
  q->heapSize+=1;
  void *h=q->h;
  int k=q->heapSize;
  const size_t size=q->size;
  int (*cmp)(const void *,const void *)=q->cmp;
  memcpy(h+k*size,p,size);
  while(k>1){
    size_t parent=k/2;
    if(cmp(h+parent*size,h+k*size)<=0) return;
    heapFunc_swap(h+parent*size,h+k*size,h,size);
    k=parent;
  }
  return;
}

void pop(heap *q,void *res){
  void *h=q->h;
  const size_t size=q->size;
  if(res!=NULL) memcpy(res,h+size,size);
  memcpy(h+size,h+size*q->heapSize,size);
  q->heapSize-=1;
  int (*cmp)(const void *,const void *)=q->cmp;
  const size_t n=q->heapSize;
  size_t k=1;
  while(2*k+1<=n){
    size_t next=cmp(h+2*k*size,h+(2*k+1)*size)<=0?2*k:2*k+1;
    if(cmp(h+k*size,h+next*size)<=0) return;
    heapFunc_swap(h+k*size,h+next*size,h,size);
    k=next;
  }
  if(2*k<=n && cmp(h+k*size,h+2*k*size)>0) heapFunc_swap(h+k*size,h+2*k*size,h,size);
  return;
}

void top(const heap *q,void *res){
  memcpy(res,q->h+q->size,q->size);
  return;
}

int cmp(const void *a,const void *b){
  return *(int *)a-*(int *)b;
}

void run(void){
  int h,w,n;
  scanf("%d%d%d",&h,&w,&n);
  heap **q=(heap **)calloc(w+1,sizeof(heap *));
  int i;
  for(i=1;i<=w;i++) q[i]=newHeap(sizeof(int),cmp);
  for(i=0;i<n;i++){
    int x,y;
    scanf("%d%d",&x,&y);
    push(q[y],&x);
  }
  int now=1;
  int min=h;
  for(i=1;i<=w;i++){
    if(!isEmpty(q[i])){
      int v;
      pop(q[i],&v);
      while(!isEmpty(q[i]) && v<=now){
	pop(q[i],&v);
      }
      if(v>now && min>v-1){
	min=v-1;
      }
      if(v==now+1) break;
    }
    now++;
    if(i+1<=w && !isEmpty(q[i+1])){
      int v;
      pop(q[i+1],&v);
      while(!isEmpty(q[i+1]) && v<now){
	pop(q[i+1],&v);
      }
      while(!isEmpty(q[i+1]) && v==now){
	now++;
	pop(q[i+1],&v);
      }
      if(v==now) {
	now++;
      } else if(v>now){
	push(q[i+1],&v);
      }
    }
  }
  printf("%d\n",min);
}

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


Measured memory_bytes: 19456
def gi; gets.to_i end
def gs; gets.chomp end
def gli; gets.split(' ').map(&:to_i) end
def d(n); Math.log10(n).to_i + 1 end
class Integer
  # 約数の組み合わせを列挙する
  def divisor_combinations
    (1..Math.sqrt(self).to_i).
      select { |i| self % i == 0 }.
      map { |i| [i, self / i] }
  end
end

S = gs
difficult = S.chars.each.with_index(1).any? { |s, i| s == (i.odd? ? 'L' : 'R') }
puts difficult ? 'No' : 'Yes'


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

int main(){
    ll N;
    cin >> N;
    ll sum = 0;
    for(ll i=1; i<=N; i++){
        if(i%3 != 0 && i%5 != 0){
            sum += i;
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3588