akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#define m 1147849
#define L 14
char dic[m][L];
int insert_str(char[]);
int find_str(char[]);
int h1(int);
int h2(int);
long long getkey(char[]);
int to_num(char);
int insert_str(char data1[]){
    long long i,key=getkey(data1),H;
    for(i=0;;i++){
        H=(h1(key)+i*h2(key))%m;
        if(strcmp(dic[H],data1)==0){
            return 1;
        }else if(strlen(dic[H])==0){
            strcpy(dic[H],data1);
            return 0;
        }
    }
    return 0;
}
int find_str(char data1[]){
    int i;
    long long key=getkey(data1),H;
    for(i=0;;i++){
        H=(h1(key)+i*h2(key))%m;
        if(strcmp(dic[H],data1)==0){
            return 1;
        }else if(strlen(dic[H])==0){
            return 0;
        }
    }
    return 0;
}
int h1(int num2){
    return num2%m;
}
int h2(int num3){
    return 1+num3%(m-1);
}
long long getkey(char str[]){
    long long sum=0;int j,p=1;
    for(j=0;j<strlen(str);j++){
        sum+=p*(to_num(str[j]));
        p*=3;
    }
    return sum;
}
int to_num(char ch){
    if(ch=='A'){
        return 1;
    }else if(ch=='C'){
        return 2;
    }else if(ch=='G'){
        return 3;
    }else if(ch=='T'){
        return 4;
    }
    return 0;
}
int main(void){
    char order[9],data[L];
    int k,n;
    scanf("%d",&n);
    for(k=0;k<m;k++){
        dic[k][0]='\0';
    }
    for(k=0;k<n;k++){
        scanf("%s %s",order,data);
        if(order[0]=='i'){
            insert_str(data);
        }else{
            if(find_str(data)){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 17484
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



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

	/*
	string S; cin >> S;
	int N = S.size();
	VI pos[26];
	REP(i, N) pos[S[i] - 'a'].push_back(i + 1);
	vector<VI>ne(N, VI(26, N));
	cout << N << endl;

	REP(i, 26) {
		if (pos[i].size()) {
			for (int k = 0; k < pos[i][0] - 1; k++)ne[k][i] = pos[i][0];
		}
		REP(j, (int)pos[i].size() - 1) {
			for (int k = pos[i][j] - 1; k < pos[i][j + 1] - 1; k++) {
				ne[k][i] = pos[i][j + 1];
			}
		}
	}
	VI dp(N + 2, INF);
	dp[N] = 1;
	for (int i = N - 1; i >= 0; i--) {
		int tmp = INF;
		REP(j, 26) {
			int a = ne[i][j];
			//cout << i << " " << a << endl; 
			int t = 0;
			//if (a != N)t++;
			chmin(tmp, dp[a] + 1);
		}
		chmin(dp[i], tmp);
	}
	cout << dp[0] << endl;
	*/


	string S;

	cin >> S;
	REP(i, S.size()) {
		FOR(j, i + 1, S.size()) {
			if (S[i] == 'C'&&S[j] == 'F') {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;

	return 0;
}



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

int main() {
  LL a, b, x;
  cin >> a >> b >>x;

  LL s, t, u;
  s = b / x;
  t = a / x;
  if (a % x == 0) {
    u = s - t + 1;
  } else {
    u = s - t;
  }

  cout << u << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define nd second
#define st first
#define pb push_back
#define pa make_pair

using namespace std;
typedef long long int lo;

lo a,b,c,d,e,g,h[500005],arr[500005];

int main(){
	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);
	cin >>a;
	for(lo i=1;i<=a+1;i++){
		cin >> arr[i];
	}
	for(lo i=1;i<=a;i++){
		cin >> h[i];
	}
	lo ans=0;
	for(lo i=1;i<=a;i++){
		if(h[i]>=arr[i]){
			h[i]-=arr[i];
			ans+=arr[i];
			if(h[i]>=arr[i+1]){
				ans+=arr[i+1];
				arr[i+1]=0;
			}
			else{
				arr[i+1]-=h[i];
				ans+=h[i];
			}
		}
		else{
			arr[i]+=h[i];
			ans+=h[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 5120
import java.util.Scanner;


public class Main {
	public static void main(String[] args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//?§???°?????????
		int Time = sc.nextInt();
		//?§???????????????????
		int T = Time / 3600;
		//?§????????????????
		int M = Time / 60 % 60;
		//?§?????§??????????
		int S = Time % 60;
		//??¨???
		System.out.println(T +":"+ M +":"+ S);
	}
}

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


YES = "YES"  # type: str
NO = "NO"  # type: str


def solve(A: str, B: str, C: str):
    print(YES if A[-1] == B[0] and B[-1] == C[0] else NO)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = next(tokens)  # type: str
    B = next(tokens)  # type: str
    C = next(tokens)  # type: str
    solve(A, B, C)


if __name__ == '__main__':
    main()


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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    string s;
    cin >> s;
    int k;
    cin >> k;
    vector<string> vc;
    string sub;
    //since its substring and not subsequence we will cal all substrings
    for (int i = 1; i < k+1; i++)
    {
        //running it for 1 to k times 
        //then for l length and cal all substrings and pushign them in the vector
        for (int j = 0; j+i-1<s.length(); j++)
        {
            sub = s.substr(j,i);
            vc.push_back(sub);
        }
    }
    //its just sorting and printing
    sort(vc.begin(),vc.end());
    unique(vc.begin(),vc.end());
    
    cout << vc[k-1] << endl;
    
    
}


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

int N, M;
int adj[20][20];
int prec[1 << 15], sum[20][1 << 15];

int cc[20][1 << 15][2];
int dp(int u, int mask, int t) {
    int &ret = cc[u][mask][t];
    if(ret != -1) return ret;
    if(u == N - 1) return ret = prec[mask ^ (1 << u)];
    if(!(mask & (1 << (N - 1)))) return ret = 1e9;

    ret = 1e9;
    if(t) {
        for(int i = mask;; i = (i - 1) & mask) {
            ret = min(ret, dp(u, mask ^ i, 0) + prec[i ^ (1 << u)]);
            if(!i) break;
        }
    }
    else {
        for(int v = 0; v < N; v++) {
            if(!adj[u][v]) continue;
            if(mask & (1 << v)) {
                ret = min(ret, dp(v, mask ^ (1 << v), 1) - 2 * adj[u][v]);
            }
        }
    }
    return ret;
}

int main() {
    scanf("%d %d", &N, &M);

    for(int i = 0; i < M; i++) {
        int u, v, w; scanf("%d %d %d", &u, &v, &w);
        u--; v--;
        adj[u][v] = adj[v][u] = w;
    }

    for(int i = 0; i < (1 << N); i++) {
        for(int j = 0; j < N; j++) {
            if(!(i & (1 << j))) continue;

            for(int k = 0; k < N; k++) {
                if(i & (1 << k)) continue;

                prec[i] += adj[j][k];
            }
        }
    }
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < (1 << N); j++) {
            for(int k = 0; k < N; k++) {
                if(j & (1 << k)) {
                    sum[i][j] += adj[i][k];
                }
            }
        }
    }

    memset(cc, -1, sizeof(cc));
    printf("%d", dp(0, (1 << N) - 2, 1) / 2);
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> l(n);
  

  rep(i,n) cin >> l[i];
  
  int cnt = 0;
  int length = 0;
  
  rep(i,n-2)
  {
    int l1 = l[i];
    
    for(int j = i+1; j < n-1; ++j)
    {
      if(l[j] != l1)
      {
        int l2 = l[j];
        
        for(int k = j+1; k<n; ++k)
        {
          if(l[k] != l1 && l[k] != l2)
          {
            int l3 = l[k];
            
            length = max({l1,l2,l3});
            length = length + length - (l1+l2+l3);
                  
            if(length < 0) ++cnt;
          }
          
        }
      }
    }
    
  }
  cout << cnt;
  return 0;
}

Measured memory_bytes: 3628
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second

int main(){
    int H, W;
    cin >> H >> W;
    vector<vector<char>> G(H, vector<char>(W));
    for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) cin >> G[i][j];
    vector<bool> tate(H);
    vector<bool> yoko(W);
    for(int i = 0; i < H; i++){
        bool can = true;
        for(int j = 0; j < W; j++) if(G[i][j] ==  '#') can = false;
        tate[i] = can;
    }
    for(int j = 0; j < W; j++){
        bool can = true;
        for(int i = 0; i < H; i++) if(G[i][j] == '#') can = false;
        yoko[j] = can;
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(!tate[i] and !yoko[j]) cout << G[i][j];
        }
        if(!tate[i]) cout << endl;
    }

}


Measured memory_bytes: 3644
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b){return b ? gcd(b, a%b) : a;}


int main(){
   int n, m;
   cin >> n >> m;
   vector<P> p(m);
   for(int i = 0; i < m; i++){
      cin >> p[i].first >> p[i].second;
   }

   for(int i = 0; i < 1000; i++){ //小さいほうから全部見ていく
      bool flag = true;
      int nx = i/10;
      int keta = 1;
      vector<int> target(1,i%10);
      while(nx != 0){
         keta++;
         target.push_back(nx%10);
         nx /= 10;
      }
      if(keta != n) continue; //桁違い
      reverse(target.begin(), target.end());
      for(int j = 0; j < m; j++){
         if(target[p[j].first-1] != p[j].second) flag = false;
      }

      if(flag == true){
         cout << i << endl;
         return 0;
      }
   }
   cout << -1 << endl;
   return 0;
}
 

Measured memory_bytes: 256
N,M=map(int,input().split())
if N>M//2:
    ans=M//2
    N-=ans
    if M%2==0:
        M=0
    else:
        M=1
else:
    ans=N
    M-=N*2
    N=0
    if M>3:
        X=M//4
        M-=X*4
        ans+=X
while True:
    if M<2:
        break
    if N==0:
        if M<4:
            break
    if N>0:
        N-=1
        M-=2
        ans+=1
    elif M>3:
        M-=2
        ans+=1
print(ans)

Measured memory_bytes: 9160
import java.util.Scanner;

public class Main {

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

		int n = sc.nextInt();
		char[] str = sc.next().toCharArray();

		int result = 1;
		for(int i = 1; i < n; i++){
			if(str[i] != str[i - 1]){
				result++;
			}
		}

		System.out.println(result);
	}

}


Measured memory_bytes: 26584
#include <iostream>
#include<vector>
#include<bits/stdc++.h>

using namespace std;

int main()
{
   int n;
   cin>>n;
   vector<int> v(n,-1);
   int m,f=0;
   cin>>m;
   for(int i=1;i<=m;i++)
    {
        int p;
        int d;
        cin>>p>>d;
        if(v[p-1]==-1)
        v[p-1]=d;
        else
        {
            if(v[p-1]!=d)
            f=1;
        }
    }
    if(v[0]==-1)
     v[0]=1;
    for(int i=0;i<n;i++)
    {
        if(v[i]!=-1)
         continue;
         else
         v[i]=0;
    }
    if(f==1 || (n>1 && v[0]==0))
    cout<<-1;
    
   else if(n==1 && m==0)
   cout<<0;
    else
    {
        int sum=0;
    for(int i=1;i<=n;i++)
     sum=sum+v[i-1]*pow(10,n-i);
     cout<<sum;
    }
     
   
   
   return 0;
}


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

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

  vector<int> a(n), b(n), c(n-1);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < n; i++) {
    cin >> b.at(i);
  }
  for (int i = 0; i < n - 1; i++) {
    cin >> c.at(i);
  }

  int m = 0, be = -1;
  for (int i = 0; i < n; i++) {
    m += b.at(a.at(i) - 1);
    if (be + 1 == a.at(i)) {
      m += c.at(be - 1);
    }
    be = a.at(i);
  }

  cout << m << endl;
}


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

int main(){
    int S;
    int h, m, s;

    cin >> S;

    // h = 13;
    // m = 2;
    // s = 59;

    // cout << h << ":" << m << ":" << s << endl;

    int shou;
    // int amari;

    s = S % 60;
    shou = S / 60;

    // cout << shou << endl;
    // cout << amari << endl;

    // m = shou / 60;
    m = shou % 60;
    // h = shou % 60;
    h = shou / 60;

    // cout << shou << endl;
    // cout << amari << endl;

    cout << h << ":" << m << ":" << s << endl;

    return 0;
}


Measured memory_bytes: 3064
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    Integer[] s = new Integer[N];

    int sum = 0;

    for (int i = 0; i < N; i++) {
      s[i] = sc.nextInt();
      sum += s[i];
    }

    sc.close();

    Arrays.sort(s);
    
    if (sum % 10 == 0) {
      for (int i = 0; i < N; i++) {
        if (s[i] % 10 != 0 ) {
          sum = sum - s[i];
          break;
        }
      }
      if (sum % 10 == 0) {
        sum = 0;
      }
    }

    System.out.println(sum);

  }

}

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

