akhauriyash/Code-Regression huggingface dataset:
#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 dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    int n;
    cin >> n;
    int z[n], w[n];
    rep(i, 0, n) {
        int x, y;
        cin >> x >> y;
        z[i] = x + y;
        w[i] = x - y;
    }
    sort(z, z + n);
    sort(w, w + n);
    int ans = max(z[n - 1] - z[0], w[n - 1] - w[0]);
    cout << ans << "\n";
}


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

using namespace std;

const int N = 200010;

int n;
char s[N], t[N];
int val[100];
int revVal[1000];

int main() {
	scanf("%s", s + 1);
	scanf("%s", t + 1);
	n = strlen(s + 1);
	memset(val, -1, sizeof val);
	memset(revVal, -1, sizeof revVal);
	for (int i = 1; i <= n; i++) {
		int u = s[i] - 'a';
		int v = t[i] - 'a';
		if (val[u] != -1 && val[u] != v) {
			puts("No");
			return 0;
		}
		val[u] = v;
		if (revVal[v] != -1 && revVal[v] != u) {
			// cout << u << " " << v << endl;
			puts("No");
			return 0;
		}
		revVal[v] = u;
	}
	puts("Yes");
	return 0;
}

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

int main(){
  int w,h,n;
  cin >> w >> h >> n;
  VI x(n), y(n), a(n);
  rep(i,n) cin >> x[i] >> y[i] >> a[i];
  
  int xmin=0,xmax=w,ymin=0,ymax=h;
  rep(i,n){
    if( a[i]==1 && x[i] > xmin ) xmin = x[i];
    if( a[i]==2 && x[i] < xmax ) xmax = x[i];
    if( a[i]==3 && y[i] > ymin ) ymin = y[i];
    if( a[i]==4 && y[i] < ymax ) ymax = y[i];
  }
  
  if( xmin < xmax && ymin < ymax ) cout << ((xmax-xmin)*(ymax-ymin)) << endl;
  else cout << 0 << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <unistd.h>
#include <cstdlib>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))

int input() {
    char buf[6];
    int size = read(0, buf, 6);
    int n = 0;
    REP (i, 5) {
        n = n * 10 + buf[i] - '0';
    }
    return n;
}
void output(int n) {
    char buf[20];
    char *s = buf + sizeof buf;
    *(-- s) = '\n';
    if (not n) *(-- s) = '0';
    for (; n; n /= 10) {
        *(-- s) = (n % 10) + '0';
    }
    write(1, s, buf + sizeof buf - s);
}


__attribute__((constructor))
int _main() {
    int a = input();
    int b = input();
    int cnt = 0;
    REP (x, 10) REP (y, 10) REP (z, 10) {
        int n = x * 10000 + y * 1000 + z * 100 + y * 10 + x;
        cnt += (a <= n and n <= b);
    }
    output(cnt);
    exit(EXIT_SUCCESS);
}

int main() {
}


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

int main() {
    int n; cin >> n;
    int total = 0;
    vector<int>v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
        total += v[i];
    }
    int avg1 = ceil((double)total/(double)n);
    int avg2 = total/n;
    int ans1 = 0;
    int ans2 = 0;
    for(int i = 0; i < n; i++){
        ans1 += (v[i] - avg1) * (v[i] - avg1);
        ans2 += (v[i] - avg2) * (v[i] - avg2);
    }
    cout << min(ans1,ans2) << endl;
	return 0;
}


Measured memory_bytes: 256
n, m = map(int,input().split())

class unionfind():
    def __init__(self,n):
        self.li = [i for i in range(n+1)]
        self.group = [1]*(n+1)

    def find(self, x):
        while self.li[x]!=x:
            x = self.li[x]
        return x

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return;
        elif x>y:
            self.li[y] = x
            self.group[x] += self.group[y]
        else:
            self.li[x] = y
            self.group[y] += self.group[x]
x = unionfind(n)
ans = 0
for _ in range(m):
    a,b = map(int,input().split())
    x.union(a,b)
print(max(x.group))

Measured memory_bytes: 24560
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 10000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} // input vector
#include <boost/integer/common_factor_rt.hpp> // gcd, lcm


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

int N, M; cin >> N >> M;
VI a(N); invec(a);

VI ah = a; for(i64 &i: ah) i /= 2;
i64 l = 1;
for(i64 i: ah) l = boost::integer::lcm(i, l);

for (i64 i: ah) 
    if (l / i % 2 == 0) {
        cout << "0\n";
        return 0;
    }  

cout << (M / l + 1) / 2  <<  "\n";
}
// 書いて考える．場合分け．情報整理．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int N,M;
	cin>>N>>M;
	int n[1001]={0};
	int m[1001]={0};
	int sc[1001]={0};
	int mx=0;
	for(int i=1;i<=N;i++){
		cin>>n[i];
	}
	for(int i=1;i<=M;i++){
		cin>>m[i];
		for(int j=1;1;j++){
			if(n[j]<=m[i]){
				sc[j]++;
				mx=max(mx,sc[j]);
				break;
			}
		}
	}
	for(int i=1;i<=N;i++){
		if(sc[i]==mx)cout<<i<<endl;
	}
	return 0;
}


