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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<pi> vpi;
typedef vector<bool> vbool;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define forall(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define F0(i,n) for(ll i = 0; i < n; i++)
#define F1(i,n) for(ll i = 1; i <= n; i++)
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define per(i,a,b) for(int i = b-1; i >= a; i--)
#define FIN ios::sync_with_stdio(false);cin.tie(0);
#define db(x) cout<<#x<<" = "<<x<<"\n"
#define all(v) v.begin(),v.end()
#define modulo(a,b) ((a%b)+b)%b
#define F first
#define S second
#define INF 1000000010
#define eps 0.000000000001
#define mod 1000000007
template<class C> void mini(C&a, C b){ a=min(a, b);}
template<class C> void maxi(C&a, C b){a=max(a,b);}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

//=======================//
int n,m;
vvi adj;
vi dp;

int hacerDP(int v) {
	if(dp[v] != -1) return dp[v];
	dp[v] = 0;
	for (auto w : adj[v]) {
		maxi(dp[v], 1 + hacerDP(w));
	}
	return dp[v];
}

int main () {
	//FIN

	cin >> n >> m;
	dp = vi(n,-1);
	adj = vvi(n);
	F0(i,m) {
		int a,b; cin >> a >> b;
		a--; b--;
		adj[a].pb(b);
	}
	int res = 0;
	F0(i,n) {
		maxi(res, hacerDP(i));
	}
	cout << res << "\n";


	return 0;
}










Measured memory_bytes: 11088
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
#define PI 3.141592653589793238462643383279
typedef long long int ll;
typedef unsigned long long ull;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

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

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

    sort(l.rbegin(),l.rend());

    int cnt = 0;
    for(int i = 0; i < k; i++){
        cnt += l[i];
    }

    cout << cnt << endl;





}

Measured memory_bytes: 3596
#include<stdio.h>
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];
int color[MAX],d[MAX],f[MAX],tt;

void depth_First_Search_visit(int u){
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(M[u][v]==0) continue;
    if(color[v]==WHITE){
      depth_First_Search_visit(v);
    }
  }
  color[u]=BLACK;
  f[u]=++tt;
}

void depth_First_Search(){
  int u;
  for(u=0;u<n;u++) color[u]=WHITE;
  tt=0;

  for(u=0;u<n;u++) if(color[u]==WHITE)depth_First_Search_visit(u);
  for(u=0;u<n;u++) printf("%d %d %d\n",u+1,d[u],f[u]);
}


int main(){
  int u,v,k,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  depth_First_Search();
  return 0;
}
   

