akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main() { 
  int d;  
  while(cin >> d) {
    int sum=0;  
    for(int i=1; i<600/d; i++) {  
      sum+=(d*i)*(d*i)*d;   
    }   
    cout << sum << endl; 
  } 
  return 0;
}


Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[20][20],d[(1<<16)],F[(1<<16)];
main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            cin>>a[i-1][j-1];
        }
    }
    int t=(1<<n)-1;
    for(int i=1;i<=t;i++)
    {
        for(int j=0;j<n;j++)
        {
            for(int k=j+1;k<n;k++)
            {
                if(((1&(i>>j))==1)&&((1&(i>>k))==1))d[i]+=a[j][k];
            }
        }
        //cout<<d[i]<<'\n';
    }
    for(int i=1;i<=t;i++)
    {
        for(int j=i;j>=0;j=((j-1)&i))
        {
            F[i]=max(F[i],F[j]+d[i^j]);
            if(j==0)break;
        }
    }
    cout<<F[t];
}


Measured memory_bytes: 4664
def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    sum = 0
    now = 0
    for a in a_list:
        if now <= a:
            now = a
        else:
            sum += now-a
    print(sum)
if __name__ == '__main__':
    main()

Measured memory_bytes: 32244
// "include" {{{
#include <deque>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <utility>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long 
#define pii pair<int,int> 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

vector<int> t;
vector<int> a;

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int r;
	cin >> r;
	if(r < 1200) cout << "ABC\n";
	else if(r < 2800) cout << "ARC\n";
	else cout << "AGC\n";
	return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
A = [list(map(int , input().split())) for _ in range(N)]

A.sort()
ans=0
x=0
for val , pon in A:
	for p in range(pon):
		ans +=val
		x +=1
		if x>=M:
			print(ans)
			exit()

Measured memory_bytes: 27880
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 200005;
ll A[MAX_N];
map<int, int> L;
map<int, int> R;

int main()
{
	int N;
	cin >> N;
	ll ans = 0;
	rep(i,N)
	{
		cin >> A[i];
		L[i+A[i]]++;
		ans += L[i-A[i]];
	}
	/*
	rep(i,N)
	{
		ans += L[i-A[i]] * R[i-A[i]];
		ans += L[i+A[i]] * R[i+A[i]];
	}
	*/
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 22108
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a[200005], sum, mn = (ll)1e16, cur;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i){
    cin >> a[i];
    sum += a[i];
  }
  for (int i = 0; i < n-1; ++i){
    cur += a[i];
    sum -= a[i];
    mn = min(mn, abs(sum-cur));
  }
  cout << mn << '\n'; 
   
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main() {
  double a, b, c, d, e, f, x, y;
  while(scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) != EOF) {
    y = (a * f - c * d) / (a * e - b * d);
    x = (c - b * y ) / a;
    printf("%.3f %.3f\n", x, y);
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>

using namespace std;

const int NMAX = 100000 + 5;

int N, K;
int a[NMAX];

vector <int> graph[NMAX];

int h[NMAX];

int ans;
void dfs(int node) {
    for (auto it: graph[node]) {
        dfs(it);
        if (h[it] == K - 1)
            ans += (node > 1);
        else
            h[node] = max(h[node], 1 + h[it]);
    }
}

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

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

    ans = (a[1] > 1);
    for (int i = 2; i <= N; ++ i)
        graph[a[i]].push_back(i);
    dfs(1);

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 998244353//1000000007
#define inf 1000000007
#define ll long long
#define ull unsigned long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 200010
#define _DEBUG
template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}
inline int gcd(int a,int b){return b==0?a:gcd(b,a%b);}
inline ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}

int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}
int pow(int a,int b,int c){
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%c;
        a=1LL*a*a%c;b>>=1;
    }
    return ans;
}

