akhauriyash/Code-Regression huggingface dataset:
n = int(input())
l = [int(input()) for _ in range(n)]
ans = 0
flg = False
button = set()
x = 1
for _ in range(n):
    ans += 1
    if l[x-1] == 2:
        flg = True
        break
    elif x in button:
        break
    else:
        button.add(x)
        x = l[x-1]
        
    
print(ans if flg else -1)


Measured memory_bytes: 13220
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

public class Program {
	public static void Main() {
		new Calc().calc();
	}
	public class Calc {
		public Calc() { }
		public void calc() {
			long mod = 1000000007;
			long N = long.Parse(Console.ReadLine());
			long pow = 1;
			for (int i = 2; i <= N; i++) {
				pow = pow * i % mod;
			}
			Console.WriteLine(pow);
		}
	}
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
ll power(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; 
}
const ll L = 2e5 + 5;
ll arr[L];
ll szz[L];
ll root(ll i)
{
    while(arr[i] != i)
    {
        arr[i] = arr[arr[i]];
        i = arr[i];
    }
    return i;
}
void union1(ll i, ll j)
{
    ll ri = root(i);
    ll rj = root(j);
    if (ri == rj) return;
    if(szz[ri] <= szz[rj])
    {
        arr[ri] = rj;
        szz[rj] += szz[ri];
    }
    else
    {
        arr[rj] = ri;
        szz[ri] += szz[rj];   
    }
}
ll find(ll i, ll j)
{
    if(root(i) == root(j))
        return true;
    return false;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, m;
    cin >> n >> m;
    for(ll i = 1; i <= n; i++)
    {
        arr[i] = i;
        szz[i] = 1;
    }
    ll a, b;
    while (m--) {
        cin >> a >> b;
        union1(a, b);
    }
    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
        ans = max(ans, szz[i]);
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6744
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9+7;
//const ll MOD = 998244353;
//const ll MOD = 924844033;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
const double EPS = 1e-5;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

#ifdef DEBUG
#define OUTPUT(x) (output(x), outendl())
#else
#define OUTPUT(x) (void)0
#endif

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

int n;
vector<int> line;
ll factorial(ll x){
	static vector<ll> memo(1e5+5,-1);
	if(x<=1)return 1;
	if(memo[x]>=0)return memo[x];
	return memo[x] = x * factorial(x-1) % MOD;
}

ll func(int place,int x){
	if(place==n){
		return x;
	}
	static vvector<ll> memo(n,vector<ll>(1e5+5,-1));
	if(memo[place][x]>=0)return memo[place][x];
	ll res = 0;
	res += func(place+1,x%line[place]) * modinv(n-place);
	res += func(place+1,x) * (n-place-1) % MOD * modinv(n-place);
	return memo[place][x] = res % MOD;
}

int main(){
	cin >> n;
	ll x;
	cin >> x;
	rep(i,n){
		int d;
		cin >> d;
		line.push_back(d);
	}

	sort(all(line),greater<int>());

	cout << func(0,x) * factorial(n) % MOD << endl;

	return 0;
}


Measured memory_bytes: 157824
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#define ll long long
//#define local

using namespace std;

const int MOD = 1e9+7;
const int inf = 0x3f3f3f3f;
const int maxn = 1e3+100;
const double PI = acos(-1.0);

ll x[maxn], y[maxn];
vector <ll> ans;
vector <string> s(maxn, "");
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
char str[10] = "DLUR";

int main() {
#ifdef local
    if(freopen("/Users/Andrew/Desktop/data.txt", "r", stdin) == NULL) printf("can't open this file!\n");
#endif
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%lld%lld", &x[i], &y[i]);
    }
    for (int i = 1; i < n; ++i) {
        if (((x[i]+y[i])&1) != ((x[0]+y[0])&1)) {
            cout << -1 << endl;
            return 0;
        }
    }
    for (ll i = 1; i < 2e9; i <<= 1) {
        ans.push_back(i);
    }
    if (((x[0]+y[0]) & 1) == 0) {
        ans.push_back(1);
    }
    for (int i = 0; i < n; ++i) {
        for (ll k = ans.size()-1; k >= 0; --k) {
            ll step = ans[k];
            int select = -1;
            ll mind = 1e18;
            for (int j = 0; j < 4; ++j) {
                if (mind > (abs(x[i]+step*dx[j]) + abs(y[i]+step*dy[j]))) {
                    mind = abs(x[i]+step*dx[j]) + abs(y[i]+step*dy[j]);
                    select = j;
                }
            }
            x[i] += step*dx[select];
            y[i] += step*dy[select];
            s[i].push_back(str[select]);
        }
    }
    cout << ans.size() << endl;
    for (ll k = ans.size()-1; k >= 0; --k) {
        if (k < ans.size()-1) cout << " ";
        cout << ans[k];
    }
    cout << endl;
    for (int i = 0; i < n; ++i) {
        cout << s[i] << endl;
    }
#ifdef local
    fclose(stdin);
#endif
    return 0;
}












Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n;  set<string> s1;  string s;
    
