akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.Map;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        NotsoDiverse solver = new NotsoDiverse();
        solver.solve(1, in, out);
        out.close();
    }

    static class NotsoDiverse {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            Map<Integer, Integer> map = new HashMap<>();
            for (int i = 0; i < N; i++) {
                int x = in.nextInt();
                map.compute(x, (k, v) -> v == null ? 1 : v + 1);
            }

            int ans = 0;

            TreeSet<int[]> set = new TreeSet<>((a1, a2) -> {
                if (a1[1] == a2[1]) {
                    return a1[0] - a2[0];
                }
                return a1[1] - a2[1];
            });
            for (int k : map.keySet()) {
                set.add(new int[]{k, map.get(k)});
            }

            while (set.size() > K) {
                ans += set.pollFirst()[1];
            }

            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

template<typename T> struct SegTree {
  int sz;
  T init;
  function<T(T, T)> f;
  vector<T> dat;
  SegTree() {}
  SegTree(int n, T init = INT_MAX, function<T(T, T)> f = [](T a, T b) { return min(a, b); })
      : dat(set_dat(n), init), init(init), f(f) {}

  int set_dat(int n) {
    sz = 1;
    while (sz < n) sz <<= 1;
    return 2 * sz - 1;
  }
  void update(int k, T x) {
    k += sz - 1;
    dat[k] = x;
    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = f(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }
  T query(int s, int t) { return query(s, t, 0, 0, sz); }
  T query(int s, int t, int k, int l, int r) {
    if (r <= s || t <= l) return init;
    if (s <= l && r <= t) return dat[k];

    int m = (l + r) / 2;
    T vl = query(s, t, k * 2 + 1, l, m);
    T vr = query(s, t, k * 2 + 2, m, r);
    return f(vl, vr);
  }
};

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

  int n, q; cin >> n >> q;
  SegTree<int> st(n);
  for (int i = 0; i < q; ++i) {
    int com, x, y; cin >> com >> x >> y;
    if (com) {
      cout << st.query(x, y + 1) << endl;
    } else {
      st.update(x, y);
    }
  }
  return 0;
}



Measured memory_bytes: 3900
#include <algorithm>
#include <iostream>
#include <vector>
#include <set>
using namespace std;
int MSB1(long long x) { int d = 0; while ((1LL << d) <= x) d++; return d; }

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (auto &ai: a) cin >> ai;
    multiset<int> se(a.begin(), a.end());
    int cnt = 0;
    while (!se.empty()) {
        int cur = *se.rbegin(); se.erase(--se.end());
        int rem = (1 << MSB1(cur)) - cur;
        auto it = se.find(rem);
        if (it == se.end()) continue;
        cnt++, se.erase(it);
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 10368
#include<bits/stdc++.h>
using namespace std;
const int M = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<vector<int>> edge(n);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        edge[u].push_back(v);
    }
    vector<double> dp(n);
    vector<double> mj(n, -1);
    for (int i = n - 2; i >= 0; --i) {
        double ma = -1;
        for (auto& j : edge[i]) {
            if (ma < dp[j]) {
                ma = dp[j];
                mj[i] = j;
            }
            dp[i] += dp[j] + 1;
        }
        if (edge[i].size() == 1) mj[i] = -1;
        dp[i] /= edge[i].size();
    }
    double ans = dp[0];
    for (int i = 0; i < n; ++i) {
        if (mj[i] == -1) continue;

        vector<double> ddp = dp;
        for (int j = i; j >= 0; --j) {
            ddp[j] = 0;
            for (auto& k : edge[j]) {
                if (j == i && mj[i] == k) continue;
                ddp[j] += ddp[k] + 1;
            }
            if (i == j) ddp[j] /= (edge[j].size() - 1);
            else ddp[j] /= edge[j].size();
        }
        ans = min(ans, ddp[0]);
    }
    cout << setprecision(12) << ans << '\n';

    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll p=pow(10,9)+7;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      
    x = x % p;  
   while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 

ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,j,i,k,m1,y1,m2,y2;
    string s,t;
    cin>>s>>t;
    cin>>i>>j;
    string u;
    cin>>u;
    if(u==s)
    i--;
    else
    j--;
    cout<<i<<" "<<j;
    

    return 0;
    
}
    


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

const int mod=1e9+7;
const int MAX=1000000;
int fac[MAX],finv[MAX],inv[MAX];

bool maketable(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}

