akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<algorithm>
#define int long long
#define ll long long
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define bs binary_search
#define mp make_pair
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ld long double
#define meme(a,no)  memset(a,no,sizeof(a))
using namespace std; 

const int INF=1e9+7;

/*const int N=1000+5;

int x;

//const int mod=998244353;

//const int N=100000+9;

vector<vector<int>>v(N);

int vis[N]={0};

int level[N];*/

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

long long binpow_mod(ll a,ll b,ll c){
    ll res=1;
    while(b>0){
        if(b&1){
            res=res*a%c;
        }
        a=a*a%c;
        b>>=1;
    }
    return res;
}

/*void dfs(int a){
    vis[a]=1;
    for(auto x:v[a]){
        if(!vis[x]){
            sz++;
            dfs(x);
        }
    }
}*/

int32_t main(){
    ios
    int T;
    //cin>>T;
    T=1;
    while(T--){
        int n,k;
        cin>>n>>k;
        int h[n];
        int i,j,l;
        for(i=0;i<n;i++){
            cin>>h[i];
        }
        int dp[n];
        dp[0]=0;
        for(i=1;i<n;i++){
            dp[i]=INF;
        }
        for(i=1;i<=min(k,n-1);i++){
            for(j=i-1;j>=0;j--){
                dp[i]=min(dp[i],dp[j]+abs(h[j]-h[i]));
            }
        }
        for(i=min(k+1,n-1);i<n;i++){
            for(j=i-1;j>=max(i-k,0ll);j--){
                dp[i]=min(dp[i],dp[j]+abs(h[j]-h[i]));
            }
        }
        cout<<dp[n-1]<<endl;
    }
    
    
}

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

int main() {
    long n, m, ans;
    scanf("%ld%ld", &n, &m);
    long x[m], y[m-1];
    for (long i = 0; i < m; i++) {
        scanf("%ld", &x[i]);
    }
    sort(x, x+m);
    if (n >= m) {
        printf("0\n");
        return 0;
    }
    for (long i = 1; i < m; i++) {
        y[i-1] = x[i] - x[i-1];
    }
    sort(y, y+m-1);
    ans = accumulate(y, y+m-1-n+1, 0L);
    printf("%ld\n", ans);
}

Measured memory_bytes: 5332
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std; using ll=long long; const int m=1e9+7; using P=pair<int,int>;
const int mx = 2e5;

int main() {
  int n; cin>>n;
  int c[n]; for(int i=0;i<n;i++) cin>>c[i];
  for(int i=0;i<n;i++) c[i]--;
  int d[mx]; fill(d,d+mx,-1); // 前にあった色iの位置
  int e[n]; fill(e,e+n,-1); // 場所iにつながる前の場所
  for(int i=0;i<n;i++) {
    if (d[c[i]] != -1 && d[c[i]] != i-1) {
      e[i] = d[c[i]];
    }
    d[c[i]] = i;
  }
  int f[n]; f[0]=1;
  for(int i=1;i<n;i++) {
    if (e[i] == -1) f[i] = f[i-1];
    else f[i] = f[i-1] + f[e[i]];
    f[i]%=m;
  }
  cout<<f[n-1]<<endl;
}

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

long long k;
int diff[55][55],ans[55];