int main() {
  long n;int k;
  cin >> n >> k;
  int ans = 1;
  while(true){
    if(n/k == 0){
      cout << ans << endl;
      return 0;
    }
    n /= k;
    ans++;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(ll i=0; i<(N); i++)
const ll mod=1e9+7;

const ll mx=1e5+5;
ll N,K;
ll h[mx];
ll ans=mod;

int main(){ 

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

cin>>N>>K;

rep(i,N){
	cin>>h[i];
}
sort(h,h+N);
rep(i,N){
	if(i+K-1>=N) continue;
	ll hh=h[i+K-1]-h[i];
	ans=min(ans,hh);
}

cout<<ans<<endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll                  long long
#define ld                  long double
#define pb                  push_back
#define mkp                 make_pair
#define f(i,l,h)            for(ll i=l;i<h;i++)
#define fr(i,h,l)           for(ll i=h;i>=l;i--)
#define mem(a,val)          memset(a,val,sizeof(a))
#define all(v)              (v).begin(),(v).end()
#define ff                  first
#define ss                  second
#define spc(x)              cout<<fixed<<setprecision((x));
#define deb(x)              cout<<#x<<" "<<x<<endl;
#define deba(x)             cout<<#x<<": "; for(auto u:x) cout<<u<<" ";  cout<<endl;
#define check               cout<<"hello"<<endl;
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
const ld pi=3.141592653589793;
const ll mod=998244353;
const ll INF=(ll)(1e9+7);
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

ll power(ll a,ll b){
    ll res=1;
	while(b){
	    if(b&1) res=(res*a);
	    a=(a*a);
	    b>>=1;
	}
	return res;
}

int main()
{
    //cout << "Hello world!" << endl;
    ll t;
    cin>>t;
    ll cnt=0;
    ll ac=0, wa=0,re=0,tle=0;
    while(t--){
        string s;
        cin>>s;
        if(s=="AC" ) ac++;
        if(s=="WA") wa++;
        if(s=="TLE") tle++;
        if( s=="RE") re++;
    }

    
    cout<<"AC x "<<ac<<endl;
    
    cout<<"WA x "<<wa<<endl;
    
    
        cout<<"TLE x "<<tle<<endl;
    
        cout<<"RE x "<<re<<endl;
    
    return 0;
}


Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<int> a(n + 1); REP(i, n + 1) cin >> a[i];
  ll ans = 1, node = 1, sum = accumulate(ALL(a), 0LL);
  if (sum == 0) {
    cout << "-1\n";
    return 0;
  }
  REP(i, n + 1) {
    if (a[i] > node) {
      cout << "-1\n";
      return 0;
    }
    node -= a[i];
    sum -= a[i];
    node = min(node * 2, sum);
    // cout << ans << ' ' << node << '\n';
    ans += node;
  }
  assert(node == 0);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3748
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader sysin = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(sysin.readLine());
		int odd = ( n + 1 ) / 2;
		System.out.println(((double) odd)/n);
	}
}

Measured memory_bytes: 33008
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<vector<int> > G(n, vector<int>());
	REP(i, m){
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int> dist(n, INF), pre(n, -1);
	dist[0] = 0;
	queue<int> q;
	q.push(0);
	while(q.size()){
		int now = q.front(); q.pop();
		for(auto v : G[now]){
			if(dist[v] != INF) continue;
			dist[v] = dist[now] + 1;
			pre[v] = now;
			q.push(v);
		}
	}
	cout << "Yes" << endl;
	rep(i, 1, n){
		cout << pre[i] + 1 << endl;
	}
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};


int main(){

  char c;
  cin >> c;
  if(c == 'A')cout << 'T' << endl;
  if(c == 'T')cout << 'A' << endl;
  if(c == 'C')cout << 'G' << endl;
  if(c == 'G')cout << 'C' << endl;


  return 0;
}


Measured memory_bytes: 256
import sys
import math
from functools import reduce
def input(): return sys.stdin.readline().rstrip()
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def main():
    k=int(input())
    sum=0
    for i in range(1,k-1):
        for j in range(i+1,k):
            for l in range(j+1,k+1):
                sum+=gcd(i,j,l)*6
    for i in range(1,k+1):
        for j in range(1,k+1):
            if i!=j:
                sum+=gcd(i,j,j)*3
    for i in range(1,k+1):
        sum+=gcd(i,i,i)
    print(sum)

if __name__=='__main__':
    main()

Measured memory_bytes: 9660
#!/usr/bin/env python3

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

MOD = 10**9 + 7

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

A = [a % MOD for a in A]
A_d = [(a * a) % MOD for a in A]
res = ((sum(A)**2) % MOD - sum(A_d) % MOD) % MOD
res = res * pow(2, MOD-2, MOD)
res %= MOD

print(res)


Measured memory_bytes: 31400
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h, w;
  cin >> h >> w;
  REP(i,h) {
    string s;
    cin >> s;
    cout << s << endl;
    cout << s << endl;
  }
  return 0;
}
//templete by private_yusuke

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

