akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
 
using namespace std;
 
struct Node{
    Node(){
        left_child = right_child = parent = -1;
    };
    int left_child,right_child,parent;
};
 
void preORDER(Node order[],int id){
    printf(" %d",id);
    if(order[id].left_child != -1) preORDER(order,order[id].left_child );
    if(order[id].right_child != -1) preORDER(order,order[id].right_child );
}
 
void inORDER(Node order[],int id){
    if(order[id].left_child != -1) inORDER(order,order[id].left_child );
    printf(" %d",id);
    if(order[id].right_child != -1) inORDER(order,order[id].right_child );
}
 
void postORDER(Node order[],int id){
    if(order[id].left_child != -1) postORDER(order,order[id].left_child );
    if(order[id].right_child != -1) postORDER(order,order[id].right_child );
    printf(" %d",id);
}
 
int main(){
    int n,id,left,right,root_id;
    scanf("%d",&n);
    Node order[n];
    for(int i = 0; i < n; i++){
        scanf("%d %d %d",&id,&left,&right);
        if(left != -1){
            order[id].left_child = left;
            order[left].parent = id;
        }
        if(right != -1){
            order[id].right_child = right;
            order[right].parent = id;
        }
    }
 
    for(root_id = 0; root_id < n; root_id++){
        if(order[root_id].parent == -1) break;
    }
 
    printf("Preorder\n");
    preORDER(order,root_id);
    printf("\n");
 
    printf("Inorder\n");
    inORDER(order,root_id);
    printf("\n");
 
    printf("Postorder\n");
    postORDER(order,root_id);
    printf("\n");
}


Measured memory_bytes: 2756
N = int(input())
l = 0
r = (N - 1)
m = (l + r) // 2

print(l)
l_stat = input()
if l_stat == "Vacant":
  exit()

print(m)
m_stat = input()
if m_stat == "Vacant":
  exit()

while True:
  if ((m - l) % 2 == 0 and l_stat == m_stat) or ((m - l) % 2 == 1 and l_stat != m_stat):
    l, m = m, (m + r + 1) // 2
    l_stat = m_stat
    print(m)
    m_stat = input() 
    if m_stat == "Vacant":
      exit()
  else:
    m, r = (l + m) // 2, m
    print(m)
    m_stat = input()
    if m_stat == "Vacant":
      exit()


Measured memory_bytes: 3660
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;


int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

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

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

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



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

	string s;
	cin >> n >> s;
	vector<bool> x(26);
	vector<bool> y(26);

	int ans = 0;
	rep(i, 0, n) {

		int tmp = 0;
		rep(j, 0, 26) {
			x[j] = false;
			y[j] = false;
		}
		rep(j, 0, i+1) {
			x[s[j] - 'a'] = true;
		}
		rep(j, i + 1, n) {
			y[s[j] - 'a'] = true;
		}

		rep(j, 0, 26) {
			if (x[j] == true && y[j] == true) {
				tmp++;
			}
		}

		ans = max(ans, tmp);

	}
	
	
		
	cout << ans << endl;
	
	
	
}
	

Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<deque>
#include<string>
#define dint __int128
using namespace std;
#define kk putchar(32)
#define gc getchar()
#define fup(i,a,b) for(int i=a,i##e=b;i<=i##e;++i)
#define fdn(i,a,b) for(int i=a,i##e=b;i>=i##e;--i)
#define mem(a,b) memset(a,b,sizeof(a))
#define hh putchar(10)
#define ll long long
inline ll rrr(){ll x,f=1;char a;while((a=gc)<48||a>57)if(a==45)f=-1;
for(x=a^48;(a=gc)>47&&a<58;x=(x<<3)+(x<<1)+(a^48));return f*x;}
void Main();int main(){Main();return 0;}

