akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() { 
  int N;
  cin >> N;
  vector<int> vec(N);
  int sum = 0;
  for(int i = 0;i < N;i++){
    cin >> vec.at(i);
  }

  for(int i = 0;i < N;i++){
    for(int j = i + 1;j < N;j++){
     sum += (vec.at(i) * vec.at(j));
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
s = input()
x = 0
y = 0
for i in range(len(s)):
  if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
    x = x + 1
  else:
    if y < x:
      y = x
    x = 0
if y < x:
  y = x
print(y)

Measured memory_bytes: 8984
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/timeb.h>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (ll NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (ll NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (ll NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()
const ll LINF = 1e18;
const int INF = 1e9;
const int mod = 1e9+7;

int main(){
    ll n;
    cin >> n;
    vector<pair<ll,ll>> a(n);
    
    REP(i, n){
        cin >> a[i].second;
        cin >> a[i].first;
    }
    
    sort(ALL(a));
    
    ll limit = a[n-1].first;
    
    BREP(i, n){
        limit -= a[i].second;
        if(limit < 0){
            cout << "No" <<endl;
            return 0;
        }
        if(i == 0)break;
        limit = min (limit, a[i-1].first);
    }
    
    cout << "Yes" << endl;
}


Measured memory_bytes: 3328
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    string s1, s2;
    int A, B;
    string s;
    cin >> s1 >> s2 >> A >> B >> s;
    if (s == s1) A--;
    else B--;

    cout << A << " " << B << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
 int N,K;
 string S;
 cin>>N>>K>>S;
 if(S.at(K-1)=='A'){
     S.at(K-1)='a';
 }
 else if (S.at(K-1)=='B'){
     S.at(K-1)='b';
 }
 else 
 S.at(K-1)='c';
 cout<<S<<endl;
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 11111
typedef pair<int,int> P;
vector<P> G[MAX_V];
bool used[MAX_V];
int prim(){
  int res=0;
  priority_queue<P,vector<P>,greater<P> > q;
  q.push(P(0,0));
  memset(used,0,sizeof(used));
  while(!q.empty()){
    P p=q.top();q.pop();
    int v=p.second,d=p.first;
    if(used[v]) continue;
    used[v]=1;
    res+=d;
    for(int i=0;i<(int)G[v].size();i++){
      q.push(G[v][i]);
    }
  }
  return res;
}
int main(){
  int V,E;
  cin>>V>>E;
  for(int i=0;i<E;i++){
    int s,t,u;
    cin>>s>>t>>u;
    G[s].push_back(P(u,t));
    G[t].push_back(P(u,s));
  }
  cout<<prim()<<endl;
  return 0;
}

Measured memory_bytes: 7840
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);

  int N, s[111], S = 0;

  std::cin >> N;

  for (int i = 0; i < N; i ++) {
    std::cin >> s[i];

    S += s[i];
  }

  if (S % 10 == 0) {
    std::sort(s, s + N);

    for (int i = 0; i < N; i ++)
      if (s[i] % 10) {
        S -= s[i];

        break;
      }

    if (S % 10 == 0)
      S = 0;
  }

  std::cout << S << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    string N;
    cin >> N;
    if (N[0] == '7' || N[1] == '7' || N[2] == '7') {
        cout << "Yes" << endl;
    } else {
        cout <<"No" <<endl;
    }

    return 0;
}

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

int main() {
  int N,X,T,ans=1; cin >> N >> X >> T;
  if(N<=X) cout << T << endl;
  if(N>X) {
    while(N>X) {
      N -= X;
      ans++;
    }
    cout << ans * T<< endl;
  }
}

Measured memory_bytes: 3632
a,b,x = list(map(int,input().split()))

import numpy as np

if a*a*b/2 < x:
    d = np.arctan(2*(a*a*b-x)/(a*a*a))
    print(d*180/np.pi)
else:
    d = np.arctan(b*b*a/(2*x))
    print(d*180/np.pi)

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

/* define const */
const long M = 5000000010;
/* finish defineing const */

int n, m;
long a[100];
long b[100];
long c[100];
long d[100];
int nex[100];

long leng(int i, int j)
{
    return (abs(a[i] - c[j]) + abs(b[i] - d[j]));
}

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < m; i++)
    {
        cin >> c[i] >> d[i];
    }
    // input

    int c = -1;
    for (int i = 0; i < n; i++)
    {
        long l = M;
        long tmp;
        for (int j = 0; j < m; j++)
        {
            tmp = leng(i, j); // i番目の学生がj番目のチェックに
            if (tmp < l)
            {
                l = tmp;
                nex[i] = j + 1;
            }
        }
    }

    for (int i = 0; i < n; i++)
    {
        cout << nex[i] << endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int H, W;

int g[27][27];

bool solve(vector<string> s){
	for(char c='A';c<='Z';c++){
		int x1=W,x2=-1,y1=H,y2=-1;
		REP(y, H)REP(x, W) if(s[y][x] == c){
			chmin(x1, x);
			chmin(y1, y);
			chmax(x2, x);
			chmax(y2, y);
		}
		if(x2 == -1) continue;
		for(int y=y1;y<=y2;y++)for(int x=x1;x<=x2;x++){
			if(s[y][x] == '.') return true;
			if(s[y][x] != c) g[c-'A'][s[y][x]-'A'] = 1;
		}
	}
	
	return false;
}

bool check(){
	int n =27;
	REP(k, n)REP(i, n)REP(j, n) g[i][j] |= g[i][k] & g[k][j];
	REP(i, n) if(g[i][i]) return true;
	return false;
}

main(){
	int n;
	cin >> n;
	while(n --){
		memset(g, 0, sizeof(g));
		cin >> H >> W;
		vector<string> s(H);
		REP(i, H) cin >> s[i];
		cout << (solve(s) || check() ? "SUSPICIOUS" : "SAFE") << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#include<stdio.h>
char s[55][55];
int main()
{
    int h,w,i,j,flag=1;
    scanf("%d%d",&h,&w);
    for(i=0;i<h;i++)
    {
          scanf("%s",&s[i]);
    }
    for(i=0;i<=h;i++)
    {
        for(j=0;j<h;j++)
        {
           if(s[i][j]=='#')
           {
               if(s[i-1][j]=='.'&&s[i][j-1]=='.'&&s[i+1][j]=='.'&&s[i][j+1]=='.')
                flag=0;
           }
        }
    }
    if(flag==0)
        printf("No");
    else
        printf("Yes");
    return 0;
}

Measured memory_bytes: 128
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}
int a[MAXN];


int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt();
    for (int i = 1; i <= n; i++) {
    	a[i] = readInt();
    }
    int len = 0;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
		if (a[i] == a[i - 1]) {
			len ++;
		} else {
			ans += (len >> 1);
			len = 1;
		}
	}
	ans += (len >> 1);
			
	cout << ans;
    return 0;
}

Measured memory_bytes: 256
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i

is_odd = false
if n.odd?
  is_odd = true
  n -= 1
end

ans = []
1.upto(n) do |i|
  (i+1).upto(n) do |j|
    if i != j && i + j != n + 1
      ans.push [i, j]
    end
  end
end

if is_odd
  1.upto(n) do |i|
    ans.push [i, n+1]
  end
end

puts ans.size
ans.each do |line|
  puts line.join(' ')
end

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

int main() {
  int64_t n;
  cin>>n;
  vector<int64_t> a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  int64_t count=0;
  for(int i=0;i<n;i++){
    if(a.at(i)%2==0){
      while(a.at(i)%2==0){
        a.at(i)/=2;
        count++;
      }
    }
  }
  cout<<count;
}

Measured memory_bytes: 384
N = int(input())
H = list(map(int, input().split()))
res = 'Yes'
for i in range(N-1):
    if H[i] < H[i+1]:
        H[i+1] -= 1
    elif H[i+1] - H[i] == 0:
        continue
    else:
        res = 'No'
        break
print(res)

Measured memory_bytes: 14396
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            string input = Console.ReadLine();

            for (int i = input.Length - 1; i >= 0; i--)
            {
                sb.Append(input[i]);
            }
            Console.WriteLine(sb);
        }
    }
}

