akhauriyash/Code-Regression huggingface dataset:
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <list>

class TVertex
{
    int FIndex;
    int FCommuniyId;
    std::list<TVertex*> FList;

public:
    TVertex(int Index)
     : FIndex(Index), FCommuniyId(0)
    {}
    void AddPath(TVertex* Vertex)
    {
        FList.push_back(Vertex);
    }
    void SetCommunity(int CommunityId)
    {
        if(FCommuniyId) return;
        FCommuniyId = CommunityId;
        for(std::list<TVertex*>::iterator It = FList.begin(); It != FList.end(); ++It){
            TVertex* V = *It;
            V->SetCommunity(CommunityId);
        }
    }
    int CommunityId()const
    {
        return FCommuniyId;
    }
};
class TGraph
{
    std::vector<TVertex*> FTable;
    void Init(int n)
    {
        assert(n > 0);
        FTable.resize(n);
        for(int i = 0; i < n; ++i){
            FTable[i] = new TVertex(i);
        }
    }
public:
    TGraph(int n)
    {
        Init(n);
    }
    void MakeFriend(int s, int t)
    {
        assert(s < FTable.size());
        assert(t < FTable.size());
        FTable[s]->AddPath(FTable[t]);
        FTable[t]->AddPath(FTable[s]);
    }
    void SetCommunity()
    {
        for(std::size_t i = 0; i < FTable.size(); ++i){
            FTable[i]->SetCommunity(i+1);
        }
    }
    bool IsSameCommunity(int s, int t)const
    {
        assert(s < FTable.size());
        assert(t < FTable.size());
        return FTable[s]->CommunityId() == FTable[t]->CommunityId();
    }
};

int main()
{
    int n, m;
    std::scanf("%d %d", &n, &m);
    TGraph Graph(n);
    for(int i = 0; i < m; ++i){
        int s, t;
        std::scanf("%d %d", &s, &t);
        Graph.MakeFriend(s, t);
    }
    int q;
    std::scanf("%d", &q);
    Graph.SetCommunity();
    for(int i = 0; i < q; ++i){
        int s, t;
        std::scanf("%d %d", &s, &t);
        std::printf("%s\n", (Graph.IsSameCommunity(s, t) ? "yes" : "no"));
    }
    return 0;
    
}

Measured memory_bytes: 15148
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define mod 1e9+7
using namespace std;
int ans[3];
int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n; i++)
    {
        int arr[3];
        scanf("%d%d%d", &arr[0], &arr[1], &arr[2]);
        arr[0]=max(arr[0]+ans[1], arr[0]+ans[2]);
        arr[1]=max(arr[1]+ans[0], arr[1]+ans[2]);
        arr[2]=max(arr[2]+ans[0], arr[2]+ans[1]);
        ans[0]=arr[0];
        ans[1]=arr[1];
        ans[2]=arr[2];
    }
    cout<<max({ans[0], ans[1], ans[2]});
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	int a[m];
	for (int i = 0; i < m; i++)
	{
		cin >> a[i];
	}
	int sum, b;
	sum = 0;
	for (int i = 0; i < m; i++)
	{
		sum += a[i];
	}
	b = n - sum;
	if (b < 0)
	{
		b = -1;
	}
	cout << b;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout << endl
#define sp(x) cout << setprecision(x);
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vpii vector<pair<int,int>> 
#define vl vector<ll> 
#define vvl vector<vector<ll>> 
#define vd vector<double> 
#define vvd vector<vector<double>> 
#define vb vector<bool> 
#define vvb vector<vector<bool>>
#define vs vector<string>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a * b / g; }
bool is_prime(ll x) { for (ll i = 2; i * i <= x; i++) { if (x % i == 0)return false; } return true; }


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, n; cin >> h >> n;
	ll a_sum = 0;
	rep(i, n)
	{
		ll a; cin >> a;
		a_sum += a;
	}
	if (a_sum >= h)co("Yes");
	else co("No");
	return 0;
}


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 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(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

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


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>s;
      rep(i,Size(s)){
        if(s[i]=='A'){
          cnt=i;
          break;
        }
      }
      rrrep(i,Size(s)-1,0){
        if(s[i]=='Z'){
          ans=i-cnt+1;
          break;
        }
      }
      Cout(ans);
     

       
return 0;
}


Measured memory_bytes: 720
import java.util.Scanner;

public class Main {
	
	public static void main( String[]args ){
		
		
		Scanner sc = new Scanner( System.in );
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if( a > 0 )
			System.out.println( "Positive");
		else if( b >= 0 )
			System.out.println( "Zero");
		else{
			
			if( (b - a + 1) % 2 == 0 )
				System.out.println( "Positive");
			else
				System.out.println( "Negative");
			
		}
		
	}

}


Measured memory_bytes: 9680
#include <bits/stdc++.h>
#include <string.h>
#include <numeric>

using namespace std;

