akhauriyash/Code-Regression huggingface dataset:
from collections import deque


def solve(n):
    if n == 1:
        return ["a"]
    alphabet = "abcdefghijkl"
    res_list = []
    queue = deque([("a", 0)])
    while len(queue) > 0:
        p, k = queue.popleft()
        for i in range(k + 2):
            q = p + alphabet[i]
            queue.append((q, max(i, k)))
            if len(q) == n:
                res_list.append(q)
        if len(q) > n:
            break
    return res_list


def main():
    n = int(input())
    res = solve(n)
    for r in res:
        print(r)


def test():
    assert solve(1) == ["a"]
    assert solve(2) == ["aa", "ab"]


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 21100
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

signed main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=n-1;i>=0;i--){
    cout<<a[i];
    if(i)cout<<" ";
  }
  cout<<endl;
}



Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(x,y) for(lli i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define bg() begin()
#define en() end()
#define ft first
#define sc second
#define vect_lli_it vector<lli>::iterator
#define set_lli_it set<lli>::iterator
#define inf 1e18
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4]==s[5])
    cout<<"Yes";
    else
    cout<<"No";
	return 0;
}


Measured memory_bytes: 256
K = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(K[k-1])

Measured memory_bytes: 38384
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    int mx = 0;
    int d = 0;
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        int v;
        cin >> v;
        mx = max(mx, v);
        d = __gcd(d, v);
    }
    if (k <= mx && k % d == 0) {
        cout << "POSSIBLE";
    }
    else {
        cout << "IMPOSSIBLE";
    }
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main() {
    int Alice = 0, Bob = 0;

    int N;
    scanf("%d", &N);

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

    for (int i = 0; i < N; i++) {
        int sub = 0;

        for (int j = 0; j < N; j++) {
            if (a[sub] < a[j]) {
                sub = j;
            }
        }

        if (i % 2 == 0) {
            Alice += a[sub];
            a[sub] = 0;
        } else {
            Bob += a[sub];
            a[sub] = 0;
        }
    }

    printf("%d\n", Alice-Bob);
}

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

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

    int ans = 0;
    for(int i=0; i<4; i++){
        if(s[i] == '+') ans += 1;
        if(s[i] == '-') ans -= 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

cases = list(itertools.permutations(list(range(1, n + 1))))
#print(cases)
count = 0
for case in cases:
  count += 1
  if p == case:
    p_c = count
  if q == case:
    q_c = count
print(abs(p_c - q_c))

Measured memory_bytes: 13752
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    string s;
    cin >> s;
    
    int k;
    cin >> k;
    
    // 全部同じ文字だった場合
    string copy = s;
    sort(copy.begin(), copy.end());
    if(copy[0] == copy[s.size() - 1]) {
        cout << s.size() * k / 2 << endl;
        return 0;
    }
    
    // 連結したところでどれだけ連続するか
    int end_index = s.size() - 1;
    int front_index = 0;
    if(s[0] == s[s.size() - 1]) {
        int tmp = 0;
        while(tmp <= s.size() - 1 && s[s.size() - 1] == s[s.size() - 1 - tmp]) {
            tmp++;
        }
        end_index -= tmp;
        
        tmp = 0;
        while(tmp <= s.size() - 1 && s[0] == s[tmp]) {
            tmp++;
        }
        front_index = tmp;
    }
    
    // 連結部以外でどれだけ変えなきゃいけないか
    long long cnt = 0;
    for(int i = front_index; i < end_index; i++) {
        int tmp = 0;
        while(i + tmp < s.size() && s[i] == s[i + tmp]) {
            tmp++;
        }
        cnt += tmp / 2;
        
        i += tmp - 1;
    }
    
    long long ans = cnt * k;    // 連結部以外の合計
    ans += (k - 1) * ((s.size() - 1 - end_index + front_index) / 2);    // 連結部の合計
    ans += (s.size() - 1 - end_index) / 2;  // 一番最後の部分
    ans += front_index / 2;     // 一番最初の部分
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    int n;
    cin >> n;
    ll sum = 0;
    map<ll, ll> mp;
    mp[0] = 1;
    rep(i, 0, n) {
        int a;
        cin >> a;
        sum += a;
        mp[sum]++;
    }
    ll ans = 0;
    for (auto x : mp) {
        ans += x.second * (x.second - 1) / 2;
    }

    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <map>
using namespace std;

map<string,int> table;

int main(){
	string word, frequent, longest;
	int frequent_length = 0;
	while (cin >> word){
		table[word] += 1;
		if (table[word] > frequent_length){
			frequent_length = table[word];
			frequent = word;
		}
		longest = (word.size() > longest.size()) ? word : longest;
	}	
	cout << frequent << ' ' << longest << endl;
	return 0;
}

Measured memory_bytes: 3024
n = int(input())
A = list(map(int, input().split()))
four = 0
odd = 0
even = 0
for a in A:
	if a % 4 == 0:
		four += 1
	elif a % 2:
		odd += 1
	else:
		even += 1
if 2 * four + 1 >= n or even == n or four >= odd:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 63472
#include <bits/stdc++.h>
using namespace std;
const int N = 270000;
const int W = 100000;
int n, S, val[N], wei[N], f[520][W + 5];
int Q;
int ans, L;
void go(int u, int sw, int sv) {
	if (u <= S) {
		ans = max(ans, f[u][L - sw] + sv);
		return;
	}
	go(u / 2, sw, sv);
	if (sw + wei[u] <= L) go(u / 2, sw + wei[u], sv + val[u]);
}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d%d", &val[i], &wei[i]);
	S = min(n, 511);
	for (int j = 0; j < wei[1]; j++) f[1][j] = 0;
	for (int j = wei[1]; j <= W; j++) f[1][j] = val[1];
	for (int i = 2; i <= S; i++) {
		for (int j = W; j >= wei[i]; j--)
			f[i][j] = max(f[i / 2][j], f[i / 2][j - wei[i]] + val[i]);
		for (int j = 0; j < wei[i]; j++)
			f[i][j] = f[i / 2][j];
	}
	scanf("%d", &Q);
	while (Q--) {
		int u;
		scanf("%d%d", &u, &L);
		if (u <= S) {
			printf("%d\n", f[u][L]);
		} else {
			ans = 0;
			go(u, 0, 0);
			printf("%d\n", ans);
		}
	}
	return 0;
}