Measured memory_bytes: 1172
#include <cmath>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>

using namespace std;

#define forsn(i,s,n) for (int i = (s);i < (int)(n);i++)
#define forn(i,n) forsn(i,0,n)
#define dforsn(i,s,n) for (int i = (n-1);i >= (int)(s);i--)
#define dforn(i,n) dforsn(i,0,n)
#define all(v) (v).begin(), (v).end()
#define F first
#define S second

bool could[100010];
int balls[100010];

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

	memset(could, 0, sizeof(could));
	
	int n, m; cin >> n >> m;
	forn(i,n) { could[i + 1] = 0, balls[i + 1] = 1; }
	could[1] = 1;
	
	while (m--) {
		int x, y; cin >> x >> y;
		
		could[y] |= could[x];
		balls[y]++;
		balls[x]--;
		could[x] &= (balls[x] != 0);
	}
	
	int res = 0;
	forn(i, n) res += could[i + 1];
	
	cout << res << endl;
}


Measured memory_bytes: 768
from collections import deque

def bfs(h, w, s, sx, sy):
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    d = [[-1] * w for _ in range(h)]
    d[sx][sy] = 0
    que = deque()
    que.append((sx, sy))

    while que:
        x, y = que.popleft()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != '#' and d[nx][ny] == -1:
                que.append((nx, ny))
                d[nx][ny] = d[x][y] + 1

    md = 0
    for i in range(h):
        for j in range(w):
          md = max(md, d[i][j])

    return md

h, w = [int(_) for _ in input().split()]
s = [0] * h
for i in range(h):
    s[i] = list(input())

ans = 0

for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            ans = max(ans, bfs(h, w, s, i, j))

print(ans)

Measured memory_bytes: 3316
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	long long int a, b, c, k;
	cin >> a >> b >> c >> k;
	if(k % 2 == 0) cout << a - b << endl;
	else cout << b - a << endl;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
public class Main {
	final Scanner sc=new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		final long STACK_SIZE=8*1024*1024;
		new Thread(null, new AOJ2061(), "RUN", STACK_SIZE).start();
	}
	
	// International party
	class AOJ2061 implements Runnable{
		AOJ2061(){}
		@Override public void run(){
			int c=0;
			while(sc.hasNext()){
				N=sc.nextInt();
				M=sc.nextInt();
				if((N|M)==0)	break;
				if(c>0)System.out.println();
				solve();
				++c;
			}
		}
		
		int N,M;
		String[] LANG;
		long[] ST;
		HashMap<String, Integer> dic;
		
		void solve(){
			LANG=new String[N];
			dic=new HashMap<String,Integer>();
			for(int i=0; i<N; ++i){
				LANG[i]=sc.next();
				dic.put(LANG[i], i);
			}
			
			ST=new long[M];
			for(int i=0; i<M; ++i){
				int K=sc.nextInt();
				for(int j=0; j<K; ++j){
					long tmp=dic.get(sc.next());
					ST[i]|=(1<<tmp);
				}
			}
			
			for(int i=1; i<=5; ++i){
				long ans=DFS(0,-1,0L,i);
				if(ans>0){
					System.out.println(Long.bitCount(ans));
					for(int j=0; j<N; ++j){
						long tmp=1<<j;
						if( (ans&tmp) >0 )	System.out.println(LANG[j]);
					}
					return;
				}
			}
			
			System.out.println("Impossible");
			
		}
		
		long DFS(int depth,int last,long used,int lim){
			
			if(depth==lim){
				int[] list=new int[Long.bitCount(used)];
				int idx=0;
				for(int i=0; i<N; ++i){
					if( (used&(1<<i)) > 0 ){
						list[idx]=i;
						++idx;
					}
				}
				boolean[] ret=isConnected(0, list, new boolean[M]);
				for(boolean b:ret)if(!b)	return 0L;
				return used;
			}
			
			long ret=0L;
			for(int i=last+1; i<N; ++i){
				long now=(1<<i);
				used|=now;
				
				long tmp=DFS(depth+1,i,used,lim);
				if(tmp > 0 && (ret == 0 || Long.bitCount(ret) < Long.bitCount(tmp) ) )	ret=tmp;
				
				used^=now;
			}
			
			return ret;
		}
		
		boolean[] isConnected(int n,int[] list,boolean[] vtd){
			for(int i=0; i<M; ++i){
				if(vtd[i])	continue;
				for(int j=0; j<list.length; ++j){
					long tmp=1<<list[j];
					if( (ST[i]&tmp) > 0 && (ST[n]&tmp) > 0 ){
						vtd[i]=true;
						vtd = isConnected(i,list,vtd);
					}
				}
			}
			return vtd;
		}
	}
}