int main() {
  int N, M, Q; cin >> N >> M >> Q;
  vector<int> a(Q);
  vector<int> b(Q);
  vector<int> c(Q);
  vector<int> d(Q);
  for (int i = 0; i < Q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  vector<int> v{1};
  int res = 0;
  auto dfs = [&](auto&& f, int i = 1) -> void {
    if (i == N + 1) {
      int t = 0;
      for (int q = 0; q < Q; q++) {
        if (v[b[q]] - v[a[q]] == c[q]) t += d[q];
      }
      res = max(t, res);
      return;
    }
    v.push_back(v[i-1]);
    for (; v[i] <= M; v[i]++) {
      f(f, i+1);
    }
    v.pop_back();
  };
  dfs(dfs);
  cout << res << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int s(vector<vector<int>>& f, int bx, int by, int ex, int ey) {
	if (bx < 0 || by < 0 || ex >= f.size() || ey >= f[0].size()) return 0;

	return f[bx][by] - f[bx][ey] - f[ex][by] + f[ex][ey];
}

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

	vector<vector<int>> f(2*k+1, vector<int>(2*k+1, 0));
	int x, y;
	char c;

	for (int i = 0; i< n; i++) {
		cin >> x >> y >> c;
		if (c == 'W') {
			x += k;
		}
		x = x % (2*k);
		y = y % (2*k);
		f[x+1][y+1] += 1;
	}

	for (int i = 1; i < 2*k+1; i++) {
		for (int j = 1; j < 2*k+1; j++) {
			f[i][j] += f[i][j-1] + f[i-1][j] - f[i-1][j-1];
		}
	}

	int ans = 0;
	for (int i = 0; i < k; i++) {
		for (int j = 0; j < k; j++) {
			int c1 = s(f, 0, 0, i+1, j+1);
			int c2 = s(f, i+k+1, 0, 2*k, j+1);
			int c3 = s(f, i+1, j+1, i+k+1, j+k+1);
			int c4 = s(f, 0, j+k+1, i+1, 2*k);
			int c5 = s(f, i+k+1, j+k+1, 2*k, 2*k);
			int cb = c1 + c2 + c3 + c4 + c5;
			if (cb > ans) {
				ans = cb;
			}
			int c6 = s(f, i+1, 0, i+k+1, j+1);
			int c7 = s(f, i+1, j+k+1, i+k+1, 2*k);
			int c8 = s(f, 0, j+1, i+1, j+k+1);
			int c9 = s(f, i+k+1, j+1, 2*k, j+k+1);
			int cb2 = c6 + c7 + c8 + c9;
			if (cb2 > ans) {
				ans = cb2;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 16000
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#include <assert.h>
#include <bitset>
#define Endl endl
#define mp make_pair
#define ll long long 
#define ull unsinged long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
template <typename T1,typename T2> inline void chmin(T1 &x,T2 b) {if(b<x) x=b;}
template <typename T1,typename T2> inline void chmax(T1 &x,T2 b) {if(b>x) x=b;}
const int inf=1039074182;
const ll llinf=1LL*inf*inf;
using namespace std;
int a[]={-1,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main()
{
//	freopen("input.txt","r",stdin);
	int k;
	cin>>k;
	cout<<a[k]<<endl;
	return 0;
}

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

#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
//map<int, int>::iterator itr; 

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b,c,co=0;cin>>a>>b>>c;
    for(int i=a;i<=b;i++){
        if(i%c==0)
        co++;
    }
    cout<<co;
    return 0;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[5];
    int i;
    cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];

    for(i=0;i<5;i++)
    {
      if(a[i]==0)
      {
          cout<<i+1<<endl;
          break;
      }
    }



}


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


using namespace std;

int main(void){
	int n;

	cin >> n;

	int k = n, sum = 0;
	while (k > 0){
		sum += k % 10;
		k /= 10;
	}

	if (n % sum == 0)
		cout << "Yes" << endl;
	else 
		cout << "No" << 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++)

const int MAX = 100;

int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i <= n; i++){
        int cnt = 0;
        int j = i;
        while(j > 0){
            j /= 10;
            cnt++;
        }
        if(cnt % 2 == 1) ans++;
    }
    cout << ans << endl;
 }

Measured memory_bytes: 256
def main():
    nvertices, nedges = map(int, input().split())
    edges = [[0 for i in range(nvertices)] for j in range(nvertices)]
    for i in range(nedges):
        u, v, c = map(int, input().split())
        edges[u][v] = c

    INF = float('inf')
    ans = 0
    while True:
        parents = bfs(0, nvertices - 1, edges)
        if parents is None:
            break
        parent, child = parents[nvertices - 1], nvertices - 1
        f = INF
        while parent != -1:
            f = min(f, edges[parent][child])
            parent, child = parents[parent], parent

        ans += f
        parent, child = parents[nvertices - 1], nvertices - 1
        while parent != -1:
            edges[parent][child] -= f
            edges[child][parent] += f
            parent, child = parents[parent], parent

    print(ans)


def bfs(s, t, edges):
    visited = [False] * len(edges)
    que = [s]
    parents = [-1] * len(edges)
    while que:
        u = que.pop(0)
        visited[u] = True
        if u == t:
            return parents

        for v in range(len(edges)):
            if not visited[v] and edges[u][v] > 0:
                parents[v] = u
                que.append(v)

    return None


main()

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

int main()
{
  string s;
  cin >> s;
  cout << s.substr(0, 3) << endl;
  
  return 0;
}

Measured memory_bytes: 3628
//解説参考

#include<iostream>
using namespace std;

int main(){
	int c[3][3];
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>c[i][j];
		}
	}
	
	int a[3],b[3];
	a[0]=0;
	for(int i=0;i<3;i++) b[i]=c[0][i];
	a[1]=c[1][0]-b[0];
	a[2]=c[2][0]-b[0];
	
	int p=1;
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			if(c[i][j]!=a[i]+b[j]) p=0;
		}
	}
	
	cout<<((p)?"Yes":"No")<<endl;

	return 0;
}

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

