akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 1100;
int N;
char W[MAXN][20];
bool vis[MAXN][20][MAXN][20];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> W[i];
	}
	int ans = 0;
	vector<pair<pair<int, int>, pair<int, int>>> q;
	for (int w1 = 0; w1 < N; w1++) {
		for (int w2 = w1 + 1; w2 < N; w2++) {
			q.push_back({{w1,0},{w2,0}});
		}
	}
	while (!q.empty()) {
		ans++;
		vector<pair<pair<int, int>, pair<int, int>>> nq;
		for (int z = 0; z < int(q.size()); z++) {
			auto state = q[z];
			int w1 = state.first.first, i1 = state.first.second;
			int w2 = state.second.first, i2 = state.second.second;
			if (w1 == N) {
				assert(i1 == 0);
				for (int w = 0; w < N; w++) {
					q.push_back({{w,0},{w2,i2}});
				}
				continue;
			}
			if (w2 == N) {
				assert(i2 == 0);
				for (int w = 0; w < N; w++) {
					q.push_back({{w1,i1},{w,0}});
				}
				continue;
			}
			assert(W[w1][i1] != '\0');
			assert(W[w2][i2] != '\0');
			if (W[w1][i1] != W[w2][i2]) {
				continue;
			}
			i1++, i2++;
			if (W[w1][i1] == '\0') w1 = N, i1 = 0;
			if (W[w2][i2] == '\0') w2 = N, i2 = 0;
			if (w1 == N && w2 == N) {
				cout << ans << '\n';
				exit(0);
			}
			if (vis[w1][i1][w2][i2]) {
				continue;
			}
			vis[w1][i1][w2][i2] = true;
			nq.push_back({{w1,i1},{w2,i2}});
		}
		q = std::move(nq);
	}
	cout << 0 << '\n';

	return 0;
}



Measured memory_bytes: 259408
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define all(a) a.begin(), a.end()
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

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

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

  sort(all(a));
  sort(all(c));

  ll ans = 0;
  rep(i, n) {
    ll an = lower_bound(all(a), b[i]) - a.begin();
    ll cn = upper_bound(all(c), b[i]) - c.begin();
    ans += an * (n - cn);
  }
  cout << ans << endl;

  return 0;
}

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

int main()
{
	int n;
	cin >> n;
	priority_queue<int> Q;
	vector<int> A;
	vector<int> nyu;
	int a;
	for (int i = 0; i < n; ++i)
	{
		cin >> a;
		A.push_back(a);
		nyu.push_back(a);
	}
	sort(A.begin(), A.end());
	for (auto o : nyu)
	{
		cout << (o == A[A.size()-1]?A[A.size()-2] : A[A.size()-1]) << endl;
	}
	return 0;
}

Measured memory_bytes: 3436
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define loop(i,x,n) for(ll i = x;i<n;i++)
#define S(v) sort(v.begin(), v.end());
#define ff first
#define ss second


int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	// freopen("in.txt","r", stdin);
	set<char> s;
	loop(i,0,4){
		char x;
		cin>>x;
		s.insert(x);
	}
	cout<<(s.size() == 2?"Yes":"No");
}

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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	ll K;
    string S;
    cin>>K>>S;
    if(S.size()>K){
        cout<<S.substr(0,K)<<"..."<<"\n";
    }else{
        cout<<S<<"\n";
    }
	
	return 0;
}

Measured memory_bytes: 3644
for x in range(20):
    a=int(input())
    if a==0: break
    
    lst = []
    for x in range(a):
        lst.append(int(input()))
    b=min(lst)
    c=max(lst)
    lst.remove(b)
    lst.remove(c)
    d=sum(lst)
    ave=d//(a-2)
    print(ave)
        


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

int main() {
  int N, K, ans;
  ans = 0;
  cin >> N >> K;
  vector<int> rope(60);
  for(int i = 0; i < N; i++){
   cin >> rope.at(i); 
  }
 sort(rope.begin(),rope.end());
  reverse(rope.begin(),rope.end());
  for(int i = 0; i < K; i++){
    ans += rope.at(i);
  }
  cout << ans << endl;
  
}


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