Measured memory_bytes: 13000
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long[] X = new long[5];
		for (int i=0;i<5;i++) {
			X[i]=sc.nextLong();
		}

		int min=0;
		for (int i=1;i<5;i++) {
			if (X[i]<X[min]) {
				min=i;
			}
		}

		long y;
		if (N<X[min]) {
			y=1;
		} else if (N%X[min]==0) {
			y=N/X[min];
		} else {
			y=N/X[min]+1;
		}
		System.out.println(y+4);
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,j,sum=0,sum1=0;
    cin>>a>>b>>c;

    for(int i=1; i<=a; i++)
    {
        j=i;
        sum=0;
        while(j>0)
        {
            sum+=j%10;
            j=j/10;
        }
        if(sum>=b && sum<=c) sum1+=i;
    }
    cout<<sum1;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2);
        if(y%2==0)
         return (p*p)%hell;
        else
        return (x*((p*p)%hell))%hell;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll x,y;
    ll f[2000000+1];
    f[0]=1;
    f[1]=1;
    for(ll i=2;i<=2000000;i++)
    {
        f[i]=(f[i-1]*i)%hell;
    }
    cin>>x>>y;
    ll a=2*x-y,b=2*y-x;
    if(a>=0&&b>=0&&a%3==0&&b%3==0)
    {
        a=a/3;
        b=b/3;
        ll z=(f[a+b]*power(f[a],hell-2))%hell;
        z=(z*power(f[b],hell-2))%hell;
        cout<<z;
    }
    else
    {
        cout<<0;
    }}

Measured memory_bytes: 19252
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;

const int INF=2e9;
int minPlus=INF,maxPlus=-INF,minMinus=INF,maxMinus=-INF;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,x,y;
    cin>>n;
    while (n--)
    {
        cin>>x>>y;
        minPlus=min(minPlus,x+y);
        maxPlus=max(maxPlus,x+y);
        minMinus=min(minMinus,x-y);
        maxMinus=max(maxMinus,x-y);
    }
    cout<<max(maxPlus-minPlus,maxMinus-minMinus);
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define SUM(n) ((n)+1)*(n)/2
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = (1e9)+7;
#define all(v) v.begin(),v.end()
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  bool ok[5]={false};
  int n, m;
  cin >> n >> m;
  char st[5];
  int s;
  char c;
  rep(i,m){
    cin >> s >> c;
    if(ok[s] && st[s] != c){
      cout << -1 << '\n';
      return 0;
    }
    st[s] = c;
    ok[s] = true;
  }
  if(ok[1] == true && st[1] == '0' && n != 1){
    cout << -1 << '\n';
    return 0;
  }
  reps(i,n){
    if(ok[i]){
      cout << st[i];
    } else {
      if(i == 1 && n != 1){
	cout << 1;
      } else{
	cout << 0;
      }
    }
  }
  cout << '\n';
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ll n;
graph t;
ll c[e5];
ll ans;
ll vis[e5];
queue<ll> q;
ll a[e5];
ll cnt[e5];

void dfs(ll x,ll pre){
  bool flag = false;
  for(auto y : t[x]){
    if(y.first == pre) continue;
    dfs(y.first, x);
    flag = true;
  }
  if(!flag){
    q.push(x);
    vis[x] = 1;
  }
}



int main(){
  cin >> n;
  for(ll i = 0;i < n-1;i++){
    ll a,b;
    cin >> a >> b;
    t[a][b] = t[b][a] = 1;
  }
  for(ll i = 0;i < n;i++) cin >> c[i];
  sort(c,c+n);
  for(ll i = 0;i < n-1;i++){
    ans += c[i];
  }
  for(ll i = 1;i <= n;i++){
    if(t[i].size() > 1){
      dfs(i,0);
      break;
    }
  }
  ll i = 0;
  while(!q.empty()){
    ll x = q.front();
    q.pop();
    a[x] = c[i];
    i++;
    for(auto y : t[x]){
      cnt[y.first]++;
      if(t[y.first].size()-cnt[y.first] <= 1){
        if(vis[y.first] == 0){
          q.push(y.first);
          vis[y.first] = 1;
        }
      }
    }


  }
  cout << ans << endl;
  for(ll i = 1;i <= n-1;i++) cout << a[i] << " ";
  cout << a[n] << endl;

}


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

using namespace std;