int main(){
  scanf("%lld",&k);
  for(int i=1;i<=50;i++){
    for(int j=1;j<=50;j++){
      if(j==i) diff[i][j]=diff[i-1][j]-50;
      else diff[i][j]=diff[i-1][j]+1;
    }
  }
  printf("50\n");
  long long a = k/50;
  int b = k-a*50;
  for(int i=1;i<=50;i++){
    printf("%lld ",50+a+diff[50-b][i]);
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;

int main() {
	#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
	#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	ll n; cin >> n;
	vl d(n); REP(i, n) cin >> d[i];

	sort(ALL(d));

	for (ll minmax_dist = 12; minmax_dist >= 0; --minmax_dist) {
		vector<vvb> dp(n + 1, vvb(13, vb(13, 0))); // dp[i][left][right]
		dp[0][0][0] = true;
		REP(i, n) REP(j, 13) REP(k, 13) {
			if (!dp[i][j][k]) continue;
			if (d[i] - j >= minmax_dist && 24 - d[i] - k >= minmax_dist) dp[i + 1][d[i]][k] = true;
			if (d[i] - k >= minmax_dist && 24 - d[i] - j >= minmax_dist) dp[i + 1][j][d[i]] = true;
		}
		REP(j, 13) REP(k, 13) {
			if (dp[n][j][k]) {
				cout << minmax_dist << endl;
				return 0;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

int main() {
    char c;
    while (cin >> c)
        cout << 'x';
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
x=[]
answer=0
for i in range(n):
    x.append(list(map(int,input().split())))
    del x[i][0]
for i in range(m):
    cnt=0
    for j in range(n):
        if i+1 in x[j]:
            cnt+=1
        else:
            break
    if cnt==n:
        answer+=1
print(answer)


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
	unsigned long long in;
	unsigned long long out = 0;
	cin >> in;
	for (unsigned long long i = 1; i <= in; i++) {
		if (i % 3 != 0 && i % 5 != 0)
			out += i;
	}
	cout << out << endl;


}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string ss;
	cin>>ss;
	if(ss=="MON") puts("6");
	if(ss=="TUE") puts("5");
	if(ss=="WED") puts("4");
	if(ss=="THU") puts("3");
	if(ss=="FRI") puts("2");
	if(ss=="SAT") puts("1");
	if(ss=="SUN") puts("7");
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];

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

		Arrays.sort(a);

		int score = a[N-1];
			for(int j = 0; j < N-1; j++) {
				score -= a[N-2-j] * Math.pow(-1, j);
			}
		System.out.println(score);
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define FOR(i, a, b) for(int i=(int)a; i<(int)b; i++)
#define ndl "\n";
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define inrep int t; cin >> t; for(int tc=1; tc<=t; tc++)
#define debug cout << "THIS - PART - HAS - BEEN - REACHED" << ndl;
inline int lcm(int a, int b) {return a/__gcd(a, b)*b;}
inline void out() {cout <<  ndl;}
template <class T> inline void in(T &a) {cin >> a;}
template <class T> inline void in(T &a, T &b) {cin >> a >> b;}
template <class T> inline void out(T a) {cout << a << ndl;}
template <class T> inline void out(T a, T b) {cout << (a) << " " << (b) << ndl;}
typedef long long LL;
typedef unsigned long long ULL;
const int N = 1e6+7;
const int LOGN = log(N) + 2;
const int MOD = 1e9+7;

int main()
{
	ios;
	string s; in(s);
	int arr[1000] = {0};
	FOR(i, 0, s.length()) {
		arr[s[i]] = 1;
	}
	FOR(i, 97, 123) {
		if (arr[i] == 0) {
			out(char(i));
			return 0;
		}
	}
	out("None");
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void){

  int n = 100;
  char s1[n];
  char s2[n];

  scanf("%s %s", s1, s2);

  int i, j, k;

  for (i = 0; i < n; i++) {
    if (s1[i] == '\0') {
      break;
    }
  } 
  for (j = 0; j < n; j++) {
    if (s2[j] == '\0') {
      break;
    }
  }

  if (i > j) {
    printf("%s\n", "GREATER");
  }
  else if (i < j){
    printf("%s\n", "LESS");
  }
  else if (i == j){
    for (k = 0; k < i; k++) {
      if (s1[k] > s2[k]) {
        printf("%s\n", "GREATER");
        break;
      }
      else if (s1[k] < s2[k]) {
        printf("%s\n", "LESS");
        break;
      }
    }
    if(k == i) {
      printf("%s\n", "EQUAL");
    }
  }

}


Measured memory_bytes: 128
import sys
readline = sys.stdin.readline
class Node:
    __slots__ = ['value', 'left', 'right']
    def __init__(self, value = None, left = None, right = None):
        self.value = value
        self.left = left
        self.right = right
class BinTree:
    __slots__ = ['_tree', 'result']
    def __init__(self):
        self._tree = None
    def insert(self, value):
        p = None
        c = self._tree
        while c is not None:
            p = c
            if value < c.value:
                c = c.left
            else:
                c = c.right
        if p is None:
            self._tree = Node(value)
        elif value < p.value:
            p.left = Node(value)
        else:
            p.right = Node(value)
    def find(self, value):
        c = self._tree
        while c is not None:
            if value == c.value:
                return True
            elif value < c.value:
                c = c.left
            else:
                c = c.right
        return False
    def delete(self, value):
        def node_move(p, c, a):
            if p.left == c:
                p.left = a
            else:
                p.right = a
        c = self._tree
        p = Node(None, c)
        while c.value != value:
            p = c
            if c is None:
                return
            if value < c.value:
                c = c.left
            else:
                c = c.right
        if c.left is None:
            node_move(p, c, c.right)
        elif c.right is None:
            node_move(p, c, c.left)
        elif c.right.left is None:
            c.right.left = c.left
            node_move(p, c, c.right)
        else:
            q = c.right
            while q.left.left is not None:
                q = q.left
            c.value = q.left.value
            q.left = q.left.right
        return
    def preoder_walk(self):
        self.result = []
        def preoder(node):
            if node is not None:
                self.result.append(node.value)
                preoder(node.left)
                preoder(node.right)
        preoder(self._tree)
        print(" " + " ".join(map(str, self.result)))
    def inorder_walk(self):
        self.result = []
        def inorder(node):
            if node is not None:
                inorder(node.left)
                self.result.append(node.value)
                inorder(node.right)
        inorder(self._tree)
        print(" " + " ".join(map(str, self.result)))
n = int(input())
tree = BinTree()
for _ in range(n):
    com = readline().split()
    if com[0] == "insert":
        tree.insert(int(com[1]))
    elif com[0] == "find":
        print("yes" if tree.find(int(com[1])) else "no")
    elif com[0] == "delete":
        tree.delete(int(com[1]))
    else:
        tree.inorder_walk()
        tree.preoder_walk()



Measured memory_bytes: 77184
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <random>

using namespace std;
constexpr int D = 365;
vector<int> c(26);
vector< vector<int> > s(D, vector<int>(26));
vector<int> num(D), ans(D);

int score() {
    int sat = 0;
    vector<int> last(26);
    for (int d=0; d<D; d++) {
        int j = num[d] - 1;
        last[j] = d + 1;
        for(int i=0; i<26; i++) {
            sat -= (d + 1 - last[i]) * c[i];
        }
        sat += s[d][j];
    }
        // assert(1 <= out[d] and out[d] <= 26)
        // j = out[d] - 1
        // last[j] = d + 1
        // for i in range(26):
        //     sat -= (d + 1 - last[i]) * c[i]
        // sat += s[d][j]
    return sat;
}

int main(void) {
    int g;
    cin >> g;
    for(int i=0; i<26; i++) {
        cin >> c[i];
    }
    for(int i=0; i<D; i++) {
        for(int j=0; j<26; j++) {
            cin >> s[i][j];
        }
    }

    int temp = numeric_limits<int>::min();
    random_device seed_gen;
    default_random_engine engine(seed_gen());
    uniform_int_distribution<> dist(1, 26);
    for(int a=0; a<100000; a++) {
        for(int i=0; i<D; i++) {
            num[i] = dist(engine);
        }
        if(int sat = score(); sat > temp) {
            ans = num;
            temp = sat;
        }
    }
    

    for(int i=0; i<D; i++) {
        cout << ans[i] << endl;
    }
    cerr << temp << endl;
    return 0;
}


Measured memory_bytes: 3688
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();

    int ans = 0;
    for (int i = 0; i < N; i++) {
      int x = sc.nextInt();
      ans += Math.min(2*x, 2*Math.abs(K-x));
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vpint> vvpint;
typedef vector<vpll> vvpll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<string>> vvstring;
typedef vector<vector<bool>> vvbool;

typedef vector<vector<vector<ll>>> vvvll;

const int c_YET = -1;
const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================





int main() {

	////==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	////==================================
	


	ll N;
	cin >> N;
	vll A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}


	ll ans = 1;
	ll odd = 1;

	for (int i = 0; i < N; i++)
	{
		if (A[i] == 0 || A[i] == 9)
		{
			ans *= 2;
			odd *= 1;
		}
		else
		{
			ans *= 3;
			
			if (A[i] % 2 == 0)
			{
				odd *= 2;
			}
			else
			{
				odd *= 1;
			}
		}

	}

	cout << ans - odd <<endl;



}





Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int main(){
    double x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    printf("%.8f\n",sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)));
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  int min = 0;
  for (int i = 0; i < N; i++) {
    int x;
    int count = 0;
    int two = 2;
    cin >> x;
    while (true) {
      if (x % two == 0) {
        count++;
        two *= 2;
      }
      else {
        break;
      }
    }
    if (i == 0 || min > count) {
      min = count;
    }
  }
  cout << min << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll __int64
//#define ll long long
int h,w,a,b;
char t[550][550];

int main(){
	cin>>a>>b;
	int aa=a;
	if(a==1&&b==1){
		cout<<"2 2"<<endl;
		cout<<".#"<<endl;
		cout<<"##"<<endl;
		return 0;
	}
	h=100;
	w=100;
	rep(i,h)rep(j,w)t[i][j]='.';

	int cnt=0;

	
	int ni=0;
	int li=1;
	a--;

	while(true){
		if(cnt>=a)break;
			
		for(int j=1;j<w-2;j+=2){
			t[ni][j]='#';
			cnt++;
			if(cnt>=a)break;
		}
		rep(j,w-1)t[li][j]='#';
		li+=2;
		ni+=2;
	}

	if(aa>1)b--;
	
	ni=h-1;
	cnt=0;
	while(true){
		if(cnt>=b)break;
		for(int j=1;j<w;j+=2){
			t[ni][j]='#';
			cnt++;
			if(cnt>=b)break;
		}
		ni-=2;
		if(cnt>=b)break;
	}
	
	cout<<h<<" "<<w<<endl;
	rep(i,h){
		rep(j,w)cout<<t[i][j];
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
class cmbs(object):
    def __init__(self, mod):
        self.mod = mod
        self.g1 = [1, 1]
        # g2[i] ha i no kaijo no gyakugen
        self.g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, 10 ** 6 + 1):
            self.g1.append((self.g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            self.g2.append((self.g2[-1] * inverse[-1]) % mod)
    def cmb(self, n, r):
        if n > 10 ** 6:
            return self.cmbl(n, r)
        return self.cmbr(n, r)
    def cmbr(self, n, r):
        if r < 0 or r > n:
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.mod
    def cmbl(self, n, r):
        t = 1
        r = min(r, n-r)
        mod = self.mod
        for i in range(n - r + 1, n + 1):
            t = t * i % mod
        return t * self.g2[r] % mod
def pown(n, m, mod):
    r = 1
    while n:
        if n & 1:
            r = r * m
            r %= mod
        m *= m
        m %= mod
        n >>= 1
    return r

def main():
    n, a, b = map(int, input().split())
    mod = 10 ** 9 + 7
    c = cmbs(mod)
    return (pown(n, 2, mod) - 1 - c.cmb(n, a) - c.cmb(n, b)) % mod
print(main())



Measured memory_bytes: 127560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int P[10] = {0,0,0,0,0,0,1,1,1,2} ;
int Q[10] = {1,1,1,2,2,3,2,2,3,3} ;
int R[10] = {2,3,4,3,4,4,3,4,4,4} ;
ll D[5] ;
ll m , r, a , c ,h ;
int main() {

  int N ;
  cin >> N ;
  rep(i,N){
    string S ;
    cin >> S ;
    if(S[0]=='M') m++ ;
    if(S[0]=='A') a++ ;
    if(S[0]=='R') r++ ;
    if(S[0]=='C') c++ ;
    if(S[0]=='H') h++ ;
  }
  D[0] = m ; D[1] = a ;D[2] = r; D[3] = c;D[4] = h ;
  ll ans = 0 ;
  rep(i,10) ans +=D[P[i]]*D[Q[i]]*D[R[i]] ;
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
if max(a) < N:
  print(0)
  exit(0)
ng = 0
ok = max(a) * N
def check(x):
  c = 0
  for i in range(N):
    c += max(-(-(a[i] + x - N + 1) // (N + 1)), 0)
  return x >= c

while ok - ng > 1:
  m = (ok + ng) // 2
  f = 1
  for i in range(N):
    if check(m + i):
      ok = m
      f = 0
      break
  if f: ng = m
for i in range(N):
  if check(ok + i):
    print(ok + i)
    break

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

using namespace std;

long long fun (long long a,long long b)
{
    if(a%b==0) return 2*a-b;
    long long c=(long)a/(long)b;
    return 2*c*b+fun(b,a%b);
};
int main()
{
	cout<<setprecision(3)<<fixed;
    long long a,b;
    cin>>a>>b;
    cout<<a+fun(max(a-b,b),min(a-b,b))<<endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    S = input()
    month_0 = True
    month_1 = True

    if S[:2] > '12' or S[:2] <'01':
        month_0 = False
    if (S[2:] > '12' or S[2:] < '01'):
        month_1 = False

    if month_0 ==False and month_1 == True:
        print('YYMM')
    elif month_0 == True and month_1 == False:
        print('MMYY')
    elif month_0 ==False and month_1 == False:
        print('NA')
    else:
        print('AMBIGUOUS')


if __name__ == '__main__' :
    main()

Measured memory_bytes: 3064
//知らない考え方だあ

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int IMAX = 1000000;

ll mod = 998244353;
ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}

ll fac[IMAX + 1], ifac[IMAX + 1], inv[IMAX + 1];

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


	int N;
	cin >> N;
	int A[200000];
	rep(i, N) cin >> A[i];

	fac[0] = 1;
	rep1(i, IMAX) fac[i] = fac[i - 1] * i % mod;
	ifac[IMAX] = modpow(fac[IMAX], mod - 2);
	for (int i = IMAX; i > 0; i--) ifac[i - 1] = ifac[i] * i % mod;
	inv[0] = 1;
	rep1(i, IMAX) inv[i] = ifac[i] * fac[i - 1] % mod;

	ll C[IMAX + 1];
	rep1(i, IMAX) C[i] = inv[i];
	rep1(i, IMAX) {
		for (int j = i + i; j <= IMAX; j += i) {
			C[j] = (C[j] - C[i] + mod) % mod;
		}
	}

	ll goukei[IMAX + 1] = {}, goukei2[IMAX + 1] = {};
	rep(i, N) {
		int sq = sqrt(A[i]);
		rep1(j, sq) {
			if (A[i] % j == 0) {
				if (j * j != A[i]) {
					goukei[A[i] / j] += A[i];
					goukei2[A[i] / j] += (ll)A[i] * A[i] % mod;
				}
				goukei[j] += A[i];
				goukei2[j] += (ll)A[i] * A[i] % mod;
			}
		}
	}

	ll kotae = 0;
	rep1(i, IMAX) {
		ll kei = goukei[i] % mod;
		ll kari = (kei * kei - goukei2[i]) % mod;
		kari = (kari + mod) * inv[2] % mod;

		kotae = (kotae + kari * C[i]) % mod;
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 47872
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N,K;
  int z=-1;
  cin>>N>>K;
  int x[N];
  REP(i,N){
    cin>>x[i];
    if(x[i]<0)z=i;
    if(x[i]==0){
      K--;
      i--;
      N--;
    }
  }
  z++;
  int ans=1000000000;
  if(K==0)ans=0;
  if(z-K>=0)ans=min(ans,-x[z-K]);
  if(z+K-1<N)ans=min(ans,x[z+K-1]);
  FOR(i,1,K){
    if(z-i<0 or z+K-i-1>=N)continue;
    int a=-2*x[z-i]+x[z+K-i-1];
    // cout<<x[z-i]<<x[z+K-i-1]<<endl;
    ans=min(ans,a);
  }
  FOR(i,1,K){
    if(z-K+i<0 or z+i-1>=N)continue;
    int a=-x[z-K+i]+2*x[z+i-1];
    // cout<<x[z-K+i]<<x[z+i-1]<<endl;
    ans=min(ans,a);
  }


  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long

int main(int argc, char const *argv[])
{
	int k,s;
	int cnt = 0,z;
	scanf("%d%d",&k,&s);
	for (int x = 0; x <= k ; ++x)
	{
		for (int y = 0; y <= k; ++y){
			z = s - x - y;
			if(0 <= z && z <= k)	++cnt;
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,N;
int main()
{
    n=read();
    if(n<=2) return 0*puts("No");
    for(N=1;N<=n+1;N<<=1);N>>=1;
    if(N==n) return 0*puts("No");puts("Yes");--N;
    for(int i=1;i<N;++i) printf("%d %d\n",i,i+1),printf("%d %d\n",i+n,i+n+1);
    printf("%d %d\n",N,n+1);
    if((n-N)%2==0)
    {
        for(int i=1;i<=n-N;i+=2)
            printf("%d 1\n%d 1\n",N+i,N+i+1),
            printf("%d %d\n%d %d\n",N+i+n,N+i+1,N+i+1+n,N+i);
        return 0;
    }
    else
    {
        for(int i=1;i<=n-N;i+=2+(i==1))
            printf("%d %d\n%d %d\n",N+i,(i-1)^i,N+i+1,(i-1)^i),
            printf("%d %d\n%d %d\n",N+i+n,N+i+1,N+i+1+n,N+i);
        printf("%d 2\n%d %d\n",N+3,N+2,N+3+n);
    }
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
#define lb lower_bound
#define ub upper_bound
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);ios::sync_with_stdio(false);



signed main(){
    ll n,ans=0;cin>>n;
    rep(i,n){
        ll x;cin>>x;
        ans=max(ans,x%2);
    }

    if(ans){
        cout<<"first"<<endl;
    }else{
        cout<<"second"<<endl;
    }
    
}

Measured memory_bytes: 256
/* 
    Author - linpaws07 
*/
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define inf (int)1e9
#define f first
#define s second
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define scd(t) scanf("%d",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define memst(a, b) memset(a, (b), sizeof(a))
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int,int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define rp(i,n) for(int i=0;i<(n);i++)
#define fr(i,a,b) for(int i=(a);i<(b);i++)
#define fre(i,a,b) for(int i=(a);i<=(b);i++)
#define frd(i,a,b) for(int i=(a);i>=(b);i--)
inline bool eq(double a, double b) { return fabs(a-b) < 1e-9; }
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
auto start = high_resolution_clock::now();
inline void measure();

int a[100002], b[100002], c[100002], dp[100002][3];
int main(){
    FAST
    //Do awesome things here
    int n;
    cin >> n;
    rp(i, n){
        cin >> a[i] >> b[i] >> c[i];
    }
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    fr(i, 1, n){
        rp(j, 3){
            if(j == 0){
                dp[i][j] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
            }
            else if(j == 1){
                dp[i][j] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
            }
            else{
                dp[i][j] = max(dp[i - 1][1], dp[i - 1][0]) + c[i];
            }   
        }
    }
    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
    return 0;
}


inline void measure(){
    auto stop = high_resolution_clock::now(); 
    auto duration = duration_cast<milliseconds>(stop - start);
    cout << duration.count() << endl;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextLine()) {
			String s = sc.nextLine();
			for(int i=0;i<26;i++) {
				String dec = caesarEncrypt(s, i);
				String[] spl = dec.split(" ");
				boolean flag = false;
				for(String t:spl) {
					if(t.equals("the") || t.equals("this") || t.equals("that")) {
						flag = true;
						break;
					}
				}
				if (flag) {
					System.out.println(dec);
					break;
				}
			}
		}
	}

	public static String caesarEncrypt(String s,int x) {
		char[] c = s.toCharArray();
		for(int i=0;i<c.length;i++) {
			if ('a' <= c[i] && c[i] <= 'z') {
				c[i] = (char) ((c[i] - 'a' + x) % 26 + 'a');
			}
		}
		return String.valueOf(c);
	}
}

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

using namespace std;

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

  vector<int>dp(W*2, -1);
  dp[0] = 0;
  int ans = 0;
  for(int i=0;i<n;i++){
    for(int j=W;j>=0;j--){
      if(dp[j] >= 0){
         dp[j+w[i]] = max(dp[j+w[i]], dp[j]+v[i]);
         if(j+w[i]<=W)ans = max(ans, dp[j+w[i]]);
      }
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3172
S = input()

cnt1 = 0
cnt2 = 0
for i in range(len(S)):
    if i%2:
        if S[i] != "1":
            cnt1 += 1
        if S[i] != "0":
            cnt2 += 1
    else:
        if S[i] != "0":
            cnt1 += 1
        if S[i] != "1":
            cnt2 += 1
            
ans = min(cnt1, cnt2)
print(ans)

Measured memory_bytes: 9148
k=int(input())
t=0
s=1000000000
a=0
for i in range(1000000):
    if i==0:
        a1=7%k
    else:
        a1=(a1*10)%k
    a+=a1
    a=a%k
    if a==0:
        s=i
        break
if s==1000000000:
    print(-1)
else:
    print(s+1)

Measured memory_bytes: 63344
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mode_Value
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> n = new List<int>();
            while (true)
            {
                string input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) break;
                n.Add(int.Parse(input));
            }

            n.Sort();
            List<int> cnt = new List<int>();
            List<int> idx = new List<int>();
            for (int i = 0; i < n.Count; ++i)
            {
                int count = 0;
                for (int j = i+1; j < n.Count; ++j)
                {
                    if (n[i] == n[j])
                    {
                        ++count;
                    }
                    else break;
                }
                cnt.Add(count);
                idx.Add(i);
            }
            List<int> ansIdx = new List<int>();
            for (int i = 0; i < cnt.Count; ++i)
            {
                if (cnt[i] == cnt.Max())
                {
                    ansIdx.Add(i);
                }

            }
            foreach (int item in ansIdx)
            {
                Console.WriteLine(n[item]);
            }

        }
    }
}



Measured memory_bytes: 18260
#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 k;
  string s;
  cin >> k >> s;
  if(s.length() <= k){
    cout << s << endl;
    return 0;
  }
  rep(i,k){
    cout << s[i];
  }
  cout << "..." << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <stdlib.h>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(int argc,char** argv){
  int n,W;
  cin >> n >> W;
  int w[n],v[n];
  for(int i = 0; i<n; i++){
    cin >> w[i] >> v[i];
  }
  long long dp[n+1][W+1];
  for(int i = 0; i <= W; i++){
    dp[0][i] = 0;
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j <= W; j++){
      if(j >= w[i]){
        dp[i+1][j] = max(dp[i][j-w[i]] + v[i], dp[i][j]);
      }else{
        dp[i+1][j] = dp[i][j];
      }
    }
  }
  cout << dp[n][W] << endl;
  return 0;
}


Measured memory_bytes: 79104
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Math;

class program
{
    static public int mod = 1000000007;
    static void Main()
    {
        double r = double.Parse(ReadLine()); ;
        Write(PI * r * 2);
    }

    static int pow(int a, int b) { string binary = Convert.ToString(b, 2); int bileng = binary.Length; long a_power = a; long value = 1; for (int i = bileng - 1; i >= 0; i--) { if (binary[i] == '1') { value = value * a_power % mod; } a_power = a_power * a_power % mod; } return (int)value; }
    static string rstr() { return ReadLine(); }
    static int rint() { return int.Parse(ReadLine()); }
    static long rlong() { return long.Parse(ReadLine()); }
    static string[] stra() { return ReadLine().Split(' '); }
    static char[] chara() { string[] a = stra(); string b = ""; for (int i = 0; i < a.Length; i++) { b += a[i]; } return b.ToCharArray(); }
    static int[] inta() { string[] read_str_array = ReadLine().Split(' '); int[] return_int_array = new int[read_str_array.Length]; for (int countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_int_array[countup_i] = int.Parse(read_str_array[countup_i]); } return return_int_array; }
    static long[] longa() { string[] read_str_array = ReadLine().Split(' '); long[] return_long_array = new long[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_long_array[countup_i] = long.Parse(read_str_array[countup_i]); } return return_long_array; }
    static double[] doublea() { string[] read_str_array = ReadLine().Split(' '); double[] return_double_array = new double[read_str_array.Length]; for (long countup_i = 0; countup_i < read_str_array.Length; countup_i++) { return_double_array[countup_i] = double.Parse(read_str_array[countup_i]); } return return_double_array; }
    static long GCD(long a, long b) { if (a < b) { long temp = a; a = b; b = temp; } if (a % b == 0) { return b; } else { long temp = b; b = a % b; a = temp; return GCD(a, b); } }
    static long LCM(long a, long b) { return a * b / GCD(a, b); }
    static void WriteArray2(int[,] a, int b, int c) { for (int i = 0; i < b; i++) { for (int j = 0; j < c; j++) { if (j != 0) Write(" "); Write(a[i, j]); } WriteLine(); } }
    static void WriteArray(int[] a, int b) { for (int i = 0; i < b; i++) { Write(" "); Write(a[i]); } WriteLine(); }
}


Measured memory_bytes: 27620
#include <bits/stdc++.h>
#include<stdlib.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
#define pr pair<ll, ll>
#define prf pair<ld,ld>
#define vct vector<ll>
#define vpt vector<pr>
#define vcf vector<ld>
#define vpf vector<prf>
#define st set<ll>
#define pq priority_queue<ll>
#define mat vector<vector<ll> >
#define all(x) x.begin(),x.end()
#define F(i, n) for(i = 0; i < (1LL*n); i++)
#define Fr(i, n) for(i = n - 1; i >= 0; i--)
 
struct custom_hash{
    static uint64_t splitmix64(uint64_t x){
        x += 0x9e3779b97f4a7c15;x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const{
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umap unordered_map<long long, long long, custom_hash>
 
void prv(vct v){for (ll i=0;i<v.size();i++)cout<<v[i]<<" ";cout << "\n";}
void prn(ll n){cout<<n<<"\n";}
void prs(string n){cout<<n<<"\n";}
void deb(string s, ll n){cout<<s<<" : "<<n<<"\n";}
void prmt(mat m){for(ll i=0;i<(1LL*m.size());i++)prv(m[i]);}
 
mat getRzMat(ll m,ll n, ll ini=0){mat mt;mt.assign(m,vector<ll>(n,ini));return mt;}
 
ll poww(ll x, ll y, ll m){
    ll res = 1;
    while (y){
        if (y%2 == 0){x = (x * x) % m;y = y / 2;}
        else{res = (res * x) % m;y--;}
    }
    return res;
}
 
vct divsors(ll n){
    vct ans;//ans.push_back(1);
    for(ll i=1;i<=sqrt(n);i++){if(n%i==0){ans.push_back(i);if(i!=(n/i))ans.push_back(n/i);}}
    sort(ans.begin(),ans.end());
    return ans;
}
vct sieve(ll n){
    vct ans(n+1,-1);
    for(ll i=2;i<=n;i++){
        if(ans[i]==-1){
            for(ll j=i;j<=n;j+=i)if(ans[j]==-1)ans[j]=i;
        }
    }
    return ans;
}
mat mt;
ll n, k, m, l, r, x, y, z;//ll ans=0;
ll t, t1, t2;
ll q;
ll i, j;
ll a, b, c, d, w;
ll mod = 1000000007;
ld epi = 0.00000001;
ll cas=0;

void solve(){
    cin>>a>>b>>t;
    prn((t/a)*b);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    // cout<<fixed<<setprecision(10);
    // freopen("input.txt", "r", stdin); 
    // freopen("output.txt", "w", stdout);
    ll t = 1;
    // cin >> t;
    cas=1;
    while (t--){
        solve();
        cas++;
    }
    return 0;
}
 

Measured memory_bytes: 3680
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
int main(){
    string s;cin>>s;
    pii hoge;
    rep(i,(int)s.size()){if(s[i]=='A'){hoge.first=i+1;break;}};
    for(int i=(int)s.size()-1;i>=0;i--){if(s[i]=='Z'){hoge.second=i+1;break;}}
    cout<<hoge.second-hoge.first+1<<endl;
}

Measured memory_bytes: 832
n = gets.chomp.to_i
w = gets.chomp.split.map(&:to_i)
ans = 10000000000000
(n-1).times do |i|
  v = (w[0..i].inject(:+) - w[i+1..n-1].inject(:+)).abs
  ans = v if v < ans
end
puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
#define rep(n) for(int i=0;i<n;i++)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define max(a,b) (a>b)? a:b
#define min(a,b) (a<b)? a:b

#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(0)
const int mod=1e9+7;
int gcd(int a,int b)
{
    if(b==0)
    return a;
    else
    return gcd(b,a%b);
}

int main()
{
   int hash[26];memset(hash,0,sizeof(hash));
   string s;cin>>s;
   rep(s.size())
   hash[s[i]-'a']++;
rep(26)
{
    if(hash[i]%2)
    {cout<<"No";
    return 0;
    }
}
cout<<"Yes"<<endl;
}


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

struct StAnsHis
{
  StAnsHis() : m_nProblmNo(0), m_nJudge("") { }

  int    m_nProblmNo;
  string m_nJudge;
};

void fnInput(int& rnProblmSiz, vector<StAnsHis>& rvoAnsHis)
{
  int nSubmitSiz;
  cin >> rnProblmSiz >> nSubmitSiz;
  rvoAnsHis.resize(nSubmitSiz);

  for(StAnsHis& roAnsHis : rvoAnsHis)
    cin >> roAnsHis.m_nProblmNo >> roAnsHis.m_nJudge;
}
  
void fnAnserCheck(int nProblmSiz, const vector<StAnsHis>& cnrvoAnsHis, 
                 int& rnRightAns, int& rnPenalty)
{
  vector<int> vnWACnt(nProblmSiz + 1);
  set<int> stRightAns;

  rnRightAns = 0;
  rnPenalty = 0;

  for (StAnsHis oAnsHis : cnrvoAnsHis)
  {
    if (oAnsHis.m_nJudge == "AC")
      stRightAns.insert( oAnsHis.m_nProblmNo );
    else
      if (!stRightAns.count( oAnsHis.m_nProblmNo ))
        vnWACnt[ oAnsHis.m_nProblmNo ]++;
  }

  rnRightAns = stRightAns.size();

  for (int nRightAns : stRightAns)
    rnPenalty += vnWACnt[nRightAns]; 
}
  
int main()
{
  int nProblmSiz;
  vector<StAnsHis> voAnsHis;
  fnInput(nProblmSiz, voAnsHis);

  int nRightAns, nPenalty;
  fnAnserCheck(nProblmSiz, voAnsHis, nRightAns, nPenalty);

  cout << nRightAns << " " << nPenalty;
  return 0;
}

Measured memory_bytes: 11520
def main():
    k, n = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    a_ = [k - a[-1] + a[0]] + [a[i] - a[i - 1] for i in range(1, n)]

    print(k - max(a_))


if __name__ == "__main__":
    main()


Measured memory_bytes: 26444
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
#define INF 500050
typedef long long ll;
using namespace std;
int arr[INF],brr[INF];
struct node
{
	int x;
    friend bool operator< (node n1, node n2)
    {
        return n1.x < n2.x;
    }
    
};
priority_queue <node> q;
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=1; i<=n; i++) {
		node x;
		cin >> x.x;
		q.push(x);
	}
	while(m) 
	{
		m--;
		node f = q.top();
		q.pop();
		node x;
		x.x = f.x / 2;
		q.push(x);
	}
	ll sum = 0;
	while(!q.empty()) 
	{
		node f = q.top();
		q.pop();
		sum += f.x;
	}
	cout<<sum<<endl;
	
	return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef unsigned long long ULL;
 
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)a.size()
#define f first
#define s second
#define FILL(a, b) memset(a, b, sizeof(a))
 
const int MAX = 400*1000+5;
const int INF = 1000*1000*1000 + 7;
const LL LINF = 1LL*INF*INF;
const int MOD = INF;
const double PI = acos(-1.);
const int MAXN = 100007;
const double EPS = 1e-6;
 
mt19937 rnd(time(0));


int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	vector<VI> a(n, VI(n));
	FOR(i, 0, n)
	{
		FOR(j, 0, n)
		{
			cin >> a[i][j];
		}
	}

	vector<VI> was(n, VI(n));
	LL ans = 0;
	FOR(k, 0, n)
	{
		FOR(i, 0, n)
		{
			FOR(j, 0, n)
			{
				if (a[i][j] > a[i][k] + a[k][j])
				{
					return cout << -1 << "\n", 0;
				}
				if (i == k || k == j)	
				{
					continue;
				}
				if (a[i][j] == a[i][k] + a[k][j])
				{
					was[i][j] = 1;
				}
			}
		}
	}
	FOR(i, 0, n)
	{
		FOR(j, i, n)
		{
			if (!was[i][j])
			{
				ans += a[i][j];
			}
		}
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1024
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log10
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

K = INT()

def S(n): # 和,nは文字列
	return sum([int(x) for x in list(n)])

def f(N):
	sunuke = []
	for d in range(-1, int(log10(N)+1)):
		sunuke.append(10**(d+1) * (N//(10**(d+1))+1)-1)
	sunuke2 = [x/S(str(x)) for x in sunuke]
	return sunuke[sunuke2.index(min(sunuke2))]

N = 1
for _ in range(K):
	print(N)
	N = f(N+1)


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

//#define debug
using namespace std;
int n, m, a, b;
const int mod = (int)1e9 + 7;

int main() {
#ifdef debug
	freopen("1.in", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	while (cin >> n) {
		using pii = pair<int, int>;
		unordered_map<int, int> odd, even;
		vector<pii> o, e;
		for (int i = 0; i < n; i++) {
			cin >> a;
			(i & 1) ? ++odd[a] : ++even[a];
		}	
		for (auto& p: odd) o.emplace_back(p.second, p.first);
		for (auto& p: even) e.emplace_back(p.second, p.first);
		sort(o.rbegin(), o.rend());
		sort(e.rbegin(), e.rend());
		int res = 100000000;
		if (o[0].second != e[0].second) {
			res = n - o[0].first - e[0].first;
		} else {
			res = min(n - o[0].first, n - e[0].first);
			if (1 < o.size()) res = min(res, n - o[1].first - e[0].first);
			if (1 < e.size()) res = min(res, n - o[0].first - e[1].first);
		}
		cout << res << endl;
	}
	return 0;
}


Measured memory_bytes: 5524
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1000000000000 ;
const ll mod=1000003 ;

ll sum[100010];

int main(){
  int n;
  cin >> n;
  int l=0;
  rep(i,3*n){
    if(i*i+i==2*n){
      cout << "Yes" << endl;
      l=i;
      break;
    }
    if(i==3*n-1){
      cout << "No" << endl;
      return 0;
    }
  }
  vector<int> v[l+1];
  int x[l+1]={};
  x[l]=1,x[l-1]=1;
  int cnt=1;
  do{
    rep(j,l+1){
      if(x[j]>0){
        v[j].push_back(cnt);
      }
    }
    cnt++;
  }while(next_permutation(x,x+l+1));
  /*
  rep(i,l+1){
    rep(j,v[i].size()){
      cout << v[i][j] << ' ';
    }
    cout << endl;
  }
  */
  cout << l+1 << endl;
  rep(i,l+1){
    cout << v[i].size() << ' ';
    rep(j,v[i].size()){
      cout << v[i][j] << ' ';
    }
    cout << endl;
  }
return 0;}

Measured memory_bytes: 2304
import java.util.* ;

public class Main {
	
	public static void main( String[] args ) {
		
		Scanner sc			= new Scanner( System.in ) ;
		int		N			= sc.nextInt();
		int		field[][]	= new int[2][N];
		
		for( int i = 0; i < 2; i++ ) {
			for( int j = 0; j < N; j++ ) {
				field[i][j] = sc.nextInt();
			}
		}
		
		field[1][0] += field[0][0] ;
		
		for( int j = 1; j < N; j++ ) {
			field[0][j] += field[0][j-1] ;
			field[1][j] += field[0][j] < field[1][j-1] ? field[1][j-1] : field[0][j] ;
		}
		
		System.out.println( field[1][N-1] ) ;
	}
}


Measured memory_bytes: 23892
#!/usr/bin/env python

while True:
	n, s = map(int, raw_input().split())
	if not n:
		break
	ans = 0
	for i in range(2**10):
		cnt = 0
		ss = 0
		for j in range(10):
			if i & (2 ** j):
				cnt += 1
				ss += j
		if cnt == n and ss == s:
			ans += 1
	print(ans)


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

struct KnuthMorrisPratt {
    string ptn;
    vector<int> mp;
    KnuthMorrisPratt(const string &ptn) : ptn(ptn) {
        int m = ptn.size();
        mp.assign(m + 1, -1);
        for (int i = 0, j = -1; i < m; i++) {
            while (j >= 0 && ptn[i] != ptn[j]) j = mp[j];
            mp[i + 1] = ++j;
        }
    }
    int period(int i) { return i - mp[i]; }
    vector<int> match(const string &s) {
        int m = ptn.size(), n = s.size();
        vector<int> res;
        for (int i = 0, k = 0; i < n; i++) {
            while (k >= 0 && s[i] != ptn[k]) k = mp[k];
            if (++k == m) res.emplace_back(i - m + 1);
        }
        return res;
    }
};

vector<long long> enum_divisors(long long n) {
    vector<long long> res;
    for (long long i = 1LL; i * i <= n; i++) {
        if (n % i != 0) continue;
        res.emplace_back(i);
        if (i != n / i) res.emplace_back(n / i);
    }
    sort(res.begin(), res.end());
    return res;
}

int main() {
    string s; cin >> s;
    int n = s.length();
    KnuthMorrisPratt kmp(s);
    if (s == string(n, s[0])) return !(cout << n << endl << 1 << endl);
    if (kmp.period(n) == n || n % kmp.period(n) != 0) {
        return !(cout << 1 << endl << 1 << endl);
    }
    string s_r = s;
    reverse(begin(s_r), end(s_r));
    KnuthMorrisPratt kmp_r(s_r);
    int cnt = 0;
    for (int i = 1; i < n; i++) {
        if (kmp.period(i) < i && i % kmp.period(i) == 0) continue;
        int j = n - i;
        if (kmp_r.period(j) < j && j % kmp_r.period(j) == 0) continue;
        cnt++;
    }
    cout << 2 << endl << cnt << endl;
    return 0;
}


Measured memory_bytes: 6168
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=200050;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	vint L;
	for(int i=0;i<2*N;i++){
		int c;
		cin>>c;
		L.pb(c);
	}
	sort(L.begin(),L.end());
	int ans=0;
	for(int i=0;i<2*N;i++){
		if(i%2==0)
			ans+=L[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256