akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <cmath>
#include <cstdarg>
#include <cstdlib>
#include <string>

#include <vector>
#include <tuple>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int> >;

int main(int argc, char const *argv[])
{
    int n, m;
    cin >> n >> m;

    Graph g(n);
    int a, b;
    for (int i = 0; i < m; i ++) {
        cin >> a >> b;
        g[--a].push_back(--b);
        g[b].push_back(a);
    }
    int ans[n] = {0};
    for (int i = 1; i < n; i ++) {
        ans[i] = -1;
    }
    
    queue<int> que;
    que.push(0);
    int now;
    while (!que.empty()) {
        now = que.front();
        que.pop();
        for (auto x: g[now]) {
            if (ans[x] == -1) {
                ans[x] = now;
                que.push(x);
            }
        }
    }
    int f = 1;
    for (int i = 0; i < n; i ++) {
        if (ans[i] == -1) {
            f = 0;
            break;
        }
    }
    if (f) {
        cout << "Yes" << endl;
        for (int i = 1; i < n; i ++) {
            cout << ans[i] + 1 << endl;
        }
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 10136
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

const int MAXN = 1e5 + 1;
vi adj[MAXN];
bool visited[MAXN];

void dfs(int u) {
	visited[u] = true;
	for (int v : adj[u]) if (!visited[v])
		dfs(v);
}

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

	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++) {
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		adj[x].push_back(y);
		adj[y].push_back(x);
	}

	int comp = 0;
	for (int u = 1; u <= n; u++) if (!visited[u]) {
		++comp;
		dfs(u);
	}
	printf("%d\n", comp);
}


Measured memory_bytes: 8960
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define infll 1000000000000000000ll
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define mpr make_pair
#define fi first
#define se second
#define pq priority_queue<int>
#define pqll priority_queue<ll>
#define up(x,y) (x<(y)?x=(y):0)
#define dn(x,y) (x>(y)?x=(y):0)
#define ad(x,y) (x=(x+(y))%mod)
using namespace std;

