akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
using vvll = vector< vector<ll> >;
using vll = vector<ll> ;
using vb = vector<bool> ;
using pll = pair<ll, ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e18;


void pre(){



}

 

void solve(){

    string s;
    cin >> s;
    int n = s.size();
    vvll dp(n+1,vll(2,0));
    dp[0][1] = 1;
    for(int i=1;i<=n;i++){
        int d = s[i-1] - '0';
        dp[i][0] = min(dp[i-1][0] + d , dp[i-1][1] + 10 - d );
        dp[i][1] = min(dp[i-1][0] + d + 1,dp[i-1][1] + 10 - d - 1);
    }
    cout << dp[n][0] << endl;

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 58924
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi= vector<int>;
using vvi= vector<vi>;
using vd= vector<double>;
using vvd= vector<vd>;
using vc= vector<char>;
using vb= vector<bool>;
#define rep(i,x,n) for(int i=x; i<n; i++)
#define all(x) x.begin(), x.end()


int main(){
  int H,W,h,w,ans;
  cin >> H >> W >> h >> w;

  ans= (H-h)*(W-w);
  cout << ans << endl;
}


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  sort(a.begin(), a.end(), greater());
  ll res = 0;
  for (int i = 0; i < n - 1; i++) {
    int ii = (i + 1) / 2;
//    cout << i << ", " << ii << endl;
    res += (ll) a.at(ii);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3900
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();;
        int b = sc.nextInt();;
        int c = sc.nextInt();
        sc.close();
        Integer[] divisors = new Integer[Math.max(a, b)];
        Arrays.fill(divisors, 0);
        for (int i = 1; i <= Math.max(a, b); i++) {
            if (a % i == 0 && b % i == 0) divisors[i - 1] = i;
        }
        Arrays.sort(divisors, Comparator.reverseOrder());
        System.out.println(divisors[c - 1]);
    }
}