int COM(int n,int k){
  	if(n<k||n<0||k<0){
      return 0;
    }
  	return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

signed main(){
    maketable();
    int X,Y;
    int ans=0;
    cin >>X>>Y;
    if((X+Y)%3==0){
        int all=(X+Y)/3;
        int r=(all+X-Y)/2;
        ans = COM(all,r);
    }
    cout <<ans <<endl;
}


Measured memory_bytes: 23680
#include<iostream>
#include<string>
#define COL 8
#define ROW 8
int field[COL][ROW];
using namespace std;

void Release(int y, int x){
	int i, j;
	if(field[y][x] == 0) return;
	field[y][x] = 0;
	for(i=1;i<=3;i++) if(x-i >= 0)  Release(y, x-i);
	for(i=1;i<=3;i++) if(x+i < ROW) Release(y, x+i);
	for(i=1;i<=3;i++) if(y-i >= 0)  Release(y-i, x);
	for(i=1;i<=3;i++) if(y+i < COL) Release(y+i, x);
	return;
}

int main(){
	string str;
	int n,i,j, loop, x, y;
	cin>>n;
	for(loop=0;loop<n;loop++){
		for(i=0;i<COL;i++){
			cin>>str;
			for(j=0;j<ROW;j++){
				field[i][j] = str[j] - '0';
			}
		}
		cin>>x>>y;
		Release(y-1, x-1);
		cout<<"Data "<<loop+1<<":\n";
		for(i=0;i<COL;i++){
			for(j=0;j<ROW;j++){
				cout<<field[i][j];
			}
			cout<<endl;
		}
	}
	return 0;
}

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

double dis[10][10];

int main(){
	int N,D;	cin>>N>>D;
	double data[N][D];
	for(int i=0;i<N;i++){
		for(int j=0;j<D;j++){
			cin>>data[i][j];
		}
	}

	int ans=0;
	for(int i=0;i<N-1;i++){
		for(int j=i+1;j<N;j++){
			double sum=0;
			int DSum=0;
			for(int k=0;k<D;k++){
				sum += pow(data[i][k]-data[j][k], 2);
			}
			DSum=sqrt(sum);
			if(sqrt(sum)==DSum){

				ans++;
			}

		}
	}

	cout<<ans<<endl;




	return 0;
}


Measured memory_bytes: 256
def main():
    N, S = open(0).read().split()
    pre = S.count("E")
    cur = pre
    for Si in S:
        if pre < cur:
            cur = pre
        if Si == "E":
            pre -= 1
        else:
            pre += 1
    print(pre if pre < cur else cur)
    return


main()


Measured memory_bytes: 3572
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    ll n=in(),m=in();
    for(ll i=0;i<m;++i)n-=in();
    cout<<max(n,-1ll)<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>

template<class H> void print(H&& head){std::cout << head << std::endl;}

int main()
{
  std::string S, T;
  std::cin >> S >> T;

  int cnt = 0LL;
  for (int i = 0; i < 3; i++) {
    if (S[i] == T[i]) cnt++;
  }

  print(cnt);

  return 0;
}


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

int main()
{
  int n, r;
  while( cin >> n >> r, n && r ) {
    int card[51];
    for(int i=n-1; i>=0; i--) card[i] = n-i-1;

    while( r-- ) {
      int p, c;
      int tmp[51];
      cin >> p >> c;
      for(int i=0; i<n; i++) tmp[i] = card[i];

      for(int i=0; i<c; i++) card[i] = tmp[i+p-1];
      for(int i=c; i<c+p-1; i++) card[i] = tmp[i-c];
    }

    cout << card[0] + 1  << endl;
  }
}

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

int main() {
	int in1, in2;
	cin >> in1 >> in2;

	int result;
	int num[5] = {};
	int checkNum = in1;
	int count = 0;

	if (in1 >= 10000 && in1 <= 99999 && in2 >= 10000 && in2 <= 99999 && in1 <= in2) {

		for (int i = 0; i <= (in2 - in1); i++) {
			checkNum = in1 + i;
			for (int j = 0; j < 5; j++) {
				num[j] = checkNum % 10 ;
				checkNum = checkNum / 10;
			}
			if (num[0] == num[4] && num[1] == num[3] ) {
				count++;
			}
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int add(int a[],int size);

int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    int arr[m];
    for(int i=0;i<m;i++)
    {
        scanf("%d",&arr[i]);
    }
    int sum = add(arr,m);
    int ans = n-sum;
    if(ans<0)
    {
        printf("-1");
    }
    else
    {
        printf("%d",ans);
    }
}

int add(int a[],int size)
{
    int s = 0;
    for(int i=0;i<size;i++)
    {
        s+=a[i];
    }
    return s;
}


Measured memory_bytes: 1756
#include<iostream>
#include<cstdio>
#define MN 1000
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
char c[MN+5][MN+5];
int n,m,A,B;
int main()
{
	n=read();m=read();A=read();B=read();
	if(A*2+B*2>n*m) return 0*puts("NO");
	for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) c[i][j]='.';
	if(n&1) for(int j=2;j<=m&&A;j+=2) c[1][j-1]='<',c[1][j]='>',--A;
	if(m&1) for(int j=2;j<=n&&B;j+=2) c[j-1][m]='^',c[j][m]='v',--B;
	for(int j=m;j>1;--j) for(int i=1;i<=n;++i)
		if(c[i][j]=='.'&&c[i][j-1]=='.'&&A) --A,c[i][j]='>',c[i][j-1]='<';
	for(int i=1;i<n;++i) for(int j=1;j<=m&&B;++j)
		if(c[i][j]=='.'&&c[i+1][j]=='.') --B,c[i][j]='^',c[i+1][j]='v';
	if(B||A) return 0*puts("NO");
	puts("YES");
	for(int i=1;i<=n;++i) puts(c[i]+1);
	return 0;
}

Measured memory_bytes: 2176
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


N = int(input())
A = list(map(int, input().split()))
M = 10**6 + 5
cnt = [0] * M

for a in A:
    if cnt[a] != 0:
        cnt[a] = 2
        continue
    for b in range(a, M, a):
        cnt[b] += 1

ans = 0

for a in A:
    if cnt[a] == 1:
        ans += 1

print(ans)





Measured memory_bytes: 31372
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <sstream>

using namespace std;

long long int c[150][150];

int main(){
	
	int n;
	
	cin >> n;
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> c[i][j];
		}
	}
	
	long long int ans = 0;
	
	for(int i = 0; i < n; i++){
		for(int j = i; j < n; j++){
			ans += min(c[i][j], c[j][i]);
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast") 
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
# define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int par[N];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n ,k ;
		cin >> n >> k ;
		fn1{
			cin >> ar[i];
			par[i] = ar[i];
		}
		map<int,int>vis;
		int last = -1,s=1;
		int i = 1,cnt =0;
		vector<int>v;
		v.pb(1);
		while(1){
			i = par[i];
			++cnt;
			vis[i]++;
			v.pb(i);
			if(vis[i]==2){
				last = i;
				break;
			}
		}
		int pos =0;
		// for(auto i : v)cout << i << " ";
		// 	cout <<'\n';
		if(v.size()-1>k){
			return cout << v[k],0;
		}
		while(pos < v.size() && v[pos]!=last)pos++;
		k-=pos;
		int sz = 0,jj=-1;
		i =pos+1;
		sz = 1;
		while(i < v.size()  &&  last!=v[i]){
			i++;
			sz++;
		}
		// trace(sz);
		k%=(sz);
		cout << v[pos+k];

	}
	return 0;
}

Measured memory_bytes: 20092
import sys

H, W = map(int, sys.stdin.readline().strip().split())

grid = []
for _ in range(H):
    grid.append(list(sys.stdin.readline().strip()))

count = 0
for i in range(H):
    for j in range(W):
        if grid[i][j] == "#":
            count += 1

if count == H + W - 1:
    print("Possible")
else:
    print("Impossible")

Measured memory_bytes: 38384
#include <cstdio>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

int main() {
  int n;
  cin >> n;
  std::vector<int> positions(n+1);
  for(int i=0; i<n; ++i) {
    int x;
    cin >> x;
    positions[x] = i;
  }

  int longest=0;
  for(int x=1; x<=n; ) {
    int pos = positions[x];
    int i=1;
    for(; i+x<=n; ++i) {
      if(pos > positions[x+i]) break;
      pos = positions[x+i];
    }
    longest = max(longest, i);
    x += i;
  }

  int ans = n-longest;

  cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
       
        Scanner sc = new Scanner(System.in);
        
        List<Integer> list = new ArrayList<>();
        
      
        int count = 0;
        
         for(int i=0; i<3; i++) list.add(sc.nextInt());
            
         for(int i=list.get(0); i <= list.get(1); i++){
                     
             if(list.get(2) % i == 0) count ++;
             
         }  
          
         System.out.println(count);
       
    }}
       


   