Measured memory_bytes: 636
/* ---------- 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>

/* ---------- 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;

const int MAX_N = 10000;
int N;
vector<int> table[MAX_N];
int C[MAX_N];

int idx = 0;
int values[MAX_N];

void dfs(int node, int par) {
    for (int next : table[node]) {
        if (next == par) continue;
        dfs(next, node);
    }

    values[node] = C[idx];
    idx++;
}

signed main() {
    cin >> N;
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        table[a].push_back(b);
        table[b].push_back(a);
    }

    for (int i = 0; i < N; i++) cin >> C[i];
    sort(C, C + N);

    int ans = 0;
    for (int i = 0; i < N - 1; i++) ans += C[i];
    cout << ans << endl;

    dfs(0, -1);

    for (int i = 0; i < N; i++) {
        cout << values[i];
        if (i != N - 1) cout << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1408
w, h, n = map(int, input().split())
ans = w * h
b = [[1 for i in range(w)] for j in range(h)]
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        for j in range(h):
            for k in range(x):
                if b[j][k] == 1:
                    b[j][k] = 0
                    ans -= 1
    elif a == 2:
        for j in range(h):
            for k in range(x, w):
                if b[j][k] == 1:
                    b[j][k] = 0
                    ans -= 1
    elif a == 3:
        for j in range(y):
            for k in range(w):
                if b[j][k] == 1:
                    b[j][k] = 0
                    ans -= 1
    elif a == 4:
        for j in range(y, h):
            for k in range(w):
                if b[j][k] == 1:
                    b[j][k] = 0
                    ans -= 1
print(ans)

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

int main() {
  int N,K;
  cin >> N >> K;
  
  vector<int> P(N);
  for(int i=0; i<N; i++)
    cin >> P.at(i);
  
  sort(P.begin(),P.end());
  
  int cost = 0;
  
  for(int i=0; i<K; i++)
    cost += P.at(i);
  
  cout << cost << endl;
  
}


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

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

    int count=0;
    while(a[i]%2==0){
      a[i] = a[i]/2;
      count++;
    }

    ans = min(ans, count);
  }

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


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

using namespace std; 
 
int main(void) 
{ 
  	cin.tie(0); 
 	ios::sync_with_stdio(false); 
  
  	string s;

  	getline(cin,s);

  	stringstream ss;
  	string token;

  	ss << s;

  	while(ss >> token)
  	{
  		cout << token[0];
  	}
  	cout << '\n';
  	
 	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;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
// #define INF __INT32_MAX__
#define INF 1e9
#define LINF __LONG_LONG_MAX__

int main() {
    int N; cin >> N;
    vl A(N);
    rep(i, N) {
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    vl sum(N);
    rep(i, N) {
        sum[i] = A[i];
    }
    rep(i, N - 1) {
        sum[i + 1] += sum[i];
    }

    int cnt = 1;
    for (int i = N - 1; i >= 1; i--) {
        if ((2 * sum[i - 1]) >=  A[i]) {
            cnt++;
        } else {
            break;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 4752
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    string x;
    cin >> x;
    ll mn = 1000;
    FOR(i,0,x.length()-2){
      if(mn > abs(753-stoi(x.substr(i,3))))
        mn = abs(753-stoi(x.substr(i,3)));
    }
    cout << mn << endl;

    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
# うまく行けば２こ一気に解消できるケースがある
# RRRRWWWWをつくれば良い，一番右のRと一番左のWを入れ替えていく
N = int(input())
C = input()
RL=[]
WL=[]
for i,c in enumerate(C):
    if c == 'R':
        RL.append(-i)
    else:
        WL.append(i)

import heapq
heapq.heapify(RL)
heapq.heapify(WL)
count = 0
if not RL or not WL:
    print(0)
    exit()

while True:
    r = heapq.heappop(RL)
    r = -r
    w = heapq.heappop(WL)
    if w>r:
        print(count)
        exit()
    heapq.heappush(RL,-w)
    heapq.heappush(WL,r)
    count+=1










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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
  int paSize = printArray.size();
  for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
  if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int Len[55], Pat[55];

int rec(int level, int layer) {
  if (level <= 0) return 1;

  if (layer <= 1) { // 1
    return 0;
  } else if (layer <= Len[level-1]+1) { // 2
    return rec(level-1, layer-1);
  } else if (layer <= Len[level-1]+2) { // 3
    return Pat[level-1] + 1;
  } else if (layer <= 2*Len[level-1]+2) { // 4
    return Pat[level-1] + 1 + rec(level-1, layer-Len[level-1]-2);
  } else { // 5
    return 2*Pat[level-1] + 1;
  }
}

signed main() {
  int N, X;
  cin >> N >> X;

  Len[0] = Pat[0] = 1;
  for (int i = 1; i <= N; i++) {
    Len[i] = Len[i-1] * 2 + 3;
    Pat[i] = Pat[i-1] * 2 + 1;
  }

  cout << rec(N, X) << endl;

  return 0;
}

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

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

    vector<int> a(m);
    for (int i = 0; i < m; i++) {a.at(i) = 0;}

    int k, tmp;
    for (int i = 0; i < n; ++i) {
        cin >>k;
        for (int j = 0; j < k; ++j) {
            cin >>tmp;
            a.at(tmp-1) += 1;
        }
    }

    int ret = 0;
    for (int i = 0; i < m; ++i) {
        if (a.at(i) == n) ++ret;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int H, M;
  cin >> H >> M;
  int H2, M2;
  cin >> H2 >> M2;
  int K;
  cin >> K;
  
  int W = H*60 + M;
  int W2 = H2*60 + M2;
  
  int a = W2 - W - K;
  
  cout << a << endl;
}

Measured memory_bytes: 3592
#include <cstdio>
#include <vector>
#include <string.h>
using namespace std;

const int MOD = 1e9 + 7;

int dp[2001][2001];

int dfs(int a, int b, int k) {
        if (a + b == 1) return dp[a][b] = 1;
        if (a + b == k) {
                if (a == k || b == k) return dp[a][b] = 0;
                return dp[a][b] = 1;
        }
        if (dp[a][b] > 0) return dp[a][b];
        int &res = dp[a][b];
        res = 0;
        for (int i = 0; i < k; i ++) if (a >= i && b >= k - i - 1) (res += dfs(a - i, b - (k - i - 1), k)) %= MOD;
        return res;
}

int main() {
        int n, m, k, ans = 0;
        scanf("%d%d%d", &n, &m, &k);
        memset(dp, -1, sizeof dp);
        for (int i = n; i > 0; i -= k - 1) for (int j = m; j > 0; j -= k - 1) (ans += dfs(i, j, k)) %= MOD;
        printf("%d\n", ans);
        return 0;
}


Measured memory_bytes: 16128
inputs = gets.split.map { |i| i.match(/\d+/) ? i.to_i : i.to_sym }
stack = []
inputs.each do |e|
  if e.is_a?(Integer)
    stack << e
  else
    a, b = stack.pop(2)
    stack << a.method(e).call(b)
  end
end
puts stack

Measured memory_bytes: 8672
import collections as co
S=input()
Q=int(input())
count=0
back=str()
front=str()
judge=True
for i in range(Q):
    a=list(map(str,input().split()))   
    if  int(a[0])==1:
        if judge==True:
            judge=False
        else:
            judge=True
    elif int(a[0])==2 and int(a[1])==1:
        if judge==True:
            front=a[2]+front
        if judge==False:
            back=back+a[2]
    else:
        if judge==True:
            back=back+a[2]
        if judge==False:
            front=a[2]+front
    a.clear
if judge==True:
    S=front+S+back
if judge==False:
    S=front+S+back
    S=S[::-1]
print(S)

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

int main(){
    string s;
    cin >> s;

    int count = 0, ans = 0;
    for(int i=0;i<s.size();i++){
        if(s.at(i)=='A'||s.at(i)=='C'
        ||s.at(i)=='G'||s.at(i)=='T'){
            count++;
        }
        else{
            count = 0;
        }
        ans = max(count, ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
struct pos { double x, y; };
double dir(pos p1, pos p2) { return sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2)); }
int main() {
    pos p[3];
    for (int i = 0; i < 3; i++) scanf("%lf %lf%*c", &p[i].x, &p[i].y);
    double a = dir(p[0], p[1]),
        b = dir(p[0], p[2]),
        c = dir(p[1], p[2]),
        s = (a + b + c) / 2.0,
        S = sqrt(s * (s - a) * (s - b) * (s - c)),
        r = 2 * S / (a + b + c),
        D = max(a, max(b, c));
    printf("%.10f\n", r * D / (2 * r + D));
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
    string str;
    int x = 1;
    int cnt= 0;
    int n;
    while(scanf("%d",&n),n){
        cin >> str;
        for(int i = 0;i < n; i++){
            string ans;
            for(int j = 0;j < str.size();){
                for(;;){
                    if(str[j] != str[j+x]){
                         if(x < 10){
                             x += 48;
                            ans += x;
                            ans += str[j];
                            x -= 48;
                            j += x;
                            x = 1;
                            break;
                         }
                         else{
                             int k = 0;
                             int w;
                             w = x;
                             for(k = 0;;){
                                 if(x < 10)break;
                                 else{
                                  x -= 10;
                                  k++;
                                 }
                             }
                             k += 48;
                             ans += k;
                             x += 48;
                             ans += x;
                             ans += str[j];
                             x = 1;
                             j += w;
                             break;
                         }
                    }
                    else{
                        ++x;
                    }
                }
            }
            str = ans;
        }
        cout << str << endl;
    }
    return 0;
}

Measured memory_bytes: 1364
#include <iostream>
#include <list>
#include <set>
#include <deque>
#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 = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;
template <class T>
using Vec = std::vector<T>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {std::make_pair(1, 0), std::make_pair(-1, 0), std::make_pair(0, 1), std::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())
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())



template <class T> inline int argmin(std::vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(std::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 BitI(int k){return 1 << k;}
inline lli BitL(int k){return 1L << k;}
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 a, b, c; scanf("%d%d%d", &a, &b, &c);
  printf("%d\n", max(0, (c / a)) * b);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.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 (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll X, K, D;
        cin >> X >> K >> D;
        X = abs(X);

        // ll tmp = X / D;
        // ll ans = abs(X - X / D * K);
        // if (tmp > K) {
        //         cout << X - D*K << endl;
        //         //cout << "s" << endl;
        //         return 0;
        // }

        // ll mn = abs(X - D * K);
        // rep(i, tmp, tmp+5) {
        //         if (i > K) break;
        //         chmin(mn, abs(X - D * i));
        // }

        // cout << mn << endl;

        ll steps = X / D;
        if (steps > K) {
                cout << X - D*K << endl;
                return 0;
        }

        ll pos = X - D * steps;
        ll r = K - steps;

        ll ans;
        if (odd(r)) {
                ans = abs(pos - D);
        } else {
                ans = pos;
        }

        cout << ans << endl;
}


Measured memory_bytes: 3608
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int A, B; std::cin >> A >> B; --A; --B;
  fin((B+A-1)/A);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

bool judge(string s){
    int sz = (int)s.size();
    if(s[0] == '0' or s[sz - 1] == '1')return 0;
    rep(i, (sz - 1) / 2)if(s[i] != s[sz - i - 2])return 0;
    return 1;
}

int main(){

    string s;
    cin >> s;

    if(!judge(s)){
        cout << -1 << endl;
        return 0;
    }

    int sz = (int)s.size();
    int diameter = sz;
    vector<int> edges(diameter, 0);

    if(sz % 2 == 0 and s[sz / 2 - 1] == '0'){
        diameter--;
        edges[0]++;
    }

    for(int i = (sz - 3) / 2; i >= 0; i--){
        if(s[i] == '0'){
            diameter -= 2;
            edges[diameter / 2 - i] += 2;
        }
    }

    int center = (diameter + 1) / 2;
    rep(i, diameter - 1){
        cout << i + 1 << ' ' << i + 2 << endl;
    }
    int now = diameter + 1;
    if(diameter % 2 == 1){
        rep(i, center){
            if(i == 0){
                rep(j, edges[0]){
                    cout << center << ' ' << now++ << endl;
                }
            } else {
                rep(j, edges[i] / 2){
                    cout << center + i << ' ' << now++ << endl;
                    cout << center - i << ' ' << now++ << endl;
                }
            }
        }
    } else {
        rep(i, center){
            rep(j, edges[i] / 2){
                cout << center + i << ' ' << now++ << endl;
                cout << center - i + 1 << ' ' << now++ << endl;
            }
        }
    }

}

Measured memory_bytes: 2048
program main
	implicit none
	integer :: i, j, n, minimum, summary, tmp
    integer, allocatable :: W(:)
    
    read(*, *) n
    allocate(w(n))
    read(*, *) (w(i), i = 1, n)
    summary = 0
    do i = 1, n
    	summary = summary + w(i)
    enddo
    tmp = 0
    minimum = summary
    do i = 1, n-1
    	tmp = tmp + w(i)
        if (abs(abs(summary - tmp) - abs(tmp)).lt.(minimum)) then
        	minimum = abs(abs(summary - tmp) - abs(tmp))
    	end if
    enddo
    write(*, *) minimum 
stop
end program main

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <bitset>
#include <list>
#include <iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
#define all(s) s.begin(),s.end()
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF = 1e+17;
const ll MODcdf = 998244353;
bool pairCompare(const P& firstElof,const P& secondElof){
    return firstElof.first<secondElof.first;
}
string A="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string a="abcdefghijklmnopqrstuvwxyz";
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll r,d,x;cin>>r>>d>>x;
    rep(i,0,10){
        x=r*x-d;
        cout<<x<<endl;
    }
}


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

int main()
{
    int i, k, n;
    cin>>k>>n;
    int a[n], d[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=n-1;i>0;--i)
        d[i-1]=(a[i]-a[i-1]);
    d[n-1]=k-a[n-1]+a[0];
    //for(i=0;i<n;i++)
      //  cout<<d[i]<<" " ;
    sort(d,d+n);
    cout<<k-d[n-1]<<endl;
    return 0;
}




Measured memory_bytes: 1920
#include<stdio.h>
int matrix[200][200];

int main(){

  
  int i,j,sumvirtex,virtexnum,connect,connectsum;

  /* for(i =0; i < 100; i++){

    for(j = 0; j < 100; j++){

      matrix[i][j] = 0;

    }

    }*/


  scanf("%d",&sumvirtex);

  for(i = 1; i <= sumvirtex; i++){

    scanf("%d",&virtexnum);
    scanf("%d",&connectsum);

    for(j = 1; j <= connectsum; j++){

      scanf("%d",&connect);

      matrix[i][connect] = matrix[i][connect] + 1;

    }
  }

  for(i =1; i<=sumvirtex; i++){

    for(j = 1; j <= sumvirtex; j++){

      if(j != sumvirtex){

      printf("%d ",matrix[i][j]);

      }

      else{

	printf("%d",matrix[i][j]);

      }

    }

    printf("\n");
    
  }

  return 0;

}