int a[N],m;
ll s[N];
ll cal1(int l,int r){
    return s[r]-s[l-1];
}
ll cal(int l,int r,int k){
    if(l==r)return 0;
    ll res=1LL*m*(r-l);
    int x=(l+r)/2,y=(r-l+1)&1;
    if(k==1){
        res+=2LL*cal1(l,x)-a[x]-2LL*cal1(x+1,r)+a[r];
        if(y)res-=2LL*a[x];
    }
    else{
        res+=2LL*cal1(l,x)-a[l]-2LL*cal1(x+1,r)+a[x+1];
        if(y)res-=a[x]+a[x+1];
    }
    //cerr<<l<<" "<<r<<" "<<k<<" "<<res<<"\n";
    return res;
}
int main(){
    //srand(time(NULL)+clock());
    int ca=0,T,k,i,j,n;
    double start=clock();
    scanf("%d%d",&m,&n);
    rep(i,1,n+1)scanf("%d",&a[i]),s[i]=s[i-1]+a[i];
    int r=n;
    ll ans=a[n];
    a[n+1]=m;
    per(i,1,n+1){
        while(r>i&&a[r]-a[r-1]>m-(a[r]-a[i]))r--;
        ll w=2LL*a[i-1]+m-a[r]+cal(i,r,1);
        Max(ans,w);
        w=a[i]+2LL*(m-a[r+1])+cal(i,r,0);
        Max(ans,w);
    }
    int l=1;
    rep(i,1,n+1){
        while(l<i&&a[l+1]-a[l]>m-(a[i]-a[l]))l++;
        ll w=2LL*a[l-1]+m-a[i]+cal(l,i,1);
        Max(ans,w);
        w=a[l]+2LL*(m-a[i+1])+cal(l,i,0);
        Max(ans,w);
    }
    printf("%lld\n",ans);
    cerr<<(1.*clock()-start)/CLOCKS_PER_SEC<<"\n";
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <math.h>

int main(void)
{
	double a, b, C, S, L, h;

	scanf("%lf %lf %lf", &a, &b, &C);

	C = C * 3.141592653589793 / 180;
	h = b * sin(C);
	S = a * h / 2;
	L = a + b + sqrt(a * a + b * b - 2 * a * b * cos(C));

	printf("%lf\n%lf\n%lf\n", S, L, h);

	return 0;
}



Measured memory_bytes: 2100
#include <stdio.h>

int main(void){
	int a[4],b[4],i,j,ht,bl;
	
	while(scanf("%d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&b[0],&b[1],&b[2],&b[3]) != EOF){
		ht=0,bl=0;
		
		// ヒットを探す
		for(i=0;i < 4;i++){
			if(a[i] == b[i]){
				ht++;
				a[i] = b[i] = -1;
			}
		}
		
		//ブローを探す
		for(i=0;i < 4;i++){
			for(j=0;j < 4;j++){
				if(a[i] != -1 && a[i] == b[j]){
					bl++;
				}
			}
		}
		printf("%d %d\n",ht,bl);
	}
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
#include <vector>
using namespace std;

int main() {
	long long n, k;
	cin >> n >> k;
	long long p, r;
	long long ans = 0;
	for (long long i = 1; i <= n; i++) {
		r = n%i;
		p = (n - r) / i;
		ans += p*max((long long)0, i - k);
		ans += max((long long)0, r - k + 1);
	}
	if (k == 0) {
		ans -= n;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <regex>

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

using namespace std;

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

int main() {
    cin >> N;

    int ans = N;
    int max_cnt = 0;
    for (int i = N; i > 0; i--) {
        int cnt = 0;
        int tmp = i;
        while (tmp % 2 == 0) {
            tmp /= 2;
            cnt++;
        }
        if (cnt > max_cnt) {
            ans = i;
            max_cnt = cnt;
        }
    }
    cout << ans << endl;
}



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

long back(long i, long j, long N) {
  long tmp = i - j;
  if (0 <= tmp) return tmp;
  return N + tmp;
}

int main() {
  long N, x;
  cin >> N >> x;
  long ans = 0;
  vector<long> A(N);
  for (long& a : A) {
    cin >> a;
    ans += a;
  }

  vector<long> B = A;
  for (long k = 1; k < N; k++) {
    long tmp = 0;
    for (long i = 0; i < N; i++) {
      B[i] = min(B[i], A[back(i, k, N)]);
      tmp += B[i];
    }
    ans = min(ans, tmp + x * k);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
    int A, B, C, D;
    bool takahashi_turn;

    scanf("%d%d%d%d", &A, &B, &C, &D);
    takahashi_turn = true;
    while(A > 0 && C > 0){
        if(takahashi_turn)
            C -= B;
        else
            A -= D;
        takahashi_turn = !takahashi_turn;
    }
    printf((C <= 0) ? "Yes" : "No");

    return 0;
}


Measured memory_bytes: 1732
def slove():
    import sys
    input = sys.stdin.readline
    x = int(input().rstrip('\n'))
    a = int(input().rstrip('\n'))
    b = int(input().rstrip('\n'))
    t = a + (x - a) // b * b
    print(x - t)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <list>
#include <numeric>
#include <cstdio>
#include <queue>


using namespace std;

int main() {

    int N, M;
    cin >> N >> M ;

    priority_queue<int> L;
    int l;
    for (int i = 0; i < N; i++) {
        scanf("%d", &l);
        L.push(l);
    }

    for (int i = 0; i < M; i++) {
        int max_L = L.top();
        L.pop();
        if (max_L == 0) {
            break;
        }
        max_L /= 2;
        L.push(max_L);
    }

    long long ans = 0;
    while (!L.empty()) {
        ans += L.top();
        L.pop();
    }

    cout << ans << '\n';

}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y; cin>>x>>y;
  bool ret=false;
  for(int turt=0;turt<=100; turt++){
 	int crane = x-turt;
    if(crane < 0) break;
    if(turt*4 + crane*2 == y){
      ret=true;
      break;
    }
  }
  if(ret) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

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

class Program
{
   static void Main(string[] args)
   {
     var list = new List<int[]>();            
            int[] arr = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            int n = arr[0];
            int m = arr[1];
            int minValue = arr[2];
            int min = 9999999;
            for (int i = 1; i <= n; i++) { 
                list.Add(Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray());
            }
            for(int bit = 0; bit < (1 << n); bit++)
            {
                var sumList = new List<int[]>();
                for (int i = 0; i < n; i++)
                {                  
                    if((bit & (1 << i)) > 0)
                    {
                        sumList.Add(list[i]);
                    }
                }
                int sumMinValue = checkSumValue(sumList, minValue);
                if (sumMinValue < min) min = sumMinValue;
            }
            if (min == 9999999) Console.WriteLine(-1);
            else Console.WriteLine(min);
   }
  
   static int checkSumValue(List<int[]> sumList , int minValue)
        {
            int lenList = sumList.Count();
     		if(lenList == 0)return 9999999;
            int lenArr = sumList[0].Length;
            int[] sumArr = new int[lenArr];
            int value = 0;
            for(int i = 0; i < lenList; i++)
            {
                for(int j = 1; j < lenArr; j++)
                {
                    sumArr[j] += sumList[i][j];
                }
                value += sumList[i][0];
            }
            for (int j = 1; j < lenArr; j++)
            {
                if (sumArr[j] < minValue) return 9999999;
            }
            return value;


        }
}

Measured memory_bytes: 20036
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{ min, max };

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

#[allow(dead_code)]
const M: i64 = 1_000_000_007;

fn pow(a: usize, b: usize) -> usize {
    if b == 0 {
        1
    } else if b == 1 {
        a
    } else if b % 2 == 0 {
        pow(a * a, b / 2)
    } else {
        pow(a * a, b / 2) * a
    }
}

fn main() {
    let mut sc = Scanner::new();
    let m: usize = sc.cin();
    let k: usize = sc.cin();

    if m == 0 {
        if k == 0 {
            put!("0 0");
        } else {
            put!("-1");
        }
    } else if m == 1 {
        if k == 0 {
            put!("0 0 1 1");
        } else {
            put!("-1");
        }
    } else {
        let m2 = pow(2, m);
        if k < m2 {
            for i in 0..m2 {
                if i == k { continue }
                print!("{} ", i);
            }
            print!("{} ", k);
            for i in (0..m2).rev() {
                if i == k { continue }
                print!("{} ", i);
            }
            println!("{}", k);

        } else {
            put!("-1");
        }
    }
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 5884
#include<bits/stdc++.h>
#include<iostream>
#define int long long
using namespace std;
int n,m,a[200001],maxv=0;
signed main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>a[i];	
	}
	int sum=0;
	sort(a+1,a+m+1);
	for(int i=1;i<m;i++){
		sum=a[i+1]-a[i];
		if(sum>maxv){
			maxv=sum;
		}
	}
	int ans=0;
	ans=n-a[m]+a[1];
	if(ans>maxv){
		maxv=ans;
	}
	cout<<n-maxv<<endl;
	return 0;
}


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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef struct data{
	int now;
	int cost;

	bool operator<(const data &ri) const{
		return cost < ri.cost;
	}
	bool operator>(const data &ri) const{
		return cost > ri.cost;
	}
}data;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};



int main(){
	int h, w;
	char area[100][100];
	int ans[100][100];
	fn(*ans, 100*100, -1);
	cin >> h >> w;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin >> area[i][j];
		}
	}

	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(area[i][j] == 'c'){
				ans[i][j] = 0;
			}else if(!(j == 0 || ans[i][j-1] == -1)){
				ans[i][j] = ans[i][j-1]+1;
			}
			cout << ans[i][j];
			if(j != w-1) cout << " ";
			else cout << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 3156
H,W=gets.split.map(&:to_i)
S=H.times.map{gets.chomp}
ans=Array.new(H){Array.new(W,"#")}
dir=[[-1,0],[1,0],[0,-1],[0,1],[1,1],[-1,1],[1,-1],[-1,-1]]
H.times do |i|
    W.times do |j|
        next if S[i][j]=="#"
        ans[i][j]=0
        dir.each do |x,y|
            if (0<=j+x && j+x<W) && (0<=i+y && i+y<H)
                ans[i][j]+=1 if S[i+y][j+x]=="#"
            end
        end
    end
end
ans.each do |e|
    puts e.join("")
end

Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] x = new int[N];
        int[] y = new int[N];
        HashMap<Integer, List<Integer>> edges = new HashMap<>();
        for (int i = 0; i < N; i++) {
            x[i] = scan.nextInt();
            y[i] = scan.nextInt()+100005;
            if (!edges.containsKey(x[i])) {
                edges.put(x[i], new ArrayList<>());
            }
            if (!edges.containsKey(y[i])) {
                edges.put(y[i], new ArrayList<>());
            }
            edges.get(x[i]).add(y[i]);
            edges.get(y[i]).add(x[i]);
        }
        boolean[] visited = new boolean[100005 * 2];
        long count = 0;
        for (int i = 0; i < N; i++) {
            if (visited[x[i]]) {
                continue;
            }
            long[] cnt = new long[2];
            cnt[0] = 0;//x
            cnt[1] = 0;//y
            dfs(cnt, visited, edges, x[i]);
            count += cnt[0] * cnt[1];
        }
        System.out.println(count - N);
    }
    public void dfs(long[] cnt, boolean[] visited, HashMap<Integer, List<Integer>> edges, int x) {
        if (visited[x]) {
            return;
        }
        visited[x] = true;
        if (x < 100005) {
            cnt[0] += 1;
        } else {
            cnt[1] += 1;
        }
        for (int y : edges.get(x)) {
            dfs(cnt, visited, edges, y);
        }
    }
}