int main(){
  int n, d[110];
  cin >> n;
  for( int i = 0; i < n; ++i ) cin >> d[i];

  int num[110]={};
  for( int i = 0; i < n; ++i ) {
    num[d[i]]++;
  }

  int res = 0;
  for( int i = 1; i <= 100; ++i ){
    if(num[i]) res++;
  }

  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    LL from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};
//頂点の定義
struct Vertex2D{
   long  double x;
   long double y;
};
//ベクトルの定義(頂点と同じ)
#define Vector2D Vertex2D

//単位ベクトル生成
Vector2D ceate_unit_vector( Vector2D v )
{
    long double len = pow( ( v.x * v.x ) + ( v.y * v.y ), 0.5 );//ベクトル長さ

    Vector2D ret;
    ret.x = 1.0000000000*v.x / len;
    ret.y = 1.0000000000*v.y / len;

    return ret;
}

//ベクトル内積
long double dot_product(Vector2D vl, Vector2D vr) {
    return 1.000000000*vl.x * vr.x + vl.y * vr.y;
}

//点Pと直線ABから線上最近点を求める
Vector2D NearPosOnLine(Vertex2D hoge, Vertex2D A, Vertex2D B )
{
    Vector2D AB,AP;//ベクトルAB AP

    AB.x = B.x - A.x;
    AB.y = B.y - A.y;
    AP.x = hoge.x - A.x;
    AP.y = hoge.y - A.y;

    //ABの単位ベクトルを計算
    Vector2D nAB = ceate_unit_vector(AB);

    //Aから線上最近点までの距離（ABベクトルの後ろにあるときはマイナス値）
    long double dist_AX = dot_product( nAB, AP );

    //線上最近点
    Vector2D ret;
    ret.x = A.x + (1.00000000 * nAB.x * dist_AX );
    ret.y = A.y + (1.00000000 *  nAB.y * dist_AX );

    return ret;
}
int main(){
    CIN(px);CIN(py);CIN(lx);CIN(ly);
    Vertex2D A,B;
    A.x = px;
    A.y = py;
    B.x = lx;
    B.y = ly;
    CIN(q);
    REP(a,q){
        CIN(hogex);CIN(hogey);
        Vertex2D hoge,ans;
        hoge.x = hogex;
        hoge.y = hogey;
        ans = NearPosOnLine(hoge,A,B);
        cout<<setprecision(20)<<ans.x<<" "<<ans.y<<endl;
    }
    return 0;
}