int read(){
	int x=0; char ch=getchar(); bool flag=0;
	while (ch<'0' || ch>'9'){ if (ch=='-') flag=1; ch=getchar(); }
	while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
	return flag?-x:x;
}
ll readll(){
	ll x=0; char ch=getchar(); bool flag=0;
	while (ch<'0' || ch>'9'){ if (ch=='-') flag=1; ch=getchar(); }
	while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
	return flag?-x:x;
}
int num[9];
int main(){
	int a,b,c,d,e,f;
	scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
	num[a]++; num[b]++; num[c]++; num[d]++; num[e]++; num[f]++;
	puts(((num[1]&num[2]&num[3]&num[4])&1)?"NO":"YES");
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
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; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int kurai(int a,int b){
  int m=pow(10,b),n=pow(10,b-1);
  return (a%m)/n;
}
int ketawa(int a){
  int k=0;
  rep(i,keta(a)){
  k+=kurai(a,i+1);
  }
  return k;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int mid(int a,int b,int c){
  vector<int> k(3);
  k[0]=a;k[1]=b;k[2]=c;
  sort(all(k));
  return k[1];
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
 if(!b)return 1; if(b&1)return modpow(a,b-1,m)*a%m;
 int memo = modpow(a,b>>1,m);
 return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a;
  cin>>a;
  int b=a%1000;
  if(b==0)
    out(0);
  else
    out(1000-b);
}

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

int n;
string s;

int ans;

int main(void){
  // Here your code !
  scanf("%d", &n);
  cin >> s;

  ans = -1;

  for (int i = 1; i < n; ++i) {
    map<char, int> mp;

    for (int j = 0; j < i; ++j) {
      auto it = mp.find(s[j]);
      if (it == mp.end()) mp[s[j]] = 1;
    }

    for (int j = i; j < n; ++j) {
      auto it = mp.find(s[j]);
      if (it != mp.end() && it->second == 1) mp[s[j]] = 2;
    }

    int tmp = 0;
    for (auto e: mp) {
      if (e.second == 2) tmp += 1;
    }

    ans = max(ans, tmp);
  }

  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

void solve(long long N, std::vector<long long> A) {
  sort(all(A));

  rep(n, N - 1) { A[n + 1] += A[n]; }

  int k;
  for (k = N - 1; k >= 1; k--) {
    if (A[k] - A[k - 1] > A[k - 1] * 2) {
      break;
    }
  }

  print(N - k);
}

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


Measured memory_bytes: 1024
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
		 static List<ArrayList<Integer>>  list = new ArrayList<ArrayList<Integer>>();
	    public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        int N = sc.nextInt();	
	        int M = sc.nextInt();	
	        int Q = sc.nextInt();	
	        long[] a = new long[Q];
	        long[] b = new long[Q];
	        long[] c = new long[Q];
	        long[] d = new long[Q];
	        for (int i=0 ; i<Q; i++) {
	            a[i] = Long.parseLong(sc.next());
	            b[i] = Long.parseLong(sc.next());
	            c[i] = Long.parseLong(sc.next());
	            d[i] = Long.parseLong(sc.next());
	        }	        
	        long ans=0;
	        LinkedList<Integer[]> q= new LinkedList<Integer[]>();
	        Integer[] t = new Integer[N];
	        for(int i=0;i<N;i++)t[i]=1;
	        		
	        q.add(t);
	        while(!q.isEmpty()){
	        	Integer[] node = q.poll();
	        	long cnt=0;
	        	for(int i=0;i<Q;i++) {
        			if(node[(int)b[i]-1]-node[(int)a[i]-1]==c[i]) {
        				cnt=cnt+d[i];
        			}
	        	}
	        	ans=Math.max(ans, cnt);
	        	if(node[N-1]==M) {
	        		for(int i=N-1;i>=0;i--) {
	        			if(node[i]!=M) {
	        				node[i]++;
	        				int tmp=node[i];
	        				for(int j=i+1;j<N;j++) {
	        					node[j]=tmp;
	        				}
	        				q.add(node);
	        				break;
	        			}
	        		}
	        	} else {
	        		node[N-1]++;
	        		q.add(node);
	        	}
	        }
	        
	    	System.out.println(ans);
	    	
	        		
	    }
	    

	}

Measured memory_bytes: 40156
#include<bits/stdc++.h>
using namespace std;
void Sort(long long int wt[],long long int val[],long long int n)
{
	for(long long int i=0;i<n;i++)
	{
		for (long long int j=i;j<n;j++)
		{
			if(wt[i]>wt[j])
			{
				long long int t1,t2;
				t1=wt[i];
				wt[i]=wt[j];
				wt[j]=t1;
				t2=val[i];
				val[i]=val[j];
				val[j]=t2;
			}
		}
	}
}
int main()
{
	long long int n;
	cin>>n;
	long long int tot;
	cin>>tot;
	long long int val[n],wt[n];
	for (long long int i=0;i<n;i++)
	{
		cin>>wt[i]>>val[i];
	}
	Sort(wt,val,n);
	long long int T[n][tot+1];
	for (long long int i=0;i<n;i++)
	{
		T[i][0]=0;
	}
	for(long long int i=1;i<=tot;i++)
	{
		if(i<wt[0])
		{
			T[0][i]=0;
		}
		else
			T[0][i]=val[0];	
	}
	for (long long int i=1;i<n;i++)
	{
		for (long long int j=1;j<=tot;j++)
		{
			if(j<wt[i])
			{
				T[i][j]=T[i-1][j];
			}
			else
			{
				T[i][j]=max(val[i]+T[i-1][j-wt[i]],T[i-1][j]);
			}
		}
	}
	cout<<T[n-1][tot]<<"\n";
}

Measured memory_bytes: 78336
#include <stdio.h>

int main()
{   int n;
    scanf("%d",&n);
    int c[n],s[n],f[n];
    for(int i=0;i<n-1;i++){
        scanf("%d%d%d",&c[i],&s[i],&f[i]);
    }
    for(int i=0;i<n-1;i++){
        int T=s[i]+c[i];
        for(int j=i+1;j<n-1;j++){
            if(T<s[j]){
                T=s[j];
            }
            int k=0;
            //printf("T=%d @i=%d",T,i);
            //printf("s[%d]+k*f[%d]=%d",j,j,s[j]+k*f[j]);
            while(T>s[j]+k*f[j]){
                //printf("k incre");
                k++;
                
            }
            //printf("path %d to %d  k=%d\n",i,j,k);
            T+=(s[j]+k*f[j]-T+c[j]);
        }
        printf("%d\n",T);
    }
    printf("0");
    return 0;
}


Measured memory_bytes: 128
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 2000 + 20 , inf = 1e9 + 20 ;
int n , mn[N] , mx[N] , cnt[N] , ans = inf ;
string s ;
vector <int> g[N] ;

void dfs (int v , int par = -1) {
	int b = -1 ;

	for (int u : g[v]) {
		if (u == par) continue ;

		dfs(u , v) ;

		mn[u] += cnt[u] ;
		mx[u] += cnt[u] ;

		mx[v] += mx[u] ;
		cnt[v] += cnt[u] ;
	
		if (b == -1 || mx[u] > mx[b]) b = u ;
	}

	if (b == -1) return ;

	if (2 * mn[b] >= mx[v] - (mx[b] - mn[b])) mn[v] = mn[b] - (mx[v] - mx[b]) ;
	else mn[v] = (mx[v] & 1) ;
}

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

	cin >> n ;
	cin >> s ;

	for (int i = 0 , u , v ; i < n - 1 ; i ++) {
		cin >> u >> v ;
		u -- , v -- ;

		g[u].pb(v) ;
		g[v].pb(u) ;
	}

	for (int root = 0 ; root < n ; root ++) {
		for (int i = 0 ; i < n ; i ++) cnt[i] = s[i] - '0' , mn[i] = mx[i] = 0 ;

		dfs(root) ;

		if (mn[root] == 0) ans = min(ans , mx[root] / 2) ;
	}

	if (ans == inf) ans = -1 ;

	cout << ans << '\n' ;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
 
typedef vector<int> Vec;
typedef pair<Vec,int> P;
 
bool check(Vec &v){
    for(int i = 0 ; i < 32 ; i++){
	if((i+1) % 8 == 0) continue;
	if((i/8+1)*10+i%8+1 != v[i]) return false;
    }
    return true;
}
 
int bfs(Vec &start,Vec &space){
    queue<P> Q;
    queue<Vec> S;
    Q.push(P(start,0));
    S.push(space);
    set<Vec> visited;
    visited.insert(start);
 
    while(!Q.empty()){
	P p = Q.front(); Q.pop();
	Vec s = S.front(); S.pop();
	if(check(p.first)) return p.second;
     
	for(int i = 0 ; i < 4 ; i++){
	    if(p.first[s[i]-1] % 10 == 7) continue;
	    for(int j = 0 ; j < 32 ; j++){
		if(p.first[s[i]-1]+1 == p.first[j]){
		    swap(p.first[s[i]],p.first[j]);
		    int tmp = s[i]; s[i] = j;
		    if(!visited.count(p.first)){
			visited.insert(p.first);
			Q.push(P(p.first,p.second+1));
			S.push(s);
		    }
		    s[i] = tmp;
		    swap(p.first[s[i]],p.first[j]);
		}
	    }
	}
    }
    return -1;
}
 
int main(){
    int Tc;
    cin >> Tc;
    while(Tc--){
	Vec v(32),space;
	for(int i = 0 ; i < 32 ; i++){
	    if(i % 8 != 0){
		cin >> v[i];
		if(v[i]%10 == 1){
		    v[i] = 0;
		    space.push_back(i);
		}
	    }else{
		v[i] = (i/8+1)*10+1;
	    }
	}
	cout << bfs(v,space) << endl;
    }
    return 0;
}

Measured memory_bytes: 16812
#include <bits/stdc++.h>
using namespace std;
#define FIO ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
vector<int>adj[100];
int visited[100];
void bfs(int s,int n)
{
    for(int i=0; i<n; i++)
    {
        visited[i]=0;
        queue<int>Q;
        Q.push(s);
        visited[s]=1;
        while(!Q.empty())
        {
            int u=Q.front();
            Q.pop();
            for(int i=0; i<adj[u].size(); i++)
            {
                if(visited[adj[u][i]]==0)
                {
                    int v=adj[u][i];
                    visited[v]=1;
                    Q.push(v);
                }
            }
        }
    }
}
int gcd(int a,int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    return (a*b)/gcd(a,b);
}

int main()
{
    FIO
   char ch;
   cin>>ch;
   cout<<char(ch+1)<<endl;
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
public class Main {
	public static void main(String[] args)throws Exception{
		Scanner stdIn=new Scanner(System.in);
		int N=stdIn.nextInt();
		HashMap<String,Integer> map=new HashMap<String,Integer>();
		String s[]=new String[N];
		String ans[]=new String[N];
		int max=0,k=0,l=0;
		for(int i=0;i<N;i++){
			String S=stdIn.next();
			int a=0;
			if(map.containsKey(S)){
				a=map.get(S);a++;
				map.put(S,a);
				if(a>max)
					max=a;
			}
			else{
				map.put(S,1);
				if(1>max)
					max=1;
				s[k]=S;k++;
			}
		}
		for(int i=0;i<N;i++){
			if(i<k&&map.get(s[i])==max){
				ans[i]=s[i];l++;
			}
			else
				ans[i]="zzzzzzzzzzz";
		}
		Arrays.sort(ans);
		for(int i=0;i<l;i++){
			System.out.println(ans[i]);
		}
	}
}


Measured memory_bytes: 88668
#include<iostream>
#include<algorithm>
using namespace std;
int dp[410][410],n,p,q;
int main(){
	for(int i=0;i<410;i++)for(int j=0;j<410;j++)dp[i][j]=1145141919;
	dp[0][0]=0;
	cin>>n>>p>>q;
	for(int i=0;i<n;i++){
		int a,b,c;cin>>a>>b>>c;
		for(int f=405-a;f>=0;f--)for(int g=405-b;g>=0;g--){
			if(dp[f][g]!=1145141919)dp[f+a][g+b]=min(dp[f+a][g+b],dp[f][g]+c);
		}
	}
	int ans=1145141919;
	for(int i=1;i<410;i++)for(int j=1;j<410;j++){
		if(i*q==j*p)ans=min(ans,dp[i][j]);
	}
	cout<<(ans==1145141919?-1:ans)<<endl;
	return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[500][500];
vll start,goal;

int main(){
  cin >> n;
  rep(i,0,n)cin >> d[i];
  ll x = 0,y = 0;
  ll p = 0,q = 0;
  rep(i,0,n){
    x += d[i];
    if(i % 2 == 0){
      if(x <= 0){
        p += -x + 1;
        x = 1;
      }
    }else{
      if(x >= 0){
        p += x + 1;
        x = -1;
      }
    }
  }
  rep(i,0,n){
    y += d[i];
    if(i % 2 != 0){
      if(y <= 0){
        q += -y + 1;
        y = 1;
      }
    }else{
      if(y >= 0){
        q += y + 1;
        y = -1;
      }
    }
  }
  print(min(p,q));
  return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  rep(i, h) cin >> grid[i];
  int cnt = 0;
  rep(i,h){
    rep(j,w){
      if(grid[i][j] == '#'){
        cnt++;
      }
    }
  }
  cout << (cnt == h + w - 1? "Possible" : "Impossible") << endl;
}

Measured memory_bytes: 256
var n,x,y:ansistring;
    i,j,k:longint;
    dem,l,o,a,b:int64;
begin
  readln(a);
  read(n);
  dem:=a;
  l:=low(int64);
  for k:=1 to a do
    begin
      dem:=0;
      x:=copy(n,1,k);
      y:=copy(n,k+1,a-k);
      for i:=1 to length(x)-1 do
        for j:=i+1 to length(x) do
          if x[i]=x[j] then x[j]:='0';
      for i:=1 to length(y)-1 do
        for j:=i+1 to length(y) do
          if y[i]=y[j] then y[j]:='1';
      for i:=1 to length(x) do
        for j:=1 to length(y) do if x[i]=y[j] then dem:=dem+1;
      if dem>l then l:=dem;;
    end;
  writeln(l);
  readln;
end.



Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


N=int(input())

if N==1:
    print(0)
    exit()

A=factorization(N)
ans=0
for a in A:
    n=a[1]#これが素因数の数
    i=1
    while n-i>=0 :
        ans+=1
        n-=i
        i+=1
print(ans)

Measured memory_bytes: 63460
#include <bits/stdc++.h>
#include <cstring>
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

int main(){
  fastIO
  int n;
  cin>>n;
  string str;
  cin>>str;
  int size=str.size();
  if(size<=n){
  	cout<<str;
  }
  else{
    
     for(int i=0;i<n;i++){
      cout<<str[i];}
      cout<<"...";


  }

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> s(N);
  for (int i = 0; i < N; i++) cin >> s.at(i);
  int total = 0;
  bool ansIsZero = true;
  for (int i = 0; i < N; i++) {
    if (s.at(i) % 10 != 0) ansIsZero = false;
    total += s.at(i);
  }
  if (ansIsZero) {
    cout << 0 << endl;
  }
  else if (total % 10 == 0) {
    int ans = 0;
    for (int i = 0; i < N; i++) {
      if ((total - s.at(i)) % 10 != 0) ans = max(ans, total - s.at(i));
    }
    cout << ans << endl;
  }
  else cout << total << endl;
}

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

int main(void){
	int N,x;
	cin>>N;
	vector<ll> a(N),suml(N+1),sumr(N+1);
	priority_queue<int,vector<int>,greater<int>> lq;
	priority_queue<int> rq;	
	rep(i,N)cin>>x, suml[0]+=x, lq.push(x);
	rep(i,N)cin>>a[i];
	rep(i,N)cin>>x, sumr[N]+=x, rq.push(x);
	rep(k,N){
		lq.push(a[k]);
		suml[k+1] = suml[k]+a[k]-lq.top();
		lq.pop();
		rq.push(a[N-1-k]);
		sumr[N-1-k] = sumr[N-k]+a[N-1-k]-rq.top();
		rq.pop();
	}
	ll res=LLONG_MIN;
	rep(k,N+1)res=max(res,suml[k]-sumr[k]);
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 3704
def main():
    N, K = map(int, input().split())
    if K == 0:
        return 1
    A = list(map(int, input().split()))
    MOD = 10**9+7
    dp = [[0]*(K+1) for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(N):
        a = A[i]
        for j in range(K+1):
            dp[i+1][j] += dp[i][j]
            if j+a+1 <= K:
                dp[i+1][j+a+1] -= dp[i][j]
        for j in range(K):
            dp[i+1][j+1] += dp[i+1][j]
        for j in range(K+1):
            dp[i+1][j] = dp[i+1][j] % MOD

    return dp[N][K]


print(main())


Measured memory_bytes: 118128
R = 'R'
L = 'L'

arr = gets.chomp

cross_indexes = []
humans = Array.new(arr.length, 0)
(arr.length-1).times do |i|
  if arr[i] == R && arr[i+1] == L
    cross_indexes.push(i)
  end
end
cross_indexes_for_left = cross_indexes.reverse

(arr.length).times do |i|
  if arr[i] == R
    target_index = cross_indexes.bsearch { |j| j >= i }
    if (target_index - i) % 2 == 0
      humans[target_index] += 1
    else
      humans[target_index + 1] += 1
    end
  else
    target_index = cross_indexes_for_left.bsearch { |j| j <= i }
    if (i - target_index) % 2 == 0
      humans[target_index] += 1
    else
      humans[target_index + 1] += 1
    end
  end
end

str = humans[0].to_s
(1..(humans.count - 1)).each do |i|
  str += ' ' + humans[i].to_s
end
puts str

Measured memory_bytes: 117804
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

const ll INF=1000000007;

ll pmod(ll x,ll y) {
    ll res=1;
    rep(i,y) res=res*x%INF;
    return res;
}

int main() {
    ll n;
    cin >> n;
    ll ans = pmod(10,n)-pmod(9,n)-pmod(9,n)+pmod(8,n);
    ans%=INF;
    ans=(ans+INF)%INF;
    cout << ans << endl;
}   

Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(4);
	vector<int> B(4);
	int res = (int)1 << 50;
	for (int i = 0; i < 4; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < 4; i++) {
		cin >> B[i];
	}

	for (int i0 = 0; i0 <= 100; i0++) {
		int num0 = i0 * B[0];
		for (int i1 = 0; i1 <= 100; i1++) {
			int num1 = num0 + i1 * B[1];
			for (int i2 = 0; i2 <= 100; i2++) {
				int num2 = num1 + i2 * B[2];
				int i3 = max((int)0, (N - num2 + B[3] - 1) / B[3]);

				res = min(res, i0 * A[0] + i1 * A[1] + i2 * A[2] + i3 * A[3]);
			}

		}
	}
	cout << res << endl;
}


Measured memory_bytes: 3196
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll mod =1e9+7;
ll boom[4];
int main()
{
    int n,a;cin>>n;
    ll ans=1;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        int sum=0;
        for(int j=0;j<3;j++)
        {
            if(boom[j]==a) sum++;
        }
        ans=ans*sum%mod;
        for(int j=0;j<3;j++)
        {
            if(boom[j]==a)
            {
                boom[j]++;
                break;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3640
import java.util.*;
class Main{
  public static void main(String[] args){
 
Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		if ((A+B)%2==0) {
			System.out.println((A+B)/2);
		}else {
			System.out.println("IMPOSSIBLE");
		}
}
}

Measured memory_bytes: 23764
import bisect as bs
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
max = a[len(a)-1]
idx  = bs.bisect_left(a,int(max/2))
if idx != 0:
    idx = idx-1 if max/2.0-a[idx-1] <= a[idx]-max/2.0 else idx
print(max,a[idx])

Measured memory_bytes: 14052
#include<stdio.h> 
int main(void){
    int n, m, i, l, j, k, q, M[102], key[102][102];
    scanf("%d", &n);
    for ( i = 0; i < n; i++ ) {
        scanf("%d%d", &M[i], &m);
    }
    M[n] = m;
    for ( i = 1; i < n + 1; i++ ) key[i][i] = 0;
    for ( l = 2; l < n + 1; l++) {
        for ( i = 1; i < n - l + 2; i++ ) {
            j = i + l - 1;
            key[i][j] = 100000000;
            for ( k = i; k <= j - 1; k++ ) {
                q = key[i][k] + key[k+1][j] + M[i-1] * M[k] * M[j];
                if ( key[i][j] > q ) {
                    key[i][j] = q;
                }
            }
        }
    }
    printf("%d\n", key[1][n]);
    return 0;
}

Measured memory_bytes: 1868
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
int main(void) 
{
	int i,j,n,m,mesi,turu,hun,hun2,con[202],min,con2[202];
	int k,p;
	scanf("%d",&n);
	for(i=0;i<202;i++) con[i]=0;
	for(i=0;i<n;i++) {
		scanf("%d %d",&mesi,&hun);
		con[i]=(mesi*60)+hun;
	}
	scanf("%d",&m);
	for(i=0;i<m;i++) {
		scanf("%d %d",&turu,&hun2);
		con[i+n]=(turu*60)+hun2;
	}
	sort(con,con+(n+m));
	for(i=0;i<n+m;i++) {
		if(con[i]==con[i+1]) i=i+1;
		printf("%d:",con[i]/60);
		if(con[i]%60<10){
			printf("0%d",con[i]%60);
		}
		else printf("%d",con[i]%60);
		if(n+m-1!=i) printf(" ");
	}
	printf("\n");
	return 0;
}
			

Measured memory_bytes: 1048
#include <bits/stdc++.h>
//#define DEBUG
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}

void solve(){
    int n, k;
    cin >> n >> k;
    set<int> d;
    for(int i = 0 ; i < 10; i++){
        d.insert(i);
    }
    for(int i = 0 ; i < k; i++){
        int x;
        cin >>  x;
        d.erase(x);
    }
    int p[5];
    for(int i = 0 ; i < 5 ; i++){
        p[i] = 0;
    }
    int j;
    for(j = 4 ; j >= 0; j--){
        p[j] = n % 10;
        n = n / 10;
        if( n == 0 ) break;
    }
    int i;
    for(i = j ; i < 5 ; i++){
        if( d.find(p[i]) == d.end()){
            break; 
        }else{
            continue;
        }
    }
    int smallest_digit = *d.lower_bound(0);
    auto it = d.lower_bound(p[i]);
    if ( it == d.end()){
        int update_index = i - 1;
        while ( d.lower_bound(p[update_index] + 1) == d.end()){
            update_index--;
        }
        p[update_index] = *d.lower_bound(p[update_index] + 1);
        int ans = 0;
        for(int k = 0 ; k < 5 ; k++){
            if( k <= update_index){
                ans = ans * 10 + p[k];
            }else{
                ans = ans * 10 + smallest_digit;
            }
        }
        cout << ans << endl;
        return;
    }

    p[i] = *it;

    int ans = 0;
    for( int k = 0 ; k < 5 ; k++){
        if( k <= i ){
            ans = ans * 10 + p[k];
        }else{
            ans = ans * 10 + smallest_digit;
        }
    } 

    cout << ans << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}


Measured memory_bytes: 3592
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let k:usize = read();
    let mut v:Vec<u128> = (0..n).map(|_| read()).collect();
    if k >= n {
        println!("0");
    } else {
        v.sort();
        let v = &v[0..n-k];
        println!("{}", v.iter().sum::<u128>());
    }
}


Measured memory_bytes: 6440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=200005;
ll n,a,q;
struct node { ll l,r; } e[maxn];
inline bool operator < (const node &a,const node &b) { return a.l<b.l; }
int main()
{
	scanf("%lld%lld%lld",&n,&a,&q);
	if(a==0 && q==0) return printf("1\n"),0;
	if(q==0) return printf("%lld\n",n+1),0;
	if(q<0) a+=(n-1)*q,q=-q;
	ll val=__gcd(abs(a),q);
	a/=val,q/=val;
	ll i,j,k,l,r,ans=0;
	for(i=0;i<=min(q-1,n);i++)
	{
		// a * x + q * y
		// (x % q) * a + ((x / q) * a + y)
		for(j=i,k=0;j<=n;j+=q,k++)
			e[k].l=j*(j-1)/2+k*a,e[k].r=j*(2*n-j-1)/2+k*a;
		sort(e,e+k);
		l=e[0].l,r=e[0].r;
		for(j=1;j<k;j++)
		{
			if(e[j].l>r) ans+=r-l+1,l=e[j].l;
			r=max(r,e[j].r);
		}
		ans+=r-l+1;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(k: usize);
    let mut count = 1;
    let mut temp = 7;

    while count < (10 as usize).pow(6) {
        temp %= k;
        if temp == 0 {
            println!("{}", count);
            return;
        }
        count += 1;
        temp = temp * 10 + 7;
    }
    println!("{}", -1);
}


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

using namespace std;

long long inf=1000000007;

long long modpow(long long n,long long p,long long mod);

int main(){
	long long n;
	cin>>n;
	cout<<n<<":";

	for(long long i=2;i*i<=n;i++){
		while(n%i==0){
			cout<<" "<<i;
			n/=i;
		}
	}
	if(n!=1) cout<<" "<<n;

	cout<<endl;

	return 0;
}

long long modpow(long long n,long long p,long long mod){
	if(p==0) return 1;
	if(p%2==0) return (modpow(n,p/2,mod)*modpow(n,p/2,mod))%mod;
	if(p%2==1) return (modpow(n,p-1,mod)*n)%mod;
	cerr<<"ERROR"<<endl;
	return 1;
}



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

using namespace std;
typedef long long ll;

deque<char> d;
string s;
ll Q;
bool f;

int main(){
    cin >> s;
    cin >> Q;
    f = true;
    for(auto &e : s) d.push_back(e);
    for(int i=0;i<Q;i++){
        int a;
        cin >> a;
        if(a == 1){
            if(f) f = false;
            else f = true;
        }else{
            int b;
            char c;
            cin >> b >> c;
            if((b == 1 && f) || (b == 2 && !f)) d.push_front(c);
            else d.push_back(c);
        }
    }
    if(!f) reverse(d.begin(),d.end());
    for(auto &e : d) cout << e;
    cout << endl;
    return 0;
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];
    vector<int> a(m);
    vector<int> b(m);
    rep(i,m) cin >> a[i] >> b[i];

    vector<bool> isGood(n);
    rep(i,n) isGood[i] = true;
    rep(i,m){
        if(h[a[i]-1] <= h[b[i]-1]) isGood[a[i]-1]=false;
        if(h[b[i]-1] <= h[a[i]-1]) isGood[b[i]-1]=false; 
    }

    sort(ALL(isGood));
    int cnt=0;
    rep(i,n){
        if(isGood[i]) break;
        cnt++;
    }

    cout << n-cnt << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  int64_t ans=0;
  for(int i=0;i<N;i++){
    int l,r;
    cin >> l >> r;
    ans+=r-l+1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
// Copyright (C) 2017 __debug.

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.


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

#define x first
#define y second
#define MP std::make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

using std::pair;
using std::vector;
using std::string;

typedef long long LL;
typedef pair<int, int> Pii;

const int oo = 0x3f3f3f3f;

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, true : false; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, true : false; }
string procStatus()
{
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}
template<typename T> T read(T &x)
{
    int f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar())
        f = (ch == '-' ? -1 : 1);
    for (x = 0; isdigit(ch); ch = getchar())
        x = 10 * x + ch - '0';
    return x *= f;
}
template<typename T> void write(T x)
{
    if (x == 0) {
        putchar('0');
        return;
    }
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    static char s[20];
    int top = 0;
    for (; x; x /= 10)
        s[++top] = x % 10 + '0';
    while (top)
        putchar(s[top--]);
}
// EOT

const int MAXN = 2e5 + 5;
const int MOD = 1e9 + 7;

int H, W, A, B;

void input()
{
    read(H); read(W); read(A); read(B);
}

LL fac[MAXN], ifac[MAXN];

LL fpm(LL base, LL exp)
{
    LL ret = 1;
    for (; exp; exp >>= 1) {
        if (exp & 1)
            (ret *= base) %= MOD;
        (base *= base) %= MOD;
    }
    return ret;
}

inline LL C(int x, int y)
{
    --x; --y;
    return fac[x + y] * ifac[x] % MOD * ifac[y] % MOD;
}

void solve()
{
    int rng = H + W;
    fac[0] = 1;
    for (int i = 1; i <= rng; ++i) {
        fac[i] = fac[i - 1] * i % MOD;
    }
    ifac[rng] = fpm(fac[rng], MOD - 2);
    for (int i = rng; i >= 1; --i) {
        ifac[i - 1] = ifac[i] * i % MOD;
    }

    LL ans = C(H, W);
    for (int i = 1; i <= B; ++i) {
        (ans -= C(H - A, i) * C(A, W - i + 1)) %= MOD;
    }
    (ans += MOD) %= MOD;

    printf("%lld\n", ans);
}

int main()
{
#ifdef __DEBUG
    freopen("D.in", "r", stdin);
    freopen("D.out", "w", stdout);
#endif

    input();
    solve();
}

// 好时节，愿得年年，常见中秋月。
//     -- 徐有贞《中秋月·中秋月》


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

int main(){
  // start process
  int a, b;
  cin >> a >> b;
  int dif = a - b;
  if(dif==0){
    cout << a + b << endl;
  }else if(dif==1){
    cout << a + a - 1 << endl;
  }else if(dif==-1){
    cout << b + b - 1 << endl;
  }else if(dif>1){
    cout << a + a - 1 << endl;
  }else{
    cout << b + b - 1 << endl;
  }
  // end process
  return 0;
}


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

vector<vector<pair<int, long long>>> connect;
int N;
vector<long long> score;

int main() {
    long long M;
    cin >> N >> M;
    long long MIN_SCORE = -pow(10, 9) * M - 1;
    connect.resize(N + 1);
    score.resize(N + 1, MIN_SCORE);
    for (int i = 0; i < M; i++) {
        int a, b;
        long long c;
        cin >> a >> b >> c;
        connect[a].push_back({ b, c });
    }

    score[1] = 0;  //開始位置の距離は0
    for (int i = 0; i < 2 * N; i++) {
        for (int v = 1; v <= N; v++) {
            for (auto edge : connect[v]) {
                if (score[v] != MIN_SCORE && score[edge.first] < score[v] + edge.second) {
                    score[edge.first] = score[v] + edge.second;
                    if (i >= N - 1 && edge.first == N) {
                        cout << "inf" << endl;
                        return 0;
                    }
                }
            }
        }
    }

    cout << score[N] << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX =2000007;
const int MOD = 998244353;
//

     signed main(){
     int n,m,k;
     cin>>n>>m>>k;
     int a[n],b[m];
     for(int i=0;i<n;i++)cin>>a[i];
     for(int i=0;i<m;i++)cin>>b[i];
     int ans=0;
     int t=0,s=0;
     while(t<m&&ans+b[t]<=k){
         ans+=b[t];
         t++;
     }
     while(s<n&&ans+a[s]<=k){
         ans+=a[s];
         s++;
     }
     int ans2=t+s;
     while(t>0){
         t--;
         ans-=b[t];
        while(s<n&&ans+a[s]<=k){
         ans+=a[s];
         s++;
     }
     ans2=max(ans2,s+t);
     }
     cout<<ans2<<endl;


     }


 


 






    





      

        


Measured memory_bytes: 6720
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
long long mod=1e9+7;

int main(){
    long long n;
    cin>>n;
    long long ten=1,eight=1,nine=1;
    for(int i=0;i<n;++i){
        ten*=10;
        ten%=mod;
    }
    for(int i=0;i<n;++i){
        eight*=8;
        eight%=mod;
    }
    for(int i=0;i<n;++i){
        nine*=9;
        nine%=mod;
    }
    nine*=2;
    nine%=mod;
    long long res=ten;
    res-=nine;
    res%=mod;
    res+=eight;
    res%=mod;
    res+=mod;
    res%=mod;
    cout<<res<<endl;
}

Measured memory_bytes: 3672
#include <bits/stdint-intn.h>
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using Int = int64_t;
using pint = pair<Int, Int>;
using vint = vector<Int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<"\n";}
template<class T>void println(T a){cout << a << "\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<((itr==--v.end())?"\n":" ");}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);

int main(void) {
    string s; cin >> s;
    if(s == "ABC") {
        println("ARC");
    } else {
        println("ABC");
    }

    return 0;
}


Measured memory_bytes: 3624
import math

k = int(input())
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        ab = math.gcd(a, b)
        if ab == 1:
            ans += k
            continue
        for c in range(1, k+1):
            ans += math.gcd(ab,c)

print(ans)

Measured memory_bytes: 9188
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in range(n):
    for j in range(i+1,n):
        a=0
        for k in range(d):
            a+=(x[i][k]-x[j][k])**2
        if a**0.5==int(a**0.5):
            ans+=1
print(ans)

Measured memory_bytes: 9396
n = gets.to_i
a =  gets.split.map(&:to_i)
puts a.join(' ')

for i in 1..n-1
  v = a[i]
  j = i - 1
  while j >= 0 && a[j] > v
    a[j+1] = a[j]
    j-=1
  end
  a[j+1] = v
  puts a.join(' ')
end

Measured memory_bytes: 6112
from math import factorial

N = int(input())
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]

def f(X):
    res = 1
    A = [i+1 for i in range(N)]
    for i in range(N):
        A.sort()
        if X[i] != min(A):
            res += factorial(N-(i+1)) * (A.index(X[i]))
        del A[A.index(X[i])]
    return res

print(abs(f(P)-f(Q)))

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>

using namespace std;

#define LL long long
#define uLL unsigned long long
#define DD double
#define LDD long double
#define PI acos(-1)
#define modulo 10000007
#define MX 10000
#define EPS 1e-9

main()
{
    //freopen("INPUT.txt", "r", stdin);
    //freopen("OUTPUT.txt", "w", stdout);

    LL a, b, x, p, q, ans=0;
    scanf("%lld %lld %lld", &a, &b, &x);
    ans = (b/x) - ((a)/x);
    if(a%x == 0) ans++;
    printf("%lld\n", ans);
}


Measured memory_bytes: 256
from itertools import product
H,W,K=map(int,input().split())

A = [input() for j in range(H)]

ans=0
for i in product([1,0],repeat=H):
    for j in product([1,0],repeat=W):
        cnt=0
        for row in range(H):
            for col in range(W):
                if ((A[row][col]=="#") and ((i[row]==0) and j[col]==0)):
                    cnt+=1
        if cnt==K:
            ans+=1
            
print(ans)
    

Measured memory_bytes: 9068
//frog1
#include<bits/stdc++.h>
using namespace std;
int n;
int height[100005];
int func(){
	int dp[100005];
	dp[0]=0;
	dp[1]=abs(height[1]-height[0]);
	for(int i=2;i<=n;i++){
		int op1=INT_MAX,op2=INT_MAX;
		if((i-1)>=0)
			op1=abs(height[i]-height[i-1]);
		if((i-2)>=0)
			op2=abs(height[i]-height[i-2]);
		dp[i]=min(dp[i-1]+op1,dp[i-2]+op2);
	}
	return dp[n-1];
}
int main(){
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	cin>>n;
	for(int i=0;i<n;i++)
		cin>>height[i];
	cout<<func()<<endl;
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))
mod = pow(10, 9) + 7
num = [-1] * (n + 1)
for i in range(n + 1):
    if num[a[i]] == -1:
        num[a[i]] = i
    else:
        samei, samej = num[a[i]], i
        break
x = n + samei - samej
same = 1
comb = n + 1
print(comb - 1)
for i in range(2, n + 2):
    comb = (comb * (n - i + 2) * pow(i, mod - 2, mod)) % mod
    if i - 1 <= x:
        same = (same * (x - i + 2) * pow(i - 1, mod - 2, mod)) % mod
    else:
        same = 0
    print((comb - same) % mod)

Measured memory_bytes: 14008
from math import floor
from fractions import gcd

def lcm(x: int, y: int) -> int:
    return (x * y) // gcd(x, y)

def calc(n: int, x: int, y: int) -> int:
    return n - n//x - n//y + n//lcm(x, y)


a, b, c, d = [int(i) for i in input().split()]
print(calc(b, c, d) - calc(a - 1, c, d))


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

int main() {
  int A,B;
  cin >> A >> B;
  int X=0;
  for(int i=0;i<2;i++){
  if(A>B){
    X =X+A;
    A--;
  }
  else{
    X =X+B;
    B--;
  }
  }
  cout << X << endl;
}
















Measured memory_bytes: 3624
n=int(input())
l=[list(map(int,input().split())) for i in range(n-1)]
connection=[[] for i in range(n)]
for i in range(n-1):
  connection[l[i][0]-1].append(l[i][1]-1)
  connection[l[i][1]-1].append(l[i][0]-1)
c=list(map(int,input().split()))
c.sort()
c.reverse()

def bfs(v):
  ans=[-1]*n
  ans[v]=0
  next=connection[v]
  next2=set()
  visited=[-1]*n
  visited[v]=1
  visitct=1
  ct=0
  while len(next)!=0 and visitct!=n:
    for i in range(len(next)):
      if visited[next[i]]==-1:
        ct+=1
        ans[next[i]]=ct
        visited[next[i]]=1
        visitct+=1
        for j in range(len(connection[next[i]])):
          if visited[connection[next[i]][j]]==-1:
            next2.add(connection[next[i]][j])
    next=list(next2)
    next2=set()
  return ans

ans=bfs(0)
print(sum(c)-c[0])
for i in range(n):
  ans[i]=str(c[ans[i]])
print(' '.join(ans))

Measured memory_bytes: 8328
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline int readint() {
	char c = getchar(); int w = 1; int x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar();
	x *= w;
	return x;
}
inline ll readll() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 3) + (x << 1) + (c ^ '0'), c = getchar();
	x *= w;
	return x;
}
void fl(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};

int main(){
    ll n;
    cin>>n;
    ll a[n+1];
    rp(i,1,n){
        cin>>a[i];
    }
    ll ans=0;
    rp(i,1,n-1){
        if(a[i]>a[i+1]){
            ans+=a[i]-a[i+1];
            a[i+1]=a[i];
        }
    }cout<<ans<<endl;return 0;
}
/* stuff to remember
	* int overflow, array bounds
	* special cases (n=1? n=0?)
	* do something instead of nothing and stay organized
	* USE STATIC ARRAYS
	* DEFINING ARRAYS BEFORE main()
	* DO NOT DEFINE ARRAYS IN main()
	* USE INT INSTEAD OF LL,NOTICE THE MLE
*/

Measured memory_bytes: 5228
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    string s; cin >> s;
    cout << s[0] << s.size()-2 << s[s.size()-1] << "\n";
}


Measured memory_bytes: 256