Measured memory_bytes: 26264
import sys
input = sys.stdin.readline
 
H, W = map(int, input().split())
mark_matrix = [[True]*(W+2)]
mark_matrix.extend([[True]+[x!='.' for x in input()] for _ in range(H)])
mark_matrix[H].append(True)
mark_matrix.append([True]*(W+2))

queue = []
for i in range(1,H+1):
  for j in range(1,W+1):
    if mark_matrix[i][j]:
      queue.append((i,j))
 
max_value = 0
while(True):
  if len(queue) == 0:
    break
  
  new_queue = []
  for i,j in queue:
  
    if not mark_matrix[i-1][j]:
      mark_matrix[i-1][j] = True
      new_queue.append((i-1,j))
    if not mark_matrix[i+1][j]:
      mark_matrix[i+1][j] = True
      new_queue.append((i+1,j))
    if not mark_matrix[i][j-1]:
      mark_matrix[i][j-1] = True
      new_queue.append((i,j-1))
    if not mark_matrix[i][j+1]:
      mark_matrix[i][j+1] = True
      new_queue.append((i,j+1))
 
  if len(new_queue) == 0:
    break
  else:
    queue = new_queue
    max_value += 1
  
print(max_value)

Measured memory_bytes: 106032
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a,c) memset(a,c,sizeof(a))