Measured memory_bytes: 3384
if __name__ == '__main__':

	s = input()
	n = int(input())

	rvcnt = 0

	tmp = "S"
	tmp_before = ""
	tmp_after = ""
	
	for _ in range(n):
		q = input()
		if len(q) == 1:
			rvcnt += 1
		else:
			i,f,c = map(str,q.split())
			if f == "1":#先頭に追加
				if rvcnt % 2 == 0:
					#先頭に追加
					tmp_before = c + tmp_before
				else:
					#末尾に追加
					tmp_after = tmp_after + c
			else:#末尾に追加
				if rvcnt % 2 == 0:
					#末尾に追加
					tmp_after = tmp_after + c
				else:
					#先頭に追加
					tmp_before = c + tmp_before


	#仮想を元に戻す
	tmp1 = tmp.replace("S",s)
	#連結
	tmp2 = tmp_before + tmp1 + tmp_after

	#最後に反転するかを決定
	if rvcnt % 2 == 1:
		print(tmp2[::-1])
	else:
		print(tmp2)


Measured memory_bytes: 10420
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

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

using namespace std;

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

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	int D, N;
	cin >> D >> N;
	long int ans = 0;
	if (N < 100) {
		ans = (int)pow(100, D)*N;
	}
	else {
		ans = (int)pow(100, D)*101;
	}
	cout << ans;
	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  maxn = 1e6 + 5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	ll res=0;
	for(int i=1;i<=n;i++){
		if(i%3!=0 && i%5!=0) res+=i;
	}
	cout<<res<<'\n';
	return 0;
}

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

