akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  ll N;
  cin>>N;
  vector<ll> A(N);
  vector<ll> P(N-1);
  vector<ll> Q(N-1);
  for(int i=0;i<N;i++) cin>>A.at(i);
  P.at(0)=A.at(0);
  for(int i=1;i<=N-2;i++) P.at(i)=gcd(P.at(i-1),A.at(i));
  Q.at(N-2)=A.at(N-1);
  for(int i=N-3;i>-1;i--) Q.at(i)=gcd(Q.at(i+1),A.at(i+1));
  ll m=max(P.at(N-2),Q.at(0));
  for(int i=0;i<=N-3;i++) m=max(m,gcd(P.at(i),Q.at(i+1)));
  cout<<m;
return 0;}

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

using namespace std;


int main(){
    string s1,s2;
    cin>>s1 >> s2;
    int cnt = 0;

    for(int i = 0; i < s1.length(); i++){
        if(s1[i] != s2[i]){
            cnt++;
        }
    }
    cout << cnt << endl ;
    return 0;

}

Measured memory_bytes: 3864
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;
int main() {
	int n; scanf("%d", &n);
	vector<int> arr(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &arr[i]);
		arr[i] -= (i + 1);
	}
	sort(arr.begin(), arr.end());
	ll b = arr[n/2], ans = 0;
	for (int i = 0; i < n; ++i) ans += abs(b - arr[i]);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1024
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
#include<utility>
#include<vector>
using namespace std;

const long mod = 1000000007;
const long indlim = 5368709119;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
long fact(long x) { if (x == 0) return 1; else return((fact(x - 1) * x) % mod); }
long mybase(long N, long B) { if (N == 0) return 0; string S = ""; while (N != 0) { string M = to_string(N % B); N -= N % B; N /= B; S = M + S; }return stol(S); }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long res = INT_MAX;
	long N; cin >> N;
	long W[1000]; for (int i = 0; i < N; i++) cin >> W[i];

	long a = 0, b = 0;

	for (int t = 1; t < N; t++) {
	    a = 0;
		b = 0;
        for (int j = 0; j < t; j++) a += W[j];
		for (int j = t; j < N; j++) b += W[j];
		res = min(res, abs(a - b));
	}

	cout << res << endl;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

string ss[]={"A","B","C"};

bool dfs(string s){
  if(s=="ABC")return true;
  if(s.length()<=3)return false;
  int n=s.length();

  bool used[3];
  bool ok=false;

  memset(used,0,sizeof(used));
  for(int j=0;j<n;){
    if(s.substr(j,3)=="ABC"){
      ok=true;
      j+=3;
    }else{
      used[s[j]-'A']=true;
      j++;
    }
  }
  if(!ok)return false;

  rep(i,3){
    if(used[i])continue;
    string ns;
    for(int j=0;j<n;){
      if(j<n-2&&s.substr(j,3)=="ABC"){
        ns+=ss[i];
        j+=3;
      }else{
        ns+=s[j];
        j++;
      }
    }
    if(dfs(ns)){
      return true;
    }
  }
  return false;
}

int main(){
	cin.sync_with_stdio(false);
  string s;
  cin>>s;
  if(dfs(s))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
	return 0;
}

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

int digit(long long x){
  int result=0;
  while(x>0){
    result++;
    x/=10;
  }
  return result;
}