Measured memory_bytes: 128436
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

class BIT {
  vector<int> num;
public:
  BIT (int n) {
    num.resize(n+1, 0);
  }
  void add(int i, int n) {
    while (i < num.size()) {
      num[i] += n;
      i += i & -i;
    }
  }
  int sum(int i) {
    int res = 0;
    while (i > 0) {
      res += num[i];
      i -= i & -i;
    }
    return res;
  }
  void clear() {
    for (int i = 1; i < num.size(); i++)
      num[i] = 0;
  }
};

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  string s;
  cin >> n >> s >> q;
  vector<BIT> alpha(26, BIT(n));
  rep(i, s.size())
    alpha[s[i]-'a'].add(i+1, 1);
  rep(query, q) {
    int x;
    cin >> x;
    if (x == 1) {
      int i;
      char c;
      cin >> i >> c;
      --i;
      alpha[s[i]-'a'].add(i+1, -1);
      alpha[c-'a'].add(i+1, 1);
      s[i] = c;
    } else {
      int l, r;
      cin >> l >> r;
      --l;
      int res = 0;
      rep(i, 26) {
        if (alpha[i].sum(r)-alpha[i].sum(l))
          res++;
      }
      cout << res << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 53660
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        for (int i = 0; i < 3; i++) {
            if (s.charAt(i) == '1') {
                System.out.print(9);
            } else if (s.charAt(i) == '9') {
                System.out.print(1);
            } else {
                System.out.print(s.charAt(i));
            }
        }
        System.out.println();
        

    }
}