int a[100005];
void Main()
{
    int n;cin>>n;
    fup(i,1,n)a[i]=rrr();
    int ans=0;
    fup(i,1,n){
        if(a[i]==i)++ans,++i;
    }
    cout<<ans;
}




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

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, m;
	while(cin >> n && n){
		cin >> m;
		
		string s;
		cin >> s;
		
		string str;
		for(int i = 0; i != m; ++i){
			if(i != 0 && s[i] == 'O' && s[i - 1] == 'I')
				str += 'J';
			else if(!(s[i] == 'I' && s[i + 1] == 'O'))
				str += s[i];
		}
		//cout << str <<endl;
		
		int ans = 0;
		int now = 0;
		for(size_t i = 0; i != str.size(); ++i){
			if(str[i] != 'O'){
				if(now >= n) ans++;
				
				if(str[i] == 'J')
					now ++;
				if(str[i] == 'I')
					now = 0;
			}
			else
				now = 0;
		}
		
		cout << ans << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 3156
using System;
using System.Linq;
 
class b{
  static void Main(){
    int N = int.Parse(Console.ReadLine());
    int[] L = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
    Array.Sort(L);
    Array.Reverse(L);
    int S = L.Sum() - L[0];
    if (L[0] < S) Console.WriteLine("Yes");
    else Console.WriteLine("No");
  }
}

Measured memory_bytes: 18820
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from collections import deque as deq

A = deq(list(input()))
B = deq(list(input()))
C = deq(list(input()))

S = {
    'a': A,
    'b': B,
    'c': C
}

def check(s):
    if len(S[s]) == 0:
        return s.upper()
    else:
        return check(S[s].popleft())

print(check('a'))


Measured memory_bytes: 3444
N = int(input())

s_p, e_p = [0] * N, [0] * N
for i in range(N):
    X, L = map(int, input().split())
    s_p[i] = X - L
    e_p[i] = X + L

# sort by end point
c = sorted(zip(e_p, s_p))
e_p, s_p = zip(*c)

# greedy
e = -float('inf')
count = 0
for i in range(N):
    if s_p[i] >= e:
        count += 1
        e = e_p[i]
print(count)

Measured memory_bytes: 26992
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

int n, m;
bool g[60][60];
bool seen[60];

void dfs(int v) {
  if(seen[v]) return;
  seen[v] = true;
  rep(i,n) if(g[v][i]) dfs(i);
}

int main() {
  cin >> n >> m;
  vi a(m), b(m);
  rep(i,m) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    g[a[i]][b[i]] = true;
    g[b[i]][a[i]] = true;
  }
  int ans = 0;
  rep(i,m) {
    rep(i,n) seen[i] = false;
    g[a[i]][b[i]] = false;
    g[b[i]][a[i]] = false;
    dfs(0);
    bool ok = true;
    rep(i,n) if(!seen[i]) ok = false;
    if(!ok) ans++;
    g[a[i]][b[i]] = true;
    g[b[i]][a[i]] = true;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;cin>>n>>k;
    double p;
    vector<double> ruiseki(n+1,0);
    for(int i=0;i<n;i++){
        cin>>p;
        ruiseki[i+1]=ruiseki[i]+p*(p+1)/(2*p);
    }
    double ans=0;
    for(int i=k;i<n+1;i++){
        ans=max(ans,ruiseki[i]-ruiseki[i-k]);
    }
    printf("%.10f\n",ans);
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int n;
int dp[500][500];
vector<int> w;

// [l,r)
int rec(int l, int r){
    if(dp[l][r] >= 0) return dp[l][r];
    if(r-l<2) return 0;

    int res = 0;
    res = max(res, rec(l,r-2)+(abs(w[r-2]-w[r-1])<=1?2:0));
    res = max(res, rec(l+2,r)+(abs(w[l]-w[l+1])<=1?2:0));
    if(rec(l+1,r-1) == r-l-2){
        res = max(res, r-l-2+(abs(w[l]-w[r-1])<=1?2:0));
    }
    else{
        res = max(res, rec(l+1,r-1));
    }
    for(int i=1;i<r-l;i++){
        res = max(res, rec(l,l+i)+rec(l+i,r));
    }
    return dp[l][r] = res;
}

int main() {
    while(cin >> n, n){
        w.resize(n);
        REP(i,n){
            cin >> w[i];
        }
        REP(i,n+1) fill(dp[i],dp[i]+n+1,-1);
        cout << rec(0,n) << endl;
    }
    return 0;
}


Measured memory_bytes: 3684
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll a=0;
    string s,t;
    cin>>s>>t;
    for(ll i=0;i<3;i++){
        if(s[i]==t[i]) a++;
    }
    cout<<a<<endl;
    return 0;
}

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

template<class T> struct QueueAggregation {
    using F = function<T(T, T)>;
private :
    struct node {
        T val, sum;
        node (const T &v, const T &s) : val(v), sum(s) { }
    };
    F op;
    stack<node> front_stack, back_stack;
public :
    QueueAggregation (const F &op)
        : op(op), front_stack(), back_stack() { }

    bool empty() const { return front_stack.empty() && back_stack.empty(); }

    size_t size() const { return front_stack.size() + back_stack.size(); }

    T fold_all() const {
        assert(!empty());
        if (front_stack.empty()) {
            return back_stack.top().sum;
        } else if (back_stack.empty()) {
            return front_stack.top().sum;
        } else {
            return op(front_stack.top().sum, back_stack.top().sum);
        }
    }

    void push(const T &x) {
        if (back_stack.empty()) {
            back_stack.emplace(x, x);
        } else {
            T s{op(back_stack.top().sum, x)};
            back_stack.emplace(x, s);
        }
    }

    void pop() {
        assert(!empty());
        if (front_stack.empty()) {
            front_stack.emplace(back_stack.top().val, back_stack.top().val);
            back_stack.pop();
            while (!back_stack.empty()) {
                T s{op(back_stack.top().val, front_stack.top().sum)};
                front_stack.emplace(back_stack.top().val, s);
                back_stack.pop();
            }
        }
        front_stack.pop();
    }

};

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    vector<int> s(n, 1);
    for (auto& e : a) cin >> e;
    for (int i = 0; i < n-1; i++) {
        if (a[i] < a[i+1]) s[i+1] += s[i];
    }
    
    auto f = [](int a, int b) { return max(a, b); };
    auto g = [](int a, int b) { return min(a, b); };
    QueueAggregation<int> qa1(f), qa2(g);
    
    int cnt = count_if(s.begin(), s.end(), [&](int x){return x == k;});
    int ans = (cnt < 2 ? 1 : -cnt + 2);
    for (int i = 0; i < k; i++) { qa1.push(a[i]); qa2.push(a[i]); }
    for (int i = k; i < n; i++) {
        qa1.push(a[i]); qa2.push(a[i]);
        int next = a[i], last = a[i-k];
        int nax = qa1.fold_all(), nin = qa2.fold_all();
        if (next != nax || last != nin) ans++;
        qa1.pop(); qa2.pop();
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5120
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>

using namespace std;

typedef long long int Int;

vector< pair<int,int> > red,blue;
bool used[100];

int main(void) {
    int N;
    cin>>N;

    fill(used,used+N,0);
    for(int i = 0;i < N;i++) {
        pair<int,int> temp;
        cin>>temp.first>>temp.second;
        red.push_back(temp);
    }

    for(int i = 0;i < N;i++) {
        pair<int,int> temp;
        cin>>temp.first>>temp.second;
        blue.push_back(temp);
    }

    sort(red.begin(),red.end());
    sort(blue.begin(),blue.end());
    
    int sum = 0;
    for(int i = 0;i < N;i++) {
        int my = -1;
        int index = -1;
        for(int j = 0;j < N;j++) {
            if(!used[j] && red[j].first < blue[i].first && red[j].second < blue[i].second) {
                if(red[j].second > my) {
                    my = red[j].second;
                    index = j;
                }
            }
        }

        if(index != -1) {
            sum++;
            used[index] = true;
        }
    }

    cout<<sum<<endl;

    return 0;
}
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
   string S, s = "abcdefghijklmnopqrstuvwxyz";
   cin >> S;
   int size = S.size(), c;
   for(int i = 0; i < size; i++){
       for(int j = 0; j < 26; j++){
           if(S[i] == s[j]){
               c++;
               s[j] = '0';
           }
       }
   }
   for(int i = 0; i < 26; i++){
       if(s == "00000000000000000000000000"){
           cout << "None" << endl;
           return 0;
       }
       if(s[i] != '0'){
           cout << s[i] << endl;
           return 0;
       }
   }
   return 0;
}


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

using namespace std;

int main()
{

	int t;
	t=1;
//	cin>>t;
	while(t--)
	{
	  int n,i,j;
	  cin>>n;
	  
	  string s;
	  cin>>s;
	  
	  if(s.length()<=n)
	  cout<<s;
	  
	  else
	  {
	  	 
	  	 for(i=0;i<n;i++)
	  	 cout<<s[i];
	  	 
	  	 cout<<"...";
	  	
	  	
	  	
	  }
	   
	   cout<<endl;
	}



}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
const int INF = 1001001001;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
int main(){
  int h,w;
  cin >> h  >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  int ans =0;
  rep(si,h) rep(sj,w){
    if(s[si][sj] == '#') continue;
    vector<vi> dist(h,vi(w,INF));
    queue<P> q;
    auto update = [&](int i, int j, int x){
      if(dist[i][j] != INF) return;
      dist[i][j] = x;
      q.emplace(i,j);
    };
    update(si,sj,0);
    while(!q.empty()){
      int i = q.front().first;
      int j = q.front().second;
      q.pop();
      rep(dir,4){
        int ni = i+di[dir],nj = j+dj[dir];
        if(ni <0 || ni>=h ||nj<0||nj>=w) continue;
        if(s[ni][nj] =='#') continue;
        update(ni,nj,dist[i][j]+1);
      }
    }
    for(auto vv: dist){
      for(auto v:vv){
        if(v ==INF) continue;
        maxs(ans,v);
      }
    }
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];
    vector<vector<int>> ans(h, vector<int>(w));
    int x = 0, y = 0;
    int cnt = 0;
    int now = 0;
    while(cnt < h * w){
        ans[x][y] = now + 1;
        ++cnt;
        if(--a[now] == 0)   ++now;
        if(x % 2 == 0){
            if(y == w - 1)  ++x;
            else    ++y;
        }
        else{
            if(y == 0)  ++x;
            else    --y;
        }
    }
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            cout << ans[i][j] << ((j == w - 1) ? "\n" : " ");
        }
    }    
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
int main()
{
	int n;
	std::cin >> n;

	std::vector<int> p;

	int temp;
	int i = 1;
	while (std::cin >> temp) {
		p.push_back(temp);
		i++;
		if (i > n)
			break;
	}


	int count = 0;
	for (int i = 1; i < p.size() - 1; i++) {
		if (p[i] > p[i - 1] && p[i] < p[i + 1])
			count++;
		if (p[i] > p[i + 1] && p[i] < p[i - 1])
			count++;
	}

	std::cout << count << std::endl;
		
	return 0;
}

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

