akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <utility>

using namespace std;

int n, m;
vector<int> g[111111];
int c[111111];
pair<int, int> t[111111];
int o[111111];

int main(void) {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b; scanf("%d%d", &a, &b);
    --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
    t[i] = {a, b};
  }
  queue<int> q;
  q.push(0);
  memset(c, -1, sizeof(c));
  c[0] = 0;
  while (!q.empty()) {
    int p = q.front(); q.pop();
    for (int i = 0; i < int(g[p].size()); i++) {
      int e = g[p][i];
      if (c[e] < 0) {
        c[e] = c[p]+1;
        q.push(e);
      }
    }
  }

  int a, b; a = b = 0;
  for (int i = 0; i < n; i++) {
    o[i] = c[i]%2;
    if (o[i] == 0) ++a;
    else ++b;
    // printf("%d ", o[i]);
  }
  // puts("");

  // printf("%d %d\n", a, b);

  bool ok = true;
  int cc = 0;
  for (int i = 0; i < m; i++) {
    if (o[t[i].first] == o[t[i].second]) {
      ok = false;
    }
  }
  if (ok) {
    printf("%lld\n", (long long)a * b - m);
  } else {
    printf("%lld\n", (long long)n * (n-1) / 2 - m);
  }
  return 0;
}


Measured memory_bytes: 7680
// B - Small and Large Integers

#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> a >> b >> k;
  vlli d(n);
  repe(i, a, b)
  {
    if (i < a + k || i > b - k)
    {
      cout << i << endl;
    }
  }
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline

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

    g = tuple(set() for _ in range(N))
    for _ in range(M):
        a, b = (int(x) - 1 for x in input().split())
        g[a].add(b)
        g[b].add(a)

    intersect = {u_1 for u_1 in g[0]} & {u_N for u_N in g[N - 1]}
    print('POSSIBLE' if intersect else 'IMPOSSIBLE')


if __name__ == '__main__':
    main()


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

int main(void) {
  int N,C,K;
	cin >> N >> C >> K;
  int T[N];
  REP(i,N) { cin >> T[i]; }
  sort(T, T+N);
  
  int ans = 1, count = 0, l_at = T[0] + K;
  REP(i,N) {
    count++;
    if (count > C || T[i] > l_at) {
      ans++;
      count = 1;
      l_at = T[i] + K;
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func next() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)

	c := next()

	if c == "a" || c == "e" || c == "i" || c == "o" || c == "u" {
		fmt.Println("vowel")
	} else {
		fmt.Println("consonant")
	}
}


Measured memory_bytes: 640
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
import sys
readline = sys.stdin.buffer.readline
geta = lambda fn: list(map(fn, readline().split()))
gete = lambda fn: fn(readline())

def main():
	n=gete(int)
	dp=[[0]*3 for _ in range(n+1)]
	
	
	for i in range(n):
		a,b,c = geta(int)
		dp[i+1][0] = max(dp[i][1], dp[i][2]) + a
		dp[i+1][1] = max(dp[i][2], dp[i][0]) + b
		dp[i+1][2] = max(dp[i][0], dp[i][1]) + c
		
	print(max(dp[n][0],dp[n][1],dp[n][2]))
	
	
	
if __name__ == "__main__":
	main()

Measured memory_bytes: 54124
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
  string a,b;
    cin>>a>>b;
  string c=a+b;
  int d=stoi(c);
  rep(i,317){
    if(i*i==d){
    cout<<"Yes"<<endl;
    return 0;
    }
  }  
   cout<<"No"<<endl; 
return 0;
}


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

int main(void){
    int N;
    cin >> N;
    vector<unsigned long long> A(N);

    for(int i{0}; i<N; ++i){
        cin >> A[i];
    }

    unsigned long long sum{0};

    unsigned long long sum_j{0};
    for(int j{1}; j<N; ++j){
        sum_j += A[j];
    }

    for(int i{0}; i<N-1; ++i){
        sum += A[i] * (sum_j % 1000000007);
        sum = sum % 1000000007 ;
        sum_j -= A[i+1];
    }

    cout << sum << endl;
}


Measured memory_bytes: 4844
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

const int MAX_N = 1 << 17;
const int INF = (1LL << 31) - 1;

template <class T>
struct MinSegTree {
	int n;
	T dat[2 * MAX_N - 1];
	void init(int n_) {
		n = 1;
		while(n < n_) n *= 2;
		for(int i = 0; i < 2 * n - 1; i++) dat[i] = INF;
	}

	void update(int k, T a) {
		k += n - 1;
		dat[k] = a;
		while(k > 0) k = (k - 1) / 2, dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
	}

	T query(int a, int b) { return query(a, b, 0, 0, n); }