    cin>>n;
    
    for(int i=1;i<=n;i++)
    {
        
        cin>>s;
        
        s1.insert(s);
        

    }
    
    cout<<s1.size()<<"\n";
    
}


Measured memory_bytes: 19120
#include<stdio.h>
 
int main(void)
{
  	int count = 0;
  	int W; /*重さ上限*/
  	int N; /*お宝の数*/
	
	while(scanf("%d", &W))
	{
		if(W == 0)
		{
			break;
		}
		
		count++;
		
		scanf("%d", &N);
		
		int va = 0;/*お宝の価値*/
		int wi = 0;/*お宝の重さ*/
		
		int li[W+1];/*袋の限界*/
		
		int i = 0, j = 0;
		
		for(i = 0; i <= W; i++)
		{
			li[i] = 0;/*お宝が入っていない*/
		}
		
		for(i = 0; i < N; i++)
		{
			scanf("%d,%d", &va, &wi);
			for(j = W; j >= 0; j--)
			{
				if(li[j] != 0 && wi + j <= W)
				{
					if(li[j] + va > li[wi + j])
					{
						li[wi + j] = li[j] + va;
					}
				}
				if(j == 0 && wi <= W)
				{
					if(va > li[wi])
					{
						li[wi] = va;
					}
				}
			}
		}
		int ansva = 0;
		int answi = 0;
		
		for(i = 0; i <= W; i++)
		{
			if(li[i] > ansva)
			{
				ansva = li[i];
				answi = i;
			}
		}
		printf("Case %d:\n", count);
		printf("%d\n%d\n", ansva, answi);
	}
	return 0;
}

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

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}

int main(){
  int k,a,b;cin>>k>>a>>b;
  for(int i=a;i<=b;i++)if(i%k==0)fin("OK");
  fin("NG");
}


Measured memory_bytes: 3604
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define var auto
#define mod 1000000007
#define inf 2147483647
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << fixed << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

// end of template
struct bit {
    vector<ll> v; // ??¨?????????bit??§?????? ???????????????a[1...n]
    bit(int n){ // bit(int n) : v(n + 1) {}
        v.resize(n + 1);
    }
    
    ll sum(int i){ // ????????????a[1]~a[i]??????????±???????
        ll ret = 0;
        for(; i > 0; i -= i & -i){ // i & -i: i???1????????£??????????????????bit??????2^?????????
            ret += v[i];
        }
        return ret;
    }
    
    void add(int i, ll w) { // index:i???w????????????
        for (; i < v.size(); i += i & -i) {
            v[i] += w;
        }
    }
};

class rmq {
private:
    int n;
    int sz;
public:
    vector<ll> v;
    rmq(int a){
        n = 1;
        for(; n * 2 < a;){
            n *= 2;
        }
        sz = n * 2;
        v.resize(4 * n - 1, inf);
    }
    
    void update(int i, ll x){
        i += sz - 1;
        v[i] = x;
        while(i > 0){
            i = (i - 1) / 2;
            v[i] = min(v[2 * i + 1], v[2 * i + 2]);
        }
    }
    