using namespace std;

vector<pair<int, char>> A(9);
int num,n;
char c;

int ans(){
    for(int i = 0;i < 3;i++){
        if(A[i*3].first + A[i*3+1].first == A[i*3+2].first*2
           && A[i*3].second == A[i*3 + 2].second && A[i*3 + 2].second == A[i*3+1].second){
            A[i*3].first = 0;
            A[i*3+1].first = 0;
            A[i*3+2].first = 0;
        }else{
            for(int j = i*3;j < 9;j++){
                if(A[j].first == A[i*3].first+1 && A[j].second == A[i*3].second){
                    for(int k = j;k < 9;k++){
                        if(A[k].first == A[j].first + 1 && A[k].second == A[j].second){
                            A[i*3].first = 0;
                            A[j].first = 0;
                            A[k].first = 0;
                            break;
                        }
                    }
                    break;
                }
            }
        }
        sort(A.begin(),A.end());
    }
//    for(int i = 0;i < 9;i++)cout << A[i].first << " ";
//    cout << endl;
    for(int i = 0;i < 9;i++){
        if(A[i].first > 0)return 0;
    }
    return 1;
}

int main(){
    cin >> n;
    for(int j = 0;j < n;j++){
        for(int i = 0;i < 9;i++){
            cin >> A[i].first;
        }
        for(int i = 0;i < 9;i++){
            cin >> A[i].second;
        }
        sort(A.begin(),A.end());
        cout << ans() << endl;
    }
}