int main(){
  long long N; cin >> N;
  int result=10000;
  for(int i=1; i<=sqrt(N); i++){
    if(N%i==0){
      result=min(result,max(digit(i),digit(N/i)));
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
import math

a,b,h,m=map(int,input().split())

hour_angle=0.5*(60*h+m)
minute_angle=6*m

diff_angle=abs(hour_angle-minute_angle)

angle=min(360-diff_angle,diff_angle)
cos_angle=math.cos(angle*(math.pi/180))

lenth=math.sqrt(a**2+b**2-(2*a*b*cos_angle))
print(lenth)

Measured memory_bytes: 9504
K = list(map(int,input()))

def f(i,cnt):
	if i == 3:
		if cnt == 7:
			return True
		else:
			return False

	if f(i+1, cnt+K[i+1]):
		ans.append("+")
		return True
	if f(i+1, cnt-K[i+1]):
		ans.append("-")
		return True
	
	

ans = []

f(0,K[0])

ans = ans[::-1]

for i in range(4):
	if i == 3:
		print(str(K[-1])+"=7")

	else:
		print(K[i], end="")
		print(ans[i], end="")





Measured memory_bytes: 3064
#include <cstdio>
#include <cmath>

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

template<typename T> void swap(T & x, T & y) { T t = x; x = y; y = t; return; }
template<typename T> T abs(T x) { return (0 <= x ? x : -x); }
template<typename T> T max(T a, T b) { return (b <= a ? a : b); }
template<typename T> T min(T a, T b) { return (a <= b ? a : b); }
template<typename T> bool setmin(T & a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T & a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, m;
LL dp[2][302][302][2];
const int MOD = 1000000007;

int main() {
	scanf("%d%d", &n, &m);
	
	int from = 0, to = 1;
	dp[to][1][1][0] = 1;
	inc(mm, m) {
		swap(from, to);
		
		inc1(i, n) {
		inc1(j, n) {
			dp[to][i][j][0] = 0;
			dp[to][i][j][1] = 0;
		}
		}
		
		inc1(i, n) {
		inc1(j, n) {
			LL zero = dp[from][i][j][0];
			LL  one = dp[from][i][j][1];
			
			(dp[to][i    ][j    ][0] += zero * j      ) %= MOD;
			(dp[to][i    ][j + 1][1] += zero * (i - j)) %= MOD;
			(dp[to][i + 1][j    ][1] += zero * (n - i)) %= MOD;
			(dp[to][i    ][i    ][0] +=  one * j      ) %= MOD;
			(dp[to][i    ][j    ][1] +=  one * (i - j)) %= MOD;
			(dp[to][i + 1][j    ][1] +=  one * (n - i)) %= MOD;
		}
		}
	}
	
	printf("%lld\n", dp[to][n][n][0]);
	
	return 0;
}


Measured memory_bytes: 3072
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };
#define X first
#define Y second
int N;
int A[200005];
ll D[200005];
int main(void) {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		scanf("%d", &A[i]);
		D[i] = D[i - 1] + A[i];
	}
	ll cnt = 0;
	// D[i] = D[j]인 (i,j)의 갯수
	sort(D, D + N + 1);
	ll samelen = 1;
	for (int i = 1; i <= N; i++) {
		if (D[i] == D[i - 1])
			samelen++;
		else {
			cnt += (samelen*(samelen - 1) / 2);
			samelen = 1;
		}
	}
	cnt += (samelen*(samelen - 1) / 2);
	printf("%lld", cnt);
}

Measured memory_bytes: 2560
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> s(a), t(b);
    for (auto& e : s) cin >> e;
    for (auto& e : t) cin >> e;
    
    vector<pair<pair<int, int>, int>> data(m);
    for (auto& e : data) {
        cin >> e.first.first >> e.first.second >> e.second;
    }
    
    int ans = *min_element(s.begin(), s.end()) + *min_element(t.begin(), t.end());
    
    for (auto e : data) {
        int i, j; tie(i, j) = e.first;
        i--; j--;
        int minu = e.second;
        int cost = s[i] + t[j] - minu;
        chmin(ans, cost);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cmath>
#include<bitset>
typedef long long ll;
#define PB	push_back
#define FOR(n)			for(int i = 0; i < n; ++i)
#define RFOR(n)			for(int i = n; i >= 0; --i)
#define FORR(start,end) for(int i = start; i < end; ++i)
#define COUT(n)			cout << n << " " << flush
#define vi(v)			vector<int> v
#define vii(v)			vector<pair<int,int>> v
#define pii(p)			pair<int,int> p
#define mii(m)			map<int, int> m
#define msi(m)			map<string, int, less<>> m
#define mmsi(m)			multimap<string, int, less<>> m
#define mkp(a,b)		make_pair(a,b)
#define ALL(obj)		obj.begin(), obj.end()
#define PI 3.141592
#define MOD 1e9+7
using namespace std;

void solve() {
	int k, x;
	cin >> k >> x;
	if (500 * k >= x)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <stdlib.h>
#include <tuple>
#include <iomanip>
#include <iterator>
#include <stdio.h>
#include <fstream>
#include <time.h>
using namespace std;
const double PI = 3.14159265358979323846;
const long long int MOD = 1000000000 + 7;

struct UnionFind {
    vector<int> parent;

    UnionFind(int N) : parent(N) {
        for (int i = 0; i < N; i++) {
            parent[i] = -1;
        }
    }

    int root(int i) {
        if (parent[i] < 0) {
            return i;
        }
        return (parent[i] = root(parent[i]));
    }

    bool unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx != ry) {
            parent[ry] += parent[rx];
            parent[rx] = ry;

            return true;
        }
        else {
            return false;
        }
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int treeSize(int x) {
        

        return -parent[root(x)];
    }
};

long long int modpow(long long int base, long long int pow, long long int mod) {
    if (pow == 1) {
        return base;
    }
    else if (pow == 0) {
        return 1;
    }

    if (pow % 2 == 0) {
        auto temp = modpow(base, pow / 2, mod);
        return (temp * temp) % mod;
    }
    else {
        return base * modpow(base, pow - 1, mod) % mod;
    }
}

long long int moddiv(long long int X, long long int Y, long long int mod) {
    auto fermatDiv = modpow(Y, mod - 2, mod);

    return (X * fermatDiv) % mod;
}

long long modCombination(long long left, long long right, long long int mod) {
    long long answer = 1;
    for (long long i = 0; i < right; i++) {
        answer = (answer * (left - i)) % mod;
        answer = moddiv(answer, (i + 1), mod);
    }

    return answer;
}

bool IsPrime(long long N) {
    if (N == 1) {
        return false;
    }
    for (long long i = 2; i * i <= N; i++) {
        if (N % i == 0) {
            return false;
        }
    }

    return true;
}



vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({ a, ex });
    }

    // 最後に残った数について
    if (N != 1) res.push_back({ N, 1 });
    return res;
}

long long euclid(long long a, long long b) {
    if (a > b) {
        long long temp = b;
        b = a;
        a = temp;
    }
    if (b % a == 0) {
        return a;
    }
    else {
        return euclid(a, b - a);
    }
}

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

    long double h = x / a / a;
    long double theta;
    if (a * a * b / 2 <= x) {
        theta = atan2l(2 * (b - h), a);
    }
    else {
        theta = atan2l(a * b * b, 2 * x);
    }

    cout << std::fixed << std::setprecision(15) << theta / PI * 180.0 << endl;
    return 0;
}