int main() {
  int H,n;
  cin >> H >> n;
  vector<int> killer(n);
  for(int i = 0 ; i < n; i++){
    cin >> killer.at(i);
  }
  for(int i = 0 ; i < n; i++){
    H -= killer.at(i);
  }
  if(H <= 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e;
  string s,ss,sss;
  cin>>a>>b;
  if(b==1)cout<<0<<endl;
 else cout<<a-b<<endl;
  return 0;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    string s;
    cin>>s;
    bool ok = true;
    
    for(int i = 0; i < s.size(); i++)
    {
        
        for(int j = 0; j < i; j++)
        {
            if(s[i]==s[j])
            {
                ok=false;
                break;
            }
        }
        
    }
    if(ok)
    {
        cout <<"yes"<<endl;
    }
    else
    {
        cout <<"no"<<endl;
    }

    return 0;
}

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

int main() {
  int n;
  cin>>n;
  if(n%2==1){
    cout<<1LL*2*(n/2)*(n/2)<<endl;
    for(int i=1;i<n;i++){
      for(int j=i+1;j<n+1;j++){
        if(i+j!=n){
          cout<<i<<' '<<j<<endl;
        }
      }
    }
  }
  else {
    cout<<1LL*2*(n/2)*(n/2-1)<<endl;
    for(int i=1;i<n;i++){
      for(int j=i+1;j<n+1;j++){
        if(i+j!=n+1)cout<<i<<' '<<j<<endl;
      }
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int factor(int N) {
    int c = 0;
    for (int i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            if (i == N / i) c++; else c += 2;
        }
    }
    return c;
}

int main() {
    int N; cin >> N;
    ll cnt = 0;
    for (int i = 1; i < N; i++) {
        int C = N - i;
        int D = factor(C);
        cnt += D;
    }
    cout << cnt << endl;
}


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

#define      pb    push_back
#define      ff    first
#define      ss    second
#define      ll    long long int
#define      endl  "\n"
#define      FASTIO        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


#define      TEST    int t ; cin >> t ; while( t -- )

const ll big = 10e17 + 11 ;

int  main (  ) {

    FASTIO ;

    int a , b ;
    cin >> a >> b ;

    if( a <= b ) cout << "unsafe" ;
    else  cout << "safe" ;


    return  0 ;
}


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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

struct UnionFind{
    vector<int> data;
    //data[i] = -x ... iが根であり、サイズがx
    //data[i] = x ... iの親がx

    //最初は全員根
    UnionFind(int size): data(size,-1){}

    bool union_set(int x, int y){//サイズがx>yになるようにしてから、xに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 find_set(int x, int y){//ルートが一致するかどうかを返す
        return root(x) == root(y);
    }
    int root(int x){//根を見つける。ついでに深さ2にしちゃう
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};

struct Edge{
    int s,t,cost;
    bool operator<(const Edge &o) const{
        return cost < o.cost;
    }
};

struct Graph{
    int n;
    vector<Edge> es;

    int kruskal(){
        sort(ALL(es));

        UnionFind uf(n);
        int min_cost = 0;
        REP(i,es.size()){
            Edge& e = es[i];
            if(!uf.find_set(e.s, e.t)){//辺を追加しても閉路ができなければ採用
                min_cost += e.cost;
                uf.union_set(e.s, e.t);
            }
        }

        return min_cost;
    }
};

int main() {

    int N;
    cin >> N;
    vector<pair<int,int>> coord_x;
    vector<pair<int,int>> coord_y;
    REP(i,N){
        int id, x, y;
        cin >> x >> y;
        id = i;
        coord_x.push_back(make_pair(x,id));
        coord_y.push_back(make_pair(y,id));
    }
    sort(ALL(coord_x));
    sort(ALL(coord_y));

    Graph g;
    g.n = 2*N-2;

    REP(i,N-1){
        Edge ex;
        ex.s = coord_x[i].second;
        ex.t = coord_x[i+1].second;
        ex.cost = abs(coord_x[i].first - coord_x[i+1].first);
        g.es.push_back(ex);
        Edge ey;
        ey.s = coord_y[i].second;
        ey.t = coord_y[i+1].second;
        ey.cost = abs(coord_y[i].first - coord_y[i+1].first);
        g.es.push_back(ey);
    }

    sort(ALL(g.es));

    cout << g.kruskal() << endl;


    return 0;
}

Measured memory_bytes: 8632
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

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

    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];

    SORT(a);

    int cnt = 1;
    int ans = 0;
    REP(i, N - 1) {
        if (a[i] == a[i + 1]) {
            cnt++;
        } else {
            if (cnt % 2 != 0) {
                ans++;
            }
            cnt = 1;
        }
    }

    if (cnt % 2 != 0)
        ans++;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int inf=400000000;
		int[] dp=new int[n],h=new int[n];
		for(int i=0;i<n;i++) {
			h[i]=sc.nextInt();
			dp[i]=inf;
		}
		dp[0]=0;
		for(int i=1;i<n;i++) {
			int cost1=dp[i-1]+Math.abs(h[i]-h[i-1]);
			if(i==1) {
				dp[i]=cost1;
			}else {
				int cost2=dp[i-2]+Math.abs(h[i]-h[i-2]);
				dp[i]=Math.min(cost1,cost2);
			}
		}
		System.out.println(dp[n-1]);
		sc.close();
	}
}

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

using vi = std::vector<int>;
using vvi = std::vector<vi>;

int ans{};
std::vector<bool> visited;
vvi edges;

bool dfs(int);

int main()
{
	int N;
	scanf("%d", &N);
	edges.resize(N + 1);
	for (int i{}; i < N - 1; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	for (int i{}; i < N; i++)
		if (edges[i].size() > 2)
		{
			edges[i].push_back(N);
			edges[N].push_back(i);
			break;
		}
	if (edges[N].empty())
	{
		puts("1");
		return 0;
	}
	visited.resize(N + 1);
	dfs(N);
	printf("%d\n", ans);

	return 0;
}

bool dfs(int index)
{
	visited[index] = true;
	int count{};
	for (auto& e: edges[index])
	{
		if (visited[e]) continue;
		if (dfs(e)) count++;
	}
	if (edges[index].size() > 2)
	{
		int diff{std::max(0, (int)edges[index].size() - 2 - count)};
		ans += diff;
		count += diff;
	}
	return count > 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#include <unistd.h>
#include <cctype>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 1 << 30
#define LLINF LLONG_MAX/3
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
using ll = long long;
using Pll = pair<ll,ll>;
using Pii = pair<int,int>;
using Pdd = pair<double,double>;
using dcomplex = complex<double>;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll fact(ll a){ll b=1;FOR(i,1,a)b*=i;return b;}
ll power(ll x,ll n){ll a=1;REP(i,n)a*=x;return a;}
double inf() {return std::numeric_limits<double>::infinity();}

map<ll,ll> p, w;
ll find(ll x){
  if(p.find(x)==p.end() || p[x] == x) return x;
  ll f = p[x];
  p[x] = find(p[x]);
  w[x] += w[f];
  return p[x];
}

int main(int argc, char const *argv[]) {
  ll N, M; cin >> N >> M;
  REP(i,M) {
    ll L, R, D; cin >> L >> R >> D;
    ll x=find(L), y=find(R);
    if(x==y&&w[R]-w[L]!=D) {
      cout << "No" << endl;
      return 0;
    }
    p[y]=x;
    w[y]=w[L]+D-w[R];
  }
  cout << "Yes" << endl;
}


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



int main() {
    int n;
    cin >> n;
    vector<string> A(n);
    for(int i = 0; i < n; i++) {
        cin >> A[i];
    }
    int countAC = 0;
    int countWA = 0;
    int countTLE = 0;
    int countRE = 0;
    for(int i = 0; i < n; i++) {
        if(A[i] == "AC") countAC++;
        if(A[i] == "WA") countWA++;
        if(A[i] == "TLE") countTLE++;
        if(A[i] == "RE") countRE++;
    }

    cout << "AC x " << countAC << endl;
    cout << "WA x " << countWA << endl;
    cout << "TLE x " << countTLE << endl;
    cout << "RE x " << countRE << endl;
}



Measured memory_bytes: 6428
N = int(input())
S = input()

r , g, b = S.count("R"), S.count("G"), S.count("B")
ans = r * g * b

for i in range(N-2):
    for d in range(N//2+1):
        j = i + d
        k = j + d
        if k >= N:break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            ans -= 1
print(ans)

Measured memory_bytes: 9172
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int solve(int a,int K) {
  if(a % K == 0) return a / K;
  if(a < K) return 0;
  int d = a / K + 1;
  int t = (a % K + d - 1) / d;
  return solve(a - t * d , K);
}

int main(){
  int n;
  cin >> n;
  int sg = 0;
  rep(i,0,n) {
    int a , K;
    cin >> a >> K;
    sg ^= solve(a , K);
  }
  cout << (sg ? "Takahashi" : "Aoki") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 1e5+10;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
vector<int> g[N];
int n,m;
bool used[N];int dp[N];
void dfs(int val,int idx)
{
	used[idx]=1;
	int value=0;
	for(auto x : g[idx])
	{
		if(used[x])
		value=max(value,dp[x]+1);
		else
		{
			used[x]=true;
			dfs(val+1,x);
			value=max(value,dp[x]+1);
		}
	}
	dp[idx]=value;
}
int main()
{  fast
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		g[x].emplace_back(y);
	}
	for(int i=1;i<=n;i++)
	{
		if(!used[i])
		dfs(0,i);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
	ans=max(ans,dp[i]);
	cout<<ans;
}


Measured memory_bytes: 8960
l,r=map(int,input().split())
count=2019
for i in range(l,r):
    for j in range(i+1,r+1):
        count=min(count,(i*j)%2019)
        if i*j%2019==0:
            break
    if i*j%2019==0:
        break
print(count)


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

int main() {
    int N;
    cin >> N;
    vl A(N);
    vl sum(N + 2);
    rep(i, N) {
        cin >> A[i];
        sum[i + 1] = A[i];
    }
    for (int i = 0; i < N; i++) {
        sum[i + 1] += sum[i];
    }
    sum[N + 1] = __LONG_LONG_MAX__;


    ll ans = __LONG_LONG_MAX__;
    for (int i = 0; i < N; i++) {
        if (i < 2) continue;
        if (i > N - 2) continue;

        // 右
        ll X = sum[i];
        int l = 0;
        int r = i + 1;
        while (r - l >= 1) {
            int mid = (r + l) / 2;
            if (2 * sum[mid] >= X) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }

        // r or r-1がX/2にもっとも近い
        ll P, Q;
        ll P1 = sum[r]; ll Q1 = X - P1;
        ll P2 = sum[r - 1]; ll Q2 = X - P2;
        if (abs(Q1 - P1) > abs(Q2 - P2)) {
            P = P2; Q = Q2;
        } else {
            P = P1; Q = Q1;
        }

        // 左
        ll Y = sum[N] - sum[i];
        l = i + 1;
        r = N + 1;
        while (r - l >= 1) {
            int mid = (r + l) / 2;
            if (2 * (sum[mid] - sum[i]) >= Y) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }

        ll R, S;
        ll R1 = sum[r] - sum[i]; ll S1 = Y - R1;
        ll R2 = sum[r - 1] - sum[i]; ll S2 = Y - R2;
        if (abs(S1 - R1) > abs(S2 - R2)) {
            R = R2; S = S2;
        } else {
            R = R1; S = S1;
        }

        ans = min(ans, abs(max(P, max(Q, max(R, S))) - min(P, min(Q, min(R, S)))));
    }
    cout << ans << endl;
}

Measured memory_bytes: 6396
#include <iostream>
#include<math.h>
#include <algorithm>
#include<string>
using namespace std;

int main() {
        long long int x,y;
        int ans=0;

        cin >> x >> y;
        long long int keep=x;

        while(keep<=y){
                ans++;
                keep*=2;
        }

        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#include <set>
#include <map>
typedef long long int ll;
using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll t;
	cin >> t;
	if(t% 1000 == 0)
		cout << 0;
	else
		cout << 1000*(t/1000 + 1) - t;
	return 0;
}

Measured memory_bytes: 3644
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
const int N=2e5+3;
int sz1[N],sz2[N];
int p1[N],p2[N];
int find(int a,int par[])
{
  while(a!=par[a])a=par[a];
  return par[a];
}
void uni(int a,int b, int sz[], int par[])
{
  a=find(a,par);b=find(b,par);
  if(a==b)return;
  if(sz[a]<sz[b])swap(a,b);
  sz[a]+=sz[b];
  par[b]=a;
}
int32_t main()
{
  #ifndef ONLINE_JUDGE
    freopen("in","r",stdin);
    freopen("out","w",stdout);
  #endif

  int n,k,l;
  cin>>n>>k>>l;
  for(int i=0;i<n;i++){p1[i]=p2[i]=i;sz1[i]=sz2[i]=1;}
  for(int i=0;i<k;i++)
  {
    int u,v;
    cin>>u>>v;
    u--;v--;
    uni(u,v,sz1,p1);
  }
  for(int i=0;i<l;i++)
  {
    int u,v;cin>>u>>v;
    u--;v--;
    uni(u,v,sz2,p2);
  }
  map<pair<int,int>,int> m;
  for(int i=0;i<n;i++)
  {
    m[{find(i,p1),find(i,p2)}]++;
  }
  for(int i=0;i<n;i++)
    cout<<m[{find(i,p1),find(i,p2)}]<<" ";
}

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

    vector<ll> adj[200];
    ll p[150], dis[200][200];

    void solve() {
        ll n, m;
        cin >> n >> m;

        for(ll i = 1; i <= n; i++)
            for(ll j = 1; j <= n; j++)
                dis[i][j] = 1000000;

        for(ll i = 1; i <= n; i++) dis[i][i] = 0;

        ll xi[m], yi[m], di[m];
        for(ll i = 0; i < m; i++) {
            ll x, y, d;
            cin >> x >> y >> d;
            xi[i] = x, yi[i] = y, di[i] = d;
            adj[x].push_back(y);
            adj[y].push_back(x);
            dis[x][y] = d, dis[y][x] = d;
        }

        for(ll k = 1; k <= n; k++)
            for(ll i = 1; i <= n; i++)
                for(ll j = 1; j <= n; j++)
                    if(dis[i][k] + dis[k][j] < dis[i][j]) {
                        dis[i][j] = dis[i][k] + dis[k][j];
                    }
       ll cnt = m;
        for(ll i = 0; i < m; i++) {
           bool pre = false;
            for(ll k = 1; k <= n; k++) if(dis[k][xi[i]] + di[i] == dis[k][yi[i]]) pre = true;
            pre ? cnt--:0;
        }
        cout << cnt << endl;
    }

    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      //ll ti;   cin >> ti;  while(ti--)
      solve();
      return 0;
    }


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define loop(i,x,n) for(ll i = x;i<n;i++)
#define loopr(i,x,n) for(ll i = n-1;i>=x;i--)
#define S(v) sort(v.begin(), v.end());
#define ff first
#define ss second
map<ll,bool> empty;


int main()
{		
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	ll t = 1;
	// cin>>t;
	while(t--){
		string s;
		cin>>s;
		ll sum = 0;
		loop(i,0,s.size()){
			sum += int(s[i] -48);
			sum = sum%9;
		}
		cout<<(sum%9 == 0?"Yes":"No");
	}
}
/*

1 5 4 1 2 2 4

*/




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

int main() {
  int L;
  int R;
  
  int A;
  int B;
  int C;
  int D;
  
  cin >> A >> B >> C >> D;
  
  L = A + B;
  R = C + D;
  
  if(L > R){
  	cout << "Left" << endl;
  }else if(L == R){
  	cout << "Balanced" << endl;
  }else if(L < R){
  	cout << "Right" << endl;
  }
}

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

int main(){
	int p[8],i,j,v,min,t,minv,si;
	int c[]={4,1,4,1,2,1,2,1};
	
	while(~scanf("%d",&p[0])){
		for(i=1;i<8;i++){
			scanf("%d",&p[i]);
		}
		
		min=-1;
		minv=-1;
		for(i=0;i<8;i++){
			t=0;
			v=0;
			for(j=0;j<8;j++){
				t+=p[j]>c[(i+j)%8]?p[j]-c[(i+j)%8]:0;
				v+=(c[(i+j)%8])*pow(10,7-j);
			}
			if(min==t || min==-1){
				if(minv>v || minv==-1){
					min=t;
					minv=v;
					si=i;
				}
			}
			if(min>t || min==-1){
				min=t;
				minv=v;
				si=i;
			}
		}
		
		for(i=0;i<8;i++){
			printf("%d",c[(si+i)%8]);
			if(i!=7)printf(" ");
		}
		printf("\n");
	}
	return 0;
}

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

int main() {
	while (true) {
		int a, b,count=0;
		cin >> a >> b;
		if (a == 0 && b == 0) {
			break;
		}
		for (int i = a ; i > 1; i--) {
			for (int j = a-1 ; j >1; j--) {
				if (j >= i) continue;
				for (int k = 1; k < a - 1; k++) {
					if (k >= j)continue;
					if (i + j + k == b) {
						if (i != j&&j != k&&k != i) {
							count++;
						}
					}
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n), f(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> f[i];
    }
    sort(all(a));
    sort(all(f), greater<ll>());
    ll ok = LINF, ng = -1;
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2LL;
        ll s = 0;
        for (int i = 0; i < n; i++) {
            ll t = mid / f[i];
            s += max(0LL, a[i] - t);
        }
        if (s <= k) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << endl;
}

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

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

char s[4010]; 
int n; 

int main() {
  scanf("%d", &n); 
  scanf(" %s", s); 
  ll r = 0, g = 0, b = 0; 
  for(int i = 0; i < n; ++i) {
    r += s[i] == 'R'; 
    g += s[i] == 'G'; 
    b += s[i] == 'B'; 
  }

  ll ans = r * g * b; 
  for(int i = 0; i < n; ++i) {
    for(int j = 1; i + 2 * j < n; ++j) {
      set<int> st({s[i], s[i + j], s[i + 2 * j]}); 
      ans -= st.size() == 3; 
    }
  }
  printf("%lld\n", ans); 
}


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

using namespace std;

using ll = long long;

constexpr ll MOD = 1000000007;

#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
#else
#define print(...)
#endif

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

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

    cout << a*b << endl;

    return 0;
}

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

int n,a,b,now;
bool bisa;
pair<int,int> arr[200005];

int main(){
	scanf("%d",&n);
	for(int i =0;i<n;i++){
		scanf("%d%d",&a,&b);
		arr[i] = {b,a};
	}
	sort(arr,arr+n);
	now = 0;
	bisa = 1;
	for(int i =0;i<n;i++){
		a = arr[i].second;
		b = arr[i].first;
		now +=a;
		if(now>b){
			bisa = 0;
			break;
		}
	}
	if(bisa) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

int group=0;  // 所属連結成分番号
vector<vector<int>> Graph(100001,vector<int>(0));   // グラフ
vector<int>         groupE(100001,-1);  // 各人の所属連結成分番号
vector<int>         sizeR(100001,0);    // 各連結成分のサイズ
int wk_v=0; // 一時処理用頂点
void dfsR(int n){ // ややこしいので、頂点番号以外はグローバル変数
  groupE.at(n) = group;   // n さんの所属連結成分番号は group
  sizeR.at(group)++;      // 連結成分番号 group のサイズに n さんの 1 を加算
  rep(i,Graph.at(n).size()){
    wk_v = Graph.at(n).at(i); // 次に処理する人の番号
    if( groupE.at(wk_v)==-1 ){ dfsR(wk_v); }  // 繋がってる人の処理
  }
}

int main() {
// １．dfs で最初に友達の連結情報を収集
// ２．各人毎に、
//    連結サイズ－１－友人－ブロック
  int N; cin >> N;  // ＳＮＳ人数：2～10^5
  int M; cin >> M;  // 友達関係数：0～10^5
  int K; cin >> K;  // ブロック数：0～10^5
  vector<int> Ans(N+1,0); // 各人の友達候補の数
  int wk_M1,wk_M2;  // 友達関係取り込み用
  rep(i,M){
    cin >> wk_M1 >> wk_M2;
    Graph.at(wk_M1).emplace_back(wk_M2);  // 双方向で友達
    Graph.at(wk_M2).emplace_back(wk_M1);
  }

  // 各人の所属連結成分とそのサイズ情報を収集
  rep1(i,N){
    if( groupE.at(i)==-1 ){   // 所属連結成分番号が未設定の場合
      group++;  // 連結成分番号を加算
      dfsR(i);  // i さんを根にして dfs
    }
  }

  // 各人の所属連結成分のサイズ（＝自分＋友達候補＋友達＋ブロック？）
  rep1(i,N){
    Ans.at(i) = sizeR.at(groupE.at(i)) - 1;
  }
  // 友達が連結成分に含まれる場合、候補数から除外
  rep1(i,N){
    rep(j,Graph.at(i).size()){  // グラフの各辺に関する処理
      if(groupE.at(i)==groupE.at(Graph.at(i).at(j))){   // 同一連結成分にある。既に友達
        Ans.at(i)--;  // 自分の分だけ引く。相手の分は、自分の処理で引く
      }
    }
  }

  // ブロックが連結成分に含まれる場合、候補数から除外
  rep(i,K){
    cin >> wk_M1 >> wk_M2;  // ここに来て、ブロック情報を読み取り(^o^)
    if(groupE.at(wk_M1)==groupE.at(wk_M2)){   // 同一連結成分にある。ブロック済み
      Ans.at(wk_M1)--;
      Ans.at(wk_M2)--;
    }
  }
  // 最後に自分の分を引く
  rep1(i,N){
    cout << Ans.at(i) << " ";
  }
  cout << endl;

}


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

stock=[]

for i in range(N):
    for j in range(i+1,N):
        if xy[i][0]-xy[j][0]==0:
            if xy[i][1]-xy[j][1]>0:
                stock.append([xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]])
            else:
                stock.append([xy[j][0]-xy[i][0],xy[j][1]-xy[i][1]])
        elif xy[i][0]-xy[j][0]>0:
              stock.append([xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]])
        else:
              stock.append([xy[j][0]-xy[i][0],xy[j][1]-xy[i][1]])

stock.sort(key=lambda x:(x[0],x[1]))
counter=0
ans=0
for i in range(1,len(stock)):

    if stock[i]==stock[i-1]:
        counter+=1
    else:
        ans=max(ans,counter)
        counter=0
ans=max(ans,counter)
print(max(N-ans-1,1))

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;

struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll sum(ll l, ll r) {
  return (l+r)*(r-l+1) / 2;
}

int main() {
  int n, k; cin >> n >> k;
  mint ans;
  for(int i = k; i <= n+1; i++) {
    ll l = sum(0, i-1), r = sum(n-i+1, n);
    ans += r-l+1;
  }
  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 3644
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value

sys.setrecursionlimit(10**8)

#メモ化再帰
def rec(x):
    global dp
    if dp[x]!=-1:
        return dp[x]
    num = 0
    for a in adj[x]:
        num = max(num, rec(a)+1)
    dp[x] = num
    return num

#入力受け取り
N, M = mi()
x = li2(M)

#隣接リスト作成
adj = [[] for i in range(N)]
for i in range(M):
    x[i][0] -= 1
    x[i][1] -= 1
    adj[x[i][0]].append(x[i][1])

#メモ化再帰を実行
dp = [-1]*N
for i in range(N):
    rec(i)

print(max(dp))

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

data1 = input()
data2 = data1.split()
A = list(map(int, data2))

def half(num):
    return num / 2

ans = 0

while all(elem % 2 == 0 for elem in A):
    ans += 1
    A = [half(x) for x in A]

print(ans)

Measured memory_bytes: 3060
# AOJ 1030 Cubes Without Holes
# Python3 2018.7.6 bal4u

import sys
from sys import stdin
input = stdin.readline

# n <= 500,  2^9 = 512
while True:
	n, h = map(int, input().split())
	if n == 0: break
	ans = []
	for i in range(h):
		s = input()
		c = s[:2]
		a, b = s[3:].split()
		a, b = int(a)-1, int(b)-1
		if c == "xy":
			k = a+(b<<9)
			ans += [k+(z<<18) for z in range(n)]
		elif c == "xz":
			k = a+(b<<18)
			ans += [k+(y<<9) for y in range(n)]
		else:
			k = (a<<9)+(b<<18)
			ans += [k+x for x in range(n)]
	print(n**3-len(set(ans)))


Measured memory_bytes: 10136
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
 
const long long int INF= 1e18L + 5; 
 
int main() {
    long long int n,W;
	cin>>n>>W;
	long long int w[n],v[n];
	long long int s=0;
	for(int i=0;i<n;i++)
	{
	    cin>>w[i]>>v[i];
	    s=s+v[i];
	}
	vector<long long int> dp(s+1,INF);
	dp[0]=0;
	for(int j=0;j<n;j++)
	{
	for(int i=s;i>=1;i--)
	{
	        if(i>=v[j])
	        dp[i]= min((dp[i-v[j]] + w[j]),dp[i]);
	}
	}
	long long int x=0;
	for(long long int i=1;i<=s;i++)
	{
	    if(dp[i]<=W)
	    x= max(x,i);
	}
	cout<<x;
	return 0;
}

Measured memory_bytes: 1024
H, W = (int(i) for i in input().split()) 

G = []
for i in range(H):
    G.append(input())

# dp[i][j] : i, j までの経路 
min = 0
dp = [[min for i in range(W + 1)] for j in range(H + 1)]
dp[1][1] = 1

for i in range(W + 1):
    dp[0][i] = 0
for i in range(H + 1):
    dp[i][0] = 0


for hh in range(H):
    for ww in range(W):
        if G[hh][ww] == "#":
            dp[hh + 1][ww + 1] = 0
        else:
            if hh == 0 and ww == 0:
                dp[0][0] = 1
            else:
                dp[hh + 1][ww + 1] = dp[hh][ww + 1] + dp[hh+1][ww]


print(dp[hh+1][ww+1] % (10 ** 9 + 7))



            


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

using namespace std;

int main() {
  int r, D, x_2000;

  cin>>r>>D>>x_2000;

  for(int i=0; i<10; i++) {
    x_2000 = r * x_2000 - D;

    cout<<x_2000<<endl;
  }

  return 0;
}

Measured memory_bytes: 256
import sys
n = int(raw_input())
nums = list(map(int,raw_input().split()))
cnt1 = [0 for x in range(100001)]
cnt2 = [0 for x in range(100001)]
for i in range(n):
    if i%2:
        cnt1[nums[i]] += 1
    else:
        cnt2[nums[i]] += 1
a1 = -1
a2 = -1
n1 = 0
n2 = 0
b1 = -1
b2 = -1
m1 = 0
m2 = 0
for i in range(100001):
    if cnt1[i]>a1:
        a2 = a1
        a1 = cnt1[i]
        n2 = n1
        n1 = i
    elif cnt1[i]>a2:
        a2 = cnt1[i]
        n2 = i
    if cnt2[i]>b1:
        b2 = b1
        b1 = cnt2[i]
        m2 = m1
        m1 = i
    elif cnt2[i]>b2:
        b2 = cnt2[i]
        m2 = i
if m1!=n1:
    print n-a1-b1
else:
    if a2+b1<a1+b2:
        print n-a1-b2
    else:
        print n-a2-b1

Measured memory_bytes: 41324
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<string>
#include<cmath>
#include<set>
#include<stack>

using namespace std;

int h,w;
int sa[1005][1005];
int d[9]={-1,0,1};
struct P{
    int x,y,h;
    P(int a,int b, int c){x=a,y=b,h=c;}
};
int main(){
    cin>>h>>w;
    queue<P>q;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char c;
            cin>>c;
            if(c=='.'){
                sa[i][j]=0;
                q.push(P(j,i,0));
            } else sa[i][j]=c-'0';
        }
    }
    int ans=0;
    while(q.size()){
        P t=q.front();
        int y=t.y,x=t.x,ph=t.h;
        ans=ph;
        q.pop();
        for(int i=0;i<3;i++)
            for(int j=0;j<3;j++){
                int nx=x+d[i];
                int ny=y+d[j];
                if(nx>=0&&nx<w&&ny>=0&&ny<h&&--sa[ny][nx]==0)
                    q.push(P(nx,ny,ph+1));
            }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5412
#include <iostream>
#include <cstring>
#include <cmath>

using namespace std;


int main()
{
    int k,s;
    int x,y;
    int c = 0;
    
    cin >> k >> s;
    
    for(x = 0;x <= k;x++){
        for (y = 0;y <= k;y++){
            if (s-k <= x+y && x+y <= s){
                c++;
            }
        }
    }
    cout << c << "\n";
}


Measured memory_bytes: 256
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

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

#define io ios_base::sync_with_stdio(false)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
#define mod 998244353
#define pii pair<int, int>
#define PI 2*acos(0.0)

int main()
{
    io;
    ll n, m;
    cin>>n >>m;
    ll s = 0;
    while(m--)
    {
        int a;
        cin>>a;
        s+= a;
    }
    if(s > n)
        cout << -1;
    else
        cout << n - s;
    return 0;
}

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

int count(int n, int x) {
    int cnt = 0;

    for (int i = 1; i <= n - 2; i++) {
        for (int j = i + 1; j <= n - 1; j++) {
            for (int k = j + 1; k <= n; k++) {
                if (i + j + k == x) {
                    cnt++;
                }
            }
        }
    }

    return cnt;
}

int main() {
    int n, x;

    while (true) {
        cin >> n >> x;
        if (n == 0 && x == 0) {
            break;
        }
        cout << count(n, x) << endl;
    }

    return 0;
}


Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  vector<char> a={s.at(0),s.at(1),s.at(2),s.at(3)};
  sort(a.begin(),a.end());
  if(a.at(0)==a.at(1)&&a.at(1)!=a.at(2)&&a.at(2)==a.at(3))cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

int main()
{
    int ans = 0, min = 0;
    int vec[5], nnn[5];
    for (int i = 0; i < 5; i++)
    {
        vec[i] = 0;
        nnn[i] = 0;
        cin >> vec[i];
        nnn[i] = 10 - vec[i] % 100 % 10;
        if (nnn[i] != 10)
            ans += vec[i] + nnn[i];
        else
        {
            ans += vec[i];
        }
    }
    for (int i = 0; i < 5; i++)
    {
        if (nnn[i] != 10 && min < nnn[i])
            min = nnn[i];
        //cout << vec[i]+nnn[i] << endl;
    }
    cout << ans - min << endl;
}

Measured memory_bytes: 256
def floor_sum(n, m, a, b):
    res = 0
    if a >= m:
        res += (n - 1) * n * (a // m) // 2
        a %= m
    if b >= m:
        res += n * (b // m)
        b %= m
    y_max = (a * n + b) // m
    x_max = y_max * m - b
    if y_max == 0:
        return res
    res += y_max * (n + (-x_max // a))
    res += floor_sum(y_max, a, m, (a - x_max % a) % a)
    return res
q = int(input())
for i in range(q):
    n, m, a, b = map(int, input().split())
    print(floor_sum(n, m, a, b))

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

const int N = (int)1e3 + 3;
const int M = (int)1e4 + 4;
const int INF = (int)2e9 + 9;

int h,n,a[N],b[N],dp[M];

int main(){
    cin >> h >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
    }
    memset(dp,INF,sizeof(dp));
    dp[0] = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= h; j++){
            if(j + a[i] <= h) dp[j + a[i]] = min(dp[j + a[i]],dp[j] + b[i]);
            else dp[h] = min(dp[h],dp[j] + b[i]);
        }
    }
    cout << dp[h];
 	return 0;  
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n, x, c;
	int i, j, k;
	while(scanf("%d %d\n", &n, &x) == 2) {
		if(n==0 && x == 0)
			break;
		
		c=0;	
		for(i=1;i<=n-2;i++) {
			for(j=i+1;j<=n-1;j++) {
				for(k=j+1;k<=n;k++) {
					if(i+j+k==x) {
						c++;
					}
				}
			}
		}
		printf("%d\n", c);
	}
	
	return 0;
}

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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;

using namespace std;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 
	string s;
	cin >> s;
	int n = 0;
	rep(i ,sz(s)){
		if(s[i] == 'S')++n;
		if(s[i] == 'T' && n)--n;
	}
	cout <<  2 * n << nl;


	return 0;
}

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

int main() {
  long long N, D;
  cin >> N >> D;
  long long X[N], Y[N];
  for (int i = 0; i < N; i++) cin >> X[i] >> Y[i];
  
  long long count = 0;
  
  for (int i = 0; i < N; i++){
    if (X[i] * X[i] + Y[i] * Y[i] <= D * D) count++;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 6684
N, K = list(map(int, input().split(" ")))

n = N // K
if K % 2 == 0:
    if N % K >= K/2:
        # print("A")
        print((n+1)**3 + n**3)
    else:
        # print("B")
        print(n**3 + n**3)
else:
    # print("C")
    print(n**3)


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#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 a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  if (e - a > k) cout << ":(" << endl;
  else cout << "Yay!" << endl;
  return 0;
}

Measured memory_bytes: 3048
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

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

signed main() {
    SS(ll,n,a,b)
    p(min(n*a,b));
}

Measured memory_bytes: 256
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()

int d;
ll c[26], s[370][26], last[370][26], t[370];


ll calc(ll dl){
        ll score = 0;
        REP(i, 1, dl+1){
                REP(j, 0, 26){
                        if(j==t[i]-1){
                                score += s[i][j];
                                last[i][j] = i;
                        }else last[i][j] = last[i-1][j];
                        score -= c[j] * (i - last[i][j]);
                }
        }
        return score;
};

int main(){
        scanf("%d", &d);
        REP(i, 0, 26) scanf("%ld", &c[i]);
        REP(i, 1, d+1) REP(j, 0, 26) scanf("%ld", &s[i][j]);
        REP(i, 1, d+1) t[i] = 0;
        REP(j, 0, 26) last[0][j] = 0;

        REP(i, 1, d+1){
                ll score = calc(i);
                REP(j, 0, 26){
                        ll prev = t[i];
                        t[i] = j+1;
                        ll newscore = calc(i);
                        if(newscore > score) score = newscore;
                        else t[i] = prev;
                }
        }

        REP(i, 1, d+1) printf("%ld\n", t[i]);
        return 0;
}

Measured memory_bytes: 3980
from collections import Counter
N = int(input())
S = input()
array = []
for i in range(1,N):
    S1 = list(S[:i])
    S2 = list(S[i:])
    S1c = Counter(S1)
    S2c = Counter(S2)
    suma = 0
    for k in S1c:
        if k in S2c:
            suma += 1
    array.append(suma)
print(max(array))

Measured memory_bytes: 3316
import numpy as np

L, R = [int(i) for i in input().split()]

if R - L > 2019:
  print(0)
else:
  arr = np.array(range(L, R + 1)) % 2019
  arr_1 = arr[:, np.newaxis]
  arr_2 = arr[np.newaxis, :]
  arr_X = (arr_1 * arr_2) % 2019
  np.fill_diagonal(arr_X, 2018)
  print(np.min(arr_X))

Measured memory_bytes: 76132
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();
int area = a*b;
int length = 2*a+2*b;
System.out.println(area + " " + length); 
}
}

Measured memory_bytes: 25904
#include <stdio.h>
#include <string.h>

long A[1000000];
long a=1000000,b=999999;

void insert(long n){
  A[--a] = n;
  return;
}
void deleteFirst(){
  if(a>b) return;
  a++;
  while(A[a] <0) a++;
  return;
}
void deleteLast(){
  if(a>b) return;
  b--;
  while(A[b] <0) b--;
  return;
}
void delete(long n){
  long i;
  if(a>b) return;
  else if(A[a]==n) {deleteFirst();return;}
  i=a+1;
  while(i<b){
    if(A[i]==n){
      A[i]=-1;
      return;
    }
    i++;
  }
  if(A[b]==n) {deleteLast(); return;}
  return;
}
void printQueue(){
  int i;
  if(a>b);
  else if(a==b)
    printf("%ld\n", A[a]);
  else {
    for (i=a; i<b; i++)
      if(A[i]>=0) printf("%ld ",A[i]);
    printf("%ld\n", A[b]);
  }
  return;
}
int main(){
  long n,N; char c[12];
  scanf("%ld\n",&N);
  while(scanf("%s %ld\n",c,&n) != EOF){
    if(*c=='i')
      insert(n);
    else if(*(c+6)=='F')
      deleteFirst();
    else if(*(c+6)=='L')
      deleteLast();
    else
      delete(n);
  }
  printQueue();
  return 0;
}



Measured memory_bytes: 9516