Measured memory_bytes: 3068
#include<algorithm>
#include<string>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<utility>
#include<functional>
#include<cassert>
#include<cmath>
#include<math.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<vint> vvint;
#define PI 3.1415926535;


int main(void) {
	int r;
	cin >> r;
	cout << r * r;
	
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

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

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a[10000000],b[10000000],c,cmp,cmpp,m,h,w,x,y,sum=0;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true,graph[100][100];

int dfs(int now,int nn,bool* visited){
  bool  allvisited=true;
    rep(i,nn){
        if(!visited[i]){
            allvisited=false;
        }
    }
  int pos=0;
    if(allvisited){
        return 1;
    }
    rep(i,nn){
        if(!graph[now][i]){
            continue;
        }
        if(visited[i]){
            continue;
        }
        visited[i]=true;
        pos+=dfs(i,nn,visited);
        visited[i]=false;
    }
    
    return pos;
}

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

      cin >> n >> m;
      rep(i,m){cin>>a[i]>>b[i];
      graph[a[i]-1][b[i]-1]=graph[b[i]-1][a[i]-1]=true;
      }
      bool visited[100];
      rep(i,n){
          visited[i]=false;
      }
      
      visited[0]=true;
     Cout(dfs(0,n,visited));
return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    pair<int , int> p[N];
    int A, B;
    for(int i=0;i<N;i++){
        cin >> A >> B;
        p[i] = make_pair(A, B);
    }
        
    // 昇順ソート
    sort(p, p + N);
    
    cout << p[N-1].first + p[N-1].second << endl;

}

Measured memory_bytes: 1024
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    l=list(map(int,input().split()))
    samunenum=100
    samune=10**18
    for i in range(n):
        x=abs(sum(l)-n*l[i])
        if x<samune:
            samunenum=i
            samune=x
    print(samunenum)
resolve()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll ;
const int maxn = 1e5 + 5 ;
int A , B , M ;
int a[maxn] , b[maxn] ; 
int x[maxn] , y[maxn] , c[maxn] ;
int main()
{
	int ans = 1e9 ;
	scanf("%d%d%d" , &A , &B , &M) ;
	for(int i = 1 ; i <= A ; i ++)  scanf("%d" , &a[i]) ;
	for(int i = 1 ; i <= B ; i ++)  scanf("%d" , &b[i]) ;
	for(int i = 1 ; i <= M ; i ++)  
	  scanf("%d%d%d" , &x[i] , &y[i] , &c[i]) ;
	int min1 = 1e9 ;
	for(int i = 1 ; i <= A ; i ++)  min1 = min(min1 , a[i]) ;
	int min2 = 1e9 ; 
	for(int i = 1 ; i <= B ; i ++)  min2 = min(min2 , b[i]) ;
	ans = min(ans , min1 + min2) ;
	for(int i = 1 ; i <= M ; i ++)
	  ans = min(ans , a[x[i]] + b[y[i]] - c[i]) ;
	printf("%d\n" , ans) ;
	return 0 ;
}