Measured memory_bytes: 256
<?php
define("MOD", 10**9+7);
fscanf(STDIN, "%d%d", $N, $M);

for($j = 2; $j <= $M; $j++){
    if($M%$j == 0){
        @$map[$j]++;
        $M/=$j;
        $j--;
    }
}
$product = 1;
foreach($map as $prime => $count){
    $product *= nCm($count + $N - 1, $count);
    $product %= MOD;
}
echo $product;

//足し算
function addm($a, $b){
    return ($a + $b) % MOD;
}
//引き算
function subm($a, $b){
    return ($a + MOD - $b) % MOD;
}
//掛け算
function mulm($a, $b){
    return ($a * $b) % MOD;
}
//割り算
function divm($a, $b){
    return mulm($a, powerm($b, MOD - 2));
}
//累乗
function powerm($a, $b){
    if($b == 0)return 1;
    if($b & 1)return (powerm($a, $b>>1)**2 % MOD) * $a % MOD;
    return powerm($a, $b>>1)**2 % MOD;
}
//階乗
function factorialm($a){
    if($a == 0)return 1;
    return factorialm($a - 1) * $a % MOD;
}
//順列
function nPm($n, $m){
    if($m == 0)return 1;
    return nPm($n, $m - 1) * ($n - $m + 1) % MOD;
}
//組み合わせ
function nCm($n, $m){
    static $memo;
    if(!isset($memo[$n][$m])){
        $m = min($m, $n-$m);
        $ret = divm(nPm($n, $m), factorialm($m));
        $memo[$n][$m] = $ret;
    }
    return $memo[$n][$m];
}

Measured memory_bytes: 4604
// Dāritys Morgho ban Rōvēgrie
// Math = ♥
// Sometimes it is people that no one imagines anything of who do things that no one can imagine
// After all this time? Always

#include <bits/stdc++.h>                        // uncomment before submission
//#include <ext/pb_ds/assoc_container.hpp>		// uncomment before submission
//#include <ext/pb_ds/tree_policy.hpp>			// uncomment before submission
//using namespace __gnu_pbds;					// uncomment before submission
using namespace std;
//<---------------------------------------------------Template----------------------------------------------------------->
#define int long long
#define ll long long
#define ld long double
const int INF = 1e15 + 7;
const int MAX = 1e5 + 7;
const int MOD = 1e9 + 7;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;                  // Vector of long long
typedef vector<vi> vvi;                 // Vector of vi
typedef vector<ii> vii;                 // Vector of pairs
typedef vector<vii> vvii;               // Vector of Vector of pairs
typedef vector<bool> vb;                // Vector of bool
#define pq priority_queue               // Max heap (To convert to min heap, use negative sign before every value)
#define ff first                        // For pairs
#define ss second                       // For pairs
#define pb push_back                    // Pushback to vector
#define mp make_pair                    // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()   // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//<----------------------------------------------------------------------------------------------------------------------->