Measured memory_bytes: 21716
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.CookieHandler;
import java.util.*;

public class Main {
    static PrintWriter out = new PrintWriter(System.out);
    static Scanner sc = new Scanner(System.in);
    static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    long[] frac;
    long mod = 1000000000+7;
    public static void main(String[] args) throws IOException {
        Main main = new Main();
        main.solve();
//        System.out.println(main.solve());
    }
    void solve() throws IOException {
        int n = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();
        frac = new long[b+1];
        frac[0] = 1;
        for(int i=1;i<=b;i++) frac[i] = frac[i-1]*i%mod;
        long ans = power(2,n)+mod-1;
        ans %= mod;
        ans -= helper(n-a+1,n)*inv(a)%mod;
        ans -= helper(n-b+1,n)*inv(b)%mod;
        ans = (ans+10*mod)%mod;
        System.out.println(ans);
    }
    // returns the inv of m!
    long inv(int m){
        if(m==0) return 1;
        return power(frac[m],mod-2);
    }
    long power(long base, long p){
        long ans = 1;
        while(p>0){
            if(p%2==1) ans = ans*base%mod;
            base = base*base%mod;
            p /= 2;
        }
        return ans;
    }
    long helper(long from, long to){
        if(from>to){
            long mid = to;
            to = from; from = mid;
        }
        long ans = from;
        for(long i=from+1;i<=to;i++){
            ans = ans*i%mod;
        }
        return ans;
    }

}



Measured memory_bytes: 25300
N=int(input())
S=[input() for i in range(N)]
a,b,ba=0,0,0
ans=0
for s in S:
  if s[0]=="B":
    if s[-1]=="A":
      ba+=1
    else:
      b+=1
  elif s[-1]=="A":
    a+=1
  for l in range(len(s)-1):
    if s[l:l+2]=="AB":
       ans+=1
#print(ans)
#print(a,b,ba)
if ba!=0:
  if a!=0:
    ans+=1
    a-=1
  if b!=0:
    ans+=1
    b-=1
  ans+=ba-1+min(a,b)
else:
  ans+=min(a,b)
print(ans)
#print(a,b,ba)

Measured memory_bytes: 46680
#                           जय श्री राम

import sys; import math; from collections import *
# sys.setrecursionlimit(10**6)