Measured memory_bytes: 680
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    if(abs(a-b) <= d && abs(b-c) <= d)
    {
        cout << "Yes" << endl;
    }
    else
    {
        if(abs(a-c) <= d)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
}


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

using namespace std;

int main ()

{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    string word;
    bool check1 = true, check2 = true, check3 = true;
    cin >> word;
    int n = (word.length()-1)/2;
    for ( int i = 0, j = word.length()-1; i < n; i++, j-- )
    {
        if(word[i] != word[j])
        {
            cout << "No\n";
            return 0;
        }
        if ( word[i] != word[n-1-i] )
        {
            cout << "No\n";
            return 0;
        }
        if ( word[j] != word[n+1+i] )
        {
            cout << "No\n";
            return 0;
        }
    }
    cout << "Yes\n";
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
#include <vector>
using namespace std;
typedef long long LL;

LL n,c1 = 0,c0 = 0,cnt[5] = {0};
LL p[400005] = {0},usd[400005] = {0};
vector <LL> G[2];

LL ec = 0,to[400005],nxt[400005],hed[200005] = {0};
void add_edge(LL f,LL t){
	++ ec; to[ec] = t; nxt[ec] = hed[f]; hed[f] = ec;
}

LL col[400005] = {0};
void dfs(LL u,LL f){
	for(LL i = hed[u];i;i = nxt[i]){
		LL v = to[i];
		if(v == f) continue;
		col[v] = 1 - col[u];
		dfs(v,u);
	}
}

int main(){
	ios::sync_with_stdio(false);
	LL u,v;
	cin >> n;
	for(LL i = 1;i < n;i ++){
		cin >> u >> v;
		add_edge(u,v);
		add_edge(v,u);
	}
	col[1] = 0; dfs(1,0);
	for(LL i = 1;i <= n;i ++) cnt[i % 3] ++;
	for(LL i = 1;i <= n;i ++){
		if(col[i] == 0){
			c0 ++;
			G[0].push_back(i);
		}
		if(col[i] == 1){
			c1 ++;
			G[1].push_back(i);
		}
	}
	if(c0 > c1){
		swap(c0,c1);
		swap(G[0],G[1]);
	}
	if(c0 <= cnt[0]){
		LL tot = 0;
		for(LL i = 0;i < G[0].size();i ++){
			v = G[0][i];
			p[v] = (i + 1) * 3; usd[(i + 1) * 3] = 1;
		}
		for(LL i = 1;i <= n;i ++){
			while(usd[tot + 1]) tot ++;
			if(!p[i]) p[i] = ++ tot;
		}
	}
	else{
		LL tot = 0;
		for(LL i = 0;i < G[0].size();i ++){
			v = G[0][i];
			if(i * 3 + 2 > n) break;
			p[v] = i * 3 + 2; usd[i * 3 + 2] = 1;
		}
		for(LL i = 0;i < G[1].size();i ++){
			v = G[1][i];
			if(i * 3 + 1 > n) break;
			p[v] = i * 3 + 1; usd[i * 3 + 1] = 1;
		}
		for(LL i = 1;i <= n;i ++){
			while(usd[tot + 1]) tot ++;
			if(!p[i]) p[i] = ++ tot;
		}
	}
	for(LL i = 1;i <= n;i ++) cout << p[i] << (i == n ? '\n' : ' ');
	return 0;
}

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

#define ll long long int
#define mp make_pair
#define ff first
#define ss second
#define fr(i,l,r) for (long long int i = l; i < r; ++i)
#define frr(i,l,r) for (long long int i = r; i >= l; --i) 
#define sortarr sort(arr,arr+n) //sorts array in asc order
#define sortarr_r sort(arr, arr+n, greater<long long int>()) //sorts array in desc order
#define make_set set<long long int>s //Set arranges in asc order
#define make_set_r set<long long int, greater <long long int>>s ////Set arranges in desc order
#define make_vector vector<long long int>v; 
#define pb push_back


// string size = str.size()

// stack <int> s; 
// queue <int> gquiz; 
// __gcd(m, n) 

// ll arr[10e5 + 5];
// char arr[10e5 + 5];

// printf ("%.9f\n",x);

bool compare(string &s1,string &s2) 
{ 
    return s1.size() < s2.size(); 
} 
void yes()
{
    cout << "YES" << endl;
}
void no()
{
    cout << "NO" << endl;
}


int main(void)
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll r;
    cin >> r;
    // double d = 22.0/7.0;
    printf ("%.2f\n",2*M_PI*r);
    return 0;
}   

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dist[1000][1000];
char a[1000][1000];