void solve() {
    string S, T;
    cin >> S;
    cin >> T;
    for (int i = 0; i < S.length(); i++)
    {
        if (S[i] != T[i])
        {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
    
}

int main() {
    solve();
    return 0;
}

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

bool cmpstring(const string &l, const string &r) {
  if(l.size() != r.size()) return l.size() < r.size();
  for(int i = 0; i < l.size(); ++i)
    if(l[i] != r[i]) return l[i] < r[i];
  return 0;
}

struct data {
  int x, y;
  string s;
};

bool operator<(const data &l, const data &r) {
  if(l.s != r.s) return cmpstring(l.s, r.s);
  if(l.x != r.x) return l.x > r.x;
  return l.y > r.y;
}

int w, h;
vector<string> s;
string dist[80][80];
int d[2] = {0, 1};
priority_queue<data> pq;

string solve();
bool ch(const data &now) {
  return now.x >= 0 && now.x < h && now.y >= 0 &&
         now.y < w && s[now.x][now.y] >= '0' &&
         s[now.x][now.y] <= '9';
}

int main() {
  while(1) {
    cin >> w >> h;
    if(w + h == 0) break;
    s.resize(h);
    for(int i = 0; i < h; ++i) cin >> s[i];
    cout << solve() << endl;
  }
  return 0;
}

string solve() {
  string ans = "";
  for(int i = 0; i < h; ++i)
    for(int j = 0; j < w; ++j) {
      dist[i][j] = "X";
      if(s[i][j] >= '1' && s[i][j] <= '9') {
        string pushs;
        pushs += s[i][j];
        dist[i][j] = pushs;
        pq.push({i, j, pushs});
        ans = max(ans, pushs);
      }
      else if(s[i][j] == '0') {
        dist[i][j] = "";
        ans = "0";
        pq.push({i, j, ""});
      }
    }
  while(!pq.empty()) {
    data now = pq.top();
    pq.pop();
    if(dist[now.x][now.y] != now.s) continue;
    for(int i = 0; i < 2; ++i) {
      data nextp = now;
      nextp.x += d[i];
      nextp.y += d[1 ^ i];
      if(!ch(nextp)) continue;
      if(nextp.s.size() != 0 || s[nextp.x][nextp.y] != '0')
        nextp.s += s[nextp.x][nextp.y];
      if(dist[nextp.x][nextp.y] == "X" ||
         cmpstring(dist[nextp.x][nextp.y], nextp.s)) {
        dist[nextp.x][nextp.y] = nextp.s;
        pq.push(nextp);
        if(cmpstring(ans, nextp.s)) ans = nextp.s;
      }
    }
  }
  return ans;
}


Measured memory_bytes: 3392
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define int long long

const int N = 7;
string s[N];
int ans;
int h, w, k;

int32_t main() {
	cin >> h >> w >> k;
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}

	for (int msk = 0; msk < (1 << (h + w)); msk++) {
		int cnt = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (s[i][j] == '#' && !((bool)(msk & (1 << i))) && !((bool)(msk & (1 << (h + j)))))
					cnt++;
			}
		}
		if (cnt == k)
			ans++;
	}
	cout << ans;
	return 0;
}




Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    sort(all(a));
    a.erase(unique(all(a)),a.end());
    cout << (a.size()&1 ? a.size() : a.size()-1) << endl;
}


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

void solve_A(){
	int a,b;
	cin >> a >> b;
	if(a>=10||b>=10) cout << "-1" << endl;
	else cout << a*b << endl;
}

void solve_B(){
	bool s[105]={0};
	int n,i,j;
	cin >> n;
	for(i=1;i<=9;i++){
		for(j=1;j<=9;j++){
			s[i*j]=true;
		}
	}
	if(s[n]) cout << "Yes" << endl;
	else cout << "No" << endl;
}

void solve_C(){
	long long n,i,m=0;
	cin >> n;
	for(i=1;i*i<=n;i++){
		if(n%i==0) m=i;
	}
	cout << m+n/m-2 << endl;
}

void solve_D(){
	double a,b,x,ans;
	cin >> a >> b >> x;
	x /= a;
	if(x>=a*b/2){
		x -= a*b/2.0;
		x = 2.0*x/a;
		x = b-x;
		ans =atan(x/a);
	} else {
		x = 2.0*x/b;
		ans = atan(b/x);
	}
	ans = ans*180.0/3.1415926535897;
	printf("%.13lf\n",ans);
}


int main() {
	// your code goes here
	solve_A();
	//solve_B();
	//solve_C();
	//solve_D();
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			int k = cin.Int();
			long[] a = new long[n];
			for (int i = 0; i < n; i++) {
				a[i] = cin.Int();
			}

			var ds = GetDivisors(a.Sum());
			ds.Reverse();
			long[] b = new long[n];
			foreach (long d in ds) {
				for (int i = 0; i < n; i++) {
					b[i] = a[i] % d;
				}

				var c = b.OrderBy(x => x).ToArray();
				long sum = c.Sum();
				long rsum = c.Sum(x => d - x);
				long tempSum = 0;
				for (int i = 0; i < n; ++i) {
					tempSum += c[i];
					rsum -= (d - c[i]);
					if (tempSum == rsum && tempSum <= k) {
						Console.WriteLine(d);
						return;
					}
				}
			}

			Console.WriteLine(1);
		}

		public static List<long> GetDivisors(long value)
		{
			long max = (long)Math.Ceiling(Math.Sqrt(value));
			var divisors = new List<long>();
			for (int i = 1; i <= max; i++) {
				if (value % i == 0) {
					divisors.Add(i);
					divisors.Add(value / i);
				}
			}

			divisors.Sort();
			return divisors;
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;
		
		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 15620
#include <stdio.h>
#include <inttypes.h>

int main(void)
{
    size_t  a, b, c;
    uint8_t s[8] = { 0 };
    scanf("%zu %zu %zu", &a, &b, &c);
    s[a]++;
    s[b]++;
    s[c]++;
    puts((s[5] == 2 && s[7] == 1) ? "YES" : "NO");
    return 0;
}


Measured memory_bytes: 128
function main()
  
  N = parse(Int,readline())
  W = map(x -> parse(Int,x), split(readline()))
  
  ans = 1000
  
  for i in 1:N
    ans = min(abs(sum(W[1:i]) - sum(W[1+i:end])),ans)
  end
  
  println(ans)
  
end

main()

Measured memory_bytes: 168032
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;
const ll M = pow(10,9)+7;
/*template*/


int main()
{
  ll r;cin>>r;
  cout<<r*r<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int w = sc.nextInt();
		
		ArrayList<Integer> list0 = new ArrayList<>();
		ArrayList<Integer> list1 = new ArrayList<>();
		ArrayList<Integer> list2 = new ArrayList<>();
		ArrayList<Integer> list3 = new ArrayList<>();
		
		int w1 = sc.nextInt();
		int v = sc.nextInt();
		list0.add(v);
		for(int i=1;i<n;i++){
			int weight = sc.nextInt();
			int value = sc.nextInt();	
			
			if(weight-w1==0)
				list0.add(value);
			if(weight-w1==1)
				list1.add(value);
			if(weight-w1==2)
				list2.add(value);
			if(weight-w1==3)
				list3.add(value);
		}

		Collections.sort(list0);
		Collections.sort(list1);
		Collections.sort(list2);
		Collections.sort(list3);
		list0.add(0);
		list1.add(0);
		list2.add(0);
		list3.add(0);
		
		long sum = 0;
		int v0 = 0, v1 = 0, v2 = 0, v3 = 0;
		for(int i=list0.size()-1;i>=0;i--){
			v0+=list0.get(i);
			v1 = 0;
			for(int j=list1.size()-1;j>=0;j--){
				v1+=list1.get(j);
				v2 = 0;
				for(int k=list2.size()-1;k>=0;k--){
					v2+=list2.get(k);
					v3 = 0;
					for(int l=list3.size()-1;l>=0;l--){
						v3+=list3.get(l);
						if((long)w1*(list0.size()-1-i)+(long)(w1+1)*(list1.size()-1-j)+(long)(w1+2)*(list2.size()-1-k)+(long)(w1+3)*(list3.size()-1-l)<=w){
							if(v0+v1+v2+v3>sum)
								sum = v0+v1+v2+v3;
						}
					}
				}
			}
		}
		System.out.println(sum);
	}

}

