akhauriyash/Code-Regression huggingface dataset:
A,B,C=map(int,input().split())

if A%2==0 or B%2==0 or C%2==0:
    print(0)
else:
    r1=(A//2)*B*C
    b1=(A-A//2)*B*C
    val1=abs(r1-b1)
    r2=A*(B//2)*C
    b2=A*(B-B//2)*C
    val2=abs(r2-b2)
    r3=A*B*(C//2)
    b3=A*B*(C-C//2)
    val3=abs(r3-b3)
    ans=min(val1,val2,val3)
    print(ans)

Measured memory_bytes: 38256
#include<iostream>
#include<vector>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)

int N,M;

ll INF = 1000000000000;

struct edge {
  ll from,to,cost;
};
vector<edge> e;
vector<ll> d;

int main(){
  cin >> N >> M;
  d.resize(N);

  rep(i,M) {
    ll a,b,c;
    cin >> a >> b >> c;
    a--;b--;c*=-1;
    e.pb((edge){a,b,c});
  }

  rep(i,N)d[i] = INF;
  d[0] = 0;

  for (int cou = 0;cou < N;cou++) {
    bool flag = true;
    rep(i,M) {
      if (d[e[i].to] > d[e[i].from] + e[i].cost) {
        flag = false;
        d[e[i].to] = d[e[i].from] + e[i].cost;
        if (cou >= N - 1 && e[i].to == N - 1) {
          cout << "inf" << endl;
          return 0;
        } 
      }
    }

    if (flag) break;
  }

  cout << -d[N - 1] << endl;
  return 0;
}



Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#include <bitset>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
//#define double long double
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch-'0'), ch=getchar();
    return s*w;
}
void print(int x) { if(x<0) x=-x, putchar('-'); if(x>9) print(x/10); putchar(x%10+'0'); }
int n,k,a[N];
signed main()
{
    n=read(), k=read();
    for(ri int i=1;i<=n;i++) a[i]=read();
    sort(a+1,a+1+n); int res=0;
    for(ri int i=1;i<=k;i++) res+=a[i];
    printf("%lld\n",res);
    return 0;
}

Measured memory_bytes: 3712
import itertools
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
A = B = 0
for i,v in enumerate(list(itertools.permutations(range(1,N+1))), 1):
    if list(v) == P:
        A = i
    elif list(v) == Q:
        B = i
        continue
    else:
        pass
print(abs(A-B) if A != 0 and B != 0 else 0)

Measured memory_bytes: 8052
import Data.List
import Data.Char
import Data.Maybe
import qualified Data.ByteString.Char8 as BS8

dig_impl 0 r = r
dig_impl n r = dig_impl (div n 10) (r + 1)

dig n = dig_impl n 0

cnt n
    | dig n <= 1 = n
    | mod (dig n) 2 == 0 = 9 * 10 ^ (dig n - 2) + cnt (n `div` 100)
    | otherwise = n - 10 * cnt (n `div` 10)

main :: IO ()
main = do
    n <- fst . fromJust . BS8.readInteger <$> BS8.getLine

    print $ cnt n


Measured memory_bytes: 380
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;



int main()
{
    int a,b,c,d;
    cin >> a >> b;
    out((a+b-1)/b);


    return 0;
}


Measured memory_bytes: 256
import numpy as np
import itertools
import math

A, B, H, M = map(int, input().split())

a_x = A*(math.sin(math.radians(H*30+M/2)))
a_y = A*(math.cos(math.radians(H*30+M/2)))
b_x = B*(math.sin(math.radians(M*6)))
b_y = B*(math.cos(math.radians(M*6)))

l = math.sqrt((a_x-b_x)**2+(a_y-b_y)**2)

print(l)

Measured memory_bytes: 27176
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	long long n;
	long long x, y, z;
	long long ans;
	bool v = true;
	scanf("%lld %lld %lld %lld", &x, &y, &z, &n);
	n = n % 2;
	ans = x - y;
	if (ans > 1000000000000000000)v = false;
	if (ans < -1000000000000000000)v = false;
	if (n == 1)ans = -ans;
	if(v)printf("%lld\n", ans);
	else printf("Unfair\n");


	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

string s;

int main(){
  cin >> s;
  int n = s.size();
  string res = "NO";
  for(int left = 0; left <= n; left++){
    for(int right = left; right <= n; right++){
      string comp = s.substr(0, left) + s.substr(right);
      //cerr << comp << endl;
      if(comp == "keyence")
        res = "YES";
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

type Restaurant struct {
	Index int
	City string
	Point int
}

type Restaurants []Restaurant

func (rs Restaurants) Len() int {
	return len(rs)
}

func (rs Restaurants) Less(i, j int) bool {
	if rs[i].City == rs[j].City {
		return rs[i].Point > rs[j].Point
	}
	return rs[i].City < rs[j].City
}

func (rs Restaurants) Swap(i, j int) {
	rs[i], rs[j] = rs[j], rs[i]
}

func main() {
	var n int
	fmt.Scan(&n)

	var rs []Restaurant

	var s string
	var p int
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		fmt.Scan(&p)
		rs = append(rs, Restaurant{i + 1, s, p})
	}

	sort.Sort(Restaurants(rs))

	for _, r := range rs {
		fmt.Println(r.Index)
	}
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
  public static void main(String args[]) {
    Scanner scanner = new Scanner(System.in);
    HashMap<Integer,Integer> freq = new HashMap<Integer, Integer>();
    int n;
    n = scanner.nextInt();
  	int x;
    long sum = 0;
    for(int i = 0;i < n; i++) {
      x = scanner.nextInt();
      sum+=x;
      if(freq.containsKey(x)) {
        freq.replace(x,freq.get(x) + 1);
      } else {
        freq.put(x,1);
      }
    }
    
    int q;
    q = scanner.nextInt();
    int b,c;
    for(int i = 0;i < q;i++) {
      b = scanner.nextInt();
      c = scanner.nextInt();
      if(freq.containsKey(b)) {
        int freq_b = freq.get(b);
        sum = sum - (long)b * freq_b + (long)c * freq_b;
        System.out.println(sum);
        freq.remove(b,freq_b);
        if(freq.containsKey(c)) {
          freq.replace(c,freq.get(c) + freq_b);
        } else {
          freq.put(c,freq_b);
        }
      } else {
        System.out.println(sum);
    }
    }
  }
}

Measured memory_bytes: 65940
fun main(arg: Array<String>) {
    val inputArray = readLine()!!.split(" ").map {it.toInt()}
    val M = inputArray[2]

    val a = readLine()!!.split(" ").map {it.toInt()}.toIntArray()
    val b = readLine()!!.split(" ").map {it.toInt()}.toIntArray()

    val amin = a.min()
    val bmin = b.min()

    var currentMin = amin!! + bmin!!

    for(i in 0..M - 1) {
        val (x, y, c) = readLine()!!.split(" ").map {it.toInt()} 
        val ax = a[x - 1]
        val by = b[y - 1]
        val ret = ax + by - c
        if(currentMin > ret) {
            currentMin = ret
        }
    }

    println(currentMin)
} 

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

int main() {
	ll N, D;
	cin >> N >> D;

	ll count = 0;
	for (ll i = 0; i < N; i++) {
		ll p, q;
		cin >> p >> q;
		if (p*p + q * q <= D * D) count++;
	}

	cout << count << endl;
	return(0);
}


Measured memory_bytes: 3632
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import itertools

N,K = map(int,read().split())

x = (N-1)*(N-2)//2
if K > (N-1)*(N-2)//2:
    print(-1)
    exit()

rest = x-K
UV = [(x,N) for x in range(1,N)] + list(itertools.combinations(range(1,N),2))
UV = UV[:N-1+rest]

print(len(UV))
print('\n'.join('{} {}'.format(x,y) for x,y in UV))

Measured memory_bytes: 3700
n = int(input())
s = input()


a = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ans = ""
for w in s:
    if a.index(w)+n <= 25:
        ans += a[a.index(w) + n]
    else:
        ans += a[a.index(w) + n - 26]

print(ans)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll x;
  cin >> x;
  map<ll, ll> mp;
  mp[0] = 0;
  for(ll i=1;i*i*i*i*i<=100*x;i++){
    ll cur=i*i*i*i*i;
    mp[cur]=i;
    mp[-cur]=-i;
    if(mp.count(cur-x)!=0){
        cout<<i<<" "<<mp[cur-x]<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3676
/* ex 4-2
    kas056 */
#include <stdio.h>
#include <math.h>

int main(void){
    int a,b,hour,minute;
    double omega1,omega2,omega,length;

    scanf("%d %d %d %d", &a,&b,&hour,&minute);//入力読み取り

    omega1 = 2*M_PI * (hour+ minute / 60.0) / 12;//短針が動いた角度
    omega2 = 2*M_PI *minute / 60.0;//長針が動いた角度
    omega = fabs(omega1-omega2);//角の差の絶対値を取り、成す角を求める

    //余弦定理の適応
    
    length = sqrt(pow(a,2) + pow(b,2) - 2*a*b*cos(omega));
    
    //10^-10まで出力
    printf("%.10lf",length);
    return 0;
}

Measured memory_bytes: 2596
#include <bits/stdc++.h>
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;

pair<int, int> num(const string &s, int i) {
  int n = 0;
  while (isdigit(s[i])) {
    n *= 10;
    n += s[i] - '0';
    ++i;
  }
  return make_pair(n, i);
}

int skip(const string &s, int i) {
  if (s[i] == '(') {
    i = skip(s, i+1);
    assert(s[i] == ')');
    assert(s[i+1] == '[');
    i = num(s, i+2).second;
    assert(s[i] == ']');
    assert(s[i+1] == '(');
    i = skip(s, i+2);
    return i+1;
  } else {
    return i;
  }
}

pair<int, int> parse(const string &a, const string &b, int i, int j) {
  if (a[i] == '(' && b[j] == '(') {
    cout << '(';
    tie(i, j) = parse(a, b, i+1, j+1);
    assert(a[i] == ')');
    assert(b[j] == ')');
    cout << ')';
    assert(a[i+1] == '[');
    assert(b[j+1] == '[');
    cout << '[';
    int n, m;
    tie(n, i) = num(a, i+2);
    tie(m, j) = num(b, j+2);
    cout << (n+m);
    assert(a[i] == ']');
    assert(b[j] == ']');
    cout << ']';
    assert(a[i+1] == '(');
    assert(b[j+1] == '(');
    cout << '(';
    tie(i, j) = parse(a, b, i+2, j+2);
    assert(a[i] == ')');
    assert(b[j] == ')');
    cout << ')';
    ++i; ++j;
  } else {
    if (a[i] == '(') {
      i = skip(a, i);
    } else if (b[j] == '(') {
      j = skip(b, j);
    }
  }
  return make_pair(i, j);
}

int main() {
  string a, b;
  cin>>a>>b;
  parse(a, b, 0, 0);
  cout << endl;
  return 0;
}

Measured memory_bytes: 3200
#復習用
import bisect

while 1:
    n,m = map(int, input().split())
    if n == m == 0:
        break
    h = [0] + [int(input()) for i in range(n)]
    w = [0] + [int(input()) for j in range(m)]
    for i in range(n):
        h[i+1] += h[i]
    for i in range(m):
        w[i+1] += w[i]
    a = [0 for i in range(n*(n+1)//2)]#行の道幅すべてを入れるリスト
    b = [0 for i in range(m*(m+1)//2)]#列の道幅すべてを入れるリスト
    k = 0
    for i in range(1,n+1):
        for j in range(i):
            a[k] = h[i]-h[j]
            k += 1

    k = 0
    for i in range(1,m+1):
        for j in range(i):
            b[k] = w[i]-w[j]
            k += 1

    ans = 0
    b.sort()
    #print(a)
    #print(b)
    for i in a:
        l = bisect.bisect_left(b,i)#1つ目の引数はソート済みのリスト 2つ目の引数は挿入する値 bisect_leftの返り値はソートを保った挿入箇所の一番左
        r = bisect.bisect_right(b,i)
        ans += r-l#行間隔と同じ列間隔の個数を足す(bが1,2,4でiが3のときlとrはともに2で0、iが2ならlは1,rは2で1)
    print(ans)


Measured memory_bytes: 85576
import itertools
import copy
import math

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

Psorted = copy.copy(P)
Psorted.sort()
PQList = list(itertools.permutations(Psorted))

a = 0
b = 0
for i in range(math.factorial(N)):
    if PQList[i] == tuple(P):
        a = i + 1
    if PQList[i] == tuple(Q):
        b = i + 1
res = a - b
if res < 0:
    res *= -1

print(res)


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

int main(){
    ll r,d,x;
    cin>>r>>d>>x;
    ll tmp;
    rep(i,10){
        tmp = r*x-d;
        cout<<tmp<<endl;
        x=tmp;
    }

}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N,X;cin>>N>>X;
  vector<int> L(N+1); 
  L[0]=0;
  for (int i=0;i<N;++i){
    int x;cin>>x;
    L[i+1]=L[i]+x;
  }
  int ans=0;
  for (int i=0;i<=N;++i){
    if (L[i]<=X)ans++;
  }
  cout<<ans<<endl;
}

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

int main() {
  int n;
  cin>>n;
  int ans=0;
  
  for(int i=1;i<=n;i++){
    int x=i;int a=0;
    while(x>0){
      x/=10;
      a++;
    }
    if(a%2==1)ans++;
  }
  
  cout<<ans<<endl;
    
  
}


Measured memory_bytes: 256
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = a; i <= b; i++)

#include <iostream>

using namespace std;

int main()
{
    int N, K, X, Y; cin >> N >> K >> X >> Y;
    if (N > K) cout << (K*X) + ((N-K)*Y) << endl;
    else cout << (N*X) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
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;}
string get_str(string s) {
	s+=',';
	string ret="";
	for(int i=0; i<s.size(); i++) {
		if(s[i]==',') ret+="=%ld, ";
		else ret+=s[i];
	}
	return ret;
}
#define dump(...) printf(get_str(#__VA_ARGS__).c_str(),__VA_ARGS__);cout<<endl
 
#define endl '\n'
#define IOS()                     \
	ios_base::sync_with_stdio(0); \
	cin.tie(0)
 template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
//******************************************************************************
 
int N,MINF=1e17;
vint a;
vint g[5050];
 
 
vector<vector<int>>dfs(int now,int par){
	auto dp = make_v<int>(2,2);
	fill_v(dp,INF);
	dp[0][0] = a[now];
	if(a[now]>0)dp[0][1] = a[now];
	for(auto e:g[now]){
		if(e==par)continue;
		auto tmp = dfs(e,now);
		int n = dp.size();
		int m = tmp.size();
		auto new_dp = make_v<int>(n+m-1,2);
		fill_v(new_dp,INF);
		rep(i,0,n-1){
			rep(j,0,m-1){
				rep(k,0,2){
					rep(l,0,2){
						chmin(new_dp[i+j][k&l],dp[i][k]+tmp[j][l]);
					}
				}
				if(i+j+1>=n+m-1)continue;
				if(tmp[j][0]<0){
					chmin(new_dp[i+j+1][0],dp[i][0]);
					chmin(new_dp[i+j+1][1],dp[i][1]);
				}
				if(tmp[j][1]<INF/2){
					chmin(new_dp[i+j+1][0],dp[i][0]);
					chmin(new_dp[i+j+1][1],dp[i][1]);
				}
			}
		}
		dp = new_dp;
	}
	return dp;
}
 
signed main()
{
	//IOS();
	cin>>N;
	a.resize(N);
	for(int i = 0;i < N;i++){
		cin>>a[i];
	}
	rep(i,0,N-1){
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	auto dp = dfs(0,-1);
	int ans = INF;
	rep(j,0,N+1){
		if(dp[j][1]<INF/2)chmin(ans,j);
		if(dp[j][0]<0)chmin(ans,j);
	}
	cout<<ans<<endl;
}

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

int	main()
{
	int	N, M, C;
	int	A, *B;
	int	n, m, count, sum;

	m = 0;
	count = 0;
	scanf("%d %d %d\n", &N, &M, &C);
	B = (int *)malloc(sizeof(int) * (M + 1));
	while (m < M)
	{
		scanf("%d ", &B[m]);
		m++;
	}
	n = 0;
	while (n < N)
	{
		m = 0;
		sum = 0;
		while (m < M)
		{
			scanf("%d ", &A);
			sum += A * B[m];
			m++;
		}
		if ((sum + C) > 0)
			count++;
		n++;
	}
	printf("%d\n", count);
	return (0);
}

Measured memory_bytes: 128
//include
//------------------------------------------
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>

#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <ctime>

// namespace
using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

// constant
static const ll MOD = 998244353LL;
static const double PI = 3.14159265358979323846;

// conversion
inline ll toint(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// print
#define RET(x) return cout << x << endl, 0;

// for loop
#define REP(i, a, b) for ((i) = (ll)(a);(i) < (ll)(b);(i)++)
#define REPD(i, a, b) for (ll i = (ll)(a);(i) < (ll)(b);(i)++)
#define REPI(v, vs) for (auto& v : vs)

//debug
#ifdef LOCAL_ENV
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define DUMP(x)
#define DEBUG(x)
#endif

#define MAX_VALUE 9223372036854775807LL

template <ull N, class T, class... Args, std::enable_if_t<N == 0, int> = 0>
auto make_multiple_vector(Args... args) {
    return T(args...);
}

template <ull N, class T, class... Args, std::enable_if_t<N != 0, int> = 0>
auto make_multiple_vector(ull size, Args... args) {
    using value_type = std::decay_t<decltype(make_multiple_vector<N - 1, T>(args...))>;
    return vector<value_type>(size, make_multiple_vector<N - 1, T>(args...));
}

int solve() {
	ll N, X, M;
	cin >> N >> X >> M;

	vector<ll> found_indices(M, -1);
	vector<ll> accums;
	ll res = 0;
	ll idx = 0;
	ll curr_x = X;
	while (idx < N) {
		res += curr_x;
		accums.emplace_back(res);

		if (found_indices[curr_x] != -1) break;
		found_indices[curr_x] = idx;

		curr_x = (curr_x * curr_x) % M;
		++idx;
	}
	if (idx == N) RET(res);
	ll prev_idx = found_indices[curr_x];
	ll cyclic_sum = accums[idx] - accums[prev_idx];
	ll cyclic_len = idx - prev_idx;

	res += (N - 1LL - idx) / cyclic_len * cyclic_sum;

	idx += ((N - 1LL - idx) / cyclic_len) * cyclic_len;
	++idx;
	while (idx < N) {
		curr_x = (curr_x * curr_x) % M;
		res += curr_x;
		++idx;
	}

	RET(res);

	return 0;
}

//main function
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();
	// ll t;
	// cin >> t;
	// REPD(i, 0, t) solve();

	return 0;
}


Measured memory_bytes: 4664
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    int N;
    cin >> N;
    string res[4]={"AC","WA","TLE","RE"};
    int ans[4]={};
    rep(i,N){
        string s;
        cin >> s;
        if(s=="AC") ans[0]++;
        else if(s=="WA") ans[1]++;
        else if(s=="TLE") ans[2]++;
        else ans[3]++;
    }
    rep(i,4) cout << res[i] << " " << "x" << " " << ans[i] << endl;
}

Measured memory_bytes: 3656
package main

import (
    "fmt"
)

var m map[int]map[int]bool
var cs []int
var chk map[int]bool

func main() {
    var n int
    fmt.Scan(&n)

    m = make(map[int]map[int]bool)
    cs = make([]int, n)
    chk = make(map[int]bool)

    for i := 0; i < n-1; i++ {
        var u, v, w int
        fmt.Scan(&u, &v, &w)
        u--
        v--
        if _, ok := m[u]; !ok {
            m[u] = make(map[int]bool)
        }
        m[u][v] = w%2 == 0
        if _, ok := m[v]; !ok {
            m[v] = make(map[int]bool)
        }
        m[v][u] = w%2 == 0
    }

    search(0, 0)

    for i := range cs {
        fmt.Println(cs[i])
    }
}

func search(pos int, clr int) {
    if b, ok := chk[pos]; ok && b {
        return
    }
    cs[pos] = clr
    chk[pos] = true
    for k, v := range m[pos] {
        if v {
            search(k, clr)
        } else {
            search(k, 1-clr)
        }
    }
    return
}


Measured memory_bytes: 37120
import java.util.*;
public class Main {
    static Scanner sc = new Scanner(System.in);//XLipÌÏ
    static double time_of_500m, time_of_1000m;//^Cði[·éÏ
    public static void main(String[] args) {
        while(sc.hasNextDouble()){//Ìsª éÈçÇÝæèÆ»èðÀs
            read();//ÇÝæè
            slove();//»è
        }
    }
    static boolean read(){
        time_of_500m = sc.nextDouble();//ÇÝæè
        time_of_1000m = sc.nextDouble();//ÇÝæè
        return true;
    }
    static void slove(){
        //System.out.println(time_of_500m);fobOpÈÌÅCÉµÈ¢Å­¾³¢
        //System.out.println(time_of_1000m);fobOpÈÌÅCÉµÈ¢Å­¾³¢
        //±±©çÍüÍÉÎµÄif¶Åðð»èµÄ¢Ü·B
        if(time_of_500m < 35.5 && time_of_1000m < 71.0){
            System.out.println("AAA");
        }else if(time_of_500m < 37.5 && time_of_1000m < 77.0){
            System.out.println("AA");
        }else if(time_of_500m < 40.0 && time_of_1000m < 83.0){
            System.out.println("A");
        }else if(time_of_500m < 43.0 && time_of_1000m < 89.0){
            System.out.println("B");
        }else if(time_of_500m < 50.0 && time_of_1000m < 105.0){
            System.out.println("C");
        }else if(time_of_500m < 55.0 && time_of_1000m < 116.0){
            System.out.println("D");
        }else if(time_of_500m < 70.0 && time_of_1000m < 148.0){
            System.out.println("E");
        }else{
            System.out.println("NA");
        }
    }
}

Measured memory_bytes: 12000
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9+7;
const int MAX = 5100000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1e9+7
vector<ll> fac(MAX), finv(MAX), inv(MAX);

int main(){
    ll n,K; cin >> n >> K;
    vl h(n+1,0);
    REP(i,1,n+1) cin >> h[i];
    ll dp[n+1][K+1][n+1];
    rep(i,n+1) rep(j,K+1) rep(k,n+1) dp[i][j][k] = linf;
    dp[0][0][0] = 0;
    rep(i,n){
        rep(j,K+1){
            rep(k,i+2){
                if(j<K) chmin(dp[i+1][j+1][k], dp[i][j][k]);
                chmin(dp[i+1][j][i+1], dp[i][j][k] + max(0LL,h[i+1]-h[k]));
            }
        }
    }
    ll ans = linf;
    rep(i,K+1)rep(j,n+1) chmin(ans, dp[n][i][j]);
    /*rep(i,n+1){
        rep(j,K+1){
            rep(k,n+1) cout << dp[i][j][k] << " ";
            cout << endl;
        }
        cout << endl;
    }*/
    cout << ans << endl;
}


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N, K; cin >> N >> K;
        vector<ll> V(N); cin >> V;
        ll ans = -INFL;
        rep(k, min(K, N) + 1) {
            repeat(x, 1, k + 1) {
                vector<ll> s;
                rep(j, x) s.push_back(V[j]);
                rep(j, k - x) s.push_back(V[N - j - 1]);
                sort(all(s));
                ll sum = accumulate(all(s), 0ll);
                int cnt = K - k;
                rep(i, min<int>(K - k, s.size())) if(s[i] < 0) {
                    sum -= s[i];
                    cnt++;
                }
                // debug(sum);
                set_max(ans, sum);
            }
        }
        cout << ans << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 256
N = int(input())

L = [int(x) for x in input().split()]

M = []
for a in range(N):
  for b in range(a+1,N):
    for c in range(b+1,N):
      if L[a]+L[b]>L[c] and L[a]+L[c]>L[b] and L[b]+L[c]>L[a] \
      and L[a] != L[b] and L[a] != L[c] and L[b] != L[c]:
        M.append((a,b,c))

print(len(M))

Measured memory_bytes: 20328
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    
    vector<vector<int>> like(N);
    rep(i, N) like[A[i] - 1].push_back(i);
    int ans = 0;
    rep(i, N) {
        for (int n : like[i]) {
            if (n == A[i] - 1) ++ans;
        }
    }
    cout << ans / 2 << endl;
    return 0;
}


Measured memory_bytes: 6144
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main() {
#ifdef RUN_LOCAL
  ifstream in("../input.txt");
  cin.rdbuf(in.rdbuf());
#endif

  cin.tie(0);
  ios::sync_with_stdio(false);

  int n;
  cin >> n;
  string s;
  cin >> s;

  vector<int> v_r, v_g;
  set<int> s_b;
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'R') {
      v_r.push_back(i);
    }
    else if (s[i] == 'G') {
      v_g.push_back(i);
    }
    else {
      s_b.insert(i);
    }
  }

  ll possible_sum = v_r.size() * v_g.size() * s_b.size();
  ll same_interval = 0;
  for (int i = 0; i < v_r.size(); ++i) {
    for (int j = 0; j < v_g.size(); ++j) {
      int smaller = min(v_r[i], v_g[j]) - abs(v_r[i] - v_g[j]);
      int bigger = max(v_r[i], v_g[j]) + abs(v_r[i] - v_g[j]);
      if (s_b.count(smaller) > 0) {
        ++same_interval;
      }
      if (s_b.count(bigger) > 0) {
        ++same_interval;
      }
      if (abs(v_r[i] - v_g[j]) % 2 == 0) {
        int mid = min(v_r[i], v_g[j]) + abs(v_r[i] - v_g[j]) / 2;
        if (s_b.count(mid) > 0) {
          ++same_interval;
        }
      }
    }
  }

  cout << possible_sum - same_interval << endl;

  return 0;
}


Measured memory_bytes: 3244
s = input()
t = input()
check = 0
con1 = len(t) - len(s)
if len(s) >= 1 and len(s) <= 10:
    for i in range (0, len(s)):
        if s[i] == t[i]:
            check = 0
            continue
        else:
            check = 1
            break
    if con1 == 1 and check == 0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 9060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	int n;
	cin>>n;
	int cnt=0;
	rep(i,n){
		int a,b;
		cin>>a>>b;
		if(a==b){
			cnt++;
			if(cnt==3){
				cout<<"Yes"<<endl;
				return 0;
			}
		}else{
			cnt=0;
		}
	}
	if(cnt==3){
		cout<<"Yes"<<endl;
		
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3628
import sys
# import math
input = sys.stdin.readline


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


def str_array():
    return input().strip().split()


def lower_letters():
    lowercase = [chr(i) for i in range(97, 97+26)]
    return lowercase

def how_frequent(lis):
	last = None
	count = []
	each = 1
	for i in range(len(lis)):
		if last != None:
			last = lis[i-1]
		if last == lis[i]:
			each += 1
		else:
			count.append(each)
			each = 0
		last = lis[i]
	return max(count)


def upper_letters():
    uppercase = [chr(i) for i in range(65, 65+26)]
    return uppercase

######################### TEMPLATE ENDS HERE ##################################
n = int(input())
if n % 1000 != 0:
	print(1000-(n%1000))
else:
	print(0)

Measured memory_bytes: 62056
#include <iostream>

using namespace std;

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

Measured memory_bytes: 2996
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const ll mod = 998244353;
    ll n;
    cin >> n;
    vector<ll> d(n);
    rep(i, n) {
        cin >> d[i];
        if (
            ((i == 0) && (d[i] != 0)) ||
            ((i != 0) && (d[i] == 0))
        ) {
            cout << 0 << endl;
            return 0;
        }
    }
    
    sort(all(d));
    vector<ll> dp(n);
    ll bv = -1, bc = 0;
    ll cv = -1, cc = 0;
    rep(i, n) {
        if (cv != d[i]) {
            if ((cv + 1) != d[i]) {
                cout << 0 << endl;
                return 0;
            }
            bv = cv; bc = cc;
            cv = d[i]; cc = 0;
        }
        cc++;
        if (d[i] < 2) dp[i] = 1;
        else {
            dp[i] = (dp[i - 1] * bc) % mod;
        }
    }
    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
#include<cmath>
#include<queue>
#include<map>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
typedef long long ll;

ll gcd(ll a,ll b){
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

int main(){

  int n,k; cin >> n >> k;
  string s; cin >> s;
  char first=s[0];
  vector<int> seqNum;
  char now=first;
  rep(i,n){
    int seq=0;
    while (s[i]==now){
      seq++;i++;
    }
    i--;
    seqNum.push_back(seq);
    if (now=='0'){now='1';}else{now='0';}
  }

  //rep(i,seqNum.size()){cout << seqNum[i] << endl;}

  int zero;
  int siz=seqNum.size();
  if (first=='0') {zero=(int)ceil(siz/2.0);}
  else {zero=(int)floor(siz/2.0);}
  int ans;

  if (k>=zero) {ans = n;}
  else {
    int l,r;
    int flag = 0;
    l=0;
    if (first=='0'){r=2*k-1;} else {r=2*k;}
    int sum=0;
    for (int i=l; i<=r; i++){
      sum+=seqNum[i];
    }
    //cout << sum << endl;
    ans=sum;
    if (first=='0'){
      l++;r+=2;
    } else {
      l+=2;r+=2;
      sum -= seqNum[l-2];
    }
    if (r==siz) {r=siz-1;flag=1;}
    sum -= seqNum[l-1];
    if (flag == 0){sum += seqNum[r-1]+seqNum[r];}
    else {sum += seqNum[r];}
    ans = max(sum,ans);
    l+=2;r+=2;
    if (r==siz) {r=siz-1;flag=1;}
    while (r<siz){
      sum -= seqNum[l-1]+seqNum[l-2];
      if (flag == 0){sum += seqNum[r-1]+seqNum[r];}
      else {sum += seqNum[r];}
      ans = max(sum,ans);
      l+=2;r+=2;
      if (r==siz) {r=siz-1;flag=1;}
    }
  }

  cout << ans << endl;


  return 0;
}


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

int main(){
int a, b, c, ans;
  cin >> a >> b;
  
  c = b -a;
  ans = 0;
    while(c){
      ans += c;
      c--;
  }
 
 ans -= b;
  
  cout << ans << endl;

  return 0;
  
}

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

int int_sort(const void * a, const void * b){
	if( *(int *)a < *(int *)b)
		return -1;
	else
	if( *(int *)a == *(int *)b)
		return 1;
}

int main(){
	int n, d[100000], i, ans;
	size_t data_cnt;

	scanf("%d", &n);


	for(i=0; i<n; i++){
		scanf("%d", &d[i]);
	}

	qsort((void *)d, n, sizeof(d[0]), int_sort);

	ans = d[n/2] - d[n/2-1];

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

	return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <set>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MAX 100000
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> P;

int main(void) {
    ll n;
    string s;
    cin >> n >> s;
    ll i, j;
    ll ans=0;
    map<pair<string, string>, ll> cnt;
    for(i=0; i<1<<n; i++) {
        string a, b;
        for(j=0; j<n; j++) {
            if(1&i>>j) a+=s[j];
            else b=s[j]+b;
        }
        cnt[{a, b}]++;
    }
    
    for(i=0; i<1<<n; i++) {
        string a, b;
        for(j=0; j<n; j++) {
            if(1&i>>j) a+=s[j+n];
            else b=s[j+n]+b;
        }
        ans+=cnt[{b, a}];
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 87040
#include <iostream>
#include <vector>
#include <cmath>
#include <climits>
#include <set>
using namespace std;
#define repn(i,s,n) for (int i=int(s); i < int(n); i++)
#define rep(i,n) repn(i,0,n)
#define repd(i,n) for (int i=int(n)-1; i >= 0; i--)

vector<char> ans;
char field[100][100];

char dir2char[4] = {'U', 'R', 'D', 'L'};
int char2dir[256];
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};

int h, w;

bool dfs(int x, int y, int dir, int rem) {
  if (rem == 0) return true;

  field[y][x] = '.';
  rep(ndir, 4) {
    if ((dir - ndir + 4) % 4 == 2) continue;
    int ny = y + dy[ndir];
    int nx = x + dx[ndir];
    while (0 <= nx && nx < w && 0 <= ny && ny < h && field[ny][nx] != 'o') {
      ny += dy[ndir];
      nx += dx[ndir];
    }

    if (0 <= nx && nx < w && 0 <= ny && ny < h) {
      ans.push_back(dir2char[ndir]);
      if (dfs(nx, ny, ndir, rem-1)) return true;
      ans.pop_back();
    }
  }
  field[y][x] = 'o';
  return false;
}


int main() {
  cin >> h >> w;
  int initX, initY, initDir;
  int numLeaf = 0;
  rep (di, 4) char2dir[dir2char[di]] = di;
  rep(i,h) rep(j,w) {
    cin >> field[i][j];
    if (field[i][j] == 'o') numLeaf++;
    else if (field[i][j] != '.') {
      initY = i;
      initX = j;
      initDir = char2dir[field[i][j]];
    }
  }
  dfs(initX, initY, initDir, numLeaf);
  cout << string(ans.begin(), ans.end()) << endl;
  return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,m,l;
  cin >> n >> m >> l;
  vector<vector<ll>> d(n,vector<ll>(n,1e18));
  for(int i=0;i<m;i++){
    int a,b,c;cin >> a >> b >> c;
    a--,b--;
    d[a][b]=d[b][a]=c;
  }
  for(int i=0;i<n;i++){
    d[i][i]=0;
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
        d[j][k]=min(d[j][k],d[j][i]+d[i][k]);
      }
    }
  }
  vector<vector<ll>> e(n,vector<ll>(n,-1));
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i==j){
        e[i][j]=0;
      }
      else if(d[i][j]<=l){
        e[i][j]=1;
      }
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
        if(e[j][i]!=-1&&e[i][k]!=-1){
          if(e[j][k]==-1){
            e[j][k]=e[j][i]+e[i][k];
          }
          else{
            e[j][k]=min(e[j][k],e[j][i]+e[i][k]);
          }
        }
      }
    }
  }
  int q;cin >> q;
  for(int i=0;i<q;i++){
    int s,t;cin >> s >> t;
    s--,t--;
    cout << max((ll)-1,e[s][t]-1) << endl;
  }
}

Measured memory_bytes: 1920
# coding: utf-8
# Your code here!
s=list(input())
t=list(input())
ans=len(t)
for i in range(len(s)-len(t)+1):
    count=0
    for j in range(len(t)):
        if s[i+j]!=t[j]:
            count+=1
    if ans>count:
        ans=count
print(ans)

Measured memory_bytes: 9092
#pragma GCC optimize("O3")

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <assert.h>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <random>
#include <cmath>
#include <chrono>
#include <bitset>

#define ld long double
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#define int long long
using namespace std;

const int INF = 2e18;
const int MOD = 1e9 + 7;
const int MB = 20;

vector<int> go(int start, int n, int l, vector<vector<int>>& a) {
	vector<int> d(n, INF);
	vector<bool> used(n);
	d[start] = 0;

	for (int i = 0; i < n; i++) {
		int mn = INF;
		int id = -1;
		for (int j = 0; j < n; j++) {
			if (!used[j] && d[j] < mn) {
				mn = d[j];
				id = j;
			}
		}
		if (id == -1) break;
		used[id] = true;
		for (int j = 0; j < n; j++) {
			if (used[j]) continue;
			int w = a[id][j];
			if (d[id] % l + w > l) w += (l - d[id] % l);
			if (d[j] > d[id] + w) {
				d[j] = d[id] + w;
			}
		}
	}

	return d;
}

void solve() {
	int n, m, l;
	cin >> n >> m >> l;
	vector<vector<int>> a(n, vector<int>(n, INF));
	for (int i = 0; i < m; i++) {
		int from, to, c;
		cin >> from >> to >> c;
		from--; to--;
		if (c > l) continue;
		a[from][to] = c;
		a[to][from] = c;
	}

	vector<vector<int>> ans(n);
	for (int i = 0; i < n; i++) {
		ans[i] = go(i, n, l, a);
		for (int j = 0; j < n; j++) {
			if (ans[i][j] == INF) ans[i][j] = -1;
			else ans[i][j] = (ans[i][j] - 1) / l;
		}
	}

	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int from, to;
		cin >> from >> to;
		from--; to--;
		cout << ans[from][to] << '\n';
	}
}
signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout.precision(12);
	solve();
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl


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

    int cnt = 0;
    for (int i=0; i<N; ++i) {
        bool flag = true;
        for (int j=0; j<i; ++j) {
            if (H[j] > H[i]) {
                flag = false;
            }
        }
        if (flag) ++cnt;
    }
    print(cnt);
}

Measured memory_bytes: 256
#include <stdio.h>
using namespace std;

int main() {
  int sum=0;
  char ch;
  while (1)
  {
    while((ch=getchar()) != '\n') {
      sum += ch - '0';
    }
    if(sum == 0) break;
    printf("%d\n", sum);
    sum =0;
  }
  
  return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;cin>>N>>M;
  for(int X=0;X<M;X++){
    int A;cin>>A;
    N-=A;
  }
  if(N<0){
    cout<<-1<<endl;
  }
  else cout<<N<<endl;
}

Measured memory_bytes: 3604
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

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 (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;


int main()
{
	int n;
	cin >> n;
	int n_odd = (n + 1) / 2;
	dbl ans = (dbl)n_odd / n;
	cout << setprecision(12) << ans << endl;
}


Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
int main() {
    int r;
    cin>>r;
    cout<<r*2*3.141592653589793;
    
    
    
      }


Measured memory_bytes: 3800
import sys
sys.setrecursionlimit(10**9)
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,M=map(int,input().split())
    a=[int(input()) for i in range(M)]
    dp=[1]*(N+1)
    if M!=0:
        dp[1]=0 if a[0]==1 else 1
        for i in a:
            dp[i]=0
    for i in range(1,N):
        if dp[i+1]!=0:
            dp[i+1] = (dp[i]+dp[i-1]) % 1000000007
    print(dp[N])


if __name__ == '__main__':
    main()


Measured memory_bytes: 44508
#include "bits/stdc++.h"

using namespace std;

void Main() {
    long long x;
    cin >> x;

    long long k = x / 11LL;
    long long l = x % 11LL;
    long long ans = 2LL * k;
    if (l == 0LL) {
        ans += 0LL;
    }
    else if (0LL < l && l <= 6LL) {
        ans += 1LL;
    }
    else {
        ans += 2LL;
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

template <typename T> void read_stdin(const size_t size, T& array)
{
   for (size_t i(0); i < size; ++i) {
      cin >> array[i];
   }
}

template <typename T> void output_stdout(const size_t size, const T& array)
{
   for (size_t i(0); i < size; ++i) {
      cout << array[i] << endl;
   }
}

string inputA;
string outputA;

int main() {
   // read
   {
      cin >> inputA;
   }

   // process
   {
      outputA = string(inputA.size(), 'x');
   }

   // output
   {
      cout << outputA << endl;
   }
   
   return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int,input().split()))
grade=[]
oldest=[]
result = [0] * (N+1-K)
for i in range(K,N+1):
    oldest.append(A[i-K])
    if i!=K:
        if A[i-1] > oldest[i-K-1]:
            print("Yes")
        else:
            print("No")

Measured memory_bytes: 31684
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    L=int(input())
    print(L**3/27)

resolve()

Measured memory_bytes: 38256
from collections import deque
n=int(input())
a=list(map(int,input().split()))
ad=deque(a)
tmp=1
ans=0
while ad:
    if ad[0] ==tmp:
        tmp+=1
        ad.popleft()
    else:
        ad.popleft()
        ans+=1
if tmp==1 and ans>0:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 78028