akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()

const int INF = 1001001001;

int main(){
	int m; ll k; cin >> m >> k;
	
	if((1<<m) <= k){
		cout << -1 << endl;
		return 0;
	}
	if(m == 1){
		if(k >= 1) cout << -1;
		else{
			rep(i, pow(2,m)){
				cout << i  << " " << i << " ";
			}
		}
			
		return 0;
	}
	int i = 0;
	while(i<=pow(2,m)-1){
		if(i == k){
			i++;
			continue;
		} 
		cout << (i)<< " ";
		i ++;
	}
	cout << (k) << " ";
	i --;
	while(i>=0){
		if(i == k){
			i--;
			continue;
		} 
		cout << (i)<< " ";
		i--;
	}
	cout << (k);
}

Measured memory_bytes: 1792
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
from sys import stdin
from itertools import combinations

for line in stdin:
    if line.startswith('0 0'):
        break
    num, ans = (int(s) for s in line.split())
    print(sum(sum(t) == ans for t in combinations(xrange(10), num)))

Measured memory_bytes: 4380
#include<bits/stdc++.h>
using namespace std;
const int N=5005,mod=1e9+7;
typedef long long ll;
int n,m,dp[N][N];
int main()
{
    //int p[N];p[0]=1;for(int i=1;i<N;i++) p[i]=(p[i-1]<<1)%mod;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++) dp[0][i]=1;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
    {
        dp[i][j]=(dp[i][j]+(ll)dp[i-1][j]*(j+1))%mod;
        dp[i][j]=(dp[i][j]+(ll)(dp[i][j-1]-(ll)dp[i-1][j-1]*j%mod+mod)%mod*2%mod+(ll)dp[i-1][j-1]*(j-1))%mod;
        /*
        for(int k=2;k<=j;k++)
            dp[i][j]=(dp[i][j]+(ll)dp[i-1][j-k+1]*(j-k+1)%mod*p[k-2]%mod)%mod;
        */
    }
    printf("%d\n",dp[n][m]);
}


Measured memory_bytes: 101520
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
#define INF 1000000000
typedef long long int ll;
typedef pair<ll, ll> P;
template <typename T>
std::string tostr(const T &t)
{
    std::ostringstream os;
    os << t;
    return os.str();
}
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main()
{
    ll n;
    cin >> n;
    vector<P> v(n);
    vector<P> pa(n);
    for (int i = 0; i < n; i++)
    {
        ll t1, t2;
        cin >> t1 >> t2;
        v[i] = {t1 + t2, i};
        pa[i] = {t1, t2};
    }
    sort(v.begin(), v.end());
    ll a = 0, b = 0, flag = 0;
    for (int i = n - 1; i >= 0; i--)
    {
        if (flag == 0)
        {
            flag = 1 - flag;
            a += pa[v[i].second].first;
        }
        else
        {
            flag = 1 - flag;
            b += pa[v[i].second].second;
        }
    }
    cout << a - b << endl;
    return 0;
}

Measured memory_bytes: 3328
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説どおりに作成したソースコード
 * 
 * https://atcoder.jp/contests/abc158/submissions/10645244 にも参考
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), p = scanner.nextInt();
			char[] s = scanner.next().toCharArray();
			// 文字列を数字に変換
			int[] s2 = new int[n];
			IntStream.range(0, n).forEach(i -> s2[i] = s[i] - '0');
			if ((2 == p) || (5 == p)) {
				System.out.println(IntStream.range(0, n).mapToLong(i -> (0 == s2[i] % p) ? i + 1 : 0L).sum());
			} else {
				long answer = 0L;
				int now = 0;
				int digit = 1;
				int[] m = new int[p];
				m[0] = 1;
				for (int i = n - 1; i >= 0; i--) {
					now += s2[i] * digit;
					now %= p;
					answer += m[now];
					m[now]++;
					digit *= 10;
					digit %= p;
				}
				System.out.println(answer);
			}
		}
	}
}


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int n, k;
    cin >> n >> k;
    if(n / 2 + n % 2 >= k){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define ld long double
#define pb push_back
#define pf push_front
#define ft first
#define sc second
#define all(v) v.begin(), v.end()
using namespace std;
const int maxn = 201001;
signed main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, m;
    cin >> n >> m;
    cout << (n * (n - 1)) / 2 + (m * (m - 1)) / 2;
}


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

using namespace std;
int main(){

  int n;
  cin >> n;
  vector<int> A(n);
  vector<int> C(n);




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

    C[0] = 0;
    C[1] = abs(A[1] - A[0]);

  for (int i = 2; i < n; i++){
          C[i] = min(C[i-1] + abs(A[i - 1] - A[i]), C[i - 2] + abs(A[i - 2] - A[i]));
      }


    cout << C[n - 1] << endl;
    return 0;


}

Measured memory_bytes: 1024
//
// Created by munaiyi on 2020/3/17.
//

#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e6 + 5;
char shit[maxn];
int dp[2][maxn];