Measured memory_bytes: 25684
#if 0
????????£?????????????´??????????
?????????pdf????????????????????????????°????????????????????????????
??????????????¨???????????????????????????????????????????????????
#endif
#include <iostream>
#include <string>
#include <cassert>
#include <cctype>
using namespace std;
string S="";
int cur=0;
char readchar()
{
  assert(cur<S.size());
  return S[cur++];
}

char peek()
{
  assert(cur<S.size());
  return S[cur];
}

int digit()
{
  assert(isdigit(peek()));
  int n=readchar()-'0';
  return n;
}

int number()
{
  int n=digit();
  while(cur<S.size()&&isdigit(peek()))
  {
    n=n*10+digit();
  }
  return n;
}

int expression();

int factor()
{
  if(peek()!='(') return number();
  cur+=1;
  int n=expression();
  assert(peek()==')');
  cur+=1;
  return n;
}

int term()
{
  int a=factor();
  while(cur<S.size()&&(peek()=='*'||peek()=='/'))
  {
    char op=readchar();
    int b=factor();
    if(op=='*')
    {
      a*=b;
    }
    else
    {
      a/=b;
    }
  }
  return a;
}

int expression()
{
  int sum=term();
  while(cur<S.size()&&(peek()=='+'||peek()=='-'))
  {
    char op=readchar();
    int b=term();
    if(op=='+')
    {
      sum+=b;
    }
    else
    {
      sum-=b;
    }
  }
  return sum;
}



int main()
{
  int n;
  cin>>n;
  for(int i=0;i<n;i++)
  {
    cur=0;
    cin>>S;
    S.resize(S.size()-1);
    cout<<expression()<<endl;
  }
  return 0;
}

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

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

    if (s == "Sunny"){
        cout << "Cloudy" << endl;
    }

    if (s == "Cloudy"){
        cout << "Rainy" << endl;
    }

    if (s == "Rainy"){
        cout << "Sunny" << endl;
    }
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <cmath>
#include <stdio.h>
#include <sstream>
#define int_inf 1000000000 //1e9
#define ll_inf  1000000000000000000 //1e18
using namespace std;
template <typename T> std::string to_string(const T& t){
	std::ostringstream os; os<<t; return os.str();
}

int main(){
	string s;
	cin >> s;
	int ans=0;
	
	for(int i=0; i<s.size(); i++){
		if(s[i]=='1') ans+=1;
	}
	cout<<ans << endl;
	return 0;
}




Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        if(a < b){
            System.out.println("a < b");
        }else if(a > b){
            System.out.println("a > b");
        }else{
            System.out.println("a == b");
        }
    } 
}


Measured memory_bytes: 26356
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int n; cin>>n;
	string s; cin>>s;
	int ans = 1;
	char col = s[0];
	REP(i,n-1){
		if(s[i]==col)continue;
		else {++ans; col = s[i];}
	}
	cout<<ans<<endl; return 0;
}


Measured memory_bytes: 512
n,m=map(int, input().split())
ab=[]
for _ in range(n):
    tmpa, tmpb=map(int, input().split())
    ab.append((tmpa,tmpb))