#define DEBUG(x) cout<<"#x"<<": "<<x<<endl

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX/3;
const ll MOD = 1000000007;
const double EPS = 1e-14;
const int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};

int main(){
    while(true){
	int n;
	cin >> n;
	if(n==0) break;
	int ans = 0;
	REP(i,n/4){
	    int temp;
	    cin >> temp;
	    ans += temp;
	}
	cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n>=64){
            System.out.println(64);
        } else if(n>=32){
            System.out.println(32);
        } else if(n>=16){
            System.out.println(16);
        } else if(n>=8){
            System.out.println(8);
        } else if(n>=4){
            System.out.println(4);
        } else if(n>=2){
            System.out.println(2);
        } else {
            System.out.println(1);
        }
    }
}

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

int main(){

  int n;
  cin>>n;
  int a[n];
  REP(i,n){
    cin>>a[i];
  }
  sort(a,a+n);
  
  int now;
  now = a[0];
  int k = 1;
  int ans =0;
  for(int i=1;i<n;i++){
    if(now == a[i]){
      k++;
    }else{
      ans += k%2;
      now = a[i];
      k = 1;
    }
  }
  ans += k%2;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(){
    double r;
    double S=0.0,L=0.0,pi=3.14159265359;
    scanf("%lf",&r);
    S=r*r*pi;
    L=2*r*pi;
    printf("%.6lf %.6lf\n",S,L);
    return 0;
}

Measured memory_bytes: 2656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int n, k;
  cin >> n >> k;
  vi a(n);
  rep(i, n) {
    cin >> a[i];
  }

  vector<bool> dp(k+1);

  rep(i, k+1) {
    rep(j, n) {
      if (i - a[j] >= 0 && dp[i-a[j]] == 0) {
        dp[i] = 1;
      }
    }
  }

  if (dp[k]) puts("First");
  else puts("Second");
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <queue>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct TEMP_OMAZINAI_ { TEMP_OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } TEMP__omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void TEMP_INPUT_IMPL_() {};
template <class T, class... Args> void TEMP_INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; TEMP_INPUT_IMPL_(args...); }
void TEMP_OUTPUT_IMPL_() {};
template <class T, class... Args> void TEMP_OUTPUT_IMPL_(T dest, Args... args) { cout << dest << (sizeof...(Args) ? " " : ""); TEMP_OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; TEMP_INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define unique_v(v) v.erase(std::unique(v.begin(), v.end()), v.end()) //必ずソート後に実行
#define out(...) (TEMP_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
#define set_fix(x) ((std::cerr<<std::fixed<<std::setprecision(x)),(std::cout<<std::fixed<<std::setprecision(x)))
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

// ^^^ Template ^^^ //


int main() {
	map<pair<ll, ll>, ll> cnt;
	in(unsigned long long , H, W, N);
	loop(i, N) {
		in(int, a, b);
		--a; --b;
		for (int dx = -1; dx <= 1; ++dx)
			for (int dy = -1; dy <= 1; ++dy) {
				ll x = b + dx;
				ll y = a + dy;
				if (0 < x && x <= W - 2 && 0 < y && y <= H - 2) {
					++cnt[{y, x}];
				}
			}
	}
	ll ans[20] = {}, c19 = 0;
	for (auto&& p : cnt) {
		++ans[p.second];
		++c19;
	}
	out((H-2)*(W-2) - c19);
	for (int i = 1; i < 10; ++i)
		out(ans[i]);
	return 0;
}


Measured memory_bytes: 56576
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;

ll get_rui(ll,ll,ll,ll,ll);

ll N,K;
ll field[2020][2020][2];
ll rui[2020][2020][2];
int main(){
  cin >> N >> K;
  rep(i,N){
    ll x,y;
    char c;
    cin >> x >> y >> c;
    x %= 2*K;
    y %= 2*K;
    x++;
    y++;
    if(c == 'W'){
      field[y][x][0]++;
    }
    else{
      field[y][x][1]++;
    }
  }
  rep(y,2*K+2){
    rep(x,2*K+2){
      rep(k,2){
        if(y > 0 && x > 0){
          rui[y][x][k] = field[y][x][k] + rui[y-1][x][k] + rui[y][x-1][k] - rui[y-1][x-1][k];
        }
        else if(y > 0){
          rui[y][x][k] = field[y][x][k] + rui[y-1][x][k];
        }
        else if(x > 0){
          rui[y][x][k] = field[y][x][k] + rui[y][x-1][k];
        }
        else{
          rui[y][x][k] = field[y][x][k];
        }
      }
    }
  }
  ll ans = 0;
  rep(y,K){
    rep(x,K){
      rep(k,2){
        ll tmp_x = x + 1;
        ll tmp_y = y + 1;
        ll tmp_ans=0;
        tmp_ans += get_rui(0,0,tmp_x,tmp_y,k);
        tmp_ans += get_rui(0,tmp_y,tmp_x,tmp_y+K,(k+1)%2);
        tmp_ans += get_rui(0,tmp_y+K,tmp_x,2*K,k);

        tmp_ans += get_rui(tmp_x,0,tmp_x+K,tmp_y,(k+1)%2);
        tmp_ans += get_rui(tmp_x,tmp_y,tmp_x+K,tmp_y+K,k);
        tmp_ans += get_rui(tmp_x,tmp_y+K,tmp_x+K,2*K,(k+1)%2);

        tmp_ans += get_rui(tmp_x+K,0,2*K,tmp_y,k);
        tmp_ans += get_rui(tmp_x+K,tmp_y,2*K,tmp_y+K,(k+1)%2);
        tmp_ans += get_rui(tmp_x+K,tmp_y+K,2*K,2*K,k);
        if(ans < tmp_ans) ans = tmp_ans;
      }
    }
  }
  cout << ans << endl;
}

ll get_rui(ll sx, ll sy , ll gx , ll gy , ll k){
  if(sx == gx) return 0;
  if(sy == gy) return 0;
  ll ret = rui[gy][gx][k] - rui[sy][gx][k] - rui[gy][sx][k] + rui[sy][sx][k];
  return ret;
}


Measured memory_bytes: 127232
#include<stdio.h>
#include<string.h>
#include<math.h>
int as[104][104];
int main(){
    char s[103][104];
    int i,j,r,c,cnt;
    scanf("%d%d",&r,&c);
    for(i=0;i<r;i++){
        scanf("%s",s[i]);
    }
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            cnt=0;
            if(s[i][j]!='.') continue;
            for(int k=0;k<c-1;k++){
                if(s[i][k]==s[i][k+1]) cnt++;
                else break;
            }
            if(cnt==c-1) as[i][j]=1;
            cnt=0;
            for(int k=0;k<r-1;k++){
                if(s[k][j]==s[k+1][j])cnt++;
                else break;
            }
            if(cnt==r-1) as[i][j]=1;
        }
    }

    for(i=0;i<r;i++){
        int u=0;
        for(j=0;j<c;j++){
            if(!as[i][j]){
                 printf("%c",s[i][j]);
                 u=1;
            }
        }
        if(u) printf("\n");
    }


}