using namespace std;

typedef double ld;

//ld dp[17][1 << 16] = {0}; // dp[next enemy][used cat]

int N, M;
ld P[16][16];

bool m1[16][1 << 16] = {0};
ld m2[16][1 << 16];

ld dp(int n, int rest) {
	if (n >= N) return (ld)1;

	if (m1[n][rest]) return m2[n][rest];

	ld ret = 0;
	for (int i = 0; i < M; ++i) {
		ld p = 0;
		if (rest & (1 << i)) {
			int nr = rest & ~(1 << i);

			ld per = 1;
			for (int j = n; j < N; ++j) {
				p += per * (1 - P[i][j]) * dp(j, nr);
				per *= P[i][j];
			}
			p += per;
		}
		ret = max(ret, p);
	}
	return m1[n][rest] = true, m2[n][rest] = ret;
}
int main() {
	cin >> M >> N;
	for (int i = 0; i < M; ++i) {
		for (int j = 0; j < N; ++j) {
			cin >> P[i][j];
		}
	}

	printf("%.12f\n", (double)dp(0, (1 << M)-1));
	return 0;
}

Measured memory_bytes: 10464
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main(){
	int n; cin>>n;
	vector<int>a(n);
	int A=0,B=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a.begin(),a.end(),greater<int>());
    for(int i=0;i<n;i++){
		if(i%2==0){
			A+=a[i];
		}
		else{
			B+=a[i];
		}
	}
	cout<<A-B<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
	
	int n; cin >> n;
	vector<int> a(n + 2, 0);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int sum = 0;
	for (int i = 1; i <= n + 1; i++) {
		sum +=abs(a[i] - a[i - 1]);
	}
	for (int i = 1; i <= n; i++) {
		int tmp = sum;
		tmp -= abs(a[i] - a[i - 1]);
		tmp -= abs(a[i + 1] - a[i]);
		tmp += abs(a[i + 1] - a[i - 1]);
		cout << tmp << endl;
	}
    return 0;
}

Measured memory_bytes: 3720
import Data.List
import qualified Data.Map as Map

scan :: Int -> Int -> Int
scan _ 1 = 1
scan 1 p = p
scan n p = Map.foldrWithKey f 1 (factors p) where
    f k a b = b * (k^(div a n))

factors :: Int -> Map.Map Int Int
factors = iter Map.empty divisors where
    iter m (p:ps) n
        | p*p <= n = case logP p n of
            Just (e, q) -> iter (Map.insert p e m) ps q
            Nothing     -> iter m ps n
        | otherwise = m

logP :: Int -> Int -> Maybe (Int, Int)
logP p n = if mod n p == 0 then iter 0 n else Nothing where
        iter e x = case divMod x p of
            (1, 0) -> Just (e+1, 1)
            (q, 0) -> iter (e+1) q
            (_, _) -> Just (e, x)                

divisors :: [Int]
divisors = 2:3:(g [5,11..] [7,13..]) where
    g (x:xs) (y:ys) = x:y:(g xs ys)

main :: IO() 
main = do
    line1 <- getLine
    let [stN, stP] = words line1
        n = read stN :: Int
        p = read stP :: Int
    let ans = scan n p
    print ans

Measured memory_bytes: 1148
#include <iostream>
#include <vector>
#include <cstdio>

using namespace std;

typedef pair<int, int> P;
typedef pair<P, P> Q;

int main() {

	int h, w;
	cin >> h >> w;

	vector< vector<int> > a(h, vector<int>(w));

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

	vector<Q> qq;

	int ans = 0;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] % 2 == 1) {
				if (j == w - 1) {
					if (i == h - 1) {

					}
					else {
						//printf("%d %d %d %d\n", i + 1, j + 1, i + 2, j + 1);
						qq.push_back(Q(P(i + 1, j + 1), P(i + 2, j + 1)));
						ans++;
						a[i][j]--;
						a[i + 1][j]++;
					}
				}
				else {
					//printf("%d %d %d %d\n", i + 1, j + 1, i + 1, j + 2);
					qq.push_back(Q(P(i + 1, j + 1), P(i + 1, j + 2)));
					ans++;
					a[i][j]--;
					a[i][j + 1]++;
				}
			}
		}
	}

	cout << ans << endl;

	for (int i = 0; i < ans; i++) {
		printf("%d %d %d %d\n", (qq[i].first).first, (qq[i].first).second, (qq[i].second).first, (qq[i].second).second);
	}
	/*
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << a[i][j] << ' ';
		}
		cout << endl;
	}
	*/
	return 0;
}