int main() {
  int h, w;
  cin >> h >> w;
  rep(i, h) rep(j, w) cin >> a[i][j];

  queue<pii> q;
  rep(i, h) rep(j, w) {
    if (a[i][j] == '#') {
      dist[i][j] = 0;
      q.push(mp(i, j));
    } else {
      dist[i][j] = INF;
    }
  }

  int ans = 0;
  while (!q.empty()) {
    int y = q.front().F;
    int x = q.front().S;
    q.pop();

    rep(i, 4) {
      int ny = y + dy[i];
      int nx = x + dx[i];
      if (!(0 <= nx && nx < w && 0 <= ny && ny < h)) continue;
      if (dist[ny][nx] <= dist[y][x] + 1) continue;
      dist[ny][nx] = dist[y][x] + 1;
      ans = max(dist[ny][nx], ans);
      q.push(mp(ny, nx));
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 13328
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
random_device rnd;
mt19937 mt(rnd());

const lld EPS = 1e-9;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7;
lld r, n;

lld calcdist(lld x, lld y)
{
    if (fabsl(x) >= r)
    {
        return 101010;
    }
    lld ok = -r;
    lld ng = y;
    while (fabsl(ok - ng) > EPS)
    {
        lld mid = (ok + ng) / 2;
        if ((x * x + (y - mid) * (y - mid)) < r * r)
        {
            ng = mid;
        }
        else
        {
            ok = mid;
        }
    }
    return ok + r;
}

int main()
{
    while (cin >> r >> n, r)
    {
        lld ans = 101010;
        map<int, lld> mp;

        rep(i, n)
        {
            int xl, xr;
            lld h;
            cin >> xl >> xr >> h;
            rep(j, xl, xr)
            {
                chmax(mp[j], h);
            }
        }
        lld cur = 0;
        rep(i, -20, 20)
        {
            lld x = i;
            lld y = min(mp[x], mp[x - 1]);
            chmin(ans, calcdist(x, y));
        }
        cout << fixed << setprecision(18) << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3276
import collections

N, M = map(int, input().split())

G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    G[b-1].append(a-1)
    G[a-1].append(b-1)

queue = collections.deque([0])
visited = [0]*N
visited[0] = 1
while queue:
    x = queue.popleft()
    for i in G[x]:
        if visited[i] == 0:
            visited[i] = x + 1
            queue.append(i)

print("Yes")
print(*visited[1:], sep="\n")

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

int a[100010];

int gcd(int x,int y){
	return x == 0 ? y : gcd(y % x, x);
}

int main(){
	int n,d,tmp,g,dic;
	cin>>n>>d;
	for(int i=1;i<=n;++i){
		cin>>tmp;
		if(i==1){
			g=abs(tmp-d);
			continue;
		} 
		dic=abs(tmp-d);
		g=gcd(dic,g);
	}
	cout<<g;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n;
  n=3;
  int a[n];
  ll ans=0;
  rep(i,0,n){
    cin>>a[i];

  }
  sort(a,a+n);
  rep(i,1,n){
    if(i>=1) ans+= abs(a[i]-a[i-1]);
  }
  cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3648
#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() {
  int x;
  cin >> x;

  int ans = 0;
  ans += x / 500 * 1000;
  x %= 500;
  ans += x / 5 * 5;

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

Measured memory_bytes: 3540
while 1:
    try:p,q=map(int,input().split())
    except:break
    a=[];b={};c=0;p%=q
    while p!=0 and p not in b:
        b[p]=c
        d,p=divmod(p*10,q)
        a+=[d];c+=1
    print(*a,sep='')
    if p!=0:print(' '*b[p]+'^'*(c-b[p]))

Measured memory_bytes: 7576
n = int(input())
A = list(input().split())

if (n - 1) % 2 == 0:
  top = [""] * ((n - 1) // 2)
  bottom = [""] * ((n - 1) // 2)
    
  t = (n - 1) // 2 - 1
  b = 0
  for i in range(1,n):
    if i % 2 == 1:
      bottom[b] = A[i]
      b += 1
    else:
      top[t] = A[i]
      t -= 1
else:
  top = [""] * ((n - 1) // 2 + 1)
  bottom = [""] * ((n - 1) // 2)
  
  t = (n - 1) // 2
  b = 0
  
  for j in range(1,n):
    if j % 2 == 1:
      top[t] = A[j]
      t -= 1
    else:
      bottom[b] = A[j]
      b += 1
      
print(*(top + [A[0]] + bottom))

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

using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
#define INF 1e9



int main(){
    string s,t; cin >> s >> t;
    string ans;
    ans +=t+s;
    
    cout << ans << endl;
    
   
    
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * f.cc: F - Division or Substraction
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

inline bool check(ll n, ll k) {
  while (n % k == 0) n /= k;
  return (n % k == 1);
}

/* main */

int main() {
  ll n;
  scanf("%lld", &n);

  int c = 0;
  ll m = n - 1;
  for (int p = 1; (ll)p * p <= m; p++)
    if (m % p == 0) {
      ll q = m / p;
      c += (p < q) ? 2 : 1;
    }
  c--;

  for (int p = 1; (ll)p * p <= n; p++)
    if (n % p == 0) {
      if (p > 1 && check(n, p)) c++;
      ll q = n / p;
      if (p < q && check(n, q)) c++;
    }

  printf("%d\n", c);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 string a,b,c; cin>>a>>b>>c;
  int x=a.size();
  int y=b.size();
  int z=c.size();
  int count=0;
  
  if(a[x-1]==b[0]) count++;
  if(b[y-1]==c[0]) count++;
  
  if(count==2) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int Adj[101];

int main()
{
  int i,j,n,u,k,c;

  scanf("%d",&n);

  for(i=1; i<=n; i++){
    c=0;
    scanf("%d%d",&u,&k);

    for(j=0; j<k; j++){
      scanf("%d",&Adj[j]);
    }

    for(j=1; j<=n; j++){
      if(j!=1)
	printf(" ");
      if(Adj[c] == j && c != k){
	printf("1");
	c++;
      }
      
      else
	printf("0");
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        string s, t;
        in >> s;
        in >> t;
        bool ans = false;
        int pos = 0;
        int len = t.size();
        for (int i = s.size() - len; i >= 0; i--) {
            int cnt = 0;
            for (int j = 0; i + j < s.size() && j < t.size(); j++) {
                cnt += s[i + j] == t[j] || s[i + j] == '?';
            }
            if (len == cnt) {
                pos = i;
                ans = true;
                break;
            }
        }
        if (ans) {
            for (int i = pos; i < pos + len; i++) {
                s[i] = t[i - pos];
            }
            for (int i = 0; i < s.size(); i++) {
                if (s[i] == '?') {
                    s[i] = 'a';
                }
            }
            out << s << '\n';
        }
        else {
            out << "UNRESTORABLE" << '\n';
        }
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int N;
  int coin[4] = { 10, 50, 100, 500 };
  bool first = true;
  while (cin >> N && N) {
    int budget[4], used[4] = {};
    cin >> budget[0] >> budget[1] >> budget[2] >> budget[3];
    int res = 20*20*20*20;
    for (int i=0; i<=budget[0]; i++) {
      int t0 = coin[0]*i;
      for (int j=0; j<=budget[1]; j++) {
        int t1 = coin[1]*j;
        for (int k=0; k<=budget[2]; k++) {
          int t2 = coin[2]*k;
          for (int l=0; l<=budget[3]; l++) {
            int t3 = coin[3]*l;
            int charge = (t0+t1+t2+t3) - N;
            if (charge < 0) continue;
            int num = 0;
            for (int m=3; m>=0; m--) {
              while (charge >= coin[m]) {
                num++;
                charge -= coin[m];
              }
            }
            if (res > budget[0]-i+budget[1]-j+budget[2]-k+budget[3]-l+num) {
              res = budget[0]-i+budget[1]-j+budget[2]-k+budget[3]-l+num;
              used[0] = i;
              used[1] = j;
              used[2] = k;
              used[3] = l;
            }
          }
        }
      }
    }
    if (first) first = false;
    else cout << endl;
    for (int i=0; i<4; i++) {
      if (used[i] > 0)
        cout << coin[i] << ' ' << used[i] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3024
N=int(input())
nums = [int(i) for i in input().split()]

def gcd(x, y):
    if x < y:
        x = x ^ y
        y = x ^ y
        x = x ^ y
    div = x % y
    while div != 0:
        x = y
        y = div
        div = x % y
    return y

memo = {}
memo[(0, 1)] = nums[0]
memo[(N-1, N)] = nums[N-1]

for i in range(2, N+1):
    memo[(0, i)] = gcd(memo[(0, i - 1)], nums[i-1])
    # print("{} {} memo:{}".format(0, i, memo[(0,i)]))


for i in reversed(range(0, N-1)):
    memo[(i, N)] = gcd(memo[(i + 1, N)], nums[i])
    # print("{} {} memo:{}".format(i, N, memo[(i,N)]))

res = 1
for i in range(1, N-1):
    res = max(res, gcd(memo[(0, i)], memo[(i+1, N)]))
    # print("gcd:{}".format(gcd(memo[(0, i)], memo[(i+1, N)])))

res = max(res, memo[(0, N-1)])
res = max(res, memo[(1, N)])

print(res)


Measured memory_bytes: 46272
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    N_kaijo=1
    for i in range(1,N+1):
        N_kaijo*=i

    x=[]
    y=[]
    for i in range(N):
        x_i,y_i=map(int,readline().split())
        x.append(x_i)
        y.append(y_i)
    
    res=0
    for i in range(N-1):
        for j in range(i+1,N):
            l=((x[j]-x[i])**2+(y[j]-y[i])**2)**0.5
            res+=l*2/N

    print(res)
if __name__=="__main__":
    main()

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

int p = 0;

void gcd(int x,int y){
  p++;
  if(y == 0){
    cout<<x<<' '<<p-1<<endl;
    return;
  }

  gcd(y,x%y);
}

int main(){

while(1){
  int x,y;
  cin >> x >> y;
  if(x == 0 && y == 0)break;
  if(x < y) swap(x,y);
  p = 0;
  gcd(x,y);
  //cout << x << " " << p-1 << endl;
  //int tmp =gcd(x,y,p);
  //cout <<  tmp << " " << p << endl;
}
  return 0;
}



Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int n,m=111,i;
  cin>>n;
  for(i=1;i<10;i++){
      if(n<=m*i)break;
  }

  cout<<m*i<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() 
{
  int a,b;
  cin >> a >> b;
  if(a > b){
    cout << "a > b" << endl;
  }else if(a < b){
    cout << "a < b" << endl;
  }else{
    cout << "a == b" << endl;
  }
  return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int tree[1000005];
int mod = 998244353;

void updateTree(int node, int start, int ends, int ind, int val)
{
    if(start == ends)
    {
        tree[node] = val;
        return;
    }
    int mid = (start+ends)/2;
    if(mid>=ind)
        updateTree(node*2, start, mid, ind, val);
    else
        updateTree(node*2+1, mid+1, ends, ind, val);
    tree[node] = max(tree[node*2], tree[node*2+1]);
}

int queryTree(int node, int start, int ends, int l, int r)
{
    if(start == ends || (start >= l && ends <= r))
        return tree[node];
    int mid = (start + ends) / 2;
    int p1 = 0, p2 = 0;
    if(mid>=l)
        p1 = queryTree(node*2, start, mid, l, r);
    if(mid < r)
        p2 = queryTree(node*2+1, mid+1, ends, l, r);
    return max(p1, p2);
}

int32_t main()
{
    int n;
    cin >> n;
    vector<pair<int, int> > v(n);
    for(int i=0; i<n; i++)
        cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end());
    vector<int> b(n);
    for(int i=0; i<n; i++)
        b[i] = v[i].first;

    vector<int> dp(n+1, 0);
    dp[n] = 1;
    for(int i=n-1; i>=0; i--)
    {
        int ind = lower_bound(b.begin(), b.end(), v[i].first + v[i].second) - b.begin();
        ind--;
        // cout << i << " " << ind << endl;
        if(ind > i)
        {
            int q = queryTree(1, 1, n, i+2, ind+1);
            // cout << " query " << q << endl;
            dp[i] = dp[i+1] + dp[q+1];
            dp[i] %= mod;
            updateTree(1, 1, n, i+1, q);
        }
        else
        {
            dp[i] = 2*dp[i+1];
            dp[i] %= mod;
            updateTree(1, 1, n, i+1, i);
        }
        // cout << dp[i] << endl;
    }
    cout << dp[0] << endl;
    return 0;
}


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

int main(){
  ll N, K, t, d;
  cin >> N >> K;
  P a[N];
  for(int i = 0; i < N; i++){
    cin >> t >> d;
    a[i] = P(d, t);
  }
  priority_queue<P, vector<P>, greater<P>> deque;
  priority_queue<P> adque;
  sort(a, a + N, greater<P>());
  bool used[N+1];
  fill(used, used+N+1, false);
  ll f_max[K+1];
  ll variety = 0, f_init = 0;
  for(int i = 0; i < K; i++){
    f_init += a[i].first;
    if(!used[a[i].second]){
      used[a[i].second] = true;
      variety++;
    } else deque.push(a[i]);
  }
  f_max[variety] = f_init + variety*variety;
  ll vb = variety, ans = f_max[vb];
  for(int i = K; i < N; i++) adque.push(a[i]);
  while(!adque.empty()){
    if(deque.empty()) break;
    ll a = adque.top().first;
    ll b = deque.top().first;
    t = adque.top().second;
    adque.pop();
    if(used[t]) continue;
    used[t] = true;
    f_max[variety + 1] = f_max[variety] + a - b + 2*variety + 1;
    ans = max(ans, f_max[variety + 1]);
    variety++;
    deque.pop();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4212
N = int(input())
a = [int(i) for i in input().split()]

friends = 0
for i in range(0,len(a)):
    if a[i] == -1 or a[i] == -2:
        continue
    if a[a[i] - 1] == (i+1) :
        friends += 1
        a[ (a[i] - 1) ] = -1
        a[i] = -1
print(int(friends))


Measured memory_bytes: 13880
#include<bits/stdc++.h>
using namespace std;
int vis[10];
bool check(int n)
{
    int i;
    while(n)
    {
       if(vis[n % 10])
       return false;
       n /= 10;
    }
    return true;
}
int main()
{
    int n,k,j;
    while(cin >> n >> k)
    {
        memset(vis,0,sizeof(vis));
        for(int i = 0;i < k;i++)
        {
            cin >> j;
            vis[j] = 1;
        }
        for(int i = n; ;i++)
        {
            if(check(i))
            {
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256