Measured memory_bytes: 205496
function main() {
  function search(w, n, xs, sum) {
    return n === ws.length ?
      (sum === w ? xs : null) :
      search(w, n+1, xs.concat(ws[n]), sum+ws[n]) || search(w, n+1, xs, sum);
  }
  var
  ws = [1,2,4,8,16,32,64,128,256,512];
  input.forEach(function(line) {
    if(line.trim() === '') return;
    console.log(search(parseInt(line, 10), 0, [], 0).join(' '));
  });
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 10956
#include<bits/stdc++.h>
using namespace std;
long long int n,x[2000000],z[2000000],y[2000000];
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x[i];
        y[i]=x[i];
    }
    sort(x,x+n);
    for(int i=0;i<n;i++){
        if(y[i]>x[n/2-1])cout<<x[n/2-1]<<endl;
        else cout<<x[n/2]<<endl;



    }

}


Measured memory_bytes: 7808
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };
int gcd(ll x, ll y)
{
	int r;

	if (x == 0 || y == 0)  // 引数チェック
	{
		fprintf(stderr, "引数エラーです。\n");
		return 0;
	}

	// ユーグリッドの互除法
	while ((r = x % y) != 0)  // yで割り切れるまでループ
	{
		x = y;
		y = r;
	}
	return y;
}

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

	ll n,a,b,ans=0,ret=M,m;
	string s;
	cin >> n;
	vi v(n);
	rep(i, n) cin >> v[i];
	ans = v[0];
	REP(i, 1, n) {
		ans = gcd(ans, v[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
a, b, k = map(int, input().split())
a, b = sorted([a, b])
lst = []

if b != 1:
    for i in range(1, a+1):
        if a%i==b%i==0:
            lst.append(i)

else:
    lst.append(1)

lst.reverse()
print(lst[k-1])

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	string s, ans;
	cin >> s;
	int n = s.length(), i, j, k;

	if (n < 26) {
		set<char> ss;
		char ch;
		for (auto ch : s) ss.insert(ch);
		for (ch = 'a'; ch <= 'z'; ch++) {
			if (ss.find(ch) == ss.end()) {
				ans = s + ch;
				break;
			}
		}
	}
	else {
		ans = s;
		if (!next_permutation(ans.begin(), ans.end())) ans = "-1";
		else {
			set<char> ss;
			for (i = n - 1; i >= 0; i--) {
				for (auto ch : ss) {
					if (ch > s[i]) {
						ans = s.substr(0, i) + ch;
						goto outer;
					}
				}
				ss.insert(s[i]);
			}
		outer:;
		}
	}

	cout << ans << "\n";


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {FIN
	
	int a, b, i, pa, pb;
	bool is = false;
	cin >> a >> b;
	i = 1;
	while (true) {
		pa = (int)floor(i * 0.08);
		pb = (int)floor(i * 0.1);
		if (pa == a and pb == b) {
			is = true;
			break;
		}
		if (pa > a and pb > b)
			break;
		i++;
	}
	if (is)
		cout << i << "\n";
	else
		cout << -1 << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
	int n,s,e,r[15]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
	cin >> n;
	for (;n>0;n--) {
     cin >> s >> e;
	 if (s>e && s<6) s=15-s;
	 while(true) { 
		 cout << r[s];
		 if (r[s]==e) {cout << endl; break;}
		 cout << ' ';
		 s=(s+1) % 15;
	 }
	}
	return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int cnt = int.Parse(Console.ReadLine());

            int count = (int)cnt / 2 + cnt % 2;
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n-1);
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n){
        cin>>b[i];
    }
    rep(i,n-1){
        cin>>c[i];
    }
    int pre=-1;
    int ans=0;
    rep(i,n){
        int k=a[i];
        ans+=b[k-1];
        if(k<=n&&pre+1==k&&pre!=-1){
            ans+=c[pre-1];
        }

        pre=k;
    }
    cout<<ans<<endl;



    return 0;
}


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

int main(){
  int a, b, c, d;
  cin>>a>>b>>c>>d;
  string ans;
  if(a+b>c+d){
    ans="Left";
  }
  else if(a+b<c+d){
    ans="Right";
  }
  else{
    ans="Balanced";
  }
  cout<<ans<<endl;
}

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

ans = []

for i in range(len(s)-1):
    dic = {}
    for j in range(i+1):
        if s[j] in s[i+1:] and s[j] not in dic:
            dic[s[j]] = 1
    ans.append(len(dic))

print(max(ans))

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

int n, m;
int a[100010];
typedef pair<int, int> P;
typedef pair<P, int> PP;
vector<PP> v;
P ans[100010];

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(int i=0; i<m; ++i){
		int p, y;
		cin >> p >> y;
		v.push_back(PP(P(y, p), i+1));
	}
	sort(v.begin(), v.end());
	for(int i=0; i<m; ++i)
		ans[v[i].second] = P(v[i].first.second, ++a[v[i].first.second]);
	for(int i=1; i<=m; ++i){
		cout << setfill('0') << setw(6) << right << ans[i].first;
		cout << setfill('0') << setw(6) << right << ans[i].second;
		cout << "\n";
	}
}