Measured memory_bytes: 2176
#include <stdio.h>

int main(void) {
	int input1, input2;      /* 入力値 */
	int buff;               /* 計算値バッファ */
	int i;                     /* loopcounter */

	while (scanf("%d %d", &input1, &input2) != EOF) {

		buff = input1 + input2;
		i = 1;

		while (buff >= 10) {
			buff /= 10;
			i++;
		}

		printf("%d\n", i);
	}


	return 0;
}


Measured memory_bytes: 2584
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int i,x,y;
		Scanner sc = new Scanner(System.in);
		for(i=1;;i++){
			x=sc.nextInt();
			y=sc.nextInt();
			if((x == 0&&y == 0)){
			    sc.close();
			    break;
			}
			if(x < y){
			    System.out.println(x+" "+y);
			}
			else{
			    System.out.println(y+" "+x);
			}
		}
		sc.close();
	}

}


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

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

  for(int i=0;i<S.size()-1;i++){
    if(S.at(i)!=S.at(i+1)){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}


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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double pi = 3.14159265358979323846;

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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 main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m;
  cin >> n >> m;
  if (n == m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

int main(){
  int N, tmp;
  cin >> N;
  vector<int> a(N);
  int all = 0;
  rep(i,N){
    cin >> tmp;
    a.at(i) = tmp;
    all = all^tmp;
  }
  
  int ans = all;
  rep(i,N-1){
    ans = all^(a.at(i));
    cout << ans << ' ';
  }
  ans = all^a.at(N-1);
  cout << ans << endl;
}

Measured memory_bytes: 3992
'use strict'
function main(inp) {
  inp = inp.trim().split('\n')
  const N = Number(inp.shift())
  inp = inp.map(S => {
    return S.split('').sort().join('')
  }).sort();

  let ans = 0
  let obj = {}

  for (let i = 0; i < N; i++) {
    if (!(inp[i] in obj)) obj[inp[i]] = 0
    obj[inp[i]]++
  }

  Object.keys(obj).forEach(key => {
    if(obj[key] > 1) {
      ans += obj[key] * (obj[key] - 1) / 2
    }
  })
  console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 62684
# -*- coding: utf-8 -*-

import sys
import os
import math

for s in sys.stdin:
    n = int(s)
    if n == 0:
        break

    M = [[None for i in range(n)] for j in range(n)]

    # 1
    x = n // 2
    y = n // 2 + 1
    M[y][x] = 1
    x = x + 1
    y = y + 1
    counter = 2

    while counter < n * n + 1:

        if x >= n:
            x = 0
        elif x < 0:
            x = n - 1

        if y >= n:
            y = 0
        elif y < 0:
            y = n - 1

        if M[y][x] is not None:
            x -= 1
            y += 1
        else:
            M[y][x] = counter
            counter += 1
            x += 1
            y += 1

    for row in M:
        for v in row:
            print(str(v).rjust(4), end='')
        print()

Measured memory_bytes: 7792
var
	N,i,j,k:Longint;
	A,B,C,S,cx,cy,cr:double;
	x,y:Array[1..50]of double;
function norm(x1,y1,x2,y2:double):double;
begin
	norm:=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
end;
function ok(id:Longint):Boolean;
begin
	ok:=norm(x[id],y[id],cx,cy)<cr+0.0000000001;
end;
procedure make(ia,ib:Longint);
begin
	cx:=(x[ia]+x[ib])/2;
	cy:=(y[ia]+y[ib])/2;
	cr:=norm(x[ia],y[ia],cx,cy);
end;
begin
	read(N);
	for i:=1 to N do read(x[i],y[i]);
	make(1,2);
	for i:=3 to N do if not ok(i)then begin
		make(1,i);
		for j:=2 to i-1 do if not ok(j)then begin
			make(i,j);
			for k:=1 to j-1 do if not ok(k)then begin
				A:=norm(x[j],y[j],x[k],y[k]);
				B:=norm(x[k],y[k],x[i],y[i]);
				C:=norm(x[i],y[i],x[j],y[j]);
				S:=(x[j]-x[i])*(y[k]-y[i])-(x[k]-x[i])*(y[j]-y[i]);
				S:=4*S*S;
				cx:=(A*(B+C-A)*x[i]+B*(C+A-B)*x[j]+C*(A+B-C)*x[k])/S;
				cy:=(A*(B+C-A)*y[i]+B*(C+A-B)*y[j]+C*(A+B-C)*y[k])/S;
				cr:=norm(x[i],y[i],cx,cy);
			end;
		end;
	end;
	writeln(sqrt(cr):0:9);
end.


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

#define forn(i,a,b) for(int i=(a);i<(b); ++i)
#define nfor(i,b,a) for(int i=(b-1);i>=a;--i)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define ifile freopen("point1.in", "r", stdin)
#define ofile freopen("point1.out   ", "w", stdout)
#define fast ios_base::sync_with_stdio(0);\
             cin.tie(0);\
             cout.tie(0);
//#define mp make_pair
#define pb push_back
//#define mt make_tuple
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ll_min LONG_LONG_MIN
#define ll_max LONG_LONG_MAX
#define _1 first
#define _2 second
#define sqr(a) ((a)*(a))
const ld PI = 3.141592653589793238462643383279;
const ld EPS = 1e-6;
const ll INF = 1e9 + 7;
const ll MOD = INF;
const ll maxn = 2e5+2;
const ll HASH_MODS[] = { 1000000007333,1000000009367, 1000000075747, 1000000158923, 1000000203119 };
//||||||||||||||||||||LOCAL||||||||||||||||||||||||||
int ma[100][100];
int main(){
    int n,m;
    cin>>n>>m;
    forn(i,0,m){
        int a,b;
        cin>>a>>b;
        ma[a][b]=true;
        ma[b][a]=true;
    }
    string s="";
    forn(i,1,n)
        s+='1'+i;
    int ans=0;
    if (ma[1][2]){
        bool t=true;
        forn(i,2,n)
            if (!ma[i][i+1])
                t=false;
        if (t)
            ans++;
    }
    while (next_permutation(s.begin(),s.end())){
       // cout<<s<<"\n";
        if (ma[1][s[0]-'0']){
                bool t=true;
            forn(i,0,n-2){
                //cout<<s[i]-'0'<<" "<<s[i+1]-'0'<<" "<<ma[s[i]-'0'][s[i+1]-'0']<<"\n";
                if (!ma[s[i]-'0'][s[i+1]-'0'])
                    t=false;
            }
            if (t){
                ++ans;
         //       cout<<"ww";
            }
        }

    }
    cout<<ans;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

s = input()

a = int(s[0])*10 + int(s[1])
b = int(s[2])*10 + int(s[3])

if 1<=a<=12 and 1<=b<=12:
    print('AMBIGUOUS')
elif 1<=a<=12:
    print('MMYY')
elif 1<=b<=12:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(a) for(int k=head[a];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=1e6+5,M=5e3+5,INF=1e9,mod=998244353;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
map<ll,ll>cnt;
int main(){
	ll n=read(),ans=0;
	rep(i,1,n){
		ll o,x=1,y=1;read(o);
		for(ll i=2;i*i*i<=o;i++){
			ll c=0;while(o%i==0)o/=i,(++c)%=3;
			if(c==1)x=x*i,y=y*i*i;
			if(c==2)x=x*i*i,y=y*i;
		}x*=o;
		if((ll)sqrt(o)*(ll)sqrt(o)==o)y*=sqrt(o);else y=y*o*o;
		cnt[x]++;
		if(x==1){if(cnt[x]==1)ans++;}else
			if(cnt[x]>cnt[y])ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int fa[200004];
int son[200004];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=2;i<=n;i++){
		scanf("%d",&fa[i]);
		son[fa[i]]++;
	}
	for(int i=1;i<=n;i++){
		printf("%d\n",son[i]);
	}
}

Measured memory_bytes: 5372
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;

public class Main {

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

		// 入力
		int A = sc.nextInt();
		int B = sc.nextInt();
		BigDecimal a = new BigDecimal(A).divide(new BigDecimal(0.08),0,RoundingMode.UP);
		BigDecimal b = new BigDecimal(B).divide(new BigDecimal(0.1),0,RoundingMode.UP);
//		double a = A / 0.08;
//		double b = B / 0.1;
		BigDecimal min = a.compareTo(b) == -1 ? a : b; 
		BigDecimal max = a.compareTo(b) == -1 ? b : a; 
//		BigDecimal min = a < b ? new BigDecimal(a) : new BigDecimal(b); 
//		BigDecimal max = a < b ? new BigDecimal(b) : new BigDecimal(a); 
		
		int ans = -1;
		for (int i = min.intValue(); i <= max.intValue(); i++) {
			BigDecimal x = new BigDecimal(i).multiply(new BigDecimal(0.08)).setScale(0,BigDecimal.ROUND_DOWN);
			BigDecimal y = new BigDecimal(i).multiply(new BigDecimal(0.1)).setScale(0,BigDecimal.ROUND_DOWN);
			if (x.compareTo(new BigDecimal(A)) == 0 && y.compareTo(new BigDecimal(B)) == 0) {
				ans = i;
			}
		}
		System.out.println(ans);			
	}

	
	// ユークリッドの控除法(最大公約数を求める)
	private static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	// 複数の最大公約数を求める
	private static long gcdex(long param[]) {
		long g = gcd(param[0], param[1]);
		for (int i = 1; i < param.length-1; i++) {
			g = gcd(g, param[i+1]);
		}
		return g;
	}

	// 最小公倍数を求める
	private static long lcm(long a, long b) {
		return (a * b) / gcd(a, b);
	}

	//
	private static long all(long n, long count, int N) {
		if (count == N) {
			return count;
		}
		return all(1, count, N);
	}

}

Measured memory_bytes: 24644
import java.util.*;

public class Main{

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int Q = sc.nextInt();
        int[] l = new int[Q];
        int[] r = new int[Q];
        for(int i = 0; i < Q; i++){
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
        }
        sc.close();

        int max = 100000;

        int[] c = new int[100001];
        c[0] = -1;
        c[1] = -1;

        for(int i = 2; i <= (int)Math.sqrt(max); i++){
            if(c[i] == 0){
                for(int j = i*i; j <= max; j = j+i){
                    c[j] = -1;
                }
            }
        }

        /* for(int i = 2; i <= max; i++){
            if(c[i] == 0)
                System.out.println(i);
        } */

        int[] s = new int[max+1];

        for(int i = 2; i <= max; i++){
            if(c[i] == 0 && c[(i+1)/2] == 0)
                s[i] = s[i-1]+1;
            else
                s[i] = s[i-1];
        }
        for(int i = 0; i < Q; i++){
            System.out.println(s[r[i]] - s[l[i]-1]);
        }
    }
}

Measured memory_bytes: 75920
#include <iostream>
int f(int n, int y) {
	auto a = (5000 * n - y) / 4000;
	auto b = (y - 1000 * n) / 4000;
	return (a >= 0 && b >= 0 && a + b == n && a * 1000 + b * 5000 == y) ? b : -1;
}
int main() {
	int n, y;
	std::cin >> n >> y;
	int a{ -1 }, b{ -1 }, c{ -1 };
	for (a = 0; a <= n; ++a) {
		if (f(n - a, y - 10000 * a) != -1) {
			b = f(n - a, y - 10000 * a);
			c = (y - 10000 * a - 5000 * b) / 1000;
			break;
		}
	}
	if (b == -1) std::cout << "-1 -1 -1";
	else std::cout << a << ' ' << b << ' ' << c;
}

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

void chmax(int& a, int b) {
  if (a < b) a = b;
}

int main() {
  int N, K;
  cin >> N >> K;
  
  string S;
  cin >> S;
  
  
  
  // 1, 0の変わり目の左端を見つける
  
  vector<int> leftbound;
  leftbound.push_back(0);
  leftbound.push_back(0);
  char temp = S[0];
  for (int i = 0; i < N; i++) {
    if (S[i] != temp) {
      leftbound.push_back(i);
      temp = S[i];
    }
  }
  leftbound.push_back(N);
  leftbound.push_back(N);
  
  int ans = 0;
  if (S[0] == '0') {
    if (K >= (leftbound.size()-2)/2) {
      cout << N << endl;
      return 0;
    }
    
    for (int i = 1; i + 2 * K < leftbound.size() ; i += 2) {
      chmax(ans, leftbound[i + 2 * K] - leftbound[i-1]);
    }
    
    
  } else {
    if (K >= (leftbound.size() - 3)/2) {
      cout << N << endl;
      return 0;
    }
    
    for (int i = 2; i + 2 * K < leftbound.size() ; i += 2) {

      chmax(ans, leftbound[i + 2 * K] - leftbound[i-1]);
    }    
  }
  
  cout << ans << endl;


}

Measured memory_bytes: 4076
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

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

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    if (b > n) {
        cout << a * n / b << endl;
    }
    else {
        cout << a * (b - 1) / b << endl;
    }
}

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

#define mp make_pair

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

struct edge { pii to; int cost; };

int n,m;
map<pii, vector<edge> > g;
set<pii> use;
typedef pair<pii,int> elem;

int main()
{
  cin >> n >> m;
  int p,q,c;
  for (int i = 0; i < m; i++) {
    cin >> p >> q >> c;
    g[mp(p-1,c)].push_back((edge){mp(q-1,c), 0});
    g[mp(q-1,c)].push_back((edge){mp(p-1,c), 0});

    g[mp(p-1,c)].push_back((edge){mp(p-1,-1), 0});
    g[mp(q-1,c)].push_back((edge){mp(q-1,-1), 0});

    g[mp(p-1,-1)].push_back((edge){mp(q-1,c), 1});
    g[mp(q-1,-1)].push_back((edge){mp(p-1,c), 1});
  }

  deque<elem> que({mp(mp(0,-1),0)});
  while (!que.empty()) {
    pii node; int cost;
    tie(node,cost) = que.front(); que.pop_front();
    if (use.find(node) != use.end()) continue;
    use.insert(node);
    if (node == mp(n-1,-1)) {
      cout << cost << endl;
      return 0;
    }
    for (edge e : g[node]) {
      if (use.find(e.to) != use.end()) continue;
      if (e.cost == 0) que.push_front(mp(e.to,cost));
      else que.push_back(mp(e.to,cost+1));
    }
  }

  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 71552
# AGC023
import collections
N = int(input())
A = list(map(int, input().split()))
ans = 0
S = [0] * (N+1)
for i in range(N):
    S[i+1] = S[i] + A[i]
c = collections.Counter(S)
c = c.most_common()
for i in range(len(c)):
    tmp = c[i][1]
    if tmp == 1:
        pass
    else:
        ans += tmp*(tmp-1) // 2
print(int(ans))

Measured memory_bytes: 48708
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

// GCD, LCM
ll gcd(ll a, ll b) {
  while (b != 0) { a %= b; std::swap(a, b); }
  return a;
}
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

int main()
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  ll cnt = 0;

  ll N;
  std::cin >> N;
  std::vector< ll > va(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
    if (va[i] != i+1) cnt++;
  }

  if (cnt <= 2) print("YES");
  else print("NO");

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<ctime>
#include<cmath>
#include<vector>
#include<set>
#include<queue>
#include<deque>
#include<map>
#include<cstring>
#include<stack>
#include<cctype>
#include<cstdio>
#include<bitset>
#ifdef LOCAL
	#define enu(i,n) for(int i=0;i<n;i++)
	#define tri(x) x*(x+1)/2;
	#define sqrsum(x) x*(x+1)*(2*x+1)/6;
	#define sqrsum_range(a,b) sqrsum(b)-sqrsum(a-1);
#endif
#define FOR(i,a,b) for(int i=a,_b=b;i<_b;i++)
#define REP(i,a,b) FOR(i,a,b+1)
#define ll_max 9223372036854775807LL
#define ll_min -9223372036854775808LL
#define int_max 2147483647
#define int_min -2147483648
#define PI 3.141592653589793238462653383
#define eps 0.00000001
#define elif else if
using namespace std;
void fast()
{
	cin.tie(NULL);
	cout.tie(NULL);
	ios_base::sync_with_stdio(false);
	return ;
}
bool isprime(int x)
{
	if(x<2)
		return false;
	for(int i=2;i<=sqrt(x);i++)
		if(x%i==0)
			return false;
	return true;
}
int GCD(int a,int b)
{
	return (b?GCD(b,a%b):a);
}
struct Tm
{
	int h,m,s;
	bool add()
	{
		s++;
		if(s==60)
			m++,
			s=0;
		if(m==60)
			h++,
			m=0;
		return (h<100);
	}
	void print()
	{
		printf("%02d:%02d:%02d",h,m,s);
		return ;
	}
	void println()
	{
		print();
		puts("");
	}
};
int main()
{
	string S;
	long long K;
	cin>>S>>K;
	vector<long long> V;
	int L=-1;
	for(int i=0;i<S.length();i++)
		if(S[i]!=S[i+1])
		{
			V.push_back(i-L+0LL);
			L=i;
		}
	if(V.size()==1)
		cout<<V[0]*K/2<<endl;
	else if(S[0]==S[S.length()-1])
	{
		long long ans=0;
		for(int i=1;i<V.size()-1;i++)
			ans+=V[i]/2;
		ans+=(V[0]+V.back())/2;
		ans*=K;
		ans-=(V[0]+V.back())/2;
		ans+=V[0]/2;
		ans+=V.back()/2;
		cout<<ans<<endl;
	}
	else
	{
		long long ans=0;
		for(int i=0;i<V.size();i++)
			ans+=V[i]/2;
		cout<<ans*K<<endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll a[100000], b[100000];
int main() {
	int n; cin >> n;
	rep(i, n) {
		cin >> a[i] >> b[i];
	}
	sort(a, a + n,greater<ll>()); sort(b, b + n);
	ll out = 0;
	rep(i, 2) {
		ll sum = 0;
		int chk = i;
		int cnt = 0;
		ll now = 0;
		bool f = false;
		int memo = 1e+7;
		while (cnt < n&&cnt<memo) {
			if (chk % 2) {
				if (now-b[cnt / 2] < 0) {
					f = true; memo = 2 * (cnt / 2) + 3; cnt++; chk = 1 - chk; continue;
				}
				sum += now-b[cnt / 2];
				now = b[cnt / 2];		
			}
			else {
				if (a[cnt / 2]-now < 0) {
					f = true; memo = 2 * (cnt / 2) + 3; cnt++; chk = 1 - chk; continue;
				}
				sum += a[cnt / 2] - now;
				now = a[cnt / 2];
			}
			chk = 1 - chk;
			cnt++;
		}
		sum += abs(now);
		out = max(out, sum);
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 1792