vector<vector<ld> > f;
vector<ld> p;

ld solve(int s, int i)
{
    if (f[s][i] >= 0) return f[s][i];
    if (s == 1 && i == 1) return p[s];
    else if (s == 1 && i == 0) return (1 - p[s]);
    else if (s == 1) return 0;
    else if (s < 0 || i < 0) return 0;

    f[s][i] = solve(s - 1, i - 1) * p[s] + solve(s - 1, i) * (1 - p[s]);
    return f[s][i];
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;

    f.resize(n + 1, vector<ld>(n + 1, -2)), p.resize(n + 1);
    for (int i = 1; i <= n; i++) cin >> p[i];

    ld ans = 0;
    int x = n;
    while (x > n / 2)
        ans += solve(n, x), x--;

    printf("%0.9Lf\n", ans);
    return 0;
}



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

int main() {
    int k; cin >> k;
    vector<int> mod(k,0);

    int n = 7;
    int ans = 0;
    while(true){
        ans++;
        n %= k;
        mod[n]++;
        if(mod[0] > 0){
            break;
        }
        if(mod[n] > 1){
            ans = -1;
            break;
        }
        n *= 10;
        n += 7;
    }
    cout << ans << endl;
}

Measured memory_bytes: 7204
// 

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n;string s;cin>>n>>s;
    int r=0,w=0,ans=0;
    rep(i,0,n){
        if(s[i]=='R')r++;
        else w++;
    }
    rep(i,0,r){
        if(s[i]=='W')ans++;
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 3724
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())


int main(){
  ll l,r;
  cin>>l>>r;
  if(r-l>2019){
    cout<<0<<endl;
  }
  else{
    r%=2019;
    l%=2019;
    if(l>r){
      cout<<0<<endl;
    }
    else{
      int m=2019;
      FOR(i,l,r){
        FOR(j,i+1,r+1){
          m=min(m,(i*j)%2019);
        }
      }
      cout<<m<<endl;
    }
  }
}


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

int main() {
  
  string S, T;
  cin >> S >> T;
  
  int n = 1000;
  int n2 = 0;
  int L = T.size();
  int D = S.size() - T.size() +1;
  
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < L; j++) {
      if (T.at(j) != S.at(j+i)) {
        n2++;
      }
    }
    n = min(n,n2);
    n2 = 0;
  }

  cout << n << endl;    

return 0;
}      

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int K, X;
  cin >> K >> X;

  vector<int> v;
  for(int i=-1000000; i<=1000000; i++){
    if(abs(i-X) < K){
      v.push_back(i);
    }
  }

  rep(i,v.size()){
    if(i>0) cout << " ";
    cout << v[i];
  }
  cout << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
#define INF 800000000
#define MAX 1000

ll gcd(ll a,ll b){
  while(a%b!=0){
    ll tmp=a%b;
    a=b;
    b=tmp;
  }
  return b;
}

int main(){
  int N,M;
  cin>>N>>M;
  vector<ll> a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
    a.at(i)/=2;
  }
  int count=0;
  ll b=a.at(0);
  while(b%2==0){
    b/=2;
    count++;
  }
  bool flag=true;
  for(int i=0;i<N;i++){
    b=a.at(i);
    int count2=0;
    while(b%2==0){
      b/=2;
      count2++;
    }
    if(count2!=count){
      flag=false;
      break;
    }
  }
  ll lcm=1;
  for(int i=0;i<N;i++){
    lcm=lcm/gcd(lcm,a.at(i))*a.at(i);
    if(lcm>M){
      flag=false;
      break;
    }
  }
  if(flag){
    cout<<M/lcm-M/(2*lcm)<<endl;
  }else{
    cout<<0<<endl;
  }



}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
 
int main(){
  int a,b,c;
  
  cin >> a >> b >> c;
  int x,y,z;
  x = a;
  y = 0;
  z = 0;
  while (x <= b){
      y = c%x;
      if (y == 0){
          z = z + 1;
      }
      x = x + 1;
      y = 0;
  }
  cout << z << endl;
      

  return 0;		 
}
		   


Measured memory_bytes: 3060
n = int(input().split()[0])
c = list(map(int,input().split()))
dp = [ i for i in range(n+1) ]

for i in range(2,n+1):
    c2 = filter(lambda n:n<=i,c)
    for j in c2:
        if j <= i and dp[i-j] + 1 < dp[i]:
            dp[i] = dp[i-j] + 1

print(dp[n])

Measured memory_bytes: 7640
#include <bits/stdc++.h>
#define ll long long
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;

