akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for (long long i=0;i<(n);i++)
#define FOR(i,a,b) for (long long i=(a);i<(b);i++)
#define RREP(i,n) for(long long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl
#define dump(x)  cerr << #x << " => " << (x) << endl
#define dumpP(p) cerr << "( " << p.first << " , " << p.second << " )" << ends
#define SORT(c) sort((c).begin(),(c).end())
#define MIN(vec) *min_element(vec.begin(), vec.end())
#define MAX(vec) *max_element(vec.begin(), vec.end())
#define UNIQ(vec) vec.erase(unique(vec.begin(), vec.end()),vec.end()) //ソートの必要あり
#define IN(n,m)  (!(m.find(n) == m.end()))
#define ENUM(m) for (auto itr = m.begin(); itr != m.end(); ++itr)
#define dump_MAP(m) for(auto itr = m.begin(); itr != m.end(); ++itr) { cerr << itr->first << " --> "  << itr->second << endl; }
#define FINDL(vec,x) (lower_bound(vec.begin(),vec.end(),x) - vec.begin())
#define FINDU(vec,x) (upper_bound(vec.begin(),vec.end(),x) - vec.begin())
#define ROUND(N) setprecision(N)
#define ROUND_PRINT(N,val) cout << fixed;cout << setprecision(N) << val << endl
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define INARR(h,w,x,y) (0 <= y && y < h && 0 <= x && x < w)
#define EQ(a,b) (abs(a - b) < 1e-10)
using namespace std;
constexpr int dx[4] = {0,1,0,-1};
constexpr int dy[4] = {1,0,-1,0};
constexpr long double pi = M_PI;
constexpr double eps = 1e-10;
constexpr long mod = 1000000007;
constexpr short shINF = 32767;
constexpr long loINF = 2147483647;
constexpr long long llINF = 9223372036854775807;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<LL,LL> pr;
typedef vector<bool> VB;
typedef vector<pr> VP;
struct Order {
	bool operator() (pr const& a,pr const& b) const {
		return a.first > b.first || ((a.first == b.first) && (a.second > b.second));
	}
};