Measured memory_bytes: 5232
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int a,b;
  cin >> a >> b;
  int w=max(a,b),q=min(a,b);
  cout << w+max(w-1,q) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define tam 220000
#define offset 100000
#define se second
#define fi first
#define forr(i,p,n) for(int i=p;i<n;i++)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
typedef pair<int,int> ii;
using namespace std;
int val[tam],mapa[tam],otro[tam];
int main()
{
 //   freopen("out.txt","w",stdout);
    forr(i,0,tam)
    mapa[i]=otro[i]=0;
    int n;
    cin>>n;
    forr(i,0,n)
    {
        cin>>val[i];
        mapa[val[i]]++;
    }
    int x=n-1;
    while(abs(x)<n)
    {
        //cout<<x<<" ";
        otro[abs(x)]++;
        x-=2;
    }
    bool cond=0;
    ll tot=1;
    forr(i,0,n)
    {
        if (otro[val[i]]!=mapa[val[i]])
            cond=1;
        if (otro[val[i]]==2)
        {
            tot*=2;
            tot%=MOD;
            otro[val[i]]--;
            mapa[val[i]]--;
        }
    }
    if (cond)
        cout<<0<<endl;
    else
        cout<<tot<<endl;
    
}

Measured memory_bytes: 2304
// In the name of God

#include <bits/stdc++.h>

using namespace std;

char grid[1005][1005];
int t[1005][1005];

int ans, n, m;
vector<pair<int,int>> starts;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};