ab.sort(reverse=True)
import heapq
h = []
ans = 0
for i in range(1, m+1):
    while ab and ab[-1][0] == i:
        heapq.heappush(h,ab.pop()[1]*(-1))
    if h:
        ans -= heapq.heappop(h)
print(ans)

Measured memory_bytes: 17244
//#pragma  GCC optimize("Ofast")

//#ifdef  DEBUG
//#define _GLIBCXX_DEBUG
//#endif

// -Ofast
// -O3
// -O2
// -fsanitize=address
// -fsanitize=undefined

// add_compile_options()

#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <stack>
#include <bitset>
#include <queue>
#include <algorithm>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <unordered_map>
#include <cmath>
#include <cassert>
#include <random>

using namespace std;
//using namesparsace __gnu_pbds;

void solve();

signed main() {
    srand(time(0));
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    //freopen("input.txt", "r", stdin);
    //freopen("trench.out", "w", stdout);
    solve();
    return 0;
}

#define ld double
#define int long long

const int maxN = 110, maxK = 1e5 + 10, inf = 2e18 + 10, mod = 1e9 + 7;

int n, k, a[maxN], dp[maxN][maxK], suf[maxK];

void solve() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i <= a[0]; i++) {
        dp[0][i] = 1;
    }
    suf[k] = dp[0][k];
    for (int i = k - 1; i >= 0; i--) {
        suf[i] = (suf[i + 1] + dp[0][i]) % mod;
    }
    for (int i = 1; i < n; i++) {
        for (int j = 0; j <= k; j++) {
            dp[i][j] = (suf[max(0ll, j - a[i])] - suf[j + 1] + mod) % mod;
        }
        suf[k] = dp[i][k];
        for (int j = k - 1; j >= 0; j--) {
            suf[j] = (suf[j + 1] + dp[i][j]) % mod;
        }
    }
    cout << dp[n - 1][k];
}

Measured memory_bytes: 80128
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

// Self settings
// clang-format off
#define MAX_N 50
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
// clang-format on