Measured memory_bytes: 256
k,n=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
maxi=0
for i in range(n-1):
    cal=abs(a[i]-a[(i+1)])
    if(cal>maxi):
        maxi=cal
if(abs(k-a[n-1])+a[0]>maxi):
    maxi=abs(k-a[n-1])+a[0]
print(k-maxi)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 998244353

ll mod_pow(ll a,ll n){
  if(n<0)return 0;
  ll res=1;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll fac[100010],finv[100010];

ll comb(ll n,ll r){
  if(n<0||r<0||n<r)return 0;
  return (fac[n]*finv[n-r]%mod)*finv[r]%mod;
}

ll K,N;
ll ans[5000];

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

  fac[0]=1;
  rep(i,100001)fac[i+1]=fac[i]*(i+1)%mod;
  rep(i,100001)finv[i]=mod_pow(fac[i],mod-2);

  cin>>K>>N;
  repl(i,2,K+2){
    ll res=0;
    if(i%2!=0){
      ll h=i/2;
      rep(k,h+1){
        ll cnt=comb(h,k)*mod_pow(2,k)%mod;
        (cnt*=comb(K-2*h+N-1,N-k))%=mod;
        (res+=cnt)%=mod;
      }
    }else{
      ll h=(i/2)-1;
      rep(k,h+1){
        ll cnt=comb(h,k)*mod_pow(2,k)%mod;
        (cnt*=comb(K-2*h-1+N-1,N-k))%=mod;
        (res+=cnt)%=mod;
      }
      N--;
      rep(k,h+1){
        ll cnt=comb(h,k)*mod_pow(2,k)%mod;
        (cnt*=comb(K-2*h-1+N-1,N-k))%=mod;
        (res+=cnt)%=mod;
      }
      N++;
    }
    ans[i]=ans[K*2+2-i]=res;
  }
  repl(i,2,K*2+1)cout<<ans[i]<<endl;

  return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define fl long double
#define pb push_back
#define mk make_pair
#define endl "\n"
#define ff first
#define ss second
#define mt make_tuple
#define np next_permutation
#define pi 3.141592653589793238
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define vll vector<ll>
#define vp vector<pair<ll,ll>>
#define all(x) x.begin(),x.end()
#define revpq priority_queue <int, vector<int>, greater<int>>
const ll mod=1000000007;
const ll INF=10000000000;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod%mod;a=a*a%mod;}return res;}

