akhauriyash/Code-Regression huggingface dataset:
using System;
using static System.Console;

class Program
{
    public static void Main()
    {
        string str = ReadLine();
        int n = 0, s = 0, w = 0, e = 0;

        for (int i = 0; i < str.Length; i++)
        {
            switch (str[i])
            {
                case 'N': n = 1; break;
                case 'S': s = 1; break;
                case 'W': w = 1; break;
                case 'E': e = 1; break;
            }
        }
        string judgement = ((n^s) | (w^e)) == 0 ? "Yes" : "No";

        WriteLine(judgement);
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>
#include <numeric>
#include <stdio.h>
using namespace std;

int main() {
    int n, r;
    int ans;
    cin >> n >> r;
    if ( n <= 9) {
        ans = r + 100 * (10 -n);
    } else
    {
        ans = r;
    }
    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 256
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
money = 0
i = 0
while True:
    if M > AB[i][1]:
        money += AB[i][0] * AB[i][1]
        M -= AB[i][1]
    else:
        money += AB[i][0] * M
        break
    i += 1

print(money)


Measured memory_bytes: 27756
words = lambda t : list(map(t, input().split()))
n = int(input())
a = words(int)

a1 = 0
for i in range(n):
    if i % 2 == 0:
        a1 += a[i]
    else:
        a1 -= a[i]

a1 = a1 // 2

ans = []
ans.append(a1*2)
prevans = a1
for i in range(n-1):
    curans = a[i] - prevans
    ans.append(curans*2)
    prevans = curans

print(" ".join(map(str, ans)))


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

int main() {
 	long long n;
 	cin >> n;
 	long long a[n];
 	unordered_map<long long, long long> mp;
 	for(long long i = 1; i < n; i++) {
        cin >> a[i];
        mp[a[i]]++;
 	}
 	for(long long i = 1; i <= n; i++) {
        if(!mp.count(i)) {
            cout << "0" << endl;
        }
        else {
            cout << mp[i] << endl;
        }
 	}
  	return 0;
}


Measured memory_bytes: 12888
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, x = LI()
p = [0] * n
a = [0] * n
a[0] = p[0] = 1
for i in range(1, n):
    a[i] = 2 * a[i - 1] + 3
    p[i] = 2 * p[i - 1] + 1


def f(n, x):
    if x==1:
        return 0 if n else 1
    elif 1 < x <= 1 + a[n - 1]:
        return f(n - 1, x - 1)
    elif x == a[n - 1] + 2:
        return p[n - 1] + 1
    elif x <= 2 * a[n - 1] + 2:
        return f(n - 1, x - a[n - 1] - 2) + p[n - 1] + 1
    else:
        return 2 * p[n - 1] + 1


print(f(n, x))

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;


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

	while (true) {
		int N, K, S;
		cin >> N >> K >> S;
		if (N == 0 and K == 0 and S == 0) {
			break;
		}

		vector<vector<vector<int>>> dp(N + 10, vector<vector<int>>(K + 10, vector<int>(S + 10)));
		dp[1][0][0] = 1;

		FOR(i, 1, N + 1) {
			FOR(j, 0, K + 1) {
				FOR(k, 0, S + 1) {
					dp[i + 1][j][k] += dp[i][j][k];
					if (k + i < dp[0][0].size()) {
						dp[i + 1][j + 1][k + i] += dp[i][j][k];
					}
				}
			}
		}
		print(dp[N + 1][K][S]);
	}

	return 0;
}


Measured memory_bytes: 3368
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // ABC051B - Sum of Three Integers

        Scanner sc = new Scanner(System.in);

        int k = sc.nextInt();   // 2 <= k <= 2500
        int s = sc.nextInt();   // 0 <= s <= 3k

        Integer count = 0;
        for (int i = 0; i <= k; i++) {
            for (int j = 0; j <= k; j++) {
                int z = s - (i + j);
                if (0 <= z && z <= k) count++;
            }
        }
        
        System.out.println(count);
    }

}