Measured memory_bytes: 22868
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int n, m;
	cin >> n;
	map<string, int> blue;
	set<string> word;
	rep(i, 0, n) {
		string s;
		cin >> s;
		word.insert(s);
		if (!blue.count(s)) {
			blue[s] = 0;
		}
		blue[s]++;
	}
	cin >> m;
	map<string, int> red;
	rep(i, 0, m) {
		string s;
		cin >> s;
		if (!red.count(s)) {
			red[s] = 0;
		}
		red[s]++;
	}
	int ans = 0;
	for (auto ite : word) {
		if (red.count(ite)) {
			ans = max(ans, blue[ite] - red[ite]);
		}
		else {
			ans = max(ans, blue[ite]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  static int w,h,c;
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    while(true) {
      w = scan.nextInt();
      h = scan.nextInt();
      c = scan.nextInt();
      if(w==0) break;
      int[][] arr = new int[w][h];
      for(int i = 0; i < w; i++) {
        for(int j = 0; j < h; j++) {
          arr[i][j] = scan.nextInt();
        }
      }
      int result = calc(arr,1,c);
      System.out.println(result);
    }
  }

  static int calc(int[][] arr, int count, int lastColor) {
    int result = 0;
    for(int i = 1; i <= 6; i++) {
      if(arr[0][0]==i) continue;
      int[][] copyArr = cloneArray(arr);
      changeColor(copyArr,i,0,0,new boolean[w][h]);
/*
        System.out.println(count+","+i);
        for(int j = 0; j < arr.length; j++) System.out.println(Arrays.toString(copyArr[j]));
        System.out.println();
*/
      if(count==5) {
        result = Math.max(result,countColor(copyArr,lastColor,0,0,new boolean[w][h]));
      }else {
        result = Math.max(result,calc(copyArr,count+1,lastColor));
      }
    }
    return result;
  }

  static void changeColor(int[][] arr, int color, int x, int y, boolean[][] checked) {
    if(checked[x][y]) return;
    checked[x][y] = true;
    if(x+1<arr.length && arr[x+1][y]==arr[x][y]) changeColor(arr,color,x+1,y,checked);
    if(y+1<arr[x].length && arr[x][y+1]==arr[x][y]) changeColor(arr,color,x,y+1,checked);
    if(x-1>=0 && arr[x-1][y]==arr[x][y]) changeColor(arr,color,x-1,y,checked);
    if(y-1>=0 && arr[x][y-1]==arr[x][y]) changeColor(arr,color,x,y-1,checked);
    arr[x][y] = color;
  }

  static int countColor(int[][] arr, int color, int x, int y, boolean[][] checked) {
    if(checked[x][y]) return 0;
    checked[x][y] = true;
    int result = 0;
    if(x+1<arr.length && arr[x+1][y]==arr[x][y]) result+=countColor(arr,color,x+1,y,checked);
    if(y+1<arr[x].length && arr[x][y+1]==arr[x][y]) result+=countColor(arr,color,x,y+1,checked);
    if(x-1>=0 && arr[x-1][y]==arr[x][y]) result+=countColor(arr,color,x-1,y,checked);
    if(y-1>=0 && arr[x][y-1]==arr[x][y]) result+=countColor(arr,color,x,y-1,checked);
    if(arr[x][y] == color) result++;
    return result;
  }

  static int[][] cloneArray(int[][] arr) {
    int[][] returnArray = new int[arr.length][];
    for(int i = 0; i < arr.length; i++) {
      returnArray[i] = new int[arr[i].length];
      for(int j = 0; j < arr[i].length; j++) {
        returnArray[i][j] = arr[i][j];
      }
    }
    return returnArray;
  }
}

Measured memory_bytes: 293956
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxx = 4e3 + 7;
int n;
char s[maxx];
int num[maxx];
vector <int> vec[maxx];
LL cnt[maxx];
bool vis[maxx];

LL chk(int a, int b, int c) {
	LL res = 0;
	for(int i = 0; i < vec[a].size(); i++) { //枚举首字母位置
		for(int j = 1; vec[a][i] + 2 * j <= n; j++) { //枚举间距
			if(num[vec[a][i] + j] == b && num[vec[a][i] + 2 * j] == c) res++;
		}
	}
	return res;
}

int main() {
	scanf("%d", &n);
	scanf("%s", s + 1);
	for(int i = 1; i <= n; i++) {
		if(s[i] == 'B') num[i] = 1;
		else if(s[i] == 'G') num[i] = 2;
		else if(s[i] == 'R') num[i] = 3;
	}
	for(int i = 1; i <= n; i++) {
		vec[num[i]].push_back(i);
		cnt[num[i]]++;
	}
	LL ans = cnt[1] * cnt[2] * cnt[3];
	ans -= chk(1, 2, 3) + chk(1, 3, 2) + chk(2, 1, 3);
	ans -= chk(2, 3, 1) + chk(3, 1, 2) + chk(3, 2, 1);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3944
n,m=map(int, input().split())
acceted=set()
penalty=0
wa_cnt=[0]*(n+1)
for i in range(m):
    p,s=map(str, input().split())
    p=int(p)
    if p in acceted:
        continue
    if s=="AC":
        penalty+=wa_cnt[p]
        acceted.add(p)
    else:
        wa_cnt[p]+=1
print(len(acceted),penalty)


Measured memory_bytes: 12652
h,w,k = (int(x) for x in input().split())
MOD = 1000000007

dp=[[0]*(w+2) for _ in range(h+2)]
fib = [0]*(w+1)

# 初期条件
fib[1] = 1
dp[0][1] = 1
# フィボナッチ
for i in range(2,w+1):
  fib[i] = fib[i-1] + fib[i-2]
  
for i in range(1, h+1):
  for j in range(1, w+1):
    dp[i][j] = (dp[i - 1][j - 1]*fib[j - 1]*fib[w - j + 1]+dp[i - 1][j]*fib[j]*fib[w - j + 1]+dp[i - 1][j + 1]*fib[j]*fib[w - j])%MOD
                                                                                                                          
print(dp[h][k])    


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();

        if (a >= 1200 ) {
            System.out.println("ARC");
        } else {
            System.out.println("ABC");
        }
    }

}

Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
int n,m,i,j,mod=924844033,dp[4005][4005][2],f[4005],a[4005],fac[4005],c,ans;
int main()
{
	scanf("%d%d",&n,&m);
	fac[0]=1;
	fz1(i,n){
		fac[i]=1ll*fac[i-1]*i%mod;
	}
	fz1(i,m){
		for(j=i;j<=n;j+=m){
			a[++c]=j;
		}
		for(j=i;j<=n;j+=m){
			a[++c]=j;
		}
	}
	dp[1][0][0]=1;
	fz(i,2,n+n){
		fz0g(j,n){
			dp[i][j][0]=(dp[i-1][j][0]+dp[i-1][j][1])%mod;
			if(j&&a[i]-a[i-1]==m){
				dp[i][j][1]=dp[i-1][j-1][0];
			}
		}
	}
	fz0g(i,n){
		f[i]=(dp[n+n][i][0]+dp[n+n][i][1])%mod;
		int t=1ll*f[i]*fac[n-i]%mod;
		if(i&1) dec(ans,t) else inc(ans,t)
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    string str;
    cin >> str;
    if(str[0] == 'R' and str[1] == 'R' and str[2] == 'R'){
        cout << "3";
        return 0;
    }
    if(str[0] == 'R' and str[1] == 'R'){
        cout << "2";
        return 0;
    }
    if(str[1] == 'R' and str[2] == 'R'){
        cout << "2";
        return 0;
    }
    if(str[0] == 'R' or str[1] == 'R' or str[2] == 'R'){
        cout << "1";
        return 0;
    }
    cout << "0";
    return 0;
}

Measured memory_bytes: 3620
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
        mut n: usize,
    }
    let chars = (b'a'..=b'z').map(char::from).collect::<Vec<_>>();
    let mut ans = vec![];
    while n != 0 {
        n = n - 1;
        let t = n % 26;
        ans.push(chars[t]);
        n = n / 26;
    }
    println!("{}", ans.into_iter().rev().collect::<String>());
}