int N, K;
int l[MAX_N];

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N >> K;
  REP(i, N) cin >> l[i];

  sort(l, l + N);
  reverse(l, l + N);

  int ans = 0;
  for (int i = 0; i < K; i++) {
    ans += l[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 888
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <iostream>
#include <string.h>
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
using namespace std;

typedef double LD;
typedef long long LL;
typedef pair<int, int> PII;
#define MP make_pair
#define PB push_back
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const LL MOD = 1000000007;
const int INF = 1e9;
const LL LINF = 1LL * INF * INF;
const int MAXN = 300007;
const LD EPS = 1e-7;

string S;

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	cin >> S;
	int n = SZ(S), m = n / 2, d = 0;
	if (n & 1)
	{
		while (m + d + 1 < n && S[m + d + 1] == S[m - (d + 1)] && S[m + d + 1] == S[m])
			++d;
		cout << m + d + 1;
		return 0;
	}
	while (m + d < n && S[m + d] == S[m - (d + 1)] && S[m + d] == S[m])
		++d;
	cout << m + d;
	//cout << endl; system("pause");
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
main()
{
    int i;
    long long A,B,C,tA,tB,tC;
    scanf("%lld%lld%lld",&A,&B,&C);
    if(A==B && B==C && A%2==0)
    {
        printf("-1");
        return 0;
    }
    i = 0;
    while(1)
    {
        if((A&1) || (B&1) || (C&1)) break;
        tA = (B+C)/2;
        tB = (A+C)/2;
        tC = (A+B)/2;
        A = tA; B = tB; C = tC;
        i++;
    }
    printf("%d",i);
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const mod = 1e9 + 7

var ifac, fac []int

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	var sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	as := make([]int, n)
	for i := range as {
		sc.Scan()
		a, _ := strconv.Atoi(sc.Text())
		as[i] = a
	}

	sort.Sort(sort.IntSlice(as))

	fac = make([]int, 1e5+1)
	ifac = make([]int, 1e5+1)
	inv := make([]int, 1e5+1)
	fac[0], fac[1] = 1, 1
	ifac[0], ifac[1] = 1, 1
	inv[0], inv[1] = 1, 1
	for i := 2; i < 1e5+1; i++ {
		fac[i] = (fac[i-1] * i) % mod
		inv[i] = (mod - inv[mod%i]*(mod/i)) % mod
		ifac[i] = (ifac[i-1] * inv[i]) % mod
	}

	var sum int
	for i := range as {
		//fmt.Println(sum)
		//fmt.Println("n-i-1,k,i", n-i-1, k, i)
		sum -= cm(as[i] * comb(n-i-1, k-1)) // min
		sum += cm(as[i] * comb(i, k-1))     // max
		sum = cm(sum)
	}

	fmt.Println(sum)
}

func cm(n int) int {
	n = n % mod
	for n < 0 {
		n += mod
	}
	return n
}

func comb(n, r int) int {
	if r > n {
		return 0
	} else if r == 0 || r == n {
		return 1
	}
	t := (ifac[n-r] * ifac[r]) % mod
	return (t * fac[n]) % mod
}


Measured memory_bytes: 5504
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 100000000
#define MOD 1000000007
using namespace std;



int main(){
    int N;
    cin >> N;
    
    int a[N],b[N],c[N],d[N];
    for(int i=0; i<N; i++){
        cin>>a[i]>>b[i];
    }
    for(int i=0; i<N; i++){
        cin>>c[i]>>d[i];
    }
    
    pair<int,int> y_color[2*N];
    for(int i=0; i<N; i++){
        y_color[a[i]].first=b[i];
        y_color[a[i]].second=0;
        
        y_color[c[i]].first=d[i];
        y_color[c[i]].second=1;
    }
    
    
    int ans=0;
    int made_pair[2*N]={};
    for(int i=0; i<2*N; i++){
        if(y_color[i].second==1){
            
            int partner=-1;
            int partner_y=-1;
            for(int j=i-1; j>=0; j--){
                if(made_pair[j]==1){
                    continue;
                }
                
                if(y_color[j].second==0 && partner_y<y_color[j].first && y_color[j].first<y_color[i].first){
                    partner=j;
                    partner_y=y_color[j].first;
                }
            }
            
            if(partner>=0){
                ans++;
                made_pair[partner]=1;
            }
            
        }
    }
    
    
    
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import collections
q = collections.deque([1])
n,m = map(int, raw_input().split(' '))
forbidden = set([int(raw_input()) for _ in range(m)])

mod = (10 ** 9) + 7
for w in range(1,n+1):
	if w not in forbidden:
		q.append(sum(q) % mod)
	else:
		q.append(0)
	if len(q) == 3:
		q.popleft() 
print q[-1]
	


Measured memory_bytes: 47900
#define $;for(i=j=0;i<n;i+=++j/n,j%=n)
#define _(a,b)$ for(b=l=0;l<n;)b+=a[i][l]*p[l++][j]%m $ a[i][j]=b%m;}
long m=1e9+7,p[50][50],a[50][50],b[50][50],k;i,j,l;main(n){scanf("%d%ld",&n,&k)$ a[i][i]=scanf("%d",p[i]+j);for(;k;k/=2){if(k&1){_(a,b[i][j])_(p,b[i][j])$ k+=a[i][j];printf("%d",k%m);}

Measured memory_bytes: 256
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
void main()
{
    long a, b, c;
    scan(a, b, c);
    auto n = lread();
    while (a >= b)
    {
        b *= 2;
        n -= 1;
    }
    // writeln(a, b, c);
    // writeln(n);
    if (c * 2 ^^ n > b)
    {
        writeln("Yes");
    }
    else
    {
        writeln("No");
    }

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 3660
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 9223372036854775807ll - 10;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

//const ll mod = 1000000007;

int main(){
    ll n; cin >> n;
    vl p(n+1); FOR(i,1,n+1) cin >> p[i];
    
    ll ans = 0;
    ll cnt = 0;
    FOR(i,1,n+1){
        if(p[i] == i){
            cnt++; continue;
        }
        else{
            ans += (cnt + 1) / 2;
            cnt = 0;
        }
    }
    ans += (cnt + 1) / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
    long long int n,t,a,m=1000000000,q=0;
    cin>>n>>t>>a;
    t=1000*t;
    a=1000*a;
    vector<int>h(1000000);
    for(int i=0;i<n;i++){
        cin>>h[i];
        h[i]=6*h[i];
    }
    for(int i=0;i<n;i++){
        if(abs(t-h[i]-a)<m){
            m=abs(t-h[i]-a);
            q=i+1;
        }
    }
    cout<<q<<endl;
    return 0;
}

Measured memory_bytes: 4096
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <algorithm>
using namespace std;

#define nln        puts("")                         ///printnewline
#define getint(a)  scanf("%d",&a);
#define max3(a,b,c) max(a,max(b,c))                  ///3 ta theke max
#define min3(a,b,c) min(a,min(b,c))                  ///3 ta theke min

#define FOR1(i,n)  for(int i=1;i<=n;i++)
#define FOR0(i,n)  for(int i=0;i<n;i++)                 ///looping
#define FORR(i,n)  for(int i=n-1;i>=0;i--)
#define ALL(p)     p.begin(),p.end()

#define SET(p)     memset(p,-1,sizeof(p))
#define CLR(p)     memset(p,0,sizeof(p))            ///memset
#define MEM(p,v)   memset(p,v,sizeof(p))

#define READ(f)    freopen(f, "r", stdin)           /// file
#define WRITE(f)   freopen(f, "w", stdout)

#define SZ(c)      (int)c.size()
#define PB(x)      push_back(x)                     ///STL defines
#define MP(x,y)    make_pair(x,y)
#define ff         first
#define ss         second

#define LI         long int
#define LLI        long long int
#define f64        long double
#define PI         acos(-1.0)                        ///PI er value

int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
void CI(int &_x)
{
    scanf("%d",&_x);
}

void CO(int &_x)
{
    cout<<_x;
}

template<typename T> void getarray(T a[],int n)
{
    for(int i=0; i<n; i++) cin>>a[i];
}
template<typename T> void printarray(T a[],int n)
{
    for(int i=0; i<n-1; i++) cout<<a[i]<<" ";
    cout<<a[n-1]<<endl;
}

const double EPS=1e-9;                              ///constatnts
const int INF=0x7f7f7f7f;

int dr8[8]= {1,-1,0,0,1,-1,-1,1};            ///8 direction move
int dc8[8]= {0,0,-1,1,1,1,-1,-1};
int dr4[4]= {0,0,1,-1};                      ///4 direction move
int dc4[4]= {-1,1,0,0};                      ///or adjacent dir.
int kn8r[8]= {1,2,2,1,-1,-2,-2,-1};          ///knight moves
int kn8c[8]= {2,1,-1,-2,-2,-1,1,2};


int main()
{
    //READ("input.txt");
    //WRITE("output.txt");
    int a,b;
    while(cin>>a>>b){

    int sum=a+b;
    int ans=0;
    while(sum){

    sum=sum/10;
    ans++;
    }
    cout<<ans<<"\n";

    }
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;
long long getGCD(long long max, long long min);
long long getSaidaKoubaisuu(long long l , long long l2);
int main()
{
#ifdef LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    int n;
    cin >> n;

    vector<long long> t;

    for(int i=0;i<n;i++){
        long long temp;
        cin >> temp;
        if(std::count(t.begin(), t.end(), temp) == 0){
            t.push_back(temp);
        }
    }

    long long saidaikouyakusuu = t[0];
    for(int i=0;i<t.size();i++){
        for(int j=i+1;j<t.size();j++){
            long long tempSaidaikoubaisuu = getSaidaKoubaisuu(t[i], t[j]);

            if(saidaikouyakusuu == -1){
                saidaikouyakusuu = tempSaidaikoubaisuu;
            }
            else{
                saidaikouyakusuu = getSaidaKoubaisuu(saidaikouyakusuu, tempSaidaikoubaisuu);
            }
        }
    }

    cout << saidaikouyakusuu << endl;

    return 0;
}
long long getGCD(long long mx, long long mn){
    if(mn == 1)return 1;

    long long a = mx;
    long long b = mn;
    while(b != 0){
        
        long long mod = a%b;
        a = b;
        b = mod;
    }
    return a;
}
long long getSaidaKoubaisuu(long long l1 , long long l2){
    long long gcd = getGCD(max(l1,l2), min(l1,l2));
    return l1/gcd*l2;
}

Measured memory_bytes: 256
N = int(input())
c = input()
rnum = 0
okrnum = 0
wnum = 0
for i in range(N):
  if(c[i]=="R"):
    rnum += 1
  else:
    wnum += 1
if(rnum == 0 or wnum == 0):
  print(0)
else:
  for i in range(rnum):
    if(c[i]=="R"):
      okrnum += 1
  #print(rnum , wnum, okrnum)
  #print("ans =",rnum-okrnum)
  print(rnum - okrnum)

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

using namespace std;

const int INF = 1e9;
const long double PI = 3.1415926535;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	if (y1 > y2) {
		swap(x1, x2);
		swap(y1, y2);
	}

	bool flag = false;
	if (x1 > x2) {
		flag = true;
		x1 = -x1;
		x2 = -x2;
	}

	int n;
	cin >> n;
	vector<int> X(n), Y(n), idxs;
	int hogex = INF, hogey = INF;
	for (int i = 0; i < n; i++) {
		cin >> X[i] >> Y[i];
		if (flag) X[i] = -X[i];
		if (Y[i] < y1 || Y[i] > y2) continue;
		if (X[i] < x1 || X[i] > x2) continue;
		if (Y[i] == y1){
			hogex = X[i];
		} 
		if (X[i] == x1) {
			hogey = Y[i];
		}
		idxs.push_back(i);
	}
	sort(idxs.begin(), idxs.end(), [&](const int& i1, const int& i2){return X[i1] < X[i2];});

	long double ans = (y2 - y1) + (x2 - x1);
	ans *= 100;
	if (x1 == x2) {
		if (hogey != INF) ans += (PI - 2) * 10;
	} else if (y1 == y2) {
		if (hogex != INF) ans += (PI - 2) * 10;
	} else if (!idxs.empty()) {
		vector<int> dp(idxs.size(), INF);
		for (int idx : idxs) {
			*lower_bound(dp.begin(), dp.end(), Y[idx]) = Y[idx];
		}
		int foo = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
		if (foo == min(x2 - x1, y2 - y1) + 1) {
			foo -= 1;
			ans += (PI - 2) * 10;
		}		
		ans -= (2 - PI / 2) * 10 * foo;
	}
	cout << fixed << setprecision(15) << ans << endl;
	return 0;
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint
{
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
struct combination
{
    vector<mint> fact, ifact;
    combination(int n) : fact(n + 1), ifact(n + 1)
    {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i)
            fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i)
            ifact[i - 1] = ifact[i] * i;
    }
    mint operator()(int n, int k)
    {
        if (k < 0 || k > n)
            return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};
signed main()
{
    int k;
    cin >> k;
    string s;
    cin >> s;
    int n = s.size();
    mint ans = 0;
    combination c(n + k);
    for (int i = 0; i <= k; i++)
    {
        int j = k - i;
        mint now = mint(25).pow(j);
        now *= mint(26).pow(i);
        now *= c(j + n - 1, n - 1);
        ans += now;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35576