int main()
{
    fastio
    ll i,j,k,n,m,t;
    cin>>n;
    cout<<n+n*n+n*n*n<<endl;
    return 0;
}


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

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

  int S = s.length();
  vector<int> l(S, 0);

  for (int i = 0; i < S; i++) {
    if (l[i] != 0) continue;
    if (s[i] == 'R') {
      int pos = s.find('L', i);
      for (int j = i; j < pos; j++) {
        if ((pos - j) % 2 == 0)
          l[j] = pos;
        else
          l[j] = pos - 1;
      }
    } else {
      if (s[i - 1] == 'R')
        l[i] = i;
      else if (s[i - 1] == 'L' && s[i - 2] == 'R')
        l[i] = i - 2;
      else
        l[i] = l[i - 2];
    }
  }

  vector<int> ans(S, 0);
  rep(i, S) ans[l[i]]++;
  rep(i, S) printf("%d ", ans[i]);
  printf("\n");
}


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

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];

    int l=0, r=1e9;
    while(r-l>1){
        int x=(l+r)/2;
        auto f=[&](int x){
          ll now=0;
          rep(i,n) now+=(a[i]-1)/x;
          return now<=k;
        };
        if(f(x)) r=x; else l=x;
    }

    cout<<r<<endl;
    return 0;
}

Measured memory_bytes: 4856
#include<bits/stdc++.h>
using namespace std;
#define INFTY 1<<20
#define rep(i,n) for (ll i = 0; i < (n); ++i)
typedef long long int ll;
using ipair = pair<int,int>;
bool operator< (const ipair a, const ipair b){return a.first < b.first;};
const int MOD=1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){ 
    int n;cin>>n;
    string s="";
    if(n==0)s = s + to_string(0);
    else{
    while(abs(n)>=1){
        if(n%(-2)!=0){
            s =  to_string(abs(n%(-2)))+s;
            n=(n-1)/(-2);
            //printf("n:%d s:%s\n",n,s.c_str());
        }
        else{
            s =  to_string(n%(-2))+s;
            n=n/(-2);
            //printf("n:%d s:%s\n",n,s.c_str());
        }
        
        
        
    }}
   //if(n==1)s = s + to_string(1);
    
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n; cin >> n;
  vector<int> a(n+1);
  rep(i,n) cin >> a[i+1];
  vector<int> b(n+1);
  for(int i = n;i >= 1; i--){
    int sum = 0;
    for(int j = i+i; j <= n ;j += i){
      sum ^= b[j];
    }
    b[i] = sum^a[i];
  }
  
  vector<int> ans;
  for(int i = 1; i <= n;i++){
    if(b[i]) ans.push_back(i);
  }
  cout << ans.size() << endl;
  rep(i,ans.size()){
    printf("%d%c", ans[i], i+1==ans.size()?'\n':' ');
  }
  return 0;
}

Measured memory_bytes: 3064
//#include <bits/stdc++.h>/*
#include <unordered_map>
#include <functional> //greater
#include <algorithm> //sort
#include <iostream>
#include <iterator>
#include <utility> //pair
#include <sstream>
#include <cstring> //memset
#include <complex>
#include <cassert>
#include <random>
#include <cstdio>
#include <string>
#include <vector>
#include <cctype> //isaplha, tolower
#include <deque>
#include <queue>
#include <stack>
#include <array>
#include <cmath> //sqrt, sin
#include <ctime>
#include <list>
#include <map>
#include <set>
//*/
 
#define int long long
#define uns unsigned
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define endl '\n'
using namespace std;
 
template<class T> ostream &operator<<(ostream &os, const pair<T,T> &p){
	return os<<"("<<p.fi<<","<<p.se<<")";}
template<class T> ostream &operator<<(ostream &os, const pair<const T,T> &p){
	return os<<"("<<p.fi<<","<<p.se<<")";}
template<class T> ostream &operator<<(ostream &os, const array<T,3> &p){
	return os<<"("<<p[0]<<","<<p[1]<<","<<p[2]<<")";}
template<class T> ostream &operator<<(ostream &os, const vector<T> &p){
	for(auto x: p) os<<x<<' '; return os;}
#define dbug(x) cerr<<">>>> "<<#x<<" = "<<x<<endl
#define _ <<", "<<
#define FOR(X,L,R) for(int X=L;X<R;X++)
#define FI(I,X) for(auto I=(X).begin();I!=(X).end();I++)
#define print(X) {cerr<<"{ ";FI(I,X)cerr<<*I<<' ';cerr<<"}"<<endl;}
#define mset(V,X) memset(V,X,sizeof(V))
#define all(X) (X).begin(),(X).end()
#define upperb(V,X) (int)(upper_bound(all(V),(X))-V.begin())
#define lowerb(V,X) (int)(lower_bound(all(V),(X))-V.begin())
 
const double EPS = 1e-9, PI = acos(-1);
const ll LINF = 0x3f3f3f3f3f3f3f3f, mod = 1e9+7;
const int INF = 0x3f3f3f3f, SZ = 2e5+20;

int n,v[100010];
int dp[100010];
int pd(int i){
	if(dp[i] != -1) return dp[i];
	return dp[i] = min( pd(i-1)+abs(v[i]-v[i-1]), pd(i-2)+abs(v[i]-v[i-2]) );
}
 