bool sortbysec(const pair<ll,ll> &a, 
              const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
} 

ll maxSubArraySum(ll a[], ll size) 
{ 
    ll max_so_far = INT_MIN, max_ending_here = 0; 
  
    for (ll i = 0; i < size; i++) 
    { 
        max_ending_here = max_ending_here + a[i]; 
        if (max_so_far < max_ending_here) 
            max_so_far = max_ending_here; 
  
        if (max_ending_here < 0) 
            max_ending_here = 0; 
    } 
    return max_so_far; 
} 

ll findSubarraySum(ll arr[], ll n, ll sum = 0) 
{
    unordered_map<ll, ll> prevSum;
    ll res = 0;
    ll currsum = 0;
    for (ll i = 0; i < n; i++)
    {
        currsum += arr[i];
        if (currsum == sum) res++;
        if (prevSum.find(currsum - sum) != prevSum.end()) res += (prevSum[currsum - sum]);
        prevSum[currsum]++;
    }
    return res; 
} 
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
ll powmp(ll x, ll y, ll p) 
{ 
    ll res = 1;     x = x % p;   
    while (y > 0) 
    {  
        if (y & 1)  res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll a,b,n;cin>>a>>b>>n;
    ll x=min(b-1,n);
    cout<<(a*x)/b-a*(x/b)<<endl;
}


Measured memory_bytes: 3616
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        long N = nl();
        long ans = Long.MAX_VALUE;
        for (long i = 1; i*i <= N; i++) {
            if(N%i==0){
                ans = Math.min(ans, i - 1 + N/i - 1);
            }
        }
        out.println(ans);
    }

    final int mod = 1000000007;
    final BigInteger MOD = BigInteger.valueOf(mod);
    int upperBound(ArrayList<Long> list, Long target){
        int i = Collections.binarySearch(list, target, new UpperBoundComparator<Long>());
        return ~i;
    }
    class UpperBoundComparator<T extends Comparable<? super T>> implements Comparator<T>{
        public int compare(T x, T y){
            return (x.compareTo(y) > 0) ? 1 : -1;
        }
    }
    int lowerBound(ArrayList<Long> list, Long target){
        int i = Collections.binarySearch(list, target, new LowerBoundComparator<Long>());
        return ~i;
    }
    class LowerBoundComparator<T extends Comparable<? super T>> implements Comparator<T>{
        public int compare(T x, T y){
            return (x.compareTo(y) >= 0) ? 1 : -1;
        }
    }
    int mul(int x, int y){
        int val = (int)((x * 1L * y) % mod);
        return val>=0 ? val : val+mod;
    }
    int add(int x, int y) {
        x += y;
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 33268
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error('\n');
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr('time : ' + end + 'ms');
  myerr('memory : ' + Math.round(process.memoryUsage().heapTotal / 1024) + 'KB');
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var s = nextCharArray();
  var output = 0;
  var t = "";
  for(var i = 0; i < s.length; i++){
  	t = s[i] + t;
  }
  for(var i = 0; i < s.length; i++){
  	output += (s[i] != t[i]) ? 1 : 0;
  }
  myout(output / 2);
}

Measured memory_bytes: 30244
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
 
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, long long m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }

const int N=1e6+5;