int f(int a,int b,int rate) {
	return (a * ((100+rate))/100 + (b * (100+rate))/100);
}
int main(void) {
	int x,y,s,ans;
	while(1) {
		ans = 0;
		cin >> x >> y >> s;
		if (x == 0 && y == 0 && s == 0) break;
		FOR(A,1,s) {
			FOR(B,1,s) {
				if (f(A,B,x) != s) continue;
				ans = max(ans,f(A,B,y));
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3040
#include<bits/stdc++.h>
using namespace std;
int C,N;
char A[1000][1000];
int t[1000][1000];
int total=0;

bool check(int x,int y){
  return (A[x][y]==A[N-1-x][y] && A[x][y]==A[x][N-1-y]);
}

void update(int x,int y){
  total-=t[x][y];
  t[x][y]=check(x,y);
  total+=t[x][y];
}

void change(int x,int y){
  A[x][y]='0'+'1'-A[x][y];
  update(x,y);
  update(N-1-x,y);
  update(x,N-1-y);
}

int solve(){
  return (total==N*N);
}

int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin>>C>>N;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cin>>A[i][j];
    }
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      t[i][j]=check(i,j);
      total+=t[i][j];
    }
  }

  int ans=solve();
  for(int i=0;i<C-1;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int x,y;
      cin>>x>>y;
      x--,y--;
      change(x,y);
    }
    ans+=solve();
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 8016
#include "bits/stdc++.h"
using namespace std;

int main(){
	long long int n,k;
	cin>>n>>k;
	map<char,long long int> mp;
	
	for(long long int i=0;i<n;i++){
		string s;
		cin>>s;
		mp[s[0]]++;
	}
	
	long long int ans=0;
	vector<long long int> a(26);
	
	for(int i=0;i<26;i++){
		a[i]=mp['A'+i];
	}
	
	
	
	while(1){
		long long int p=0;
		sort(a.begin(),a.end(),greater<long long int>());
		for(long long int i=0;i<26;i++){
			if(p<k&&a[i]!=0){
				a[i]--;
				p++;
			}
		}
		if(p==k){
			ans++;
		}else{
			break;
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}
	

Measured memory_bytes: 256
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65
//おまじない



int main() {

	int city[50] = { 0 };
	int n, m;
	cin >> n >> m;

	rep(i, 0, m) {
		int a, b;
		cin >> a >> b;
		city[a-1] += 1;
		city[b-1] += 1;
	}

	rep(i, 0, n) {
		cout << city[i] << endl;
	}




	return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n, m;
int a[300][300];
int pos[300];
int cnt[300] = {};
bool del[300] = {};
int ans;

int main() {
    scanf("%d%d", &n, &m);
    forn(i, n) forn(j, m) scanf("%d", a[i] + j), --a[i][j];
    ans = 0;
    forn(i, n) {
        pos[i] = 0;
        ans = max(ans, ++cnt[a[i][0]]);
    }
    forn(_, m - 1) {
        int ind = 0;
        forn(i, m) if (cnt[i] > cnt[ind]) {
            ind = i;
        }
        del[ind] = true;
        forn(i, n) while (del[a[i][pos[i]]]) {
            --cnt[a[i][pos[i]]];
            ++pos[i];
            ++cnt[a[i][pos[i]]];
        }
        int cur = 0;
        forn(i, m) cur = max(cur, cnt[i]);
        ans = min(ans, cur);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int n,i,a[100001],k=1,h=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	sort(a,a+n);
	for(i=0;i<n;i++)
	{
		if(a[i]==a[i+1])
		{
			k++;
		}
		else
		{
			if(k==a[i])
			{
				k=1;
			}
			else if(k>a[i])
			{
				h=h+k-a[i];
				k=1;
			}
			else
			{
				h=h+k;
				k=1;
			}
		}
	}
	printf("%d\n",h);
	return 0;
}





		

		

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

#ifdef BTK
#define DEBUG if(1)
#else
#define DEBUG if(0)
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#endif

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r){bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r){bool a=l<r;if(a)l=r;return a;}
template <typename T>istream& operator>>(istream &is,vector<T> &v){for(auto &it:v)is>>it;return is;}

constexpr char ln = '\n';
constexpr int mod = 1e9+7;
const string ok = "Yes";
const string ng = "No";
void f(int K,vector<int>& v){
    int id=0;
    while(v[id]==0)id++;
    if(v[id]==1){
        v[id]=0;
    }
    else{
        v[id]--;
        REP(i,id)v[i]=K;
    }
}

void solve(int K,int N){
    if(K%2==0){
        cout<<K/2;
        REP(i,N-1)cout<<" "<<K;
        cout<<endl;
    }
    else{
        int x=N/2;

        if(K!=1){
            int p=(K+1)/2;
            vector<int> ret(N,p);
            REP(i,x){
                f(K,ret);
            }
            reverse(ALL(ret));
            cout<<ret[0];
            FOR(i,1,N)if(ret[i])cout<<" "<<ret[i];
            cout<<endl;
        }
        else{
            int len=N-x;
            REP(i,len-1)cout<<1<<" ";
            cout<<1<<endl;
        }
    }
}
int main(){
    int k,n;
    cin>>k>>n;
    solve(k,n);
    return 0;
}


Measured memory_bytes: 3456
#include <cstdio>
#include <set>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

#define ll unsigned long long
const ll N = 1000000000;

void solve() {
}

int main(){
    string s;
    cin >> s;
    if (s[1] == 'B') {
        s[1] = 'R';
    } else {
        s[1] = 'B';
    }

    cout << s;


    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>

 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vvi;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 



int main(){
	int s=0,t=0,u;
	rep(i,4) cin>>u,s+=u;
	rep(i,4) cin>>u,t+=u;
	cout<<max(s,t)<<endl;
}

Measured memory_bytes: 1160
n = int(input())
s = input()
s = list(s)

for i in range(len(s)):
    if ord(s[i])+n > 90:
        s[i] = chr(ord(s[i])+n-26)
    else:
        s[i] = chr(ord(s[i])+n)
print("".join(s))

Measured memory_bytes: 9084
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
ans = sum(B)
for i in range(N-1):
    if A[i] + 1 == A[i+1]:
        ans += C[A[i]-1]
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <stdlib.h>

using namespace std;

int main(void)
{
    int x1,y1,x2,y2;
    int sx,sy;

    cin >> x1 >> y1 >> x2 >> y2;

    sx = x2 - x1;
    sy = y2 - y1;

    cout << x2 - sy << " " << y2 + sx << " " << x1 - sy << " " << y1 + sx << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int k;
    cin>>k; int b[101];

        for(int i=0;i<101;i++)
            b[i]=0;
    while(k--)
    {
        int d;
        cin>>d;
        int a[d];
        for(int i=0;i<d;i++)
            cin>>a[i];

        for(int i=0;i<d;i++)
            b[a[i]]++;
    }int ctr=0;
    for(int i=1;i<=n;i++)
    {//cout<<b[i]<<" ";
        if(b[i]==0)
            ctr++;
    }
    cout<<ctr;
}


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

const int maxn=1e5+10;
const int maxm=2e5+10;

int n,k,L[maxn],R[maxn];
int c0,c1,dep[maxn],fa[maxn];
int tote,TO[maxm],NEXT[maxm],FIR[maxn];

void addedge(int u,int v)
{
	TO[++tote]=v;
	NEXT[tote]=FIR[u];
	FIR[u]=tote;
}

void prework(int u)
{
	dep[u]=dep[fa[u]]+1;
	for (int p=FIR[u];p;p=NEXT[p])
	{
		int v=TO[p];
		if (v==fa[u]) continue;
		fa[v]=u;
		prework(v);
	}
}

bool solve1(int u)
{
	bool flag=1;
	for (int p=FIR[u];p;p=NEXT[p])
	{
		int v=TO[p];
		if (v==fa[u]) continue;
		flag&=solve1(v);
	}
	if (L[u]>-1e7||R[u]<1e7)
	{
		L[fa[u]]=max(L[fa[u]],L[u]);
		R[fa[u]]=min(R[fa[u]],R[u]+2);
	}
	return flag&(L[u]<=R[u]);
}

void solve2(int u)
{
	if (L[u]<=-1e7&&R[u]>=1e7)
		L[u]=R[u]=L[fa[u]];
	else
	{
		if (!fa[u]) R[u]=L[u];
		else
		{
			if (L[u]<=L[fa[u]]&&L[fa[u]]<=R[u])
				L[u]=R[u]=L[fa[u]];
			else
				L[u]=R[u]=L[fa[u]]-2;
		}
	}
	for (int p=FIR[u];p;p=NEXT[p])
		if (TO[p]!=fa[u]) solve2(TO[p]);
}

int main()
{
#ifdef h10
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	int i,u,v;
	scanf("%d",&n);
	for (i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		addedge(u,v);
		addedge(v,u);
	}
	prework(1);

	for (i=1;i<=n;i++)
		L[i]=-1e8,R[i]=1e8;

	scanf("%d",&k);
	for (i=1;i<=k;i++)
	{
		scanf("%d%d",&u,&v);
		v-=dep[u];
		v&1?c1++:c0++;
		L[u]=R[u]=v;
	}
	if (c1&&c0) {puts("No"); return 0;}
	if (!solve1(1)) {puts("No"); return 0;}
	solve2(1);
	puts("Yes");
	for (i=1;i<=n;i++)
		printf("%d\n",L[i]+dep[i]);
}


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

int main()
{
  string S;
  cin >> S;
  int N = S.size();
  int one, zero;
  one = zero = 0;

  for(int i = 0; i < N; i++){
    switch(S[i]){
      case '1':
        one++;
        break;
      case '0':
        zero++;
        break;
      default:
        break;
    }
  }

  cout << min(one, zero) * 2 << endl;

  return 0;
}

Measured memory_bytes: 512
//div 3 c
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long int
int main()
{
	string s;
	cin>>s;
	ll check=1;
	if(s[2]!=s[3])
	{
		check=0;
	}
	if(s[4]!=s[5])
	{
		check=0;
	}
	if(check)
	{
		cout<<"Yes"<<endl;
	}
	else
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>

 

using namespace std;

 

int main()
{
   int a , b;
   cin >> a >> b;

   
   if (a == b)
       cout << "a == b" << endl; 
   else if (a > b)
       cout << "a > b" << endl;
   else
       cout << "a < b" << endl;
   
   return 0;
}


Measured memory_bytes: 3108
from collections import Counter

def main():
    num = int(input())
    data = Counter(list(map(int, input().split())))
    score_sorted = sorted(data.items(), key=lambda x: -x[0])

    ans = []
    for ele, kosuu in score_sorted:
        if kosuu >= 2:
            if len(ans) == 0 and kosuu >= 4:
                ans = [ele, ele]
                break
            else:
                ans.append(ele)
                if len(ans) == 2:
                    break
    if len(ans) == 2:
        print(ans[0] * ans[1])
    else:
        print(0)



if __name__ == '__main__':
    main()




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

using namespace std;

// Repetitions
#define FOR(i,a,n) for(ll i = ((ll) a); i < ((ll) n); ++i)
#define FORR(i, s, g) for(ll i = ((ll)s - 1); i >= ((ll) g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)

// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

// For Debug
#define DMP(x)  cerr << #x << " = " << (x) << endl
#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

// Aliases
#define PB push_back
#define MP make_pair
using ll = long long;
using ld = long double;
using str = string;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vs = vector<str>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

// Constant variables
const ld PI = (acos(-1));
const ll MOD = 1000000007;

// I/O Asynchronizing
struct __io_async{
    __io_async(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
};

#define BINGO_SIZE 3
int a[BINGO_SIZE][BINGO_SIZE];
bool called[BINGO_SIZE][BINGO_SIZE];

inline bool judge() {
    return (called[0][0] && called[0][1] && called[0][2]) || (called[1][0] && called[1][1] && called[1][2]) || (called[2][0] && called[2][1] && called[2][2]) ||
        (called[0][0] && called[1][0] && called[2][0]) || (called[0][1] && called[1][1] && called[2][1]) || (called[0][2] && called[1][2] && called[2][2]) ||
        (called[0][0] && called[1][1] && called[2][2]) || (called[0][2] && called[1][1] && called[2][0]);
}

int main() {
    REP(i, BINGO_SIZE) {
        REP(j, BINGO_SIZE) {
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    REP(i, n) {
        int b;
        cin >> b;
        REP(j, BINGO_SIZE) {
            REP(k, BINGO_SIZE) {
                if(a[j][k] == b) called[j][k] = true;
            }
        }
    }
    cout << (judge() ? "Yes" : "No") << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <time.h>
#define int long long int
#define pb push_back
#define all(a) a.begin(), a.end()
#define scnarr(a, n) for (int i = 0; i < n; ++i) cin >> a[i]
#define vi vector<int>
#define si set<int>
#define pii pair <int, int>
#define sii set<pii>
#define vii vector<pii>
#define mii map <int, int>
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
using namespace chrono;
/*
	Things to remember : check for coners n = 1, pass references instead
*/
/* -------------------------------Solution Sarted--------------------------------------*/

//Constants
const int MOD = 1000000007; // 1e9 + 7
const int MAXN = 1000005; // 1e6 +5
const int INF = 100000000000005; // 1e15 +5

void solve(){
	int n, cnt = 0;
	string s;
	cin >> n >> s;
	int i = 0, j = n -1;
	while(i < j){
		if(s[i] == 'W' and s[j] == 'R'){
			s[i] ^= s[j]; s[j] ^= s[i]; s[i] ^= s[j];
			++i, --j;
			cnt++;
		}else if(s[i] == 'W'){
			--j;
		}else{
			++i;
		}
	}
	cout << cnt << endl;
}

signed main()
{
	faster;
#ifndef ONLINE_JUDGE
	freopen("ip.txt", "r", stdin);
	freopen("op.txt", "w", stdout);
#endif
	// int t; cin >> t; while(t--)
		solve();
	return 0;
}


//Author : Ankit Raj
//Problem Link :

/*Snippets*/
/*
sieve - prime factorization using sieve and primes in range
zpower - pow with mod
plate - Initial template
bfs 
dfs
fenwik - BIT
binary_search
segment_tree
*/
	

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

int main() {
  int A, B;
  cin >> A >> B;
  
  int ans;
  if ((A > 9) || (B > 9)) {
    ans = -1;
  } else {
    ans = A * B;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long a[10001]={0};
    int n;
    long long min;
    long long max;
    int i;
    long long sum=0;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    min=a[0];
    for(i=0;i<n;i++){
        if(min>a[i])    min=a[i];
        }
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    max=a[0];
    for(i=0;i<n;i++){
        if(max<a[i])    max=a[i];
        }    
    for(i=0;i<n;i++)    sum=sum+a[i];        
    cout<<min;
    cout<<" ";
    cout<<max;
    cout<<" ";
    cout<<sum;
    cout<<endl;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
//#define Akshay

using namespace std;

template< class t>
long long int gcd( t g,t h )
{
    return ( h==0 ? g : gcd(h,g%h) );
}

int main()
{
    #ifdef Akshay
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    	
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a,b;
    
    cin>>a>>b;
    
    cout<<((a+b)%24);
    
    return 0;
    
}


Measured memory_bytes: 256
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

a1 = T1 * A1
a2 = T2 * A2
a = a1 + a2
b1 = T1 * B1
b2 = T2 * B2
b = b1 + b2


def bis(p, ok, ng):
    mid = (ok + ng) // 2
    return (
        ok if abs(ok - ng) == 1 else
        bis(p, mid, ng) if p(mid) else
        bis(p, ok, mid)
    )


def p(k):
    x = k * a
    y = k * b
    # print(f"k: {k}, x: {x}, y: {y}")
    #print(f"k: {k}, x+: {x + a1}, y+: {y + b1}")
    if x < y:
        return x + a1 >= y + b1
    else:
        return y + b1 >= x + a1


def p2(k):
    x = k * a + a1
    y = k * b + b1
    if x < y:
        return x + a2 >= y + b2
    elif x > y:
        return y + b2 >= x + a2
    else:
        return False

if a == b:
    ans = "infinity"
else:
    # print(bis(p, -1, 10**16))
    # print(bis(p2, -1, 10**16))
    c = 1 if (a1 < b1 and a > b) or (b1 < a1 and b > a) else 0
    # k = bis(lambda k: k * a + a1 >= k * b + b1, 0, 10**16) if a < b else bis(lambda k: k * a + a1 <= k * b + b1, 0, 10**16)
    # d = if k * a + a1 == k * b + b1
    ans = bis(p, 0, 10**16) + bis(p2, 0, 10**16) + c

print(ans)

# print('-------')

# x = 0
# y = 0
# for i in range(114):
#     x += a1
#     y += b1
#     #print(x, y)
#     print(f"{i} {x < y}")
#     x += a2
#     y += b2
#     print(f"{i} {x < y}")
#     #print(x, y)




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

const ll INF = 1001001001;

ll gcd(ll a,ll b){
  if(b==0) return a;
  else return gcd(b,a%b);
}

int main(){

  ll n; cin>>n;
  map<string,int>mp;
  
  rep(i,n){
    string s; cin>>s;
    mp[s]++;
  }
  int ans=0;
  for(auto p:mp){
    ans++;
  }
  cout<<ans<<endl;
  
  
}



Measured memory_bytes: 19204
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-12;

	int m, start;

	void run(){
		for(;;){
			m=sc.nextInt();
			start=sc.nextInt();
			if((m|start)==0){
				break;
			}
			solve();
		}
	}

	int[] isPrime;

	void solve(){
		int M=(int)1e6+100;
		if(isPrime==null){
			isPrime=new int[M];
			fill(isPrime, 1);
			isPrime[0]=isPrime[1]=0;
			for(int j=0; j<M; j++){
				if(isPrime[j]==0){
					continue;
				}
				for(int i=j*2; i<M; i+=j){
					isPrime[i]=0;
				}
			}
		}
		int n=2000;
		int[][] dp=new int[n][n];
		int[][] index=new int[n][n];
		for(int i=0; i<n; i++){
			fill(dp[i], -1);
		}
		int[] _=spiralN2XY(start);
		int x0=_[0]-n/2, y0=_[1];
		dp[0][n/2]=isPrime[start];
		index[0][n/2]=start*isPrime[start];
		for(int j=0; j<n; j++){
			for(int i=0; i<n; i++){
				if(dp[j][i]<0){
					continue;
				}
				for(int k=-1; k<=1; k++){
					if(j+1>=n||i+k<0||i+k>=n){
						continue;
					}
					int val=spiralXY2N(x0+i+k, y0+j+1);
					// debug(val, x0+i+k, y0+j+1);
					if(val>m){
						continue;
					}
					if(dp[j][i]+isPrime[val]>dp[j+1][i+k]){
						dp[j+1][i+k]=dp[j][i]+isPrime[val];
						// index[j+1][i+k]=val;
						index[j+1][i+k]=isPrime[val]==1?val:index[j][i];
						// index[j+1][i+k]=max(index[j][i], val*isPrime[val]);
					}
				}
			}
			// left--;
			// right++;
			// debug(dp[j]);
		}
		for(int j=0; j<n; j++){
			// debug(index[j]);
		}
		int maxVal=0, maxIndex=0;
		for(int j=0; j<n; j++){
			for(int i=0; i<n; i++){
				if(dp[j][i]>maxVal||(dp[j][i]==maxVal&&index[j][i]>maxIndex)){
					maxVal=dp[j][i];
					maxIndex=index[j][i];
				}
			}
		}
		println(maxVal+" "+maxIndex);
	}

	int[] spiralN2XY(int n){
		int m=(int)sqrt(n-1)+1; // n<=m^2 NOTE: in the case of long...?
		int x=m/2-min(m*m-n, m-1), y=m/2-max(m*m-m+1-n, 0);
		if(m%2==0){
			x=-x+1;
			y=-y;
		}
		return new int[]{x, y};
	}

	int spiralXY2N(int x, int y){
		int d=max(abs(x), abs(y));
		if(y>=x)
			return (2*d+1)*(2*d+1)-abs(d-x)-abs(d-y);
		else
			return (2*d)*(2*d)-abs(-d+1-x)-abs(-d-y);
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 507304
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n;
while(  cin >> n ){
int h = n/3600;

int m = (n%3600)/60;

int s = (n%3600)%60;

cout << h << ":" << m << ":" << s  << endl;
}


    return 0;
}


Measured memory_bytes: 3084
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
//#define rep1(i,n) for(ll i=1;i<=n;++i);
struct Tree{
  vector<int> top;
  int num;
  ll count;
  void calc(){
    num=top.size();
    count=0;
  }
};
void solve(vector<Tree>& tree,int n,vector<int>& memo){
  queue<int> next;
  next.push(1);
  memo[1]==1;
  while(!next.empty()){
    int buf=next.front();
    next.pop();
    for(int i=0;i<tree[buf].num;i++){
      int buf2=tree[buf].top[i];
      if(memo[buf2]!=0)continue;
      next.push(buf2);
      tree[buf2].count+=tree[buf].count;
      memo[buf]=1;
    }
  }
  for(int i=1;i<=n;i++){
    cout<<tree[i].count<<" ";
  }
  cout<<endl;
}
int main(){
  int n,q;
  cin>>n>>q;
  vector<Tree> tree(n+1);
  vector<int> memo(n+1,0);
  int a,b;
  for(int i=0;i<n-1;i++){
    cin>>a>>b;
    tree[a].top.push_back(b);
    tree[b].top.push_back(a);
  }
  for(int i=1;i<=n;i++)tree[i].calc();
  int p,x;
  for(int i=0;i<q;i++){
    cin>>p>>x;
    tree[p].count+=x;
  }
  solve(tree,n,memo);
  return 0;
}


Measured memory_bytes: 18676
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;

signed main() {
	double a, b, p, q, r; cin >> a >> b >> p >> q >> r;
	printf("%.9lf\n", b + (b*p - (b - a)*q) / (q + r));
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, std::vector<long long> B){
    B.insert(B.begin(), INFL);
    B.PB(INFL);

    LL ans = 0;
    REP(i, B.size()-1) {
        ans += min(B[i], B[i+1]);
    }

    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> B(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(B));
    return 0;
}


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


#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  int n;
  cin >> n;
  int h[n];
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  
  int dp[n] = {0};
  for(int i=0;i<n-1;i++){
    if(i==0){
      dp[i+1] = dp[i]+abs(h[i]-h[i+1]);
    }
    else{
      dp[i+1] = min(dp[i]+abs(h[i]-h[i+1]), dp[i-1]+abs(h[i-1]-h[i+1]));
    }
  }

  cout << dp[n-1] << endl;
  
  return 0;
}


Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int h;
  cin >> h;
  vector<int> m(h);
  for(int i=0;i<h;i++){
    cin >> m.at(i);
  }
  int w;
  cin >> w;
  vector<int> p(w);
  for(int i=0;i<w;i++){
    cin >>p.at(i);
  }
  sort(m.begin(),m.end());
  sort(p.begin(),p.end());
  int k=0;
  for(int i=0;i<w;i++){
    for(int j=k;j<h;j++){
      if(p.at(i)==m.at(j)){
        k=j+1;
        break;
      }
      if(j==h-1){
        cout <<"NO";
        return 0;
      }
    
        
    }
  }
  cout << "YES";
}


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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> a(h);
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }
  cout << string(w + 2, '#') << endl;
  for (int i = 0; i < h; i++) {
    cout << '#' + a[i] + '#' << endl;
  }
  cout << string(w + 2, '#') << endl;
}


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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n, d, x;
  cin >> n >> d >> x;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);

  ll res = x;
  rep(i, d) {
    rep(j, n) {
      int aa = a.at(j);
      if (i % aa == 0) {
        res++;
      }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

//https://beta.atcoder.jp/contests/agc028/tasks/agc028_a

public class Program_AGC028_A // ←Class名変更！！
{


    public static void Main(string[] args)
    {
        var st = Console.ReadLine();
        var s = Console.ReadLine();
        var t = Console.ReadLine();

        var l = Lcm(s.Length, t.Length);
        //var l = (int)ll;
        //        var x = new char[l + 1];
        var x = new Dictionary<long, char>();

        //char[] x = null;

        //for (int cm = 1; cm < 10000; cm++)
        //{
        //var isCorrect = true;
        //var l = Lcm(s.Length, t.Length) * cm;
        //x = new char[l + 1];

        for (int i = 0; i < s.Length; i++)
        {
            var pos = i * (l / s.Length)+1 ;
            x[pos] = s[i];
        }


        for (int i = 0; i < t.Length; i++)
        {
            var pos = i * (l / t.Length)+1 ;
            if (x.ContainsKey(pos))
            {
                if (x[pos]!=t[i])
                {
                    Console.WriteLine(-1);
                    return;

                }
            }
            //else
            //{
            //    x.Add(pos, t[i]);
            //}
        

            //if (x[pos] != t[i] && x[pos] != '\0')           /////////////////////////
            //{
            //    Console.WriteLine(-1);
            //    return;
            //    //isCorrect = false;
            //    //    continue;
            //}
        }

        //if (isCorrect)
        //{
        //    Console.WriteLine(x.Length - 1);
        //    return;
        //}
        // }


        Console.WriteLine(l);
        // Console.WriteLine( - 1);

    } // Main



    //// 最小公倍数 least common multiple 
    //public static int Lcm(int a, int b)
    //{
    //    return a * b / Gcd(a, b);
    //}

    //// ユークリッドの互除法 
    //public static int Gcd(int a, int b)
    //{
    //    if (a < b)
    //        // 引数を入替えて自分を呼び出す
    //        return Gcd(b, a);
    //    while (b != 0)
    //    {
    //        var remainder = a % b;
    //        a = b;
    //        b = remainder;
    //    }
    //    return a;
    //}




  
static long Gcd(long a, long b)
    {
        return (a < b) ? Gcd(b, a)
             : (b > 0) ? Gcd(b, a % b)
                       : a;
    }

    static long Lcm(long a, long b)
    {
        return a / Gcd(a, b) * b;
    }


    static long gcd(long a, long b)
    {
        long c = Math.Max(a, b) % Math.Min(a, b);
        b = Math.Min(a, b);
        while (c != 0)
        {
            a = b % c;
            b = c;
            c = a;
        }
        return b;
    }

}     // Class




Measured memory_bytes: 21856
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
																													   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL; 																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																							   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////

int a[1000005];
int b[1000005];

///////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////

/////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	int n;
	cin >> n;
	
	a[0] = 0;
	b[0] = 0;
	
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		b[i] = a[i];
	}
	
	int cnt = 0;
	
	for(int i = n; i >= 1; i--){
		int suma = 0;
		for(int j = i; j <= n; j+=i){
			suma += b[j];
		}
		b[i] = suma % 2;
		if(b[i]){
			cnt++;
		}
	}
	
	//cout << "b: " << endl;
	//for(int i = 1; i <= n;i++){
		//cout << b[i] << " ";
	//}
	//cout << endl;
	
	cout << cnt << endl;
	for(int i = 1; i <= n; i++){
		if(b[i]){
			cout << i << endl;
		}
	}
	
	
	return 0;
}




Measured memory_bytes: 5888
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    N = int(input())
    if N==0:
        break
    count = 0
    for i in range(1,N//2+2):
        for j in range(i+1,N//2+2):
            hoge = (j-i+1)*(2*i+j-i)//2
            if hoge  == N:
                count += 1
            elif hoge > N:
                break
    print(count)

Measured memory_bytes: 6720
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

#define all(c) (c).begin(),(c).end()
#define INF (1<<29)

using namespace std;

int main(void) {
  int n,m;
  cin >> n >> m;

  vector<int> a(m), dp(n+1, INF);
  for(int i=0;i<m;i++)cin >> a[i];

  //fill(all(dp), INF);
  dp[0] = 0;
  for(int i=0;i<m;i++){
    for(int j=0;j+a[i]<=n;j++){
      dp[j + a[i]] = min(dp[j + a[i]], dp[j] + 1);
    }
  }

  cout << dp[n] << endl;
}



Measured memory_bytes: 3180
#include<stdio.h>

int A[1000000], n;

int binarySearch(int key) {
	int left = 0;
	int right = n;
	int mid;
	while(left <= right) {
		mid = (left + right) / 2;
		if(A[mid] == key) return 1;
		if(key < A[mid]) right = mid-1;
		else if(key > A[mid]) left = mid+1; 
	}
	return 0;	
}

int main() {
	int i, q, key, sum = 0;
	
	scanf("%d", &n);
    for(int i = 0; i < n; i++) { 
        scanf("%d", &A[i]);
    }
    
    scanf("%d", &q);
    for(int i = 0; i < q; i++) {
	    scanf("%d", &key);
		if( binarySearch(key)) sum++; 
	}
	printf("%d\n", sum);
	
	return 0;    
}

Measured memory_bytes: 2952
#include <bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int mod=1e9+7;
int32_t main()
{
  BOOST;
  int ans=3,n;
  string s1,s2;
  cin>>n>>s1>>s2;
  for (int i=0;i<n;i++){
  	if (s1[i]==s2[i]) {if (i&&s1[i-1]==s2[i-1])ans*=2,ans%=mod;}
  	else if (s1[i-1]==s2[i-1])ans*=2,ans%=mod,i++;
  	else ans*=3,ans%=mod,i++;
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 3616
#include<iostream>
#include<math.h>
#define MN 10000001
using namespace std;

bool prime[MN];

int main()
{
  prime[0] = prime[1] = true;
  for(int i = 2; i < sqrt(MN) + 1; i++)
  {
    if(prime[i])
      continue;
    for(int j = i + i; j < MN; j += i)
      prime[j] = true;
  }
loop:
  int N;
  cin >> N;
  if(!N)
    return 0;
  for(int i = N; i >= 0; i--)
  {
    if(!(prime[i - 8] || prime[i - 6] || prime[i - 2] || prime[i]))
    {
      cout << i << endl;
      break;
    }
  }
  goto loop;
}

Measured memory_bytes: 10924
#include <iostream>

#define llint long long unsigned int

int main(void){
  llint n, a, b;

  std::cin >> n >> a >> b;

  if(a>b){
    std::cout << 0 << std::endl;
    return 0;
  }else if(n==1 && a!=b){
    std::cout << 0 << std::endl;
    return 0;
  }

  llint minimum = (n-1)*a+b;
  llint maximum = a+(n-1)*b;
  std::cout << (maximum-minimum+1) << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  F
//
//  Created by 曾憲揚 on 2020/8/12.
//  Copyright © 2020 曾憲揚. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;
const int maxn = 3005;
const int MOD = 998244353;
int a[maxn];
long long dp[maxn][maxn];

int main(int argc, const char * argv[]) {
    memset(dp, 0, sizeof(dp));
    
    int n, s; cin >> n >> s;
    for(int i=1; i<=n; i++) cin >> a[i];
    
    
    long long ans = 0;
    //dp[0][0] = 0;
    for(int i=1; i<=n; i++){
        
            for(int j=0; j<=s; j++){
                dp[i][j] = dp[i-1][j];
            }
            dp[i][a[i]] += i;
            for(int j=1; j+a[i]<=s; j++){
                dp[i][j+a[i]] += dp[i-1][j];
                dp[i][j+a[i]] %= MOD;
            }
            ans += dp[i][s];
            ans %= MOD;
        
    }
    
    /*for(int i=0; i<=n; i++){
        for(int j=0; j<=s; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    cout << dp[n][s] << endl;*/
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 74088
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.NothingToLearn
{
    class ABC099_B
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] ab = ReadInts();
            int a = ab[0];
            int b = ab[1];
            int delta = b - a;
            WriteLine((delta - 1) * delta / 2 - a);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>

using namespace std;


int main(){

 long long int n,m,l,a[200010],b[200010],c[100010];
  
  cin >> n >> m ;
  
  for(int i=0;i<n;i++)
    cin >> a[i];
  for(int i=0;i<n;i++)
    cin >> b[i];
  
  sort(a,a+n);
  sort(b,b+n,greater<long long int>());
  long long int ok=-1,ng=1e13;
  while(ok+1<ng){
    long long int mid=(ok+ng)/2;
    long long int ans=0;
    for(int i=0;i<n;i++){
      if(a[i]*b[i]>mid){
        ans+=a[i]-mid/b[i];
      }
    }
    if(ans<=m){
      ng=mid;
    }
    else{
      ok=mid;
    }
  }
  cout << ng << endl;
}
  
  

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
vector<vector<int>> v(200000);
vector<ll> ans(200000,0LL);
// vector<bool> used(200000);


void search(int p,int parent){
	// used[p] = true;
	for(int i = 0; i < v[p].size(); i++) {
		if (v[p][i] != parent){
			ans[v[p][i]] += ans[p];
			search(v[p][i],p);
		}
	}
}

int main(){
	int n,q;cin>>n>>q;
	int a,b;
	for(int i = 0; i < n - 1; i++) {
		cin>>a>>b;
		v[a - 1].pb(b - 1);
		v[b - 1].pb(a - 1);
	}
	for(int i = 0; i < q; i++) {
		ll a,b;cin>>a>>b;
		ans[a - 1LL] += b;
	}
	search(0, 0);

	for(int i = 0; i < n; i++) {
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 24320
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

bool is_inte(double x) {
    return floor(x) == x;
}

int main() {
    int n, d;
    cin >> n >> d;
    int x[n][d];
    for (int i = 0; i < n; i++) {
        for (int k = 0; k < d; k++) {
            cin >> x[i][k];
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int k = i + 1; k < n; k++) {
            double dis = 0;
            for (int l = 0; l < d; l++) {
                dis += (x[i][l] - x[k][l]) * (x[i][l] - x[k][l]);
            }
            dis = sqrt(dis);

            if (is_inte(dis)) {
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {   
    // 4 / n = 1 / a + 1/ b + 1/ c;
    // 4abc = nab + nbc + nac
    // a = nbc / (4bc - nb - nc)
    long long int n;
    cin >> n;
    for (long long int c = 1; c <= 3500; c++) {
        for (long long int b = 1; b <= 3500; b++) {
            if (4 * b * c - n * b - n * c <= 0) {
                continue;
            }
            if (n * b * c % (4 * b * c - n * b - n * c) == 0) {
                cout << n * b * c / (4 * b * c - n * b - n * c) << " " << b << " " << c << endl;
                return 0; 
            }
        }
    }
}




Measured memory_bytes: 3644
n = int(input())
dp = [[0 for _ in range(3)] for _ in range(n+1)]

for i in range(n):
    abc = list(map(int,input().split()))
    for j in range(3):
        for k in range(3):
            if j!=k :
                dp[i+1][j]  = max( dp[i+1][j], dp[i][k] + abc[j])

print(max(dp[-1]))

Measured memory_bytes: 28852
INF = 10 ** 12
MV = 10 ** 5

N, W = map(int, input().split())
dp = [[INF for _ in range(MV + 1)] for _ in range(N + 1)]
dp[0][0] = 0
# dp[品物のidx][価値の総和] = 実現する最小重量

for i in range(1, N + 1):
    w, v = map(int, input().split())
    for j in range(MV + 1):
        if j - v >= 0:
            dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v] + w)
        else:
            dp[i][j] = dp[i - 1][j]

ans = -1
j = MV
while j >= 0:
    if dp[N][j] <= W:
        ans = j
        break
    j -= 1
print(ans)


Measured memory_bytes: 173300
#include<bits/stdc++.h>
using namespace std;
int main(){
  int c=0;
  char a,b;
  cin>>a>>b;
  if(a>b)  
    cout<<">"<<endl;
  else if(a==b)
    cout<<"="<<endl;
  else 
    cout<<"<"<<endl;
  return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n,x;
void nhap()
{
    cin>>x>>n;
}
void xuli()
{
    if(x*500>=n)
        cout<<"Yes";
    else cout<<"No";
}
int main()
{
    nhap();
    xuli();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr int mod = 1e9 + 7;

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

/*-------------------------------------------*/
// 0-indexed, 半開
template <typename T> struct BIT {
  private:
    int n;
    vector<T> dat;

  public:
    BIT(int n) : n(n) { dat.assign(n + 1, 0); }
    void update(int k, T a) {
        for(k++; k <= n; k += k & -k)
            chmax(dat[k], a);
    }
    // [0,a)
    T query(int a) {
        T ret = 0;
        for(; a > 0; a -= a & -a)
            chmax(ret, dat[a]);
        return ret;
    }
};

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

    int n;
    cin >> n;
    int h[n];
    BIT<ll> dp(n + 1);

    rep(i, n) cin >> h[i];
    rep(i, n) {
        int a;
        cin >> a;
        dp.update(h[i], dp.query(h[i]) + a);
    }

    cout << dp.query(n + 1);

    return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);

	void a() {
		String s = sc.next();
		char c1 = s.charAt(0),c2 = 0;
		int c1cnt = 1,c2cnt = 0;
		for(int i = 1;i < s.length();i ++) {
			char c = s.charAt(i);
			if(c == c1) c1cnt++;
			else if(c != c2) {
				c2cnt = 1;
				c2 = c;
			}
			else if(c == c2) c2cnt++;
		}
		if(c1cnt == 2 && c2cnt == 2) System.out.println("Yes");
		else System.out.println("No");
	}
	public static void main(String[] args) {
		new Main().a();
	}

}





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

int lcs();

int lcs(char *s,char *t)
{
  int x[1001][1001];
  int n,m,i,j;

  n = strlen(s)+1;
  m = strlen(t)+1;

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

  for(i=1;i<n;i++) {
    for(j=1;j<m;j++) {
      if(s[i-1] == t[j-1]) {
	x[i][j] = x[i-1][j-1]+1;
      }else if(x[i-1][j] >= x[i][j-1]) {
	x[i][j] = x[i-1][j];
      }else{
	x[i][j] = x[i][j-1];
      }
    }
  }
  return x[n-1][m-1];
}

int main()
{
  int q,i;
  char s[1001],t[1001];

  scanf("%d",&q);

  for(i=0;i<q;i++) {
    scanf("%s",s);
    scanf("%s",t);
    printf("%d\n",lcs(s,t));
  }
  return 0;
}
  



Measured memory_bytes: 5648
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int N, X;
	cin >> N >> X;
	int sum = 0, mn = INF;
	rep(i, N) {
		int num;
		cin >> num;
		sum += num;
		mn = min(mn, num);
	}
	int ans = N + (X - sum) / mn;
	cout << ans;
}

Measured memory_bytes: 256