Measured memory_bytes: 3956
#include<cstdio>

using namespace std;

int main(){
    int a, b;

    scanf("%d %d", &a, &b);

    if ((a + b) % 2 == 0) printf("%d\n", (a + b) / 2);
    else printf("%d\n", (a + b + 1) / 2);
}

Measured memory_bytes: 504
// This code was written by WuTan
#include <bits/stdc++.h>
#define io_faster ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define EL cout<<'\n'
#define pli pair<ll,int>
#define pii pair<int,int>
#define fi first
#define se second
#define PROB "StonesAT"

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

void file(){
#ifndef ONLINE_JUDGE
	freopen(PROB".inp","r",stdin);
	freopen(PROB".out","w",stdout);
#endif
}

// Talk less
// Love more

const int N = 105, K = 1e5 + 5;
int n, a[N], k, f[K];
void readinp(){
    cin >> n >> k;
    for (int i=1;i<=n;i++)
        cin >> a[i];
}


/// 1 : win
/// 0 : lose

int ff(int x){
    if (x < 0) return 1;
    return f[x];
}

void solve(){
    for (int i=1;i<=n;i++)
        f[a[i]] = 1;
    for (int i=1;i<=k;i++){
        int ok = 0;
        for (int j=1;j<=n;j++){
            if (!ff(i - a[j])){
                ok = 1; break;
            }
        }
        f[i] = ok;
    }
    if (f[k]) cout << "First";
    else cout << "Second";
}

int main(){
    io_faster
    file();
    int t = 1;
//    cin >> t;
    while (t--){
        readinp();
        solve();
    }
}


Measured memory_bytes: 4012
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	long long a[n];
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	reverse(a, a + n);
	long long l = 0, s = 0;
	for (int i = 0; i < n - 1; i++)
	{
		if(a[i] == a[i+1]) {
			if(l == 0) l = a[i];
			else if(s == 0) s = a[i];
			i++;
		}
	}

	cout << l * s << endl;
	return 0;
}


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

using namespace std;

#define SZ(x) ((int) (x).size())
const int N = 105;