///////////////////////////////////////////
//const long long int INF = 1000000000000000000LL;
const long long int INF = 1000000;
using ll = long long int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return 1; } return 0; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return 1; } return 0; }
template<class T>T sqar(T x){ return x*x; }
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(    v[0])>()) //降順でVをソート
///////////////////////////////////////////

int main(){
    int a,b,c;cin>>a>>b>>c;
    cout<<max(c*10+a+b,max(a*10+b+c,a+b*10+c))<<endl;
    return 0;
}

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

ll const mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<ll> dp1(n+1,0),dp2(n+1,0);
    dp1[0] = 1;
    for (int i = 0;i < n;++i) {
        if (s[i] == '1') {
            (dp1[i+1] = dp1[i]<<1) %= mod;
            (dp2[i+1] += dp1[i]) %= mod;
        } else dp1[i+1] = dp1[i];
        (dp2[i+1] += dp2[i]*3) %= mod;
    }
    cout << (dp1[n]+dp2[n])%mod << endl;
    // p_ary(dp1,0,n+1,i);
    // p_ary(dp2,0,n+1,i);
    return 0;
}

Measured memory_bytes: 2048
#include<iostream>
#include<cstdlib>
#include<vector>
#include<unordered_map>
#include<climits>
#include<string>
#include<algorithm>
#include<unordered_set>
//#include<>

using namespace std;



// Driven Program 
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int d, t, s;
    cin >> d >> t >> s;
    float ans = (float)d / (float)s;
    if ( ans <= t) {
        cout << "Yes";
        return 0;
    }
    cout << "No";
}


Measured memory_bytes: 3644
// https://atcoder.jp/contests/abc099/tasks/abc099_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, C;
    cin >> N >> C;
    vector<vector<int>> D(C, vector<int>(C));
    REP(i, C) REP(j, C) { cin >> D[i][j]; }
    vector<vector<int>> E(N, vector<int>(N));
    REP(i, N) REP(j, N) {
        cin >> E[i][j];
        E[i][j]--;
    }
    // 予め色を変更した違和感を計算
    vector<vector<int>> cost(C, vector<int>(3));
    REP(c, C) REP(i, N) REP(j, N) { cost[c][(i + j) % 3] += D[E[i][j]][c]; }

    // 異なる色を３種類決める
    int minv = 1e9;
    REP(c1, C) {
        REP(c2, C) {
            if (c1 == c2)
                continue;
            REP(c3, C) {
                if (c1 == c3 || c2 == c3)
                    continue;
                minv = min(minv, cost[c1][0] + cost[c2][1] + cost[c3][2]);
            }
        }
    }
    cout << minv << endl;

    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")