    ll query_(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return inf;
        if(a <= l && r <= b) return v[k];
        else{
            ll vl = query_(a, b, k * 2 + 1, l, (l + r) / 2);
            ll vr = query_(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
    
    ll query(int a, int b){
        return query_(a, b, 0, 0, sz);
    }
};

int main() {
    // source code
    
    int N = inputValue();
    int Q = inputValue();
    rmq r(N);
    rep(i, Q){
        int com = inputValue();
        if(com){ // find
            int x = inputValue();
            int y = inputValue();
            output(r.query(x, y + 1), 0);
        }
        else{ // update
            int x = inputValue();
            ll y;
            cin >> y;
            r.update(x, y);
        }
    }
    
    return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  ll x;
  cin >> x;
  ll now = 100;
  ll co = 0;
  while(now < x){
    now *= 1.01;
    co++;
  }
  cout << co << endl;
  return 0;
}

Measured memory_bytes: 3596
main(N,R,M,m,y,n,t,c,i,d){double r;
	for(scanf("%d",&N);N--;printf("%d\n",R)){
		for(scanf("%d%d%d",&M,&y,&n),R=M;n--;R=m>R?m:R){
			if(m=M,d=0,scanf("%d%lf%d",&t,&r,&c),t){ //fukuri
				for(i=0;i<y;i++){
					m+=(int)(r*m)-c;
				}
			}else{ //tanri
				for(i=0;i<y;i++){
					d+=(int)(r*m);
					m=m-c;
				}
				m+=d;
			}
		}
	}
exit(0);}

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

bool isPrime(int n){
  if(n <= 1) return false;
  if(n == 2) return true;
  if(n%2 == 0) return false;
  for(int i = 3; i*i <= n; i += 2){
    if(n%i == 0) return false;
  }
  return true;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  vector<int> ans;
  for(int i = 6; i <= 55555; i += 5){
    if(isPrime(i)) ans.push_back(i);
  }
  REP(i, N){
    cout << ans[i] << " ";
  }
  cout << endl;
}

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

int main() { 
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  for(int i = 0; i < n-1; i++) a[i+1] += a[i];

  int ans = 0;
  rep(i, n){
    int tmp;
    cin >> tmp;
    if(i == 0) ans = tmp+a[0];
    else{
      ans = max(ans+tmp, a[i]+tmp);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3604
N,T = map(int,input().split())

min_c = 1001
for i in range(N):
      c,t = map(int,input().split())
      if t <= T and min_c > c:
            min_c = c
if min_c == 1001:
      print("TLE")
else:
      print(min_c)
            

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

namespace ConsoleApp48 {
    class Program {
        static void Main(string[] args) {
            double N = long.Parse(Console.ReadLine());

            bool flag = true;
            long ans = 0;

            for (long i = (long)Math.Sqrt(N); (i >= 1 && flag); i--) {
                if ((N % i) == 0) {
                    flag = false;
                    ans = ((long)N / i) + i - 2;
                    break;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
long long a[100];
int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    int cnt = 1;
    int mx = abs(a[1]);
    for (int i = 2; i <= n; i++){
        if (abs(a[i]) > mx){
            mx = abs(a[i]);
            cnt = i;
        }
    }
    cout << 2 * n << "\n";
    if (a[cnt] > 0){
        cout << cnt << " " << 1 << "\n";
        cout << cnt << " " << 1 << "\n";
        for (int i = 1; i < n; i++){
            cout << i << " " << i + 1 << "\n";
            cout << i << " " << i + 1 << "\n";
        }
    }
    else{
        cout << cnt << " " << n << "\n";
        cout << cnt << " " << n << "\n";
        for (int i = n; i > 1; i--){
            cout << i << " " << i - 1 << "\n";
            cout << i << " " << i - 1 << "\n";
        }
    }
    return 0;
}


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

int main()
{
    int n;
    //int max;
    int *R;
    int i, j;
    int *max;
    int profit;

    scanf("%d", &n);
    max = malloc(sizeof(int) * n);
    R = malloc(sizeof(int) * n);

#if 0
    0  - 0-4のmax
    1  - 1-4のmax - 0
    2  - 2-4のmax - 1
    3  - 3-4のmax - 2
    4  - 4
#endif

    for(i = 0; i < n; i++) {
        scanf("%d", &R[i]);
        max[i] = R[i];
    }
    for(i = n-2; i >= 0; i--) {
        if(max[i+1] > max[i]) {
            max[i] = max[i+1];
        }
        //printf("[%d]:[%d]\n", i+1, i);
    }


    profit = max[1] - R[0];
    for(i = 0; i < n-1; i++) {
        if(max[i+1]-R[i] > profit) {
            profit = max[i+1]-R[i];
        }
    }
    /*
    max = R[1]-R[0];
    for(i = 0; i < n-1; i++) {
        for(j = i+1; j < n; j++) {
            if(R[j]-R[i] > max) {
                max = R[j]-R[i];
            }
        }
    }
    */

    printf("%d\n", profit);

    return 0;
}


Measured memory_bytes: 3304
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define forA(i,a,n,x) for(ll i=a;i<n;i+=x)
#define forD(i,a,n,x) for(auto i=n-1;i>=0;i-=x)
#define ranit(it,n) for(auto it:n)
#define testCases ll t;cin>>t;while(t--)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define init(a,x) memset(a,x,sizeof(a))

ll vs=1000003;
vll sievevector(vs,0);	vll countofprimes(vs,0);

void sieve()
{
	sievevector[2]=1;
	forA(i,3,vs,2)
	{
		sievevector[i]=1;
	}
	forA(i,3,vs,2)
	{
		forA(j,i*i,vs,2)sievevector[j]=0;
	}
}

void factorise(ll n)
{
	forA(i,2,sqrt(n)+1,1)
	{
		ll c=0;
		while(n%i==0)
		{
			n/=i;c=1;
		}
		countofprimes[i]+=c;
	}
	if(n>1)countofprimes[n]++;
}

ll gcd(ll a, ll b)
{
	if(a==0) return b;
	return gcd(b%a,a);
}

int main()
{
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	sieve();
	ll n; cin>>n; vll v(n); forA(i,0,n,1)cin>>v[i];

	//forA(i,0,n,1)cout<<sievevector[v[i]]<<" ";
	forA(i,0,n,1)
	{
		factorise(v[i]);
	}
	bool a1=true,a2=false,a3=false;

	forA(i,2,vs,1)
	{
		if(countofprimes[i]>1){a1=false; break;}
	}

	forA(i,2,vs,1)
	{
		if(countofprimes[i]==n){a2=true; break;}
	}

	if(a1)cout<<"pairwise coprime";
	else
	{
		if(a2)cout<<"not coprime";
		else cout<<"setwise coprime";
	}

	//cout<<a1;
	// if(a1)cout<<"pairwise coprime";
	// else
	// {
	// 	ll g=gcd(v[0],v[1]);
	// 	forA(i,2,n,1)
	// 	{
	// 		g=gcd(g,v[i]);
	// 	}
	// 	if(g==1)cout<<"setwise coprime";
	// 	else 
	// }
	return 0;
}

Measured memory_bytes: 26656
#include<stdio.h>
int main()
{
int s,w;
scanf("%d%d",&s,&w);
if(s>=1 && s<=100 && w>=1 && w<=100)   
{
if(w>=s)
{printf("unsafe\n");}       
else
{printf("safe\n");}         
}   
return 0;   
}

Measured memory_bytes: 1612
#include<stdio.h>
#include<stdlib.h>
int main(){
  int n,i,w[101],j,sum1=0,sum2=0,dif=10001;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&w[i]);
    sum2+=w[i];
  }

  for(i=0; i<n; i++){
    sum1+=w[i];
    sum2-=w[i];
    if(abs(sum2-sum1)<dif){
      dif=abs(sum2-sum1);
    }
  }
  printf("%d\n",dif);
  return 0;

}


Measured memory_bytes: 128
#import<bits/stdc++.h>
#import<atcoder/all>
using namespace std;
int I=1e9,N,K,a;
int main(){
  cin>>N>>K;
  int s=2*N,t=2*N+1;
  atcoder::mcf_graph<int,long long> G(2*N+2);
  G.add_edge(s,t,N*K,I);
  for(int i=0;i<N;i++){
    G.add_edge(s,i,K,0),G.add_edge(N+i,t,K,0);
    for(int j=0;j<N;j++)cin>>a,G.add_edge(i,N+j,1,I-a);
  }
  cout<<1LL*N*K*I-G.flow(s,t,N*K).second<<'\n';
  vector<string> A(N,string(N,'.'));
  for(auto e:G.edges())if(e.from!=s&&e.to!=t&&e.flow)A[e.from][e.to-N]='X';
  for(string S:A)cout<<S<<'\n';
}

Measured memory_bytes: 3960
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	int n = 0;
	char s[100000], c;
	while((c=getchar())!='\n') s[n++] = c;

	int p=0, g=0, ans=0;
	REP(i, 0, n){
		if(n-i<=g-p and s[i]=='g') ans++, p++;
		else{
			if(s[i]=='g') g++;
			else{
				if(p<g) p++;
				else ans--, g++;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;
#define MAX 1000000007

int main()
{
    int n;
    cin >> n;
    vector<int> h(n+1);
    rep(i,n)cin >> h[i+1];
    h[0]=1000000;
    vector<int> dp(n+1);
    dp[0]=1000000;
    dp[1]=0;
    for(int i=2;i<=n;++i){
        dp[i]=min((dp[i-1]+abs(h[i]-h[i-1])),(dp[i-2]+abs(h[i]-h[i-2])));
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long  
int main(){
    string s[30][30];
    int H,W;
    cin >> H >> W;
    REP(i,H){
        REP(j,W){
            cin >> s[i][j];
            if(s[i][j]=="snuke"){
                cout << (char)('A'+j) << i+1 << endl;
            }
        }
    }
	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		
		char[] base = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();
		
		List<String> list = new ArrayList<>();
		for (int i = 0; i < base.length; i++) {
			if (base.length <= i + t.length-1)
				continue;
			
			boolean flg = true;
			for (int j = 0; j < t.length; j++) {
				flg &= base[i+j] == t[j] || base[i+j] == '?';
			}
			
			if (flg) {
				char[] tmp = new char[base.length];
				for (int j = 0; j < base.length; j++) {
					tmp[j] = i <= j && j <= i+t.length-1 ? t[j-i] : base[j] == '?' ? 'a' : base[j];
				}
				
				list.add(new String(tmp));
			}
			
		}
		
		if (list.isEmpty()) {
			System.out.println("UNRESTORABLE");
			return;
		}
		
		String ans = list.stream().sorted().findFirst().get();
		System.out.println(ans);
	}
	
}


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

int main() {
  char x, y;
  cin >> x >> y;;
  
  
  if(x == y)
    cout << "=" << endl;
  else if(x > y)
    cout << ">" << endl;
  else
    cout << "<" << endl;
}

Measured memory_bytes: 256
N = input()
A = list(map(int, input().split()))
C = sorted(A)
l = len(A)
i = 0
S = 1

while i < l:
   S = S * C[i]
   i = i + 1
   if S > 1000000000000000000:
        print(-1)
        break
   elif i == l:
        print(S)
        break


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

int main() {
    string S;
    cin >> S;
    if (S[S.size() - 1] == 's')
    {
        S += "es";
    }else
    {
        S += 's';
    }
    

    cout << S << endl;
    
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	for (int n; cin >> n&&n;) {
		vector<int> a(n);
		rep(i, 0, n)cin >> a[i];
		vector<int> s = a;
		sort(all(s));

		bool flag = true;
		int ans = 0;
		while (flag) {
			flag = false;
			rep(h, 0, n - 1) {
				rep(i, 0, n - 1 - h) {
					if (a[i] > a[i + 1]) {
						swap(a[i], a[i + 1]);
						ans++;
						flag = true;
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    while(n--){
        int r,t;
        cin >> r >> t;
        if( r % 100 == 0 and t % 30 == 0 ){
            cout << (r / 100) + (t/30) * 5 << endl;
        }else if( r % 100 == 0 ){
            cout << (r / 100) + (t/30) * 5 << " ";
            cout << (r / 100) + ((t+29)/30) * 5 << endl;
        }else if( t % 30 == 0 ){
            cout << (r / 100) + (t/30) * 5 << " ";
            cout << (r+99) / 100 + (t/30) * 5 << endl;
        }else{
            cout << (r / 100) + (t/30) * 5 << " ";
            cout << (r+99) / 100 + (t/30) * 5 << " ";
            cout << (r / 100) + ((t+29)/30) * 5 << " ";
            cout << (r+99) / 100 + ((t+29)/30) * 5 << endl;
        }
    }
 
}

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<queue>
using namespace std;

typedef long long ll;

int main() {
  string S,T; cin >> S >> T;

  string ans = "";
  reverse(S.begin(),S.end());
  reverse(T.begin(),T.end());  
  int i = 0;
  bool f = false,f2 = false;
  while(1) {
    f = true;
    int cnt = 0;
    for ( int j = i; j < i+T.length(); j++ ) {
      if ( S[j] == '?' || S[j] == T[j-i] )cnt++;
      else  f = false;
    }
    if(f == true && cnt == T.length()) {
      for ( int k = 0; k < T.length(); k++ ) {
	ans += T[k];
      }
      f2 = true;      
      for ( int k = i+T.length(); k < S.length(); k++ ) {
	if ( S[k] == '?' ) ans += 'a';
	else ans += S[k];			     
      }
      break;
    } else if ( S[i] == '?' ) {
      ans += 'a';
      i++;
    } else {
      ans+=S[i];
      i++;
    }
    
    if( i >= S.length() ) break;

  }
  reverse(ans.begin(),ans.end());
  if(f2) cout << ans << endl;
  else cout << "UNRESTORABLE" << endl;
  return 0;
}


Measured memory_bytes: 256
import bisect
import collections
import sys

sys.setrecursionlimit(100000)
input = sys.stdin.readline
ACMOD = 1000000007
INF = 1 << 62


def lmi():
    return list(map(int, input().split()))


def llmi(n):
    return [lmi() for _ in range(n)]


S,W = lmi()
print("unsafe" if S <= W else 'safe')



Measured memory_bytes: 9468
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n;
    cin >> n;
    vector<int> a(n);
    repeat(i, n) cin >> a[i];
    vector<pair<int, int>> ans;
    
    auto minit = min_element(a.begin(), a.end());
    int minval = *minit;
    int minpos = distance(a.begin(), minit);
    
    auto maxit = max_element(a.begin(), a.end());
    int maxval = *maxit;
    int maxpos = distance(a.begin(), maxit);
    
    if (minval >= 0) {
        repeat(i, n - 1) ans.emplace_back( make_pair(i + 1, i + 2) );
    }
    else if (maxval <= 0 ) {
        repeat(i, n - 1) ans.emplace_back( make_pair(n - i, n - i - 1) );
    }
    else if (minval < 0 && maxval + minval >= 0) {
        repeat(i, n) ans.emplace_back( make_pair(maxpos + 1, i + 1) );
        repeat(i, n - 1) ans.emplace_back( make_pair(i + 1, i + 2) );
    }
    else if (minval < 0 && maxval + minval < 0) {
        repeat(i, n) ans.emplace_back( make_pair(minpos + 1, i + 1) );
        repeat(i, n - 1) ans.emplace_back( make_pair(n - i, n - i - 1) );
    }
    cout << ans.size() << endl;
    repeat(i, ans.size()) {
        cout << ans[i].fst << " " << ans[i].snd << endl;
    }   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  int n, m;
  cin >> n >> m;
  int A[n][m];
  rep(i,n)rep(j,m) cin >> A[i][j];
  int b[m];
  rep(i,m) cin >> b[i];
  int c[n];
  rep(i,n) {
    c[i] = 0;
    rep(j,m) c[i] += A[i][j]*b[j];
  }
  rep(i,n) printf("%d\n", c[i]);
  return 0;
}


Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  int count=0;
 for(int i=1;i<N+1;i++){
 string s=to_string(i);
   int n=s.size();
  
   if(n%2==1){
   count++;
   }
 
 }
 cout<<count<<endl; 

}


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


int main(){
  
  int N, cnt;
  cin >> N;
  cnt = 0;
  vector<int> A(N);
  
  for(int i = 0; i < N; i++){
	int a;
    cin >> a;
    //cout << a << endl;
    
    while(a % 2 == 0){
      //cout << a << endl;
      a = a / 2;
      cnt++;
    }
    //cout << cnt << endl;
    A.at(i) = cnt;
    cnt = 0;
  }
  
  sort(A.begin(), A.end());
  cout << A.at(0) << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)

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

int N;
string S;
vector<int> sct;

int solve() {
    S.push_back('A');   //番兵
    int wh_cnt = 0, bl_cnt = 0, wh_cur = 0, bl_cur = 0, res = INF;
    for(int i = 0; i < S.size(); ++i)
        if(S[i] == '.') wh_cnt++;
        else if(S[i] == '#') bl_cnt++;
    for(int i = 0; i < S.size(); ++i) {
        res = min(res, bl_cur + wh_cnt - wh_cur);

        if(S[i] == '.') wh_cur++;
        else if(S[i] == '#') bl_cur++;
    }
    return res;
}

int main(int argc, char **argv) {
    cin >> N >> S;
    cout << solve() << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
  struct node *prev;
  struct node *next;
  long key;
};
typedef struct node * NP;
NP MN(long);
void IN(NP);
void DN(NP);
void FI(long);
NP dummy;
 
int main(){
  long int val,i,n;
  char op[12];
  NP roop;
 
  scanf("%ld",&n);
  dummy = MN(0);
 
   
 
  for(i=0;i<n;i++){
    scanf("%s",op);
     
    if(strcmp(op,"insert") == 0){
      scanf("%ld",&val);
      IN(MN(val));
    }
    else if(strcmp(op,"delete") == 0){
      scanf("%ld",&val);
      FI(val);
    }
    else if(strcmp(op,"deleteFirst") == 0){
      DN(dummy->next);
    }
    else if(strcmp(op,"deleteLast") == 0){
      DN(dummy->prev);
    }
  }
 
  for(roop=dummy->next;roop!=dummy;roop =roop->next){
    printf("%ld",roop->key);
    if(roop->next != dummy)printf(" ");
  }  
  printf("\n");
 
  return 0;
}
 
 
void FI(long value){
  NP n;
  dummy->key = value;
  for(n = dummy->next;;n=n->next){
    if(n->key == value)break;
  }
  if(n != dummy)DN(n);
     
}
 
 
void DN(NP th){
  th->prev->next = th->next;
  th->next->prev = th->prev;
  th->prev = th->next = th;
  free(th);
  //delete th;
}
 
 
void IN(NP newn){
  newn->next = dummy->next;
  newn->next->prev = newn;
  dummy->next = newn;
  newn->prev = dummy;
}
 
NP MN(long key){
  NP no = (NP)malloc(sizeof(struct node));
  //n = new struct node();
  no->prev = no;
  no->next = no;
  no->key = key;
  return no;
} 


Measured memory_bytes: 33852
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
//int p = 998244353;
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
int max_kai = 150000;
vel kai(max_kai, 1);
vel inv_kai;
int rui(int a, int n) {
	if (n == 0) { return 1; }
	int x = rui(a, n / 2);
	x *= x; x %= p;
	if (n % 2 == 1) { x *= a; x %= p; }
	return x;
}
int inv(int a) { return rui(a, p - 2); }
void make_kai() {
	for (int i = 1; i < max_kai; i++) { kai[i] = kai[i - 1] * i; kai[i] %= p; }
	inv_kai = kai;
	rep(i, max_kai) { inv_kai[i] = inv(kai[i]); }
}
int nCr(int n, int r) {
	int a = kai[n] * inv_kai[r]; a %= p;
	a *= inv_kai[n - r]; a %= p;
	return a;
}
vel pa;
int root(int x) {
	if (pa[x] == -1) { return x; }
	int ans = root(pa[x]); pa[x] = ans;
	return ans;
}
void marge(int x, int y) {
	x = root(x);
	y = root(y);
	if (x != y) {pa[x] = y;}
}
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int num_lp(int a, vel &nex) {
	unordered_set<int> se;
	int ans = 0;
	while (true) {
		if (se.find(a) != se.end()) {
			break;
		}
		se.insert(a);
		a = nex[a];
		ans++;
	}
	return ans;
}
int find_cr(int a, vel &nex) {
	unordered_set<int> se;
	while (true) {
		if (se.find(a) != se.end()) {break;}
		se.insert(a);
		a = nex[a];
	}
	return num_lp(a, nex);
}
int inf = 2000000000;
vvel dp;
int solve(vvel &sum, int i, int j, bool is_f) {
	int h = sum.size(); h--;
	int w = sum[0].size();
	if (i == h || j == w) { return 0; }
	if (dp[i][j] == inf) {
		int ans1 = solve(sum, i + 1, j, !is_f);
		int ans2 = solve(sum, i, j + 1, !is_f);
		ans2 += sum[i][j];
		if (is_f) {
			dp[i][j] = min(ans1, ans2);
		}
		else {
			dp[i][j] = max(ans1, ans2);
		}
	}
	return dp[i][j];
}
int rui10(int a) {
	if (a == 0) { return 1; }
	return 10 * rui10(a - 1);
}
int gcd(int a, int b) {
	if (a < b) { swap(a, b); }
	if (b == 0) { return a; }
	return gcd(b, a%b);
}
vel mul(vel &a, vel &b) {
	int n = a.size();
	vel c(n,-1);
	rep(i, n) {
		rep(j, n) {
			if (a[i] >= 0 && b[j] >= 0) {
				mmax(c[(i + j) % n], a[i] + b[j]);
			}
		}
	}
	return c;
}
vel rui(vel &a, int n) {
	if (n == 1) { return a; }
	vel b = rui(a, n / 2);
	b = mul(b, b);
	if (n % 2 == 1) {
		b = mul(b, a);
	}
	return b;
}
signed main(){
	int n, m, t; cin >> n >> m >> t;
	vel a(t, -1); a[0] = 0;
	rep(i, n) {
		int x; cin >> x;
		mmax(a[x%t], x);
	}
	vel ans = rui(a, m);
	for (int i = t - 2; i >= 0; i--) {
		mmax(ans[i], ans[i + 1]);
	}
	int q; cin >> q;
	rep(i, q) {
		int x, y; cin >> x >> y;
		if (ans[x] >= y * t + x) { cout << "yes" << endl; }
		else { cout << "no" << endl; }
	}
	return 0;
}


Measured memory_bytes: 4184
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<int> > mat;

int main()
{
  ll n, k;
  cin >> n >> k;
  ll ans = 0;
  for (int i = k + 1; i <= n; i++)
  {
    ans += n / i * (i - k);
    ans += max(0LL, n - (n / i) * i - k + 1);
    if (k == 0)
    {
      ans--;
    }
  }
  cout << ans << "\n";
}

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

int main(){
  int k,n;
  cin >> k >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  sort(a.rbegin(),a.rend());
  cout << max(2*a[0]-k-1,0);
  return 0;
}

Measured memory_bytes: 3572
n,k = map(int,input().split())
p = list(map(int,input().split()))

d_tmp = sum(p[0:k])
d_max = sum(p[0:k])
for i in range(n-k):
  d_tmp = d_tmp + p[k+i] - p[i]
  d_max = max(d_max,d_tmp)

ans = (d_max + k)/2
print(ans)

Measured memory_bytes: 31956
// #![allow(unused_mut)]
#![allow(dead_code)]
#![allow(unused_macros)]

use proconio::{input};

// The debug version
#[cfg(feature = "debug")]
macro_rules! debug {
    ($( $args:expr ),*) => { eprintln!( $( $args ),* ); }
}
// Non-debug version
#[cfg(not(feature = "debug"))]
macro_rules! debug {
       ($( $args:expr ),*) => {}
}


use num_traits::int::PrimInt;
// #[overflow_checks(off)]
// i32 -> i32, i64 -> i64
fn accum<T: PrimInt>(a: &Vec<T>) -> Vec<T> {
    let n: usize = a.len();
    let mut ac: Vec<T> = Vec::with_capacity(n + 1);
    ac.push(a[0] - a[0]);  // ac.push(0) がしたいんですけど
    for i in 0..n {
        ac.push(ac[i] + a[i]);
    }
    ac
}
/// i32 -> i64
fn accum64(a: &Vec<i32>) -> Vec<i64> {
    let n: usize = a.len();
    let mut ac: Vec<i64> = Vec::with_capacity(n + 1);
    ac.push(0);
    for i in 0..n {
        ac.push(ac[i] + i64::from(a[i]));
    }
    ac
}

fn rle<T: PrimInt>(a: &Vec<T>) -> Vec<(T,u32)> {
    let mut res: Vec<(T,u32)> = Vec::with_capacity(0);

    let mut last : T = T::zero();
    let mut cnt : u32 = 0;

    for c in a.iter() {
        if *c == last {
            cnt += 1;
        } else {
            if cnt > 0 {
                res.push((last, cnt));
            }
            last = *c;
            cnt = 1;
        }
    };
    if cnt > 0 {
        res.push((last, cnt));
    }
    res
}
fn rle_str(a: &str) -> Vec<(char,u32)> {
    let mut res: Vec<(char,u32)> = Vec::with_capacity(0);

    let mut last : char = '\0';
    let mut cnt : u32 = 0;

    for c in a.chars() {
        if c == last {
            cnt += 1;
        } else {
            if cnt > 0 {
                res.push((last, cnt));
            }
            last = c;
            cnt = 1;
        }
    };
    if cnt > 0 {
        res.push((last, cnt));
    }
    res
}

fn yesno(b: bool) -> &'static str {
    if b {
        return "Yes";
    } else {
        return "No";
    }
}

fn solve(mut x:i64, k:i64, d:i64) -> i64 {
    debug!("Input: x={}, k={}, d={}", x,k,d);
    if x < 0 {
        x = -x;
    }
    let q = x / d;
    let r = x % d;
    debug!(" q={}, r={}", q, r);

    if k <= q {
        return x - d*k;
    }
    // k > q
    // let r_comp = d - r;
    if (k - q) % 2 == 1 {
        return d - r;
    } else {
        return r;
    }
}

fn main() {
    input! {
        x: i64,
        k: i64,
        d: i64,
    }
    let ans: i64 = solve(x,k,d);
    println!("{}", ans);
}


Measured memory_bytes: 2160
//##Moh_K_Imar .......
//27/08/2020  ...  7.55
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    string a;
    cin>>a;
    ll counter=0,sum=0;
    for(ll i=0;i<a.size();i++){
        if(a[i]=='R')counter++;
        else sum++;
    }
    if(counter==3)cout<<3<<endl;
    else if(counter==1)cout<<1<<endl;
    else if(counter==0)cout<<0<<endl;
    else if(counter==2) {
        for(ll i=0;i<a.size();i++){
            if(a[i]=='R'&&a[i+1]=='S'){
                cout<<1<<endl;
                break;
            }
            else if(a[i]=='S'&&a[i+1]=='R'){
                cout<<2<<endl;
                break;
            }
            else if(a[i]=='R'&&a[i+1]=='R'){
                cout<<2<<endl;
                break;
            }
        }
    }


    return 0;
}



Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
    int W,a,b,ans;
    cin>>W>>a>>b;
    if(a+((a+W)/2)<=b)ans=b-(a+W);
    if(a+((a+W)/2)>b)ans=a-(b+W);
    if(ans<0)ans=0;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <misc/C++/Debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}

struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
  }
}init;





int main(){
  double a,b,x;
  while(cin >> a >> b >> x){
    double ans = 0;

    double lb = 0, ub = 90;

    auto check =
      [&](double t){
        if(a * tan(t * M_PI / 180) <= b){
          return x <= a*a*b - 0.5*a*a*a*tan(t * M_PI / 180);
        }else{
          return x <= 0.5*a*b*b*tan((90.0-t) * M_PI / 180);
        }
        
      };
    /*
    FORE(i,0,90){
      dump(check(i));
    }

    */

    REP(i,1000){
      double mid = (ub+lb) / 2;

      if(check(mid)){
        lb = mid;
      }else{
        ub = mid;
      }
    }
    
    ans = lb;


    cout << fixed << setprecision(12) << ans << endl;
  }

  return 0;
}


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



int main(){
  int N;
  long u,v,w;
  cin>>N;
  vector<int> ans(N,-1);
  
  vector<int> odd[100010];
  vector<int> even[100010];
  for(int i=0;i<N-1;i++){
    cin>>u>>v>>w;
    if(w%2==0){
      even[u-1].push_back(v-1);
      even[v-1].push_back(u-1);
    }else{
      odd[u-1].push_back(v-1);
      odd[v-1].push_back(u-1);
    }
  }
  queue<int> q;
  q.push(0);
  ans[0]=0;
  while(!q.empty()){
    int now=q.front();
    q.pop();
    for(int i=0;i<even[now].size();i++){
      if(ans[even[now][i]]!=-1) continue;
      ans[even[now][i]]=ans[now];
      q.push(even[now][i]);
    }
    for(int i=0;i<odd[now].size();i++){
      if(ans[odd[now][i]]!=-1) continue;
      ans[odd[now][i]]=((ans[now]==1)?0:1);
      q.push(odd[now][i]);
    }
  }
  for(int i=0;i<N;i++){
    cout<<ans[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 9856
#include "bits/stdc++.h"
using namespace std;

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n; read(n);
	vector<int> v(n + 1);
	rep(i, 1, n + 1) read(v[i]);
	int a = 0;
	rep(i, 1, n + 1) if (i % 2 == 1 && v[i] % 2 == 1) a++;
	write(a);
}


Measured memory_bytes: 3608
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<lli>
#define mii             map<lli,lli>
#define pqb             priority_queue<lli>
#define pqs             priority_queue<lli,vi,greater<lli> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            lli x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
const lli N = 2e6 + 5;
lli fact[N];
lli mul(lli a, lli b) {
	return ((a % mod) * (b % mod)) % mod;
}
lli add(lli a, lli b) {
	return ((a % mod) + (b % mod)) % mod;
}
lli fastPow(lli base, lli power) {
	lli ret = 1;
	while (power) {
		if (power & 1)ret = mul(base, ret);
		base = mul(base, base);
		power >>= 1;
	}
	return ret;
}
void pre() {
	fact[0] = 1;
	for (lli i = 1; i < N; i++) {
		fact[i] = mul(i, fact[i - 1]);
	}
}
lli modInv(lli x) {
	return fastPow(x, mod - 2);
}
lli nCr(lli n, lli r) {
	return mul(fact[n], modInv(mul(fact[r], fact[n - r])));
}
void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}
void solve() {
	lli ret = 0;
	pre();
	lli k;
	cin >> k;
	string s;
	cin >> s;
	lli n = s.size();
	for (lli i = n; i <= k + n; i++) {
		lli temp = mul(nCr(n + k, i), fastPow(25, k + n - i));
		ret = add(ret, temp);
	}
	cout << ret << endl;
}
int main()
{
	zanj0();
	solve();
	return 0;
}

Measured memory_bytes: 19952