Measured memory_bytes: 8772
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n,cnt;
    cin>>n;
    for(int i=6;i>-1;i--)
    {
 
      if((int)(n/pow(10,i))!=0)
        {cnt=i+1;
        //cout<<n/pow(10,i)<<endl;
        break;
        }
    }
    switch(cnt)
    {
      case 1:cout<<n;
            break;
      case 2:cout<<"9";
            break;
      case 3:cout<<n-90;
            break;
    case 4:cout<<"909";
            break;
    case 5:cout<<n-9090;
            break;
    case 6:cout<<"90909";
            break;
    }
    //cout<<cnt;
    return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    ll sum = 0;
    rep(i, N) {
        cin >> A[i];
        sum += A[i];
    }

    set<int> Yakusu;
    for (int i = 1; i * i <= sum; i++) {
        if (sum % i == 0) {
            Yakusu.insert(i);
            Yakusu.insert(sum / i);
        }
    }

    int ans = 1;
    for(int x:Yakusu){
      vector<int> mods(N);
      rep(i,N) mods[i] = A[i]%x;
      // 1 15 9 9 5 3 →7で割った余りを取って→ 1 1 2 2 5 3 みたいな

      sort(all(mods)); 
      // 1 1 2 2 3 5 みたいな。
      // この場合は、各数値から合計14回引けば、全部割り切れる。
      // でも、足したり引いたりして帳尻を合わせないといけないので、
      // 引くだけはだめ。

      int total = accumulate(all(mods),0);
      // 余りを足し上げたtotalは、必ずxで割れる。→xは全体の約数だから。

      int left = N - total / x;
      // 左から何個目までを引くかを決める。

      int k = 0;
      rep(i,left) k+=mods[i];
      if(k<=K) ans = max(ans,x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/**
 *    author:  Taichicchi
 *    created: 20.09.2020 18:38:14
 **/

#include <bits/stdc++.h>

#include <algorithm>
#include <atcoder/all>
#include <iostream>
#include <vector>

using namespace std;
using namespace atcoder;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int main() {
    int N, Q;

    cin >> N >> Q;

    dsu d(N);

    rep(i, Q) {
        int t, u, v;
        cin >> t >> u >> v;

        if (t == 0) {
            d.merge(u, v);
        } else {
            if (d.same(u, v)) {
                cout << 1 << endl;
            } else {
                cout << 0 << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 4024
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;
#pragma endregion

#pragma region const
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#pragma endregion

#pragma region util
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}
#pragma endregion

#pragma region init
struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

int main()
{
	i64 X,Y;
	cin >> X >> Y;
	cout << X+Y/2 << endl;
	return 0;
}


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

int main() {
  int k;
  string s;
  cin >> k >> s;
  if (s.length() <= k) {
    cout << s << endl;
  } else {
    cout << s.substr(0, k) + "..." << endl;
  }
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main(){
    string inp;
    int n;
    cin >> n;
    while(n--){
        cin >> inp;
            inp.append(1, '0');
        bool head = true;
        char headNum;
        int count;
        for(int i = 0; inp[i]; i++){
            if((inp[i - 1] == '0' && inp[i] == '0') || (i == 0 && inp[i] == '0')) continue;
            if(head){
                headNum = inp[i];
                count = 0;
                head = false;
            }
            if(headNum == inp[i] && headNum != '0'){
                count++;
            }else{
                char outp;
                if(headNum == '1'){
                    count %= 5;
                    if(count == 0) count = 5;
                    if(count == 1) outp = '.';
                    else if(count == 2) outp =',';
                    else if(count == 3) outp ='!';
                    else if(count == 4) outp ='?';
                    else if(count == 5) outp =' ';
                }else if(headNum >= '2' && headNum <= '6'){
                    count %= 3;
                    if(count == 0) count = 3;
                    outp = 'a' - 1 + count + (headNum - '2') * 3;
                }else if(headNum == '7'){
                    count %= 4;
                    if(count == 0) count = 4;
                    outp = 'p' - 1 + count;
                }else if(headNum == '8'){
                    count %= 3;
                    if(count == 0) count = 3;
                    outp = 't' - 1 + count;
                }else if(headNum == '9'){
                    count %= 4;
                    if(count == 0) count = 4;
                    outp = 'w' - 1 + count;
                }
                cout.put(outp);

                if(inp[i] - '0'){
                    i--;
                }
                head = true;
                continue;
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI 				acos(-1)
#define mp				make_pair
#define pb				push_back
#define all(a)			(a).begin(), (a).end()
#define sz(a)			a.size()
#define srt(a)			sort(all(a))
#define mem(a, h)		memset(a, (h), sizeof(a))
#define f 				first
#define s 				second
#define MOD1			998244353
#define fore(i, b, e)	for(int i = b; i < e; i++)
#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
using namespace __gnu_pbds;

typedef long long 		ll;
typedef unsigned long long 		ull;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//find_by_order kth largest  order_of_key <
const int tam = 100010;
const int MOD = 1e9+7;
const double EPS = 1e-9;
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	//freopen("qwe.txt", "r", stdin);
	//freopen("asd.txt", "w", stdout);
	string s; int k;
	cin>>s>>k;
	if(k > 100)
	{
		fore(i, 0, s.size())
			if(s[i] != '1')
			{
				cout<<s[i]<<'\n';
				return 0;
			}
	}
	int pos = 0;
	fore(i, 0, s.size())
		if(s[i] != '1')
		{
			pos = i;
			break;
		}
	if(pos < k)
		cout<<s[pos]<<'\n';
	else
		cout<<1<<'\n';
	return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};

int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n;
    double sum=0;
    cin>>n;
    while(n--){
        double x;
        cin>>x;
        sum+=(1.0/x);
    }
    sum=(1.0)/sum;
    cout<<setprecision(10)<<fixed<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
	int n; string s;
    cin >> n >> s;
	
    int ans = 0;
    for(int i = 0; i < n; ++i){
                int j =0;
		for(j = i+1; j < n; ++j){
			if(s[i] != s[j]){break;}
        }
        i = j-1;
        ++ans ;
    }
    
    cout << ans << endl;
    return 0;
}

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

int main() {
  int k, a, b;
  cin >> k;
  cin >> a >> b;

  if (k == 1) {
    printf("OK");
    return 0;
  }

  for (int i = a; i <= b; ++i) {
    if (i % k == 0) {
      printf("OK");
      return 0;
    }
  }
  printf("NG");
  return 0;
}

Measured memory_bytes: 3684
#include <stdio.h>

int main(void) {
  int w,h,i,j,k,a[100],b[100];
  char grid[100][101];
  scanf("%d %d",&h,&w);
  getchar();
  for (i = 0;i < h;i++) {
      fgets(grid[i],w + 2,stdin);
  }
  for (i = 0;i < h;i++) {
      a[i] = 1;
      for (j = 0;j < w;j++) {
            if (grid[i][j] == '#') {
                a[i] = 0;
                break;
            }
      }
    }
    for (i = 0;i < w;i++) {
        b[i] = 1;
        for (j = 0;j < h;j++) {
              if (grid[j][i] == '#') {
                  b[i] = 0;
                  break;
              }
        }
      }
  for (i = 0;i < h;i++) {
      if (a[i] == 0) {
          for (j = 0;j < w;j++) {
              if(b[j] == 0) putchar(grid[i][j]);
          }
          printf("\n");
      }
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = vector<int>;
using Vlli = vector<lli>;
using Wint = vector<Vint>;
using Wlli = vector<Vlli>;
using pii = pair<int, int>;
using pll = pair<lli, lli>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1), make_pair(0, -1)};
constexpr char BR = '\n';

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())


template <class T> inline int argmin(vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}
inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res = "";
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
  std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


int main(void){
  int n; cin >> n;
  string s; cin >> s;
  int count_red = 0;
  vREP(ch, s) if(ch == 'R') count_red++;
  if(2 * count_red > n) cout << "Yes" << BR;
  else cout << "No" << BR;
  return 0;
}

Measured memory_bytes: 888
n,m=map(int,input().split())
d=[[float('inf') for i in range(n)] for i in range(n)]
r=[list(map(int,input().split())) for i in range(m)]

def wf(d):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j]=min(d[i][j],d[i][k]+d[k][j])
    return d


for u,v,c in r:
    u,v=u-1,v-1
    d[u][v]=d[v][u]=c

wf(d)

cnt=0
for u,v,c in r:
    u,v=u-1,v-1
    if d[u][v]!=c:
        cnt+=1
print(cnt)

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

namespace CF2016
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int N = int.Parse(str[0]);
            int M = int.Parse(str[1]);
            int K = int.Parse(str[2]);
            int f = 0;
            for(int i = 0; i <= N;i++)
            {
                if (N - 2 * i == 0)
                {
                    if (M * i == K)
                    {
                        f++;
                        break;
                    }
                }else if ((K - M * i) / (N - 2 * i) >= 0 && (K-M*i)/(N-2*i)<=M&& (K - M * i) % (N - 2 * i) == 0)
                {
                    f++;
                    break;
                }
            }
            if (f == 0)
            {
                Console.WriteLine("No");
            }
            else
            {
                Console.WriteLine("Yes");
            }

        }
    }
}


Measured memory_bytes: 13140
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def lcm(a, b):
    return a * b // gcd (a, b)

temp=input().split()
A=int(temp[0])
B=int(temp[1])
C=int(temp[2])
D=int(temp[3])

x=B//C-(A-1)//C
y=B//D-(A-1)//D
s=lcm(C, D)
z=B//s-(A-1)//s

print(int(B-A+1-x-y+z))

Measured memory_bytes: 38384
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
	
def main():
	S = input()
	S = list(S)
	K = int(input())
	
	if len(S) == 1:
		print(S[0])
		sys.exit()
		
	tmp = -1
	for i, val in enumerate(S):
		if int(val) != 1:
			tmp = int(i)+1
			break
	
	if K >= tmp:
		print(S[tmp-1])
	else:
		print(1)
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 12176
//**KEEP IT SHORT AND SIMPLE**
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FILES freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define REP(i,a,b) for (int i = a; i < b; i++)
#define NL '\n'
#define F first
#define S second
#define dot(a, b) (conj(a) * (b)).real()
#define cross(a, b) (conj(a)* (b)).imag()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef bool bl;
typedef vector < vector<long long> > vvl;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
typedef map <long long, long long> mll;
typedef map <long long, bool> mlb;
typedef priority_queue<long long, vector<long long>, greater<long long> > minPq;
typedef tuple<ll, ll, ll> line;
typedef complex<double> point;
const double pi = 2 * acos(0.0);
const int OO = 0x3f3f3f3f;
int main()
{
    IO
    string s;
    cin >> s;
    int a = (s[0] - '0') * 10 + (s[1] - '0');
    int b = (s[2] - '0') * 10 + (s[3] - '0');
    if(a <= 12 && a && (b > 12 || !b))
        cout << "MMYY";
    else if(b <= 12 && b && (a > 12 || !a))
        cout << "YYMM";
    else if(a <= 12 && a && b <= 12 && b)
        cout << "AMBIGUOUS";
    else
        cout << "NA";
    return 0;
}


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

using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ldouble = long double;
 
const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;

string res;

int main()
{
    vector<ll> a(3);
    for (ll i = 0; i < 3; i++)
    {
        cin >> a[i];
    }

    sort(all(a));

    if (a[0] == 5 & a[1] == 5 && a[2] == 7)
    {
        println("YES");
    }
    else
    {
        println("NO");
    }
    
}

Measured memory_bytes: 3560
import bisect

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

A = sorted(A)

ans1 = A[-1]

ind = bisect.bisect_left(A, ans1/2)


c = float("inf")
for i in range(max(0,ind-1), min(N-1,ind+2)) :
    calc = abs(ans1/2 - A[i])
    if calc < c :
        ans2 = A[i]
        c = calc
print(ans1,ans2)
    

Measured memory_bytes: 14052
from collections import Counter
#N, K = map(int, input().split( ))
#L = list(map(int, input().split( )))
N = int(input())
A = list(map(int, input().split( )))
Q = int(input())
Sum = sum(A)
#Counterなるものがあるらしい
coun = Counter(A)
#Q個の整数の組(B,C)が与えられてB \to Cとして合計を計算
#合計は(Ci-Bi)*(A.count(Bi))変化する.
for _ in range(Q):
  b, c = map(int, input().split( ))
  Sum += (c-b)*coun[b]
  coun[c] += coun[b]
  coun[b] = 0
  print(Sum)
  # replaceするとタイムエラーになるのか…
  #  A = [c if a == b else a for a in A]

Measured memory_bytes: 24092
end = True

while end:
    data = input().split()
    data1 = int(data[0])
    data2 = int(data[1])
    if data1 == 0 and data2 ==0:
        end = False
    elif data1 <= data2:
        print(data1, data2)
    else:
        print(data2,data1)

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

int main() {
  int N;
  string A, B, C;
  cin >> N;
  cin >> A >> B >> C;
  int ans = 0;
  
  for(int i=0; i<N; i++) {
    ans += 2;
    if (A[i] == B[i])
      ans--;
    if (B[i] == C[i])
      ans--;
    if (A[i] == C[i])
      ans--;
    if (A[i] == B[i] && B[i] == C[i])
      ans++;
  }
  
  cout << ans << endl;
  
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int WWW = 0;WWW < (n);WWW++)cerr << v[WWW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

int x[80][111111];
ll diff[111111];

int main(){
	
	ll n;cin >> n;
	vector<ll> v(n);
	REP(i,n)cin >> v[i];
	ll m,k;cin >> m >> k;
	vector<ll> a(m);
	REP(i,m){
		cin >> a[i];
	}
	
	REP(i,n)x[0][i] = i;
	REP(i,m)swap(x[0][a[i]],x[0][a[i]-1]);
	
	for(int i = 0;i < 69;i++){
		REP(j,n){
			x[i+1][j] = x[i][x[i][j]];
		}
	}
	
	for(int i = 1;i < n;i++){
		int tmp = i;
		for(ll j = 0;j < 60;j++){
			if(k & (1LL << j)){
				tmp = x[j][tmp];
			}
		}
		diff[i] = v[tmp] - v[tmp-1];
	}

	diff[0] = v[0];
	cout << v[0] << endl;
		
	for(int i = 1;i < n;i++){
		diff[i] += diff[i-1];
		cout << Decimal << (double)diff[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 37504
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

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

   int cnt = 0;
   rep(i,n){
      int h;
      cin >> h;

      if(k <= h) cnt++;
   }

   cout << cnt << endl;

   return 0;
}

Measured memory_bytes: 256
require 'prime'
require 'set'
require 'tsort'
include Math
ALP = ('a'..'z').to_a
INF = 0xffffffffffffffff
def max(a,b);              a > b ? a : b                              end
def min(a,b);              a < b ?  a : b                             end
def swap(a,b);             a, b = b, a                                end
def gif;                   gets.to_i                                  end
def gff;                   gets.to_f                                  end
def gsf;                   gets.chomp                                 end
def gi;                    gets.split.map(&:to_i)                     end
def gf;                    gets.split.map(&:to_f)                     end
def gs;                    gets.chomp.split.map(&:to_s)               end
def gc;                    gets.chomp.split('')                       end
def pr(num);               num.prime_division                         end
def pr?(num);              Prime.prime?(num)                          end
def digit(num);            num.to_s.length                            end
def array(s,ini=nil);      Array.new(s){ini}                          end
def darray(s1,s2,ini=nil); Array.new(s1){Array.new(s2){ini}}          end
def rep(num);              num.times{|i|yield(i)}                     end
def repl(st,en,n=1);       st.step(en,n){|i|yield(i)}                 end

a,b,c,x,y=gi
ans = []
ans << a*x + b*y
ans << x*2*c + max(0,y-x)*min(b,2*c)
ans << max(0,x-y)*min(a,2*c) + y*2*c
ans << x*a + y*b
puts ans.min



Measured memory_bytes: 2300
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
typedef pair<int, int> P;

int main(){
    int n; cin >> n;
    int p[n];
    rep(i, n) cin >> p[i];

    int count = 0;
    rep(i, n-2){
        int mx_p = max(p[i], max(p[i+1], p[i+2]));
        int mn_p = min(p[i], min(p[i+1], p[i+2]));
        if(mx_p!=p[i+1]&&mn_p!=p[i+1]) count++;
    }

    out(count);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld long double
using namespace std;
int main() {
    int n;cin>>n;
    ld a[n];

    for(int i = 0; i < n; i++)  cin>>a[i];

    sort(a,a+n);
    // reverse(a,a+n);
    for(int i = 0; i < n-1; i++)    a[i+1] = (a[i]+a[i+1])/2.0;

    cout<<a[n-1]<<"\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  int N; cin>>N;
  string S; cin>>S;
  if(S.size()%2==1){
    cout<<"No"<<endl;
  }
  else{
    int ans=0;
    for(int i=0; i<N/2; i++){
      if(S.at(i)!=S.at(N/2+i)){
        ans=1;
      }
    }
    if(ans==1){
      cout<<"No"<<endl;
    }
    else{
      cout<<"Yes"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>
#include <climits>

using namespace std;

double sq(double x){return x*x;}

int t[] = {
	0,
	31,
	29,
	31,
	30,
	31,
	30,
	31,
	31,
	30,
	31,
	30,
	31
};

string b[] = {
	"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday"
};

int main(){
	for (int i = 0; i < 12; i++)
	{
		t[i+1] += t[i];
	}
	int m,d;
	while(~scanf("%d %d",&m,&d),(m||d)){
		int x = t[m-1] + d + 2;
		cout << b[x % 7] << endl;
	}

	return 0;
}

Measured memory_bytes: 0
###
### atcorder test program
###

import sys

### math class
class math:
    ### pi
    pi = 3.14159265358979323846264338

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Prime number search
    def Pnum(self, a):
        if a == 1: return False
        for i in range(2,int(a**0.5)+1):
            if a % i == 0:
                return False
        return True

    ### Circle area
    def caria(self, r):
        return r*r*self.pi

math = math()

### input sample
#i = input()
#A, B, C = [x for x in input().split()]
#inlist = [int(w) for w in input().split()]
#R = float(input())
#A = [int(x) for x in input().split()]
#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

#A, B, C = [int(x) for x in input().split()]

def get_input():
  N = []
  while True:
    try:
      N.append(input())
      #N.append(int(input()))
    except EOFError:
      break
  return N
 

while True:
    N = int(input())
    if N == 0:
        break
    t = 0
    for i in range(1, 7):
        t += N//(5**i)
        #print(i,N//(i**5))
    print(t)






Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  int N, K;
  cin >> N >> K;
  int i = 0;
  while(N >= K){
    N /= K;
    i++;
  }
  cout << i+1 << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
// const int mod=998244353;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int k;
    cin>>k;
    int ans=0;
    REP(a,1,k)REP(b,1,k)REP(c,1,k)ans+=gcd(a,gcd(b,c));
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

namespace Header_Template {
  typedef long long li;
  template<class T>inline void read(T &x) {
    x = 0;
    T tmp = 1;
    char c = getchar();
    while ((c < '0' || c > '9') && c != '-') c = getchar();
    if (c == '-') tmp = -1, c = getchar();
    while (c >= '0' && c <= '9')
      x = (x << 1) + (x << 3) + c - '0', c = getchar();
    x *= tmp;
  }
  template<class T>inline void Max(T &x, T y) {
    if (y > x) x = y;
  }
  template<class T>inline void Min(T &x, T y) {
    if (y < x) x = y;
  }
}
using namespace Header_Template;

const int Mod = 1e9 + 7;
const int N = 1e5 + 10;

namespace Tree {
  int n, c[N];
  void Init(int nn) {
    n = nn + 1;
    memset(c, 0, sizeof c);
  }

  inline int lowbit(int x) { return x & -x; }
  void Add(int x, int val) {
    ++x;
    for (; x <= n; x += lowbit(x)) {
      c[x] += val;
      if (c[x] >= Mod) c[x] -= Mod;
    }
  }
  int Query(int x) {
    ++x;
    int res = 0;
    for (; x; x -= lowbit(x)) {
      res += c[x];
      if (res >= Mod) res -= Mod;
    }
    return res;
  }
}

int n, m, a[N], b[N];
int v[N], f[N];

pair<int, int> c[N];
inline bool cmp(pair<int, int> x, pair<int, int> y) {
  return x.first < y.first || (x.first == y.first &&
                               x.second > y.second);
}

int main(void) {
  read(n), read(m);
  for (int i = 1; i <= n; ++i) read(a[i]);
  for (int i = 1; i <= m; ++i) read(b[i]);
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] < b[1] || a[i] > b[m]) continue;
    int p = lower_bound(b + 1, b + 1 + m, a[i]) - b;
    c[++cnt] = {a[i] - b[p - 1], b[p] - a[i]};
    v[cnt] = b[p] - a[i];
  }
  sort(v + 1, v + 1 + cnt);
  int nn = unique(v + 1, v + 1 + cnt) - v - 1;
  sort(c + 1, c + 1 + cnt, cmp);
  cnt = unique(c + 1, c + 1 + cnt) - c - 1;
  for (int i = 1; i <= cnt; ++i)
    c[i].second = lower_bound(v + 1, v + nn + 1, c[i].second) - v;

  int ans = 1;
  Tree::Init(nn);
  for (int i = 1; i <= cnt; ++i) {
    int tmp = Tree::Query(c[i].second - 1) + 1;
    ans += tmp;
    if (ans >= Mod) ans -= Mod;
    Tree::Add(c[i].second, tmp);
  }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 2560
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0

for i in range(n):
    if (v[i] - c[i] > 0):
        ans += v[i] - c[i]
print(ans)


Measured memory_bytes: 9056
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N;
int nums[200009];

ll f(ll x,ll y,int idx){
    x+=nums[idx];
    y-=nums[idx];
    return abs(x-y);
}

auto calc(){
    vector<pair<ll,ll>> res(N);
    ll A=nums[0], B=0, md=0;
    rep1(i,N-1){
        B+=nums[i];
        while(abs(A-B)>f(A,B,md+1)){
            md++,A+=nums[md],B-=nums[md];
        }
        res[i]={max(A,B),min(A,B)};
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    rep(i,N) cin>>nums[i];
    
    
    auto L=calc();
    reverse(nums,nums+N);
    auto R=calc();
    reverse(all(R));
    
    ll mn=LLINF;
    rep1(i,N-3){
        ll tmp=max(L[i].first,R[i+1].first)-min(L[i].second,R[i+1].second);
        chmin(mn,tmp);
    }
    cout1(mn)
}

Measured memory_bytes: 7296
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dunk(n) cout << n << endl
#define all(v) v.begin(), v.end()
typedef long long ll;



int main() {
    int n, m;
    cin >> n >> m;
    n++;
    vector<vector<int>> g(n);
    int a, b;
    rep(i,m){
        cin >> a >> b;
        g.at(a).push_back(b);
        g.at(b).push_back(a);
    }
    
    map<int,int> dist;
    dist[1] = 0;
    
    queue<int> q;
    q.push(1);
    
    int cnt = 1;
    
    map<int,int> ans;
    
    while(!q.empty()){
        int size = int(q.size());
        rep(i,size){
            int x = q.front(); q.pop();
            for(int y: g.at(x)){
                if(!dist.count(y)){
                    dist[y] = cnt;
                    q.push(y);
                    ans[y] = x;
                }
            }
        }
        cnt++;
    }
    
    n--;
    
    if(dist.size() != n) dunk("No");
    else{
        dunk("Yes");
        for(int i=2; i<=n; i++) dunk(ans[i]);
    }
    
    return 0;
}



Measured memory_bytes: 22280
import java.util.Scanner;

// https://atcoder.jp/contests/abc164/tasks/abc164_b
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		sc.close();


		while(true) {
			c = c - b;
			if(c<=0) {
				System.out.println("Yes");
				return;
			}
			a = a - d;
			if(a<=0) {
				System.out.println("No");
				return;
			}

		}
	}
}


Measured memory_bytes: 27084
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T> void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}

inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}

// ll dx[4] = {1, 0, -1, 0};
// ll dy[4] = {0, 1, 0, -1};

signed main() {
	IOS();
	ll n, m, k;
	cin >> n >> m >> k;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			ll c = i * (m - j) + j * (n - i);
			if (c == k) {
				dump("Yes");
				return 0;
			}
		}
	}
	dump("No");
	return 0;
}

Measured memory_bytes: 256