int n, m, k;
int a[N][N];

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

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    scanf("%d%d%d", &n, &m, &k);

    memset(a, 1, sizeof a);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            a[i][j] = 0;
        }
    }

    int x = 1, y = 1, d = 0;
    for (int i = 1; i <= k; i++) {
        int c;
        scanf("%d", &c);
        while (c > 0) {
            a[x][y] = i;
            c--;
            // printf("x=%d y=%d\n", x, y);

            if (i == k && c == 0)
                break;
            while (1) {
                int nx = x + dx[d];
                int ny = y + dy[d];
                if (a[nx][ny] != 0) {
                    d = (d + 1) % 4;
                    continue;
                }

                x = nx, y = ny;
                break;
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            printf("%d ", a[i][j]);
        }
        puts("");
    }
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int s = scan.nextInt();
	int h =s/3600;
	int m =(s-h*3600)/60;
	s = s - h*3600 -m*60;
	System.out.println(h+":"+m+":"+s);

	}

}

Measured memory_bytes: 26220
//Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb push_back
#define koto_memory(a) cout<<(sizeof(a)/1048576.0)<<" MB";
#define res(v) v.resize(unique(v.begin(), v.end()) - v.begin());
#define cnt_res(v) std::distance(v.begin(),std::unique(v.begin(), v.end())); 
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=2e6+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
int val[N][2];
ll powM(ll b, int p,int M) {
  ll r=1;
  for(; p; b=b*b%M, p/=2)
    if(p&1)
      r=r*b%M;
  return r;
}
int f(int n){
	int cnt=0;
	while(n){
		cnt++,n%=__builtin_popcount(n);
	}
	return cnt;
}
void solve(){
	int n;cin>>n;
	bitset<N>a;cin>>a;
	int set=a.count();
	int n1=set+1,n2=set-1;
	int ans1=0,ans2=0;
	val[0][0]=val[0][1]=1;
	rep(i,0,n-1){
		val[i+1][0]=2*val[i][0]%n1;
		if(n2!=0)val[i+1][1]=2*val[i][1]%n2;
		if(a[i]==1)ans1+=val[i][0],ans2+=val[i][1];
	}
	per(i,n-1,0){
		if(a[i]==1){
			if(n2==0){cout<<0<<" ";continue;}
			int cnt=ans2-val[i][1]+n2;
			cnt%=n2;
			cout<<1+f(cnt);
		}
		else{
			int cnt=ans1+val[i][0];
			cnt%=n1;
			cout<<1+f(cnt);
		}
		cout<<"\n";
	}
}
int32_t main()
{
  ibs;cti;
  solve()
  /*,cout<<"\n"*/;
  // cout<<"\n";
  int xx=0;
  // int t;cin>>t;while(t--){/*xx++;cout<<"Case "<<xx<<":\n"*/;solve();cout<<"\n";}
  return 0;
}

Measured memory_bytes: 7008
# -*- coding: utf-8 -*-


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

    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    # See:
    # https://www.youtube.com/watch?v=ENSOy8u9K9I&feature=youtu.be
    # KeyInsight:
    # 移動: 周期的ではない + 周期的に繰り返すの合計
    # 実装上のポイント
    # 経路と順番を別々に管理する
    path = list()
    order = [-1 for _ in range(n + 1)]  # -1: 到達していない
    place = 1

    # 到達していない点がある限り、ループを繰り返す
    # = 同じ点を2回通るまで繰り返す
    while order[place] == -1:
        order[place] = len(path)  # ある場所を通った順番を管理
        path.append(place)  # 経路を更新
        place = a[place - 1]  # 次の行き先

    # 周期: 同じ点を2回通るまでに要した移動回数 - 周期に入るまでの移動回数
    cycle = len(path) - order[place]
    before_cycle_count = order[place]

    if (k < before_cycle_count):
        print(path[k])
    else:
        k -= before_cycle_count
        k %= cycle  # 周期: 途中の繰り返し部分を省いて、途中の部分だけ計算するようにする
        print(path[before_cycle_count + k])


if __name__ == '__main__':
    main()


Measured memory_bytes: 31412
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,ans=1e9;
  cin>>n;
  int a[n],b[n];
  r(i,n)cin>>a[i];
  r(i,n)b[i]=a[i];
  r(j,4){
    int s1=0;
    r(i,n)a[i]=b[i];
    a[0]-=j;
    for(int i=0;i<n-1;i++){
      if(a[i]<=0)continue;
      s1+=a[i]*2;
      a[i+1]-=a[i];
    }
    if(a[n-1]<0)a[n-1]=0;
    ans=min(ans,s1+a[n-1]+j);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3136
class Main {

	public static void main(String[] a) {
		StringBuilder sb = new StringBuilder();

		for(int i = 1; i <= 9; i++) {
			for(int j = 1; j <= 9; j++) {
				sb.append(i + "x" + j + "=" + i*j + "\n");
			}
		}
		System.out.print(sb);
	}
}

Measured memory_bytes: 23812
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

const double  PI = 3.14159265;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    double R;cin >> R;
    cout << 2 * R * PI << endl;

}


