akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;
int main()
{
	int a[1010];
	a[0]=2;
	int cnt=1;
	for(int i=3; i<=1000; i++)
	{
		int muri=0;
		rep(j, cnt) if(i%a[j]==0) muri=1;
		if(muri==0) a[cnt]=i, cnt++;
	}
	int k=0, n;
	cin >> n;
	int b[1010]={};
	while((a[k]<=n)&&(k<cnt))
	{
		int j=0, l=a[k];
		while(l<=n)
		{
			b[k]+=(n/l);
			l*=a[k];
		}
		k++;
	}
	ll ans=1;
	rep(i, k) ans=(ans*(1+b[i]))%MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=10000000007;

ll k(ll n){
  ll u=0;
  while(n>0){
    n/=10;
    u++;
  }
  return u;
}

int main(){
  string s;cin>>s;
  ll a[s.size()];
  rep(i,s.size()){
    if(s[i]=='1'){
      a[i]=1;
    }
    if(s[i]=='2'){
      a[i]=2;
    }
    if(s[i]=='3'){
      a[i]=3;
    }
    if(s[i]=='4'){
      a[i]=4;
    }
    if(s[i]=='5'){
      a[i]=5;
    }
    if(s[i]=='6'){
      a[i]=6;
    }
    if(s[i]=='7'){
      a[i]=7;
    }
    if(s[i]=='8'){
      a[i]=8;
    }
    if(s[i]=='9'){
      a[i]=9;
    }
  }
  ll dp[s.size()];
  int ans=0;
  map<int,int> mp;
  int now=1;
  int sum=0;
  rep(i,s.size()){
    int u=s.size()-1-i;
    sum+=a[u]*now;
    sum%=2019;
    now=now*10;
    now%=2019;
    mp[sum]++;
  }
  
  for(auto u:mp){
    if(u.fi==0) ans+=u.se;
    ans+=(u.se-1)*(u.se)/2;
  }
  
  cout<<ans<<endl;
    
}
    




Measured memory_bytes: 5232
from collections import deque
s=deque(list(input()))
Q=int(input())
count = 0
for i in range(Q):
    q=input()
    if q[0]=='1':
        count += 1
    elif (q[2]=='1' and count%2==0) or (q[2]=='2' and count%2==1):
        s.appendleft(q[4])
    elif (q[2]=='2' and count%2==0) or (q[2]=='1' and count%2==1):
        s.append(q[4])

if count%2==0:
    print(''.join(s))
else:
    print(''.join(reversed(s)))

Measured memory_bytes: 8676
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  
  int n,a,b,c,ans[101];
  vector<int> vec[101];
  queue<int> que;
  
  fill(ans,ans+101,105);
  ans[1] = 0;
  
  cin >> n;
  for(int i=0;i<n;i++){ 
    cin >> a >> b;
    for(int j=0;j<b;j++){
      cin >> c;
      vec[a].push_back(c);
    }
  }

  que.push(1);
  
  while(!que.empty()){
    
    int d = que.front();
    que.pop();
    
    for(int i=0;i<vec[d].size();i++){
      int e = vec[d][i];
      if(ans[e] > ans[d]+1){
	ans[e] = ans[d]+1;
	que.push(e);
      }
    }
    
  }
  for(int i=1;i<=n;i++){
    cout << i << ' ' ;
    if(ans[i]==105) cout << -1 << endl;
    else cout << ans[i] << endl;
  }
  return (0);
}

Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+5;
const ll INF = 2e18;