Measured memory_bytes: 57940
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    vi a(n);
    vi d(1001001);
    REP(i, n) cin >> a[i];
    SORT(a);
    REP(i, n) {
        if (d[a[i]] != 0) {
            d[a[i]] = 2;
            continue;
        }
        for (int j = a[i]; j <= 1000000; j += a[i]) d[j]++;
    }
    int ans = 0;
    REP(i, n) {
        if (d[a[i]] != 2) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 7960
import bisect

N = int(input())
A = sorted(list(map(int, input().split())))
B = list(map(int, input().split()))
C = sorted(list(map(int, input().split())))

ans = 0
for i in range(N):
    top = bisect.bisect_left(A, B[i])
    bottom = N - bisect.bisect_right(C, B[i])
    ans += top * bottom

print(ans)

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

#define int long long
#define forn(i,a,n) for (int i=a; i<n; i++)

int n,m;
char a[21][21];
int d[21][21];
int res=-2e18;
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};

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

	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	
	cin>>n>>m;
	forn(i,0,n) forn(j,0,m) cin>>a[i][j];
	forn(i,0,n){
		forn(j,0,m){
			memset(d,-1,sizeof(d));
			if (a[i][j]=='#') continue;
			queue<int> q;
			q.push(i); q.push(j);
			d[i][j]=0;
			while (!q.empty()){
				int x=q.front(); q.pop();
				int y=q.front(); q.pop();
				forn(k,0,4){
					int nx=x+dx[k];
					int ny=y+dy[k];
					if (nx<0 || nx>=n || ny<0 || ny>=m) continue;
					if (d[nx][ny]==-1 && a[nx][ny]=='.'){
						d[nx][ny]=d[x][y]+1;
						q.push(nx); q.push(ny);
					}
				}
			}
			forn(r,0,n)
				forn(c,0,m)
					res=max(res,d[r][c]);
		}
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
 
int main() {
	int k;
	cin >> k;
	rep(i,k) cout << "ACL";
	cout << endl;
	return 0;
}

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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1010;
const ll INF = 1LL << 60;

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;}



