akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;

int n, a[100000], f[100000], b[100000];
int gcd(int a, int b) {
	if (a < b)
		swap(a, b);
	while (b) {
		int r = a % b;
		a = b;
		b = r;
	}
	return a;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);

	if (n == 2) {
		printf("%d\n", max(a[0], a[1]));
		return 0;
	}

	f[0] = a[0];
	for (int i = 1; i < n; i++)
		f[i] = gcd(f[i - 1], a[i]);
	
	b[n - 1] = a[n - 1];
	for (int i = n - 2; 0 <= i; i--)
		b[i] = gcd(b[i + 1], a[i]);

	int mx = max(f[n - 2], b[1]);
	for (int i = 1; i + 1 < n; i++)
		mx = max(mx, gcd(f[i - 1], b[i + 1]));
	printf("%d\n", mx);
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
ll ans[55555];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,x,y; cin>>n>>x>>y;
	x--; y--;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			int dist=abs(i-j);
			dist=min(dist,abs(i-x)+1+abs(y-j));
			dist=min(dist,abs(i-y)+1+abs(x-j));
			ans[dist]++;
		}
	}
	for(int i=1;i<=n-1;i++)
	{
		cout<<ans[i]<<'\n';
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define DEBUG(x) cerr << #x << " = " << x << endl
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
signed main() {
  int N; cin >> N;
  int x, y; cin >> x >> y;
  REP(i,N-1) {
    int a, b; cin >> a >> b;
    int l[2], r[2];
    l[0] = a * ((x + a - 1) / a);
    r[0] = b * ((x + a - 1) / a);
    l[1] = a * ((y + b - 1) / b);
    r[1] = b * ((y + b - 1) / b);
    // DEBUG(l[0]);
    // DEBUG(r[0]);
    // DEBUG(l[1]);
    // DEBUG(r[1]);
    if(l[0] >= x && r[0] >= y) {
      x = l[0], y = r[0];
    }
    else {
      x = l[1], y = r[1];
    }
    // DEBUG(x);
    // DEBUG(y);
  }
  cout << (x + y) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int n=s.size();
  int ans=n;
  for(int i=0;i<n;i++){
    if(s[i]==s[i+1]){
      ans--;
      i+=2;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main()
{
  int n, m, s, g1, g2;
  while(cin >> n >> m >> s >> g1 >> g2, n || m || s || g1 || g2){
    s--, g1--, g2--;
    int G[101][101];
    const int inf = (1 << 25);
    for(int i = 0; i < 101; i++){
      for(int j = 0; j < 101; j++) G[i][j] = inf;
      G[i][i] = 0;
    }
    while(m--){
      int b1, b2, c;
      cin >> b1 >> b2 >> c;
      b1--, b2--;
      G[b1][b2] = c;
    }
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
	for(int k = 0; k < n; k++){
	  G[j][k] = min(G[j][k], G[j][i] + G[i][k]);
	}
      }
    }
    int ans = inf;
    for(int i = 0; i < n; i++){
      ans = min(ans, G[s][i]+G[i][g1]+G[i][g2]);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>
#include<stdbool.h>

int main(void){
  int box[100000];
  bool flg[100000];
  int i,j,k,M,N,x,y;

  scanf("%d%d",&N,&M);
  for(i=0;i<N;i++){
    box[i]=1;
    flg[i]=(i==0);
  }
  
  for(i=0;i<M;i++){
    scanf("%d%d",&x,&y);
    x--;
    y--;
    if(flg[x]) flg[y]=true;
    if(flg[x] && box[x]==1) flg[x]=false;
    box[x]--;
    box[y]++;
  }

  for(i=k=0;i<N;i++) k+=flg[i];
  printf("%d\n",k);
  return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){
  
  int n;
  cin >> n;
  vector<ll> v(100100,0);
  ll res = 0;
  rep(i,n){
    int x;cin >> x;
    v[x]++;
    res += 1ll*x;
  }
  int q;
  cin >> q;
  while(q--){
    int b,c;cin >> b >> c;
    res -= v[b]*b;
    v[c] += v[b];
    res += v[b]*c;
    v[b] = 0;
    cout << res << "\n";
  }

  




  return 0;
}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N=2e5+5;

int n,k;
LL a[N],ans;

int main()
{
	
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=n-k;i++)
		ans+=a[i];
	cout<<ans<<'\n';
		
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
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; }

int main(){
    int a,b,c;
    cin >> a>>b>>c;
    int d=(a-1)/c;
    int e=b/c;
    cout <<e-d<<endl;
    return 0;
}


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }


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

    ll k, x;
    cin >> k >> x;
    if (k * 500 >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    int ans = 1;
    int diff = 0;
    rep(i, 1, n){
        int tmp = a[i] - a[i - 1];
        if(tmp == 0) continue;
        tmp = (tmp > 0 ? 1 : -1);
        if(diff == 0){
            diff = tmp;
        }else{
            if(diff != tmp){
                diff = 0;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
const int mod=1e9+7;

int main(){
  int N;
  string s;
  cin>>N>>s;
  string t="RGB";
  vector<vector<int>>sum(N,vector<int>(100));
  for(int i=0;i<N;i++){
    sum[i][s[i]-'A']++;
    for(int j=0;j<3;j++){
      if(i+1<N){
        sum[i+1][t[j]-'A']+=sum[i][t[j]-'A'];
      }
    }
  }

  //cout<<sum[N-1]['R'-'A']<<endl;
  int64_t ans=0;
  for(int i=0;i<N;i++){
    char s1=s[i];
    for(int j=i+1;j<N;j++){
      if(s[j]!=s[i]){
        char s2=s[j];
        int len=j-i;
        char s3;
        for(int k=0;k<3;k++){
          if(t[k]!=s1&&t[k]!=s2){
            s3=t[k];
          }
        }
        //cout<<s3<<endl;
        ans+=sum[N-1][s3-'A']-sum[j][s3-'A'];
        if(j+len<N&&s[j+len]==s3){ans--;}
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5260
#include <bits/stdc++.h>
#include <vector>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
 
struct kank{
  ll num;
  ll dx;
};
 
int main(){
  
  ll n,m;
  cin>>n>>m;
  ll l[m],r[m],d[m];
  list<kank> kanks[n+1];
  REP(i,m){
    cin>>l[i]>>r[i]>>d[i];
    kank k;
    k.num = r[i];
    k.dx = d[i];
    kanks[l[i]].push_back(k);
    k.num = l[i];
    k.dx = -d[i];
    kanks[r[i]].push_back(k);
  }
  
  string ans = "Yes";
  ll x[n+1];
  REP(i,n+1){
    x[i] = 0;
  }
  bool tukatta[n+1];
  REP(i,n+1){
    tukatta[i] = false;
  }
  
  for(int i=1;i<=n;i++){
    if(tukatta[i]==false){
      tukatta[i] = true;
      queue<ll> q;
      q.push(i);
      while(!q.empty()){
        ll l = q.front();
        q.pop();
        tukatta[l] = true;
        while(!kanks[l].empty()){
          kank k = kanks[l].front();
          kanks[l].pop_front();
          if(tukatta[k.num]){
            if((x[k.num]-x[l])!=k.dx){
//              cout<<k.dx<<" "<<x[k.num]-x[l]<<endl;
              ans="No";
              cout<<ans<<endl;
              return 0;
            }
          }else{
 
            x[k.num] = x[l] + k.dx;
        //                cout<<k.num<<" "<<x[k.num]<<endl;
            q.push(k.num);
            tukatta[k.num]=true;
          }
        }
      }
    }
  }
  cout<<ans<<endl;
  
  return 0;
}

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

int main(void) {
	int i, j;
	int N;
	long long int *A;
	long long int ans, temp;
	long long int naive_ans;
	long long int module = 1000000000 + 7;
	char buf[128], *ch;
	char *great_buf;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	N = atoi(ch);

	A = (long long int *)calloc(N, sizeof(long long int));
	great_buf = (char *)calloc(N*12, sizeof(char));
	fgets(great_buf, N*12, stdin);
	ch = strtok(great_buf, " ");
	A[0] = atoi(ch);
	for(i = 1; i < N; i += 1) {
		ch = strtok(NULL, " ");
		A[i] = atoi(ch);
	}
	free(great_buf);
	/*
	for(i = 0; i < N; i += 1) {
		A[i] = rand()%100000000;
	}
	*/

	/*
	naive_ans = 0;
	for(i = 0; i < N; i += 1) {
		for(j = i + 1; j < N; j += 1) {
			temp = A[i] * A[j];
			temp = temp % module;
			naive_ans += temp;
			naive_ans = naive_ans % module;
		}
	}
	printf("%lld\n", naive_ans);
	*/

	ans = 0;
	temp = 0;
	for(i = 0; i < N; i += 1) {
		temp += A[i];
	}
	for(i = 0; i < N - 1; i += 1) {
		temp -= A[i];
		ans += ((temp % module) * A[i]) % module;
		ans = ans % module;
	}
	printf("%lld\n", ans);

	free(A);
	return 0;
}


Measured memory_bytes: 5404
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Green Bin
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int L = 10;

/* typedef */

typedef long long ll;
typedef map<ll,int> mli;

/* global variables */

char s[L + 4];
mli bmap;

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  ll sum = 0;
  for (int i = 0; i < n; i++) {
    scanf("%s", s);
    sort(s, s + L);

    ll bits = 0;
    for (int j = 0; j < L; j++)
      bits |= (ll)(s[j] - 'a') << (j * 5);

    mli::iterator mit = bmap.find(bits);
    if (mit != bmap.end())
      sum += mit->second++;
    else
      bmap[bits] = 1;
  }

  printf("%lld\n", sum);
  return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

const int INF = 1001001001;

void Main() {
  Cin(int, k, t);
  Cins(int, t, a);

  int prev = -1, dup = 0;
  for (int cnt = 0; cnt < k; ++cnt) {
    int maxi = -1, maxv = -INF;
    for (int i = 0; i < t; ++i) {
      if (a[i] > maxv && i != prev) {
        if (a[i] == 0) continue;
        maxi = i;
        maxv = a[i];
      }
    }
    if (maxi != -1) {
      a[maxi]--;
      prev = maxi;
      continue;
    }
    for (int i = 0; i < t; ++i) {
      if (a[i] > 0) {
        a[i]--;
        prev = i;
        dup++;
        break;
      }
    }
  }

  cout << dup << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned int  ull;
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int, int>
#define int ll
#define pll pair<ll, ll> 
#define pdd pair<ld, ld> 
#define pb push_back
#define reset(x,v) memset(x,v,sizeof(x))
#define mod 1000000007
using namespace std;

ll power(ll x, ll y){  
	if(x == 1 || y == 0)
		return 1;
    ll res = 1;   
    x = x % mod; 
    if (x == 0) 
		return 0;  
    while (y > 0){  
        if (y & 1)  
	        res = (res * x) % mod;  
        y = y >> 1; 
        x = (x * x) % mod;  
    }  
    return res;  
} 
vi pr;
void sieve(int n){ 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++){ 
        if (prime[p] == true){ 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 

    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          pr.pb(p); 
} 

unordered_map<int, int> mp1, mp2;
signed main(){
	FASTIO
	int n;
	cin >> n;
	int a[n], b[n];
	rep(i, 0, n){
		cin >> a[i];
		mp1[a[i]]++;
	}
	rep(i, 0, n){
		cin >> b[i];
		mp2[b[i]]++;
	}
	bool f = false;
	rep(i, 0, n){
		if(mp2.count(a[i]) > 0 && mp1[a[i]] + mp2[a[i]] > n){
			f = true;
			break;
		}
	}
	if(f){
		cout << "No";
		return 0;
	}
	reverse(b, b + n);
	f = true;
	rep(i, 0, n){
		int z = 2000;
		while(b[i] == a[i] && z > 0){
			int r = rand() % n;
			if(b[r] != a[i] && a[r] != b[i]){
				swap(b[r], b[i]);
				break;
			}
			z--;
		}
		if(b[i] == a[i]){
			f = false;
			break;
		}
	}
	if(!f){
		cout << "No";
		return 0;
	}
	cout << "Yes\n";
	rep(i, 0, n){
		cout << b[i] << " ";
	}
    return 0;
}


Measured memory_bytes: 22880
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;
 
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))
 
const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
 
const ll M = 1000000007;
 
vector<int> G[200010];
vector<int> rid[200010];
vector<P> dp_ord;
vector<int> dep[200010];
vector<int> cnt[200010];
P max_dep[200010][2];
int sum_cnt[200010];
bool s_[200010];
void make_ord_dfs1(int v,int p){
	for(int i = 0 ; i < G[v].size() ; i ++){
		if(G[v][i] != p){
			make_ord_dfs1(G[v][i],v);
			dp_ord.pb(P(v,i));
		}
	}
}
void make_ord_dfs2(int v,int p){
	for(int i = 0 ; i < G[v].size() ; i ++){
		if(G[v][i] == p){
			dp_ord.pb(P(v,i));
			break;
		}
	}
	for(int i = 0 ; i < G[v].size() ; i ++){
		if(G[v][i] != p){
			make_ord_dfs2(G[v][i],v);
		}
	}
}
void make_ord(){
	make_ord_dfs1(1,0);
	make_ord_dfs2(1,0);
}
void dfs(int v,int id){
	int u = G[v][id];
	if(max_dep[u][0].sc != rid[v][id])dep[v][id] = max_dep[u][0].fr+1;
	else dep[v][id] = max_dep[u][1].fr+1;
	cnt[v][id] = sum_cnt[u]-cnt[u][rid[v][id]]+(s_[u]?1:0);
	if(max_dep[v][1] < P(dep[v][id],id)){
		max_dep[v][1] = P(dep[v][id],id);
		if(max_dep[v][0] < max_dep[v][1])swap(max_dep[v][0],max_dep[v][1]);
	}
	sum_cnt[v] += cnt[v][id];
}
 
int main(){
	static int n;
	static int a[200010],b[200010];
	string s;
	scanf("%d",&n);
	rep1(i,n-1)scanf("%d%d",&a[i],&b[i]);
	cin >> s;
	
	rep1(i,n-1){
		rid[a[i]].pb(G[b[i]].size());
		rid[b[i]].pb(G[a[i]].size());
		G[a[i]].pb(b[i]);
		G[b[i]].pb(a[i]);
		dep[a[i]].pb(0);
		cnt[a[i]].pb(0);
		dep[b[i]].pb(0);
		cnt[b[i]].pb(0);
	}
	rep1(i,n){
		max_dep[i][0] = P(0,-1);
		max_dep[i][1] = P(0,-1);
		sum_cnt[i] = 0;
	}
	rep1(i,n){
		if(s[i-1] == '1')s_[i] = true;
		else s_[i] = false;
	}
	
	make_ord();
	for(P p: dp_ord){
		dfs(p.fr,p.sc);
	}
	
	ll ret = 0;
	rep1(i,n){
		vector<P> vec;
		rep(j,G[i].size()){
			vec.pb(P(dep[i][j],cnt[i][j]));
		}
		vec.pb(P(0,(s_[i]?1:0)));
		sor(vec);
		int d_max = vec[vec.size()-1].fr;
		int k = vec.size()-2;
		int I = 0;
		while(I+1 < vec.size() && vec[I].sc == 0)I ++;
		ret += max( min( d_max , vec[k].fr+2 ) - vec[I].fr , 0 );
	}
	cout << ret+1 << endl;
}

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

int main(){
    int n ;
    cin>>n;
    vector<P> a(n);
    rep(i, n) {
        cin>>a[i].first;
        a[i].second=i+1;
    }
    sort(a.begin(), a.end());
    rep(i, n-1){
        cout << a[i].second << " ";
    }
    cout << a[n-1].second<<endl;
    return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>

int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int i, j;
	for (i = a; i <= b; i++)
	{
		if (c%i == 0) j++;
	}
	printf("%d\n", j);
	return 0;
}

Measured memory_bytes: 1028
$S=<STDIN>;chomp $S;
@S=split "",$S;

$L=@S+0;$L2=int($L/2);
#print $L," ",$L2;
for($i=0;$i<=$#S;$i++){ $c{$S[$i]}+=1; }
for($i=0;$i<=$#S;$i++){
	$s=$S[$i];$c=$c{$s};
	$c2=(++$c2{$s});$c3=$c2*2-1;
	if ($c3<$c) {
		push @A,$i;#left
		$o{$s}{$c-$c2+1}=$#A;
	} elsif ($c3>$c) {
		die unless( exists($o{$s}{$c2}) );
		die if( $B[$L2-$o{$s}{$c2}-1]!=0);
		$B[$L2-$o{$s}{$c2}-1]=$i
	} else {
		if ($#C>=0 ) { print "-1\n";exit;}
		push @C,$i;#center
	}
}
@SS = ( @A,@C,@B);

$r=0;
@T=();
for($j=$#SS;$j>=0;$j--){
	$i=$SS[$j]+1;
	$k=$i;
	while($k>0){
		$r+=$T[$k];
		$k &= $k-1;
	}
	while ($i<=$#SS+1) {
		$T[$i] += 1;
		$i+= $i & (-$i);
	}
}

print "$r\n";


Measured memory_bytes: 53964
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const &auto s, const &auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

int main() {
  string s;
  cin>>s;
  if(((s[0]==s[1]&&s[2]==s[3])||(s[0]==s[2]&&s[1]==s[3])||(s[0]==s[3]&&s[2]==s[1]))&&!(s[0]==s[1]&&s[2]==s[1]&&s[2]==s[3])){
    cout<<"Yes";
  }else{
    cout<<"No";
  }
}

Measured memory_bytes: 256
import Data.List

main = do
  li <- getLine
  let [n,h] = map read $ words li
  co <-getContents
  let abs = map (l2p . map read . words) $ lines co
  let ans = compute n h abs
  print ans

l2p :: [Int] -> (Int,Int)
l2p [a,b] = (a,b)

{-
切りつけるのはaiの最大値のものamaxだけでよい。
十分なダメージを与えたところで、amaxを超えるbiを全て投げる。
biだけで片がつく場合もある。
-}

compute :: Int -> Int -> [(Int,Int)] -> Int
compute n h abs
  | bsum >= h = length $ takeWhile (h >) $ scanl (+) 0 bs1
  | True = n1 + div (h-bsum+amax-1) amax
  where
    amax = maximum $ map fst abs
    bs1 = reverse $ sort $ filter (amax <) $ map snd abs
    bsum = sum bs1
    n1 = length bs1

Measured memory_bytes: 76028
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N,M;cin>>N>>M;
    vector<ll> X(M);
    REP(i,M) cin>>X[i];
    sort(All(X));
    vector<ll> B(M);
    ll s=0;
    REP(i,M-1){
        B[i]=X[i+1]-X[i];
        s+=B[i];
    }
    ll ans=s;
    N--;
    sort(rAll(B));
    REP(i,min(N,M)){
        ans-=B[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
import java.io.InputStream;
import java.io.OutputStream;
import java.util.*;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class Main{
    //WRWWRWRR     wwwrrrrwwwwrrr
    ///112 112
    ///1223 12

    int mod = (int) 1e9+7;
    public void solve(int testNumber, InputReader in, PrintWriter out) {

    }
    public static void main(String[] args){
        Scanner scanner = new Scanner(new InputStreamReader(System.in));
        long n = Long.parseLong(scanner.nextLine());
        int mod = (int) 1e9+7;
        int N = (int)1e6+3;
        long a=1,b=0,c=0,d=0;
        for(int i=1;i<=n;i++){
            long a1 = a*8;
            long b1 = b*9+a;
            long c1 = c*9+a;
            long d1 = b+c+d*10;
            a = a1%mod;b =b1%mod;c=c1%mod;d=d1%mod;
        }
        System.out.println(d);

    }
    //	public static void main(String[] args){
//        InputStream inputStream = System.in;
//        OutputStream outputStream = System.out;
//        InputReader in = new InputReader(inputStream);
//        PrintWriter out = new PrintWriter(outputStream);
//        Main solver = new Main();
////        int num = in.nextInt();
////        while(num-->0){
////            solver.solve(1, in, out);
////        }
//        solver.solve(1, in, out);
//        out.close();
//    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

Measured memory_bytes: 35800
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [-int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    N = NI()
    a = LI()

    x = 0
    for b in a:
        x ^= b
    ans = []
    for b in a:
        ans.append(x^b)
    print(*ans,sep=' ')


if __name__ == '__main__':
    main()

Measured memory_bytes: 111480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;

#define valid(i,j) (i<=h && j<=w && grid[i][j])

int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    bool grid[h+1][w+1]; char ch;
    ll dp[h+1][w+1] = {};
    for(int i = 1; i <= h; ++i)
        for(int j = 1; j<= w; ++j) {
            cin >> ch;
            grid[i][j] = ch == '.';
        }
    dp[h][w] = 1;
    for(int i = h; i > 0; i--) {
        for (int j = w; j > 0; j--) {
            if(i == h && j == w) 
                continue;
            if (valid(i+1,j))
                dp[i][j] = (dp[i][j] + dp[i+1][j])%mod;
            if (valid(i,j+1))
                dp[i][j] = (dp[i][j] + dp[i][j+1])%mod;
        }
    }
    cout << dp[1][1];
    return 0;
}


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

#define ll long long
#define N 200050

struct cline
{
    ll M, C;
    cline() {}
    cline(ll m, ll c): M(m), C(c) {}
};
cline line[N];
ll H[N];

bool bad(const cline & l1,const cline & l2,const cline & l3)
{
    return (l3.C-l1.C)*(l1.M-l2.M)<=(l2.C-l1.C)*(l1.M-l3.M);///(slope dec+query min),(slope inc+query max)
}

void add(cline l,int &last)
{
    line[last++]=l;
    while(last>=3&&bad(line[last-3],line[last-2],line[last-1]))
    {
        line[last-2]=line[last-1];
        last--;
    }
}

///(slope dec+query min),(slope inc+query max) -> x increasing
long long query(long long x,int &pointer,int last)
{
    if (pointer>=last)
        pointer=last-1;

    /// for minimum
    while (pointer<last-1 &&line[pointer+1].M*x+line[pointer+1].C <=line[pointer].M*x+line[pointer].C)
        pointer++;
    return line[pointer].M*x+line[pointer].C;
}

int main()
{
    int last = 0, pointer = 0;
    int n;
    ll c;
    scanf("%d %lld",&n,&c);
    for(int i=1; i<=n; i++) scanf("%lld",&H[i]);
    cline ln(-H[1],H[1]*H[1]);
    add(ln,last);
    ll ret;
    for(int i=2; i<=n; i++)
    {
        ret=query(2*H[i],pointer,last);
        ret+=H[i]*H[i]+c;

        ln.M=-H[i],ln.C=ret+H[i]*H[i];
        add(ln,last);
    }
    printf("%lld\n",ret);
    return 0;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int v[10];

    scanf("%d %d %d", &v[1], &v[2], &v[3]);
    sort(v+1, v+4);
    printf("%d\n", v[3] - v[1]);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

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

        try{
            //入力
            int n = scan.nextInt();
            int[] v = new int[n];
            for(int i = 0; i < n; i++){
                v[i] = scan.nextInt();
            }

            int[][] ans = new int[2][100001];
            for(int i = 0; i < n; i++){
                if(i % 2 != 0){
                    ans[0][v[i]]++;
                }else{
                    ans[1][v[i]]++;
                }
            }

            int num = 0;

            int even = calcNum(ans[0]);
            int odd = calcNum(ans[1]);
            int evenNum = ans[0][even];
            int oddNum = ans[1][odd];

            if(even == odd){
                ans[0][even] = 0;
                ans[1][odd] = 0;
                int even2 = calcNum(ans[0]);
                int odd2 = calcNum(ans[1]);
                int even2Num = ans[0][even2];
                int odd2Num = ans[1][odd2];

                if(evenNum + odd2Num >= oddNum + even2Num){
                    num = n-evenNum-odd2Num;
                }else{
                    num = n-oddNum-even2Num;
                }
            }else{
                num = n-evenNum-oddNum;
            }

            System.out.println(num);

        }finally{
            scan.close();
        }
    }

    static int calcNum(int[] ansEven){
        int max = -1;
        int maxNum = 0;
        for(int i = 0; i < 100001; i++){
            if(max < ansEven[i]){
                max = ansEven[i];
                maxNum = i;
            }
        }

        return maxNum;
    }

}


Measured memory_bytes: 50984
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

//var done []bool = make([]bool, 10)
//var memo []int = make([]int, 10)

//func fib(n int) int {
//	fmt.Println(n)
//	if n == 0 {
//		return 0
//	}
//	if n == 1 {
//		return 1
//	}
//	if done[n] {
//		fmt.Println("done" + fmt.Sprint(n))
//		return memo[n]
//	}
//	done[n] = true
//	memo[n] = fib(n-1) + fib(n-2)
//	return memo[n]
//}

var dp []int = make([]int, 10)
var m map[string]int = make(map[string]int)
var mInt map[int]int = make(map[int]int)

func fib(n int) int {
	dp[0] = 0
	dp[1] = 1
	for i := 2; i <= n; i++ {
		dp[i] = dp[i-1] + dp[i-2]
	}
	return dp[n]
}

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	n := nextInt()
	for i := 0; i < n; i++ {
		a := nextInt()
		d := mInt[a]
		if d == 1 {
			fmt.Fprint(out, string("NO"))
			return
		}
		mInt[a] = 1
	}
	fmt.Fprint(out, string("YES"))
}


Measured memory_bytes: 12672
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, a, b;
    cin >> x >> a >> b;
    if(abs(x-a) < abs(x-b)) {
        cout << "A" << endl;
    }
    else {
        cout << "B" << endl;
    }
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int d[n];
    for(int i=0;i<n;i++){
        cin >> d[i];
    }
    sort(d, d+n);
    int result = 1;
    for(int i=1;i<n;i++){
        if(d[i] == d[i-1]){
            continue;
        }else{
            result++;
        }
    }
    printf("%d", result);
}

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

vector<int> d(int n) {
    vector<int> r;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            r.push_back(i);
            if (i * i != n)
                r.push_back(n / i);
        }
    }
    return r;
}

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

    int n, m = 0;
    cin >> n;

    vector<int> a(n + 1);
    vector<int> b;

    rep(i, 1, n + 1) cin >> a[i];

    for (int i = n; i > 0; i--) {
        vector<int> dv = d(i);
        if (a[i] == 1) {
            m++;
            b.push_back(i);
            for (auto x : dv)
                a[x] ^= 1;
        }
    }

    reverse(b.begin(), b.end());
    cout << m << endl;
    for (auto x : b)
        cout << x << ' ';
    cout << endl;
    return 0;
}


Measured memory_bytes: 2424
from itertools import permutations
a2e = [int(input()) for i in range(5)]

perm = list(permutations(list(range(5))))

m = 643
t = 0

for i in perm:
    for j in range(5):
        t += a2e[i[j]]
        if t % 10 != 0 and j < 4:
            wait = 10 - (t % 10)
            t += wait
    if m > t:
        m = t
    t = 0
print(m)


Measured memory_bytes: 3060
import java.util.*;
 
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
      int num1 = sc.nextInt();
      int num2 = sc.nextInt();
      int num3 = sc.nextInt();
      
    if(num1 + num2 == num3 || num1+num3 == num2 || num2+num3 == num1){
            System.out.println("Yes");
      
    }else{
            System.out.println("No");
      
      }
  }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
100 100 100
)");
#define cin input
#endif

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

	cout << min(a, b) << ' ' << max(a + b - n, 0) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

int main(){
  string s;
  cin>>s;
  int l=0, r=s.size()-1, c=0;
  while(1){
    //cout<<s[i]<<" "<<s[ind]<<endl;
    if(s[l]==s[r]){
      l++;
      r--;
    }else if(s[l]=='x'){
      l++;
      c++;
    }else if(s[r]=='x'){
      r--, c++;
    }else{
      cout<<-1<<endl;
      return 0;
    }
    if(l>r) break;
  }
  cout<<c<<endl;
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
 
const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;
 
#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)
 
int main(void) {
    int A,B;
    cin >> A >> B;
    cout << (A+B)%24 << endl;
    return 0;
}

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

#define int long long int
#define pb push_back
#define mp make_pair

#define fr(i,a,b) for(i=a;i<=b;i++)

const int N=1e5+5;

int32_t main()
{
     
     int n,i,j,ans=0,cnt[205]={0};
     
     cin>>n;
     
     for(i=1;i<=200;i++)
     {
          for(j=1;j<=200;j++)
          {
               if(j%i==0)
               cnt[j]++;
          }
     }
     for(i=1;i<=n;i++)
     {
          if(i%2!=0 && cnt[i]==8)
          ans++;
     }
     cout<<ans;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if (a==b) {
      System.out.println(c);
    } else if (a==c) {
      System.out.println(b);
    } else {
      System.out.println(a);
    }
  }
}

Measured memory_bytes: 22100
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <bitset>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

const int MAX_N = 200050;
const int MAX_M = 200050;

int N, M, A[MAX_N], X[MAX_N], Y[MAX_N];

int ball_num[MAX_N] = {};
int range_num[MAX_N] = {};

int main(int argc, char **argv) {
    std::cin >> N >> M;

    for (int i = 1; i <= N; i++) {
        std::cin >> A[i];
    }

    for (int i = 1; i <= M; i++) {
        std::cin >> X[i] >> Y[i];
    }

    for (int i = 1; i <= N; i++) {
        ball_num[A[i]]++;
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 0; j < ball_num[i]; j++) {
            if (1 <= i - j) {
                range_num[i-j]++;
            }
        }
    }

    int cnt = 0;
    for (int i = 1; i <= N; i++) {
        if (range_num[i] == 0) {
            cnt++;
        }
    }

    //std::cout << "check:" << cnt << std::endl;

    for (int i = 1; i <= M; i++) {
        if (A[X[i]] != Y[i]) {
            //std::cout << "check:" << i << std::endl;
            int dis_range = A[X[i]] - ball_num[A[X[i]]] + 1;
            int inc_range = Y[i] - ball_num[Y[i]];

            //std::cout << i << " " << dis_range << " " << inc_range << std::endl;
            
            if (1 <= dis_range) {
                range_num[dis_range]--;
                if (range_num[dis_range] == 0) {
                    cnt++;
                }
            }

            if (1 <= inc_range) {
                if (range_num[inc_range] == 0) {
                    cnt--;
                }
                range_num[inc_range]++;
            }
            ball_num[A[X[i]]]--;
            ball_num[Y[i]]++;
            A[X[i]] = Y[i];

            //for (int i = 1; i <= N; i++) {
            //    std::cout << A[i] << " ";
            //}
            //std::cout << std::endl;
            //for (int i = 1; i <= N; i++) {
            //    std::cout << range_num[i] << " ";
            //}
            //std::cout << std::endl;
        }
        std::cout << cnt << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 5376
#!/usr/bin/ruby                                                                                                                                   
# encoding: utf-8                                                                                                                                 
while x = gets do
  h = gets
  if x.to_i == 0 && h.to_i == 0
    break
  else
    printf("%.6f\n", x.to_i ** 2 + x.to_i * Math.sqrt(h.to_i ** 2 + (x.to_i / 2.0) ** 2) / 2.0 * 4)
  end
end

Measured memory_bytes: 6152
typedef struct point{
    int x_elem;
    int y_elem;
}point;

#include <stdio.h>

int main(void) {
  point point[4], diff;

  scanf("%d %d %d %d", &point[0].x_elem, &point[0].y_elem, &point[1].x_elem, &point[1].y_elem);

  diff.x_elem = point[1].x_elem - point[0].x_elem;
  diff.y_elem = point[1].y_elem - point[0].y_elem;

  point[2].x_elem = point[1].x_elem - diff.y_elem;
  point[2].y_elem = point[1].y_elem + diff.x_elem;

  point[3].x_elem = point[0].x_elem - diff.y_elem;
  point[3].y_elem = point[0].y_elem + diff.x_elem;

  printf("%d %d %d %d\n", point[2].x_elem, point[2].y_elem, point[3].x_elem, point[3].y_elem);

  return 0;
}

Measured memory_bytes: 1732
require 'pp'
require 'prime'

$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end
n = gets_i
max = (n ** 0.5).ceil
min = n
1.upto(max) do |i|
  if n % i == 0
    min = [min, i + n / i - 2].min
  end
end

puts min


Measured memory_bytes: 14988
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())
 
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll MOD=1e9+7;
 
ll tim(ll ans, int a){
	return (ans*(ll)a)%MOD;
}
 
int main(){
	int N,M;
	cin>>N>>M;
	int A[1005], B[1005];
	rep(i,N)cin>>A[i];
	rep(i,M)cin>>B[i];
	sort(A, A+N, greater<int>());
	sort(B, B+M, greater<int>());
	A[N]=0;B[M]=0;
	rep(i,N-1)if(A[i]==A[i+1]){
		cout<<0<<endl;
		return 0;
	}
	rep(j,M-1)if(B[j]==B[j+1]){
		cout<<0<<endl;
		return 0;
	}
	ll ans=1;
	int ca=0;
	int cb=0;
	for(int i=N*M; i>=1; i--){
		if(A[ca]==i && B[cb]==i){
			ca++;cb++;
		}
		else if(A[ca]==i){
			ca++;
			ans=tim(ans, cb);
		}
		else if(B[cb]==i){
			cb++;
			ans=tim(ans, ca);
		}
		else{
			int t=ca*cb-(N*M-i);
			if(t<0){
				ans=0;
				break;
			}
			ans=tim(ans, t);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
	vector <string> v(3);
	for(int i=0; i<3; i++){
		cin >> v[i];
	}
	int index=0;
do{
	char temp=v[index][0];
		
		v[index].erase(v[index].begin());
		index = int(temp-'a');

	}	while(!v[index].empty());
	cout << char(index+'A') << endl;
	return 0;
}

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


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

int main()
{
  int n;
  for(;cin>>n;)
    {
      long long int data[n];
      for(int i=0;i<n;i++)
	cin>>data[i];
      long long int ans=0;
      long long int sum=0;
      sort(data,data+n);
      for(int i=0;i<n;i++)
	{
	  sum+=data[i];
	  ans+=sum;
	}
      cout<<ans<<endl;
      
    }
}

Measured memory_bytes: 1184
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

string s;

int f(map<int,int> M,int g){
	int r=0;
	if(g==0){
		rep2(i,1,10)if(M[i]>=2){
			map<int,int> N=M;
			N[i]-=2;
			r|=f(N,1);
		}
		return r;
	}
	int h=1;
	rep2(i,1,10)if(M[i])h=0;
	if(h)return 1;
	rep2(i,1,10)if(M[i]>=3){
		map<int,int> N=M;
		N[i]-=3;
		r|=f(N,1);
	}
	rep2(i,1,8)if(M[i]&&M[i+1]&&M[i+2]){
		map<int,int> N=M;
		N[i]--,N[i+1]--,N[i+2]--;
		r|=f(N,1);
	}
	return r;
}

int main(){
	while(cin>>s){
		vi a;
		map<int,int> M;
		rep(i,13)M[s[i]-'0']++;
		rep2(i,1,10)if(M[i]<=3){
			map<int,int> N=M;
			N[i]++;
			if(f(N,0))a.pb(i);
		}
		if(a.sz==0)cout<<0<<endl;
		else rep(i,a.sz)cout<<a[i]<<(i<a.sz-1?" ":"\n");
	}
}

Measured memory_bytes: 928
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,i,e,f,g,n,m,k,l;
string s;
int main() {
    cin>>n;
    for(long long i=1;i<=n;i++) {
        if(i%3==0 || i%5==0) continue;
        k+=i;
    }
    cout<<k;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int ask(int x)
{
    printf("%d\n", x); fflush(stdout);
    char buf[255];
    scanf("%s", buf);
    if(buf[0] == 'V')
    {
        exit(0);
    }
    return buf[0] == 'M';
}
int main()
{
    int N; scanf("%d", &N);
    int lo = 0, lot = ask(lo);
    int hi = N-1, hit = ask(hi);
    while(true)
    {
        int mi = (lo+hi)/2;
        int v = ask(mi);
        if(abs(lo-mi)%2 != abs(lot-v)%2)
        {
            hi = mi;
            hit = v;
        }
        else
        {
            lo = mi;
            lot = v;
        }
    }
}

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

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

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    A, B, C, K = MAP()

    if A > K:
        a, b, c = K, 0, 0
    else:
        a = A

        if B > K - A:
            b, c = K - A, 0
        else:
            b, c = B, K - A - B

    print(a - c)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10080
package main

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

func sliceAtoi(sa []string) ([]int, error) {
	si := make([]int, 0, len(sa))
	for _, a := range sa {
		i, err := strconv.Atoi(a)
		if err != nil {
			return si, err
		}
		si = append(si, i)
	}
	return si, nil
}

func stdInInt() int {
	var N int
	fmt.Scan(&N)
	return N
}

func stdInNumSlice() []int {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	stringInput := scanner.Text()
	A, _ := sliceAtoi(strings.Split(stringInput, " "))
	return A
}

func stdOutList(list *[]int) {
	str := fmt.Sprintf("%v", *list)
	str = strings.Trim(str, "[]")
	fmt.Println(str)
}

func main() {
	N := stdInInt()
	A := stdInNumSlice()
	i := 0
	s := 0
	for i < N-1 {
		min := i
		for j := i; j < N; j++ {
			if A[j] < A[min] {
				min = j
			}
		}
		if A[min] != A[i] {
			tmp := A[min]
			A[min] = A[i]
			A[i] = tmp
			s++
		}
		i++
	}
	stdOutList(&A)
	fmt.Println(s)
}



Measured memory_bytes: 1200
$debug=0
def aux(s,cmds)
  puts "s: #{s}" if $debug>1
  while cmds.length>0
    cmd = cmds.shift
    op= cmd[0]
    a = cmd[1].to_i
    b = cmd[2].to_i
    p = cmd[3]
    len=s.length
    puts "op: #{op}, a: #{a}, b: #{b}, p: #{p}"  if $debug>1
    if op=="print"
      puts s.slice(a..b)
    elsif op=="reverse"
      s = s.slice(0,a) + s.slice(a..b).reverse + s.slice(b+1,len-b)
    elsif op=="replace"
      s = s.slice(0,a) + p + s.slice(b+1,len-b)
    else
      abort("no such command: #{op}")
    end
    puts "s: #{s}"  if $debug>1

  end
  s

end
s="abcde"
a=1
b=3

def main
  fh=STDIN
  #fh=File.new("x.txt", "r")
  s = fh.gets.chomp
  n = fh.gets.chomp.to_i
  cmds = []
  n.times {|i|
    cmds <<fh.gets.chomp.split
  }
  aux(s,cmds)
end

if $0 == __FILE__ then
  main
end


Measured memory_bytes: 7052
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) < *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static 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;
}

int main(void) {
	size_t N, M;
	int32_t B[20];
	int32_t C;

	scanf("%zu %zu %"PRId32"\n", &N, &M, &C);
	for (size_t i = 0; i < M; i++) {
		scanf("%"PRId32, &B[i]);
		if (i < M - 1) {
			scanf(" ");
		}
		else {
			scanf("\n");
		}
	}

	size_t count = 0;

	for (size_t i = 0; i < N; i++) {
		int32_t sum = C;
		for (size_t j = 0; j < M; j++) {
			int32_t A;
			scanf("%"PRId32, &A);
			if (j < M - 1) {
				scanf(" ");
			}
			else {
				if (i < N - 1) {
					scanf("\n");
				}
			}
			sum += B[j] * A;
		}

		if (0 < sum) {
			count++;
		}
	}

	printf("%zu\n", count);

	return 0;
}


Measured memory_bytes: 256