	T query(int a, int b, int k, int l, int r) {
		if(r <= a || b <= l) return INF;
		if(a <= l && r <= b) return dat[k];
		int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
		return min(vl, vr);
	}

	void show() {
		for(int i = 0; i < n; i++) cout << dat[i + n - 1] << " ";
		cout << endl;
	}
};

MinSegTree<int> st;

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

	int n, q;
	cin >> n >> q;

	st.init(n);

	while(q--) {
		int c, x, y;
		cin >> c >> x >> y;
		if(c == 0) {
			st.update(x, y);
		}
		else {
			cout << st.query(x, y + 1) << endl;;
		}
	}
}

Measured memory_bytes: 4176
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;
#define MAX_N 100001



int main()
{
	
	ll N;
	cin>>N;
	stack<char> str;
	while( N > 0){
		ll num = N % 26;
		char ch;
		if(num == 0){
			ch = 'z';
			N = N / 26;
			N--;
		}else{
			ch = 'a' - 1 + num;
			N = N / 26;
		}
		
		str.push(ch);
		
		//cout<<num<<endl;
	}
	while(!str.empty()){
		cout<<str.top();
		str.pop();
	}
	cout<<endl;
	return 0;
}


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

int main()
{
    int x,i;
    char qwe[10];
    while(~scanf("%s",qwe))
    {
        x=0;
        for(i=0;i<4;i++)
        {
            if(qwe[i]=='+')
            {
                x=x+1;
            }
            if(qwe[i]=='-')
            {
                x=x-1;
            }
        }printf("%d\n",x);
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int n, m;
  cin >> n >> m;
  cout << (n - 1) * (m - 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N,M;
    cin >> N >> M;
    ll dp[N+1][M+1];
    rep(i,N+1){
        rep(j,M+1){
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;
    vl S(N),T(M);
    rep(i,N){
        cin >> S[i];
    }
    rep(i,M){
        cin >> T[i];
    }
    rep(i,N+1){
        rep(j,M+1){
            if(i*j==0){
                dp[i][j]=1;
            }
            else{
                dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
              	if(S[i-1]==T[j-1]){
                  	dp[i][j]+=dp[i-1][j-1];
                }
            }
            dp[i][j]%=MOD;
        }
    }
    cout << (dp[N][M]+MOD)%MOD << endl;
}


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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) (a).begin(),(a).end()
#define SORT(a) sort(all(a))
using ll = long long;
constexpr ll INF = 10000000000;
constexpr ll MOD = 1000000007;

using namespace std;

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

	ll n, m; cin >> n >> m;

	ll count = 0;			//作ったSccの数
	
	count = min(n, m / 2);

	ll nl = 0;
	ll ml = 0;


	nl = n - min(n, m / 2);
	ml = m - n * 2;

	
	if (ml >= 4) {
		count += ml / 4;
	}
	

	//cout << nl << ' ' << ml << endl;
	cout << count << endl;
}


Measured memory_bytes: 256
'use strict'
const main = (input: string) => {
    const std: string[] = input.split('\n');
    const n = Number(std.shift())
    const p = std.shift().split(' ').map(Number)
    let count = 0
    for (let i = 1; i < n-1; i++) {
        if (p[i-1] < p[i] && p[i] < p[i+1] || p[i-1] > p[i] && p[i] > p[i+1]) {
            count++
        }
    }
    console.log(count)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim())


Measured memory_bytes: 7372
N,K = map(int,input().split())
start = sum(range(0,K-1))
ans = 0

for i in range(N-K+2):
    n = K+i
    start = n*(n-1)//2
    saidai = (n*(2*N - n + 1)//2)
    ans += saidai - start + 1
print(ans % ((10**9)+7))

Measured memory_bytes: 9200
#include <numeric>
#include <iostream>
#include <array>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <math.h> 
#include <set>
#include <map>
#include <utility>
#include <deque>
#include <queue>
#include <iomanip>
#include <limits>

using namespace std;

#define ll long long int
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repp(i, n) for(ll i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define riverse(v) reverse((v).begin(), (v).end())
#define pb push_back
#define mp make_pair
#define all(a)  (a).begin(),(a).end()
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
const ll MOD = 1e9 + 7;
const double pi = 3.14159265358979323846264338327950288;
vi alphabet = { 'a','b','c','d','e','f','g','h','i','j','k','l','m',
               'n','o','p','q','r','s','t','u','v','w','x','y','z' };



int main() {
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    double degree;
    degree = (60 * H + M) * 5.5;
    while (degree >= 360) {
        degree -= 360;
    }
    if (degree > 180) degree = 360 - degree;
    degree = degree * pi / 180;
    double yo = cos(degree);
    double a2 = A * A + B * B - 2 * A * B * yo;
    double ans = sqrt(a2);
    cout << fixed << setprecision(10);
    cout << ans << endl;
}   

Measured memory_bytes: 4236
#include <bits/stdc++.h>
using namespace std;
int main () {
  string a, b;
  cin >> a >> b;
  int x = stoi(a + b);
  int ans = (int)sqrt(x);
  if (ans * ans == x) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
h = Array.new(5) { Array.new(3) { Array.new(10,0) } }
n = gets.to_i
n.times do
  a,b,c,d = gets.split.map(&:to_i)
  h[a-1][b-1][c-1] += d
end

for i in 0...4  do
      puts "#"*20 if i >0
  for j in 0...3 do
      puts " "+h[i][j].join(" ") 
  end
end


Measured memory_bytes: 6892
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>
//#include<bits/stdc++.h>

using namespace std;
long long MOD = 1000000007LL;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<char>> vec(N + 2, vector<char>(M + 2, '.'));

	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= M; ++j) {
			cin >> vec[i][j];
		}
	}
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= M; ++j) {
			if (vec[i][j] == '#'
				&& vec[i + 1][j] == '.'
				&& vec[i - 1][j] == '.'
				&& vec[i][j + 1] == '.'
				&& vec[i][j - 1] == '.') {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;


//1
int main() {
	int ans = 0;
	for (int i = 0; i < 10; i++) {
		int a;
		cin >> a;
		ans += a;
	}
	cout << ans << endl;

	return 0;
}


/*
//2
int main() {


return 0;
}
*/

/*
//3
int main() {


return 0;
}
*/

/*
//4
int main() {


return 0;
}
*/

/*
//5
int main() {


return 0;
}
*/

/*
//6
int main() {


return 0;
}
*/

/*
//7
int main() {


return 0;
}
*/

/*
//8
int main() {


return 0;
}
*/

/*
//9
int main() {


return 0;
}
*/

/*
//10
int main() {


return 0;
}
*/




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

using namespace std;	
typedef long long LL;
const int nn = 1e6 + 5;

int main() {
	LL r, D, x;
	scanf("%lld %lld %lld", & r, & D, & x);
	for (int i = 1; i <= 10; i++) {
		x = r * x - D;
		printf("%lld\n", x);
	}
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(void){
    int n, q;
    ll k;
    cin >> n >> k >> q;
    vi a(n+1, 0);
    REP(i, q) {
        int x;
        cin >> x;
        a[x]++;
    }
    REP(i, n) {
        if(q-a[i+1] < k) {
            cout << "Yes" << endl;
        }else {
            cout << "No" << endl;
        }
    }
    return 0;
}

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

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

    x /= 50;

    int cnt = 0;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            int k = x - (10 * i + 2 * j);
            if (0 <= k && k <= c) {
                cnt++;
            }
        }
    }

    cout << cnt << endl;
    
    return 0;
}

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

int main(){
    vector<int> s(3);
    for(int i=0;i<3;i++)cin>>s[i];
    sort(s.begin(), s.end());
    for(int i=0;i<2;i++){
        cout<<s[i]<<" ";
    }
    cout<<s[2]<<endl;
    return 0;
}



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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) ;
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;

int dx[4]{0, 1, 0, -1};
int dy[4]{1, 0, -1, 0};

ll N;
string X;

long long modpow(const long long a, const long long n, const long long mod)
{
        if (n == 0) return 1;
        long long t = modpow(a, n / 2, mod);
        (t = t * t) %= mod;
        if (n & 1)
			(t = t * a) %= mod;
        return t;
}

const ll M = 2*100000+10;
ll n2f[M];

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

	cin >> N >> X;

	ll cnt1=0;
	for (auto e : X) cnt1+=e-'0';

	auto f = [](ll n) -> ll
			 {
				 ll cnt{0};
				 while (true)
				 {
					 if (n == 0) return cnt;
					 ++cnt;
					 n %= __builtin_popcount(n);
				 }
			 };


	REP(i, M)
	{
		n2f[i] = f(i);
	}

	ll to1, to2;
	to1 = to2 = 0;
	REP(i, N)
	{
		if (X[i] == '1')
		{
			if (cnt1 > 1)
				(to1 += modpow(2, N-1-i, cnt1-1)) %= (cnt1-1);
			(to2 += modpow(2, N-1-i, cnt1+1)) %= (cnt1+1);
		}
	}

	REP(i, N)
	{
		ll res;

		if (X[i] == '1')
		{
			if (cnt1 <= 1) res = 0;
			else res = n2f[(to1 - modpow(2, N-1-i, cnt1-1) + (cnt1-1)) % (cnt1-1)] + 1;
		}
		else
			res = n2f[(to2 + modpow(2, N-1-i, cnt1+1)) % (cnt1+1)] + 1;
		std::cout << res << std::endl;
	}
	
	return 0;
}