def get_ints(): return map(int, input().split())
def get_list(): return list(get_ints())
def printspx(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")

UGLYMOD = int(1e9+7); SEXYMOD = 998244353; MAXN = int(1e5)

# sys.stdin  = open("input.txt","r"); sys.stdout = open("output.txt","w")

# for _testcases_ in range(int(input())):
n =  int(input())
li = get_list()
d = Counter(li)
s = sum(li)
q = int(input())
for _ in range(q):
    b, c = get_ints()
    item = 0
    if b in d:
        item = d[b]
        del d[b]
    s -= item * b
    if c in d:
        d[c] += item
    else:
        d[c] = item
    s += item * c
    print(s)




'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS MINE @luctivud ( UDIT GUPTA )
Link may be copy-pasted here if it's taken from other source.
DO NOT PLAGIARISE.
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''

Measured memory_bytes: 91384
#include <stdio.h>

#include <algorithm>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long llong;

struct State {
  State() {
    pos[0] = pos[1] = pos[2] = 0;
  }
  void set_bit(int n) {
    bits |= 1U << n;
  }
  void reset_bit(int n) {
    bits &= ~(1U << n);
  }
  bool is_set(int n) {
    return bits & (1U << n);
  }
  unsigned int bits = 0;
  int n = 0;
  int pos[3];
};

static int ord(char x) {
  switch (x) {
    case 'R':
      return 0;
    case 'G':
      return 1;
    case 'B':
      return 2;
    default:
      break;
  }
  return 0;
}

vector<int> reverse_num[3];

static llong recurse_last(const string& s, int start, State& state) {
  llong sum = 0;

  int lookfor = 0;  // R
  if (state.bits == 5)
    lookfor = 1;  // G
  else if (state.bits == 3)
    lookfor = 2;  // B

  int ret = reverse_num[lookfor][start];

  int illegal_pos = state.pos[1] * 2 - state.pos[0];
  if (illegal_pos < s.size() && ord(s[illegal_pos]) == lookfor)
    --ret;

  return ret;
}

static llong recurse_sub(const string& s, int start, State& state) {
  llong sum = 0;
  for (int i = start; i < s.size() - 1; ++i) {
    int o = ord(s[i]);
    if (state.is_set(o))
      continue;
    state.set_bit(o);
    state.pos[state.n] = i;
    ++state.n;
    sum += recurse_last(s, i + 1, state);
    --state.n;
    state.reset_bit(o);
  }
  return sum;
}

static void recurse_top(const string& s, llong& sum) {
  for (int i = 0; i < s.size() - 2; ++i) {
    State state;
    state.set_bit(ord(s[i]));
    state.pos[0] = i;
    state.n = 1;
    sum += recurse_sub(s, i + 1, state);
  }
}

void DRGBTriplets(std::istream& in, std::ostream& out) {
  int n;
  string s;
  in >> n;
  in >> s;

  int count[3];
  count[0] = count[1] = count[2] = 0;
  for (int i = 0; i < s.size(); ++i) {
    ++count[ord(s[s.size() - 1 - i])];
    reverse_num[0].push_back(count[0]);
    reverse_num[1].push_back(count[1]);
    reverse_num[2].push_back(count[2]);
  }
  reverse(reverse_num[0].begin(), reverse_num[0].end());
  reverse(reverse_num[1].begin(), reverse_num[1].end());
  reverse(reverse_num[2].begin(), reverse_num[2].end());

  llong sum = 0;
  recurse_top(s, sum);
  out << sum << endl;
}

int main(int argc, char** argv) { DRGBTriplets(cin, cout); return 0; }


Measured memory_bytes: 3232
#include <stdio.h>

#define N (int)1e6
int p[N];

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

  for (i = 2; i < N; ++i) p[i] = 1;
  for (i = 2; i * i < N; ++i) {
    if (!p[i]) continue;
    for (j = i + i; j < N; j += i) {
      p[j] = 0;
    }
  }

  for (i = 2; i < N; ++i) p[i] += p[i - 1];

  while (~scanf("%d", &n)) printf("%d\n", p[n]);

  return 0;
}

Measured memory_bytes: 4500
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>
 
int main() {
  int n, len;
  int a[100];
  int nums[100] = {};
  std::cin >> n;
  for (int ni = 0; ni < n; ++ni) {
    std::cin >> a[ni];
    ++nums[a[ni]];
  }
  len = *std::max_element(a, a + n);
  for (int x = 0; x <= len; ++x) {
    --nums[std::max(len - x, x)];
  }
  if (*std::min_element(nums, nums + 100) < 0 or
      *std::max_element(nums, nums + (len + 1) / 2 + 1) > 0) {
    std::cout << "Impossible" << std::endl;
    return 0;
  }
  std::cout << "Possible" << std::endl;
  return 0;
}

Measured memory_bytes: 256
// Date: 2020-03-13

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

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define FIO ios::sync_with_stdio(false);cin.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int dp[N], h[N], n, k;

int main() {
    FIO;
    cin >> n >> k;
    rep(i, 1, n) cin >> h[i];
    mem(dp, 0x3f);
    dp[1] = 0;
    rep(i, 2, n) {
        int up = min(k, i-1);
        rep(j, 1, up) chkmin(dp[i], dp[i-j] + abs(h[i]-h[i-j]));
    }
    cout << dp[n];

    return 0;
}