bool valid(int x, int y) {
	if(x < n && x >= 0 && y < m && y>= 0) return true;
	return false;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	for(int i=0; i<1005; i++) {
		for(int j=0; j<1005; j++) {
			t[i][j] = 1e7;
		}
	}
	int sx, sy;
	for(int i=0; i<n; i++) {
		for(int j=0; j<m; j++) {
			cin >> grid[i][j];
			if(grid[i][j] == '#') starts.push_back(make_pair(i, j));
		}
	}
	queue<pair<int,int>> q;
	for(auto &p : starts) {
		t[p.first][p.second] = 0;
		q.push(make_pair(p.first, p.second));
	}
	while(!q.empty()) {
		auto p = q.front();
		q.pop();
		for(int i=0; i<4; i++) {
			int ex = p.first + dx[i], ey = p.second + dy[i];
			if(!valid(ex, ey)) continue;
			if( t[ex][ey] > t[p.first][p.second] + 1 ) {
				t[ex][ey] = t[p.first][p.second] + 1;
				q.push(make_pair(ex, ey));
			}
		}
	}
	int ans = 0;
	for(int i=0; i<n; i++) {
		for(int j=0; j<m; j++) {
			ans = max(ans, t[i][j]);
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 21224
#include<bits/stdc++.h>
using namespace std;
 
typedef vector <int> vi;
typedef pair< int ,int > pii;
#define all(v) v.begin(),v.end()
#define PB push_back
#define T(val) while(val--)
#define FIN for(i=0;i<n;i++)
#define FIS for(i=0;i<s.length();i++)
#define AIN for(i=0;i<n;i++){cin>>a[i];}
#define F(i,k,n) for(i=k;i<n;i++)
#define FG(i,k,n,x) for(i=k;i<n;i+=x)
#define YES cout<<"YES\n"; 
#define NO cout<<"NO\n"; 
#define ll long long
#define MOD 1000000007
#define deb(x) cout << #x << "=" << x << endl;
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//sort(arr, arr+n, greater<int>()); For sorting in reverse order 
ll dp[105][100005],sum[105][100005]; 
// dp[x][y]
// dp[x][0]=1
// dp[1][0]=dp[1][1]=dp[1][2]=.....=dp[1][a[0]]=1;
// dp[x][y]=dp[x-1][y]+dp[x-1][y-1]+....dp[x-1][y-a[i]];
int solve(){
        int n;
        cin>>n;
        ll k,a[n];
        ll i,j;
        cin>>k;
        AIN
        ll x=0;
        for(i=1;i<=n;i++){
                for(j=0;j<=k;j++){
                        if(j==0){
                                dp[i][j]=1;
                                sum[i][j]=(dp[i][j]+MOD)%MOD;
                                continue;
                        }
                        if(i==1&&j<=a[0]){
                                dp[i][j]=1;
                                sum[i][j]=(sum[i][j-1]+dp[i][j]+MOD)%MOD;
                                continue;
                        }
                        if(i==1&&j>a[0]){
                                dp[i][j]=0;
                                sum[i][j]=(sum[i][j-1]+dp[i][j]+MOD)%MOD;
                                continue;
                        }
                        if(j>a[i-1]){
                                dp[i][j]=(sum[i-1][j]-sum[i-1][j-a[i-1]-1]+MOD)%MOD;
                                sum[i][j]=(sum[i][j-1]+dp[i][j]+MOD)%MOD;
                        }
                        else{
                                dp[i][j]=(sum[i-1][j]+MOD)%MOD;
                                sum[i][j]=(sum[i][j-1]+dp[i][j]+MOD)%MOD;                              
                        }
                }
        }
        /*
        for(i=1;i<=n;i++){
                for(j=0;j<=k;j++){
                cout<<dp[i][j]<<" ";
                }

                cout<<"\n";
        }*/
        cout<<dp[n][k]<<"\n";
  return 0;
}
int main(){
fast
        int t=1;
        // cin>>t; 
        T(t){
          solve();
        }
        return 0;
}

Measured memory_bytes: 159880
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)
k=A[0]
if N%2==0:
    for i in range(1,N//2):
        k+=2*A[i]
else:
    for i in range(1,(N-1)//2):
        k+=2*A[i]
    k+=A[i+1]
print(k)

Measured memory_bytes: 31400
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    N, M = map(int, input().split())
    AB = [[] for _ in range(10**5)]
    for i in range(N):
        a, b = map(int, input().split())
        AB[a-1].append(b)
    
    q = []
    ans = 0
    i = 0
    while i < M:
        for ab in AB[i]:
            heappush(q,-ab)
        if q:
            ans -= heappop(q)
        i += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 24560
n = int(input())
pow6s = [6, 36, 216, 1296, 7776, 46656]
pow9s = [9, 81, 729, 6561, 59049]
coins = sorted([1] + pow6s + pow9s)
dp = [n+1] * (n+1)
dp[0] = 0
dp[1] = 1
for i in range(len(coins)):
    c = coins[i]
    ndp = dp[:]
    for j in range(n+1):
        if j-c >= 0:
            ndp[j] = min(dp[j], ndp[j-c] + 1)
    dp = ndp
print(dp[-1])

Measured memory_bytes: 10856
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (A, B) = nextIntList()
    println(if (B % A == 0) A + B else B - A)
}

Measured memory_bytes: 36008
def resolve():
	m,d=map(int,input().split())
	cnt=0
	for i in range(1,m+1):
	    for j in range(10,d+1):
	        if (j//10)*(j%10)==i and j//10>1 and j%10>1:
	            cnt+=1
	print(cnt)
resolve()

Measured memory_bytes: 38768
function Main(input) {
  var count = 0;
  input = input[0];
  var s1 = input[0];
  if (s1 === '1') {
    count ++;
  }
  var s2 = input[1];
  if (s2 === '1') {
    count ++;
  }
  var s3 = input[2];
  if (s3 === '1') {
    count ++;
  }
  console.log(count);
}

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


Measured memory_bytes: 7372
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,k;
    cin>>k>>n;
    int *a=new int[n+1];
    for(int i=0;i<n;i++) cin>>a[i+1];
    int ans=k-a[n]+a[1]; //默认答案
    for(int i=0;i<n;i++){
        ans=max(ans,a[i+1]-a[i]);//寻找一个最大的区间,跨度越大，答案越小
    }
    cout<<k-ans<<endl;
    return 0;
}

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

using i64 = long long;
using u64 = unsigned long long;

#define dbg(x) cerr << "[" #x << " : " << x << "]\n"

const int mod = (int)1e9+7;

int main()
{
    int n;
    scanf("%d", &n);
    i64 a[400000];
    vector<int> cnt(65, 0);
    for(int i = 0; i < n; i++) {
        scanf("%lld", &a[i]);
        for(i64 j = 0; j < 62; j++) {
            cnt[j] += ((a[i] & (1LL << j)) > 0);
        }
    }
    vector<i64> powers(65, 0);
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < 62; j++) {
            if(a[i] & (1LL<<j)) {
                cnt[j]--;
                powers[j] += n-i-1-cnt[j];
            } else {
                powers[j] += cnt[j];
            }
        }
    }
    i64 ans = 0;
    for(int i = 0; i < 61; i++) {
        i64 tmp = powers[i];
        for(int j = 1; j <= i; j++) {
            tmp *= 2;
            tmp %= mod;
        }
        ans += tmp;
        ans %= mod;
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 6116
/* Isn't passion overrated?*/

#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
    ll a,b,n;
    cin>>a>>b>>n;
    cout<<(a*(min(b-1,n)))/b - a*(min(b-1,n)/b);
    return 0;
}


Measured memory_bytes: 3652
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  vector<vector<int64_t>> counts(10, vector<int64_t>(10, 0));

  for (int64_t i = 1; i <= N; ++i) {
    const int64_t lowest = i % 10;
    int64_t temp = i;
    while (temp >= 10) {
      temp /= 10;
    }
    const int64_t highest = temp;
    // cerr << i << ": " << min(lowest, highest) << ", " << max(lowest, highest) << endl;
    ++counts[lowest][highest];
  }
  int64_t result = 0;
  for (int64_t i = 1; i < 10; ++i) {
    for (int64_t j = 1; j < 10; ++j) {
      int64_t temp_count = counts[i][j] * counts[j][i];
      result += temp_count;
    }
  }
  cout << result << endl;
  return 0;
}


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

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;}

// 約数列挙関数
vector<ll> enum_divisors(ll n){

    vector<ll> res;
    for(ll i = 1; i*i <= n; i++){
        if(n%i==0){
            res.push_back(n/i);
            // 重複しない場合には加える
            // if(n/i != i) res.push_back(n/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int main(){

    ll n; cin >> n;
    ll res = enum_divisors(n)[0];
    ll ans = 0;
    while(res){
        ans++;
        res/=10;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256