int n;
ll sum[maxn];
int main(){
    #ifdef Irene
    freopen("in.txt", "r", stdin);
    #endif // Irene
    //ios_base::sync_with_stdio(false);

    cin >> n;
    ll t;
    for(int i = 1;i <= n;i++){
        cin >> t;
        sum[i] = sum[i-1] + t;
    }
    ll ans = INF;
    for(int i = 1;i < n;i++){
        ans = min(ans, abs(sum[n] - sum[i] - sum[i]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
A, B, C, X, Y = map(int, input().split())
if A + B <= 2 * C:
    print(A * X + B * Y)
else:
    if X > Y:
        mi = Y
        print(mi * 2 * C + (X - mi) * min(A, 2*C))
    else:
        mi = X
        print(mi * 2 * C + (Y - mi) * min(B, 2*C))

Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const int INF = 1001001001;

int main(){

    int n, m;
    cin >> n >> m;

    vector<int> to[100005];

    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;

        a--; b--;

        to[a].push_back(b);
        to[b].push_back(a);

        // cout << a << " " << b << endl;
    }

    queue<int> q;

    vector<int> distance(n, INF);
    vector<int> pre(n, -1);

    // adding the first room
    distance[0] = 0;
    q.push(0);

    while(!q.empty()){

        int cur = q.front();
        q.pop();

        // cout << cur << endl;

        for(int i = 0; i < to[cur].size(); i++){
            // cout << i << endl;

            // if(distance[item] != INF)
            //     continue;
            
            // distance[item] = distance[cur] + 1;
            // // cout << item << "  " << distance[item] << endl;
            // pre[item] = cur;
            // q.push(item);

            int item = to[cur][i];
            // cout << "item == " << item + 1 << endl;

            if(distance[item] != INF){
                continue;
            }

            distance[item] = distance[cur] + 1;
            pre[item] = cur;
            q.push(item);

            // cout << "pushed == " << item + 1 << endl;
        }

        // cout << endl;
    }

    cout << "Yes" << endl;

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

        if(i == 0) continue;
        int res = pre[i];
        res++;

        cout << res << endl;

    }

    return 0;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main() {
  string s;

  while(cin >> s) {
    int ans = 0;

    REP(i, s.size()) {
      int tmp, tmp2;
      if(s[i] == 'I') tmp = 1;
      else if(s[i] == 'V') tmp = 5;
      else if(s[i] == 'X') tmp = 10;
      else if(s[i] == 'L') tmp = 50;
      else if(s[i] == 'C') tmp = 100;
      else if(s[i] == 'D') tmp = 500;
      else tmp = 1000;
      
      ans += tmp;
      if(i-1 >= 0) {
	if(s[i-1] == 'I') tmp2 = 1;
	else if(s[i-1] == 'V') tmp2 = 5;
	else if(s[i-1] == 'X') tmp2 = 10;
	else if(s[i-1] == 'L') tmp2 = 50;
	else if(s[i-1] == 'C') tmp2 = 100;
	else if(s[i-1] == 'D') tmp2 = 500;
	else tmp2 = 1000;
	if(tmp > tmp2) ans -= tmp2*2;
      }
    }
    cout << ans << endl; 
  }
}

Measured memory_bytes: 1180
import numpy as np
A = np.array(list(input()))
B = np.array(list(input()))
A_unique = np.unique(A)
B_unique = np.unique(B)
ans = 'Yes'
for i in range(A_unique.shape[0]):
    if len(np.unique(B[np.where(A == A_unique[i])])) != 1:
        ans = 'No'
        break
for i in range(B_unique.shape[0]):
    if len(np.unique(A[np.where(B == B_unique[i])])) != 1:
        ans = 'No'
        break
print(ans)



Measured memory_bytes: 18604
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        
        for(int i=0; i<N; i++){
            a[i] = sc.nextInt();
        }
        if(N%2!=0){
            for(int i=N-1; i>=0; i=i-2){
                System.out.print(a[i]+" ");
            }
            for(int i=1; i<=N-2; i=i+2){
                if(i!=N-2){
                    System.out.print(a[i]+" ");
                }else{
                    System.out.println(a[i]);
                }
            }
        }else{
            for(int i=N-1; i>=0; i=i-2){
                System.out.print(a[i]+" ");
            }
            for(int i=0; i<=N-2; i=i+2){
                if(i!=N-2){
                    System.out.print(a[i]+" ");
                }else{
                    System.out.println(a[i]);
                }
            }
        }
    }
}


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

struct Node {
    int key;
    Node* left;
    Node* right;
    Node* parent;
};

class Tree {
public:
    Node* nodes_;
    Node nil;
    Node* root_;
    int elements_;

    Tree(int n) {
        nodes_ = (Node *)malloc(n*sizeof(Node));
        nil = {-1, nullptr, nullptr, nullptr};
        root_ = &nil;
        elements_ = 0;
    }
    
    void insert(int k) {
        Node *y = nullptr;
        Node *x = root_;
        nodes_[elements_] = {k, nullptr, nullptr, nullptr};
        Node *z = &nodes_[elements_];

        while (x != nullptr and elements_ > 0) {
            y = x;
            if (z->key < x->key) {
                x = x->left;
            } else {
                x = x->right;
            }
        }
        z->parent = y;

        if (y == nullptr) {
            root_ = &nodes_[0];
        } else if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
        elements_++;
    }

    void inorder(Node* n) {
        if (n->left != nullptr) {
            inorder(n->left);
        }
        std::cout << " " << n->key;
        if (n->right != nullptr) {
            inorder(n->right);
        }
    }

    void preorder(Node* n) {
        std::cout << " " << n->key;
        if (n->left != nullptr) {
            preorder(n->left);
        }
        if (n->right != nullptr) {
            preorder(n->right);
        }
    }

    void print() {
        inorder(root_);
        std::cout << "\n";
        preorder(root_);
        std::cout << "\n";
    }
};


int main() {
    int n;
    std::cin >> n;
    Tree T(n);
    for (int i=0; i<n; i++) {
        std::string operation;
        int operand;
        std::cin >> operation;
        if (operation == std::string("insert")) {
            std::cin >> operand;
            T.insert(operand);
        } else {
            T.print();
        }
    }

    return 0;
}


Measured memory_bytes: 18748
// Problem : B - Substring
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*

WINNERS NEVER QUIT AND QUITTERS NEVER WIN!!

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<long,long> pl;
typedef pair<ll,ll> pll;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> umll;

#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define REV(i,a,b) for(long long i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define tc ll tests;cin>>tests;while(tests--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define coutv(v) for(auto it: (v))cout<<it<<" ";newl;
#define cout2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define cinv(v,n) vll (v)(n);FOR(i,0,(n)){cin>>v[i];}
#define cinvg(v,n) (v).resize(n);FOR(i,0,(n)){cin>>v[i];}
#define cin2d(v,n,m) vvll (v)(n,vll(m,0));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define cin2dg(v,n,m) (v).resize(n,vll(m));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define newl cout<<"\n"
#define mod 1000000007
#define INF LLONG_MAX/2

int main()
{
    io;
    string s,t;
    cin>>s>>t;
    
    ll ans=INF;
    
    FOR(i,0,s.size()-t.size()+1)
    {
    	ll temp=0;
    	FOR(j,0,t.size())
    	{
    		if(t[j]!=s[i+j])
    		{
    			temp++;
    		}
    	}
    	ans=min(ans,temp);
    }
    
    if(ans==INF){cout<<0;}
    else
    {
    	cout<<ans;
    }
    
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
typedef long long ll;
#define X first
#define Y second
typedef double dbl;
#define forn(i,n,k) for(int i=0;i<n;i=i+k)
#define forpn(p,n,k) for(int i=p;i<n;i+=k)

using namespace std;
long long gcd(int a,int b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
int main()
{
    int n,k;
  cin>>n>>k;
  vector<int> v(n);
  for(int i=0;i<k;i++)
  {
    int d;
    cin>>d;
    for(int i=0;i<d;i++)
    {
      int x;
      cin>>x;
      v[x-1]++;
    }
  }
  int count=0;
  for(int i=0;i<n;i++)
       if(v[i]==0)
         count++;
  cout<<count;
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a;cin>>a;
    int b;cin>>b;
    if(a*b%2==0){
        cout<<"Even"<<endl;
    }else{
        cout<<"Odd"<<endl;
    }
    
    return 0;
    
    
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
string mxr;
int main(int argc, char const *argv[])
{
	int ans=0;
	cin>>mxr;
	for(int i=0;i<mxr.size();i++)
	{
		if(mxr[i]=='1')
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;

#define all(a) (a).begin(),(a).end()

class UnionFind {
    private:
        vector<int> parent,rank;
    public:
        UnionFind(int size) {
            for (int i=0; i<size; i++) {
                parent.push_back(i);
                rank.push_back(0);
            }
        }

        int findset(int x) {
            return x==parent[x] ? x : parent[x]=findset(parent[x]);
        }

        void unite(int x,int y) {
            x=findset(x);y=findset(y);
            if (x==y) return;
            if (rank[x]>rank[y]) swap(x,y);
            parent[x]=y;
            if (rank[x]==rank[y]) rank[y]+=1;
        }

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

struct edge {ll u,v,cost;};
vector<edge> es;
int v,e;

bool comp(const edge& e1,const edge& e2){return e1.cost < e2.cost;}

ll kruskal(int v,int e,vector<edge> es) {
    sort(es.begin(),es.end(),comp);   
    UnionFind node(v);
    ll ret=0;
    for (int i=0; i<e; i++) {
        edge e=es[i];
        if (!node.same(e.u,e.v)) {
            ret+=e.cost;
            node.unite(e.u,e.v);
        }
    }
    return ret;
}

int main(){
    cin >> v >> e;
    for(int i=0; i<e; i++){
        int s,t,w;
        cin >> s >> t >> w;
        es.push_back(edge{s,t,w});
    }
    cout << kruskal(v,e,es) << endl;
}

Measured memory_bytes: 7816
#include <iostream>

using namespace std;

int N;
/*
int C[300];

void CALC(void) {
	for (int i = 2; i <= 200; i++) {
		
		if (C[i] == 0) {
			for (int j = 2; i*j <= 200; j++) {
				C[i*j] = 1;
			}
		}
	}
}

bool CHECK(int K) {
	if (K % 2 == 0) { return false; }

	int count = 0;

}
*/
/*int FUNC(int M) {
	cout << M << endl;
	if (M <= 1) { return 0; }
	for (int i = 2; i <= 200; i++) {
		if (C[i] == 0 && M%i==0) { return 1 + FUNC(M /i); }
	}
	return 0;
}*/

int COUNT(int M) {
	int count = 0;

	for (int i = 1; i <= M; i++) {
		if (M%i == 0) { count++; }
	}
	return count;
}

int main(void) {

	cin >> N;

	int ans = 0;

	//CALC();

	/*for (int i = 1; i <= 200; i++) {
		 cout <<i<<" " << COUNT(i) << endl; 
	}*/

	for (int i = 1; i <= N; i++) {
		if (i%2==1 && COUNT(i)==8) { ans++; }
	}

	cout << ans << endl;
	
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
def main(A):
    maxInt = max(A)
    secondInt = sorted(A)[-2]

    for a in A:
        if a == maxInt:
            print(secondInt)
        else:
            print(maxInt)

if __name__ == '__main__':
    N = int(input())
    A = [int(input()) for _ in range(N)]
    main(A)


Measured memory_bytes: 68540
function Main(input) {
  var s = input.split("\n")[0];
  var oddstr = "";
  for(var i = 0; i < s.length; i++) if((i + 1) % 2 === 1) oddstr += s[i];
  console.log(oddstr);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 10188
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<string> s(n);
    for (int i=0; i<n; i++) {
        cin >> s.at(i);
    }
    for (int i=0; i<n; i++) {
        sort(s.at(i).begin(), s.at(i).end());
    }
    sort(s.begin(), s.end());
    ll ans = 0;
    ll buf = 1;
    for (int i=1; i<n; i++) {
        if (s.at(i) != s.at(i-1)) {
            ans += buf*(buf-1)/2;
            buf = 1;
        }
        else {
            buf++;
        }
    }
    ans += buf*(buf-1)/2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7936
// Cut and Count

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;


int common_letter(string str1, string str2) {
    vector<int> v1(26, 0);
    vector<int> v2(26, 0);

    for (int i = 0; i < str1.size(); i++) {
        v1[str1[i] - 'a']++;
    }
    for (int i = 0; i < str2.size(); i++) {
        v2[str2[i] - 'a']++;
    }

    int res = 0;
    for (int i = 0; i < 26; i++) {
        if (v1[i] > 0 && v2[i] > 0) {
            res++;
        }
    }

    return res;
}


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

    int res = 0;
    for (int i = 1; i < n; i++) {
        int tmp = common_letter(s.substr(0, i), s.substr(i));
        if (tmp > res) {
            res = tmp;
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
// finish date: 2019/06/29

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;

////dijkstra(開始ノード、ノード数、edge[頂点名][距離、行先の頂点])
//dijkstra(開始ノード、ノード数、edge[頂点名][距離、行先の頂点])
vi dijkstra(int s, int V, vector<vector<pii>> edge) {
    vi dist(V, INF); //INFの値がこれでいいか確認するべき
    vb used(V, false);
    priority_queue<pii, vector<pii>, greater<pii>> pq;
    pq.push(pii(0, s));
    while (!pq.empty()) {
        int d, t;
        tie(d, t) = pq.top();
        pq.pop();
        if (used[t]) continue;
        used[t] = true;
        dist[t] = d;
        for (pii e:edge[t]) {
            if (dist[e.second] < d + e.first) continue;
            pq.push(pii(d + e.first, e.second));
        }
    }
    return dist;
}

int main() {
    int N, M;
    cin >> N >> M;
    vi u(M), v(M);
    vector<vector<pii>> edge(N * 3);
    rep(i, M) {
        cin >> u[i] >> v[i];
        u[i]--;
        v[i]--;
        edge[u[i]].emplace_back(pii(1,v[i] + N));
        edge[u[i] + N].emplace_back(pii(1,v[i] + N * 2));
        edge[u[i] + N * 2].emplace_back(pii(1,v[i]));
    }
    int S, T;
    cin >> S >> T;
    S--;
    T--;
    vi dist = dijkstra(S, N * 3, edge);
    if (dist[T] == INF) {
        cout << -1 << endl;
        return 0;
    } else {
        cout << dist[T]/3 << endl;
    }


    return 0;
}


Measured memory_bytes: 35072
#include<iostream>

using namespace std;
int a[30],b[30],c[30];
//bool vis[30];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)cin>>b[i];
	for(int i=1;i<=n-1;i++)cin>>c[i];
	int ans=b[a[1]];
	for(int i=2;i<=n;i++)
	{
		ans+=b[a[i]];
		if(a[i]==a[i-1]+1)ans+=c[a[i-1]]; 
	}
	cout<<ans<<endl;
	return 0;
}

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

#define int long long
#define double long double
#define pq priority_queue
#define pb push_back
#define mp make_pair

int root(int dsu[],int x)
{
  while(dsu[x]!=x)
  {
    dsu[x]=dsu[dsu[x]];
    x=dsu[x];
  }
  return x;
}

void init(int dsu[], int n)
{
  for(int i=0;i<=n;i++)
  {
    dsu[i]=i;
  }
}

void un(int dsu[],int x,int y)
{
  int a=root(dsu,x);
  int b=root(dsu,y);
  dsu[a]=dsu[b];
}

void printprecise(double l,int precision){
    std::cout << std::fixed;
    std::cout << std::setprecision(precision);
    std::cout << l <<endl;
}

int gcd(int x,int y)
{
  if(x==0)
  {
    return y;
  }
  else
  {
    return gcd(y%x,x);
  }
}

int lcm(int x,int y)
{
  return (x*y)/gcd(x,y);
}

main() 
{

  
  int n,k;
  cin>>n>>k;
  int arr[n];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  int cst[n];
  for(int i=1;i<n;i++)
  {
    cst[i]=100000000000000;
  }
  cst[0]=0;
  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<=i+k&&j<n;j++)
    {
      cst[j]=min(cst[j],cst[i]+abs(arr[i]-arr[j]));
    }
  }
  cout<<cst[n-1];
  

}

  // #ifndef ONLINE_JUDGE
  // cout << "\nTime Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  // #endif
// }
// #ifndef ONLINE_JUDGE
// cout << "\nTime Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
// #endif

Measured memory_bytes: 1792
#include<bits/stdc++.h>
		#include <bitset>
		using namespace std;
		#define ll long long 
		#define ld long double
		#define MOD 1000000007
		#define mod9 1000000009
		#define mod 1000003
		#define fast ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
		#define mp make_pair
		#define pb push_back
		#define ct ll t;cin>>t;while(t--)
		#define bi begin()
		#define ei end()
		#define fi first 
		#define se second   	
		bool isPrime(ll n) 
		{ 
			// Corner case 
			if (n <= 1) 
				return false; 
			
			// Check from 2 to n-1 
			for (ll i = 2; i*i <= n; i++) 
				if (n % i == 0) 
					return false; 
			
			return true; 
		}
		long long binpow(long long a, long long b) {
			long long res = 1;
			while (b > 0) {
				if (b & 1)
					res = (res%mod) * (a%mod);
				a = (a%mod) * (a%mod);
				b >>= 1;
			}
			return res%mod;
		}

		bool compare(const pair<ll,ll>&a,const pair<ll,ll>&b)
		{
			return (a.se<b.se);
		}
		ll lcm(ll a,ll b)
		{
			return(a*b)/__gcd(a,b);
		}
		// vector<ll>s;
		void SieveOfEratosthenes() 
		{  
			ll n=10005;
			bool prime[1000005]; 
			memset(prime, true, sizeof(prime)); 
			// s[0]=1;
			// s[1]=1;
			for (int p=2; p*p<=n; p++) 
			{ 
				
				if (prime[p] == true) 
				{   
					for (int i=p*p; i<=n; i += p) {
						prime[i] = false; 
						// s[i]=1;
						}
				} 
			} 
			for(ll i=2;i<10005;i++)
			{
				if(prime[i])
				{
					// s.pb(i);
				}
			}
		} 
		void eea(ll a, ll b, ll & x, ll & y) {
		if (a == 0) {
			x = 0;
			y = 1;
			return ;
		}
		ll x1, y1;
		eea(b % a, a, x1, y1);
		x = y1 - (b / a) * x1;
		y = x1;
		return ;
	}
	ll modinverse(ll a,ll m)
	{
		ll x, y;
		eea(a, m, x, y);
		if (__gcd(a,m) != 1) {
		return -1;
		}
	else {
		x = (x % m + m) % m;
		cout << x << endl;
		return x;
	}
	}
		ll fact[1000007]={0};
		ll expo(ll x, ll y) {ll res=1;x=x%MOD;while(y>0){if(y&1)res=(1ll*res*x)%MOD;
		y=y>>1;x=(1ll*x*x)%MOD;} return res;}
		void facto() {fact[0]=1;fact[1]=1;for(ll i=2;i<100007;i++)fact[i]=(fact[i-1]*i)%MOD;}
		ll npr(ll n,ll r) {facto(); ll res=1; res=fact[n]; res=(res*(expo(fact[n-r],MOD-2)))%MOD; return res; }
		ll ncr(ll n,ll r){ ll res=1; if(r>n-r)r=n-r; for(ll i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res;}
			ll C(ll n, ll k) {
    ll res = 1;
    for (ll i = 1; i <= k; ++i)
        res = ((res) * (n - k + i) / i)%MOD;
    return (ll)(res + 0.01)%MOD;
}
				
		int main()
		{
			fast
			ll k,sum=0;
			cin>>k;
			for(ll i=1;i<=k;i++)
			{
				for(ll j=1;j<=k;j++)
				{
					for(ll m=1;m<=k;m++)
					{
						sum+=__gcd(i,__gcd(j,m));
					}
				}
			}
			cout<<sum<<"\n";
			}

 

Measured memory_bytes: 3648
sx,sy,tx,ty = map(int, raw_input().split())
x = tx - sx
y = ty - sy
route = ''
for _ in range(y):
    route += 'U'
for _ in range(x):
    route += 'R'
for _ in range(y):
    route += 'D'
for _ in range(x):
    route += 'L'
route += 'L'
for _ in range(y+1):
    route += 'U'
for _ in range(x+1):
    route += 'R'
route += 'D'
route += 'R'
for _ in range(y+1):
    route += 'D'
for _ in range(x+1):
    route += 'L'
route += 'U'
print route


Measured memory_bytes: 2692
def main():
    dish = [int(input()) for i in range(5)]
    dish_10 = [ [dish[i]%10, dish[i]] for i in range(5)]
    for i in range(len(dish_10)):
    	if (dish_10[i][0]==0):
    		dish_10[i][0] = 10
    dish_10.sort()
    ans = 0
    for i in range(1,5):
        ans += ceiling_10(dish_10[i][1])
    ans += dish_10[0][1]
    print(ans)
 
def ceiling_10(i):
    if (i%10 == 0):
        return i
    else:
        return (i//10+1)*10
main()

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

int main(){
    char a,b; cin >> a >> b;
    string A,B;
    for(int i=0;i<(int)b-'0';i++){
        A += a;
    }
    for(int i=0;i<(int)a-'0';i++){
        B += b;
    }
    if(A<B){
        cout << A << endl;
    }else{
        cout << B << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main(){
  string s;
  int K, n;
  cin >> s >> K;
  n = s.length();
  set<string> st;
  for(int i=1; i<=5; i++){
    for(int j=0; j<=n-i; j++){
      string str = "";
      rep(k, i) str += s[j+k];
      st.insert(str);
    }
  }
  auto itr = st.begin();
  rep(i, K-1) ++itr;
  cout << *itr << endl;
  return 0;
}
      
      

Measured memory_bytes: 4716
#pragma GCC optimize("Ofast")

// #define _GLIBCXX_DEBUG

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

#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
// #define NP next_permutation;
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
// typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
// using vvvi=vector<vvi>;
/*
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
*/
template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
// template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
/*
void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){ll c; while(b!=0){c=a%b; a=b; b=c;} return a;}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a * c%mod;} a=a * a%mod; b>>=1;} return c;}
vi calc(ll x){vi res; while(x>0){res.pb(x%10); x/=10;} reverse(all(res)); return res;}
*/
void solve() {
  ll n; cin>>n;
  ll p=sqrt(n),q;
  REP(i,1,p+2){
    if(n%i==0) q=i+n/i-2;
  }
  out(q);
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

void add(long long &x, long long y){
    x = (x + y) % MOD;
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N)
        cin >> A[i];
    map<tuple<int, int, int>, long long> mp;
    mp[make_tuple(-1, -1, -1)] = 1;
    REP(i, N){
        map<tuple<int, int, int>, long long> mp2;
        for(auto xyz : mp){
            int x, y, z;
            tie(x, y, z) = xyz.first;
            long long cnt = xyz.second;
            if(x == A[i]-1){
                vector<int> v = {A[i], y, z};
                sort(v.begin(), v.end());
                add(mp2[make_tuple(v[0], v[1], v[2])], cnt);
            }
            if(y == A[i]-1){
                vector<int> v = {x, A[i], z};
                sort(v.begin(), v.end());
                add(mp2[make_tuple(v[0], v[1], v[2])], cnt);
            }
            if(z == A[i]-1){
                vector<int> v = {x, y, A[i]};
                sort(v.begin(), v.end());
                add(mp2[make_tuple(v[0], v[1], v[2])], cnt);
            }
        }
        mp = mp2;
    }
    long long ans = 0;
    for(auto x : mp)
        add(ans, x.second);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
package main

import (
	"fmt"
	"math"
)

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

func main() {
	var n, x, r, t, i int
	fmt.Scan(&n, &x)

	for ; i < n; i++ {
		fmt.Scan(&t)
		t = int(math.Abs(float64(t - x)))
		if i == 0 {
			r = t
			continue
		}
		if g := gcd(t, r); r > g {
			r = g
		}
	}

	fmt.Println(r)
}

Measured memory_bytes: 5504
#include <stdio.h>

int main(void){
	int n,m;
	int i;
	int a[100005]={0};
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	int sp = 0;
	int next = 0;
	for(i=0;i<n;i++){
		if(a[i] == i+1 && a[i+1] == i+2){
			sp+=2;
			next++;
			i++;
		}else if(a[i] == i+1){
			sp++;
		}else{
		}
	}
	printf("%d",sp-next);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <string>
#include <vector>
/* 変数i を n回繰り返すマクロ */
#define rep(i,n) for (int i = 0;i < (n);i++)
typedef long long ll;
using namespace std;
int main()
{
    cout << fixed << setprecision(10);//小数点以下10桁出力
    string s;
    cin >> s;
    if(s.at(2) == s.at(3) && s.at(4) == s.at(5)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll H, W;
	cin >> H >> W;

	REP(i, W+2) cout << "#";
	cout << endl;

	REP(i, H){
		cout << "#";
		string S;
		cin >> S;
		REP(j, W) cout << S[j];
		cout << "#";
		cout << endl;
	}

	REP(i, W+2) cout << "#";
	cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(n);++i)

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

  if (N % 2) {
    cout << 0 << "\n";
    return 0;
  }

  ll ans = 0;
  N /= 2;
  rep(i, 100) {
    if (N <= 0)
      break;
    N /= 5;
    ans += N;
  }
  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

	/** 
	 * Javaで同じ内容のコードを書いてTLEになるか検証する。
	 * @param args
	 */
	public static void main(String[] args) {
		class Drug {
			final int excess;
			final int cost;
			Drug(int a, int b, int c, int ma, int mb) {
				this.excess = a * mb - b * ma;
				this.cost = c;
			}
		}
		
		final int n, ma, mb;
		final List<Drug> drugs = new ArrayList<>();
		try (Scanner scan = new Scanner(System.in)) {
			n = scan.nextInt();
			ma = scan.nextInt();
			mb = scan.nextInt();
			for (int i = 0; i < n; i++) {
				drugs.add(new Drug(scan.nextInt(), scan.nextInt(), scan.nextInt(), ma, mb));
			}
		}
		
		int minimumCost = 4001;
		List<Set<Integer>> memo;		
		List<Set<Integer>> nextMemo = IntStream.range(0, minimumCost)
				.mapToObj(i -> new HashSet<Integer>())
				.collect(Collectors.toList());
		
		Set<Integer> zero = new HashSet<Integer>();
		zero.add(0);
		nextMemo.set(0, zero);
		
		for (int i = 0; i < n; i++) {
			memo = nextMemo;
			nextMemo = new ArrayList<>();
			nextMemo.add(memo.get(0));
			for (int cost = 1; cost < memo.size(); cost++) {
				Set<Integer> next;
				if (cost - drugs.get(i).cost < 0) {
					next = memo.get(cost);
				} else {
					final int j = i;
					next = memo.get(cost - drugs.get(i).cost).stream()
							.map(it -> it + drugs.get(j).excess)
							.collect(Collectors.toSet());
					next.addAll(memo.get(cost));
				}
				
				nextMemo.add(next);
				if (nextMemo.get(cost).contains(Integer.valueOf(0))) {
					minimumCost = cost;
					break;
				}
			}
		}
		
		System.out.println(minimumCost == 4001 ? -1 : minimumCost);
	}
	
}


Measured memory_bytes: 194600
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
#define INF	100000000
#define pb	push_back
#define fi first
#define sec second
#define SS stringstream
using namespace std;
typedef pair<int, int> P;
typedef long long int	ll;

int a = 50000;
bool sosuu[50001] = {false};
int x;
int n;

int main(){
	x = floor(sqrt(a));
	for(long long int i = 2; i < x+1; i++){
		if(sosuu[i] == true){
			continue;
		}
		for(long long int j = 2*i; j < a+1; j = j+i){
			sosuu[j] = true;
		}
	}
	while(cin >> n){
		int ans = 0;
		if(n == 0) break;
		if(n % 2 != 0){
			if(sosuu[n-2] == false) cout << "1" << endl;
			else cout << "0" << endl;
			continue;
		}
		for(int i = 2; i < n; i++){
			if(i > n-i) break;
			if(sosuu[i] == false && sosuu[n-i] == false) ans++;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[110],b[110],n,ans;
	cin>>n;
	for(int i=1;i<=n-1;i++)
		cin>>b[i];
	for(int j=2;j<=n-1;j++)
	{
		a[j]=min(b[j],b[j-1]);
		ans+=a[j];
	}
	cout<<ans+b[1]+b[n-1];
	return 0;
}

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

using namespace std;

int main()
{
    int n; cin >> n ;
   int dp [n],arr[n];
   for (int i=0;i<n ;i++){
    cin >> arr[i];
   }
   dp[0]=0;
   dp[1]= abs(arr[1]-arr[0]);
   for (int i=2; i<n;i++){
    dp[i]=min (abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
   }
   cout << dp[n-1];


}


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

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

  vector<int> s(N);
  rep(i, N) cin >> s[i];

  sort(s.begin(), s.end());

  int ans = 0;
  rep(i, N) ans += s[i];

  if (ans % 10 == 0) {
    rep(i, N) {
      if (s[i] % 10 != 0) {
        ans -= s[i];
        break;
      }
    }
  }

  if (ans % 10 == 0)
    ans = 0;

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using vi = vector<int>;
using i64 = int64_t;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

i64 cnt = 0;

template <typename T>
void print(vector<T> v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

void merge(vi &A, int left, int mid, int right) {
  auto n1 = mid - left;
  auto n2 = right - mid;
  vi L(n1 + 1), R(n2 + 1);
  copy(A.begin() + left, A.begin() + mid, L.begin());
  copy(A.begin() + mid, A.begin() + right, R.begin());
  L[n1] = INF;
  R[n2] = INF;
  int i = 0, j = 0;
  FOR(k, left, right) {
    if (L[i] <= R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
      cnt += n1 - i;
    }
  }
}

void merge_sort(vi &A, int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    merge_sort(A, left, mid);
    merge_sort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main() {
  int n;
  cin >> n;
  vi S(n);
  REP(i, n) cin >> S[i];
  merge_sort(S, 0, n);
  cout << cnt << endl;
}


Measured memory_bytes: 4388
#include <iostream>

int convert(char c){
    switch(c){
        case 'S': return 0;
        case 'H': return 1;
        case 'C': return 2;
        case 'D': return 3;
        default:  return -1;
    }
}

char convertInv(int k){
    switch(k){
        case 0: return 'S';
        case 1: return 'H';
        case 2: return 'C';
        case 3: return 'D';
        default: return '\n';
    }
}

int main(void){
    bool A[4][13];
    for(int i = 0; i < 4; i++) for(int j = 0; j < 13; j++) A[i][j] = true;
    int n; scanf("%d", &n);
    while(n--){
        char c; int p; scanf("\n%c %d", &c, &p);
        A[convert(c)][p-1] = false;
    }
    for(int i = 0; i < 4; i++) for(int j = 0; j < 13; j++) if(A[i][j]){
        printf("%c %d\n", convertInv(i), j+1);
    }
    return 0;
}


Measured memory_bytes: 3196
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    ll tmp = N;
    ll sum = 0;
    while(tmp > 0) {
        sum += tmp % 10;
        tmp /= 10;
    }
    if (N % sum == 0) yes;
    else no;
    return 0;
}


Measured memory_bytes: 256
N,X = list(map(int,input().split()))
x = list(map(int,input().split()))

number = []

for i in range(N):
    number.append(abs(x[i]-X))

import fractions 

ans = number[0]
for i in range(1, N):
    ans = fractions.gcd(ans, number[i])
    
print(ans)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,ll>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void print() { cout << "\n"; }
template <class T, class... Args>
void print(const T &x, const Args &... args) { cout << x << " "; print(args...);}
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

template <typename T>
bool bellman_ford(int n, int s, vector<T> &dist, const vector<vector<pair<int,T> > > &G) {
  const T INF = numeric_limits<T>::max();
  dist.resize(n, INF);
  dist[s] = 0;
  rep(cnt,n) {
    rep(v,n) {
      for (auto e : G[v]) {
        int to = e.first;
        T cost = e.second;
        if (dist[v] != INF && dist[to] > dist[v]+cost) {
          dist[to] = dist[v] + cost;
          if (cnt == n-1) return false; //NEGATIVE CYCLE
        }
      }
    }
  }
  return true;
}

void dfs(int i, vector<bool> &vis, const vector<vector<int> > &G) {
  vis[i] = true;
  for (auto to : G[i]) {
    if (!vis[to]) dfs(to, vis, G);
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n, m;
  ll p;
  cin >> n >> m >> p;
  vector<vector<int> > G(n), rG(n);
  vector<int> a(m), b(m);
  vector<ll> c(m);
  rep(i,m) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--;
    G[a[i]].emplace_back(b[i]);
    rG[b[i]].emplace_back(a[i]);
  }
  vector<bool> visit(n,false), rvisit(n,false); //到達できるか確かめる
  visit[0] = true;
  rvisit[n-1] = true;
  dfs(0,visit, G);
  dfs(n-1,rvisit, rG);

  vector<vector<P> > pG(n);
  rep(i,m) {
    if (visit[a[i]] && rvisit[a[i]] && visit[b[i]] && rvisit[b[i]]) {
      pG[a[i]].emplace_back(P(b[i], -c[i]+p)); //-(コスト-P)が最小になる経路を求める
    }
  }
  vector<ll> dist;
  bool nonneg = bellman_ford(n, 0, dist, pG);
  if (!nonneg) {
    cout << -1 << endl;
    return 0;
  }
  ll ans = max(0LL, -dist[n-1]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N, KK;
  cin >> N >> KK;
  vector<ll> v;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
  }

  ll ret = 0;

  rep(K,KK+1){
    rep(i,K+1){
      if(K-i>N) continue;
      if(K-i<i) continue;
      int j = K-i;
      rep(jj,j+1){
        vector<int> take(N, 0);
        rep(kk,jj) if(kk<N) take[kk] = 1;
        rep(kk,j-jj) if(N-1-kk>=0) take[N-1-kk] = 1;
        vector<ll> w;
        rep(jj,N) if(take[jj] == 1) w.push_back(v[jj]);
        
        sort(ALLOF(w));
        rep(jj,i) if(jj<w.size()) w[jj] = 0;
        ll sum = 0;
        rep(jj,w.size()) sum += w[jj];
        ret = max(ret, sum);
      }   
    }
  }
  
  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

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

	string K; cin >> K;
	int n = K.size();
	int D; cin >> D;

	vector<vector<vector<ll>>> dp(2, vector<vector<ll>>(D, vector<ll>(2, 0)));
	dp[0][0][1] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < D; j++) {
			for (int b = 0; b < 2; b++) {
				for (int k = 0; k < 10; k++) {
					int ni = (i + 1)%2, nj = (j + k) % D, nb = 0;
					int curNum = K[i] - '0';

					if (b) {
						if (k > curNum) { break; }
						else if (k == curNum) { nb = 1; }
					}
					dp[ni][nj][nb] += dp[(i%2)][j][b]; dp[ni][nj][nb] %= mod;
				}
				dp[i%2][j][b] = 0;
			}
		}
	}

	ll ans = dp[(n%2)][0][0] + dp[(n%2)][0][1]; ans %= mod;
	ans--; ans %= mod;
	if (ans < 0) { ans += mod; }
	cout << ans << '\n';
}

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

int main() {
  ll n, k;
  cin >> n >> k;

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

  set<ll> s;
  vector<ll> order;
  ll now = 0;
  while (s.count(now) == 0) {
    s.insert(now);
    order.push_back(now);
    now = a[now];
  }

  ll loop_start = 0;
  while (order[loop_start] != now) loop_start++;
  ll loop_size = order.size() - loop_start;

  if (k < order.size()) {
    cout << order[k] + 1 << endl;
  } else {
    cout << order[loop_start + (k - loop_start) % loop_size] + 1 << endl;
  }
}


Measured memory_bytes: 15324
total = 0
ticket = 1
def f(p, cost, route):
    for k, c in data.items():
        a, b = k
        if a == p:
            if not b in route:
                value1, value2 = dis(p, c, cost)
                if not b in cost or value1 < cost[b][total]:
                    cost[b] = [value1, value2]
        elif b == p:
            if not a in route:
                value1, value2 = dis(p, c, cost)
                if not a in cost or value1 < cost[a][total]:
                    cost[a] = [value1, value2]
    else:
        del cost[p]
    b, c = sorted(cost.items(), key=lambda x: x[1])[0]
    if b == g:
        print cost[g][total]
    else:
        route.append(b)
        f(b, cost, route)
        
def dis(p, c, cost):
    lis = cost[p][ticket][:]
    if len(cost[p][ticket]) != t:
        value1 = cost[p][total]+c/2
        lis.append(c)
        value2 = lis
    else:
        mini = sorted(cost[p][ticket])[0]
        if mini < c:
            value1 = cost[p][total]+(mini/2)+(c/2)
            lis.remove(mini)
            lis.append(c)
            value2 = lis
        else:
            value1 = cost[p][total]+c
            value2 = lis
    return value1, value2
        
while True:
    t, n, m, s, g = map(int, raw_input().split())
    if t == n == m == s == g == 0: break
    data = {}
    for i in range(m):
        a, b, c = map(int, raw_input().split())
        data[(a, b)] = c
    else:
        f(s, cost={s:[0, []]}, route=[s])

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

using namespace std;

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

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

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

#define INF 2e9

int N;

int i,j,len;

char S[200000];

map<string,int> M;

int ans = 0;

void vvv(int it, string pre, string v){
    if(pre != v){
        ans++;
        if(it + 1 < len){
            vvv(it+1, v, {S[it+1]});
        }
    }else{
        if(it + 1 < len){
            vvv(it+1, pre, v + S[it+1]);
        }else{

        }
    }
}


int main(){

    scanf("%s",S);

    string SS(S);

    len = (int)(SS.length());


    vvv(0, "", {S[0]});

    printf("%d",ans);
    

    return 0;
}

Measured memory_bytes: 28800
H,W=map(int,input().split())
C=[list(input()) for _ in range(H)]
newc=[[None]*W for _ in range(2*H)]
for i in range(2*H):
    for j in range(W):
        newc[i][j]=C[i//2][j]
for i in range(2*H):
    for j in range(W):
        print(newc[i][j],end="")
    print("\n")


Measured memory_bytes: 4736
s = input()
s = s[:-1]
while True:
    if len(s) % 2 == 0:
        b = True
        for i in range(len(s) // 2):
            if s[i] != s[i + len(s) // 2]:
                b = False
        if b:
            print(len(s))
            exit()
    s = s[:-1]


Measured memory_bytes: 2940