Measured memory_bytes: 2148
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     	int t = Integer.parseInt(br.readLine());
     	//while(t-->0) {
     	int ar[] = new int[t];
   		int dp[] = new int[t];
   		StringTokenizer st = new StringTokenizer(br.readLine());
       	for(int i =0;i<t;i++) {
       		ar[i] = Integer.parseInt(st.nextToken());
       	}
     	
       	if(t==1)
       		System.out.println(ar[0]);
       	else {
       		dp[0] = 0;
       		for(int i =1;i<t; i++) {
       			dp[i] = Math.min(i>1 ? dp[i-2] + Math.abs(ar[i] - ar[i-2]) : Integer.MAX_VALUE, dp[i-1]+Math.abs(ar[i]-ar[i-1]));
       		}
       		System.out.println(dp[t-1]);
       	}
	}

}


Measured memory_bytes: 42872
#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 int MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    int p[n],q[n];
    REP(i,n){
        cin >> p[i];
    }
    REP(i,n){
        q[i] = i + 1;
    }
    int cnt = 0;
    REP(i,n){
        if(p[i] != q[i]) cnt++;
    }
    if(cnt <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long INF = (1LL<<61);

signed main(void){
    
    long long N;
    std::cin >> N;
    std::vector<long long> A,K(N+1,0ll);
    for(int i=0;i<=N;i++){
        long long a;
        std::cin >> a;
        A.push_back(a);
    }
    
    //N=0の場合だけ分ける
    if(N==0){
        if(A[0]==1){
            std::cout << 1 << std::endl;
        }else{
            std::cout << -1 << std::endl;
        }
        return 0;
    }
    
    //存在しなければtrue
    bool invalid = false;
    
    if(A[0]!=0){
        invalid=true;
    }
    
    //漸化式を解く
    K[0]=1;
    for(int i=0;i<N;i++){
        if(K[i]-A[i]<0)invalid=true;
        K[i+1]=std::min(INF,2ll*(K[i]-A[i]));
    }
    if(K[N]-A[N]<0)invalid=true;
    
    //後ろからも解く
    K[N]=A[N];
    for(int i=N-1;i>=0;i--){
        K[i]=std::min(K[i],K[i+1]+A[i]);
    }
    
    //存在しない
    if(invalid){
        std::cout << -1 << std::endl;
        return 0;
    }
    
    //存在する
    long long Ans=0;
    for(int i=0;i<=N;i++){
        Ans+=K[i];
    }
    std::cout << Ans << std::endl;
    
    return 0;
}


Measured memory_bytes: 5100
#include<stdio.h>

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

    int tmp = x;
    for(int i = 0; i < 10; i++){
        tmp = r*tmp - d;
        printf("%d\n", tmp);
    }
    return 0;

}

Measured memory_bytes: 128
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        Deque<Long> queue = new ArrayDeque<>();
        for (long i = 1; i <= 9; i++) {
            queue.add(i);
        }
        for (int i = 0; i < k - 1; i++) {
            long x = queue.remove();
            long n = 10 * x + x % 10;
            if (x % 10 != 0) {
                queue.add(n - 1);
            }
            queue.add(n);
            if (x % 10 != 9) {
                queue.add(n + 1);
            }
        }
        System.out.println(queue.remove());
    }
}


Measured memory_bytes: 30036
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <cmath>
#include <queue>
using namespace std;
#define mod (long)(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<long> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } long C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int main(){
    int N, M, C;
    cin >> N >> M >> C;
    int B[M];
    cins(B, B + M);
    int ans = 0;
    for(int i = 0; i < N; i++){
        int A[M];
        cins(A, A + M);
        int sum = C;
        for(int j = 0; j < M; j++){
            sum += A[j] * B[j];
        }
        if(sum > 0){
            ans++;
        }
    }
    cout << ans << endl;
}


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

int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    string s;
    cin >> s;
    
    ll n = s.size() + 1;
    vector<ll> a(n,0);
    
    for(int i = 0 ; i < n - 1; i++){
        if(s[i]=='<') a[i+1] = a[i] + 1;
    }
    for(int i = n - 2; i >= 0; i--){
        if(s[i]=='>') a[i] = max(a[i],a[i+1] + 1);
    }
    
    ll sum = 0;
    rep(i,n) sum += a[i];
    cout << sum << endl;
}



Measured memory_bytes: 4764
// copied by Nurstan Duisengaliev
// skatal
#include <bits/stdc++.h>
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) x.size()
 
using namespace std;
 
const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
int a[N];
void solve () {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> a[i];
	}	
	int sum = 0;
	for (int i = 1; i <= n; i ++) {
		if (i == 1) sum ++;		
		else {
			if (a[i - 1] >= a[i]) sum ++;
			a[i] = min (a[i - 1], a[i]);
		}
	}
	cout << sum;
}
 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//  cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
  
  char converter[26];
  
  char letter(int n){
    char l = 'a' + n - 1;
    return l;
    
  }
  
  char format[100];

int main(){
  
  unsigned long long n; cin >> n;
  int index = 0;
  while(n>0){
    int temp = n%26;
    if(temp==0)temp = 26;
    format[index++] = letter(temp);
    n/=26;
    if(temp==26)n--;
    
  }
  format[index] = '\n';
  for(int i=index-1;i>=0;i--)printf("%c",format[i]);
  printf("\n");
  
  return 0;
}

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

const int N = 1e5 + 5, mod = 1e9 + 7, inf = INT_MAX;

int par[N], rnk[N];
ll siz[N];

int findp(int x)
{
    return (par[x] == x? x: par[x] = findp(par[x]));
}