Measured memory_bytes: 5324
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
using namespace std;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

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

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 1000 * 100 + 47;

int A[MAX];

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	
	ios::sync_with_stdio(false); cin.tie(0);
	int n, l;
	cin >> n >> l;
	FOR(i, 0, n)
	{
		cin >> A[i];
	}

	int ind = -1;
	FOR(i, 1, n)
	{
		if (A[i] + A[i - 1] >= l)
		{
			ind = i;
			break;
		}
	}

	if (ind == -1)
	{
		cout << "Impossible" << endl;
		return 0;
	}

	cout << "Possible" << endl;
	FOR(i, 0, ind - 1) cout << i + 1 << "\n";
	RFOR(i, n - 1, ind) cout << i + 1 << "\n";
	cout << ind << "\n";
}

Measured memory_bytes: 1280
#pragma region Header
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, a, b) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

// {waapu, h, w}
using p = tuple<int, int, int>;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int h_size, w_size;
    cin >> h_size >> w_size;
    int h_from, w_from;
    cin >> h_from >> w_from;
    --h_from;
    --w_from;
    int h_to, w_to;
    cin >> h_to >> w_to;
    --h_to;
    --w_to;
    vector can_go(h_size, vector<bool>(w_size));
    rep(h, h_size)
    {
        rep(w, w_size)
        {
            char c;
            cin >> c;
            can_go[h][w] = (c == '.');
        }
    }

    // dijkstra
    int ans = -1;
    vector dist(h_size, vector<int>(w_size, 1000'000));
    priority_queue<p, vector<p>, greater<p>> pq;
    vector used(h_size, vector<bool>(w_size, false));
    pq.emplace(0, h_from, w_from);
    while (not pq.empty())
    {
        auto [cost, h, w] = pq.top();
        pq.pop();
        if (h == h_to and w == w_to)
        {
            ans = cost;
            break;
        }
        if (used[h][w])
        {
            continue;
        }
        used[h][w] = true;
        FOR(dh, -2, 2)
        {
            FOR(dw, -2, 2)
            {
                auto h_new = h + dh, w_new = w + dw;
                if (h_new < 0 or h_new >= h_size or w_new < 0 or w_new >= w_size)
                {
                    continue;
                }
                if (not can_go[h_new][w_new] or used[h_new][w_new])
                {
                    continue;
                }
                int dcost = (abs(dh) + abs(dw) > 1);
                if (not chmin(dist[h_new][w_new], cost + dcost))
                {
                    continue;
                }
                pq.emplace(cost + dcost, h_new, w_new);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7908
x1,y1,x2,y2 = map(int, input().split())


x3 = x2 - (y2 - y1)
y3 = y2 + x2 - x1
x4 = x1 - (y2 - y1)
y4 = y1 + x2 - x1

print(x3, y3, x4, y4)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int long long int 
#define fi first
#define se second
#define FIO {ios::sycnt2_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pow10(n) stoll("1"+string(n,'0'))
//fill(all(arr),1)
//if(map.count(key)){}
//bitset<20>(n);
//int mini=min({a,b,c,d,e});
#define int long long int
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;
int32_t main()
{
  string s,t;
  cin>>s>>t;
  int mini=INT_MAX;
  if(s.size()==t.size())
  {
    int cnt=0;
    forn(i,s.size())
    {
      if(s[i]!=t[i])cnt++;
    }
    cout<<cnt;return 0;
  }
  forn(i,s.size()-t.size())
  {
    int cnt=0;
    for(int j=0;j<t.size();j++)
    {
      //cout<<s[i+j]<<t[j];
      if(s[i+j]!=t[j])
      {
        cnt++;
      }
    }
    mini=min(mini,cnt);
      //cout<<cnt<<mini;
    //if(mini==INT_MAX)cout<<0;
  }
  cout<<mini;
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x,a,b;
    cin >> x >> a >> b;
    if(abs(x-a) < abs(x-b)) cout << "A" << "\n";
    else cout << "B" << "\n";
    return 0;
}

Measured memory_bytes: 3584
/*
Writer: SPD_9X2
https://atcoder.jp/contests/abc163/custom_test
どう考えても余事象
つまり、各色に関してそれを通らないパスの数を計算できれば良い

1色のみを考える場合→いい感じにdfs
自分がその色なら、各子について nC2をansに加えて自分は0を返す
問題は色が多い事

オイラーツアーと聞いた
オイラーツアーをすると尺取り法で求められる？
葉でreturnするときに、2つappendすることで、おなじ頂点が2個
入るのを防ぐことが出来る

=====解法を確認======

公式開放？？？？
なのでマージテクの方でいこう

ans[c] = 色cを通らないパスの数
chnum[v] = vの部分木にある頂点数
dp[v][c] = vの部分木の内,根から色cを通らないと行けない頂点数

とすれば、各v(色c)について、各子uに関して
ans[c] += nCr( chnum[u] - dp[u][c] , 2 )
とし、dp[v][c] = 0とすればよい

dp[v][c]のcの部分をmapにすれば、マージテクで、マージはO(NlogN)になる。
探索がO(logN)なので,結果 O(NlogNlogN)で解ける

*/

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n,m) for(ll (i)=(n);(i)<(m);(i)++)
#define rrep(i,n,m) for(ll (i)=(n);(i)>(m);(i)--)
using ll = long long;
const ll mod = 998244353;

ll nC2(ll x){
    return x*(x-1)/2;
}



void dfs(ll v,ll p,vector<vector<ll>>& lis,vector<ll>& col,vector<ll>& ans,vector<ll>& chnum,vector<map<ll,ll>>& dp){

    rep(i,0,lis[v].size()){
        if (lis[v][i] != p){
            dfs(lis[v][i],v,lis,col,ans,chnum,dp);
            ans[col[v]] += nC2(chnum[lis[v][i]] - dp[lis[v][i]][col[v]]);
            chnum[v] += chnum[lis[v][i]];
            
            if (dp[v].size() < dp[lis[v][i]].size()){
                swap(dp[v],dp[lis[v][i]]);
            }

            for (const auto& [k,val] : dp[lis[v][i]]){
                dp[v][k] = dp[v][k] + val;
            }

        }
    }

    dp[v][col[v]] = chnum[v];

    return;
}

int main(){

    ll N;
    cin >> N;
    vector<ll> c(N,0);
    rep(i,0,N){
        cin >> c[i];
        c[i]--;
    }
    vector<vector<ll>> lis(N,vector<ll> (0));
    ll a,b;
    rep(i,0,N-1){
        cin >> a >> b;
        a--;
        b--;
        lis[a].push_back(b);
        lis[b].push_back(a);
    }

    vector<ll> ans(N,0);
    vector<ll> chnum(N,1);
    vector<map<ll,ll>> dp(0);
    rep(i,0,N){
        map<ll,ll> tmp;
        dp.push_back(tmp);
    }

    dfs(0,0,lis,c,ans,chnum,dp);
    rep(i,0,N){
        ans[i] += nC2(N - dp[0][i]);
    }

    rep(i,0,N){
        ans[i] = nC2(N) - ans[i];
    }

    rep(i,0,N){
        ans[c[i]] ++;
    }

    rep(i,0,N){
        cout << ans[i] << endl;
    }

}

Measured memory_bytes: 90544
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  int a, b, c; cin >> a >> b >> c;
  if(a + b == c || b + c == a || c + a == b) cout << "Yes\n";
  else cout << "No\n";
  return;
}

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


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

ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}
 
#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
template<class T> int size(T && a) { return a.size(); }
 
using LL = long long;
using PII = pair<int, int>;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;
	vector<int> A(n), B(n);
	vector<PII> p(n);
	REP(i, n) cin >> A[i];
	REP(i, n) cin >> B[i];
	REP(i, n) p[i] = {A[i], B[i]};
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(p.begin(), p.end(), [&](PII x, PII y) { return x.ND < y.ND; });

	bool hard = true;
	REP(i, n) {
		if(A[i] > B[i]) {
			cout << "No\n";
			return 0;
		}

		if(i && A[i] <= B[i - 1])
			hard = false;
	}
	
	if(hard) {
		map<int, int> pos;
		REP(i, n) pos[A[i]] = i;
		vector<int> jump(n);
		REP(i, n) jump[i] = pos[p[i].ST];
		vector<bool> vis(n);
		int s = 0, cnt = 0;
		while(!vis[s]) {
			vis[s] = true;
			s = jump[s];
			cnt++;
		}

		if(cnt == n)
			cout << "No\n";
		else
			cout << "Yes\n";

		return 0;
	}

	cout << "Yes\n";
}


Measured memory_bytes: 6912
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
using namespace std;
#define ll long long

void swap1(string *a,string *b){
	string temp=*a;
	*a=*b;
	*b=temp;
}
void sort1(string a[],int lower,int upper){
	 string bound=a[lower];
	 int l=lower,u=upper;
	//printf("lower = %d, upper = %d\n",l,u);
	
	do{
		while(a[l]<bound)l++;
		while(a[u]>bound)u--;
		if(l<=u){
			swap1(&a[l],&a[u]);
			l++;
			u--;
		}
	}while(l<u);
	if(lower<u)sort1(a,lower,u);
	if(l<upper)sort1(a,l,upper);
}
int main(){
	string s[100000];
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s[i];
		sort(s[i].begin(),s[i].end());
		//cout<<s[i]<<endl;//
	}
	sort1(s,0,n-1);
	for(int i=0;i<n;i++){
		//cout<<s[i]<<endl;//
	}
	ll cnt=0;
	ll ans=0;
	for(int i=0;i<n-1;i++){
		if(s[i]==s[i+1]){
			cnt++;
			ans+=cnt;
			//cout<<"yes!"<<endl;//
		}else{
			cnt=0;
		}
	}
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 7424
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
using namespace std;
 
const int MAXN=200000+10;
 
map<int,int> mp;
vector<int> v;
set<int> s;
int a[MAXN];
 
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>a[i];
		mp[a[i]]++;
	}
	for(int i=0;i<n;i++){
		if(s.find(a[i])==s.end()){
			v.push_back(mp[a[i]]);
			s.insert(a[i]);
		}
	}
	sort(v.begin(),v.end());
	int cnt=0;
	int p=v.size()-k;
	int res=max(0,p);
	if(res==0){
		cout<<0<<endl;
		return 0;
	}
	for(int i=0;i<res;i++){
		cnt+=v[i];
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 20596
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

// auto mod int
const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll n,k;

int main(){
    cin >> n >> k;
    mint ans = 0;
    vector<mint>g(k+1,0);
    for(int j=k;j>=1;j--){
        ll p = k/j;
        mint now = modpow(p,n);
        for(ll q=2;q*j<=k;q++){
            now -= g[q*j];
        }
        g[j] = now;
        ans += now * j;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4020
//Radhe Radhe
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include<boost/math/common_factor.hpp>
#include <ext/numeric>
using namespace __gnu_cxx;
using namespace std;
#define int long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define array(a,n) int a[n]; for(int i=0;i<n;i++) cin>>a[i];
#define loop(i,a,b,x) for(int i=a;i<b;i+=x)
const int MOD = 1000000007;
const int N = 10001;
//const int N = (2 * (1e5)) + 2;



int dp[3][100005];
int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
    
    int t = 1;
    //cin >> t;
    while (t--) {
        int N;
        cin >> N;
        vector<int> a(N), b(N), c(N);
        for (int i = 0; i < N; i++) {
            cin >> a[i] >> b[i] >> c[i];
        }

        dp[0][0] = a[0];
        dp[1][0] = b[0];
        dp[2][0] = c[0];
        for (int i = 1; i < N; i++) {
            dp[0][i] = a[i] + max(dp[1][i - 1], dp[2][i - 1]);
            dp[1][i] = b[i] + max(dp[0][i - 1], dp[2][i - 1]);
            dp[2][i] = c[i] + max(dp[0][i - 1], dp[1][i - 1]);
        }
        cout << max(max(dp[0][N - 1], dp[1][N - 1]), dp[2][N - 1]) << endl;

    }
    return 0;

}






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

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

    int a,b,k;
    cin>>a>>b>>k;

    for(int i=0;i<k;i++)
    {
        if(i%2==0)
        {
            a/=2;
            b+=a;
        }
        else
        {
            b/=2;
            a+=b;
        }
    }

    cout<<a<< " " << b;

    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef vector<LL> VEC;
typedef vector<VEC> VVEC;
typedef  pair<LL,LL> P;


const LL INF=1<<30;
const LL MOD=1000000007;





int main(){
    int n,k;
    cin>>n>>k;
    map<int ,int> a;
    for(int i=0;i<n;++i){
        int b;
        cin>>b;
        a[b]++;
    }
    VEC c;
    
    for(auto x:a){
        c.push_back(x.second);
    }
    sort(c.begin(),c.end(),greater<LL>());
    LL ans=0;
    for(int i=k;i<=c.size();++i){
        ans+=c[i];
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 11768
import math
A, B, K = map(int, input().split())


def divisors(n):
    ret = set()
    for i in range(1, math.ceil(n**0.5) + 1):
        if n % i == 0:
            ret.add(i)
            ret.add(n//i)
    return ret


a = sorted(list(divisors(A) & divisors(B)))
print(a[-K])


Measured memory_bytes: 38384
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define dump(x) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int main(){
    iostream_init();
    int x, y;
    cin >> x >> y;
    int a = abs(x);
    int b = abs(y);
    int ans = 0;
    if(a < b) {
        if(x < 0) ans++;
        ans += abs(b - a);
        if(y < 0) ans++;
    } else if(a == b) {
        if(x != y) ans++;
    } else {
        if(x > 0) ans++;
        ans += abs(b - a);
        if(y > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <iterator>
#include <algorithm>
#include <cfenv>
#include <random>
#include <numeric>
#include <cmath>
#include <iosfwd>
#include <iostream>
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cstdlib>
#include<string>
#include <bitset>

#define SIZE 100001
typedef long long ll;
using namespace std;

int main(){
    string S;
    cin >> S;
    int rain = 0;
    if(S[0] == 'R'){
        if(S[1] == 'R'){
            if(S[2] == 'R'){
                cout << "3" << endl;
            }else{
                cout << "2" << endl;
            }
        }else{
            if(S[2] == 'R'){
                cout << "1" << endl;
            }else{
                cout << "1" << endl;
            }
        }
    }else{
        if(S[1] == 'R'){
            if(S[2] == 'R'){
                cout << "2" << endl;
            }else{
                cout << "1" << endl;
            }
        }else{
            if(S[2] == 'R'){
                cout << "1" << endl;
            }else{
                cout << "0" << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int ravel[] = new int[6];
		for(int i = 0; i < 6; i++){
			ravel[i] = scan.nextInt();
		}
		Dice dice = new Dice(ravel);
		int q = scan.nextInt();
		int ans[] = new int[q];
		for(int i = 0; i < q; i++){
			int top = scan.nextInt();
			int front = scan.nextInt();
			ans[i] = dice.Right(top, front);
		}
		scan.close();
		for(int i = 0; i < q; i++){
			System.out.println(ans[i]);
		}
	}

	static class Dice{
		public int ravel[] = new int[6];

		public Dice(int[] _ravel) {
			ravel = _ravel;
		}

		public int Right(int topRavel, int frontRavel) {
			this.ShowSpecifiedTop(topRavel);
			this.ShowSpecifiedFront(frontRavel);
			return ravel[2];
		}

		public void ShowSpecifiedTop(int topRavel){
			int pos = 0;
			for(int i = 0; i < 6; i++){
				if(ravel[i] == topRavel){
					pos = i;
				}
			}
			switch(pos){
			case 0:
				break;
			case 1:
				this.MoveExec('N');
				break;
			case 2:
				this.MoveExec('W');
				break;
			case 3:
				this.MoveExec('E');
				break;
			case 4:
				this.MoveExec('S');
				break;
			case 5:
				this.Move("NN");
				break;
			}
		}

		public void ShowSpecifiedFront(int frontRavel){
			int pos = 1;
			for(int i = 1; i <= 4; i++){
				if(ravel[i] == frontRavel){
					pos = i;
				}
			}
			int[] oldRavel = ravel.clone();
			switch(pos){
			case 1:
				break;
			case 2:
				ravel[1] = oldRavel[2];
				ravel[2] = oldRavel[4];
				ravel[4] = oldRavel[3];
				ravel[3] = oldRavel[1];
				break;
			case 3:
				ravel[1] = oldRavel[3];
				ravel[3] = oldRavel[4];
				ravel[4] = oldRavel[2];
				ravel[2] = oldRavel[1];
				break;
			case 4:
				ravel[1] = oldRavel[4];
				ravel[3] = oldRavel[2];
				ravel[4] = oldRavel[1];
				ravel[2] = oldRavel[3];
				break;
			}
		}

		public void Move(String order){
			char ch[] = order.toCharArray();
			for(int i = 0; i < ch.length; i++){
				MoveExec(ch[i]);
			}
		}

		private void MoveExec(char chOrder){
			int[] oldRavel = ravel.clone();
			switch(chOrder){
			case 'E':
				ravel[0] = oldRavel[3];
				ravel[3] = oldRavel[5];
				ravel[5] = oldRavel[2];
				ravel[2] = oldRavel[0];
				break;
			case 'N':
				ravel[0] = oldRavel[1];
				ravel[1] = oldRavel[5];
				ravel[5] = oldRavel[4];
				ravel[4] = oldRavel[0];
				break;
			case 'S':
				ravel[0] = oldRavel[4];
				ravel[4] = oldRavel[5];
				ravel[5] = oldRavel[1];
				ravel[1] = oldRavel[0];
				break;
			case 'W':
				ravel[0] = oldRavel[2];
				ravel[2] = oldRavel[5];
				ravel[5] = oldRavel[3];
				ravel[3] = oldRavel[0];
				break;
			}
		}
	}
}

Measured memory_bytes: 26280
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];
		long sum  =0;
		for (int i=0;i<N;i++) {
			A[i] = sc.nextInt();
			sum +=A[i];
		}
		long temp =0;
		long min = Long.MAX_VALUE;
		for (int i=0;i<N-1;i++) {
			temp+=A[i];
			sum -=A[i];
			if (Math.abs(temp-sum)<min) {
				min = Math.abs(temp-sum);
			}
		}
		System.out.print(min);
	}
}

Measured memory_bytes: 65172
import math

def radi(deg):
    return deg * (math.pi / 180)

def resolve():
    ha, hb, h, m = map(int, input().split())
    hr = radi(30*h+(m/2))
    mr = radi(6*m)
    hx = ha * math.cos(hr)
    mx = hb * math.cos(mr)
    hy = ha * math.sin(hr)
    my = hb * math.sin(mr)
    v = (abs(hx - mx)**2 + abs(hy - my)**2)**0.5
    print(v)
resolve()

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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define PI (acos(-1))

int main(){
  int H,W,K;
  cin >> H >> W >> K;
  K--;
  ll dp[110][10] = {};
  dp[0][0] = 1;
  rep(h,H){
    rep(b,1<<(W-1)){

      //横棒が隣り合っていたら抜ける
      bool judge = true;
      rep(i,W-2){
        if(b&(1<<i) && b&(1<<(i+1)))judge = 0;
      }
      if((!judge))continue;

      int perm[W];
      rep(i,W)perm[i]=i;
      rep(i,W-1){
        if(b&(1<<i))swap(perm[i],perm[i+1]);
      }

      rep(i,W){
        dp[h+1][perm[i]] += dp[h][i];
        dp[h+1][perm[i]] %= MOD;
      }

    }
  }

  cout << dp[H][K] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<cmath>
#include<algorithm>
using namespace std;
void insert(int *kid,int n){
    for(int i=1;i<n;i++){
        int v=kid[i];
        int j=i-1;
        while(j>=0&&v<kid[j]){
            kid[j+1]=kid[j];
            j--;
        }
        kid[j+1]=v;
        
    }
}
int main(){

    int N,x;
    cin>>N>>x;
    int kid[N];
    for(int i=0;i<N;i++){
        cin>>kid[i];
    }
    insert(kid,N);
    int ans=0;
    for(int i=0;i<N;i++){
        x=x-kid[i];
        
        if(x<0){
            break;
        }else if(i!=N-1&&x>0){
            ans++;
        }else if(i==N-1&&x==0){
            ans++;
        }else if(x==0){
            ans++;
            break;
        }
    }
    cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int A,B,H,M;
    cin >> A >> B >> H >> M;
    double t=30*H+0.5*M;
    double m=360*H+6*M;
    double t_h=fmod(t,360);
    double m_h=fmod(m,360);
    if(m_h==0){
        m_h=360;
    }
    if(t_h==0){
        t_h=360;
    }
    double kaku=abs(t_h-m_h)*M_PI/180.0;
    double ans=sqrt(pow(A,2)+pow(B,2)-2*A*B*cos(kaku));
    printf("%.10lf\n",ans);
    

}


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

using namespace std;

vector<int> ptable(int M){
    int max = (int)sqrt(M) + 1;
    vector<int> flags(M + 1, 1);
    flags[0] = flags[1] = 0;
    for (int i=2; i <= max; i++) {
        if (flags[i]) {
            for (int j = i*2; j <= M; j += i) {
                flags[j] = 0;
            }
        }
    }

    return flags;
}

int main(void){
    int N = 100000+10;
    vector<int> P(move(ptable(N)));
    vector<int> V(N);
    V[0] = 0;
    for(int i=1;i<N;i++){
        if(i%2 == 1 && P[i] && P[(i+1)/2]){
            V[i] = V[i-1] + 1;
        } else {
            V[i] = V[i-1];
        }
    }

    int Q;
    cin >> Q;
    for(int i=0;i<Q;i++){
        int l, r;
        cin >> l >> r;
        cout << V[r] - V[l-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	int n,k,s;
	cin>>n>>k>>s;
	int z = 1e9;
	if(s!=z)
	{
		for(int i=1;i<=k;i++)
			cout<<s<<" ";
		for(int i=1;i<=n-k;i++)
			cout<<z<<" ";
		cout<<"\n";
	}
	else
	{
		for(int i=1;i<=k;i++)
			cout<<z<<" ";
		for(int i=1;i<=n-k;i++)
			cout<<"1 ";
		cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3564
import heapq
import sys
input = sys.stdin.readline

N = int(input())
edges = {i: [] for i in range(N)}
for i in range(N - 1):
    a, b, c = map(int, input().split(" "))
    edges[a - 1].append((b - 1, c))
    edges[b - 1].append((a - 1, c))
Q, K = map(int, input().split(" "))

# Kからの最短距離を計算
dist = [-1 for i in range(N)]
que = []
heapq.heappush(que, (0, K - 1, -1)) # (distance, index, parent)
while len(que) > 0:
    d, ind, par = heapq.heappop(que)
    if dist[ind] != -1:
        continue
    dist[ind] = d
    for edge in edges[ind]:
        if edge[0] == par:
            continue
        heapq.heappush(que, (d + edge[1], edge[0], ind))

for _ in range(Q):
    x, y = map(int, input().split(" "))
    print(dist[x - 1] + dist[y - 1])

Measured memory_bytes: 90468