// Main Code
set<ll> s;
int main()
{
	ll n, m;
	cin>>n>>m;
	for(ll i=1; i*i <= m; i++)
	{
		if(m%i == 0)
		{
			s.insert(i);
			s.insert(m/i);	
		}
	}
	ll z = m / n;
	auto itr = s.upper_bound(z);
	if(*itr == z) cout<<z<<endl;
	else 
	{
		itr--;
		cout<<*itr<<endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b,k;
    cin >> k >> a >> b;
    int d = a/k, e=b/k;
    int f = d*k;
    if(f<a) f=(d+1)*k;
    if(f>b) cout << "NG" << endl;
    else cout << "OK" << endl;
    return 0;
}

Measured memory_bytes: 3588
R,G,B,N=map(int,input().split())

answer=0
for r in range(N//R+1):
  for g in range(N//G+1):
    b_ball=N-r*R-g*G
    if b_ball<0:
      break
    elif b_ball%B==0:
      #print(r,g,b_ball%B)
      answer+=1
      
print(answer)

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

using ll = long long;
using namespace std;
constexpr ll inf = 1e15;
constexpr ll mod = 1e9+7;

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

    string S;
    cin>>S;
    char prev = S[0];
    int count = 0;
    for (int i = 1; i < S.length(); i++) {
        if (prev != S[i]) count++;
        prev = S[i];
    }
    cout<<count<<endl;

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>

using namespace std;

int main(){
	int a, b, c;
	int p = 0;
	cin >> a >> b >> c;
	for (int i = a; i <= b; i++){
		if (c%i == 0){
			p++;
		}
	}
		cout << p << endl;
	return 0;
	}


Measured memory_bytes: 3108
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define rep(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define irep(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define rrep(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

const int MOD = 1e9 + 7;

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    set<int> lis;
    for (int i = 0; i <= n; i++) {

        lis.insert(i * m);
        for (int j = 0; j <= m; j++) {
            lis.insert(i * m + (n - 2 * i) * j);
        }
    }
    cout << (lis.count(k) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 13056
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n; cin >> n;
  int64 a[n];
  rep(i, n) cin >> a[i];
  sort(a, a + n);

  int64 s[n];
  s[0] = a[0];

  for (int i = 1; i < n; ++i){
    s[i] = s[i - 1] + a[i];
  }

  bool flag[n] = {};

  for (int i = 0; i < n - 1; ++i){
    if (s[i] * 2 >= a[i + 1]) flag[i] = true;
  }
  flag[n - 1] = true;
  int ans = 0;

  int pos = n - 1;
  while (flag[pos]) {
    --pos; ++ans;
  }

  print(ans);
  
  return 0;
}

Measured memory_bytes: 1920
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

typedef long long LL;

int N,A,B;
int X[100010];
int d[100010];
LL ans;

int main(){
	scanf("%d%d%d%d" , &N , &A , &B , &X[0]);
	repp(i,1,N){
		scanf("%d" , X + i);
		d[i] = X[i] - X[i-1];
	}
	sort(d+1,d+N);
	repp(i,1,N){
		if((LL)A * d[i] >= (LL)B){
			ans += (LL)B * (N - i);
			break;
		}
		ans += (LL)A * d[i];
	}
	printf("%lld\n" , ans);
	return 0;
}


Measured memory_bytes: 896
#include<stdio.h>
#include<string.h>

#define MAX 100

int n,c,d=0;
int i;
int pre[1000],in[1000],post[1000];

int find(int x){
  for(i=0; i<n;i++){
    if(x==in[i]){return i;}
  }

  return 0;
}

void rec(int l, int r){
  int a,b;
  if(l>=r){return;}

  a=pre[d++];
  b=find(a);

  rec(l,b);
  rec(b+1,r);
  post[c++]=a;
}

int main(void){
  scanf("%d",&n);

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

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

  rec(0,n);

  for(i=0; i<n;i++){
    if(i!=n-1){
      printf("%d ",post[i]);
    }else{
      printf("%d\n",post[i]);
    }

  }

  return 0;

}


Measured memory_bytes: 2144
#include <iostream>
int main() {
    int N;
    double odd = 0.0000;
    std::cin >> N;
    for (int i = 0; i < N; i++){
        if(((i+1)%2) == 1){
            odd = odd + 1.0000;
        }
    }
    std::cout << (odd / N) << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;



int main()
{
	int n,m,a,b,c,sum=0;
	vector<int>v;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		sum+=a;
		v.push_back(a);
	}
	cin>>m;
	for(int i=0;i<m;i++)
	{
		cin>>b>>c;
		cout<<sum-v[b-1]+c<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int lengthFirst = scanner.nextInt();
		int lengthSecond = scanner.nextInt();
		int maximum = scanner.nextInt();
		int[] books1 = new int[lengthFirst];
		int[] books2 = new int[lengthSecond];
		
		for(int i = 0; i < lengthFirst; i++)
			books1[i] = scanner.nextInt();
		for(int i = 0; i < lengthSecond; i++)
			books2[i] = scanner.nextInt();
		
		long[] sum = new long[lengthFirst];
		sum[0] = books1[0];
		int nums1 = 0;
		if(sum[0] > maximum)
			nums1--;	
		
		
		for(int i = 1; i < lengthFirst; i++) {
			sum[i] = sum[i - 1] + books1[i];
			if(sum[i] > maximum)
				break;
			nums1++;
		}
		long[] sum2 = new long[lengthSecond];
		sum2[0] = books2[0];
		int nums2 = 0;
		if(sum2[0] > maximum)
			nums2--;	
		for(int i = 1; i < lengthSecond; i++) {
			sum2[i] = sum2[i - 1] + books2[i];
			if(sum2[i] > maximum)
				break;
			nums2++;
		}
		int result = Math.max(nums2 + 1, nums1 + 1);
		int temporal = nums2;
		for(int i = 0; i <= nums1; i++) {
			int temporal2 = temporal;
			for(int j = temporal; j >= 0; j--) {
				if(sum[i] + sum2[j] > maximum) {
					temporal2--;
				}
				else {
					result = Math.max(result, j + i + 2);
					break;
				}
			}
			temporal = temporal2;
		}
		
		System.out.println(result);
	}

}


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

int d[50];

int main() {
    
    int n;
    int total=0;

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

    for (int i=0; i<n; i++){
        for (int j=0; j<n; j++){
            if (j>i){
                total += d[i] * d[j];
            }
        }
    }
    cout << total << "\n";


    return 0;
}

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

using namespace std;

typedef long long int ll;
 
template<class T> inline bool chmax(T& a,T b){ if(a<b){ a=b; return true;} return false; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){ a=b; return true;} return false; }
 
typedef pair<int,int> pair;

int gcd(int a,int b){
    return (a%b==0) ? b : gcd(b,a%b); 
}

int main(){
    int k; cin >> k;
    ll ans=0;

    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int l=1;l<=k;l++){
                ans+=gcd(gcd(i,j),l);
            }
        }
    }
    
    cout << ans << endl;

}

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

	typedef long long int ll;
	typedef long double ld;

	//****************************************************                
	#define lp(var,start,end) for (ll var = start; var <end ; ++var)
	#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
	#define pb push_back
	#define mp make_pair
	#define pf push_front
	#define ff first
	#define ss second
	#define vll vector<ll>
	#define pll pair<ll,ll> 
	#define vpll vector<pll>
	#define all(X) X.begin(),X.end()
	#define endl "\n" //comment it for interactive questions
	#define trace1(a) cerr << #a << ": " << a << endl;
	#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
	#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
	#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
	#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
	#define MOD (ll)1e9+7; //change it for other mods
	#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
	        //*******************************************************
	//Some Functions

	ll powmod(ll a,ll b)
	{
	   ll res = 1;
	   while(b > 0) {
	      if(b & 1) res = (res * a) % MOD;
	      a = (a*a)%MOD;
	      b = b >> 1; 
	  }
	  return res % MOD;
	}

	vll gr[10000];
	ll ghodi;
	double dp[1000];
	double dp2[1000];

	double expected(ll source) {
		if(dp[source] != -1) {
			return dp[source];
		}
		double count = 0;
		double total_paths = 0;
		double jmax = 0;
		if(gr[source].size() == 1 && source == ghodi) {
			return (dp[source] = expected(gr[source][0]) + 1);
		}
		for(ll j : gr[source]) {
			// cout << source << "-> ";
			count++;
			total_paths += expected(j);
			// cout << expected(j) << " ";
			// cout << "\n";
			jmax = max(jmax, dp[j]);
		}
		// cout << "\n";
		if(source == ghodi) {
			dp[source] = (total_paths - jmax)/(count - 1);
		}
		else {
			dp[source] = total_paths/count;
		}
		dp[source]++;
		// cout << source << " " << dp[source] << "\n";
		return dp[source];
	}

	void solve()
	{
	    ll n,m;
	    cin >> n >> m;
	    for(ll i=0;i<m;i++) {
	    	ll x,y;
	    	cin >> x >> y;
	    	gr[x].pb(y);
	    }
	    for(ll i=1;i<=n;i++) {
	    	dp[i] = -1;
	    	dp2[i] = -1;
	    	// cout << i << ": ";
	    	// for(ll j : gr[i]) {
	    	// 	cout << j  << " ";
	    	// }
	    	// cout << "\n";
	    }
	    dp[n] = 0;
	    ghodi = 0;
	    double yoans = expected(1);
	    for(ll i=1;i<n;i++) {
	    	for(ll j=1;j<n;j++) {
	    		dp[j] = -1;
	    	}
	    	ghodi = i;
	    	yoans = min(yoans, expected(1));
	    }
	    cout << fixed << setprecision(8) << yoans << "\n";
	}

	int main()
	{
	    FAST_IO;
	    // #ifndef ONLINE_JUDGE 
	    //   OC;
	    // #endif
	    ll t = 1;
	    // cin >> t;
	    while(t--){
	        solve();
	    }
	}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
  #include "_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;
const int MOD = 1000000007;

struct Combination{
  vector<int> fact; //　fact[i] = iの階乗
  Combination(int n) : fact(n+1){
    fact[0] = fact[1] = 1;
    for(int i = 2; i <= n; i++){
      fact[i] = fact[i-1] * i % MOD;
    }
  }

  int nCr(int n, int r){ // nCr = n!/r!(n-r)!
    if(n < r) return 0;
    return fact[n] * inv(fact[r]*fact[n-r]%MOD) % MOD;
  }

  int inv(int n, int p = MOD-2){ // a/n ≡ a*n^(p-2) nとpは互いに素
    int r = 1;
    for(; p > 0; p >>= 1){
      if(p & 1LL) r = r * n % MOD;
      n = n * n % MOD;
    }
    return r; // r = n^p % MOD
  }
};

signed main(){

  int k; cin >> k;
  string s; cin >> s;

  Combination c(2e6);
  int n = s.size(), ans = 0;
  for(int i = 0; i <= k; i++){
    ans = (ans + c.nCr(n-1+i, i) * c.inv(25, i) % MOD * c.inv(26, k-i)) % MOD;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 20076
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstring>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(a) (a).begin(), (a).end()
#define OUT(x) out << (x) << endl;
#define M0(x) memset(x, 0, sizeof(x))
#define MINF(x) memset(x, 0x3f, sizeof(x))
#define MMINUS(a) memset(a, 0xff, sizeof(a))
#define ten(n) ((int)1e##n)

const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
const double EPS = 1.0 / INF;
const char ENDL = '\n'; // for JetBrains IDE only supports yen

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 gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

using namespace std;

//===================================== template =========================================================

int main() {
    cin.tie(nullptr); ios_base::sync_with_stdio(false);
    int N, M, Q; cin >> N >> M >> Q;
    vector<vector<int>> v(N);
    REP(i, N) {
        vector<int> ve(N+1, 0); v[i] = ve;
    }

    REP(i, M) {
        int l, r; cin >> l >> r; l--; r--;
        FOR(j, r+1, N) v[l][j]++;
    }

    REP(i, Q) {
        int p, q; cin >> p >> q; p--; q--;
        int res = 0;
        FOR(i, p, q) {
            res += v[i][q+1] - v[i][p];
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 1920
use proconio::input;

fn main() {
    input! {
        x: i32,
        y: i32,
    }

    for a in 0 .. x + 1 {
        let b = x - a;
        let sum = a * 2 + b * 4;
        if sum == y {
            println!("Yes");
            return
        }
    }

    println!("No");
}


Measured memory_bytes: 2132
r = input().split()
a = int(r[0])
b = int(r[1])

if a>b:
    print('{0}{1}{2}'.format('a',' > ','b'))
elif a<b:
    print('{0}{1}{2}'.format('a',' < ','b'))
else:
    print('{0}{1}{2}'.format('a',' == ','b'))

Measured memory_bytes: 7716
#include <iostream>
#include <set>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
using namespace std;

int main(void)
{
	int ans = 0;
	int N; cin >> N;
	vector<lli> a(0); 
	set<lli> s;
	rep(i, 0, N) {
		lli tmp; cin >> tmp;
		if (tmp > 100000)ans++;
		else {
			s.insert(tmp);
			a.push_back(tmp);
		}
	}
	sort(a.begin(), a.end());

	set<lli>::iterator li;
	int k = 0;
	for (li = s.begin(); li != s.end(); li++) {
		int count = 0;
		while (*li == a[k]) {
			count++;
			if (k + 1 >= a.size())break;
			k++;
		}
		if (count < *li)ans += count;
		else ans += (count - *li);
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
  int N = 0, K = 0, d = 0;
  
  cin >> N >> K;
  
  d = 1;
  
  for (int i = 0; i < N; i++) {
    if ((d * 2) < (d + K)) {
      d *= 2;
    }
    else {
      d += K;
    }
  }
  
  cout << d << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll a,b,c;cin>>a>>b>>c;
    ll l=a+b;
    ll r=c-l;
    if(r<=0){
        cout<<"No"<<endl;
        return 0;
    }
    r=r*r;
    l=4*a*b;
    if(l<r)cout<<"Yes"<<Endl;
    else cout<<"No"<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 256
#include<stdio.h>
#define N 100000
#define INF 1000000000
int count;
typedef struct{
  char mark;
  int value;
}card;
void quicksort(card[],int,int);
void merge(card[],int,int,int);
void mergeSort(card[],int,int,int);
int partition(card[],int,int);
int main(){
  int n,i,x,z=1;
  card A[N],B[N];
  char X[100];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %d",X,&x);
    A[i].mark=B[i].mark=X[0];
    A[i].value=B[i].value=x;
  }
  mergeSort(A,n,0,n);
  quicksort(B,0,n-1);
  for(i=0;i<n;i++){
    if(A[i].mark!=B[i].mark)
      z=0;
  }
  if(z==1)
    printf("Stable\n");
  else
    printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",B[i].mark,B[i].value);
  }
  return 0;
}


void quicksort(card A[],int p,int r){
  int q;
  if(p<r){
    q=partition(A, p, r);
    quicksort(A, p, q-1);
    quicksort(A, q+1, r);
  }
}
void merge(card A[],int left,int mid,int right){
  int i,j,x;
  int inf=1000000000;
  int n1=mid-left;
  int n2=right-mid;
  card L[n1],R[n2];
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1].value=R[n2].value=inf;
  i=0;
  j=0;
  for(x=left;x<right;x++){
    count++;
    if(L[i].value<=R[j].value){
      A[x]=L[i];
      i=i+1;
    }
    else{
      A[x]=R[j];
      j=j+1;
    }
  }
}
void mergeSort(card A[],int n,int left,int right){
  if(left+1<right){
    int mid=(left+right)/2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid,right);
    merge(A,left,mid,right);
  }
}
int partition(card A[],int p,int r){
  int i,y;
  card x,z;
  x=A[r];
  y=p-1;
  for(i=p;i<r;i++){
    if(A[i].value<=x.value){
      y++;
      z=A[y];
      A[y]=A[i];
      A[i]=z;
    }
  }
  z=A[y+1];
  A[y+1]=A[r];
  A[r]=z;
  return y+1;
}



Measured memory_bytes: 4140
#include <iostream>
#include <climits>
#include <vector>
using namespace std;
const int INF=1e9+5;
int main()
{
    int n;
    cin >> n;
    int h[n],cost=0;
    vector<int> dp(n,INF);
    dp[0]=0;
    
    for(int i=0;i<n;++i)
    {
        cin >> h[i];
    }
    
    for(int i=0;i<n;++i)
    {
        if(i+1<n)
        dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
        if(i+2<n)
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
    }
    cout << dp[n-1] << endl;
    
    return 0;
}

Measured memory_bytes: 4020
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb emplace_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1e9+7;
const ll inf=LONG_LONG_MAX;
const ll ms=(2e5)+5;

string s;

int go(int i,int j)
{
    i--; j--;
    while(i>=0)
    {
        if(s[i]!=s[j])return 0;
        i--; j--;
    }
    return 1;
}


int main()
{
    idfc;
  ///  string s;
   ll n;
   cin>>n;
   n--;

   ll ans= (n*(n+1))/2;
   cout<<ans;

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i,j,a,b,c,d,e,f,g;
  c=0;
  cin >> a >>b;
  int x[a];
  for(i=0;i<a;i++){
    cin >> x[i];
  }
  for (i=0; i<a; ++i) {
    for (j=i+1; j<a; ++j) {
      if (x[i] > x[j]) {
        g =  x[i];
        x[i] = x[j];
        x[j] = g;
      }
    }
  }
    for(i=0;i<b;i++){
      c=c+x[i];
    }
    cout << c;
}

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

typedef long long int ll;
typedef pair<int, int> P;
#define INF 10000000000000

int p[100005];
P s[100005];

// Union-Find木
struct UnionFind
{
	vector<int> par;
	vector<int> height;

	UnionFind(int n)
	{
		for (int i = 0; i < n; i++)
		{
			par.push_back(i);
			height.push_back(0);
		}
	}

	int find(int x)
	{
		if (par[x] == x)
			return x;
		else
			return par[x] = find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);
		if (x == y)
			return;

		if (height[x] < height[y])
			par[x] = y;
		else
		{
			par[y] = x;
			if (height[x] == height[y])
				height[x]++;
		}
	}

	bool same(int x, int y)
	{
		return find(x) == find(y);
	}
};

int main()
{
	int N, M;
	int ans = 0;

	cin >> N >> M;

	UnionFind u(N+1);

	for (int i = 1; i <= N; i++)
		cin >> p[i];

	for (int i = 0; i < M; i++)
	{
		cin >> s[i].first >> s[i].second;
		u.unite(s[i].first, s[i].second);
	}

	for (int i = 1; i <= N; i++)
	{
		if (u.same(p[i], i))
			ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2420
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


s = S()
n = len(s)
ans = 0
for i in range(2 ** (n - 1)):
    res = '' + s[0]
    for j in range(n - 1):
        if i >> j & 1:
            res += '+'
        res += s[j + 1]
    res = list(map(int, res.split('+')))
    ans += sum(res)
print(ans)


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N; cin >> N;
    vector<vector <P>> X(N);
    rep(i, N){
        int a; cin >> a;
        rep(j, a){
            int x, y; cin >> x >> y;
            x--;
            X.at(i).push_back(make_pair(x, y)); // ind, state
        }
    }

    // bit全探索
    int ans = 0;
    for (int bit = 0; bit < (1<<N); ++bit) { // 1を左に2回シフトすると100
        vector<int> S; // 正直者の集合
        vector<int> state(N); rep(i, N){state.at(i) = 0;} // 1: 正直, 0: 嘘つき
        for (int i = 0; i < N; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                S.push_back(i);
                state.at(i) = 1;
            }
        }
        bool flag = false; // 失敗すると立つ
        for (auto s: S){
            for (auto p: X[s]){
                if (state.at(p.first) != p.second){ // 証言が矛盾する場合break
                    flag = true;
                }
                if (flag){break;}
            }
            if (flag){break;}
        }
        if (!flag){
            if (S.size() > ans){ans = S.size();}
        }
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math
sys.setrecursionlimit(10**8)


def eratosthenes_sieve(n):
    table = [0] * (n + 1)
    prime_list = []

    for i in range(2, n + 1):
        if table[i] == 0:
            prime_list.append(i)
            for j in range(i + i, n + 1, i):
                table[j] = 1

    return prime_list


def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = 0
    m = max(A)
    zeta = [0]*(m+1)
    for a in A:
        zeta[a] += 1

    # 素数の列挙
    primes = eratosthenes_sieve(m)
    # ゼータ変換
    for p in primes:
        for i in range(1, m//p+1):
            zeta[p*i] += zeta[i]

    for a in A:
        if zeta[a] == 1:
            ans += 1
    print(ans)

    # print(zeta)
    # for a in A:
    # print(a, zeta[a])

    return


if __name__ == '__main__':
    main()


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

typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

const int level = 62;

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif
  int n;
  LL k;
  cin >> n >> k;

  vector <int> a (n + 1);
  for (int i = 1; i <= n; i++) cin >> a[i];

  vector <vector <int> > nxt (n + 1, vector <int> (65, -1));
  for (int i = 1; i <= n; i++) nxt[i][0] = a[i];
  for (int i = 1; i <= level; i++) {
    for (int node = 1; node <= n; node++) {
      nxt[node][i] = nxt[nxt[node][i - 1]][i - 1];
    }
  }

  int cur = 1;
  for (int i = 0; i <= 62; i++) {
    if ((k >> i)&1) cur = nxt[cur][i];
  }

  cout << cur << endl;
  return 0;
}



Measured memory_bytes: 61808
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int isprime(int x) {
	if (x < 2) return 0;
	else if (x == 2)return 1;
	if (x % 2 == 0)return 0;
	for (int i = 3; i * i <= x; i += 2) {
		if (x % i == 0) {
			return 0;
		}
	}
	return 1;
}

int main() {
	int n, x, cnt = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x;
		cnt += isprime(x);
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3048
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(long long N, long long D, long long A, std::vector<long long> X, std::vector<long long> H){
  vector<pair<long long, long long>> m;
  vector<long long> dist(N);
  vector<long long> dec(N, 0);
  long long d = 0;
  long long ret = 0;
  for (int i = 0; i < N; ++i) {
    m.emplace_back(X[i], H[i]);
  }
  sort(m.begin(), m.end());
  for (int i = 0; i < N; ++i) {
    auto itr = lower_bound(m.begin(), m.end(), make_pair(m[i].first + D*2 + 1, 0LL));
    dist[i] = static_cast<long long>(itr - m.begin());
    // std::cout << dist[i] << std::endl;
  }
  long long t;
  for (int i = 0; i < N; ++i) {
    d -= dec[i];
    if (m[i].second <= d) {
      continue;
    } else {
      t = (m[i].second - d - 1) / A + 1;
      ret += t;
      d += t * A;
      if (dist[i] >= N) continue;
      dec[dist[i]] += t * A;
    }
  }
  std::cout << ret << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long D;
  scanf("%lld",&D);
  long long A;
  scanf("%lld",&A);
  std::vector<long long> X(N);
  std::vector<long long> H(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&X[i]);
    scanf("%lld",&H[i]);
  }
  solve(N, D, A, std::move(X), std::move(H));
  return 0;
}


Measured memory_bytes: 12656
#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 << "[";
    if (v.size() == 0) return 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 << "{";
    if (s.begin() == s.end()) return 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 << "{";
    if (s.begin() == s.end()) return 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 << "{";
    if (m.begin() == m.end()) return 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 << "{";
    if (m.begin() == m.end()) return 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 << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N, K;
    cin >> N >> K;
    vec<lint> x_list(N);
    range(i, 0, N) cin >> x_list.at(i);
    lint res = (1LL << 58);
    range(start, 0, N - K + 1) {
        lint left = x_list.at(start), right = x_list.at(start + K - 1);
        lint time;
        if (left >= 0) time = right;
        else if (right <= 0) time = -left;
        else time = min(right, -left) + right - left;
        res = min(res, time);
    }
    cout << res << "\n";
}

Measured memory_bytes: 1024
S = input()

a=0
ab=0
ans=0
n=1
m=10**9+7
for s in S:
    if s=='A':
        a+=n
    elif s=='B':
        ab+=a
    elif s=='C':
        ans+=ab
    else:
        ans+=2*ans+ab
        ab+=2*ab+a
        a+=2*a+n
        n*=3
        n%=m
    ans%=m
    ab%=m
    a%=m
print(ans)



Measured memory_bytes: 41196
#!/usr/bin/env python3
import sys


def solve(S: str):
    n = len(S)
    print("x" * n)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> ii;

const int len = 2e5+5;
int dis[len];
vector<int> adj[len];

void dfs(int u){
    for (int j = 0; j < adj[u].size(); j++){
        int v = adj[u][j];
        if (!dis[v])
            dis[v] = dis[u]+1, dfs(v);
    }
}

int main(){
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n-1; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        adj[a].pb(b);
        adj[b].pb(a);
    }

    dis[1] = 1;
    dfs(1);
    int mx = 0, u;
    for (int i = 1; i <= n; i++)
        if (dis[i] > mx)
            mx = dis[i], u = i;

    for (int i = 1; i <= n; i++)
        dis[i] = 0;
    dis[u] = 1;
    dfs(u);
    mx = 0;
    for (int i = 1; i <= n; i++)
        mx = max(mx, dis[i]);

    if (mx%3 == 2)
        printf("Second\n");
    else
        printf("First\n");
    return 0;
}


Measured memory_bytes: 21376
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n,k;
    cin >> n >> k;
    vector<pair<int, ll>> v(n);
    REP(i,n){
        cin >> v[i].second >> v[i].first;
    }
    sort(ALL(v));
    reverse(ALL(v));
    ll now = 0;
    set<int> s;
    multiset<ll> used;
    for(int i = 0; i < k; i++){
        now += v[i].first;
        if(s.count(v[i].second)) used.insert(v[i].first);
        else s.insert(v[i].second);
    }
    now += s.size() * s.size();
    ll ans = now;
    for(int i = k; i < n; i++){
        if(used.size() == 0) break;
        if(!s.count(v[i].second)){
            now -= *used.begin();
            used.erase(used.begin());
            s.insert(v[i].second);
            now += v[i].first;
            now += s.size() * s.size() - (s.size() - 1) * (s.size() - 1);
            ans = max(ans, now);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6272