Measured memory_bytes: 3820
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());
        var A = new List<int>();
        for(int i = 0; i < N; i++)
        {
            A.Add(int.Parse(Console.ReadLine()));
        }

        // 降順ソートする
        var maxList = new List<int>(A);
        maxList.Sort((a, b) => (b - a));

        var maxIndex = A.IndexOf(maxList[0]);

        for(int i = 0; i < N; i++)
        {
            if (i == maxIndex) Console.WriteLine(maxList[1]);
            else Console.WriteLine(maxList[0]);
        }
    }
}



Measured memory_bytes: 45748
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

#define int long long
#define double long double

typedef pair<int, int> P;
typedef tuple<int, int, int> T;

template<class T> string tostr(T x) { stringstream o; o << x; return o.str(); }
template<class T> T sqr(T x) { return x*x; }
template<class T> T mypow(T x, int n) { T r = 1; while (n > 0) { if (n & 1)r = r*x; x = x*x; n >>= 1; }return r; }

int toint(string s) { int v; stringstream i(s); i >> v; return v; }
bool check(int x, int y, int w, int h) { return x >= 0 && y >= 0 && w > x && h > y; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define REP(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	REP(i,0,n)
#define PER(i,a,b)	for(int (i) = (a-1);i >= (b);(i)--)
#define per(i,n)	PER(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define dump(val) 	cerr << #val " = " << val << endl;
#define dum(val)	cerr << #val " = " << val;
#define FILL(a,v)	fill(a,a+sizeof(a)/sizeof(*a),v)

const int dx[8] = { +1,+0,-1,+0,+1,+1,-1,-1 };
const int dy[8] = { +0,-1,+0,+1,-1,+1,-1,+1 };
const int mod = 1e9 + 7;
const int INF = 1e17 + 9;

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

	int n, c, k;
	cin >> n >> c >> k;

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

	int st = -1, cn = 0, ans = 0;

	each(i, t) {
		if (st < i || cn >= c) {
			st = i + k;
			cn = 1;
			ans++;
		}
		else {
			cn++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int d1=0, d2=0;
	int ans=0;

	for(int i=0; i<N; i++){
	    d1 = sc.nextInt();
	    d2 = sc.nextInt();
	    if(d1==d2 || ans>=3){
		if(ans>=3)continue;
		ans++;
	    }else ans=0;
	}
	if(ans>=3)System.out.println("Yes");
	else System.out.println("No");
    }
}

Measured memory_bytes: 36040
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		double tot = 0.0;
		for(int i=1;i<=N;i++){
			double p = 1.0 / (double) N;
			long v = i;
			while(v < K){
				p *= 0.5;
				v *= 2L;
			}
			tot += p;
		}
		Console.WriteLine(tot);
	}
	int N;
	long K; 
	public Sol(){
		var d = ria();
		N = d[0]; K = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

int main()
{
	int n,ans = 0;
	cin >> n;

	rep(i, n) {
		int l, r;
		cin >> l >> r;
		ans += r - l + 1;
	}
	cout << ans << endl;
	return	0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
 
#define int ll
 
typedef int64_t ll;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,0,1,-1}, dy4[4] = {1,-1,0,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) signed((a).size())
#define LEN(a) signed((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end());reverse((c).begin(),(c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define YESNO(x) puts((x)?"YES":"NO")
#define YesNo(x) puts((x)?"Yes":"No")
 
signed main(){
    int N;
    cin >> N;
    int t=1,a=1;
    REP(i,N){
        int tmp1,tmp2;
        cin >> tmp1 >> tmp2;
        int n = max((t+tmp1-1)/tmp1,(a+tmp2-1)/tmp2);
        t = n*tmp1,a = n*tmp2;
    }
    printf("%lld\n",t+a);
}


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

int q=0;

struct tranp{
  char gara;
  int atai;
};

int partition(struct tranp CC[],int N,int p,int r){
  int i=0,j=0;
  struct tranp x;
  struct tranp tmp;
  x=CC[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(CC[j].atai<=x.atai){
      i=i+1;
      tmp=CC[i];
      CC[i]=CC[j];
      CC[j]=tmp;
    }
  }
  tmp=CC[i+1];
  CC[i+1]=CC[r];
  CC[r]=tmp;
  return i+1;
}

void quicksort(struct tranp CC[], int N, int p, int r){
  int q;
  if(p<r){
    q=partition(CC,N,p,r);
    quicksort(CC,N,p,q-1);
    quicksort(CC,N,q+1,r);
  }
}
void marge(struct tranp C[],int N, int left, int mid, int right){
  int i,j,k;
  int n1=0,n2=0;
  struct tranp L[500010];
  struct tranp R[500010];
  n1=mid-left;
  n2=right-mid;
  for(i=0;i<n1;i++){
    L[i]=C[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=C[mid+i];
  }
  L[n1].atai=2000000000;
  R[n2].atai=2000000000;
  j=0;
  i=0;
  for(k=left;k<right;k++){
    if(L[i].atai<=R[j].atai){
      C[k]=L[i++];
      
    }
    else {
      C[k]=R[j++];
    }
  }
}

void margesort(struct tranp C[],int N, int left, int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    margesort(C,N,left,mid);
    margesort(C,N,mid,right);
    marge(C,N,left,mid,right);
  }
}

int main(){
  struct tranp C[100000];
  struct tranp CC[100000];
  int n=0,i=0;
  int N=0;
  int left=0,right=0;
  char gara1[10];
  int atai1;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%s %d",gara1,&atai1);
    C[i].gara=CC[i].gara=gara1[0];
    C[i].atai=CC[i].atai=atai1;
  }
  margesort(C,N,0,N);
  quicksort(CC,N,0,N-1);
  for(i=0;i<N;i++){
    if(C[i].gara!=CC[i].gara){
      printf("Not stable\n");
      break;
    }
  }
  if(i==N)printf("Stable\n");
  for(i=0;i<N;i++){
    cout<<CC[i].gara<<" "<<CC[i].atai<<endl;
    
  }
  return 0;
}



Measured memory_bytes: 5500
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

vec dp;
mat c;
void func(int start,int i,set<int> S,int sum){
    if(i==1)return;
    for(auto itr=S.begin();itr!=S.end();itr++){
        int s=sum;
        set<int> T=S;
        s+=c[i][*itr];
        T.erase(*itr);
        if(*itr==1)dp[start]=min(dp[start],s);
        func(start,*itr,T,s);
    }
    return;
}

int main(){
    int H,W;cin>>H>>W;
    c.resize(10,vec(10));
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++)
            cin>>c[i][j];
    }
    dp.resize(10,pow(10,9));
    set<int> X;
    for(int i=0;i<10;i++)
        X.insert(i);
    set<int> Y[10];
    Y[0]=X;Y[0].erase(0);func(0,0,Y[0],0);
    dp[1]=0;
    for(int i=2;i<10;i++){
        Y[i]=X;Y[i].erase(i);
        func(i,i,Y[i],0);
    }
    int ans=0;
    int A[210][210];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>A[i][j];
            if(A[i][j]!=-1)ans+=dp[A[i][j]];
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int min( int a, int b )
{
    if( a < b )
        return a;
    else
        return b;
}