int get(int k)
{
    int s=0;
    while(k>0)
    {
        s+=(k%10);
        k/=10;
    }
    return s;
}

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int ans=1e6;
    for(int i=1;i<=n-1;i++)
    {
        int j=n-i;
        ans=min(ans, get(i) + get(j));
    }
    cout<<ans;
    return 0;
} 

Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long,long>
#define INF 1000000000000000000
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; }
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
class Union_Find {
private:
	vector<int> par;
	vector<int> rank;
public:
	Union_Find(int n) {
		rep(i, n) {
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x) {
		if (par.at(x) == x) return x;
		else return par.at(x) = find(par.at(x));
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank.at(x) < rank.at(y)) {
			par.at(x) = y;
		}
		else {
			par.at(y) = x;
			if (rank.at(x) == rank.at(y)) rank.at(x)++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<int>a(n), b(n); rep(i, n) { cin >> a[i]; b[i] = a[i]; }
	sort(b.begin(), b.end());
	rep(i, n) {
		if (i == n - 1)cout << b[i] << endl;
		else cout << b[i] << " ";
	}
	bool flag = true;
	int i = 0;
	int cnt = 0;
	while (flag) {
		flag = false;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = true;
				cnt++;
			}
		}
		i++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3216
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var s = Console.ReadLine();
            Console.WriteLine(700 + s.Count(x => x == 'o') * 100);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    a.push_back(INF);
    vector<P> v(m);
    rep(i, m) cin >> v[i].second >> v[i].first;
    sort(all(a));
    sort(all(v));
    reverse(all(v));
    int pos = 0, ans = 0;
    rep(i, m)
    {
        int x = v[i].first;
        int l = pos, r = n + 1;
        if (a[l] >= x)
            break;
        while (r - l > 1)
        {
            int mid = (l + r) / 2;
            if (a[mid] < x)
                l = mid;
            else
                r = mid;
        }
        int num = l - pos + 1;
        //cout << pos << " " << l << endl;
        ans += min(num, v[i].second) * x;
        pos += min(num, v[i].second);
    }
    for (int i = pos; i < n; i++)
        ans += a[i];
    cout << ans << endl;
}

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

using namespace std;

long long a,b,x,ans,sum;

int main()
{
	cin>>a>>b>>x;
	if(a%x==0) ans=a/x;
	else ans=a/x+1;
	sum=b/x;
	cout<<sum-ans+1<<endl;
	return 0;
}

Measured memory_bytes: 256
#define __USE_MINGW_ANSI_STDIO
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef long long ll;
typedef long long ull;
typedef pair<int, int> ii;

#define all(v)		((v).begin()), ((v).end())
#define sz(v)		((int)((v).size()))
#define endl		"\n"
#define fx(n)		fixed<<setprecision(n)
#define mk			make_pair	

void fast()
{
	ios::sync_with_stdio(NULL);
	cout.tie(NULL);
	cin.tie(NULL);
/*#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
#ifdef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("pyramid.in", "r", stdin);
#endif*/
}
const double pi = 2 * acos(0.0);
const ll oo = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int nn = 5e3 + 15;
int dx[8] = { -1, 0, 0, 1, 1, -1, 1, -1 };
int dy[8] = { 0, -1, 1, 0, 1, -1, -1, 1 };

ll dp[55][55][55 * 55];
ll n, a;
int arr[55];
ll solve(int idx, int sum, int cnt = 0)
{
	if (idx == n)
		return sum == a*cnt&&cnt;
	if (dp[idx][cnt][sum] != -1)
		return dp[idx][cnt][sum];
	ll c1 = solve(idx + 1, sum, cnt);
	ll c2 = solve(idx + 1, sum + arr[idx], cnt + 1);
	return dp[idx][cnt][sum] = c1 + c2;
}
int main()
{
	fast();
	cin >> n >> a;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}
	memset(dp, -1, sizeof dp);
	cout << solve(0, 0) << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 71808
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n;
        cin >> n;
        int r = n % 10;
        if(r == 3){
            cout << "bon\n";
        }else if(r == 0 || r == 1 || r == 6 || r== 8){
            cout << "pon\n";
        }else{
            cout << "hon\n";
        }
    }
}


Measured memory_bytes: 34584
from collections import deque
 
N, X, Y = map(int, input().split())
ans = [0 for i in range(N)]

dqs = [-1, 1]
for i in range(N-1):
  vis = [-1 for _ in range(N)]
  Q = deque([i])
  vis[i] = 0
  while Q:
    q = Q.popleft()
    for dq in dqs:
      if 0 <= q + dq < N:
      	if vis[q + dq] == -1:
          vis[q + dq] = vis[q] + 1
          Q.append(q + dq)
          if q + dq > i:
            ans[vis[q + dq]] += 1
    if q==X-1:
      if vis[Y-1] == -1:
        vis[Y-1] = vis[q] + 1
        Q.append(Y-1)
        if Y-1 > i:
          ans[vis[Y-1]] += 1
    if q==Y-1:
      if vis[X-1] == -1:
        vis[X-1] = vis[q] + 1
        Q.append(X-1)
        if X-1 > i:
          ans[vis[X-1]] += 1
for a in ans[1:]:
  print(a)

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