int main()
{
	int N, M;
	cin >> N >> M;
	vector<ll> X(M), diff;
	for (int i = 0; i < M; i++)
	{
		cin >> X[i];
	}
	sort(X.begin(), X.end());
	for (int i = 1; i < M; i++)
	{
		diff.push_back(X[i] - X[i - 1]);
	}
	ll ans = 0;

	sort(diff.begin(), diff.end());

	if (M <= N)
	{
		cout << 0 << "\n";
		return 0;
	}

	for (int i = 0; i < diff.size(); i++)
	{
		ans += diff[i];
	}

	reverse(diff.begin(), diff.end());

	for (int i = 0; i < N - 1; i++)
	{
		ans -= diff[i];
	}

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

Measured memory_bytes: 2168
/* Don't try to copy it!
                    nhi too,
                         goli maar ke cheed bana dunga...;););)
 
                 
    _/﹋\_
    (҂`_´)
    <,︻╦╤─҉- - - - - - - - => - => - =>
    _/﹋\_
                
*/
 
#include "bits/stdc++.h"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define vll vector<ll>
#define T ll t; cin>>t; while(t--)
#define freeopen freopen("input.txt","r",stdin);
#define freeclose freopen("output.txt","w",stdout);
#define MOD 1000000007
using namespace std;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
ll n,cap;
ll v[100005],w[100005];
ll dp[105][100005];


ll max_val(ll p,ll total)
{
    if(p>=n)
    return 0;
    
    if(dp[p][total]!=-1)
        return dp[p][total];
    if(total+w[p]<=cap)
    {
        dp[p][total]=max(max_val(p+1,total),v[p]+max_val(p+1,total+w[p]));
    }
    else
        dp[p][total]=max_val(p+1,total);

    return dp[p][total];
}



main()
{
   //ll n;
    memset(dp,-1,sizeof(dp));
   cin>>n>>cap;
   f(n)
   {
    cin>>w[i];
    cin>>v[i];
   }

   cout<<max_val(0,0);
}



Measured memory_bytes: 85644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int culc( int n ) {
	int x4 = 0;
	int x3 = 0;
	int x2 = 0;
	int x1 = 0;
	int x0 = 0;

	x4 = n / 10000;
	n -= x4 * 10000;

	x3 = n / 1000;
	n -= x3 * 1000;

	x2 = n /100;
	n -= x2 * 100;

	x1 = n /10;
	n -= x1 * 10;

	x0 = n;

	return x4 + x3 + x2 + x1 + x0;

}

int main() {
	int n,a,b; cin >> n >> a >> b;
	int AnsSum = 0;

	for (int i = 1; i <= n; ++i)
	{
		if( a <= culc(i) && culc(i) <= b ){
			AnsSum += i;
		}
	}

	cout << AnsSum << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string>
#include<cstdio>
typedef unsigned long long ll;
const ll inf = 1e18; 
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	ll ans=1,temp,t;
	int flag=0;
	for(int i=0;i<n;i++)
	{
		cin>>temp;
		if(temp==0)
		{
			cout<<0<<endl;
			return 0;
		}
		if(inf/temp<ans)
			flag=1;
		else
			ans*=temp;
	}
	if(flag)
		cout<<-1<<endl;
	else
		cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<math.h>
#include<stdio.h>

using namespace std;

using ll = long long;

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

const ll INF = 1LL << 60;

typedef pair<ll, double> P;

bool pairCompare(const P & firstElof, const P & secondElof)
{
	return firstElof.second < secondElof.second;
}

bool IsPrime(ll num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

signed main() {
	ll ans = 0;

	ll a, b;
	cin >> a >> b;

	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	
	vector<ll>y;
	for (ll i = 1; i * i <= b; i++){
		if (b % i == 0) {
			y.push_back(i);
			y.push_back(b / i);
		}
	}
	for (ll i : y) {
		if (IsPrime(i))ans++;
	}
	ans++;
	cout << ans;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    ll k; cin >> k;
    ll c = 0;
    rep(i, s.size()) {
        if (s[i] != '1') break;
        c++;
    }
    if (k <= c) cout << 1 << endl;
    else cout << s[c] << endl;
}


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

struct UnionFind
{
	int N;
	vector<int> parent;
	vector<int> size_r;
	int num_of_sets;

	UnionFind(int N) : N(N), parent(N), size_r(N, 1), num_of_sets(N) {
		for (int i = 0; i < N; ++i) parent[i] = i;
	}

	int root(int x) {
		if (parent[x] == x) return x;
		return parent[x] = root(parent[x]);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (size_r[x] < size_r[y]) swap(x, y);
		parent[y] = x;
		size_r[x] += size_r[y];
		size_r[y] = 0;
		num_of_sets--;
		return true;
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	int size(int x) {
		return size_r[root(x)];
	}

	vector<int> roots() {
		vector<int> v(N);
		for (int i = 0; i < N; ++i) v[i] = root(i);
		return v;
	}
};

int main() {
	int n, m;
	cin >> n >> m;
	UnionFind uf(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		uf.merge(a, b);
	}
	vector<int> s(n, 0);
	auto v = uf.roots();
	for (int e : v) {
		s[e]++;
	}
	int ans = 0;
	for (int e : s) {
		ans = max(ans, e);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6028
#include <stdio.h>

int main(int argc, const char * argv[]) {
    long d, i, s;
    
    while (scanf("%ld\n", &d) != EOF) {
        s = 0;
        for (i=0; i<600 ;i += d) {
            s += i*i*d;
        }
        printf("%ld\n", s);
    }
    
    return 0;
}

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

N = int(input())
H = list(map(int, input().split()))

ans = 0
count = 0
tmp = H[0]
for i in range(1, N):
    if tmp >= H[i]:
        count += 1
        ans = max(ans, count)
    else:
        count = 0
    tmp = H[i]

print(ans)

Measured memory_bytes: 14252
#1147
while True:
	n = int(input())
	if n == 0: break
	s, vmin, vmax = 0, 1001, -1
	for i in range(n):
		a = int(input())
		vmin = min(vmin, a)
		vmax = max(vmax, a)
		s += a
	print((s-vmin-vmax)//(n-2))



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

int main()
{
    int w, a, b;
    cin >> w >> a >> b;
    if(b > a + w) cout << b - a - w << endl;
    else if(b + w < a) cout << a - b - w << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
open System
let R T = stdin.ReadLine()|> T
let RS T = stdin.ReadLine().Split()|>Array.map T
let R2 T U = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U)
let R3 T U V = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V)
let R4 T U V W = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V),(c.[3]|>W)
let R5 T U V W X = RS string|>fun c-> (c.[0]|>T),(c.[1]|>U),(c.[2]|>V),(c.[3]|>W),(c.[4]|>X)
let outl s = stdout.WriteLine(s|>string)
let outsep ls = stdout.WriteLine(String.concat " " (ls|>Array.map string))
let outsepl ls = stdout.WriteLine(String.concat "\n" (ls|>Array.map string))
let Mod = (1e9|>int64)+7L
[<EntryPoint>]
let main argv =
    R int
    |>fun c->3*c*c
    |>outl
    0

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

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

int main()
{
  const int BLACK = 1 << 0;
  const int WHITE = 1 << 1;

  int w, h;
  while (cin >> w >> h) {
    if ((w|h) == 0)
      break;

    vector<string> area(h);
    for (int i = 0; i < h; ++i)
      cin >> area[i];

    vector<vector<int> > color(h, vector<int>(w, 0));
    for (int y = 0; y < h; ++y) {
      for (int x = 0; x < w; ++x) {
	if (area[y][x] != '.') {
	  int base = 0;
	  if (area[y][x] == 'B')
	    base = BLACK;
	  else
	    base = WHITE;
	  queue<pair<int, int> > que;
	  for (int d = 0; d < 4; ++d) {
	    int xx = x + dx[d];
	    int yy = y + dy[d];
	    if (0 <= xx && xx < w && 0 <= yy && yy < h && area[yy][xx] == '.')
	      que.push(make_pair(yy, xx));
	  }
	  while (!que.empty()) {
	    pair<int, int> p = que.front();
	    que.pop();

	    if (color[p.first][p.second] & base)
	      continue;

	    color[p.first][p.second] |= base;
	    for (int d = 0; d < 4; ++d) {
	      int xx = p.second + dx[d];
	      int yy = p.first + dy[d];
	      if (0 <= xx && xx < w && 0 <= yy && yy < h && area[yy][xx] == '.')
		que.push(make_pair(yy, xx));
	    }
	  }
	}
      }
    }

    int black = 0, white = 0;
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
	if (color[i][j] == BLACK)
	  ++black;
	else if (color[i][j] == WHITE)
	  ++white;
      }
    }
    cout << black << " " << white << endl;
  }
  return 0;
}

Measured memory_bytes: 0
a,b=map(int,input().split())
s=list(input())
def r(x):
    if x=="0"or x=="1"or x=="2"or x=="3"or x=="4"or x=="5"or x=="6"or x=="7"or x=="8"or x=="9":
        return True
    else:return False
for i in range(a):
    if r(s[i]):continue
    else:
        print("No")
        exit()
if s[a]!="-":
    print("No")
    exit()
for i in range(b):
    if r(s[a+i+1]):continue
    else:
        print("No")
        exit()
print("Yes")

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

int main(){
	int a, b, A;
	char op;
	
	
	while(1){
		cin >> a >> op >> b;
		
		if ( op == '+'){
			A = a + b;
		}else if( op == '-'){
			A = a - b;
		}else if (op == '*'){
			A = a * b;
		}else if (op == '/'){
			A = a / b;
		}else{
			break;
		}
		cout << A << endl;
	}
	  
	return 0;	
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int n,a;
    cin >> n >> a;
    vector<int> x(n);
    rep(i,0,n) cin >> x[i];
    static int64_t dp[51][51][2501];
    dp[0][0][0]=dp[0][1][x[0]]=1;
    rep(i,1,n){
        rep(j,0,i+2){
            rep(k,0,2501){
                dp[i][j][k]+=dp[i-1][j][k];
                if(j-1>=0 and k-x[i]>=0) dp[i][j][k]+=dp[i-1][j-1][k-x[i]];
            }
        }
    }

    int64_t ans=0;
    rep(i,1,n+1) ans+=dp[n-1][i][a*i];
    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 26368
import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        String S = sc.next();
        char[] chars = S.toCharArray();
        String output = "";
        for(int i = 0; i<chars.length;i++){
            int num = chars[i] + N;
            if(num > 'Z'){
                num = num-26;
            }
            output += (char)(num);
        }

        System.out.println(output);
    }
}


Measured memory_bytes: 148916
import sys

def move(FROM, edges):
  for edge in edges:
    if FROM in edge:
      edges.remove(edge)
      edge.remove(FROM)

      return edge[0]
  
  return 0


loadNum = 3
startNode = 1
a = [0]*loadNum
for i in range(loadNum):
    a[i] = list(map(int, input().split()))

nowhere = startNode
for i in range(loadNum):
  nowhere = move(nowhere, a)
  if nowhere == 0:
    print('NO')
    sys.exit()

print('YES')

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

int main(){
 long long K,u,c,N;
  cin>>N>>K;
 vector<pair<int,int>>d(N);
  for(int i=0;i<N;i++){
    cin>>c>>u;
    d[i]=make_pair(c,u);
  }
  u=0;
  sort(d.begin(),d.end());
    for(int i=0;i<N;i++){
u+=d[i].second;
      if(K<=u){
        cout<<d[i].first<<endl;
        return 0;
      }
  }
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'

const int N = 1e6 + 11;
int f[N], a[N];

int32_t main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(nullptr), cout.tie(nullptr);

    int n; cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> a[i]; f[a[i]]++;
    }
    for (int i = 1; i < N; i++) {
      if (!f[i]) continue; // has to be present in array
      for (int j = 2; i * j < N; j++) 
        f[i * j]++;
    }
    int cnt = 0;
    for (int i = 0; i < n; i++)
      cnt += f[a[i]] == 1;
    cout << cnt << endl;
}

Measured memory_bytes: 12984
x, y, a, b, c = map(int, input().split())
p = [int(i) for i in input().split()]
q = [int(i) for i in input().split()]
r = [int(i) for i in input().split()]

p = sorted(p)
q = sorted(q)
#r = sorted(r)
tmp = sorted(p[-x:] + q[-y:] + r)
ans = sum(tmp[-(x+y):])

print(ans)

Measured memory_bytes: 113644
X,Y,A,B,C=map(int,input().split())
listD=[0]*(A+B+C)
listA=list(map(int,input().split()))
listB=list(map(int,input().split()))
listC=list(map(int,input().split()))

listA.sort(reverse=True)
listB.sort(reverse=True)
listC.sort(reverse=True)

for i in range(X):
    listD[i]=listA[i]
for i in range(Y):
    listD[A+i]=listB[i]
for i in range(C):
    listD[A+B+i]=listC[i]

listD.sort(reverse=True)

list_answer=[0]*(X+Y)

for i in range(X+Y):
    list_answer[i]=listD[i]

sum1=sum(list_answer)


print(sum1)

Measured memory_bytes: 25760
#include<bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define FOR(i,n) for(int i=0;i<(int)n;i++)
#define ALL(x) (x).begin(),(x).end()
using namespace std;

inline lli getint(){
    lli n;
    scanf("%lld",&n);
    return n;
}

inline vector<lli> getints(int n){
    vector<lli> a(n);
    for(int i=0;i<n;i++)scanf("%lld",&a[i]);
    return a;
}

inline string getstr(){
  string s;
  cin>>s;
  return s;
}

inline string slice(string s,int a,int b){
  return s.substr(a,b-a-1);
}
void dumpints(vector<lli> a){
  cout<<"[";
  for(int i=0;i<a.size()-1;i++){
    cout<<a[i]<<",";
  }
  cout<<a[a.size()-1]<<"]"<<endl;
}

template<class T> bool ifinclude(vector<T> a,T x){
    auto itr=find(a.begin(),a.end(),x);
    return distance(a.begin(),itr)!=a.size();
}

int main(void){
  int x=getint(),y=getint();
  int ans;
  if(x==y){
    ans=0;
  }else if(x==-y){
    ans=1;
  }else if(x>0&&y>0){
    if(x<y){
      ans=y-x;
    }else{
      ans=x-y+2;
    }
  }else if(x==0&&y>0){
    ans=y;
  }else if(x>0&&y==0){
    ans=x+1;
  }else if(x>=0&&y<0){
    ans=abs(x+y)+1;
  }else if(x<0&&y>0){
    ans=abs(y+x)+1;
  }else if(x<0&&y==0){
    ans=-x;
  }else{
    if(x<y){
      ans=y-x;
    }else{
      ans=x-y+2;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    string S1,S2,ans;
    cin >> S1 >> S2;
    
    for ( int i = 0; i < S1.length(); i++ ) {
        ans += S1[i];
        if ( i < S2.length() ) { ans += S2[i]; }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 764
n = gets.to_i
s = gets.split('')
minus = 0
for i in 0..n-1
  j=i+1
  k=i+2
  #count=0
  while k<n
    if (s[i]!=s[j] && s[j]!=s[k] && s[i]!=s[k])
      minus += 1
    end
    #count+=1
    j+=1
    k+=2
  end
end


r = s.count('R')
g = s.count('G')
b = s.count('B')


puts r*g*b - minus

Measured memory_bytes: 14380
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

enum m = 1_000_000_007;
void main() {
  int n;
  readf (" %d", &n);
  auto a = new long[n];
  foreach (t; 0 .. n) {
    readf (" %d", &a[t]);
  }
  long res;
  foreach (k; 0 .. 60) {
    immutable mask = 1L << k;
    int t1 = a.count! (i => (i & mask) != 0).to!int;
    //0, 1
    //1, 0
    long t0 = n - t1; 
    long t = (t0 * t1) % m;
    t *= mask % m;
    res += t;
  }
  res %= m;
  writeln (res);
}



Measured memory_bytes: 4220
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    def check(i):
        for j in range(tn):
            if s[i + j] != "?" and s[i + j] != t[j]:
                return False
        return True

    s = list(input())
    t = list(input())
    sn = len(s)
    tn = len(t)
    for i in range(sn - tn, -1, -1):
        if check(i):
            s = s[:i] + t + s[i + tn:]
            break
    else:
        print("UNRESTORABLE")
        exit()
    for i in range(sn):
        if s[i] == "?": s[i] = "a"
    print(*s, sep="")

main()


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
class Main
{
	static void merge(int arr[], int l, int m, int r) 
    { 
        int n1 = m - l + 1; 
        int n2 = r - m; 
        int L[] = new int [n1]; 
        int R[] = new int [n2]; 
        for (int i=0; i<n1; ++i) 
            L[i] = arr[l + i]; 
        for (int j=0; j<n2; ++j) 
            R[j] = arr[m + 1+ j]; 
        int i = 0, j = 0; 
        int k = l; 
        while (i < n1 && j < n2) 
        { 
            if (L[i] <= R[j]) 
            { 
                arr[k] = L[i]; 
                i++; 
            } 
            else
            { 
                arr[k] = R[j]; 
                j++; 
            } 
            k++; 
        } 
        while (i < n1) 
        { 
            arr[k] = L[i]; 
            i++; 
            k++; 
        } 
        while (j < n2) 
        { 
            arr[k] = R[j]; 
            j++; 
            k++; 
        } 
    } 
    static void sort(int arr[], int l, int r) 
    { 
        if (l < r) 
        { 
            int m = (l+r)/2; 
            sort(arr, l, m); 
            sort(arr , m+1, r); 
            merge(arr, l, m, r); 
        } 
    } 
    static int gcd(int a, int b) 
    { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    } 
    static long power(long n,long m)
    {
    	if(m==0)
    		return 1;
    	long ans=1;
    	while(m>0)
    	{
    		ans=ans*n;
    		m--;
    	}
    	return ans;
    }
	static int binarySearch(ArrayList<Integer> arr, int x) 
    { 
        int l = 0, r = arr.size() - 1,m=l + (r - l) / 2; 
        while (l <= r) { 
            m = l + (r - l) / 2; 
            if (arr.get(m) == x) 
                return m; 
            if (arr.get(m) < x) 
                l = m + 1; 
            else
                r = m - 1; 
        } 
        return (int)Math.max(l, m); 
    } 
	public static void main(String args[])throws Exception
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		    int n,k;
	        String s=br.readLine();
	        String ss[]=s.split(" ");
	        n=Integer.parseInt(ss[0]);
	        k=Integer.parseInt(ss[1]);
	        if(k>=n)
	        System.out.println("unsafe");
	        else
	        	System.out.println("safe");
	    
	}
}


Measured memory_bytes: 32524
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define SZ(x) ((int)(x).size())
#define fastin ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
int a[30],p,n,sv;
int ans[110][3],q;
void add(int u,int v,int w){
	q++;
	ans[q][0]=u;
	ans[q][1]=v;
	ans[q][2]=w;
} 
int main(){
	scanf("%d",&n);
	sv=n;
	while(n){
		a[++p]=n%2;
		n/=2;
	}
	rep(i,2,18){
		add(i,i+1,0);
	}
	rep(i,2,18){
		add(i,i+1,1<<(20-i));
	}
	rep(i,0,3)	add(19,20,i);
	int base=0;
	int tmp=2*a[2]+a[1];
	rep(i,0,tmp-1)	add(1,20,i);
	base+=tmp;
	rep(i,3,p){
		if(a[i]){
			int to=22-i;
			add(1,to,base);
			base+=(1<<(i-1));
		}
	}
	printf("20 %d\n",q);
	rep(i,1,q){
		printf("%d %d %d\n",ans[i][0],ans[i][1],ans[i][2]);
	}
	return 0;
}

Measured memory_bytes: 3760
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int digits(ll n){
	if(n == 0) return 1;
	int res = 0;
	while(n > 0){
		n /= 10;
		res++;
	}
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int ans = 1e9;
	for(int i = 1; i <= n-1; ++i){
		int b = n - i;
		int a = i;
		int cmp = 0;
		while(a > 0){
			cmp += a%10;
			a /= 10;
		}
		while(b > 0){
			cmp += b%10;
			b /= 10;
		}
		chmin(ans, cmp);
	}
	cout << ans << endl;
	return 0;
}


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

using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define mp make_pair
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <class T>
bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> p) { ll x = get<0>(p), y = get<1>(p); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};
int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	ll A, B; cin >> A >> B;
  cout << max(A*B, max(A-B, A+B)) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <cmath>
#include <string>

using std::cin;
using std::cout;
using std::endl;
using std::min;
using std::max;
using std::vector;
using std::string;

using llint = long long int;

int main()
{

	
	llint N,M;
	cin >> N >> M;

	vector<int> ac(N);
	vector<int> pena(N);

	for (auto& a:ac)a = 0;
	for (auto& a:pena)a = 0;

	for (size_t i = 0;i < M;i++){
		llint p;
		string s;
		cin >> p >> s;

		if(s == "AC"){
			ac[p-1] = 1;
		}else{
			if(ac[p-1] == 0){
				pena[p-1]++;
			}
		}
	}
	
	llint a = 0,b = 0;

	for (size_t i = 0;i < N;i++){
		if(ac[i] == 1){
			a++;
			b += pena[i];
		}
	}

	cout << a << " " << b << endl;

	return 0;
}


Measured memory_bytes: 1024
n,c,k = map(int,input().split())
t = [int(input()) for i in range(n)]

t.sort()

bus = 0
dis = t[0] + k
temp = 0 

for i in range(n):
    if (t[i] > dis) or (temp+1 > c):
        bus += 1
        dis = t[i]+k
        temp = 1
        
        
    else:
        temp += 1
            
    

print(bus+1)

Measured memory_bytes: 7488
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int, int> P;
typedef long long ll;

int main() {
	int h, w; cin >> h >> w;
	vector<vector<char>> g(h, vector<char>(w));
	queue<P> q;
	int dx[] = { 1,0,-1,0 };
	int dy[] = { 0,1,0,-1 };

	rep(i, h) {
		rep(j, w) {
			cin >> g[i][j];
			if (g[i][j] == '#') {
				q.push(P(i, j));
			}
		}
	}

	bool jud = true;

	while (!q.empty()) {
		bool tmp = false;
		P p = q.front(); q.pop();

		rep(i, 4) {
			if (p.first + dx[i] <= -1 || p.first + dx[i] >= h) continue;
			if (p.second + dy[i] <= -1 || p.second + dy[i] >= w) continue;

			if (g[p.first + dx[i]][p.second + dy[i]] == '#') tmp = true;
		}

		if (!tmp) {
			jud = false;
			break;
		}

	}

	if (jud) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int N;
	scanf("%d",&N);
	
	int a[N];
  	float sum,ans;
	for(int i=0;i<N;i++){
      scanf("%d",&a[i]);
      sum += 1.0/a[i];
    }
	ans = 1.0/sum;  
	printf("%f\n",ans);
	
	return 0;
}

Measured memory_bytes: 128
arr = []
while True:
    tmp = tuple(map(int, input().split()))
    if tmp == (0, 0):
        break
    else:
        arr.append(tmp)
for elem in arr:
    n = elem[0]
    x = elem[1]
    ans = 0
    li = [i for i in range(1, (n + 1))]
    for i in range(n):
        for j in range(i + 1, n):
            for k in range(j + 1, n):
                if li[i] + li[j] + li[k] == x:
                    ans += 1
    print(ans)



Measured memory_bytes: 5604
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtype!real;

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = rint;
	long[] as = rlong(n); 
	
	long ans;
	long limit = 0;
	foreach(i; 0 .. n){
		long a = as[i];
		log("i:", i, "a:", a, "limit:", limit, "ans:", ans);
		if(a <= limit) continue;
		else if(a == limit + 1) limit += 1;
		else if(limit == 0) ans += a - 1, limit += 1;
		else ans += (a - 1) / (limit + 1);
		log(" -> ", "limit:", limit, "ans:", ans);
	}
	
	ans.writeln;
}


Measured memory_bytes: 4092
from itertools import starmap

q = int(input())
while q:
    q -= 1
    p0, p1, p2, p3 = starmap(complex, zip(*[map(int, input().split())] * 2))
    prod = (p1 - p0).conjugate() * (p3 - p2)
    print(2 if abs(prod.imag) < 1e-6 else 1 if abs(prod.real) < 1e-6 else 0)

Measured memory_bytes: 7700
#include <stdio.h>
#include <string.h>
#define rep(i,l,n) for(i=l;i<n;i++)

int main(void){
	char s[101];
	char p[101];
	int i,j,ls,lp,a,m;
	
	scanf("%s",s);
	scanf("%s",p);
	
	ls=strlen(s);
	lp=strlen(p);
	
	a=0;
	
	rep(i,0,ls){
		if(a) break;
		rep(j,0,lp){
			m=i+j;
			if(m>=ls) m-=ls;
			if(s[m]!=p[j]) break;
			if(j==lp-1) a++;
			
		}
	}
	
	if(a) printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

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

int main() {
    int K, A, B;
    cin >> K >> A >> B;
    bool is_yes = false;
    rep(i, 1000){
        if(A<=K*i && B>=K*i) {
            is_yes = true;
            break;
        }
    }
    if(is_yes) cout << "OK" << endl;
    else cout << "NG" << endl;
}


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

int main() {
    ll k,t;
    std::cin >> k>>t;
    vector<ll> a(t);
    for (int i = 0; i < t; i++) {
        std::cin >> a[i];
    }
    sort(a.begin(),a.end());
    
    ll sum = 0;
    for (int i = 0; i < t-1; i++) {
        sum += a[i];
    }
    std::cout << max((ll)0,a[t-1]-sum-1) << std::endl;
}


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

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define sqr(x) x*x

int main(){
  int n, f;
  int s1, s2, s3;

  scanf("%d",&n);
  while(n--){
    scanf("%d %d %d",&s1,&s2,&s3);
    f = 0;
    if(sqr(s1) == sqr(s2) + sqr(s3)) f = 1;
    if(sqr(s2) == sqr(s1) + sqr(s3)) f = 1;
    if(sqr(s3) == sqr(s1) + sqr(s2)) f = 1;

    if(f) printf("YES\n");
    else printf("NO\n");
  }

  return 0;
}

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

#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
template<class T> void writerLn(T x){writer(x,'\n');}


#define incID(i, l, r) for(int i = (l); i < (r); i++)
#define inc(i, n) incID(i, 0, n)
template<typename T> bool setmin(T &a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T &a, T b) { if(b <= a) { return false; } else { a = b; return true; } }


// ---- ----

int n, k;
vector<int> vec[100000];
bool has[100000];
int mi[100000];
int ma[100000];

void prod(int x, int y) {
	if(has[y]) {
		bool flag = true;
		if(has[x] && (mi[x] - mi[y]) % 2 == 0) { flag = false; }
		setmax(mi[x], mi[y] - 1);
		setmin(ma[x], ma[y] + 1);
		has[x] = true;
		if(mi[x] > ma[x]) { flag = false; }
		if(! flag) {
			puts("No");
			exit(0);
		}
	}
}

bool dfs(int node, int pre) {
	if(pre != -1) { prod(node, pre); }
	for(auto && e : vec[node]) {
		if(e != pre) {
			dfs(e, node);
			prod(node, e);
		}
	}
}

int main() {
	reader(&n);
	inc(i, n - 1) {
		int a, b;
		reader(&a, &b);
		a--; b--;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	fill(mi, mi + n, -1000000);
	fill(ma, ma + n,  2000000);
	reader(&k);
	inc(j, k) {
		int v, p;
		reader(&v, &p);
		v--;
		mi[v] = p;
		ma[v] = p;
		has[v] = true;
	}
	
	dfs(0, -1);
	dfs(0, -1);
	
	puts("Yes");
	inc(i, n) { writerLn(mi[i]); }
	
	return 0;
}


Measured memory_bytes: 11904
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2 * 10**6)


def inpl():
    return list(map(int, input().split()))


def main():

    tA, tB = input().split()
    A = int(tA)
    B = int(tB.replace(".", ""))
    # print(B)
    ans = A * B // 100

    print(ans)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9176
#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; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    int n;
    cin >> n;
    map<int,ll> x;
    map<int,ll> cnt;
    int a[n];
    rep(i,n){
        cin >> a[i];
        cnt[a[i]]++;
    }
    ll sum=0;
    for(auto p:cnt){
        sum+=p.S*(p.S-1);
        x[p.F]+=p.S*(p.S-1)-(p.S-1)*(p.S-2);
    }
    rep(i,n){
        cout << (sum-x[a[i]])/2 << endl;
    }

    


}

/*



 */



Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
int main() {
    init();
    ll N;
    cin >> N;
    vl A(N + 1, 1);
    repe(i, 2, N + 1) for (ll j = i; j <= N; j += i) A[j]++;

    ll ans = 0;
    repe(i, 1, N + 1) ans += i * A[i];
    cout << ans << endl;
}

Measured memory_bytes: 81344
#include <iostream>
#include <math.h>
#include <algorithm>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>


using namespace std;

int gx, gy;
string s;
bool dpx[10000][16001];
bool dpy[10000][16001];


int main() {
	cin >> s;
	cin >> gx>> gy;

	int a[8000] = {};
	
	int p = 0;
	for (int i = 0; i < s.size(); i++)
	{
		
		if (s[i] == 'F') {
			a[p]++;
		}
		else if (s[i] == 'T') {
			p++;
		}

	}

	

	vector<int> x(1);
	vector<int> y(1);

	x[0] = a[0];
	y[0] = 0;

	for (int i = 1; i <= p; i++)
	{
		if (i % 2 == 1) {
			y.push_back(a[i]);
		}
		else {
			x.push_back(a[i]);
		}
	}

	dpx[0][x[0]+8000] = true;
	dpy[0][y[0]+8000] = true;

	for (int i = 1; i < x.size(); i++)
	{
		for (int j = 0; j < 16001; j++)
		{
			if (dpx[i - 1][j] == true) {
				dpx[i][j + x[i]] = true;
				dpx[i][j - x[i]] = true;
			}
		}
	}
	for (int i = 1; i < y.size(); i++)
	{
		for (int j = 0; j < 16001; j++)
		{
			if (dpy[i - 1][j] == true) {
				dpy[i][j + y[i]] = true;
				dpy[i][j - y[i]] = true;
			}
		}
	}

	if (dpx[x.size() - 1][gx + 8000] == true && dpy[y.size() - 1][gy + 8000]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	


	return 0;


}

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

set<long long>st;

void makeLun(long long x, int d){
	if(d==10){
		st.insert(x);
		return;
	}


	st.insert(x);

	int last=x%10;
	for(int l=max(last-1,0); l<=min(last+1,9); l++){
		makeLun(x*10 +l, d+1);
	}
}

int main(){
	int k;	cin>>k;

	for(int i=1;i<=9;i++){
		makeLun(i,1);
	}

	auto it=st.begin();
	for(int cnt=1;cnt<k;cnt++)++it;
	cout<<*it<<endl;

	return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector<int> c(n), s(n), f(n);
	for(int i=0; i<n-1; i++){
		cin >> c[i] >> s[i] >> f[i];
	}
	for(int i=0; i<n; i++){
		int time = 0;
		for(int j=i; j<n-1; j++){
			if(time < s[j]) {
				time = s[j];
			} else {
				time = (time + f[j] - 1) / f[j] * f[j];
			}
			time += c[j];
		}
		cout << time << endl;
	}
	return 0;
}


Measured memory_bytes: 256