akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <list>
#include <array>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <random>
#include <chrono>
#include <fstream>

#define PI 3.14159265359
#define mt make_tuple
#define mp make_pair
#define pii pair <int, int>
#define pll pair <long long, long long>
#define all(x) (x).begin(), (x).end()

//mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());

using namespace std;

const int MOD = 1000000007;

int main()
{
	int S;
	cin >> S;
	vector <long long> dp(S + 10, 0);
	vector <long long> sum(S + 10, 0);
	sum[0] = sum[1] = sum[2] = 1;
	for (int i = 3; i <= S; ++i)
	{
		dp[i] = sum[i - 3];
		sum[i] = (1LL * sum[i - 1] + dp[i]) % MOD;
	}
	cout << dp[S] << "\n";
	return 0;
}



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

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

    for(int i=0; i<n; i++){
        cin >> len[i];
    }
    sort(len.begin(), len.end());

    int sum = 0;

    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            int a = len[i] + len[j];
            auto itr = lower_bound(len.begin(),len.end(),a);
            int tmp = itr - len.begin() - 1 - j;
            if(tmp > 0){
                sum += tmp;
            }
        }
    }

    cout << sum << endl;

}

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

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+1 >= c){
        cout << (b+c) << endl;
    }else{
        int c_eatable = a+b+1;
        cout << (b+c_eatable) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
#define MAX  1000
#define WIMAX 10000
 
int n, a[MAX], s;
int b[MAX], T[WIMAX + 1];
 
 
int partition(int a[], int p, int r){
  int i, j;
  int t, x;
  x = a[r];
  i = p - 1;
 
  for(j = p ; j < r ; j++){
    if(a[j] <= x){
      i++;
      t = a[i];
      a[i] = a[j];
      a[j] = t;
    }
  }
 
  t = a[i + 1];
  a[i + 1] = a[r];
  a[r] = t;
 
  return i + 1;
}
void quickSort(int a[], int p, int r){
  int q;
  if(p < r){
    q = partition(a, p, r);
    quickSort(a, p, q - 1);
    quickSort(a, q + 1, r);
  }
}

    
int solve(){
  int i, cur, S, m, an, v,   ans = 0 ;
 
  int V[MAX];
  for(i = 0 ; i < n ; i++){
    b[i] = a[i];
    V[i] = 0;
  }
 
  quickSort(b, 0, n - 1);
 
  for(i = 0 ; i < n ; i++) T[b[i]] = i;
  for(i = 0 ; i < n ; i++){
    if(V[i]) continue;
    cur = i;
    S = 0;
    m = WIMAX;
    an = 0;
    while(1){
      V[cur] = 1;
      an++;
      v = a[cur];
 
      if(v < m) m = v;
 
      S += v;
      cur = T[v];
      if(V[cur]) break;
    }
    if(S + (an -2) * m < m + S + (an + 1) * s) ans += S + (an -2) * m;
    else ans +=  m + S + (an + 1) * s;
  }
  return ans;
}
 
        
    
int main(){
  int i;
 
  scanf("%d", &n);
  s = WIMAX;
  for(i = 0 ; i < n ; i++){
    scanf("%d", &a[i]);
    if(a[i] < s) s = a[i];
}
 
  int ans = solve();
  printf("%d\n", ans);
 
  return 0;
}










Measured memory_bytes: 2112
/*
  AOJ 1116
  Title:
  @kankichi573
*/
#include <stdio.h>
#include <string.h>

int N;
char piece[9][5];
char ban[3][3][5]; // N,E,S,W
char use[9];


void show()
{
  int i,j;

  for(i=0;i<3;i++)
    {
      for(j=0;j<3;j++)
	printf("-%c-|",ban[i][j][0]);
      printf("\n");
      for(j=0;j<3;j++)
	printf("%c-%c|",ban[i][j][3],ban[i][j][1]);
      printf("\n");
      for(j=0;j<3;j++)
	printf("-%c-|",ban[i][j][2]);
      printf("\n");
      printf("---+---+---+\n");
    }
}
int match(char c1,char c2)
{
  if((islower(c1) && isupper(c2) && toupper(c1)==c2) ||
     (islower(c2) && isupper(c1) && toupper(c2)==c1))
    return(1);
  else
    return(0);
}

solve(int y,int x,char use[])
{
  int i,j,k,ret,xn,yn;
  char use2[9];

  //printf("y=%d x=%d\n",y,x);

  ret=0;
  for(i=0;i<9;i++)
    {
      if(use[i])
	continue;
      for(j=0;j<4;j++)
	if(((x == 0) ||match(piece[i][(j+3)%4],ban[y][x-1][1])) &&
	   ((y == 0) ||match(piece[i][j]      ,ban[y-1][x][2])))
	  {
	    for(k=0;k<4;k++)
	      ban[y][x][k]=piece[i][(j+k)%4];

	    if(x==2 && y==2)
	      {
		//show();
		ret++;
	      }
	    xn=x+1,yn=y;
	    if(xn>2)
	      xn=0,yn=y+1;
	    memcpy(use2,use,sizeof(use2));
	    use2[i]=1;
	    ret += solve(yn,xn,use2);
	  }
    }
  return(ret);
}



main()
{
  int i,j,k,ret;
  
  scanf("%d",&N);
  for(i=0;i<N;i++)
    {
      for(j=0;j<9;j++)
	scanf("%s",&piece[j][0]);

      memset(use,0,sizeof(use));
      memset(ban,' ',sizeof(ban));
      ret=solve(0,0,use);
      printf("%d\n",ret);
    }
  return(0);
}

Measured memory_bytes: 596
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Main main = new Main();
		main.solveA();
	}

	private void solveA() {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long A = sc.nextLong();
		long B = sc.nextLong();
		long min = A * (N - 1) + B;
		long max = B * (N - 1) + A;
		if (A > B || (N == 1 && A != B)) {
			System.out.println(0);
		} else {
			System.out.println(max - min + 1);
		}
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,s1,s2;
    cin>>s;
    int x= s.length();
    int y=x/2;
    x=x-1;
    int counter=0;
    for(int i=0;i<y;i++)
    {
        if(s[i]!=s[x-i])
            counter++;
    }
    cout<<counter<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

#define LEN 12

int main(void){
    char input[LEN + 1], first[LEN + 1];
    
    scanf("%s", input);
    
    strcpy(first, input);
    first[4] = '\0';
    
    printf("%s %s\n", first, &(input[4]));
    
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
#include <climits>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << v.first << " " << v.second;
    return ostr;
}

int64 powmod(int64 n, int64 count, int64 mod) {
    if (count == 0) return 1;
    if (count % 2 == 0) {
        int64 t = powmod(n, count / 2, mod);
        return t * t % mod;
    }
    return n * powmod(n, count - 1, mod) % mod;
}

int64 ncr(int64 n, int64 r, int64 mod) {
    int64 a;
    if (n < r) a = min(n, r - n);
    else a = min(n - r, r);

    int64 res = 1;
    rep(i, a) {
        res = res * (n - i) % mod;
        res = res * powmod(i + 1, mod - 2, mod) % mod;
    }

    return res;
}

int main() {
    int N; cin >> N;
    int T, A; cin >> T >> A;
    vector<int> L(N); rep(i, N) cin >> L[i];

    double _min = INF;
    int ans = 0;
    rep(i, N) {
        double b = L[i] * 0.006;

        if (_min > abs(A - (T - b))) {
            _min = abs(A - (T - b));
            ans = i + 1;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const ll MOD = 1000000007LL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
int a[1000005];
int sieve[1000005];
vector<int> prime;
set<int> num;
unordered_map<int, int> h;
int check(int x) {
  int tmp = sieve[x];
  while (x != 1) {
    tmp = sieve[x];
    if (x % tmp == 0 && h[tmp] > 1)
      return 0;
    while (x % tmp == 0)
      x /= tmp;
  }
  return 1;
}
void fact(int x) {
  int tmp = sieve[x];
  while (x != 1) {
    tmp = sieve[x];
    if (x % tmp == 0)
      h[tmp]++, x /= sieve[x];
    while (x % tmp == 0)
      x /= tmp;
  }
}
int main() {
  IOS;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    num.insert(a[i]);
  }
  int g = a[1];
  for (int i = 2; i <= n; i++) {
    g = __gcd(g, a[i]);
  }
  for (int i = 1; i <= 1000000; i++)
    sieve[i] = (i & 1 ? i : 2);
  for (int i = 3; i <= 1000000; i++) {
    if (sieve[i] == i)
      for (int j = i; j <= 1000000; j += i) {
        if (sieve[j] == j)
          sieve[j] = i;
      }
  }
  for (int i = 1; i <= n; i++) {
    fact(a[i]);
  }
  int ok = 1;
  for (int i = 1; i <= n; i++) {
    if (!check(a[i]))
      ok = 0;
  }
  if (ok) {
    cout << "pairwise coprime" << endl;
  } else if (!ok && g == 1) {
    cout << "setwise coprime" << endl;
  } else if (!ok) {
    cout << "not coprime" << endl;
  }
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    char c; cin >> c;
    cout << char(c+1) << endl;
} 
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define N	    100001
#define rep(i,a,b)  for(int i=a;i<b;i++)
typedef long long ll;
void self_max(int &a, int b) {
	a = max(a, b);
}
int main() {
	int n;
	cin>>n;
	vector<double> dp(n + 1);
	dp[0] = 1;
	for(int coins = 1; coins <= n; coins++) {
		double p;
		scanf("%lf", &p);
		for(int i = coins; i >= 0; i--) {
			dp[i] = (i == 0 ? 0 : dp[i - 1] * p) + dp[i] * (1 - p);
		}
	}
	double ans = 0;
	for(int heads = 1; heads <= n; heads++) {
		int tails = n - heads;
		if(heads > tails) {
			ans += dp[heads];		
		}
	}
	printf("%.10lf", ans);
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>

#define int long long

using namespace std;

signed main() {
        int h;
        cin >> h;

        int div = 0;
        int ans = 0;
        while(h > 0) {
                ans += pow(2, div);
                div++;
                h /= 2; 
        }

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

Measured memory_bytes: 512
def get_int
  gets.chop.to_i
end

def get_ints
  gets.chop.split.map(&:to_i)
end

def get_strs
  gets.chop.split
end

def main
  n, m = get_ints
  p_a = []
  s_a = []
  m.times do
    pi, si = get_strs
    p_a << pi.to_i
    s_a << si
  end
  res = Hash.new(0)
  wa_n = 0
  ca_n = 0
  0.upto(m-1) do |i|
    pi = p_a[i]
    si = s_a[i]
    if si == "AC"
      if res[pi] != -1
        ca_n += 1
        wa_n += res[pi]
        res[pi] = -1
      end
    elsif si == "WA"
      if res[pi] != -1
        res[pi] += 1
      end
    end
  end
  puts "#{ca_n} #{wa_n}"
end

if __FILE__ == $0
  main
end

Measured memory_bytes: 16764
#include "bits/stdc++.h"
#define ll long long
using namespace std;
int main(){
string s;
ll N,Q;
cin>>N>>Q>>s;
vector<ll> qs(Q);
vector<ll> qe(Q);
vector<ll> pos(N,0);
for(ll i=0;i<Q;i++){
cin>>qs[i]>>qe[i];
}
ll tmp=0;
for(ll i=1;i<N;i++){
  pos[i]=pos[i-1];
  if(s[i]=='C'&&s[i-1]=='A'){
    tmp++;
    pos[i]=tmp;
  }
}
for(ll i=0;i<Q;i++){
printf("%lld\n",pos[qe[i]-1]-pos[qs[i]-1]);
}
}


Measured memory_bytes: 3456
import Control.Monad
import Data.Function
import Data.List

temp t x = 1000 * t - 6 * x

err a r = abs $ 1000 * a - r

main = do
    n <- readLn :: IO Int
    [t, a] <- map read . words <$> getLine :: IO [Int]
    hs <- zip [1..n] . map read . words <$> getLine :: IO [(Int, Int)]
    print $ fst $ minimumBy (on compare (err a . temp t . snd)) hs
    

Measured memory_bytes: 1404
n, k, c = gets.split.map(&:to_i)
s = gets.chomp.split("")

wd = Array.new(n).map{Array.new(3,0)}

#top
cnt = 0
pre = c
for i in 0..(n-1)
  pre += 1
  if s[i]=="o" && pre > c
    wd[i][0] = 1
    pre = 0
    cnt += 1
    break if cnt >= k
  else
    wd[i][0] = 0
  end
end

#bottom
cnt = 0
pre = c
id = n-1
while id >= 0
  pre += 1
  if s[id]=="o" && pre > c
    wd[id][1] = 1
    pre = 0
    cnt += 1
    break if cnt >= k
  else
    wd[id][1] = 0
  end
  id -= 1
end

#both
cnt = 0
tpre = c
bpre = c
tid = 0
bid = n-1
cmp = -1
for i in 1..((k+1)/2)
  while 1
    tpre += 1
    if s[tid]=="o" && tpre > c
      wd[tid][2] = 1
      tpre = 0
      cnt += 1
      cmp = tid if cnt >= k
      tid += 1
      break
    else
      wd[tid][2] = 0
    end
    tid += 1
  end
  while 1
    bpre += 1
    if s[bid]=="o" && bpre > c
      wd[bid][2] = 1
      bpre = 0
      cnt += 1
      if cnt >= k && cmp > -1
        if cmp != bid
          wd[cmp][2] = 0
          wd[bid][2] = 0
        end
      end
      bid -= 1
      break
    else
      wd[bid][2] = 0
    end
    bid -= 1
  end
end

for i in 0..(n-1)
  puts i+1 if wd[i][0]*wd[i][1]*wd[i][2] == 1
end

Measured memory_bytes: 43488
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

int n, k;
int v[55], v_rev[55];

int pqpop(priority_queue<int>& pq) {
    int a = pq.top();
    pq.pop();
    return a;
}

signed main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; ++i) {
        cin >> v[i];
        v_rev[n-i+1] = v[i];
    }

    int mx = 0;

    for (int len = 1; len <= k && len <= n; ++len) {
        for (int i = 1; i <= len; ++i) {
            priority_queue<int, vector<int>, greater<int>> pq1, pq2;

            for (int j = 1; j <= i; ++j) {
                pq1.push(v[j]);
                pq2.push(v_rev[j]);
            }
            for (int j = 1; j <= len - i; ++j) {
                pq1.push(v_rev[j]);
                pq2.push(v[j]);
            }

            int zan = k - len;

            while (zan > 0) {
                if (!pq1.empty() && pq1.top() < 0) pq1.pop();
                if (!pq2.empty() && pq2.top() < 0) pq2.pop();
                zan--;
            }

            int sum1 = 0, sum2 = 0;

            while (!pq1.empty()) {
                sum1 += pq1.top();
                pq1.pop();
            }

            while (!pq2.empty()) {
                sum2 += pq2.top();
                pq2.pop();
            }

            mx = max(mx, sum1);
            mx = max(mx, sum2);
        }
    }

    cout << mx << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
// #define fore(i,a) for(auto &i:a)
// #define all(x) (x).begin(),(x).end()
// #pragma GCC optimize ("-O3")
// using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
// typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
// 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; }

using namespace std;

int main()
{
  string s,t;
  cin>>s>>t;
  
  rep(i,0,s.size()){
    if(s[i]==t[i]) continue;
    else{
      cout<<"No"<<endl;
      return 0;
    }
  }
  
  if(s.size()+1==t.size()) cout<<"Yes"<<endl;
  
  return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>

int main() {
  int N=0, M=0;
  int A[1001];
  scanf ("%d %d", &N, &M);
  int sum = 0;
  
  for (int i = 0; i < N; i++) {
    scanf ("%d ", &A[i]);
    sum += A[i];
  }
  int valid = 0;
  for (int i = 0; i < N; i++) {
    if ((double)A[i]/(double)sum >= 1.0/(4.0*(double)M)) valid++;
  }
  if (valid >= M) printf("Yes");
  else printf("No");
  
  return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> D(N);
  for(int i=0;i<N;i++){
    cin >> D.at(i);
  }
  sort(D.begin(),D.end());
  cout << D.at(N/2) - D.at(N/2 - 1) << endl;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
typedef pair<ll, pair<int, int> > E;
#define MOD (1000000007ll)
#define l_ength size
#define cost first
#define u second.first
#define v second.second

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int ufr[123456],ufp[123456];

void ufinit(int n){
	int i;
	for(i=0; i<n; ++i){
		ufr[i] = 0;
		ufp[i] = i;
	}
}

int ufind(int x){
	if(ufp[x] == x){
		return x;
	}else{
		ufp[x] = ufind(ufp[x]);
		return ufp[x];
	}
}

void unionf(int x, int y){
	x = ufind(x);
	y = ufind(y);
	if(x == y){
		return;
	}
	if(ufr[x] > ufr[y]){
		ufp[y] = x;
	}else{
		ufp[x] = y;
	}
	if(ufr[x] == ufr[y]){
		++ufr[y];
	}
}

bool comp(P a, P b){
	return (a.first < b.first);
}

vector<P> x,y;
priority_queue<E, vector<E>, greater<E> > pq;

int main(void){
	int n,i;
	ll xi,yi,ans;
	E e;
	cin >> n;
	ufinit(n);
	for(i=0; i<n; ++i){
		cin >> xi >> yi;
		x.push_back(P(xi,i));
		y.push_back(P(yi,i));
	}
	sort(x.begin(),x.end(),comp);
	sort(y.begin(),y.end(),comp);
	for(i=1; i<n; ++i){
		pq.push(E(x[i].first-x[i-1].first,P(x[i-1].second,x[i].second)));
		pq.push(E(y[i].first-y[i-1].first,P(y[i-1].second,y[i].second)));
	}
	while(!pq.empty()){
		e = pq.top(); pq.pop();
		if(ufind(e.u) == ufind(e.v)){
			continue;
		}
		ans += e.cost;
		unionf(e.u,e.v);
	}
	cout << ans << endl;
	return 0;
}


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

void fill(char *aa,int a,int L){
  rep(i,L){
    aa[i] = '0' + a%10;
    a=a/10;
  }
}

int main(){
  for(;;){
    int a,L;
    scanf("%d %d",&a,&L);
    if(!(a+L)) break;

    int count = 0;
    char aa[7];
    int tmp=a;

    int rec[21]={0};
    rec[0]=a;
    aa[L]='\0';
    int j,d;
    int end=0;

    for(;;){
      if(end)break;
      fill(aa,tmp,L);
      //printf("%d\n",tmp);
      sort(aa,aa+L,greater<char>()); 
      int l=atoi(aa);
      sort(aa,aa+L);
      int s=atoi(aa);
      //printf("l = %d, s = %d\n",l,s);
      tmp = l-s;
      count++;
      //printf("count = %d\n",count);
      rec[count] = tmp;
      rep(i,count+1){
	if(count!=i && rec[i]==tmp){
	  //printf("%d\n",rec[i]);
	  j=i;
	  d=count-i;
	  end=1;
	  break;
	}
      }
    }
    printf("%d %d %d\n",j,tmp,d);
  }
}

Measured memory_bytes: 1208
from math import sqrt
from collections import Counter

n, m = map(int, input().split())

mod = 10**9+7

def factor(n) :
    factors = Counter()
    p = 2
    while p*p <= n :
        while n%p == 0 :
            factors.update([p])
            n //= p
        p += 1
    if n > 1 :
        factors.update([n])
    return factors

def comb(n, r) :
    if n - r < r: r = n - r
    if r < 0: return 0
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

vv = factor(m).values()
ans = 1
for v in vv :
    a = 0
    for i in range(min(n, v)) :
        a += comb(n, i+1)*comb(v-1, i)
    ans *= a
    ans %= mod
print(ans)

Measured memory_bytes: 3316
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct data{int a,b;}M[100];//,tmp[51];
/*void msort(struct data* m,int first,int last){
	int i,j,p,middle;
	printf("s %d %d %d : ",first,first+last>>1,last);for(i=0;i<6;i++)printf("%d ",m[i].a);puts("");
	if(first<last){
	middle=first+last>>1;
	msort(m,first,middle);
	msort(m,middle+1,last);
	for(i=first;i<=middle;i++)tmp[i-first]=m[i];
	j=0;
	p=first;
	while(i<=last&&j<middle-first)
		if(m[i].b<tmp[j].b)m[p++]=m[i++];
		else m[p++]=tmp[j++];
	while(j<middle-first)m[p++]=tmp[j++];
	}
	printf("e %d %d %d : ",first,first+last>>1,last);for(i=0;i<6;i++)printf("%d ",m[i].a);puts("");
}*/
void exc(struct data *a,struct data *b){
	struct data tmp;
	tmp=*a;*a=*b;*b=tmp;
	return;
}
int comp(const struct data*a, const struct data*b){
    return b->b - a->b;
}
int main(){
	int i,j,n,m,buf;
	while(1){
		scanf("%d %d",&n,&m);
		if(!n&&!m)return 0;
		for(i=0;i<m;i++)M[i].a=i+1,M[i].b=0;
		for(j=0;j<n;j++)for(i=0;i<m;i++)scanf("%d",&buf),M[i].b+=buf;
		//msort(M,0,m-1);
		//qsort(M,m,sizeof(struct data),comp);
		//for(j=0;j<m;j++)for(i=0;i<j;i++)if(M[i].b==M[j].b&&M[i].a>M[j].a)exc(&M[i],&M[j]);
		j=0;while(j<m&&n!=j){n=j;for(i=0;i<m;i++)if(M[i+1].b>M[i].b)exc(&M[i],&M[i+1]),j=i;}
		//for(i=m-1;i>=0;i--)printf("%d ",M[i].a);
		for(i=0;i<m-1;i++)printf("%d ",M[i].a);
		printf("%d\n",M[m-1].a);
	}
}

Measured memory_bytes: 0
#include <iostream>
//cut begin
template<typename T>
T modpow(T a,T n,T mod){//(a^n)%MOD
    T ret=1;
    while(n>0){
        if((n&1)!=0){//n%2==1
            ret=ret*a%mod;
        }
        a=a*a%mod;
        n=n/2;
    }
    return ret;
}
//cut end
int main(){
    long long n,m;
    std::cin>>n>>m;
    std::cout<<modpow(n,m,1000000007ll)<<std::endl;
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define ll long long
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const int N = 5 + 1e5;
int n , k  ;
const int INF = 1e9;
int main() {
    fastIO
    vector<int> dp(N, INF), arr(N);
    cin >> n >> k;
    for (int i = 0 ; i < n ; i++) cin >> arr[i];
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j <= i + k; j++)
            if (j < n) dp[j] = min(dp[j], dp[i] + abs(arr[i] - arr[j]));
    }
    cout << dp[n - 1] << endl;
}

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

using namespace std;

using ll = long long;

ll lcm(ll m, ll n ) {
    if (0 == m || 0 == n)
        return 0;
    return (m / __gcd(m, n)) * n; // lcm = m * n / gcd(m,n)
}

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

    long long A, B, C, D;
    cin >> A >> B >> C >> D;

    ll lcm_val = lcm(C, D);
    ll res = B - A + 1 - (B / C - (A - 1) / C) - (B / D - (A - 1) / D) + (B / lcm_val - (A - 1) / lcm_val);

    cout << res << '\n';

    return 0;
}


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

int main(){
  string a, b, c;
  int aa, bb, cc;
  aa = bb = cc = 0;
  cin >> a >> b >> c;
  char key = 'a';
  while(1){
    if(aa == a.size() + 1){
      cout << 'A' << endl;
      return 0;
    }else if(bb == b.size() + 1){
      cout << 'B' << endl;
      return 0;
    }else if(cc == c.size() + 1){
      cout << 'C' << endl;
      return 0;
    }
    if(key == 'a'){
      key = a[aa];
      aa++;
    }
    if(key == 'b'){
      key = b[bb];
      bb++;
    }
    if(key == 'c'){
      key = c[cc];
      cc++;
    }
  }
}


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


int main() {
  ll N, M, K;
  cin >> N >> M >> K;

  vector<ll> A(N), SA(N + 1);
  vector<ll> B(M), SB(M + 1);
  rep(i, N) cin >> A[i];
  rep(i, M) cin >> B[i];

  SA[0] = 0;
  rep(i, N) {
    SA[i + 1] = SA[i] + A[i];
  }
  SB[0] = 0;
  rep(i, M) {
    SB[i + 1] = SB[i] + B[i];
  }

  ll ans = 0;
  ll b_index = M;
  for (int i = 0; i <= N; i++) {
    ll tmp_sum = SA[i];
    if (tmp_sum > K) break;
    ll tmp_ans = i;
    while (b_index > 0) {
      if (SB[b_index] > K - tmp_sum) {
        b_index--;
      } else {
        break;
      }
    }
    if (ans < i + b_index) ans = i + b_index;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9556
#include <iostream>

using namespace std;

int main()
{
    char a[5];
    int sum = 0;
    cin>>a;
    for (int i = 0; i < 4; i++)
    {
        if (a[i] == '+')
            sum++;
            else sum--;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var k int
	fmt.Scan(&k)
	var ans int
	for i := 1; i <= k; i++ {
		for j := 1; j <= k; j++ {
			for p := 1; p <= k; p++ {
				 gcdij := gcd(i, j)
				 gcdijk := gcd(gcdij, p)
				ans += gcdijk
			}
		}
	}
	fmt.Println(ans)
}

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


Measured memory_bytes: 1780
#include <iostream>

using namespace std;
using ll = long long;

int main() {
  ll N, A, ans{}, s{}, m{1 << 30};
  cin >> N;
  for (int i = 0; i != N; ++i) {
    cin >> A;
    if (A < 0) A *= -1, ++s;
    m = min(m, A);
    ans += A;
  }
  cout << ans - (s % 2 ? 2 * m : 0) << endl;
}


Measured memory_bytes: 3552
#include<iostream>
#include<string>
#include<cstdio>
#include<deque>
#include<list>
#include<queue>
#include<stack>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<set>
#include<complex>
#include<cmath>
#include<limits>
#include<cassert>
#include<bitset>
#include<numeric>
#include<functional>

using namespace std;


int main(){
  int s, t;
  cin >> s >> t;
  int p, q, m;
  cin >> p >> q >> m;
  int y;
  cin >> y;
  cout << (t ^ s ^ y) << endl;
}



Measured memory_bytes: 3044
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=1e5+5;
int n,m,dp[N],in[N],ans=-1;
vector<int>v[N];
bool notroot[N];
int dfs(int now)
{
	if(dp[now]!=-1)return dp[now];
	if(v[now].empty())return 0;
	for(int i=0;i<v[now].size();i++)
	{
		int to=v[now][i];
		dp[now]=max(dp[now],dfs(to)+1);
	}
	return dp[now];
}
int main()
{
	memset(dp,-1,sizeof(dp));
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		a--,b--;
		v[a].pb(b);
		notroot[b]=true;
	}
	for(int i=0;i<n;i++)
		if(!notroot[i])
			ans=max(ans,dfs(i));
	cout<<ans<<endl; 
	return 0;
}

Measured memory_bytes: 10880
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#define eps 0
using namespace std;
struct P{
	double x,y,w;int id;
	P(){}
	P(double a,double b){x=a;y=b;}
	friend P operator +(P a,P b){
		return P(a.x+b.x,a.y+b.y);
	}
	friend P operator -(P a,P b){
		return P(a.x-b.x,a.y-b.y);
	}
	friend double operator *(P a,P b){
		return a.x*b.y-a.y*b.x;
	}
}a[105];
int s[105],top,n;
double ans[105];
bool cmpx(P a,P b){
	return a.x<b.x;
}
bool cmpw(P a,P b){
	if(fabs(a.w-b.w)>eps) return a.w>b.w;
	return fabs(a.x-::a[1].x)>fabs(b.x-::a[1].x);
}
const double pi=acos(-1);
double calc(P a,P b){
	double len=sqrt((a.x*a.x+a.y*a.y)*(b.x*b.x+b.y*b.y));
	double ans=(a.x*b.x+a.y*b.y)/len;
	ans=acos(ans);
	if(ans<0) ans=-ans;
	return (pi-ans)/(2*pi);
}
void solve(){
	sort(a+1,a+n+1,cmpx);
	for(int i=2;i<=n;i++) a[i].w=atan2(a[i].y-a[1].y,a[i].x-a[1].x);
	sort(a+2,a+n+1,cmpw);
	s[++top]=1;
	for(int i=2;i<=n;i++){
		if(i>2&&fabs(a[i].w-a[i-1].w)<eps) continue;
		while(top>1&&(a[i]-a[s[top]])*(a[s[top]]-a[s[top-1]])<eps) top--;
		s[++top]=i;
	}
	for(int i=1,pre,nxt;i<=top;i++){
		pre=i-1,nxt=i+1;
		if(pre==0) pre=top;
		if(nxt==top+1) nxt=1;
		pre=s[pre];nxt=s[nxt];
		ans[a[s[i]].id]=1e9;//calc(a[s[i]]-a[pre],a[s[i]]-a[nxt]);
		for(int p=1;p<=n;p++){
			for(int j=1;j<=n;j++){
				if(p==s[i]||j==s[i]) continue;
				ans[a[s[i]].id]=min(ans[a[s[i]].id],calc(a[s[i]]-a[p],a[s[i]]-a[j]));
			}
		}
	}
}
int main(){
	scanf("%d",&n);
	if(n==1) return puts("1.0"),0;
	for(int i=1;i<=n;i++) scanf("%lf%lf",&a[i].x,&a[i].y),a[i].id=i;
	solve();
	for(int i=1;i<=n;i++) printf("%.12lf\n",ans[i]);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int i,j,k,n;
	scanf("%d",&n);
	int data[200][3],flg[200][3],sum[200] ={0};
	for(i = 0;i < n;i++){
			scanf("%d%d%d",&data[i][0],&data[i][1],&data[i][2]);
	}
	for(i = 0;i < n-1;i++){
		for(j = i+1;j < n;j++){
			for(k = 0;k < 3;k++){
				if(data[i][k] == data[j][k]){
					flg[i][k] = -1;flg[j][k] = -1;
				}
			}
		}
	}
	for(i = 0;i < n;i++){
		for(j = 0;j < 3;j++){
			if(flg[i][j] != -1){
				sum[i] += data[i][j];
			}
		}
		printf("%d\n",sum[i]);
	}
return 0;

}
	

Measured memory_bytes: 1028
#include<iostream>
#include<string>
#include<sstream>
#include<map>
using namespace std;

#define INF 100000000
#define fs first
#define sc second
typedef pair<int,int> P;

int stoi(string s){
  stringstream ss(s);
  int res;
  ss >> res;
  return res;
}

P par[210];
int rank[210];

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

P find(int a){
  if(par[a].fs == a)return par[a];
  P tmp = find(par[a].fs);
  return par[a] = P(tmp.fs,tmp.sc + par[a].sc);
}

bool same(int a,int b){
  return (find(a).fs == find(b).fs);
}

bool unite(int a,int b,int cost){
  P x = find(a);
  P y = find(b);
  
  if(same(x.fs,y.fs)){
    //cout << a << " " << b << endl;
    cout << x.sc << " " << y.sc << " " << cost << endl;
    if(y.sc - x.sc != cost)return false;
  }else{
    if(rank[x.fs]<rank[y.fs]){
      par[x.fs] = P(y.fs,par[b].sc-cost);
    }else{
      par[y.fs] = P(x.fs,par[a].sc+cost);
      if(rank[x.fs] == rank[y.fs])rank[x.fs]++;
    }
  }
  return true;
}

int g[210][210];
int n,c[110],f,t;
string a[110],b[110],tmp;
map<string,int> m;

int main(){
  int i;
  while(cin >> n,n){
    m.clear();
    for(i=0;i<n;i++){
      cin >> tmp; cin >> a[i]; cin >> tmp;
      cin >> tmp; c[i] = stoi(tmp.substr(3,tmp.size()-3));
      cin >> b[i];
    }
    for(i=0;i<n;i++){
      if(m.find(a[i])==m.end())m[a[i]] = m.size()-1;
      if(m.find(b[i])==m.end())m[b[i]] = m.size()-1;
    }

    for(i=0;i<m.size();i++)
      for(int j=0;j<m.size();j++)
	if(i==j)g[i][j] = 0;
	else g[i][j] = INF;

    for(i=0;i<n;i++){
      f = m[a[i]]; t = m[b[i]];
      if(g[f][t] != INF){
	if(g[f][t] != c[i]){
	  cout << "No" << endl;
	  break;
	}
      }else{
	g[f][t] = c[i];
	for(int x=0;x<m.size();x++){
	  if(x!=t && g[x][f] != INF){
	    for(int y=0;y<m.size();y++){
	      if(y!=f && g[t][y] != INF){
		g[x][y] = g[x][f] + g[f][t] + g[t][y];
	      }
	    }
	  }
	}

	g[t][f] = -c[i];
	for(int x=0;x<m.size();x++){
	  if(x!=f && g[x][t] != INF){
	    for(int y=0;y<m.size();y++){
	      if(y!=t && g[f][y] != INF){
		g[x][y] = g[x][t] + g[t][f] + g[f][y];
	      }
	    }
	  }
	}
      }
    }
    if(i==n)cout << "Yes" << endl;
    /*
    init(m.size());
    for(i=0;i<n;i++){
      if(!unite(m[a[i]],m[b[i]],c[i])){
	cout << "No" << endl;
	break;
      }
    }
    
    if(i==n)cout << "Yes" << endl;
    */
  }
}

Measured memory_bytes: 1428
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<utility>
#include<functional>
#include<cassert>
#include<cmath>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<ll> vint;
typedef vector<vint> vvint;
#define PI 3.1415926535
#define MOD 1000000007
#define rep(i, n) for(ll i=0;i<(n);i++)


int main(void) {
	ll n,ans=0; cin >> n;
	vvint a(n, vint(100));
	ll time=0;

	rep(i, n) {
		ll x;
		ll j = 0;
		cin >> x;
		while (x != 0) {
			a[i][j] = x % 2;
			j++;
			x /= 2;
		}
		time = max(time, j);
	}

	rep(i, time) {
		ll cnt = 0;
		rep(j, n) {
			if (a[j][i] == 1) {
				cnt++;
			}
		}
		ll y = ((ll)1 << i) % MOD;
		ans += (((cnt * (n - cnt))%MOD)*y)%MOD ;
	}
	ans %= MOD;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 246400
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
const int MOD = 1000000009;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  double w, h, x, y;

  cin >> w >> h >> x >> y;

  cout << (w * h) / 2 << ' ' << (x + x == w && y + y == h)? 1 : 0;
  cout << endl;
  return 0;
}




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

int main(){
    
    for(int i = 1; i <= 9;i++)
    {
        for(int j = 1;j <= 9;j++)
        {
            cout << i << "x" << j << "=" << i * j << endl;
        }
    }    

    return 0;
}

Measured memory_bytes: 1116
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) > (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)


int main(){

    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    printf("%d\n",min(c,a+b+1)+b );
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
 
using namespace std;
 
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define vvi vector<vector<int> >
#define ss second
#define ff first
#define ll long long
#define mod (1000*1000*1000+7)
#define pq priority_queue< int >
#define endl '\n'
#define int ll
#define gcd __gcd

void solve(){
    int n;
    cin >> n;
    if(n >= 30){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
}


int32_t main(){

    #ifndef ONLINE_JUDGE 
  
    freopen("input.txt", "r", stdin); 
  
    freopen("output.txt", "w", stdout); 
  
    #endif 

    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
 

    int t = 1;
    // cin >> t;
    while(t--){
        solve();
        // cout << "Case #" << (tt+1) <<":" << endl;
    }
}

Measured memory_bytes: 3648
a=gets.to_i
line=gets.chomp.split().map(&:to_i)
a.times do |count|
  if line[count] %2 ==0 
    if line[count]%6 !=0  && line[count]%10 !=0
      puts "DENIED"
      break
    end   
  end  
  if count == line.size-1
    puts "APPROVED"
  end  
end  

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(a) cout<<#a<<":"<<a<<endl;
const ll INF=0x3f3f3f3f;
const ll N=1e6+7;
const ll mod=1e9+7;
ll maxn,minn;
ll T,n;
ll W;
ll dp[N];
ll w[N];
ll v[N];

int main() {
	cin>>n>>W;
	for(ll i=1; i<=n; i++) {
		scanf("%lld%lld",w+i,v+i);
	}
	for(ll i=1; i<=n; i++) {
		for(ll j=W; j>=w[i]; j--) {
			dp[j]=max(dp[j-w[i]]+v[i],dp[j]);
		}
	}
	cout<<dp[W]<<endl;


	return 0;
}





Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;


int main() {
    int k; cin >> k;
    ll ans = 0;
    for(int i = 1;i <= k;i++){
        for(int j = 1;j <= k;j++){
            for(int l = 1;l <=k;l++){
                ll a = GCD(i,j);
                ans += GCD(a,l);
            }
        }
    }
    cout << ans;
}



Measured memory_bytes: 3644
function main(input) {
	var list = input.split("\n");
	var time = 0;
	list = list.map((item) => {
		var min = +item%10 > 0 ? 10 * (parseInt(+item/10) + 1) : +item;
		return {
			chori  : +item,
			chumon : min,
			rug : min - +item
		};
	});
	list.sort((x, y) => {
		return x.rug - y.rug;
	});
	list.forEach((item, index) => {
		if(index === list.length - 1) {
			time += item.chori;
		} else {
			time += item.chumon;
		}
	});
	console.log(time);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(){
	int n;
	cin >> n;
	int ans = 0;
	if(n>=64) ans = 64;
	else if(n>=32) ans = 32;
	else if(n>=16) ans = 16;
	else if(n>=8) ans = 8;
	else if(n>=4) ans = 4;
	else if(n>=2) ans = 2;
	else ans = 1;
	cout << ans << endl;
	return 0;
} 

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

int main()
{
	int N, M;
	cin >> N >> M;
	N = 1 << N;

	vector<vector<int>> s(M);
	for (int i = 0; i < M; ++i)
	{
		vector<int> v;
		int k;
		cin >> k;

		for (int i = 0; i < k; ++i)
		{
			int elem;
			cin >> elem;
			--elem;

			v.push_back(elem);
		}
		s[i] = v;
	}

	vector<int> p(M);
	for (int i = 0; i < M; ++i)
	{
		int l;
		cin >> l;
		p[i] = l;
	}

	int count = 0;
	for (int i = 0; i < N; ++i)
	{
		bool allOn = true;
		for (int j = 0; j < M; ++j)
		{
			int on_count = 0;
			for (auto v : s[j])
			{
				if ((i & 1 << v) != 0)
				{
					++on_count;
				}
			}

			if (on_count % 2 != p[j])
			{
				allOn = false;
				break;
			}
		}

		if (allOn)
		{
			++count;
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
int main(){
	vector<pair<int,int> >v;
	int N,M,a,b,i=0,s=1,t=0,r=0;
	for(scanf("%d%d",&N,&M),i=0;i<M;i++)
		scanf("%d%d",&a,&b),v.push_back(make_pair(a,b));
	sort(v.begin(),v.end());
	for(i=0;i<M;i++){
		if(v[i].first>s){
			if(v[i].first-t>1||t<s){
				puts("Impossible");
				return 0;
			}
			if(t==N){
				printf("%d\n",r+1);
				return 0;
			}
			s=t+1;r++;
		}
		if(t<v[i].second)t=v[i].second;
	}
	if(t==N){
		printf("%d\n",r+1);
		return 0;
	}
	puts("Impossible");
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 200010
#define test(a,n) REP(i,n) cout << a[i] << " "; cout << endl;
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  vector<ll> b(n+1,0);
  REP(i,n){
    cin >> a[i];
    b[a[i]]++;
  } 
  
  ll sum = 0;
  REP(i,n+1) sum += b[i]*(b[i]-1)/2;
  
  REP(i,n) cout << sum - b[a[i]] + 1 << endl;
  return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,j,k) for(int i=j;i<k;i++)
#define FORD(i,j,k) for(int i=j;i>=k;i--)
#define ll long long
#define ull unsigned long long int
#define ld long double
//Make sure no overflow problems
#define pii  pair<int, int>
#define vi vector<int >
#define pb push_back
#define mp make_pair
#define endl '\n'
#define x first
#define y second
#define VAR(i,n) __typeof(n) i = (n)
#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();i++)
#define FORDEACH(i,c) for( VAR(i,(c).rbegin()),i!=(c).rend();i++)
#define REP(i,n) FOR(i,0,n)
#define mod 1000000007
#define MEM(a, b) memset(a, (b), sizeof(a))
#define addmod(a,b,mod) (a%mod + b%mod)%mod
#define submod(a,b,mod) (a%mod - b%mod + mod)%mod
#define N 1000000
const ld EPS = 10e-9;
const int MAX = 1e6;

bool prime[N];
void sieve(int n) {
    for(int i = 0;i <= n; i++)
        prime[i] = true;
    prime[0] = false;
    prime[1] = false;
    for (int k = 2; k*k<=n; k++) { 
        if(prime[k])
            for (int i = k*k; i <= n; i += k) 
                prime[i] = false; 
    } 
}
int main(){
    ios_base:: sync_with_stdio(false); 
    cin.tie(0);
    
    sieve(1000000);
    int x;
    cin >> x;
    while(true){
        if(prime[x]){
            cout << x;
            break;
        }
        x++;
    }
    return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;

int main()
{
  string s;
  cin >> s;
  for(int i = 0; s[i] != '\0'; i++) cout << "x";
  cout << endl;
  return 0;
}

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

#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N], col[N], dpos[2 * N - 1], dneg[2 * N - 1];
bool X[N][N];

void init(){
    for(int i=0; i<N; i++){
        row[i] = FREE;
        col[i] = FREE;
    }
    for(int i=0; i<2*N-1; i++){
        dpos[i] = FREE;
        dneg[i] = FREE;
    }
}

void printBoard(){
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            if(X[i][j]){
                if(row[i] != j) return;
            }
        }
    }
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            cout << ((row[i] == j) ? "Q" : ".");
        }
        cout << endl;
    }
}

void recursive(int i){
    if(i == N){ // ?????????????????¨????????????????????????
        printBoard();
        return;
    }
    for(int j=0; j<N; j++){
        // (i, j)????????????????????????????????´????????????
        if(NOT_FREE == col[j] || 
           NOT_FREE == dpos[i + j] ||
           NOT_FREE == dneg[i - j + N - 1]
          ) continue;
        // (i, j)???????????????????????????
        row[i] = j;
        col[j] = dpos[i + j] = dneg[i - j + N -1] = NOT_FREE;
        // ?¬????????????????
        recursive(i+1);
        // ????¶???§?????????????????????????????£?????????(i, j)????????????????????????
        row[i] = col[j] = dpos[i + j] = dneg[i - j + N -1] = FREE;
    }
    // ??????????????????????????§??????
}

 
int main() 
{
    ios::sync_with_stdio(false);
    init();

    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            X[i][j] = false;
        }
    }

    int k;
    cin >> k;

    for(int i=0; i<k; i++){
        int r, c;
        cin >> r >> c;
        X[r][c] = true;
    }
    recursive(0);

    return 0;
}

Measured memory_bytes: 3220
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

#define MOD_BIG 1000000007
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using std::vector;

template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) {
    vec.resize(len);
    for (auto &v : vec) ndarray(v, args...);
}

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

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

int main() {
    string S;
    cin >> S;
    
    ll N = S.length() + 1;
    ll ans = 0;
    
    ll cnt = 1;
    char b = S[0];
    ll yama = 0;
    for (ll i = 1; i < N-1; i++) {
        if (b == S[i]) {
            cnt += 1;
        } else {
            if (b == '<') {
                yama = cnt;
                ans += (cnt * (cnt - 1)) / 2;
            } else {
                ans += std::max(cnt, yama);
                ans += (cnt * (cnt - 1)) / 2;
            }
            cnt = 1;
            b = S[i];
        }
        //cerr << ans << endl;
    }
    if (b == '<') {
        ans += cnt;
        ans += (cnt * (cnt - 1)) / 2;
    } else {
        ans += (cnt * (cnt + 1)) / 2;
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 900
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
    int a,b;
    while(cin>>a>>b){
        if(a==0&&b==0){
            break;
        }
        if(a<b){
            cout<<a<<" "<<b<<endl;
        }else{
            cout<<b<<" "<<a<<endl;
        }
    }
    return 0;
}

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

const int MOD = 1000000007;
const int INF = 1e9;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

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

//最大公約数 
 ll gcd(ll a,ll b){
 if(b == 0) return a;
 return gcd(b,a%b);
 }

//最小公倍数
 ll lcm(ll a,ll b){
 ll g = gcd(a,b);
 return a / g * b; // Be careful not to overflow  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
} 

#define INF 1LL<<60



  int main(){
    string S;
    cin >> S;
    if(S == "SUN")  print("7");
    else if(S == "MON") print("6");
    else if(S == "TUE") print("5");
    else if(S == "WED") print("4");
    else if(S == "THU") print("3");
    else if(S == "FRI") print("2");
    else if(S == "SAT") print("1");

     
  }


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

//最大公約数を求める関数
ll gcd(ll a,ll b){
    int c,d,e;
    c=max(a,b);
    d=min(a,b);
    while(1){
        c=c%d;
        if(c==0){
            break;
        }
        e=d;
        d=c;
        c=e;
    }
    return d;
}

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

    ll ans=a[0];
    rep(i,n-1){
        ans=gcd(ans,a[i+1]);
    }

    cout << ans << endl;

    

    return 0;
}

Measured memory_bytes: 3992