akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define fastio std::ios::sync_with_stdio(false);
#define ll long long
#define scann(n) scanf("%d",&n)
#define scand(n) scanf("%lf",&n)
#define scans(s) scanf("%s",&s)
#define pb push_back
#define ppb pop_back
#define full v.begin(),v.end()
#define debug cout<<"Bug! Vag! Bagh!"<<endl;
#define pi acos(-1)
#define mx 10010
#define inf 10e10

int main()
{
    ll n;
    cin>>n;
    vector<ll>v;
    ll x;
    ll ans=0;
    cin>>x;
    v.pb(x);
    ll flag=x;
    for(ll i=1;i<n;i++)
    {
        cin>>x;
        if(x<flag)
        {
            ans=ans+flag-x;
        }
        else
        {
            flag=x;
        }
    }
    cout<<ans<<endl;

    return 0;
}
///arBishal_2017331022


Measured memory_bytes: 3564
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
// #include<unordered_map>
#include<set>
// #include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y, idx;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

ll bisect_left(ll arr[], ll arr_size, ll key) {
	return distance(arr, lower_bound(arr, arr + arr_size, key));
}

ll bisect_left(vector<ll> vc, ll key) {
	return lower_bound(vc.begin(), vc.end(), key) - vc.begin();
}

ll pow_mod(ll a, ll x) {
	if (x == 0) return 1;
	if (x == 1) return a;
	ll ret = pow_mod(a, x / 2);
	if (x % 2 == 0) ret = (ret*ret) % MOD;
	else ret = (a * ((ret*ret) % MOD)) % MOD;
	return ret;
}

void build_mod_fact(ll arr[], ll n) {
	arr[0] = 1;
	repi(i, 1, n + 1) {
		arr[i] = (arr[i - 1] * i) % MOD;
	}
	return;
}

void build_mod_fact_inv(ll arr_fact[], ll arr_fact_inv[], ll n) {
	arr_fact_inv[n] = pow_mod(arr_fact[n], MOD - 2);
	repd(i, n - 1, -1) {
		arr_fact_inv[i] = (arr_fact_inv[i + 1] * (i + 1)) % MOD;
	}
	return;
}

ll comb_mod(ll n, ll r, ll arr_fact[], ll arr_fact_inv[]) {
	return (((arr_fact[n] * arr_fact_inv[n - r]) % MOD) * arr_fact_inv[r]) % MOD;
}


///////////////////////////////////////////////////////////////////////////////////////

ll n, fact[MAX_10p5], fact_inv[MAX_10p5];
ll l, r, idx[MAX_10p5];