int main() {
    scanf("%s", shit);
    int l = strlen(shit);
    while (l && shit[l - 1] == '0') l--;
    int sum = 0;
    for (int i = 0; i < l; i++) {
        sum += shit[i] - '0';
    }
    dp[0][l] = 0;
    dp[1][l] = maxn;
    for (int i = l - 1; i >= 0; i--) {
        dp[0][i] = min(dp[0][i + 1], dp[1][i + 1]) + shit[i] - '0';
        dp[1][i] = min(dp[0][i + 1] + 1  + 10 - shit[i] + '0', dp[1][i + 1] + 9 - shit[i] + '0');
//        dp[1][i] = min(dp[1][i], dp[1][i + 1] + shit[i] - '0');
//        printf("%d %d %d\n", i, dp[0][i], dp[1][i]);
    }
    printf("%d\n", min(dp[0][0], dp[1][0]));
    return 0;
}

Measured memory_bytes: 9088
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] mount = new int[n];
        for (int i = 0; i < n; i++) {
            mount[i] = Integer.parseInt(sc.next());
        }
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            boolean taller = true;
            for (int j = 0; j < i; j++) {
                if (mount[j] > mount[i]) {
                    taller = false;
                    break;
                }
            }
            if (taller) {
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
  
#define mp make_pair
#define f first
#define s second
#define ll long long
#define pb push_back
 
using namespace std;
/*
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  */
const int inf = 2e9+7, mod=1e9+7;
const int N = 1e3;
 
ll xx[8]={1, 1, -1, -1, 1, -1, 0, 0};
ll yy[8]={1, -1, 1, -1, 0, 0, 1, -1};

int main(){
	ios_base :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a, b, c;
	cin >> a >> b >> c;
	cout << c << " " << a << " " << b;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define sb __builtin_popcount
#define MOD (ll)1000000007
#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>
using namespace std;

int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     ll k;
     cin >> k;
     ll sum = 0;
     for (ll i = 1; i <= k; i++)
     {
          for (ll j = 1; j <= k; j++)
          {
               for (ll l = 1; l <= k; l++)
               {
                    sum += __gcd(__gcd(i, j), l);
               }
          }
     }
     cout << sum << endl;
}


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

int a,b,c;
int np;
int ans=0;

int dfs(int x,int d){
	d++;
	if(d==b){
		if(np==c)ans++;
		return 0;
	}
	if(d<b){
		for(int i=x+1;i<=a;i++){
			np+=i;
			dfs(i,d);
			np-=i;
		}
	}
	return 0;
}

int main(){
	while(cin>>a>>b>>c){
		ans=0;
		if(a==0&&b==0&&c==0)break;
		for(int i=1;i<=a;i++){
			np=i;
			dfs(i,0);
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
int main(){
    int d,g;
    cin>>d>>g;
    vector<int> p(10);
    vector<int> c(10);
    for(int i=0;i<d;i++)cin>>p[i]>>c[i];
    int ans=1e9;
    for(int mask=0;mask<(1<<d);mask++){
        int sum=0,max_d=-1,n=0;
        for(int i=0;i<d;i++){
            if(mask&(1<<i)){
                sum+=100*(i+1)*p[i]+c[i];
                n+=p[i];
            }
            else max_d=i;
        }
        if(sum<g){
            int s=100*(max_d+1);
            int need=(g-sum+s-1)/s;
            if(need>p[max_d])continue;
            n+=need;
        }
        ans=min(ans,n);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
using namespace std;
const long long INF = 1LL << 58;

int main()
{
	int a, b, q;
	long long ans = INF;
	cin >> a >> b >> q;
	vector<long long> s(a), t(b), x(q);

	for (int i = 0;i < a;i++)
	{
		cin >> s[i];
	}

	for (int i = 0;i < b;i++)
	{
		cin >> t[i];
	}

	for (int i = 0;i < q;i++)
	{
		cin >> x[i];
	}

	s.push_back(INF);
	s.push_back(-INF);
	t.push_back(INF);
	t.push_back(-INF);
	sort(s.begin(), s.end());
	sort(t.begin(), t.end());

	for (long long dis : x)
	{
		vector<long long> s1(2), t1(2);
		auto iter1 = lower_bound(s.begin(), s.end(), dis);
		auto iter2 = lower_bound(t.begin(), t.end(), dis);
		for (int i = 0;i < 2;i++)
		{
			s1[i] = *(iter1 - i);
			t1[i] = *(iter2 - i);

		}

		for (int i = 0;i < 2;i++)
		{
			for (int j = 0; j < 2;j++)
			{
				long long x1 = abs(s1[i] - dis);
				long long x2 = abs(t1[j] - s1[i]);
				long long x3 = abs(t1[j] - dis);
				if (x1 + x2 < ans)
				{
					ans = x1 + x2;
				}

				if (x3 + x2 < ans)
				{
					ans = x2 + x3;
				}
			}
		}

		cout << ans << endl;
		ans = INF;
	}

	return 0;
}

Measured memory_bytes: 3680
K = int(input())

from collections import deque
q = deque(range(1, 10))
for _ in range(K - 1):
    d = q.popleft()
    if d % 10 > 0:
        q.append(d * 10 + d % 10 - 1)
    q.append(d * 10 + d % 10)
    if d % 10 < 9:
        q.append(d * 10 + d % 10 + 1)
print(q.popleft())


Measured memory_bytes: 40816
module Main where
--import Debug.Trace
import Data.List
import Data.Char
import Data.Array
import Data.Maybe
import Data.Ord
import Control.Monad

solve :: [Int] -> String -> Int
solve pl = sim (listArray (0, 5) pl) where
    sim dice [] = dice!0
    sim dice (c:cs) = sim roll cs where
        roll = case c of
            'N' -> dice // [(0, dice!1), (1, dice!5), (4, dice!0), (5, dice!4)]
            'E' -> dice // [(0, dice!3), (2, dice!0), (3, dice!5), (5, dice!2)]
            'W' -> dice // [(0, dice!2), (2, dice!5), (3, dice!0), (5, dice!3)]
            'S' -> dice // [(0, dice!4), (1, dice!0), (4, dice!5), (5, dice!1)]
                
readLine:: IO [Int]
readLine = fmap (map read . words) getLine

main :: IO() 
main = do
    pl <- readLine
    cl <- getLine
--    print pl
--    print cl
    print (solve pl cl)



Measured memory_bytes: 3716
using System;

public class Sample19{
    public static void Main(){
          while(true){  
              
            string[] board = Console.ReadLine().Trim().Split(' ');
            var h = int.Parse(board[0]);
            var w = int.Parse(board[1]);
            
            //終了処理,バリデーション
            if ((h == 0) && (w== 0)){
                break;
            }else if( h < 1 || w < 1 || 300 < h || 300 < w){
                
                Console.WriteLine("入力された値が範囲外です。");
                Environment.Exit(0);
            }

            //チェス盤作成
            for(int y = 0; y < h; y++) {
                for(int x = 0; x < w; x++) {
                    Console.Write((x + y) % 2 == 0 ? '#' : '.');
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }
    }
}


Measured memory_bytes: 15912
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}
//unionfind
struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

void dfs(vector<vector<pair<int,int>>> &g,int i,vector<int> &ans,int sgn){
  if(ans.at(i)!=-1)return;
  ans.at(i)=sgn;
  rep(j,g.at(i).size()){
    int now=sgn+g.at(i).at(j).second;
    now%=2;
    dfs(g,g.at(i).at(j).first,ans,now);
  }
}
int main(){
  int n;
  cin >> n;
  vector<vector<pair<int,int>>> g(n);
  rep(i,n-1){
    int x,y,z;
    cin >> x >> y >> z;
    x--;
    y--;
    z%=2;
    g.at(x).push_back(make_pair(y,z));
    g.at(y).push_back(make_pair(x,z));
  }
  vector<int> ans(n,-1);
  dfs(g,0,ans,1);
  rep(i,n)
    cout << ans.at(i) << endl;
}

Measured memory_bytes: 12252
import java.util.*;

class Main{

    int n, m, sz;
    char[] kakko;
    int[] a, bkt, add;

    void solve(){
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        m = sc.nextInt();
        kakko = sc.next().toCharArray();

        sz = Math.max(1, (int)Math.sqrt(n) - 1);
        a = new int[n];
        bkt = new int[n/sz+10];
        add = new int[n/sz+10];
        TreeSet<Integer> set = new TreeSet<Integer>();

        for(int i=0; i<n; i++){
            if(i==0) a[i] = 1;
            else{
                if(kakko[i]=='(') a[i] = a[i-1] + 1;
                else{
                    a[i] = a[i-1] - 1;
                    set.add(new Integer(i));
                }
            }
            bkt[i/sz] = Math.min(a[i], bkt[i/sz]);
        }

        for(int i=0; i<m; i++){
            int q = sc.nextInt()-1;
            int idx = 0;
            if(kakko[q]=='('){
                kakko[q] = ')';
                set.add(new Integer(q));
                add(q, n, -2);
                //idx = set.higher(new Integer(-1));
                idx = set.pollFirst();
                kakko[idx] = '(';
                set.remove(new Integer(idx));
                add(idx, n, 2);
            }else{
                kakko[q] = '(';
                set.remove(new Integer(q));
                add(q, n, 2);
                idx = search(q);
                kakko[idx] = ')';
                add(idx, n, -2);
                set.add(new Integer(idx));
            }
            //System.out.println(Arrays.toString(kakko));
            System.out.println(idx+1);
        }
    }

    void add(int start, int last, int num){
        int from = start - start%sz;
        int to = from + sz;
        for(int i=start/sz; i<=last/sz; i++){
            if(start<=from && to<=last){
                add[i] += num;
            }else{
                for(int j=from; j<to; j++){
                    if(start<=j && j<last){
                        a[j] += num;
                    }
                }
                int min = Integer.MAX_VALUE;
                for(int j=from; j<to && j<a.length; j++){
                    min = Math.min(min, a[j]);
                }
                bkt[i] = min;
            }
            from = to;
            to += sz;
        }
    }

    int search(int f){        
        int from = f - f%sz;
        int to = from + sz;
            
        for(int i=f/sz; i>=0; i--){
            if(bkt[i]+add[i]<=1){
                for(int j=Math.min(f-1, to-1); j>=from; j--){
                    if(a[j]+add[i]==1) return j+1;
                }
            }
            to = from;
            from -= sz;
        }
        return 0;
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 116144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    REP(i, 5) {
        ll x;
        cin >> x;
        if(x == 0) cout << i+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int A1,A2,B1,B2;
	scanf("%d%d%d%d",&A1,&B1,&A2,&B2);
	A1=max(A1,A2);
	B1=min(B1,B2);
	int ans=B1-A1;
	if(ans<0) ans=0;
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long A[1000000];
int main(){
    long long X,Y; cin >> X >> Y;
    int index =0;
    for(long long i=X; i <= Y; i*= 2){
        A[index] = i;
        index++;
    }
    cout << index << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
sum = 0
for i in range(n):
    l = bisect.bisect_left(a,b[i])
    r = bisect.bisect_right(c,b[i])
    sum += l*(n-r)
    
print(sum)

Measured memory_bytes: 105332
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(m)]
import itertools
ans=0
l = [i for i in range(1,n+1)]
p = itertools.permutations(l, n)
for v in p:
  v=list(v)
  if v[0]!=1:
    continue
  x=0
  for i in range(n-1):
    w=v[i:i+2]
    w.sort()
    if w not in ab:
      x=1
      break
  if x==0:
    ans+=1
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <cmath>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int count_surround_bomb(int H, int W, int h, int w, vector<string> v) {
  int count = 0;
  if (h>0 && w>0    && v[h-1][w-1]  == '#') count++;
  if (h>0           && v[h-1][w]    == '#') count++;
  if (h>0 && w<W-1  && v[h-1][w+1]  == '#') count++;
  if (w>0           && v[h][w-1]    == '#') count++;
  if (w<W-1         && v[h][w+1]    == '#') count++;
  if (h<H-1 && w>0  && v[h+1][w-1]  == '#') count++;
  if (h<H-1         && v[h+1][w]    == '#') count++;
  if (h<H-1 && w<W-1&& v[h+1][w+1]  == '#') count++;
  return count;
}

int main()
{
  int h, w;
  vector<string> v;

  scanf("%d %d", &h, &w);
  for (int i=0; i<h; i++) {
    char line[w+1];
    scanf("%s", line);
    v.push_back(line);
  }

  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      if (v[i][j] == '#') {
        continue;
      } else {
        int n = count_surround_bomb(h, w, i, j, v);
        v[i][j] = '0'+n;
      }
    }
  }

  for (int i=0; i<h; i++) {
    printf("%s\n", v[i].c_str());
  }

  return 0;
}

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

using namespace std;

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

    long long a, b, x;

    cin >> a >> b >> x;

    if (a == 0)
        cout << b / x + 1 << endl;
    else
        cout << (b / x - (a - 1) / x) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
void Digvijay()
{
    int n;
    cin>>n;
    vector<int> a(1000000,0);
    for(int i=1;i<201;i++)
    {
        for(int j=1;j<201;j++)
        {
            for(int k=1;k<201;k++)
            {
                int val= i*i+j*j+k*k+i*j+j*k+k*i;
                a[val]++;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        cout<<a[i]<<"\n";
    }
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _=1;
    //cin>>_;
    for(int __=1;__<=_;__++)
    {
        Digvijay();
    }
}



Measured memory_bytes: 11092
N=int(input())
S=input()
ans=0
inS=set()
for s in S:
  inS.add(s)
inS=list(inS)

def searcher(num,S):
  for i in range(len(S)):
    if num==S[i]:
      return i
  return -1

for i in inS:
  x=searcher(i,S)
  for j in inS:
    y=searcher(j,S[x+1:])
    if y==-1: continue
    for k in inS:
      z=searcher(k,S[x+y+2:])
      if z==-1: continue
      #print(i,j,k)
      ans+=1
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

internal class Program {
    static void Main() => CustomMain();

    static void Solve() {
        int a, b;
        ReadMulti(out a, out b);
        WriteAnswer(RoundUp(a + b, 2));
    }


    static void CustomMain() {
#if DEBUG
        // ファイルからテストケースを読み込む
        ChangeStdIn();
        // 時間計測
        var stopwatch = new Stopwatch();
        stopwatch.Start();
#endif
        // 出力高速化
        var streamWriter = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(streamWriter);
        // 回答
        Solve();
#if DEBUG
        stopwatch.Stop();
        Console.WriteLine(stopwatch.Elapsed);
#endif
        Console.Out.Flush();
    }

    static string ReadString() => Console.ReadLine().Trim();
    static int ReadInt() => int.Parse(ReadString());
    static long ReadLong() => long.Parse(ReadString());
    static float ReadFloat() => float.Parse(ReadString());
    static double ReadDouble => double.Parse(ReadString());

    static string[] ReadStringArray() => ReadString().Split(' ');
    static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse);
    static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse);
    static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse);
    static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse);

    static T TypeConversion<T>(string s) {
        if (typeof(T) == typeof(int)) {
            return (T) Convert.ChangeType(int.Parse(s), typeof(T));
        } else if (typeof(T) == typeof(long)) {
            return (T) Convert.ChangeType(long.Parse(s), typeof(T));
        } else if (typeof(T) == typeof(double)) {
            return (T) Convert.ChangeType(double.Parse(s), typeof(T));
        } else {
            return (T) Convert.ChangeType(s, typeof(T));
        }
    }

    static void ReadMulti<T, U>(out T a, out U b) {
        var str = ReadStringArray();
        a = TypeConversion<T>(str[0]);
        b = TypeConversion<U>(str[1]);
    }

    static void ReadMulti<T, U, V>(out T a, out U b, out V c) {
        var str = ReadStringArray();
        a = TypeConversion<T>(str[0]);
        b = TypeConversion<U>(str[1]);
        c = TypeConversion<V>(str[2]);
    }

    static void WriteAnswer(object ans) => Console.WriteLine(ans);

    static bool IsOdd(long num) {
        return (num & 1) == 1;
    }

    static bool IsEven(long num) {
        return (num & 1) == 0;
    }

    static long GCD(long a, long b) {
        return b != 0 ? GCD(b, a % b) : a;
    }

    static long RoundUp(long a, long b) {
        return (a + b - 1) / b;
    }


    static void ChangeStdIn() {
        var path = "./../../TestCase.txt";
        var exStdIn = new System.IO.StreamReader(path);
        Console.SetIn(exStdIn);
    }
}

Measured memory_bytes: 11092
#include <math.h>
#include <bits/stdc++.h>
#include <deque>
#define ll long long
#define l long double
#define pi 3.14159265358979323846
#define mod 1000000007
#define vali 1000000000000000000
using namespace std;
int main()
{
    ll n;
    cin>>n;
    string s;
    cin>>s;
    if(n>=3200)
    cout<<s<<endl;
    else
    cout<<"red"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXN 100005
#define X first
#define Y second
#define mod 1000000007
#define inf 1e10
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
ll r,p,s;
ll win(char ch){
    if(ch=='r') return p;
    if(ch=='s') return r;
    return s;
}

int main()
{
    fastio;
    ll n,k;
    cin>>n>>k;
    cin>>r>>s>>p;
    ll ans=0,mx=0;
    string t;
    cin>>t;
    char used;
    for(ll i=0;i<k;i++){
        used=t[i];
        ans+=win(t[i]);
        for(int j=i+k;j<n;j+=k){
            if(t[j]!=used){
                ans+=win(t[j]);
                used=t[j];
            }
            else used='e';
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 512
#import <stdio.h>
int main() {
    char a,b,c,d,e,f,g,h,i;
    scanf("%c%c%c %c%c%c %c%c%c",&a,&b,&c,&d,&e,&f,&g,&h,&i);
    printf("%c%c%c",a,e,i);
    return 0;
}


Measured memory_bytes: 7116
#include <iostream>
using namespace std;
typedef long long ll;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N,K,Ans=0;
	cin>>N>>K;
	for(ll b=N;b>K;b--){
		ll tmp,tmp2;
		ll c=N/b,d=N%b,c2=(!K?0:(K-1)/b),d2=(!K?0:(K-1)%b);
		tmp=(b-K)*c+(d-K+1>0?d-K+1:0);
		tmp2=(b-K)*c2+(d2-K+1>0?d2-K+1:0);
		Ans+=tmp-tmp2;
	}
	cout<<Ans<<endl;
	return 0;
}

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


int main(){
    int a, b;
    cin >> a >> b;
    if(a > b){
        cout << a-1 << endl;
    }else{
        cout << a << endl;
    }
}


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

int D;
vector<int> c(26); 
vector<vector<int>> s(365, vector<int>(26));

int cal_score(vector<int> t){
    vector<int> res(D);
    int satis = 0;
    vector<int> last(26, 0);
    rep(d, D){
        satis += s[d][t[d] - 1];
        last[t[d] - 1] = d + 1;
        rep(i, 26){
            satis -= c[i] * (d - last[i] + 1);
        }
        res[d] = satis;
    }
    return res[D - 1];
}

int ch_sch(vector<int> t, int d, int q, int score){
    // change t[d - 1] -> q
    // calculate the score
    int old = t[d - 1];
    score -= s[d - 1][old - 1];
    score += s[d - 1][q - 1];

    int last_old = 0, last_new = 0;
    rep(i, D){
        if(t[i] == old ) last_old = i + 1;
        else if(t[i] == q) last_new = i + 1;
        score += c[old - 1] * (i - last_old + 1);
        score += c[q - 1] * (i - last_new + 1);
    }

    t[d - 1] = q;

    last_old = 0, last_new = 0;
    rep(i, D){
        if(t[i] == old) last_old = i + 1;
        else if(t[i] == q) last_new = i + 1;
        score -= c[old - 1] * (i - last_old + 1);
        score -= c[q - 1] * (i - last_new + 1);
    }
    return score;
}

int main(){
    // input 
    cin >> D;
    rep(i, 26) cin >> c[i];
    rep(i, D){
        rep(j, 26){
            cin >> s[i][j];
        }
    }

    // greedy
    vector<int> last(26, 0);
    vector<int> res(D);

    rep(d, D){
        int max_plus = -10000;
        int use = -1;
        rep(i, 26){
            int tmp = s[d][i] + c[i] * (d - last[i] + 1);
            if(max_plus < tmp){
                max_plus = tmp;
                use = i;
            }
        }
        last[use] = d + 1;
        res[d] = use + 1;
    }

    int cur_score = cal_score(res);

    while((clock() / (double)CLOCKS_PER_SEC) < 1.9){
        int ch_d = rand() % D + 1;
        int ch_c = rand() % 26 + 1;
        int old_c = res[ch_d - 1];
        res[ch_d - 1] = ch_c;
        int new_score = ch_sch(res, ch_d, ch_c, cur_score);
        if(cur_score < new_score){
            cur_score = new_score;
        }else{
            res[ch_d - 1] = old_c;
        }
    }

    rep(i, D){
        cout << res[i] << endl;
    }
    return 0;
}

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

string A;

int main(){
	cin >> A;
	bool ok1 = false;
	for (int i = 0; i < A.size(); i ++){
		if (A[i] == 'R'){
			ok1 = true;
		}
	}

	bool ok2 = false;
	for (int i = 1; i < A.size(); i ++){
		if (A[i] == 'R' && A[i - 1] == 'R'){
			ok2 = true;
		}
	}

	bool ok3 = (A[2] == 'R' && A[1] == 'R' && A[0] == 'R');

	if (ok3){
		cout << "3\n";
	}else if (ok2){
		cout << "2\n";
	}else if (ok1){
		cout << "1\n";
	}else{
		cout <<"0\n";
	}
}

Measured memory_bytes: 3544
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <regex>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cins(S);
    Cins(T);
    bool eq = true;
    for(int i=0;i<S.length();i++){
        if(S[i]!=T[i]) eq = false;
    }
    if(eq && T.length()==S.length()+1)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3128
def solve():
    ABCDEmin = min(ABCDE)
#    print(ABCDEmin)
    if N % ABCDEmin == 0:
        t = N//ABCDEmin + 4
    else:
        t = N//ABCDEmin + 4 + 1
    print(t)

        

if __name__ == "__main__":
    N = int(input())
    ABCDE = [int(input()) for _ in range(5)]
    solve()


Measured memory_bytes: 9108
N = int(input())
F = 0
B = 0
X = 0
S = 0
for i in range (N+1):
    if i%3==0:
        F = F + i
for j in range (N+1):
    if j%5==0:
        B = B + j
for k in range (N+1):
    if k%15==0:
        X = X + k
for l in range(N+1):
    S = S + l
print(S-F-B+X)

Measured memory_bytes: 9132
import sys
sys.setrecursionlimit(10 ** 7)

N = int(input())
visited = [False] * N
colors = [-1] * N
dist = [float('inf')] * N

def dfs(u):
    if visited[u]:
        return

    visited[u] = True
    for (v, w) in edges[u]:
        if visited[v]:
            continue
        if colors[v] != -1:
            continue

        dist[v] = dist[u] + w
        if dist[v] % 2 == 0:
            colors[v] = 0
        else:
            colors[v] = 1
        dfs(v)


edges = [[] for _ in range(N)]
for _ in range(N-1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    edges[u].append((v, w))
    edges[v].append((u, w))


colors[0] = 0
dist[0] = 0
dfs(0)
for c in colors:
    print(c)

Measured memory_bytes: 83756
#include<stdio.h>
#include<string.h>
int main()
{
	char a[100];
	gets(a);
	int m = strlen(a);
	int i,j;
	for(i = 0;i<m;i++)
	{
		if(a[i] != ',')
		{
			printf("%c",a[i]);
		}
		else if(a[i] == ',')
		{
			printf(" ");
		}
	}
	return 0;
} 

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int x;
    int c = 1;
    while(true) {
        cin >> x;
        if(x == 0){
            break;
        }
        cout << "Case " <<  c << ": " << x << endl;
        c = c + 1;
        
    }
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
 
int x,y,z;
string s1,s2;
 
int main() {
	cin >> s1;
	if (s1[0] == '7' || s1[1] == '7' || s1[2] == '7') printf("Yes\n"); else printf("No\n");
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <array>
using namespace std;
typedef long long ll;
const ll INF=2e16;
ll n,s,b,p,q,minb=INF,minb2=INF;
double routen;

ll func(ll b,ll n)
{
  if(n<b) return n;
  else
    {
      ll nextn=n/b;
      return (func(b,nextn) + (n%b));
    }
}

int main(int argc,char const* argv[])
{
  cin >> n >> s;
  if(s==n)
    {
      cout << n+1 << endl;
      return 0;
    }
  else
    {
      routen=sqrt(n);
      for(int i=2;i<=routen;i++)
	{
	  if(func(i,n)==s)
	    {
	      if(i<minb)minb=i;
	    }
	}
      if(minb!=INF)
	{
	  cout << minb << endl;
	  return 0;
	}
      else
	{
	  if((n-s)<=0)
	    {
	      cout << -1 << endl;
	      return 0;
	    }
	  for(int p=1;p<routen;p++)
	    {
	      ll canb=(n-s)/p +1;
	      if(canb<2) break;
	      if(func(canb,n)==s)
		{
		  if(minb2>canb) minb2=canb;
		}
	    }
	  if(minb2==INF)
	    {
	      cout << -1 << endl;
	      return 0;
	    }
	  else
	    {
	      cout << minb2 << endl;
	      return 0;
	    }
	}
    }
}


Measured memory_bytes: 256
def solve():
    n = int(input())
    d_org = {}
    d = {}
    for i in range(n):
        s, p = input().split()
        p = int(p)
        if s not in d:
            d_org[s] = {p: i + 1}
            d[s] = [p]
        else:
            d_org[s][p] = i + 1
            d[s].append(p)

    # print(d)
    # print(d_org)

    for s in sorted(d.keys()):
        for p in sorted(d[s], reverse=True):
            # print(d_org[s][p], s, p)
            print(d_org[s][p])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
x = int(input())
flg = False
for i in range(1, int(x**0.5)+1):
  if flg:
    break
  if x % i == 0:
    a = 0
    b = - i
    while True:
      cnt = a**5 - b**5
      if cnt == x:
        flg = True
        print(a, b)
        break
      else:
        if a > 0 and b > 0:
          if cnt > x:
            break
        a += 1
        b += 1
      


Measured memory_bytes: 9356
a, b, c = readlines.map{|line| line.chomp.chars}

card = a.shift
winner = loop do
    hand = case card
    when "a" then
        a
    when "b" then
        b
    when "c" then
        c
    end
    
    if hand.empty?
        break card.upcase
    else
        card = hand.shift
    end
end

puts winner

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

using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

template <typename T>
void print(T x)
{
	std::cout << x <<" " ;
}


template <typename T>
void println(T x)
{
	std::cout << x << "\n";
}

signed main(void) {
	int N;
	vector<int> A,B;
	cin >> N ;
	A.resize(N+1);
	B.resize(N);

	rep(i, N+1) {
		cin >> A[i];
	}

	rep(i, N) {
		cin >> B[i];
	}
	
	int ans = 0;
	rep(i, N) {
		if (A[i] >= B[i]) {
			ans +=B[i];
			//std::cout << "ans1="<< ans << "\n";
		}
		else {
			ans += A[i];
			//std::cout << "ans2=" << ans << "\n";
			B[i] -= A[i];
			if (A[i + 1] > B[i]) {
				ans += B[i];
				//std::cout << "ans3=" << ans << "\n";
				A[i + 1] -= B[i];
			}
			else {
				ans += A[i+1];
				A[i + 1] =0;
				//std::cout << "ans4=" << ans << "\n";
			}
		}
	}

	print(ans);
}

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

int main() {
	char a,b,ans;
	cin>>a>>b;
	if(a=='H'&&b=='D')ans='D';
	if(a=='H'&&b=='H')ans='H';
	if(a=='D'&&b=='H')ans='D';
	if(a=='D'&&b=='D')ans='H';
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<vector<int>> g(n);
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        cin >> x >> y;
        g[x].emplace_back(y);
        g[y].emplace_back(x);
    }
    int root = -1;
    for (int i = 0; i < n; i++) {
        if (g[i].size() == 1) {
            g[i].emplace_back(-1);
            root = i;
            break;
        }
    }
    int k = 0;
    vector<int> a(n);
    vector<int> b(n, 1);
    function<void(int, int)> dfs = [&](int v, int p) {
        if (g[v].size() == 1) {
            return;
        }
        for (int to : g[v]) {
            if (to == p) {
                continue;
            }
            dfs(to, v);
            a[v] += a[to];
        }
        if (g[v].size() == 2) {
            for (int to : g[v]) {
                if (to == p) {
                    continue;
                }
                a[v] = a[to];
                b[v] = b[to];
            }
            return;
        }
        if (a[v] + 2 <= g[v].size()) {
            k += g[v].size() - a[v] - 2;
            a[v] = 1;
            b[v] = 1;
        } else {
            a[v] = 1;
            b[v] = 0;
        }
    };
    dfs(root, -1);
    k += b[root];
    cout << k << '\n';
    return 0;
}

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

main()
{
    int n; cin>>n;
    int k; cin>>k;
    int ze=0;
    vector<long long> po,ne;
    for(int i=0; i<n; ++i)
    {
        int a; cin>>a;
        if(!a) ze++;
        else
        {
            if(a>0) po.emplace_back(a);
            else ne.emplace_back(-a);
        }
    }
    sort(rbegin(po), rend(po));
    sort(rbegin(ne), rend(ne));
    int mod(1e9+7);
    long long ans(1);
    if(ne.size()/2*2+po.size()<k)
    {
        if(ze>0) cout << 0 << "\n";
        else
        {
            for(int x: po)
            {
                ans=ans*x%mod;
            }
            for(int x:ne) ans=ans*-x%mod;
            if(ans<0) ans+=mod;
            cout << ans << "\n";
        }
    }
    else if(po.empty())
    {
        if(k&1)
        {
            if(ze>0) cout << 0 << "\n";
            else
            {
                reverse(begin(ne), end(ne));
                for(int x:ne)
                {
                    if(k==0) break;
                    k--;
                    ans*=x;
                    ans%=mod;
                }
                ans=mod-ans;
                cout << ans << "\n";
            }
        }
        else
        {
            for(int x: ne)
            {
                if(k==0) break;
                k--;
                ans*=x;
                ans%=mod;
            }
            cout << ans << "\n";
        }
    }
    else
    {
        if(k&1)
        {
            ans=po[0];
            po.erase(po.begin());
        }
        k/=2;
        vector<long long> po2,ne2;
        for(int i=1; i<po.size(); i+=2)
        {
            po2.emplace_back(po[i]*po[i-1]);
        }
        for(int i=1; i<ne.size(); i+=2)
        {
            ne2.emplace_back(ne[i]*ne[i-1]);
        }
        for(int i=0,j=0; k; k--)
        {
            if(i<po2.size())
            {
                if(j<ne2.size())
                {
                    if(po2[i]<ne2[j])
                    {
                        ans=ne2[j++]%mod*ans%mod;
                    }
                    else
                    {
                        ans=po2[i++]%mod*ans%mod;
                    }
                }
                else
                {
                    ans=po2[i++]%mod*ans%mod;
                }
            }
            else
            {
                assert(ne2.size()>j);
                ans=ne2[j++]%mod*ans%mod;
            }
        }
        cout << ans << "\n";
    }
}

Measured memory_bytes: 6576
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.lang.StringBuilder
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)
    val n = sc.nextInt()
    val a = Array(n) { sc.nextInt() - 1 }
    var count = 0
    for (i in 0 until n) {
        if (a[a[i]] == i) count++
    }
    println(count / 2)
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15); 
    int n, i, j;
    cin >> n >> i;
    j = n + 1 - i; 
    cout << j << endl; 
    return 0; 
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){

    int n,t,e,a;
    cin>>n>>t>>e;
    for(int i=1;i<=n;i++){
        cin>>a;
        for(int j=t-e;j<=t+e;j++){
            if(j%a==0){
                cout<<i<<endl;
                goto end;
            }
        }
        if(i==n)cout<<"-1"<<endl;
    }
    end:
    return 0;

}

Measured memory_bytes: 1164
import math
N, D = map(int, input().split())
X = [[int(_) for _ in input().split()] for _ in range(N)]
ans = 0
for i in range(N - 1):
    x1 = X[i]
    for j in range(i + 1, N):
        x2 = X[j]
        work = 0
        for x, y in zip(x1, x2):
            work += (x - y) ** 2

        # 判定
        if math.sqrt(work).is_integer():
            ans += 1

print(ans)

Measured memory_bytes: 3064
long d[1<<18]={0,0,1,6,19,65},M=998244353,m;b,c,N,s[4];
main(f){
	for(m=M-3;read(0,&c,1),c-10;s[c-97]++,f&=b!=c,b=c)
		m=!N|N++%3?m:(m+m)%M,
		d[N+5]=(5*d[N+4]-6*d[N+3]+2*d[N+2]-10*d[N+1]+12*d[N]+M*20)%M;
	printf("%d\n",!*s+!s[1]+!s[2]>1?:(d[N]+(N%3|*s%3-s[2]%3?f:N>3?m+f:m))%M);
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,m,k;
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k;
    vector<int>v;
    v.push_back(0);
    for(int i=0;i<n;i++)
    {
        cin>>m;
        v.push_back(m);
    }
    long long  int dp[n+1];
  
    for(int i=1;i<=n;i++)
    dp[i]=2000000000;
    dp[1]=0;
    for(int i=2;i<=n;i++)
    {
        // cout<<"i"<<i<<"\n";
        for(int j=i-1 ;j>0 and j>=i-k;j--){
        
        
            dp[i]=min(dp[i],dp[j]+abs(v[i]-v[j]));
        }
        // cout<<dp[i]<<"\n";
       
    }
    
      
          
        
    
      
    cout<<dp[n];
        
    
}

Measured memory_bytes: 4464
s = input()
t = input()
l_s = len(s)
l_t = len(t)

match = 0
num = 0
for i in range(l_s - l_t + 1):
    for j in range(l_t):
        if s[i + j] == t[j]:
            match += 1
    num = max(num, match)
    match = 0
print(l_t - num)

Measured memory_bytes: 8928
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int32_t main()
{
    IOS;
    int n,x,t;
    cin>>n>>x>>t;
    int need=n/x+(n%x!=0);
    cout<<need*t;
}

Measured memory_bytes: 3648
#include <iostream>

using namespace std;

char d[1<<22];
unsigned char key[256];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, hash;
    char com[8], str[16], *p;
    key['A']=0;
    key['C']=1;
    key['G']=2;
    key['T']=3;
    
    cin>>n;
    for(int i=0; i<n; i++) {
        cin>>com>>str;
        hash=1;
        p=str;
        while(*p) hash = (hash<<2)+key[(unsigned)*(p++)];
        
        if(com[0]=='i') {
            d[hash>>3] |= 1<<(hash&7);
        } else {
            if(d[hash>>3] & (1<<(hash&7)) ) cout<<"yes\n";
            else cout<<"no\n";
        }
    }
    return 0;
}

Measured memory_bytes: 1368