Measured memory_bytes: 1152
fun main(args:Array<String>?): Unit {
    val (n, t, h, l) = readLine()!!.trim().split(' ').map(String::toInt)
    val vendor = Vendor(t, h, l)
    val members = List(n){
        val (ten, hundred) = readLine()!!.trim().split(' ').map(String::toInt)
        Member(it, ten, hundred)
    }
    tailrec fun sub(vendor: Vendor, index: Int): Int {
        if (members[index].hasNoCoin()) return index
        val coins =  vendor.insert(members[index].putCoin())
        return when (coins) {
            null -> index
            else -> {
                coins.forEach { (i, c) -> members[index].receiveCoin(i, c) }
                sub(vendor, (index + 1) % n)
            }
        }
    }
    println(sub(vendor, 0) + 1)

}
enum class Coin(val value: Int){
    Ten(10), Hundred(100)
}
class Vendor(private var ten: Int, private var hundred: Int, private val tenLimit: Int) {
    private var account: Int = 0
    fun insert(coin: Coin): Collection<Pair<Int, Coin>>? {
        account += coin.value
        when(coin){
            Coin.Ten -> ++ten
            Coin.Hundred -> ++hundred
        }
        return when{
            ten > tenLimit -> null
            account >= 90 -> {
                val coins = pay(account - 90)
                account = 0
                coins
            }
            else -> listOf()
        }
    }
    private fun pay(value: Int): Collection<Pair<Int, Coin>>? {
        return if (ten * 10 >= value) {
            ten -= value / 10
            listOf(Pair(value / 10, Coin.Ten))
        }else if (ten * 10 + hundred * 100 >= value && ten * 10 >= value % 100) {
            val h = (value - ten * 10 + 99) / 100
            hundred -= h
            ten -= (value - 100 * h) / 10
            listOf(Pair(h, Coin.Hundred), Pair((value - 100 * h) / 10, Coin.Ten))
        }else {
            null
        }
    }
}
class Member(val id: Int, private var ten: Int, private var hundred: Int) {
    fun putCoin(): Coin {
        return if (ten > 0) {
            --ten
            Coin.Ten
        }else {
            --hundred
            Coin.Hundred
        }
    }
    fun hasNoCoin(): Boolean = ten == 0 && hundred == 0
    fun receiveCoin(count: Int, coin: Coin): Unit {
        when(coin){
            Coin.Ten -> ten += count
            Coin.Hundred -> hundred += count
        }
    }
}


Measured memory_bytes: 34192
#include<bits/stdc++.h>
#define MAX_N 200005
using namespace std;
typedef long long ll;
const int DAT_SIZE=(1<<19)-1;
 
ll data[DAT_SIZE],datb[DAT_SIZE];
 
void add(int a,int b,int x,int k=0,int l=0,int r=(1<<18)){
  if(a<=l&&r<=b)data[k]+=x;
  else if(l<b&&a<r){
    datb[k]+=(min(b,r)-max(a,l))*x;
    add(a,b,x,k*2+1,l,(l+r)/2);
    add(a,b,x,k*2+2,(l+r)/2,r);
  }
}
 
ll sum(int a,int b,int k=0,int l=0,int r=(1<<18)){
  if(b<=l||r<=a)return 0;
  else if(a<=l&&r<=b)return data[k]*(r-l)+datb[k];
  else{
    ll res=(min(b,r)-max(a,l))*data[k];
    res+=sum(a,b,k*2+1,l,(l+r)/2);
    res+=sum(a,b,k*2+2,(l+r)/2,r);
    return res;
  }
}
 
ll Get(int x){
  return sum(x,x+1);
}
 
 
int n,q,A[MAX_N];
ll s,t;
ll B[MAX_N],ans=0;
 
 
ll f(ll x){
  if(x<0)return x*s;
  return x*t;
}
 