int main() {
	cin >> n;
	build_mod_fact(fact, n + 1);
	build_mod_fact_inv(fact, fact_inv, n + 1);
	repi(i, 1, n + 2) {
		ll t;
		cin >> t;
		if (idx[t] == 0) idx[t] = i;
		else {
			l = idx[t];
			r = i;
			break;
		}
	}
	repi(i, 1, n + 1) {
		ll ans = comb_mod(n + 1, i, fact, fact_inv);
		if ((l - 1) + (n + 1 - r) >= i - 1) {
			ans -= comb_mod((l - 1) + (n + 1 - r), i - 1, fact, fact_inv);
			if (ans < 0) ans += MOD;
			cout << ans << endl;
		}
		else {
			cout << ans << endl;
		}
	}
	cout << 1 << endl;
	return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using ll = unsigned long long;
using namespace std;

int main(void) {
    int k, x;
    cin >> k >> x;

    // int min = -1000000;
    // int max = 1000000

    for (int start = x - (k-1);start <= x + (k-1); start++) {
        cout << start << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // clang-format off
using namespace std;
using Int = long long;
#define REP2(i, n) for (Int i = 0, max_i = (n); i < max_i; i++)
#define REP3(i, a, b) for (Int i = (a), max_i = (b); i < max_i; i++)
#define OVERLOAD2(_1, _2, _3, name, ...) name
#define REP(...) OVERLOAD2(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
struct in {
    int n; in() {} in(int n_) : n(n_){}
    template <class T> operator T() { T ret; cin >> ret; return ret; }
    template <class T> operator vector<T>() { vector<T> ret(n); for (int i = 0; i < n; i++) cin >> ret[i]; return ret; }
};
struct SetupIO { SetupIO() { cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Jan 18 21:00:12 JST 2020
 **/

using pii = pair<Int, Int>;
template <class T> inline bool chmin(T& a, const T& b) {
    if (a <= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmax(T& a, const T& b) {
    if (a >= b) return false;
    a = b;
    return true;
}

signed main() {
    Int n = in();
    vector<pii> a(n);
    REP(i, n) {
        Int x = in(), L = in();
        a[i] = {x + L, x - L};
    }
    sort(a.begin(), a.end());
    Int ma = -1e18, ans = 0;
    REP(i, n) {
        if (a[i].second >= ma) {
            chmax(ma, a[i].first);
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
  int a,b;
  int c;

  scanf("%d",&a);
  scanf("%d",&b);

  c = (a + b)/2;
  if((a+b) % 2 == 1){
    c = c + 1;
  }

  printf("%d",c);

  return 0;
}


Measured memory_bytes: 128
//Author: A_S_M_M@sud_P@rvez
#include<bits/stdc++.h>
using namespace std;
#define    MP ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define    for0(i,n) for(int i=0;i<n;i++)
#define    forn(i,n) for(int i=1;i<=n;i++)
#define    fors(i,s) for(int i=0;i<s.size();i++)
#define    Sort(s) sort(s.begin(),s.end())
#define    gcd(a, b) __gcd(a , b)
#define    lcm(a,b) (a*(b/__gcd(a,b)))
#define    nl     "\n"
#define    End    return 0 
#define    gt     greater<int>()
#define    ll     long long int
#define    mp     make_pair
#define    pb     push_back
#define    vi     vector<int>
#define    vl     vector<ll>
#define    mod    1000000007
#define    sp(n)  fixed<<setprecision(n)
#define    pi     acos(-1)
const ll inf=1000000000000000000;
int main()
{
MP;
	ll n,a,s1=1;
    double s=1.0;
    cin>>n;
    forn(i,n)
    {
        cin>>a;
        s1*=a;
        s*=a*1.0;
    }
    if(s>inf||s1>inf)cout<<-1;
    else cout<<s1;
	
End;
}


Measured memory_bytes: 3644
#include<stdio.h>
int main()
{
    int a,b,k,s,f;
    scanf("%d %d",&a,&b);
    k=(a+b)/2;
    s=abs(a-k);
    f=abs(b-k);

    if(s==f&&a!=b)
    {
        printf("%d\n",k);
    }
    else
    {
        printf("IMPOSSIBLE\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e4;
const long inf=1e18;
int main(){
	int N,K;cin>>N>>K;
	int cnt=0;
	while(N>=K){
		N/=K;
		cnt++;
	}
	cout<<cnt+1<<endl;
}

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

#define IOS cin.tie(0);ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vs      vector<string>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())
#define END cout<<"\n"

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)    for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 200;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//


signed main(){
    CIN(a,b,c,d);
    while(a>0&&c>0){
        c-=b;
        if(c<=0||a<=0)break;
        a-=d;
    }
    if(c<=0)printf("Yes");
    else printf("No");

    return 0;
}

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

using namespace std;
# define ll long long int
ll sq(ll a,ll b)
{
    ll res=ceil(sqrt(a*a+b*b));
    return res;
}
int main()
{
    ll n,d,c;
    cin>>n>>d;
    c=d*d;
    int count=0;
    for(int i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        if(abs(x)>d||abs(y)>d)
        {
            continue;
        }
         ll dist=sq(x,y);
        if(dist<=d)
        {
           count++;
        }

    }
    cout<<count;
    return 0;
}


Measured memory_bytes: 3736
#include<bits/stdc++.h>
#define ll long long
#define ii pair<int,int>
#define vi vector<int>


using namespace std;

int power(int a,int b){
    if(b == 0)return 1;
    int r = power(a,b/2);
    if(b%2)return r*r*a;
    else return r*r;
}


int main(){
    int n;cin>>n;
    vector<int>a(n);
    for(int i = 0;i<n;i++){
        cin>>a[i];
    }
    int mn = 0;
    for(int i =0;i <n-1;i++){
        if(a[i] > a[i+1]){
            a[i]--;
            mn = max(a[i],mn);
        }
        if(a[i] < mn){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}

Measured memory_bytes: 640
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
string a,b;
int main(){
	cin>>a>>b;
	bool f = 1;
	for(int i = 0;i < a.size();i++){
		if(a[i] != b[i]) {f = 0;break;}
	}
	if(f) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	if (s[0] == s[1] && s[2] == s[3] && s[0] != s[3])cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

using namespace std;

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

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

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

int cnt[300];

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

    int N, Q;
    while(true){
        std::cin >> N >> Q;
        if(!N){break;}

        memset(cnt, 0, sizeof(cnt));
    
        for(int i=0;i<N;++i){
            int M;
            std::cin >> M;

            for(int j=0;j<M;++j){
                int d;
                std::cin >> d;

                ++cnt[d];
            }
        }
        
        int res = 0;
        for(int i=1;i<200;++i){
            if(cnt[i] >= Q && cnt[i] > cnt[res]){
                res = i;
            }
        }

        std::cout << res << std::endl;
    }
}



Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <climits>
using namespace std;

typedef vector<int>			vi;
typedef vector<vi>			vvi;
typedef vector<vvi>			vvvi;
typedef long long int 		ll;
typedef vector<ll>			vll;
typedef vector<vll>			vvll;
typedef vector<vvll>		vvvll;

typedef pair<int, int>		ii;
typedef vector<ii>			vii;
typedef set<int> 			si;


int main(){

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

	int r, d, x;
	cin >> r >> d >> x;

	for(int i = 1; i <= 10; i++){
		x = r * x - d;
		cout << x << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;
using ps = pair<string,string>;

int main(){
    int n;
    while(cin >>n,n){
        int d;
        cin >>d;
        vector<string> name(n);
        rep(i,n) cin >>name[i];
        sort(all(name));

        vector<set<string>> v(n);
        rep(i,n){
            string s = name[i];
            int S = s.size();
            string t;

            // delete
            rep(j,S){
                t = s;
                t.erase(t.begin()+j);
                v[i].insert(t);
            }

            // insert
            rep(j,S+1){
                rep(k,26){
                    char c = 'a'+k;
                    t = s;
                    t.insert(j,string(1,c));
                    v[i].insert(t);
                }
            }

            // replace
            rep(j,S){
                rep(k,26){
                    char c = 'a'+k;
                    t = s;
                    if(t[j] != c){
                        t[j] = c;
                        v[i].insert(t);
                    }
                }
            }

            // swap ADJACENT
            rep(j,S-1){
                t = s;
                if(t[j]!=t[j+1]){
                    swap(t[j],t[j+1]);
                    v[i].insert(t);
                }
            }
        }

        map<string,vector<int>> idx;
        rep(i,n){
            for(string ss:v[i]) idx[ss].pb(i);
        }

        set<pi> ans;
        // d==1
        rep(i,n)for(int j=i+1; j<n; ++j){
            if(v[i].count(name[j])) ans.insert({i,j});
        }
        if(d==2){
            for(const auto p:idx){
                vector<int> tt = p.se;
                int sz = tt.size();

                rep(i,sz)rep(j,i){
                    if(tt[j]!=tt[i]) ans.insert({tt[j],tt[i]});
                }
            }
        }

        // for(pi p:ans) dbg(p);
        for(pi p:ans) cout << name[p.fi] << "," << name[p.se] << "\n";
        cout << ans.size() << "\n";
    }
    return 0;
}



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

int main() {
  string S; cin >> S;
  int N = S.size();
  int sum = 0;
  for (int i = 0; i < N; i++) sum += S[i] - '0';
  cout << (sum % 9 == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3688
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#define pb push_back
#define mp make_pair
using namespace std;

int n;
string s;
string tar = "keyence";


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

    cin >> s;
    n = (int)s.size();

    if(s == tar)
    {
        cout << "YES" << endl;
        return 0;
    }
    if(n < (int)tar.size())
    {
        cout << "NO" << endl;
        return 0;
    }

    int to_rmv = n - (int)tar.size();
    for(int i = 0; i + to_rmv <= n; i++)
    {
        string cur = "";
        for(int j = 0; j < i; j++)
            cur.pb(s[j]);
        for(int j = i + to_rmv; j < n; j++)
            cur.pb(s[j]);

        if(cur == tar)
        {
            cout << "YES" << endl;
            return 0;
        }
    }

    cout << "NO" << 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 a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		int c = sc.nextInt();
      		int d = sc.nextInt();
		int e = sc.nextInt();
if(a==0){
  System.out.println("1");
}else if(b==0){
  System.out.println("2");
}else if(c==0){
  System.out.println("3");
}else if(d==0){
  System.out.println("4");
}else if(e==0){
  System.out.println("5");
}
	}
}

Measured memory_bytes: 35684
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()

bool binarysearch(int ans, vector<int> s) {
  int left = 0;
  int right = s.size();
  while(left < right) {
    int mid = (left+right)/2;
    if(s.at(mid) == ans) return 1;
    else if(s.at(mid) < ans) left = mid+1;
    else right = mid;
  }
  return 0;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, q;
  cin >> n;
  vector<int> s(n);
  rep(i, 0, n) cin >> s.at(i);
  cin >> q;
  
  int c = 0;
  int t;
  
  rep(j, 0, q) {
    cin >> t;
    if(binarysearch(t, s)) c++;
  }    
  
  cout << c << "\n";

}



Measured memory_bytes: 3440
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	//adjMatrix[u][v] = 1 if there is an edge from u to v, otherwise 0
	private int[][] adjMatrix;
	//adjWeight[u][v] -- the weight of the edge from u to v if there is one
	private int[][] adjWeight;
	//if a node is settled (e.g., processed in the Dijkstra's algorithm)
	private Boolean[] ifSettled;
	public Graph() { totalVertex = 0; }
	public int getTotalVertex() { return totalVertex; }
	//load graph from standard input
	public void loadAdjMatrix() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjMatrix = new int[totalVertex][totalVertex];
		adjWeight = new int[totalVertex][totalVertex];
		ifSettled = new Boolean[totalVertex];
		int i, j;
		for (i = 0; i < totalVertex; i++) {
			for (j = 0; j < totalVertex; j++) {
				adjWeight[i][j] = in.nextInt();
				if (adjWeight[i][j] != -1) {
					adjMatrix[i][j] = 1;
				}
			}
			ifSettled[i] = false;
		}
		in.close();;
	}
	//return weight of the edge from u to v if there is one
	public int getWeight(int u, int v) {
		return adjWeight[u][v];
	}
	//return neighbors of u as a LinkedList
	public LinkedList<Integer> getNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if(adjMatrix[u][v] == 1) tmp.add(v);
		}
		return tmp;
	}
	//return unsettled neighbors of u as a LinkedList
	public LinkedList<Integer> getUnsettledNeighbors(int u) {
		LinkedList<Integer> tmp = new LinkedList<Integer>();
		for(int v = 0; v < totalVertex; v ++) {
			if((adjMatrix[u][v] == 1) && (ifSettled[v] == false)) tmp.add(v);
		}
		return tmp;
	}
	//return the unsettled node that has the smallest dist
	public int getUnsettledNearest(int[] dist) {
		int md = Integer.MAX_VALUE;
		int mv = -1;
		int v;
		for(v = 0; v < totalVertex; v ++) {
			if((ifSettled[v] == false) && (dist[v] < md)) {
				md = dist[v];
				mv = v;
			}
		}
		return mv;
	}
	//implement the following	
	public int[] Dijkstra(int s) {		
		int[] dist = new int[totalVertex];
		
		for (int i=0;i<totalVertex;i++) {
			dist[i] = Integer.MAX_VALUE;
		}
		
		dist[s] = 0;			
		int curr = s;
		
		while (curr != -1 && dist[curr] != Integer.MAX_VALUE) {
			LinkedList<Integer> neighbor = getUnsettledNeighbors(curr);
			ifSettled[curr] = true;
			for(Integer i : neighbor) {
				dist[i] = Math.min(dist[i], getWeight(curr, i));
			}
			
			curr = getUnsettledNearest(dist);
		}		
		return dist;

	}
}

public class Main{
	public static void main(String[] argv) {
		Graph g = new Graph();
		g.loadAdjMatrix();
		int[] dist = g.Dijkstra(0);
		int n = 0;
		for(int i = 0; i < g.getTotalVertex(); i ++) {
			n += dist[i];
		}
		System.out.println(n);
	}
}


Measured memory_bytes: 40864
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;
const ll MAXN = 1000000;
const ll MOD = 998244353;

void err()
{
    cout << 0 << endl;
    exit(0);
}

int main()
{
    int n;
    cin >> n;
    vector<ll> cnts(MAXN, 0);
    rep(i, 0, n)
    {
        int d;
        cin >> d;
        if (i == 0 ^ d == 0) err();

        ++cnts[d];
    }
    if (cnts[0] != 1)
    {
        cout << 0 << endl;
        return 0;
    }

    ll res = 1;
    rep(i, 0, MAXN)
    {
        rep(j, 0, cnts[i+1])
        {
            res *= cnts[i];
            res %= MOD;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 8064
def solve():
    n = int(input())
    lst = [int(input())-1 for _ in[0]*n]
    visit = set()
    current = 0
    while True:
        visit.add(current)
        current = lst[current]
        if current == 1:
            print(len(visit))
            break
        if current in visit:
            print(-1)
            break

if __name__=="__main__":
    solve()

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

int main() {
  int a, N;
  cin >> N;
  int cnt = 0;
  rep(i, N) {
    cin >> a;
    if ((i + 1) % 2 == 0) continue;
    if (a % 2 == 0) continue;
    cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <vector>
#define ll long long
using namespace std;
const int N=1e6+50;
int a[N],w[N],fa[N];
int gi(){
    char ch=getchar(); int x=0,q=0;
    while(ch<'0'||ch>'9') q=ch=='-'?1:q,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return q?-x:x;
}
struct D{
    ll W; int s,x;
    bool operator <(const D &p) const {
        if(W*p.s!=p.W*s) return W*p.s<p.W*s;
        return x<p.x;
    }
}p[N];
int cnt=0,b[N];
set<D>treap;
int fat(int x){ return b[x]==x?x:b[x]=fat(b[x]); }
void del(const D &w) { treap.erase(w); return; }
void ins(const D &w) { treap.insert(w); return; }
void work(int n){
    cnt=n;
    ll ans=0; D t;
    while(!treap.empty()){
	t=*treap.begin(); treap.erase(t);
	int y=fat(fa[t.x]);
        if (!y) continue;
	ans+=(t.s-t.W)*p[y].W;
	del(p[y]);
        D G=t;
        G.W+=p[y].W,G.s+=p[y].s,G.x=++cnt;
        b[cnt]=cnt,b[y]=cnt,b[fat(t.x)]=cnt;
        fa[cnt]=fa[y],fa[t.x]=cnt;
        p[cnt]=G,ins(G);
    }
    cout<<ans<<endl;
    return;
}
int main(){
    int n=gi();
    for (int i=2;i<=n;i++) fa[i]=gi();
    for (int i=1;i<=n;i++) w[i]=gi();
    for (int i=1;i<=n;i++){
        p[i]=(D){w[i],1,i};
        treap.insert(p[i]);b[i]=i;
    }
    work(n);
    return 0;
}


Measured memory_bytes: 28672
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int x,y;
    cin>>x>>y;
    //maxmin
    if(y>x)swap(x,y);
    while(x%y!=0)
    {
        x=x%y;
        if(y>x)swap(x,y);
    }
    cout<<y<<endl;
    return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = a; i >= (b); --i)
#define all(x) x.begin(), x.end()
#define pb  push_back
#define mb  make_pair
#define fi  first
#define se  second
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
const ll mod = 1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}



void solve()
{
    long v, n;
    cin >> v >> n;
    long sum = 0,t;
    rep(i,0,n)
    {
        cin >> t;
        sum += t;
    }
    if(sum > v)
        cout << -1;
    else
        cout << v - sum;
}

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

	solve();
	return 0;
}


Measured memory_bytes: 3644
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int[] arr = new int[in.nextInt() + 1];
		for(int i = 1; i < arr.length; i++) {
			arr[i] = in.nextInt();
		}
		for(int i = 1; i < arr.length; i++) {
			System.out.print("node " + i + ": key = " + arr[i]  + ", ");
			if(i != 1) System.out.print("parent key = " + arr[(i / 2)] + ", ");	
			if(i * 2 < arr.length) System.out.print("left key = " + arr[i * 2] + ", ");
			if(i * 2 + 1 < arr.length) System.out.print("right key = " + arr[(i * 2) + 1] + ", ");
			System.out.print("\n");
		}
	}
}



Measured memory_bytes: 27488
import unittest


class TestC(unittest.TestCase):
    def test_1(self):
        self.assertEqual(
            think(2, [[1, 'WA'], [1, 'AC'], [2, 'WA'], [2, 'AC'], [2, 'WA']]),
            (2, 2)
        )

    def test_2(self):
        self.assertEqual(
            think(100000, [[7777, 'AC'], [7777, 'AC'], [7777, 'AC']]),
            (1, 0)
        )

    def test_3(self):
        self.assertEqual(
            think(6, []),
            (0, 0)
        )


def solve():
    n, list_of_p_and_s = read()
    result = think(n, list_of_p_and_s)
    write(result)


def read():
    n, m = read_int(2)
    list_of_p_and_s = []
    for _ in range(m):
        p_and_s = input().split(' ')[:2]
        list_of_p_and_s.append([int(p_and_s[0]), p_and_s[1]])
    return n, list_of_p_and_s


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(n, list_of_p_and_s):
    ac = [False for _ in range(n + 1)]
    penalty = [0 for _ in range(n + 1)]

    for p, s in list_of_p_and_s:
        if s == 'AC':
            ac[p] = True
        elif s == 'WA':
            if ac[p]:
                continue
            else:
                penalty[p] += 1
        else:
            raise RuntimeError()

    count_a = 0
    sum_penalty = 0
    for a, p in zip(ac, penalty):
        if a:
            count_a += 1
            sum_penalty += p
    return count_a, sum_penalty


def write(result):
    print('{0:d} {1:d}'.format(result[0], result[1]))


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 84692
#include<stdio.h>
int main(void){
int N, ch=0;
scanf("%d", &N);
for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
       if(N != i*j){
   ch+=1;
    } 
  }
}
if(ch ==81){
  printf("No\n");
}else{
  printf("Yes\n");
}
return 0;
}

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

int main() {
  string data;
  int counter_1 = 0;
  int counter_0 = 0;

  cin >> data;

  for(int i = 0;i < data.size();i++){
    if(data.at(i) == '0')counter_0++;
    else counter_1++;
  }

  cout << min(counter_0,counter_1) * 2 << endl;;
}


Measured memory_bytes: 512
///   ***   ---   |||		 In the name of ALLAH		|||   ---   ***   ///



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


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
//
//debug
template<typename F,typename S>ostream&operator<<(ostream&os,const pair<F,S>&p){return os<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&v){os<<"{";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"}";}
template<typename T>ostream&operator<<(ostream&os,const set<T>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<",";os<<*it;}return os<<"]";}
template<typename T>ostream&operator<<(ostream&os,const multiset<T>&v) {os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"]";}
template<typename F,typename S>ostream&operator<<(ostream&os,const map<F,S>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<it->first<<" = "<<it->second;}return os<<"]";}
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu(){cerr << endl;}
template<typename T>void faltu(T a[],int n){for(int i=0;i<n;++i)cerr<<a[i]<<' ';cerr<<endl;}
template<typename T,typename...hello>void faltu(T arg,const hello&...rest){cerr<<arg<<' ';faltu(rest...);}
//#else
//#define dbg(args...)

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


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

const int mx = 1e5+123;

int dp[mx][4], n;
int a[mx][4];

int solve ( int i, int f1 )
{
	if ( i == n ) return 0;
	if ( dp[i][f1] != -1 ) return dp[i][f1];

	int ret = 0;
	for ( int j = 1; j <= 3; j++ ) {
		if ( j != f1 ) {
			ret = max ( ret, a[i][j] + solve ( i+1, j ) );
		}
	}

	return dp[i][f1] = ret;
}

int main()
{
	optimize();

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


	mem ( dp, -1 );
	int ans = 0;
	for ( int i = 1; i <= 3; i++ ) ans = max ( ans, a[0][i] + solve ( 1, i ) );
	cout << ans << endl;

	return 0;
}


















Measured memory_bytes: 14536
#include <cstdio>
#include <cstdlib>
#include <iostream>

using namespace std;

long long int n;
int digitCount(long long int num) {
    int res = 0;
    if (num == 0)
        return 1;
    
    while (num) {
        num /=10;
        res++;
    }
    return res;
}

int f(long long int a, long long int b) {
    return max(digitCount(a),digitCount(b));
}

int main()
{
    cin >> n;
    long long int ans = 9876543210;
    for (long long int i = 1; i*i <= n; i++) {
        
        if (n % i == 0) {
            int t = f(i, n/i);
            if (t < ans)
                ans = t;
        }
    }
    cout << ans << "\n";
    
    
    return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  int N; cin >> N;
  vector<int> d(N); REP(i, N) cin >> d[i];
  int ans = 0;
  for(int i = 0; i < N; ++i) {
    for(int k = i + 1; k < N; ++k) {
       ans += (d[i] * d[k]);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3580
import java.util.Scanner;

// https://atcoder.jp/contests/abc139/tasks/abc139_a
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();

		int ans = 0;
		int count = 1;

		while(count<B) {
			count = count -1;
			count = count + A;
			ans = ans + 1;
		}

		System.out.println(ans);

	}

}


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

int main() {
  string s;
  cin>>s;
  int q;
  cin>>q;
  int cur=1;
  string a="",b="";
  for(int i=0;i<q;i++){
    int t;
    cin>>t;
    if(t==1) {
      if(cur==1) cur=2;
      else cur=1;
    }
    else{
      int v;
      cin>>v;
      char c;
      cin>>c;
      if(v==1) {
        if(cur==1) a=c+a;
        else b=b+c;
      }
      else{
        if(cur==1) b=b+c;
        else a=c+a;
      }
    }
  }
  if(cur==1) cout<<a+s+b<<endl;
  else {
    reverse(a.begin(),a.end());
    reverse(s.begin(),s.end());
    reverse(b.begin(),b.end());
    cout<<b+s+a<<endl;
  }
  return 0;
}

Measured memory_bytes: 1512
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const int MAX_N = 100000;
ll fact[MAX_N + 1];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll ans;
    fact[0] = 0;
    fact[1] = 1;
    ll fs = 1;
    for (int i = 2; i < MAX_N + 1; i++){
        fs = (fs*i) % MOD;
        fact[i] = (fact[i-1] + fs) % MOD;
    }
    while (1){
        int N, R;
        cin >> N;
        if (N == 0) break;
        vector<int> word(N);
        for (int i = 0; i < N; i++) word[i] = i;
        word.push_back(0);
        ans = 0;
        cin >> R;
        vector<int> s(4*R+2, 0);
        s[2 * R + 1] = N;
        for (int i = 0; i < R; i++){
						int s1, s2;
            cin >> s1 >> s2;
						s[4*i]   = s1;
            s[4*i+1] = s2;
            s1--; s2--;
            s[4*i+2] = s1;
						s[4*i+3] = s2;
            swap(word[s1], word[s2]);
        }
				s[4*R] = 0; s[4*R+1] = N;
        sort(s.begin(), s.end());
        s.erase(unique(s.begin(), s.end()), s.end());
        for (int i = 0, R = s.size() - 1; i < R; i++){
            ans =(ans + word[s[i]] * (fact[N - s[i] - 1] - fact[N - s[i+1] - 1] + MOD)) % MOD;
            for (int j = i + 1, dif = s[i+1] - s[i]; j < R; j++){
                word[s[j]] -= (word[s[j]] > word[s[i]] ? dif : 0);
            }
        }
        cout << ans % MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 2792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
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; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


int main() {
    string s; cin >> s;
    map<char,ll> mp;
    bool ok = true;
    for (ll i = 0;i<s.size();i++) {
        mp[s.at(i)]++;
        if (mp[s.at(i)] >= 2) ok = false;
    }
    if (ok) cout << "yes" << endl;
    else cout << "no" << endl;
}


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

using namespace std;

typedef long long ll;
#define INF (1<<29)
#define INFF 0x7fffffff
#define LINF (1ll<<60)
#define LINFF 0x7fffffffffffffff
#define PI 3.14159265359
#define _fi(n) for(int i = 0;i < n;i++)
#define _fj(n) for(int j = 0;j < n;j++)
#define _fk(n) for(int k = 0;k < n;k++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define YESNO(ans) cout << (ans?"YES":"NO") << endl;
#define pqueue priority_queue
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define endl '\n'


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

    int n, k, s;cin>>n>>k>>s;

    vector<int>v;
    _fi(k) v.pb(s);
    _fi(n-k) v.pb((s+2)%1000000000);

    for(auto x:v) cout << x << " ";
    cout << endl;

    return 0;
}


Measured memory_bytes: 1912
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define rFOR(i, a, b) for(int i=b; i>=a; i--)
#define MAX 2001
typedef long long ll;
using namespace std;

int main(void){
  int r;  cin >> r;
  if(r<1200)  cout<<"ABC"<<endl;
  else if(r<2800) cout << "ARC" << endl;
  else cout << "AGC" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int x, y;
    cin >> x >> y;

    int a, b, c;
    cin >> a >> b >> c;

    vector<int> p(a), q(b), r(c);
    for (int i = 0; i < a; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < b; i++) {
        cin >> q[i];
    }
    for (int i = 0; i < c; i++) {
        cin >> r[i];
    }
    sort(p.begin(), p.end(), greater<>());
    sort(q.begin(), q.end(), greater<>());
    sort(r.begin(), r.end(), greater<>());

    ll t = 0;
    for (int i = 0; i < x; i++) {
        t += p[i];
    }
    for (int i = 0; i < y; i++) {
        t += q[i];
    }

    ll s = t;
    int m = min(x + y, c);
    x--; y--;
    for (int i = 0; i < m; i++) {
        t += r[i];
        if (x >= 0 && (y < 0 || p[x] < q[y])) {
            t -= p[x--];
        } else {
            t -= q[y--];
        }
        s = max(s, t);
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 1408
#include<cstdio>

const int maxn = 1e5 + 10;

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

int A[maxn], pre[maxn], suf[maxn];

inline void upt(int &x, int y)
{
	x = x < y ? y : x;
}

int main()
{
	int N;
	scanf("%d", &N);
	for(int i = 1; i <= N; ++i)
		scanf("%d", &A[i]);
	pre[1] = A[1];
	for(int i = 2; i <= N; ++i)
		pre[i] = gcd(pre[i - 1], A[i]);
	suf[N] = A[N];
	for(int i = N - 1; i >= 1; --i)
		suf[i] = gcd(suf[i + 1], A[i]);
	int ans = 0;
	pre[0] = suf[N + 1] = 0;
	for(int i = 1; i <= N; ++i)
		upt(ans, gcd(pre[i - 1], suf[i + 1]));
	printf("%d\n", ans);	
}

Measured memory_bytes: 1280
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int n;cin>>n;
  cout << 3 * n * n << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int x;
	cin >> x;
	i64 t = 1;
	int i = 1, sum = 0;
	while (1) {
		sum += i;
		if (sum >= x) {
			break;
		}
		t++;
		i++;
	}
	cout << t << endl;
	return 0;
}

Measured memory_bytes: 256
def resolve():
    n, m = map(int, input().split())
    arr = [None] * n
    for i in range(m):
        s, c = input().split()
        s = int(s) - 1
        if arr[s] is None or arr[s] == c:
            arr[s] = c
        else:
            return print(-1)

    if arr[0] == '0' and n >= 2:
        return print(-1)

    if arr[0] is None:
        if n == 1:
            arr[0] = '0'
        else:
            arr[0] = '1'

    arr = ['0' if e is None else e for e in arr]

    print(''.join(arr))

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 3064
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MultiWayIf #-}


import Control.Arrow
import Control.Concurrent
import Control.Monad
import qualified Data.ByteString.Builder as B
import qualified Data.ByteString.Char8 as C
import Data.Complex
import Data.Char
import Data.Function
import Data.Function.HT
import qualified Data.IntMap.Strict as IM
import qualified Data.IntSet as IS
import Data.List
import Data.Monoid
import Data.Ord
import qualified Data.Sequence as Sq
import Data.Vector.Algorithms.Search
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import Debug.Trace
import System.IO


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine


main :: IO ()
main = do
    n <- readLn
    let (s,d) = shift n
    putStrLn $ toStr (n - s - 1) d


shift n = (last &&& length) $ (0:) $ takeWhile (<n) $ scanl1 (+) $ map (26^) [1..]

toStr n d
    | d == 0 = []
    | otherwise = let   s = 26^(d-1)
                        (dv,m) = divMod n s
        in chr (ord 'a' + dv) : toStr m (d-1)




Measured memory_bytes: 3908
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#define INF 900000000
 
using namespace std;
 	int v=0;
 	int a,b;char op;
int main()
{

	while(v<=0){
		while(cin>>a>>op>>b){
		if(op=='+') cout<<a+b<<endl;
		if(op=='-') cout<<a-b<<endl;
		if(op=='*') cout<<a*b<<endl;
		if(op=='/') cout<<a/b<<endl;
		if(op=='?') v++;
	}
	}
	return 0;
}



Measured memory_bytes: 3084
using System;
using System.Collections.Generic;
using System.Linq;

namespace Baumkuchen {
	class Baumkuchen {
		static void Main(string[] args) {		
			int N = int.Parse(Console.ReadLine());
			long[] v_list = new long[N + 1];
			v_list[0] = 0;
			for (int n = 1; n < N + 1; n++) {
				v_list[n] = v_list[n - 1] + long.Parse(Console.ReadLine());
			}
			Baumkuchen baumkuchen = new Baumkuchen(v_list);
			Console.WriteLine(baumkuchen.GetAnwser());
		}

		readonly long[] v_list;
		readonly int N;
		readonly double tripartition;
		public Baumkuchen(long[] _v_list) {
			N = _v_list.Length - 1;
			v_list = _v_list;
			tripartition = v_list[N] / 3.0;
		}

		public long GetAnwser() {
			long interm_maxV = -1;
			int n0_max = findLeftIndex(0, N, tripartition);
			for (int n0 = 0; n0 <= n0_max; n0++){
				long tmp = searchOne(n0);
				if (tmp > interm_maxV) interm_maxV = tmp;
			}
			return interm_maxV;
		}

		private long searchOne(int n0) {
			int n1_left = findLeftIndex(n0, N, tripartition + v_list[n0]);
			int n2_left = findLeftIndex(n1_left, N, 2 * tripartition + v_list[n0]);
			long V_ll = getMinV(n0, n1_left, n2_left);
			long V_lr = getMinV(n0, n1_left, n2_left + 1);
			long V_rl = getMinV(n0, n1_left + 1, n2_left);
			long V_rr = getMinV(n0, n1_left + 1, n2_left + 1);
			return Math.Max(Math.Max(V_ll, V_lr), Math.Max(V_rl, V_rr));
		}

		private long getMinV(int n0, int n1, int n2) {
			long V0 = v_list[n1] - v_list[n0];
			long V1 = v_list[n2] - v_list[n1];
			long V2 = v_list[n0] - v_list[n2] + v_list[N];
			return Math.Min(Math.Min(V0, V1), V2);
		}

		private int findLeftIndex(int from_n, int to_n, double target) {
			int n_left = from_n;
			int n_right = to_n;
			while (n_right - n_left !=1) {
				int n_mid = (n_right + n_left) / 2;
				if (v_list[n_mid] <= target) n_left = n_mid;
				else n_right = n_mid;
			}
			return  n_left;
		}
	}
}

Measured memory_bytes: 21236
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD (ll) (1e9+7)
int main()
{
	string s;
	cin>>s;
    if(s=="RRS")
    {
    	cout<<2<<"\n";
    }
    else if(s=="SRR")
    {
    	cout<<2<<"\n";
    }
    else if(s == "SRS" || s == "RSR" || s=="SSR" || s=="RSS")
    {
    	cout<<1<<"\n";
    }
    else if(s=="RRR")
    {
    	cout<<3<<"\n";
    }
    else if(s=="SSS")
    {
    	cout<<0<<"\n";
    }
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define MOD 1000000007
int n,m,a[1111],b[1111],ans=1;
signed main(){
	cin>>n>>m;
	rep(i,n)cin>>a[i];
	rep(i,m)cin>>b[i];
	sort(a,a+n);
	sort(b,b+m);
	rep(i,n-1){
		if(a[i]==a[i+1]){
			puts("0");
			return 0;
		}
	}
	rep(i,m-1){
		if(b[i]==b[i+1]){
			puts("0");
			return 0;
		}
	}
	for(int i=n*m;i>=1;i--){
		bool s=binary_search(a,a+n,i),t=binary_search(b,b+m,i);
		if(s&&!t)ans*=m-(lower_bound(b,b+m,i)-b);
		if(!s&&t)ans*=n-(lower_bound(a,a+n,i)-a);
		if(!s&&!t)ans*=(n-(lower_bound(a,a+n,i)-a))*(m-(lower_bound(b,b+m,i)-b))-(n*m-i);
		ans%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
#define MAX_H 50
#define MAX_W 50
typedef pair<int, int> P;
const int INF = 1e9;
char c[MAX_H][MAX_W + 1];
int d[MAX_W][MAX_W + 1];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int sx = 0, sy = 0;
int h, w; 

int bfs() {
    queue<P> que;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) d[i][j] = INF;
    }
    que.push(P(sx, sy));
    d[sx][sy] = 0;

    while (!que.empty()) {
        P p = que.front(); que.pop();
        for (int i = 0; i < 4; i++) {
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if (0 <= nx && 0 <= ny && nx < h && ny < w && c[nx][ny] == '.' && d[nx][ny] == INF) {
                que.push(P(nx, ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    return d[h - 1][w - 1];
}

int main() {
    cin >> h >> w;
    for (int i = 0; i < h; i++) cin >> c[i];
    int sum = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (c[i][j] == '.') sum++;
        }
    }
    int ans = sum - bfs() - 1; 
    if (bfs() == INF) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 256