int main()
{
    int n, m, i, j;

    cin >> n >> m;

    for( int k = 0; k < m; k++ )
    {
        cin >> i >> j;
        cout << min( min( i - 1, n - i ), min( j - 1, n - j ) ) % 3 + 1 << endl;
    }
    
    return 0;
}


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

int main(){

    int n; cin >> n;

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

    int count = 0;
    for(int i=2; i<n; i++){
        if(p[i-1] < p[i] && p[i] < p[i+1]){
            count++;
        }
        else if(p[i+1] < p[i] && p[i] < p[i-1]){
            count++;
        }
    }

    cout << count << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
const ll mod = 1000000007;
int main(void){
    ll n;cin>>n;
    vector<ll> a(n+100,1);
    a[0]=a[1]=a[2]=0;
    rep(i,n+1){
        if(i<=2)continue;
        ll buf=0;
        rep(j,i-2){
            buf+=a[j];
            buf%=mod;
        }
        a[i]+=buf;
        a[i]%=mod;
        //cout<<i<<" "<<a[i]<<endl;
    }
    cout<<a[n]<<endl;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vst = vector<st>;
using vch = vector<char>;
using vbl = vector<bl>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;} return false;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

int main(){
	db a, b, m, h;
	cin >> a >> b >> h >> m;
	db theta = abs(m / 60 - (m + 60 * h) / (60 * 12)) * 2 * pi;
	if(theta >  pi) theta = 2 * pi - theta;
	cout << fixed << setprecision(10);
	cout << sqrt(a * a + b * b - 2 * a * b * cos(theta)) << endl;
}

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

namespace AtCoder.Abc
{
    //https://atcoder.jp/contests/abc086/tasks/abc086_a
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            string result = "";

            if (inputLongArray[0] % 2 == 0 || inputLongArray[1] % 2 == 0)
            {
                result = "Even";
            }
            else
            {
                result = "Odd";
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 13396
import sys

n=int(input())
h=list(map(int,input().split()))
count=0
be=h[0]
maxcount=h.count(max(h))
becount=0

for i in range(n):
  if be<=h[i] and h[0]<=h[i]:
    if becount<=h[i]:
      if h[i]==max(h):
        maxcount-=1
        count+=1
        becount=h[i]
        if maxcount==0:
          print(count)
          sys.exit()
      else:
        count+=1
        becount=h[i]
    else:
      pass
  be=h[i]
  
print(count)

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

const int mod=1000000007;
ll dp[101][100005];
int a[101];
int main(){
    int n,k;
    cin>>n>>k;
    rep(i,n) cin>>a[i];
    dp[0][0]=1;
    rep(i,n){
        ll sum=0;
        rep(j,k+1){
            sum+=dp[i][j];
            if(j-a[i]-1>=0) sum-=dp[i][j-a[i]-1];
            dp[i+1][j]=sum;
            dp[i+1][j]=(dp[i+1][j]+mod)%mod;
        }
    }
    cout<<dp[n][k]<<endl;
    return 0;
}


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

int main()
{
 int N;
  cin>>N;
 int count=0;
  for(int i=1;i<N+1;i++)
  {
    int now=i;
    while(now>99)
    {
     now=now/100;
    }
    if(now<10)count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
z = int(input())
ar = list(map(int,input().split(" ")))
y = int(input())
count = 0
for i in range(y):
    l = list(map(int,input().split(" ")))
    for j,a in enumerate(ar):
        if j != l[0] -1:
            count += a
    count += l[1]
    print(count)
    count = 0

Measured memory_bytes: 3060
n = int(input())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(n-1, -1, -1):
    if (A[i]+ans) % B[i] == 0:
        continue
    else:
        ans += B[i] - (A[i]+ans) % B[i]
print(ans)

Measured memory_bytes: 11052
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000003;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[3000010];
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=3000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){return modpow(x,mod-2);}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int q;
    cin>>q;
    init_fact();
    while(q--){
        int x,d,n;
        cin>>x>>d>>n;
        if(d==0){
            cout<<modpow(x,n)<<endl;
            continue;
        }
        x=x*inv(d)%mod;
        if(x%mod==0||(x/mod!=(x+n-1)/mod)){
            cout<<0<<endl;
        }
        else{
            cout<<kaijo[x+n-1]*inv(kaijo[x-1])%mod*modpow(d,n)%mod<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 24320
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll N = 1e9+7;
const int n_max = 1e5+10;

int main(){
    int n; cin >> n;
    vector<ld> a(n);
    ld sum = 0;
    rep(i,n){
        cin >> a[i];
        sum += ld(1.0)/a[i];
        // cout << sum << endl;
    }
    ld ans;
    ans = ld(1.0) / sum;
    // cout << fixed << setprecision(13) << ans << endl;
    cout << ans << endl;
    // cout << typeid(ans).name() << endl;
    // cout << typeid(200.0/3.0).name() << endl;
    // cout << typeid(double(200)/double(3)).name() << endl;
    // cout << typeid(float(200)/float(3)).name() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;

int dsum(int n){
	if(n<10) return n;
	return dsum(n/10)+n%10;
}

int main(){
	int ans=0;
	rep(i,4){
		char s;
		cin>>s;
		if(s=='+')ans++;
		else ans--;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <algorithm>
#define MAX 50000
#define INF 100000000
using namespace std;
typedef long long ll;
int t[MAX+1],c[21];
struct bags{
	int value;
	int weight;
};
vector<bags> B;
int dp[102][10002];
int main()
{	
	int n,m; 
	struct bags tian;
	cin>>n>>m;
	B.push_back(tian);
	for(int i=1;i<=n;i++)
	{
		struct bags tmp;
		cin>>tmp.value>>tmp.weight;
		B.push_back(tmp);
	}
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=0;
		dp[0][i]=0;
	}
	dp[0][0]=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		{
			if(j<B[i].weight)
				dp[i][j]=dp[i-1][j];
			else{
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-B[i].weight]+B[i].value);
			}
		}
	cout<<dp[n][m]<<endl;
}


Measured memory_bytes: 7072
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    lint N, Y;
    cin >> N >> Y;
    lint k;
    range(i, 0, N + 1) {
        range(j, 0, N - i + 1) {
            k = N - i - j;
            lint amount = 10000 * i + 5000 * j + 1000 * k;
            if (amount == Y) {
                cout << i << " " << j << " " << k << "\n";
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << "\n";
    return 0;
}

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

int main(){
	int64_t h;
  	int64_t w;
  	cin>>h;
    cin>>w;
  	int64_t sum;
  if (h==1){
    sum=1;
  }
  else if (w==1){
    sum=1;
  }
  else{
  
  	if ((h*w)%2==0){
      	sum=(h*w)/2;
    
    }
   	else{
      	sum=(h*w+1)/2;
    }
  }
  	cout<<sum<<endl;
}

Measured memory_bytes: 256
def main():
    N, L = map(int, input().split())

    total = 0
    min_taste = 10 ** 12

    for i in range(1, N + 1):
        taste = L + i - 1
        if abs(taste) < min_taste:
            min_taste = abs(taste)
            min_taste_index = i

    for i in range(1, N + 1):
        if i == min_taste_index:
            continue
        total += L + i - 1

    print(total)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61940
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int N = 2e5 + 4 , mod = 998244353;
struct point
{
	int x , y;
};
point p[N];
int xx[N] , yy[N] , n;

inline int read(void)
{
	int x = 0 ; char c = getchar() ;bool f = 0; 
	while(c > '9' || c < '0') f |= (c=='-') ,c = getchar();
	while(c <= '9' && c >= '0') x = x * 10 + c - '0' , c = getchar();
	return f? -x : x;
}

int *tree , *pow2;
void add(int x)
{
	for( ; x <= n ; x += x & -x)
		tree[x] ++;
}
int ask(int x)
{
	int res = 0;
	for( ; x ; x ^= x & -x)
		res += tree[x];
	return res;
}

bool cmp(const point &a , const point &b)
{
	return a.x < b.x;
}

int main()
{
	n = read() ;
	for(int i = 1 ; i <= n ; i ++)
		xx[i] = p[i].x = read() , yy[i] = p[i].y = read();
	sort(xx + 1 , xx + 1 + n) , sort(yy + 1 , yy + 1 + n);
	for(int i = 1 ; i <= n ; i ++)
	{
		p[i].x = lower_bound(xx + 1 , xx + 1 + n , p[i].x) - xx;
		p[i].y = lower_bound(yy + 1 , yy + 1 + n , p[i].y) - yy;
	}
	
	pow2 = xx , tree = yy ;
	pow2[0] = 1;
	for(int i = 1 ; i <= n ; i ++)
		pow2[i] = 2 * pow2[i - 1] % mod;
	memset(tree + 1 , 0 , n * sizeof(int));
	
	sort(p + 1 , p + 1 + n , cmp);
	long long ans = 0;
	for(int i = 1 ; i <= n ; i ++)
	{
		ans += pow2[n] - 1;
		ans -= pow2[ p[i].x - 1 ];
		ans -= pow2[ n - p[i].x ];
		ans -= pow2[ p[i].y - 1 ];
		ans -= pow2[ n - p[i].y ];
		int left_down = ask(p[i].y);
		int left_up = p[i].x - 1 - left_down;
		int right_down = p[i].y - 1 - left_down;
		int right_up = n - 1 - right_down - left_up - left_down;
		ans += pow2[left_down];
		ans += pow2[left_up];
		ans += pow2[right_down];
		ans += pow2[right_up];
		
		ans = ( ans % mod + mod ) % mod;
		add(p[i].y); 
	}
	printf("%lld\n" , ans);
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> ii;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k;
    cin >> k;
    int n = 1 << k, t;
    multiset<int> todo;
    for (int ctr1 = 0; ctr1 < n; ++ctr1)
        cin >> t, todo.insert(-t);
    
    vector<int> done;
    for (int ctr1 = 0; ctr1 <= k; ++ctr1) {
        if (ctr1 == 0) {
            auto it = todo.begin();
            done.push_back(*it);
            todo.erase(it);
        } else {
            int l = 1 << (ctr1 - 1);
            for (int ctr2 = 0; ctr2 < l; ++ctr2) {
                auto it = todo.upper_bound(done[ctr2]);
                if (it == todo.end()) {
                    cout << "No";
                    return 0;
                }
                done.push_back(*it);
                todo.erase(it);
            }
        }
    }

    cout << "Yes";
    return 0;
}

Measured memory_bytes: 13688