int main(){  
  cin>>n>>q>>s>>t;
  for(int i=0;i<=n;i++){
    cin>>A[i];
    add(i,i+1,A[i]);
  }
  for(int i=0;i<n;i++){
    ll cal=A[i]-A[i+1];
    B[i]=f(cal);
    ans+=B[i];
  }
 
   
  /*  for(int j=0;j<n;j++){
    cout<<B[j]<<' ';
  }
  cout<<endl<<endl;*/
 
   
  int l,r,x;
  for(int i=0;i<q;i++){
    cin>>l>>r>>x;
    r++;
    ans-=B[l-1];
    ans-=B[r-1];
    add(l,r,x);
 
     
    B[l-1]=f(Get(l-1)-Get(l));
     
    B[r-1]=f( Get(r-1) - Get(r) );
    if(r-1==n)B[r-1]=0;
    ans+=B[l-1]+B[r-1];
     
    /*    for(int j=0;j<n;j++){
      cout<<B[j]<<' ';
    }
    cout<<endl<<endl;*/
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 10172
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n,m;cin>>n>>m;
  ll ans = lcm((ll)n,(ll)m);
  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int x,y,m,n;
	cin>>x>>y;
	
	if(y%2!=0 || y-4*x>0 || 2*x-y>0)
{
	cout<<"No";
	return 0;
}
m=(4*x-y)/2;
n=x-m;
if((2*m+4*n)==y)
cout<<"Yes";
else
cout<<"No";
}

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

int main(){
    double n;
    cin>>n;
    double maxv=0;
    for (double i = 0.000001; i < n; i+=0.000001)
    {
        /* code */
        maxv=max(maxv,i*i*(n-(i+i)));
    }
    cout<<fixed<<setprecision(12)<<maxv<<endl;
    }


Measured memory_bytes: 256
#include "iostream"
using namespace std;
int main() {
	int n, k, x, y, ans;
	ans = 0;
	cin >> n >> k >> x >> y;
	for (int i = 1; i <= n; i++) {
		if (i <= k)ans += x;
		else ans += y;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	long N,L[87],i;
	L[0] = 2;
	L[1] = 1;
	scanf("%ld",&N);
	for(i=2;i<=N;i++){
		L[i] = L[i-1] + L[i-2];
	}
	printf("%ld\n",L[N]);
	return 0;
}

Measured memory_bytes: 128
pref_num, city_num = map(int, input().split())
py = sorted([list(map(int, input().split())) + [i] for i in range(city_num)], key=lambda py: py[1])

city_num_in_prefs = [0 for _ in range(pref_num)]

city_nums = []
for pref, year, i in py:
    city_num_in_prefs[pref-1] += 1
    city_num = "{:06}{:06}".format(pref, city_num_in_prefs[pref-1])
    city_nums.append([city_num, i])

city_nums.sort(key=lambda x: x[1])
for num, index in city_nums:
    print(num)


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

inline int read() { 
	int s = 0, t = 1; char c = getchar();
	while( !isdigit(c) ) { if( c == '-' ) t = -1; c = getchar(); }
	while( isdigit(c) ) s = s * 10 + c - 48, c = getchar();
	return s * t;
} 

const int N = 1e5+5;
vector<int> S[N];
int n, x, y, rt, ans = 0, h[N], f[N], g[N]; 
//f xuan
//g erzi buxuan
inline void dfs(int x,int fa=0) { 
	for(auto i : S[x]) if( i != fa ) { 
		dfs(i,x);
		f[x] |= f[i];
		if( !f[i] ) g[x]++;
	}
	if( g[x] > 1 ) ans += g[x] - 1, f[x] = 1;
}

inline void Dfs(int x,int fa=0) { 
	for(auto i : S[x]) if( i != fa ) { 
		h[i] = h[x] + 1, Dfs(i,x);
	}
	if( h[x] > h[rt] ) rt = x;
}

int main() {
	n = read();
	rep(i,0,n-2) x = read() + 1, y = read() + 1, S[x].push_back(y), S[y].push_back(x);
	Dfs(1);
	dfs(rt);
	cout<<ans + 1<<endl;
	return 0;
}


Measured memory_bytes: 9984
def main():
    N, M = map(int, input().split())
    li = list(map(int, input().split()))
    s = 0
    for i in range(M):
      s += li[i]

    if s <= N:
      print(N-s)
    else:
      print('-1')

if __name__ == '__main__':
  main()


Measured memory_bytes: 10060
X, Y = map(int, input().split())


def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


if (2*Y-X)%3 == 0 and (2*X-Y)%3 == 0:
    a = (2*Y-X)//3
    b = (2*X-Y)//3
    
    mod = 10**9+7 #出力の制限
    N = a+b
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル

    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )
        
    ans = cmb(a+b, a, mod)

else:
    ans = 0
    
print(ans)

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

using namespace std;
 
const int MOD=1e9+7;


//const int MOD=998244353;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    string s;
    cin>>s;
    
    int ans=0;
    
    for(int i=0; i<3; i++){
        int j=i;
        while(j<3 && s[j]=='R') j++;
        ans=max(ans,j-i);
    }
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 3604
def main():
     s = list(input())
     count = int((len(s)*(len(s)-1))/2+1)
     dic = {}
     for i in range(len(s)):
         try:
             dic[s[i]].append(i)
         except Exception:
             dic[s[i]] = [i]

     for j in dic.values():
         count-=int((len(j)*(len(j)-1))/2)
     print(count)


if __name__=="__main__":
    main()

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

vector<pair<int, int>> pos;
int m;
vector<pair<int, int>> table;

int dfs(bitset<16> s) {
  int ans = 0;
  if (s.count() == m) {
    for (int i = 0; i < table.size(); ++i) {
      for (int j = i + 1; j < table.size(); ++j) {
        if (!(table[i].first * table[j].second - table[i].second * table[j].first)) {
          ans++;
        }
      }
    }
    return ans;
  } else {
    int i, j;
    for (i = 0; i < m; ++i) {
      if (!s[i]) {
        break;
      }
    }
    for (j = i+1; j < m; ++j) {
      if (!s[j]) {
        table.push_back(pair<int, int>{pos[i].first - pos[j].first, pos[i].second - pos[j].second});
        ans = max(dfs(s | bitset<16>(1 << i) | bitset<16>(1 << j)), ans);
        table.pop_back();
      }
    }
    return ans;
  }
}

int main() {
  cin >> m;
  pos = vector<pair<int, int>>(m);
  for (int i = 0; i < m; ++i) {
    cin >> pos[i].first >> pos[i].second;
  }
  bitset<16> s;
  cout << dfs(s) << endl;
  return 0;
}


Measured memory_bytes: 3124
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int P[100001];
int kotae[100001];
inline int Find(int A) {
	if (P[A] < 0) return A;
	return P[A] = Find(P[A]);
}

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int dm = 1 << 20;
char dn[dm], * di = dn;
inline void putint(int X) {
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	int N = getint(), M = getint(), K = getint();

	rep1(i, N) P[i] = -1;

	rep(i, M) {
		int A = getint(), B = getint();
		int a = Find(A);
		int b = Find(B);
		if (a != b) {
			if (P[a] > P[b]) swap(a, b);
			P[a] += P[b];
			P[b] = a;
		}
		kotae[A]--;
		kotae[B]--;
	}
	rep(i, K) {
		int A = getint(), B = getint();
		int a = Find(A);
		int b = Find(B);
		if (a == b) {
			kotae[A]--;
			kotae[B]--;
		}
	}

	rep1(i, N) {
		int majikotae = kotae[i] - P[Find(i)] - 1;
		if (majikotae) putint(kotae[i] - P[Find(i)] - 1);
		else {
			*di++ = '0';
			*di++ = '\n';
		}
	}
	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 2176
//Let's join Kaede Takagaki Fan Club !!
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}

int main(){
	ios::sync_with_stdio(false);
	string s; cin >> s;
	for(auto &a:s) if(a == '?') a = 'D';
	cout << s << endl;
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,s,cnt=0;
    cin>>k>>s;
    for(int i=0;i<=k;i++)
    {
        for(int j=0;j<=k;j++)
        {
            if((i+j)<=s && (s-(i+j)<=k))
                cnt++;
        }
    }
    cout<<cnt<<endl;
}


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

int check(char [],int);

int main (void){

	int i,count=0,counter=0,pod;
	char get,search[100];

	for(i=0;;i++){
		get=getchar();
		if(get=='\n'){
			search[i]='\0';
			break;
		}
		search[i]=get;
		count++;

	}
	while(1){
		pod=check(search,count);
		if(pod==-1)
			break;
		counter+=pod;
	}
	printf("%d\n",counter);
	
	return 0;
}
	
int check(char search[],int count){

	int i,j,counter=0,len,len2,flag=0;
	char word[1000],out[100]="END_OF_TEXT";
	scanf("%s",word);
	if(strcmp(out,word)==0){
		return -1;
	}
	len=strlen(word);
	len2=strlen(search);
	if(len!=len2)
		return 0;
	for(i=0;i<len;i++){
		for(j=0;j<count;j++){
			if(word[i]!=search[j]&&word[i]+32!=search[j]&&word[i]-32!=search[j]){
				i-=j;
				flag=1;
				break;
			}
			else i++;
			if(j==count-1)
				counter++;
		}
	if(flag==1)
		break;
	}
	return counter;
}

Measured memory_bytes: 552
w=gets.chomp
warr=[]
narr=[]
w.chars do |ch|
  if warr.include?(ch)
    narr[warr.index(ch)]+=1
  else
    warr.push(ch)
    narr.push(1)
  end
end
puts narr.all?{|v| v.even?} ? "Yes":"No"


Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
#define int long long
int partition(int* A,int p,int r){
  int x=A[r];
  int i=p-1;
  for(int j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1],A[r]);
  return i+1;
}
signed main(){
  int n;
  cin>>n;
  int A[n];
  for(int i=0;i<n;i++) cin>>A[i];
  int k=partition(A,0,n-1);
  for(int i=0;i<n;i++){
    if(i) cout<<" ";
    if(i==k) cout<<"[";
    cout<<A[i];
    if(i==k) cout<<"]";
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 3848
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        getAns(a, n);

    }
    static void getAns (int[] a, int n)
    {
        var max = a[0];
        var count = 1;
        for (int i = 1; i < n; i++)
        {
            if (a[i]  >= max) { count++;  max = a[i]; }
        }
        Console.WriteLine(count);
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(9);
    
    int N;
    cin >> N;
    int t[100],v[100];
    int sum = 0;
    for(int i=0; i<N; i++){
        cin >> t[i];
        sum += t[i];
    }
    for(int i=0; i<N; i++) cin >> v[i];
    int all[20001];
    for(int i=0; i<=sum; i++) all[i] = min(i, sum-i);
    int now = 0;
    for(int i=0; i<N; i++){
        for(int j=0; j<=now; j++) all[j] = min(all[j], v[i]+now-j);
        for(int j=now; j<=now+t[i]; j++) all[j] = min(all[j], v[i]);
        now += t[i];
        for(int j=now; j<=sum; j++) all[j] = min(all[j], j-now+v[i]);
    }

    //for(int i=0; i<=sum; i++) cout << i << " " << all[i] << endl;
    double ans = 0;
    int tmp = 0;
    now = 0;
    for(int i=0; i<sum; i++){
        ans += (double)(all[i] + all[i+1]) / 2;
        if(all[i] == all[i+1] && all[i] < v[now]) ans += 0.25;
        tmp++;
        if(tmp == t[now]){
            tmp = 0;
            now++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384