int main()
{
    //ios::sync_with_stdio(false);cin.tie(nullptr);ios_base::sync_with_stdio(false);
    ll n, m;
    pair<int, int> a[N];
    cin >> n >> m;
    ll beg = n * (n - 1) / 2;
    for (int i = 1; i <= n; i++)
        siz[i] = 1, par[i] = i;
    for (int i = 0; i < m; i++)
        cin >> a[i].first >> a[i].second;
    stack<ll> s;
    for (int i = m - 1; i >= 0; i--)
    {
        s.push(beg);
        int x = findp(a[i].first), y = findp(a[i].second);
        if (x != y)
            par[y] = x,
            beg -= siz[x] * siz[y],
            siz[x] += siz[y];
    }
    while (!s.empty())
        cout << s.top() << endl,
        s.pop();
    return 0;
}

Measured memory_bytes: 6720
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
typedef long long llong;

#define INFTY 1000000000



int main() {
	vector<char> vt;
	char ipt[100];
	bool juge = false;
	char obj[] = "keyence";

	cin >> ipt;
	for (int i = 0; ipt[i] != '\0'; i++) {
		vt.push_back(ipt[i]);
	}

	int sp = 0;
	while (vt[sp] == obj[sp]) {
		vt[sp] = '!';
		sp++;
		if (sp > vt.size() - 1)break;
	}
	int ep = 0;
	while (vt[vt.size() - 1 - ep] == obj[6 - ep]) {
		vt[vt.size() - 1 - ep] = '!';
		ep++;
		if (ep > vt.size() - 1)break;
	}
	if (sp + ep >= 7)juge = true;

	if (juge)cout << "YES" << endl;
	else cout << "NO" << endl;

	


	



	return 0;
}

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

int main(){
	int n,m,t;
	cin>>n>>m>>t;
	int s[114514]={};
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		s[a-m+1]++;
		s[a+m+1]--;
		}
		
	for(int i=1;i<11450;i++){
		s[i]+=s[i-1];
		}	
		
	int ans=0;
	for(int i=1;i<=t;i++){
		if(!s[i])ans++;
		}	
		cout<<ans<<endl;
	return 0;
	}

Measured memory_bytes: 3540
x = int(input())

# 1, 2, 3, ... , nの総和がX以上ならば、
# 適当に保持をいれることでたどり着ける
# 総和の公式は(1 + n)*n//2

ans = 0
while True:
    if ((1+ans)*ans)//2 >= x:
        print(ans)
        exit(0)
    ans+=1