int main(){
  ll N;string S;cin >> N >> S;
  vector<ll> ac(N);
  ac[0] = ((S[0]=='E') ? 1 : 0);
  for(ll i=1;i<N;++i){
    ac[i] = ac[i-1] + ((S[i]=='E') ? 1 : 0);
  }
  ll ans = 1e9;
  rep(i,N){
    if(i==0) ans = min(ans,ac[N-1]-ac[0]);
    else ans = min(ans,(i-ac[i-1])+(ac[N-1]-ac[i]));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3076
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926

typedef long long int ll;

//ll num[ten52];
//ll num[10][10];

int main(void)
{
    long long int sum=0,range=0,ceiling;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=0,money;
    long long int a,a1=0,a2=0,a3=0,ar,as,at1;
    char c;
    a=a1=a2=a3=0;
    //vector <int> v;
    //float f,g,h;
    //int c,d,big=0;
    string s,s1,s2;
    cin>>s>>s1;
    cin>>a>>a1;
    cin>>s2;
    if(s2==s) cout<<a-1<<" "<<a1;
    else cout<<a<<" "<<a1-1;
    return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    cin>>k;
    long long t=7;
    int count=1;
    if(k%2==0)
    {
        cout<<-1;
        return 0;
    }
    while(true)
    {
        if(t%k==0)
        break;
        else
        {
            t=((t*10)%k+7)%k;
            count++;
            if(count>k)
            {
                cout<<-1;
                return 0;
            }
        }
    }
    cout<<count;
    return 0;
}


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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
int mod = 998244353;

long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
double eps = .000000001;
int primeFactors(long long n)
{
    // Print the number of 2s that divide n
   
    bool found = false;
    int cnt = 0;
    while (n%2 == 0)
    {
      found = true;
        n = n/2;
    }
    if (found){
      cnt++;
    }
    // n must be odd at this point.  So we can skip 
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i+2)
    {
      
        // While i divides n, print i and divide n
        bool found2 = false;
        while (n%i == 0)
        { 
          found2 = true;
            n = n/i;
        }
        if (found2){
          cnt++;
        }
    }

    // This condition is to handle the case when n 
    // is a prime number greater than 2
    if (n > 2)
        cnt++;
    return cnt;
}
int main ()
{
  prep();
  long long a, b;
  cin >> a >> b;
  long long num = gcd(a, b);
  int primes = primeFactors(num);
  cout << primes+1;
  return 0; 
}


Measured memory_bytes: 256
# coding: utf-8


def solve(*args: str) -> str:
    n, d = map(int, args[0].split())
    D = pow(d, 2)
    cnt = 0
    for x, y in map(lambda a: map(int, a.split()), args[1:]):
        if pow(x, 2)+pow(y, 2) <= D:
            cnt += 1
    return str(cnt)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 26216
S=str(input())
formula=[""]*(len(S)*2-1)
ans=0
for i in range(len(S)*2-1):
    if i%2==0:
        formula[i]=S[i//2]
place=pow(2,len(S)-1)-1
for i in range(place+1):
    for j in range(len(bin(i))-2):
        #strしたbinには0bのprefixが付く。
        if int(str(bin(i))[-j-1])==1:
            formula[2*j+1]="+"
    ans+=eval(''.join(formula))
    for k in range((len(formula)-1)//2):
        formula[2*k+1]=""
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
int main(){
    int N;
    int a[114514];
    int now=1;
    int ans=1;
    bool b[114514]={};
    b[1]=1;
    cin >> N;
    REP(i,N){cin >> a[i+1];}
    while(b[2]==0){
        now=a[now];
        if(b[now]==1){
            cout << -1 << endl;
            break;
        }
        b[now]=1;
        if(b[2]==1){
            cout << ans << endl;
            break;
        }
        
        ans++;
    }
return 0;
}

Measured memory_bytes: 768
/*
        karmany evadhikaras te
        ma phalesu kadacana 
        ma karma-phala-hetur bhur
        ma re sango'stv akarmani (B.G.-2.47)
 
Translation:
        Lord Krsna to Arjuna.
You have a right to perform your prescribed duty, 
but you are not entitled to the fruits of action. 
Never consider yourself the cause of the results of your activities, 
and never be attached to not doing your duty.    
*/
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define int long long
const int N = 200005;
const ll mod = 2000000011;
#define ld long double
#define PI 3.14159265358979323846
const int X = 10000000;

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(20);
}

//3. Structure or classes
//3. Ends here

//1. Data structures declaration here
vector<int>Next;
//1. Ends here

//2. Extra Functions here
//2. Ends here


void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    for(int i=1;i<=t;i++){
        solve();
    }
    return 0;
}

void solve()
{
    int n;
    int k;
    cin>>n>>k;
    Next.resize(n+1);

    for(int i=1;i<=n;i++){
        cin>>Next[i];
    }

    long long slo = Next[1];
    long long fas = Next[Next[1]];

    vector<int>repo1;
    vector<int>repo2;


    while(slo!=fas){
        repo1.push_back(slo);
        slo = Next[slo];
        fas = Next[Next[fas]];
    }

    repo2.push_back(slo);
    int lambda=1;
    slo = Next[slo];
    while(slo!=fas){
        repo2.push_back(slo);
        slo = Next[slo];
        lambda++;
    }

/*
    
    for(auto i:repo1){
        cout<<i<<" ";
    }

    cout<<"\n";

    for(auto i:repo2){
        cout<<i<<" ";
    }
*/
    k--;
    if(k<repo1.size()){
        cout<<repo1[k];
    }
    else{
        k-=repo1.size();
        k%=repo2.size();
        cout<<repo2[k];
    }

    return;
}

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

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

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 998244353LL;

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

int main() {
    ll N,S;
    cin>>N>>S;
    vector<ll> v(N);
    rep(i,N) cin>>v[i];
    vector<ll> ans(3005,0);
    ll A = 0;
    for(int i = 0; i < N; i++){
        ans[0]++;
        for(int j = 3005; j >=0; j--){
            if(0<=j-v[i]){
                ans[j]=(ans[j]+ans[j-v[i]])%mod;
            }
        }
        A = (A+ans[S])%mod;
    }
    cout<<A<<endl;
}

Measured memory_bytes: 3624
import java.util.*;

public class Main {
	Scanner sc;
	int N, D;
	
//=============
// constructor
//
	public Main() {
		sc = new Scanner(System.in);
	}
	
//==================
// instance methods
//
	void out(Object o) {
		System.out.println(o);
		System.out.flush();
	}
	
	public void exec() throws Exception {
		N = sc.nextInt();
		D = sc.nextInt();
		
		int n = (N+2*D) / (2*D+1);
		out(n);
	}
	
//======
// main
//
	public static void main(String[] args) throws Exception {
		Main m = new Main();
		m.exec();
	}

}

Measured memory_bytes: 22996
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x1 = scan.nextInt();
		int y1 = scan.nextInt();
		int x2 = scan.nextInt();
		int y2 = scan.nextInt();
		scan.close();
		//int l = (int)Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
		int v1x = x2 - x1;
		int v1y = y2 - y1;
		int x4 = -v1y + x1;
		int y4 = v1x + y1;
		int v2x = x1 - x4;
		int v2y = y1 - y4;
		int x3 = -v2y + x4;
		int y3 = v2x + y4;

		System.out.println(x3 + " " + y3 + " " + x4 + " " + y4);


	}
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int W; int H; int T;
	while(~scanf("%d%d%d", &W, &H, &T)) {
		int P;
		scanf("%d", &P);
		vector<vi> v(H, vi(W));
		rep(i, P) {
			int x; int y; int t;
			scanf("%d%d%d", &x, &y, &t);
			++ v[y][x];
		}
		vector<vector<int> > s(H, vector<int>(W));
		for(int i = 0; i < H; ++ i) for(int j = 0; j < W; ++ j)
			scanf("%d", &s[i][j]);
		int ans = 0;
		rep(i, H) rep(j, W) if(s[i][j] == 1)
			ans += v[i][j];
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 3280
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

long long mod = 1e9 + 7;
long long N,K;
vector<int> a;
vector<int> b;

int main(){
    cin >> N >> K;
    a.resize(N);
    b.resize(N);
    for(int i=0;i<N;i++) cin >> a[i];
    long long c = 0;
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            if(a[i] > a[j]) c++;
        }
    }
    sort(a.begin(),a.end());
    b[0] = 0;
    long long b_sum = 0;
    for(int i=1;i<N;i++){
        if(a[i] == a[i-1]){
            b[i] = b[i-1];
            b_sum += b[i];
            continue;
        }
        b[i] = i;
        b_sum += b[i];
    }
    long long ans = c;
    ans += (K-1) * c;
    ans %= mod;
    long long kk = (K*(K-1)/2);
    kk %= mod;
    ans += b_sum*kk;
    ans %= mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int mod=1e9+7;
int dp[1000006][2][2];
signed main()
{
	int n;
	cin>>n;
	dp[0][0][0]=1;
	for (int i=0;i<n;i++)
		for (int j=0;j<2;j++)
			for (int k=0;k<2;k++)
				if (dp[i][j][k]){
					int aa=dp[i][j][k];
					if (j+k==0)
						dp[i+1][0][1]+=aa,dp[i+1][1][0]+=aa,dp[i+1][0][0]+=aa*8%mod;
					if (j+k==1)
						dp[i+1][1][1]+=aa,dp[i+1][j][k]+=aa*9%mod;
					if (j&&k)
						dp[i+1][1][1]+=aa*10%mod;
				}
	cout<<dp[n][1][1]%mod;
	re 0;
}


Measured memory_bytes: 34828