int32_t main(){
	ios::sync_with_stdio(false);cin.tie(0);
	
	mset(dp,-1);
	cin>>n;
	FOR(i,0,n) cin>>v[i];
	dp[0] = 0; dp[1] = abs(v[1]-v[0]);
	cout<<pd(n-1)<<endl;
 
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#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 int ll
using pint = pair<int, int>;

int cmb (int n, int k) {
    int res = 1;
    rep (i, 1, k + 1) {
        res *= n - i + 1;
        res /= i;
    }
    return res;
}

signed main() {
    int n, a, b;
    cin >> n >> a >> b;
    double v[n];
    rep (i, 0, n) cin >> v[i];
    sort (v, v + n, greater<double>());

    double ave = 0;
    rep (i, 0, a) ave += v[i];
    ave /= a;

    int cnt = 0;
    rep (i, 0, n) if (v[i] == v[a - 1]) cnt++;

    int ans = 0;
    rep (i, a, b + 1) {
        int cnt2 = 0;
        rep (j, 0, i) if (v[a - 1] == v[j]) cnt2++;
        if (v[0] == v[i - 1]) {
            ans += cmb (cnt, cnt2);
        } else if (i == a) {
            ans += cmb (cnt, cnt2);
        }
    }
    cout << fixed << setprecision (15) << ave << "\n" << ans << "\n";
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/


int main(){
    ll a, b, c; cin >> a >> b >> c;
    
    if(c - a - b > 0 and (c - a - b) * (c - a - b) - 4 * a * b > 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
n = gets.chomp.to_i

claim = Array.new(n){ Array.new(n, 0) }
n.times do |i|
  a = gets.chomp.to_i
  a.times do
    x, y = gets.chomp.split.map(&:to_i)
    claim[i][x-1] = 2*y - 1
  end
end

max = 0
[-1,1].repeated_permutation(n) do |arr|
  possible = true
  honest = arr.count(1)
  next if max >= honest
  list = arr
  n.times do |i|
    next if arr[i] == -1
    if arr.zip(claim[i]).flat_map{|p,q| p*q}.include?(-1)
      possible = false
      break
    end
  end
  max = honest if possible
end

puts(max)

Measured memory_bytes: 2300
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Map<Integer, Long> map = new HashMap<>();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
			if (map.get(a[i]) == null) {
				map.put(a[i], 1L);
			} else {
				map.put(a[i], map.get(a[i]) + 1);
			}
		}
		Map<Integer, Long> res = new HashMap<>();
		Map<Integer, Long> res2 = new HashMap<>();
		for (int i = 0; i < n; i++) {
			if (res.get(a[i]) == null) {
				long tmp = map.get(a[i]);
				res.put(a[i], tmp * --tmp / 2);
			}
			if (res2.get(a[i]) == null) {
				long tmp = map.get(a[i]) - 1;
				res2.put(a[i], tmp * --tmp / 2);
			}
		}
		long sum = 0L;
		for (int key : res.keySet()) {
			sum += res.get(key);
		}
		for (int i = 0; i < n; i++) {
			System.out.println(sum - Math.abs(res.get(a[i]) - res2.get(a[i])));
		}
	}
}


Measured memory_bytes: 117476
#include <iostream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>

using namespace std;
int n,m;
int main() {
	while(cin >> n >> m && n > 0)
	{
		pair<int, int> pd
		[10000];
		int d,p;
		int y = 0;
		for(int i = 0; i < n; i++)
		{
			cin >> d >> p;
			pd[i] = make_pair(p, d); 
			y += d*p;
		}
		sort(pd,pd+n);
		reverse(pd,pd+n);
		for(int i = 0; i < n; i++)
		{
			if(m < 0) cout << y;
			else{
				int e = min(m, pd[i].second);
				y -= pd[i].first * e;
				m -= e;
			}
		}
		cout << y << endl;
	}
	
}


Measured memory_bytes: 3112
N, C, K = map(int, input().split())
T = [int(input()) for t in range(N)]
T.sort()

current_bus = -1
n_people_in_current_bus = 0
n_buses = 0
for t in T:
    if t <= current_bus <= t + K and n_people_in_current_bus < C:
        n_people_in_current_bus += 1
    else:
        n_buses += 1
        current_bus = t + K
        n_people_in_current_bus = 1
print(n_buses)


Measured memory_bytes: 7384
#include <stdio.h>

int call(int);

int main(void) {
    int i, n;
    for(i = scanf("%d", &n); i <= n; i++) {
        call(i) && printf(" %d", i);
    }
    printf("\n");
    return 0;
}

int call(int x) {
    int rslt = 0;
    x % 3 || (rslt = 1);
    for(x *= 10; (x /= 10) > 0; x % 10 == 3 && (rslt = 1));
    return rslt;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <utility>

using namespace std;

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

	vector<int> w(n);
	vector<int> e(n);
	for (int i = 0; i < n; i++) {
		if (s.at(i) == 'W') {
			w.at(i)++;
		}
		else {
			e.at(i)++;
		}
		if (i != 0) {
			w.at(i) += w.at(i - 1);
			e.at(i) += e.at(i - 1);
		}
	}
	
	vector<int> ans(n);
	for (int i = 0; i < n; i++) {
		if (i != 0) ans.at(i) += w.at(i - 1);
		ans.at(i) += e.at(n - 1) - e.at(i);
	}

	sort(ans.begin(), ans.end());
	cout << ans.at(0) << endl;

	return 0;
}

Measured memory_bytes: 7140
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <functional>
#include <sstream>
#include <bitset>
#include <map>

using namespace std;

typedef long long ll;


int main() {
  ll N,ans,counter;
  cin>>N;
  ans = 0;
  counter = 1;
  while(counter * counter < N) {
    if (N % counter == 0) {
      ll tmp = N / counter - 1;
      if(N / tmp == N % tmp) ans += N / counter - 1;
    }
    counter++;
  }
  cout<<ans<<endl;
  return 0;
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

signed main()
{
    int n; cin>>n;
    vector<ll> a(n);
    ll s=0;
    rep(i,n) {
        cin>>a[i];
        s+=a[i];
    }
    ll x=s;
    for(int i=1; i<n; i+=2){
        x-=a[i]*2;
    }
    cout<<x<<endl;
    for(int i=0; i<n-1; i++){
        x=a[i]*2-x;
        cout<<x<<endl;
    }
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll H, A;
  cin >> H >> A;

  ll ans = H / A;
  if(H % A != 0) ans++;

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


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(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 trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;

#define PI 3.141592653589793
#define mod 1000000007
#define N 1000000000
//# define N 2003
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=(ans*a)%m; b/=2; a=(a*a)%m; } return ans%m; }
# define INF 10000000
# define A 1000000

//bool vis[N+5],vis1[N+5];
string s;
int dp[300][300][300];
int  solve(int l,int r,int k)
{
	if(l==r)
	{
		return 1;
	}
	if(l>r)
	{
		return 0;
	}
	if(dp[l][r][k]!=-1)
		return dp[l][r][k];
	int ans;
	if(s[l]==s[r])
		ans=(2+solve(l+1,r-1,k));
	else
	{
		ans=max(solve(l+1,r,k),solve(l,r-1,k));
		if(k)
		ans=max(ans,2+solve(l+1,r-1,k-1));
	}
	return dp[l][r][k]=ans;
}
int main()
{
	IOS;
	int k;
	cin >> s;
	cin >> k;
    memset(dp,-1,sizeof dp);
	int l=s.length();
	cout << solve(0,l-1,k);
}

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

int main(){
	string s;
	cin>>s;
	
	int ans=0;
	for(int i=0;i<s.size();i++){
		if(ans%2==0){
			if(s[i]=='A')ans++;
			}
		else{
			if(s[i]=='Z')ans++;
			}	
		}
	ans/=2;
	ans*=2;
	for(int i=0;i<ans;i+=2)cout<<"AZ";
	if(ans==0)cout<<-1;
	cout<<endl;
	return 0;	
	}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
// -----------------------------------------------------------------------------

double f(int n, double d, double x) {
    dbg(n, d, x);
    if (n == 0) return 0;
    return (2 * n - 1) * x / 2 + d + f(n - 1, d + d / n + 5 * x / (2 * n), x + 2 * x / n);
}

int main() {
    int n, d, x;
    cin >> n >> d >> x;
    printf("%.15f\n", f(n, d, x));
}

Measured memory_bytes: 6528
#include <iostream> 

using namespace std;

int main() {
    int N, H;
    cin >> N >> H;
    int counter = 0;
    for (int i=0; i<N; i++) {
        int temp;
        cin >> temp;
        if (temp>=H) counter++;
    }
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int w,n;
	cin >> w >> n;
	vector<pair<int,int>> v;
	rep(i,0,n){
		int a,b;
		scanf("%d,%d",&a,&b);
		a--;
		b--;
		v.push_back(pair<int,int> (a,b));
	}
	
	int ans[w];

	rep(i,0,w){
		int now = i;
	
		rep(j,0,n){
			//cout << now << " " << v[j].first << " " << v[j].second << endl;
			if( v[j].first == now )
				now = v[j].second;
			else if( v[j].second == now)
				now = v[j].first;
		}
		
		ans[now] = i+1;
		
		//cout << "now:" <<  now+1 << endl;
	}
	
	rep(i,0,w)
		cout << ans[i] << endl;

	ret 0;
}


Measured memory_bytes: 3236
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  int ans = 0;
  int l, r;
  for(int i=0;i<N;++i) {
    cin>>l>>r;
    ans += r-l+1;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3560