Measured memory_bytes: 9164
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
long long  mod = 1000000007;
vector<string> s;
int main()
{
	int N;
	cin >> N;
	string S;
	for (int i = 0; i < N; i++) {
		cin >> S;
		s.push_back(S);
	}
	for (int i = 0; i < N - 1; i++) {
		if (s[i].back() != s[i + 1].front()) {
			cout << "No";
			return 0;
		}
	}
	sort(s.begin(), s.end());
	for (int i = 0; i < N - 1; i++) {
		if (s[i] == s[i + 1]) {
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long int
#define db double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define endl "\n"
#define mp make_pair
#define f first
#define s second
ll power(ll x, ll y, long long int mod = 1000000007){ ll ans = 1;x %= mod;while(y){if(y&1)ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;}
using namespace std;
int main()
{
    fastio;
    int n;
    cin >> n;
    ll act[n][3], dp[n][3];
    for(int i = 0; i < n; i++) {
        cin >> act[i][0] >> act[i][1] >> act[i][2];
    }
    
    //dp[0] = max(act[0][0], max(act[0][1], act[0][2]));
    //ll ans = dp[0];
    for(int i = 0; i < 3; i++) {
        dp[0][i] = act[0][i];
    }
    for(int i = 1; i < n; i++) {
        dp[i][0] = act[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = act[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = act[i][2] + max(dp[i - 1][1], dp[i - 1][0]);
        //dp[i] = max(ac1, max(ac2, ac3));
        //cout << dp[i] << " ";
        //ans += dp[i];
        //cout << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << endl;
    }
    cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2])) << endl;
}

Measured memory_bytes: 4992
#include<iostream>
using namespace std;
int main(){
   int n,a,b,c;
   while(cin>>n){
     a=n/100;
     b=n/10%10;
     c=n%10;
     if(a==c)
        cout<<"Yes"<<endl;
     else
        cout<<"No"<<endl;
   }
   return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

static const int ARRAY_NUM = 10;

class sort{
private:
	int tmp;
public:
	int* bable(int a[]);
};

int* sort::bable(int a[]){
	for(int i=0;i<ARRAY_NUM;++i){
		for(int j=ARRAY_NUM-1;j>i;--j){
			if(a[j]>a[j-1]){
				tmp    = a[j-1];
				a[j-1] = a[j];
				a[j]   = tmp;
			}
		}
	}
	return a;
}

int main(void){

	//int *array = new int [5];
	sort sort;
	int hgt_mt[10];
	int* hgt_max;

	//cout << "input height of mountain" << endl;

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

	hgt_max = sort.bable(hgt_mt);

	for(int i=0;i<3;i++){
		cout << hgt_max[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
n, k = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]

Y = []
Z = []

for x in X:
    if x == 0:
        Y.append(0)
        Z.append(0)
    elif x < 0:
        Y.append(abs(x))
    else:
        Z.append(x)

ans = sum(Y) + sum(Z)
Y.reverse()

for i, y in zip(range(1, len(Y)+1), Y):
    if i <= k and k - i <= len(Z):
        ans = min(ans, y + (0 if k - (i + 1) < 0 else 2 * Z[k-(i+1)]))

for i, z in zip(range(1, len(Z)+1), Z):
    if i <= k and k - i <= len(Y):
        ans = min(ans, (0 if k - (i + 1) < 0 else 2 * Y[k-(i+1)]) + z)

print(ans)

Measured memory_bytes: 14368
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] d = new long[N];
		
		for(int i = 0; i < N; i++) {
			d[i] = sc.nextLong();
		}
		
		Arrays.sort(d);
		
		if(d[N / 2 - 1] == d[N / 2]) {
			System.out.println(0);
			return;
		}
		
		long ans = d[N / 2] - d[N / 2 - 1];
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 59700
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {

fast();

{
  int n,a;
  cin>>n>>a;
  int x=n%500;
  //cout<<x<<endl;
  if(x<=a)
  {
    Yes
  }
  else
  {
    No
  }

  
  
  

}
return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	cs := make([]string, h)
	for i := range cs {
		fmt.Scan(&cs[i])
	}

	for _, s := range cs {
		fmt.Println(s)
		fmt.Println(s)
	}
}


Measured memory_bytes: 512
n = int(input())
H = list(map(int, input().split(' ')))

ans = 0
max = 0
for i in range(0, n-1):
    if H[i] >= H[i+1]:
        ans += 1
    else:
        if max < ans:
            max = ans
        ans = 0
if max < ans:
    max = ans

print(max)

Measured memory_bytes: 15020
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
vector<vector<int> > g;
vector<int> V;
int C1 = 0;
int C2 = 0;
int H, W;
void dfs(int a) {
	{
		int i = a % W;
		int j = a / W;
		if ((i + j) % 2 == 0)C1++;
		else C2++;
	}
	V[a] = 1;
	for (int i : g[a]) {
		if (V[i] == 0) {
			dfs(i);
		}
	}
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> H >> W;
	g.resize(H*W);
	V.resize(H*W, 0);
	vector<string> S(H);
	for (int i = 0; i < H; i++) {
		cin >> S[i];
	}
	int a, b;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (i + 1 < H && S[i][j] != S[i + 1][j]) {
				a = i * W + j;
				b = (i + 1) * W + j;
				g[a].push_back(b);
				g[b].push_back(a);
			}
			if (j + 1 < W && S[i][j] != S[i][j + 1]) {
				a = i * W + j;
				b = (i)* W + (j + 1);
				g[a].push_back(b);
				g[b].push_back(a);
			}
		}
	}
	int res = 0;
	for (int i = 0; i < H * W; i++) {
		if (V[i] == 0) {
			C1 = 0;
			C2 = 0;
			dfs(i);
			//cerr << C1 << " " << C2 << endl;
			res += C1 * C2;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 17920
#include<bits/stdc++.h>
#define ll long long
#define pp pair<ll,ll>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
template <typename T>
ll max(ll x, ll y)
{
    return x>y ? x : y;
}
ll min(ll x, ll y)
{
    return x<y ? x : y;
}
map<pair<ll,ll>,ll> m;ll ans;
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;cin >> n;
    for(ll i=1;i<=n;i++)
    {
        ll d=i;
        ll g=d%10;
        ll u=g;
        while(d)
        {
            if(d/10)
            u=d/10;
            d/=10;
        }
       //trace3(i, u, g);
        m[{u,g}]++;
    }
    for(auto i : m)
    {
        //trace3(i.first.first, i.first.second, i.second);
        ans+=(m[{i.first.second,i.first.first}])*i.second;
    }
    cout << ans;
    }

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

int main (void){
  int n = 0,k = 0,d = 0,b = 0,x = 0,z = 0;
  cin >> n >> k;
  vector<int> a(n,0);
  do{
    cin >> d;
    for(int i = 0;i < d;i++){
      cin >> b;
      a[b - 1]++;
    }
    x++;
  }while(x < k);

  for(int i = 0;i < n;i++){
    if(a[i] == 0){
      z++;
    }
  }

  cout << z << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>
#include <string.h>
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int a[200100], l[200010], r[200010], d[2001000];

char s[20010];
int ans[20010];
int cnt, sum;

int main(){
	int i;
	int n, temp;

	scanf("%s",s);
	n = strlen(s);
	for(i = 0 ; i < n ; i++){
		a[i + 1] = a[i] + (s[i] == '\\' ? -1 : s[i] == '/');
	}
	l[0]=a[0];

	for(i = 0 ; i < n ; i++){
		l[i + 1] = max(l[i], a[i+1]);
	}
	r[n] = a[n];

	for(i = n ; i > 0 ; i--){
		r[i - 1] = max(r[i], a[i-1]);
	}
	for(i = 0 ; i <= n ; i++){
		d[i] = min(l[i], r[i]) - a[i];
	}
	temp=0;

	for(i = 0 ; i <= n ; i++){
		if(d[i] == 0){
			if(temp != 0){
				ans[cnt++] = temp;
				sum += temp;
				temp = 0;
			}
		}else{
			temp += d[i];
		}
	}
	printf("%d\n%d%c",sum,cnt,cnt ? 32 : 10);
	for(i = 0 ; i < cnt ; i++){
		printf("%d%c",ans[i], i == cnt - 1 ? 10 : 32);
	}
}



Measured memory_bytes: 2208
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int N,M,sum;
	cin>>N>>M;
	int *a=new int[N];
	int i;
	sum=0;
	for(i=0;i<N;i++)		
	{
		cin>>a[i];
		sum+=a[i];	
	}
	sort(a,a+N);
	if(a[N-M]*4*M>=sum)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	else cout<<"No"<<endl;
	return 0;
 } 

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

#define ll long long
const ll N = 1000000007;
const ll MAX = 100000000000;

int D;
ll G;

ll pow(int deg)
{
    if (deg<0) return 0;
    if (deg==0) return 1;
    if (deg%2==1) return (pow(deg-1)*3)%N;
    ll t = pow(deg/2);
    return (t*t)%N;
}

vector<pair<int, int>> v;

int main()
{
ios_base::sync_with_stdio(false);
string s;
cin>>s;
int n = s.length();
vector<ll> a0(n), c0(n), w0(n), a1(n), c1(n), w1(n);
a0[0] = c0[0] = w0[0] = 0;
for (int i = 1; i<n; i++)
{
    a0[i] = a0[i-1]+(s[i-1]=='A');
    c0[i] = c0[i-1]+(s[i-1]=='C');
    w0[i] = w0[i-1]+(s[i-1]=='?');
}
a1[n-1] = c1[n-1] = w1[n-1] = 0;
for (int i = n-2; i>=0; i--)
{
    a1[i]=a1[i+1]+(s[i+1]=='A');
    c1[i] = c1[i+1]+(s[i+1]=='C');
    w1[i] = w1[i+1]+(s[i+1]=='?');
}

ll counter = 0;
for (int i = 0; i<n; i++)
{
    if (s[i]=='B'||s[i]=='?')
    {
        counter+=((((a0[i]*c1[i])%N))*pow(w0[i]+w1[i]))%N;
        counter%=N;
        counter+=(((a0[i]*w1[i]+c1[i]*w0[i])%N)*pow(w0[i]+w1[i]-1))%N;
        counter%=N;
        counter+=(((w0[i]*w1[i])%N)*pow(w0[i]+w1[i]-2))%N;
        counter%=N;
    }
    
}

cout<<counter%N;

}

Measured memory_bytes: 5200
fn main() {
    let mut buf = String::new();
    let _ = std::io::stdin().read_line(&mut buf).ok();
    let n: usize = buf.trim().parse().unwrap();
    for _ in 0..n {
        let mut buf = String::new();
        let _ = std::io::stdin().read_line(&mut buf).ok();
        let mut buf = buf.split_whitespace();
        let mut path = vec![0; n];
        let _: usize = buf.next().unwrap().parse().unwrap();
        let k: usize = buf.next().unwrap().parse().unwrap();
        for _ in 0..k {
            let p: usize = buf.next().unwrap().parse().unwrap();
            path[p-1] = 1;
        }
        for i in 0..n {
            print!("{}", path[i]);
            if i != n-1 {
                print!(" ");
            }
        }
    println!();
    }
}



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

int main(){
  int n,a,sum=0,ave,ans=0,temp=0;
  vector<int> v;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a;
    v.push_back(a);
    sum+=a;
  }
  ave=sum/n;
  for(int i = 0; i < n; i++){
    ans += (v[i]-ave)*(v[i]-ave);
  }
  for(int i = 0; i < n; i++){
    temp += (v[i]-ave+1)*(v[i]-ave+1);
  }
  if(ans > temp){
      ans = temp;
  }
  temp = 0;
  for(int i = 0; i < n; i++){
    temp += (v[i]-ave-1)*(v[i]-ave-1);
  }

  if(ans > temp)ans = temp;
  for(int i = 0; i < n; i++){
    temp = 0;
    for(int j = 0; j < n; j++){
      temp += (v[i]-v[j])*(v[i]-v[j]);
    }
    if(ans > temp){
      ans = temp;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
map<ll, ll>ins;
void facterize(ll n) {
	ll a = 2;
	while (n >= a * a) {
		if (n % a == 0) {
			ins[a]++;
			ins[a] = ins[a] % 1000000007;
			n /= a;
		}
		else {
			a++;
		}
	}
	ins[n]++;
}

vector<ll>relation[20], money(20, 1);
char s[110][110];
int dp[110][110];

int main() {
	string s;
	cin >> s;
	int n = s.length();
	ll ans = 0;
	ll black = 0;
	rep(i, n) {
		if (s[i] == 'B')black++;
		else {
			ans += black;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
 
//
// # Examples
//
// # integers
// input! { n: usize, m: usize, ... }
//
// # array
// input! { n: usize, v: [u64; n], }
//
// # matrix
// input! { n: usize, m: usize, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: usize,
//     w: usize,
//     board: [chars; h],
// }
 
// https://practice.contest.atcoder.jp/tasks/practice_1

fn main() {
    input! { nums: [i32;5] }
    let mut nums2 = vec![];
    for e in nums.iter() {
        let a = e%10;
        nums2.push(if a == 0 {0} else {10-a});
    }
    nums2.sort();
    let mut ans = 0;
    for e in nums.iter() { ans = ans+e; }
    for (i,e) in nums2.iter().enumerate() {
        if i < 4 { ans = ans+e; }
    }
    println!("{}",ans);
}

Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			int n = int.Parse(Console.ReadLine());
			//string s = Console.ReadLine();
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int ans = saiki(n, 0);
			Console.WriteLine(ans);


			Console.Out.Flush();
		}

		static int saiki(int n, int x)
		{
			int result = 0;
			{
				int i = x;
				bool f3 = false, f5 = false, f7 = false;
				while (i > 0) {
					int j = i % 10;
					if (j == 3) {
						f3 = true;
					} else if (j == 5) {
						f5 = true;
					} else if (j == 7) {
						f7 = true;
					}
					if (f3 && f5 && f7) {
						result++;
						break;
					}
					i /= 10;
				}
				//System.Diagnostics.Debug.WriteLine($"{x} {f3 && f5 && f7}");
			}

			{
				long k = (long)x * 10 + 3;
				if (k <= n) { result += saiki(n, (int)k); }
				k = (long)x * 10 + 5;
				if (k <= n) { result += saiki(n, (int)k); }
				k = (long)x * 10 + 7;
				if (k <= n) { result += saiki(n, (int)k); }
			}
			return result;
		}
	}
}


Measured memory_bytes: 13140
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  string a; readV(a);

  auto p = new int[][](26);
  foreach (int i, ai; a) p[ai-'a'] ~= i;

  int[] s;
  auto c = 0, b = new bool[](26);
  foreach_reverse (i, ai; a) {
    if (!b[ai-'a']) {
      b[ai-'a'] = true;
      ++c;

      if (c == 26) {
        s ~= i.to!int;
        c = 0;
        b[] = false;
      }
    }
  }
  s.reverse();
  auto k = s.length.to!int;

  char[] r;
  auto j = -1;
  foreach (i; 0..k) {
    foreach (d; 0..26) {
      auto di = p[d].assumeSorted.upperBound(j).front;
      if (di >= s[i]) {
        r ~= cast(char)('a'+d);
        j = di;
        break;
      }
    }
  }

  foreach (d; 0..26) {
    auto di = p[d].assumeSorted.upperBound(j);
    if (di.empty) {
      r ~= cast(char)('a'+d);
      break;
    }
  }

  writeln(r);
}


Measured memory_bytes: 4408
N = int(input())
S = [input() for i in range(N)]
cm, ca, cr, cc, ch = 0, 0, 0, 0, 0
s = ''
c = 1
v = []

def dfs(s, c):
    if len(s) >= 2:
        if s[len(s)-1] == s[len(s)-2]:
            s = s[:-1]
            return 0
    if len(s) >= 3:
        if s[len(s)-1] == s[len(s)-3]:
            s = s[:-1]
            return 0
    if len(s) == 3:
        if s in v:
            s = s[:-1]
            return 0
        for i in range(3):
            for j in range(3):
                for k in range(3):
                    v.append(s[i] + s[j] + s[k])
        s = s[:-1]
        return c

    c = dfs(s+'M', c*cm) + dfs(s+'A', c*ca) + dfs(s+'R', c*cr) + dfs(s+'C', c*cc) + dfs(s+'H', c*ch)

    s = s[:-1]
    return c

for w in S:
    if w[0] == 'M':
        cm += 1
    elif w[0] == 'A':
        ca += 1
    elif w[0] == 'R':
        cr += 1
    elif w[0] == 'C':
        cc += 1
    elif w[0] == 'H':
        ch += 1

c = dfs(s, c)

if cm + ca + cr + cc + ch != 0:
    print(c)
else:
    print(0)


Measured memory_bytes: 9776
#include <bits/stdc++.h>
#define int long long int
#define ss second
#define ff first
#define pb push_back
using namespace std;
const int MAX_N = 2 * 1e5 + 10, inf = 1e13 + 10, mod = 1000ll * 1000 * 1000 + 7ll;
vector <int> adj[MAX_N];
int dp[MAX_N];
int a[MAX_N];

int32_t main()
{
    //ios :: sync_with_stdio(false); cin.tie(0);
    int n, k; cin >> n >> k;
    for(int i = 0; i < n; i++) cin >> a[i];
    dp[0] = 0;
    for(int i = 1 ; i < n; i++) dp[i] = inf;
    for(int i = 1; i <= k; i++) dp[i] = abs(a[i] - a[0]);
    for(int i = k+1; i < n; i++)
    {
        for(int j = 1; j <= k; j++)
            dp[i] = min(dp[i], dp[i-j] + abs(a[i] - a[i-j]));
    }

    cout << dp[n-1];
    return 0;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

const int N = 60;

using namespace std;

int Graph[N][N];
bool vis[N];

void dfs(int s, int n)
{
    vis[s]=1;
    int i;
    for (i=1;i<=n;i++)
    {
        if (Graph[s][i] && !vis[i])
            dfs(i,n);
    }
}

main()
{
    fast;
    int n,m,i,j;
    cin>>n>>m;
    int a[m],b[m];
    for (i=0;i<m;i++)
    {
        cin>>a[i]>>b[i];
        Graph[a[i]][b[i]]=Graph[b[i]][a[i]]=1;
    }
    int ans=0;
    for (i=0;i<m;i++)
    {
        Graph[a[i]][b[i]]=Graph[b[i]][a[i]]=0;
        for (j=1;j<=n;j++)
            vis[j]=false;
        dfs(1,n);
        int flag=0;
        for (j=1;j<=n;j++)
        {
            if (!vis[j])
            {
                flag=1;
                break;
            }
        }
        if (flag)
            ans++;
        Graph[a[i]][b[i]]=Graph[b[i]][a[i]]=1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer t = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(t.nextToken());
		int k = Integer.parseInt(t.nextToken());
		t = new StringTokenizer(br.readLine());
		int[] h = new int[n], dp = new int[n];
		for(int i = 0 ; i < n ; i++) h[i] = Integer.parseInt(t.nextToken());
		Arrays.fill(dp,Integer.MAX_VALUE);
		dp[n-1] = 0;
		for(int i = n-2 ; i >= 0 ; i--)
		{
		      for(int j = i+1 ; j <= Math.min(n-1,i+k) ; j++) dp[i] = Math.min(dp[i],Math.abs(h[i]-h[j])+dp[j]);
		}
		System.out.println(dp[0]);
	}
}

Measured memory_bytes: 34824
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    vector<int> a(n + 1), b(n);
    for (int i = 0; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }

    ll r = 0;
    for (int i = 0; i < n; i++) {
        int t = min(a[i], b[i]);
        b[i] -= t;
        r += t;
        t = min(a[i + 1], b[i]);
        a[i + 1] -= t;
        r += t;
    }

    cout << r << endl;

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  
  for (int i = 0; i < N; i++) {
    for (int j = N - 1; i < j; j--) {
      if (a.at(j) > a.at(j - 1)) {
        int copy = a.at(j);
        a.at(j) = a.at(j - 1);
        a.at(j - 1) = copy;
      }
    }
  }
  
  int Alice = 0;
  int Bob = 0;
  
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      Alice += a.at(i);
    } else {
      Bob += a.at(i);
    }
  }
  
  cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
using namespace std;

#define ll long long int

const int MOD = 1000000007;

int max(int a, int b) {

	if (a > b)return a;
	else return b;

}
int main() {

	int x = 0, N, ans = 0;
	string S;

	cin >> N >> S;

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

		if (S[i] == 'I')x++;
		else x--;
		if (ans < x)ans = x;

	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
from heapq import heappop, heappush
n, m = map(int, input().split())
l = [[] for i in range(n)]
for i in range(n):
    a,b = map(int, input().split())
    c = min(m-a, n-1)
    if c < 0:
        continue
    heappush(l[c], -b)
heap = []
ans = 0
for i in range(n)[::-1]:
    for b in l[i]:
        heappush(heap, b)
    if heap:
        b = heappop(heap)
        ans += -b
print(ans)


Measured memory_bytes: 17848
#include <stdio.h>
#include <stdlib.h>
#define TEMP 0x3FFFFFFF

int gcd(int a,int b){
	if(!b)	return a;
	else gcd(b,a % b);
}

int abs(int n){
	if(n < 0)	n *= -1;
	return n;
}

int main(int argc, char const *argv[]){
	int n,x,*city;
	int min = TEMP;
	scanf("%d%d",&n,&x);
	city = (int *)malloc(sizeof(int) * n);
	for (int i = 0; i < n; ++i){
		scanf(" %d", &city[i]);
		city[i] = abs(x - city[i]);
		if(city[i] < min)	min = city[i];
	}
	for (int i = 0; i < n; ++i){
		city[i] = gcd(city[i],min);
		if(city[i] < min)	min = city[i];	
	}
	printf("%d\n", min);
	return 0;
}

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;

#define INF 		2000000007
#define MINF		-2000000007
#define MOD			10e9+7
#define MAX 		200005
// テンプレ終了
//====================================================================//


// agc034
int main(){
	string str;cin>>str;
	int N = str.length();

	REPS(i,1,N){
		if(str[i-1]=='B' && str[i]=='C'){
			str[i-1]='D';
			str[i] = ' ';
		}
	}


	ll ans = 0;
	int cntA=0;
	REP(i,N){
		if(str[i]=='A')cntA++;
		else if(str[i]=='B' || str[i]=='C')cntA=0;
		else if(str[i]==' ')continue;
		else{
			ans += cntA;
		}
	}

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> card = new ArrayList<>(9);
        for (int i = 0; i < 9; i++) {
            card.add(sc.nextInt());
        }
        int count = sc.nextInt();
        int res = 0;
        for (int i = 0; i < count; i++) {
            int num = sc.nextInt();
            int index = card.indexOf(num);
            if (-1 < index) {
                res += Math.pow(2, index);
            }
        }
        int[] yesArr = {7, 56, 448, 73, 146, 292, 273, 84};
        boolean bingo = false;
        for (int yes : yesArr) {
            if ((res & yes) == yes) {
                bingo = true;
                break;
            }
        }
        System.out.println(bingo ? "Yes" : "No");
    }
}

Measured memory_bytes: 21844