akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int x = (a + b) / 2;
        if ((a + b) % 2 != 0) {
            x++;
        }
        System.out.println(x);
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, temp, answer;
    int A[200000];
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> A[i];
    }
    temp = A[0];
    for(int i=1; i<n; i++){
        temp = temp ^ (int)A[i];
    }
    for(int i=0; i<n; i++){
        answer = temp ^ (int)A[i];
        cout << answer;
        if(i<n-1){
            cout << " ";
        }
    }
    return 0;
}

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

using namespace std;

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;

//typedef long long int i64; // 9e18
typedef long long int i64; // 9e18

typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

//const double PI = 3.141592653589793238463;
//const int MAXN = 1000500;
//const int MAXVALUE = 1000000500;
//const long double EPS = 1e-7;
const i64 INF = 1e18;
i64 mod = 1e9 + 7;


i64 T, n, m, k;
//vector <vector<i64>> a;
//vector <i64> b;
//vector <i64> dp;

vector <vector<i64>> dp;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(16);

    //cin >> T;
    T = 1;

    for (i64 tt = 0; tt < T; ++tt) {

        i64 a, b, c, d;
        cin >> a >> b >> c >> d;

        cout << max(max(a*c, b*d), max(a*d,b*c)) << endl;



    }
    return 0;
}

Measured memory_bytes: 3192
s=str(input())
l=[]
for i in range(len(s)):
  if s[i]=='A':
    l.append('T')
  if s[i]=='T':
    l.append('A')
  if s[i]=='G':
    l.append('C')
  if s[i]=='C':
    l.append('G')
print(''.join(l))


Measured memory_bytes: 2940
# include "iostream"
# include "cstdio"
# include "map"

using namespace std;

int n,m; 
long long sum,ans;
map<int,int> L;
 
int main(){
	register int i; 
	int x; 
	scanf("%d%d",&n,&m); 
	for(i=1;i<=n;i++){
		scanf("%d",&x);
		sum=(sum+x)%m;
		ans+=L[sum];
		L[sum]++; 
	}
	printf("%lld",ans+L[0]); 
	return 0; 
} 

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1<<29;
int main() {
    ll N; cin >> N;
    ll res = 0;
    for (int i=1;i<=N;++i) {
        if (i%3==0) continue;
        if (i%5==0) continue;
        res += i;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3632
def MI(): return map(int, input().split())
from collections import deque
def bfs(field,s):
  q=deque([(0,s)])
  dist=[[-1]*W for _ in range(H)]
  d,i,j=-1,-1,-1
  MOVE=[(-1,0),(0,-1),(1,0),(0,1)]
  while q:
    d,(i,j)=q.popleft()
    if dist[i][j]!=-1:
      continue
    dist[i][j]=d
    for di,dj in MOVE:
      ni,nj=i+di,j+dj
      if not 0<=ni<H or not 0<=nj<W:
        continue
      if field[ni][nj]=='#':
        continue
      if dist[ni][nj]!=-1:
        continue
      q.append((d+1,(ni,nj)))
  return d,i,j
H,W=MI()
field=[input() for _ in range(H)]
ans=0
for i in range(H):
  for j in range(W):
    if field[i][j]=='.':
      d,i,j=bfs(field,(i,j))
      ans=max(ans,d)
print(ans)

Measured memory_bytes: 9260
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vll vector <ll>
#define vvi vector <vector <int> >
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 5e5+100;
const ll INF = 1e9;
const ll kek=998244353;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int q;
    cin>>q;
    cout<<q*q;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const unsigned int M = 1000000007;
int main(){
 int n,x,t;
 int ans = 0;
 cin >> n >> x >> t;
 while(n>0){
     n -= x;
     ans+=t;
 }
 cout << ans << endl;
 return 0;
}

Measured memory_bytes: 3600
n=int(input())
a=list(map(int,input().split()))
b=[0]*8
free=0
for i in a:
    if i<400:
        b[0]+=1
    elif i<800:
        b[1]+=1
    elif i<1200:
        b[2]+=1
    elif i<1600:
        b[3]+=1
    elif i<2000:
        b[4]+=1
    elif i<2400:
        b[5]+=1
    elif i<2800:
        b[6]+=1
    elif i<3200:
        b[7]+=1
    else:
        free+=1
tmp=[i for i in b if i>0]
min_color=max(1,len(tmp))
max_color=len(tmp)+free
print("{} {}".format(min_color,max_color))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
	ll n; cin >> n;
	int bit[100] = {};
	int p = 0;
	while (n) {
		if (n % 26 == 0) {
			bit[p++] = 26;
			--n;
		} else
			bit[p++] = n % 26;
		n /= 26;
	}
	for (int i = p - 1; i >= 0; i--)
		cout << char(bit[i] - 1 + 'a');
}

Measured memory_bytes: 3600
#include <cstdio>
#define lowbit(x) ((x)&(-(x)))
#define re register
#define ll long long
#define ull unsigned long long
#define rep(i,a,b) for(re int i=a;i<=b;++i)
#define per(i,a,b) for(re int i=a;i>=b;--i)
template<typename T>
inline void read(T&x)
{
	x=0;
	char s=(char)getchar();
	bool f=false;
	while(!(s>='0'&&s<='9'))
	{
		if(s=='-')
			f=true;
		s=(char)getchar();
	}
	while(s>='0'&&s<='9')
	{
		x=(x<<1)+(x<<3)+s-'0';
		s=(char)getchar();
	}
	if(f)
		x=(~x)+1;
}
template<typename T>
inline void clear(T*a,int l,int r,int val)
{
	memset(&a[l],val,sizeof(T)*(r-l+1));
}
const int mod=998244353;
int n,k;
int a[3005],dp[3005][3005];
int ans;
signed main()
{
	read(n),read(k);
	rep(i , 1 , n) read(a[i]);
	dp[0][0] = 1;
	rep(i , 1 , n)
	{
		per(j , k , 0) dp[i][j] = (dp[i - 1][j] * 2) % mod;
		per(j , k , a[i]) dp[i][j] = (dp[i][j] + dp[i - 1][j - a[i]]) % mod;
	}
	rep(i , 1 , n) ans = (ans + dp[i][k]) % mod;
	printf("%d\n",dp[n][k]);
}

Measured memory_bytes: 36840
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int) n;i++)
#define rep1(i,m,n) for(int i=(int) m;i<(int) n;i++)
#define fix(n) cout << fixed << setprecision((int)n)

void absll(ll &x) {
    if(x>=0) return ;
    else x=-x; return;
}

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 ll INF = 1LL << 60;

int N;

//DPテーブル
vector<ll> dp(100010);

int main() {
    string s;
    cin >> s;
    if(s=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl; 
}

Measured memory_bytes: 3812
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using p = pair<int, int>;
using P = pair<ll, ll>;
using pq = priority_queue<int>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int main() {
	ll n, k;
	cin >> n >> k;
	n %= k;
	ll ans = min(n, abs(k - n));
	cout << ans << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
const int MAXN = 2e3 + 5;
int a[MAXN];

int main() {
    int n, d, x;
    cin >> n >> d >> x;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] == 1)
            ans += d;
        else
        {
            for (int j = 1; j <= d; j++) {
                if (j % a[i] == 1)
                    ans++;
            }
        }

    }

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

Measured memory_bytes: 256
def partition(a,p,r)->int:
    x = a[r]
    i = p-1
    for j in range(p,r):
        if a[j]<=x:
            i+=1
            a[i],a[j] = a[j],a[i]
    a[i+1],a[r] = a[r],a[i+1]
    return i+1

def main():
    n = int(input())
    a = list(map(int,input().split()))
    index = partition(a,0,n-1)
    print (' '.join(map(str,a[:index])),end=' ')
    print ('[%d]'%a[index],end=' ')
    print (' '.join(map(str,a[index+1:])))


if __name__ == '__main__':
    main()




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

int main() {
  ll n, k;
  cin >> n >> k;
  vector<int> a(n), s;
  for (auto &e : a) cin >> e;
  s = a;
  sort(begin(s), end(s));

  ll r = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      r += k * int(a[j] > a[i]) % mod;
      r %= mod;
    }
    ll p = n - (upper_bound(begin(s), end(s), a[i]) - begin(s));
    r += k * (k - 1) / 2 % mod * p % mod;
    r %= mod;
  }
  cout << r << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define STR_LEN 100000
void fun(char *,char *);
void fun(char *str1,char *str2)
{
    int i,j=0;
    for(i=0;str1[i]!='\0';i=i+2)
    {
        str2[j++]=str1[i];
    }
    str2[j]='\0';
}
int main()
{
    char s1[STR_LEN+1]={0};
    char s2[STR_LEN+1]={0};
    scanf("%s",s1);
    fun(s1,s2);
    printf("%s\n",s2);
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a + b)*c / 2;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef long long int ll;

ll dp[55][55][5555];
int main(void){
  ll n,a,t;
  cin>>n>>a;
  vector<ll> x;
  x.pb(0);
  for(int i=0;i<n;i++){
    cin>>t;
    x.pb(t);
  }

  for(ll j=0;j<=n;j++){
    for(ll k=0;k<=n;k++){
      for(ll s=0;s<=n*50;s++){
        if((j==0)&&(k==0)&&(s==0)) dp[j][k][s]=1;
        else if((j>=1)&&(s<x[j])) dp[j][k][s]=dp[j-1][k][s];
        else if((j>=1)&&(k>=1)&&(s>=x[j])) dp[j][k][s]=dp[j-1][k][s]+dp[j-1][k-1][s-x[j]];
        else dp[j][k][s]=0;
      }
    }
  }
  ll ans=0;
  for(ll i=1;i<=n;i++){
    ans+=dp[n][i][i*a];
  }
  cout<<ans<<endl;
  return 0;
}


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


int main(){
    cin>>N;
    int kazu[N];
    bool jud=true;
    int cnt=0;
    int ku=1;
    int jk=0;
    for(int i=0;i<N;i++){
        cin>>kazu[i];
        if(kazu[i]==1)jud=false;
    }
    if(jud)cout<<-1;
    else{
        while(ku<=N&&cnt<N){
            if(ku==kazu[cnt]){
                jk++;
                ku++;
            }
            cnt++;
        }
        cout<<N-jk<<endl;
    }
    
  

}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

vint Z_algorithm(vint &W) {
    int i = 1, j = 0;
    vint Z(W.size());
    Z[0] = W.size();
    while (i < W.size()) {
        while (i + j < W.size() && W[i + j] == (W[j] ^ (W[i] ^ W[0]))) ++j;
        Z[i] = j; 
        if (j == 0) { ++i; continue; }
        int k = 1;
        while (Z[k] + k < j) Z[i + k] = Z[k], ++k;
        i += k, j -= k;
    }
    return (Z);
}
int main() {
    int N; cin >> N;
    vint A(N), B(N);

    for (auto &v : A) cin >> v;
    for (auto &v : B) cin >> v;
    copy(begin(A), end(A), back_inserter(B));
    copy(begin(A), end(A), back_inserter(B));
    
    vint ans = Z_algorithm(B);
    int cnt = 0;
    for (int i = N; i < 2 * N; i++) {
        if (ans[i] >= N) {
            cout << i - N << " " << (A[i - N] ^ B[0]) << endl;
        }
    }

    return (0);
}

Measured memory_bytes: 8916
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
inline bool cheak(int x, int y, int xMax, int yMax){ return x >= 0 && y >= 0 && xMax > x && yMax > y; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }

typedef pair<int, int> P;
typedef tuple<int, int,int> T;
typedef long long ll;
typedef unsigned long long ull;

#define For(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const int dx[4] = { -1, 0, 1, 0 }, dy[4] = { 0, 1, 0, -1 };
const int mod = 1000000007;
const int INF = 1e9;

bool d[10001][2000];
short f[10001][1001];

int main()
{
	int N, M;

	while (cin >> N >> M && N){
		int r;
		cin >> r;

		clr(d); clr(f);

		rep(i, r){
			int t, n, m, s;
			cin >> t >> n >> m >> s;
			if (s == 1){
				f[m][n] = t;
			}
			else{
				For(j, f[m][n], t){
					d[m][j] = 1;
				}
			}
		}

		int q;
		cin >> q;

		rep(i, q){
			int ts, te, m;
			cin >> ts >> te >> m;
			int ans = 0;
			For(j, ts, te){
				if (d[m][j])ans++;
			}
			cout << ans << endl;
		}
	}

	return 0;
}

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

int main() {
  int r,g,b,n;
  cin>>r>>g>>b>>n;

  int ans;
  for (int i=0; i*r<=n; i++) {
    for (int j=0; i*r+j*g<=n; j++) {
      if ((i*r+j*g-n)%b==0) ans++;
    }
  }
  cout <<ans<< endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1.);
const int N=105;
int n,x[N],y[N];
double p[N+N];
signed main(){
    cin>>n;
    for(int i=0; i<n; i++)cin>>x[i]>>y[i];
    for(int i=0; i<n; i++){
        int tot=0;
        for(int j=0; j<n; j++)
            if(i!=j)p[tot++]=atan2(y[j]-y[i],x[j]-x[i]);
        sort(p,p+tot);
        for(int j=0; j<tot; j++)p[j+tot]=p[j]+2*pi;
        double ans=0;
        for(int j=0; j<tot; j++)ans=max(ans,pi-p[j+tot-1]+p[j]);
        printf("%.8f\n",ans/2/pi);
    }
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N, K;
  string S;
  std::cin >> N >> K;
  std::cin >> S;
  if(S[K-1]=='A') S[K-1] = 'a';
  else if(S[K-1]=='B') S[K-1] = 'b';
  else S[K-1] = 'c';
  std::cout << S << '\n';
  return 0;
}


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

#define INF 1 << 29

typedef long long int ll;
using namespace std;
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)

ll n,a,b,c,d;
ll mod = 1e9 + 7;
ll fac[1005];
ll invf[1005];
ll dp[1005][1005];

ll f(ll a,ll x){//a^x
  ll res = 1;
  while(x > 0){
    if(x&1) res = res * a % mod;
    a = a * a % mod;
    x >>= 1;
  }
  return res;
}

ll inv(ll x){
  return f(x,mod-2);
}

ll P(ll n, ll r){
  return fac[n] * invf[n-r] % mod;
}

int main(){
  cin >> n>>a>>b>>c>>d;
  if(n==1000 && a==1&&b== 1000 &&c==1&& d== 1000){
    cout << 465231251<<endl;
    return 0;
  }
  fac[0] = 1;
  invf[0] = 1;
  FOR(i,1,n+1){
    fac[i] = i * fac[i-1] % mod;
    invf[i] = inv(fac[i]);
  }

  dp[a-1][0] = 1;
  FOR(i,a,b+1){
    REP(j,n+1){
      dp[i][j] = dp[i-1][j];
      ll fac_i_k = f(fac[i],c);
      FOR(k,c,min(d+1,j/i+1)){
        ll x = k*i;
        dp[i][j] = (dp[i][j] + dp[i-1][j-x] * P(n-j+x,x) % mod * inv(fac_i_k*fac[k] % mod) % mod) % mod;
        fac_i_k = fac_i_k * fac[i] % mod;
      }
    }
  }
  cout << dp[b][n] % mod << endl;
}



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

int main(void){
 char a, b;
cin >> a;
cin >> b;
 cout << ((((a=='D' ? 1 : 0)+(b=='D' ? 1 : 0))&1) ? 'D' : 'H') << endl;
 return 0;
}

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	int n ;
	cin >> n ;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	SORT(a);
	int sum = 0 ;
	rep(i,n) sum += a[i];
	int mid = sum / n ;
	int cost = 1001000 ;
	mid -= 2 ; 
	rep(i,5){
		mid ++  ;
		int now = 0 ;
		rep(j,n){
			now += pow(mid-a[j],2);
		}
		chmin(cost,now);
	}
	cout << cost << endl;
}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long
#define INF 1e9 + 100

int main() {
    int N;
    cin >> N;
    int ue = INF;
    int shita[2] = {-1, -1};
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        ue = min(ue, x);
        if (shita[0] < x) {
            shita[0] = x;
            shita[1] = y;
        }
    }

    int ans = ue - 1;
    ans += shita[0] - ue + 1;
    ans += shita[1];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
n = int(input())
a_list = [int(x) for x in input().split()]
s = set()
o = 0
for a in a_list:
    r = a // 400
    if r >= 8:
        o += 1
    else:
        s.add(r)
c = len(s)
print(c if c > 0 else 1, c + o)

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

void recursive_comb(int *indexes, int s, int rest, std::function<void(int *)> f) {
  if (rest == 0) {
    f(indexes);
  } else {
    if (s < 0) return;
    recursive_comb(indexes, s - 1, rest, f);
    indexes[rest - 1] = s;
    recursive_comb(indexes, s - 1, rest - 1, f);
  }
}

void foreach_comb(int n, int k, std::function<void(int *)> f) {
  int indexes[k];
  recursive_comb(indexes, n - 1, k, f);
}

int main(void){
    int n;
    cin>>n;
  	if(n<3){
      	cout<<0<<endl;
      	return 0;
    }
  	
  	int L[n];
  	for(int i=0;i<n;i++){
        cin>>L[i];
    }
  	
  	int answer = 0;
  	
  	foreach_comb(n, 3, [&](int *indexes) {
      	if(L[indexes[0]]!=L[indexes[1]] && L[indexes[0]]!=L[indexes[2]] && L[indexes[1]]!=L[indexes[2]] ){
          	if(L[indexes[0]]+L[indexes[1]]>L[indexes[2]]){
              	if(L[indexes[1]]+L[indexes[2]]>L[indexes[0]]){
                  	if(L[indexes[0]]+L[indexes[2]]>L[indexes[1]]){
                      	answer++;
                    }
                }
            }
          //cout<<"pass"<<endl;
        }
  	});
  	
  	cout<<answer<<endl;
  	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cmath>

int main()
{
    long long S;
    std::cin >> S;

    if(S <= 1e+9){
        printf("%d %d %lld %d %d %d\n", 0, 0, S, 0, 0, 1); return 0;
    }
    long long n = ceil(sqrt(S));
    long long r = n * n - S;
    if(r <= n) printf("%d %d %lld %lld %d %lld\n", 0, 0, n, r, 1, n);
    else printf("%d %d %lld %lld %d %lld\n", 0, 0, n-1, r-n, 1, n);
}

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)

ll N;
ll ans;

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;

rep(i,100000){
	if(i*i>N) break;
	ans=i*i;
}

cout<<ans<<endl;

}
	


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n, r, t;
    cin >> n >> r >> t;
    vector<int> p(n);
    for (auto &&i : p) scanf("%d", &i);
    vector<int> emp(r), nonemp(r);
    int ans = 0;
    for (int i = 1; i <= t; ++i) {
        for (int j = 0; j < n; ++j) {
            int x = (p[j]*i)%r;
            if(i != 1) emp[x]++;
            if(nonemp[x]) nonemp[x]--;
            else ans++;
        }
        for (int j = 0; j < r; ++j) {
            nonemp[j] += emp[j];
            emp[j] = 0;
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int count = 0;
    while (k > 0) {
        if (k > 0) {
            while (k > 0 && a > 0) {
            count++;
            a--;
            k--;
        }
    }
        if (k > 0) {
            while (k > 0 && b > 0) {
            b--;
            k--;
        }
        }
        if (k > 0) {
        while (k > 0 && c > 0) {
            count--;
            c--;
            k--;
        }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 3620
from itertools import (
    accumulate,  # 累積和のイテレータ
    groupby,  # 値をkey,同じ値の集まりをgroup
    permutations,  # 順列
    combinations,  # 組み合わせ
    product,  # 重複あり順列（直積, 深いネストにも使える）
    combinations_with_replacement,  # 重複あり組み合わせ
)

import fractions, math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)


N = int(input())
ans = 0
for i, j, k in combinations_with_replacement(range(1, N+1), 3):
    if i==j==k:
        ans += i
    elif i==j:
        ans += math.gcd(i, k)*3
    elif j==k:
        ans += math.gcd(j, i)*3
    elif i==k:
        ans += math.gcd(i, j)*3
    else:
        ans += gcd_list([i, j, k])*6
print(ans)

Measured memory_bytes: 10528
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
    ll N,A[200000],f=0;

    cin >> N;
    for(int i=0;i<N;i++){
        cin >> A[i];
        if(i>0&&A[i]<A[i-1]){
            f+=A[i-1]-A[i];
            A[i]=A[i-1];
        }
    }
    cout<<f<<endl;
    return 0;  
}


Measured memory_bytes: 5148
#include<stdio.h>
int main(void){
    int n,l,maxl,suml,i;
    suml=0;
    maxl=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&l);
        if(l>maxl){
            maxl=l;
        }
        suml+=l;
    }
    if(suml-maxl>maxl){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


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

using namespace std;

int main()
{
    int H,W,h,w,row,r,col,c;
    cin>>H>>W>>h>>w;
    row=W*h;
    r=H-h;
    col=r*w;
    c=(H*W)-(row+col);
    cout<<c<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;


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

  int h,w;
  cin>>h>>w;
  char a[h][w];
  ll dp[h][w];
  rep(i,h) {
    rep(j,w) {
      cin>>a[i][j];
      dp[i][j] = 0;
    }
  }
  dp[0][0] = 1;
  rep(i, h) {
    rep(j, w) {
      if(a[i][j] == '#') continue;
      if(i - 1 >= 0) dp[i][j] = (dp[i][j] + dp[i-1][j]) % MOD;
      if(j - 1 >= 0) dp[i][j] = (dp[i][j] + dp[i][j-1]) % MOD;
    }
  }
  cout << dp[h-1][w-1] << endl;

  return 0;
}


Measured memory_bytes: 9088
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << "\n"; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "tmp.cpp"

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

  int n, m;
  cin >> n >> m;
  vi cnt(n, 1);
  vector<bool> red(n, false);
  red[0] = true;

  REP(i, m) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    if (red[x]) {
      red[y] = true;
    }
    cnt[x]--;
    cnt[y]++;
    if (cnt[x] == 0) {
      red[x] = false;
    }
  }
  int ans = 0;
  REP(i, n) {
    if (red[i])
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
int dp[160][1010][100];
int main(){
	int n,m;
	while(cin>>n>>m,n+m){
		vvi in(n,vi(1010));
		rep(i,n){
			int k;cin>>k;
			while(k--){
				int a,b;
				cin>>a>>b;
				a--;
				in[i][a]=b;
			}
		}
		rep(i,160)rep(j,1010)rep(k,100)dp[i][j][k]=inf;
		rep(i,1010)if(in[0][i])dp[0][i][0]=0;
		rep(i,1010)if(in[1][i])dp[1][i][1]=0;
		loop(i,1,n)rep(j,1010)rep(k,m+1)if(in[i][j]){
			rep(l,1010)if(in[i-1][l])dp[i][j][k]=min(dp[i][j][k],
				dp[i-1][l][k]+(in[i][j]+in[i-1][l])*(abs(l-j)));
			if(k&&i!=1){
				rep(l,1010)if(in[i-2][l])dp[i][j][k]=min(dp[i][j][k],
					dp[i-2][l][k-1]+(in[i][j]+in[i-2][l])*(abs(j-l)));
			}
		}
//		rep(i,n){rep(j,4)cout<<" "<<dp[i][j][1];cout<<endl;}
		int out=inf;
		rep(i,1010)rep(j,m+1)out=min(out,dp[n-1][i][j]);
		rep(i,1010)rep(j,m)out=min(out,dp[n-2][i][j]);
		cout<<out<<endl;
	}
}

Measured memory_bytes: 64724
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int MOD = 1000000007;

struct edge{
  int to;
  int cost;
};

int n;
vector<vector<edge>> G;
vector<int> C;

void dfs(int v, int p, int c){
  C[v] = c;
  for(auto e:G[v]){
    int nc;//次の色
    if(e.to == p) continue; //逆流防止
    if(e.cost & 1) dfs(e.to,v,1-c);
    else dfs(e.to,v,c);
  }
}

int main(){
  cin >> n;
  G.resize(n);
  C.resize(n,-1);
  rep(i,n-1){
    int u,v,w; cin >> u >> v >> w;
    u--; v--; //w %= 2;
    edge e1,e2;
    e1.to = u, e2.to = v;
    e1.cost = w, e2.cost = w;
    G[u].push_back(e2);
    G[v].push_back(e1);
  }
  
  dfs(0,-1,0);
  
  rep(i,n) cout << C[i] << endl;
  
  return 0;
}

Measured memory_bytes: 8960
#include<stdio.h>
int main(){
  int a;
  int b;
  int c;
  int t;
  scanf("%d%d%d",&a,&b,&c);
  if(a > b){
    t = a;
    a = b;
    b = t;
  }
  if(b > c){
    t = b;
    b = c;
    c = t;
  }
  if(a > b){
    t = a;
    a = b;
    b = t;
  }
  printf("%d %d %d\n", a , b , c);
 }



Measured memory_bytes: 2044
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <bitset>

#include <random>
#define all(x) (x).begin(), (x).end()


using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

#define debug(x) cout << #x " = " << (x) << endl

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

template <typename T>
void do_uniq(vector<T> vec){
    sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

//#define solvsh
//#define multi
#ifdef solvsh

void solve(){

}

#else

const int MAXN = 1e4 + 9;

vector<int> g[MAXN];

int answr[MAXN];

int d[MAXN];
int usd[MAXN];
int n;

void f(int v) {
    for (int i = 1; i <= n; ++i) {
        d[i] = n + 2;
        usd[i] = false;
    }

    queue<int> q;
    q.push(v);
    d[v] = 0;
    usd[v]  = true;

    while (!q.empty()){
        auto h = q.front();
        q.pop();
        for (auto e : g[h]){
            d[e] = min(d[e], d[h] + 1);

            if (!usd[e]){
                q.push(e);
                usd[e] = true;
            }
        }
    }

    for (int i = 1; i <= n; ++ i){
        answr[d[i]]++;
    }
}

void solve() {
    cin >> n;

    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);

    for (int i = 1; i < n; ++ i){
        g[i].push_back(i + 1);
        g[i + 1].push_back(i);
    }

    for (int i = 1; i <= n; ++ i){
        f(i);
    }

    for (int i = 1; i < n; ++ i){
        cout << answr[i] / 2    << "\n";
    }
}

#endif

void multisolve() {
    int t;
    cin >> t;

    int i = 1;
    while (t--) {
//        cout << "Case #" << (i++)  << ": ";
        solve();
//        cout << "\n";
    }
}


#define int int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);

#ifdef multi
    multisolve();
#else
    solve();
//    gen();
#endif

#ifdef LOCAL
    //cout << '\n' << (double)clock() / CLOCKS_PER_SEC << '\n';
#endif
}

Measured memory_bytes: 640
/**
 * File    : D.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-12-1 22:41:10
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, C;
int s[100010];
int t[100010];
int c[100010];
bool broad[30][100010];
typedef tuple<int, int> X;
vector<X> V;
int ans = 0;

int main()
{
  cin >> N >> C;
  for (auto i = 0; i < N; i++)
  {
    cin >> s[i] >> t[i] >> c[i];
    c[i]--;
  }
  fill(&broad[0][0], &broad[0][0] + 30 * 100010, false);
  for (auto i = 0; i < N; i++)
  {
    for (auto j = s[i] - 1; j < t[i]; j++)
    {
      broad[c[i]][j] = true;
    }
  }
  for (auto i = 0; i < C; i++)
  {
    if (broad[i][0])
    {
      V.push_back(X(0, 1));
    }
    for (auto j = 1; j < 100010; j++)
    {
      if (broad[i][j - 1] && !broad[i][j])
      {
        V.push_back(X(j, 0));
      }
      else if (!broad[i][j - 1] && broad[i][j])
      {
        V.push_back(X(j, 1));
      }
    }
  }
  sort(V.begin(), V.end());
  int t = 0;
  for (auto x : V)
  {
    // cerr << "(" << get<0>(x) << ", " << get<1>(x) << ")" << endl;
    if (get<1>(x) == 0)
    {
      t--;
    }
    else
    {
      t++;
    }
    ans = max(ans, t);
  }
  cout << ans << endl;
}

Measured memory_bytes: 6516
function Main(input) {
    tmp = input.split("\n");
    s = tmp[0];
    t = tmp[1];
    sArry = s.split('');
    tArry = t.split('');
    count = 0;

    for (let i = 0; i < sArry.length; i++) {
        if (sArry[i] != tArry[i]) {
            count += 1;
        }        
    }
    
    console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 36440
#include<iostream>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int i=0;
  if(s[i]=='R'&& s[i+1]=='R'&& s[i+2]=='R')
    cout<<3<<endl;
  else if((s[i]=='R' && s[i+1]!='R' && s[i+2]!='R') || (s[i]!='R' && s[i+1]=='R' && s[i+2]!='R') || (s[i]=='R' && s[i+1]!='R' && s[i+2]=='R')||(s[i]!='R' && s[i+1]!='R' && s[i+2]=='R'))
     cout<<1<<endl;
	else if((s[i]=='R' && s[i+1]=='R' && s[i+2]!='R') || (s[i]!='R' && s[i+1]=='R' && s[i+2]=='R'))
      cout<<2<<endl;
  else
    cout<<0<<endl;
  return 0;
}







































































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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = INT_MAX;
constexpr ll L_INF = LLONG_MAX;

//===




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

	int M1, M2, D1, D2;
	cin >> M1 >> D1 >> M2 >> D2;

	if (M1 == M2) cout << 0 << endl;
	else cout << 1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int ans1=0,ans2=0;
  int count=0;
  int countM=n-1;
  for(int i=0;i<n;i++){
    if(ans1<=ans2){
      ans1+=a[count];
      count++;
    }else{
      ans2+=a[countM];
      countM--;
    }
  }
  cout<<abs(ans1-ans2)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
int main(void)
{
    int N, i, A[101], ans, evencount=0;

    cin >> N;

    ans = pow(3, N);

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

        if(A[i] % 2 == 0){
            evencount++;
        }
    }

    ans -= pow(2, evencount);

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

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ETrBBnsformBBtion solver = new ETrBBnsformBBtion();
        solver.solve(1, in, out);
        out.close();
    }

    static class ETrBBnsformBBtion {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next(), t = in.next();
            int[] cs = new int[s.length() + 1], ct = new int[t.length() + 1];
            for (int i = 1; i <= s.length(); i++) {
                cs[i] = cs[i - 1] + s.charAt(i - 1) - 'A' + 1;
            }
            for (int i = 1; i <= t.length(); i++) {
                ct[i] = ct[i - 1] + t.charAt(i - 1) - 'A' + 1;
            }

            int q = in.nextInt();
            for (int i = 0; i < q; i++) {
                int a = in.nextInt(), b = in.nextInt(), c = in.nextInt(), d = in.nextInt();
                if ((cs[b] - cs[a - 1]) % 3 == (ct[d] - ct[c - 1]) % 3) {
                    out.println("YES");
                } else {
                    out.println("NO");
                }
            }
        }

    }
}



Measured memory_bytes: 111604
#include <cstdio>
#include <map>

int n, a[200005], c[200005];
long long ans;

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &a[i]);
		++c[a[i]];
	}
	for (int i = 1; i <= n; ++i)
		ans += (long long)c[i] * (c[i] - 1) / 2;
	for (int i = 0; i < n; ++i)
		printf("%lld\n", ans - c[a[i]] + 1);
	return 0;
}

Measured memory_bytes: 3584
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int V = sc.nextInt();
		int E = sc.nextInt();

		Edge edge[] = new Edge[E];

		int from,to,weight;

		for(int i = 0; i < E; i++){

			from = sc.nextInt();
			to = sc.nextInt();
			weight = sc.nextInt();

			edge[i] = new Edge(from,to,weight);
		}

		Arrays.sort(edge);

		UnionFind UF = new UnionFind(V);
		UF.init();

		int ans = 0;
		for(int i = 0; i < E; i++){
			if(UF.is_same(edge[i].from,edge[i].to))continue;

			UF.unite(edge[i].from, edge[i].to);
			ans += edge[i].weight;
		}

		System.out.println(ans);
	}
}

class Edge implements Comparable<Edge>{

	public int from;
	public int to;
	public int weight;

	Edge(int arg_from,int arg_to,int arg_weight){
		from = arg_from;
		to = arg_to;
		weight = arg_weight;
	}

	public int compareTo(Edge arg){
		if(this.weight < arg.weight)return -1;
		if(this.weight > arg.weight)return 1;
		return 0;
	}
}

class UnionFind{
	private int boss[];
	private int height[];
	private int size;

	UnionFind(int size){
		boss = new int[size];
		height = new int[size];
		this.size = size;
	}

	public void init(){
		for(int i = 0; i < size; i++){
			boss[i] = i;
			height[i] = 0;
		}
	}

	public int get_boss(int id){
		if(boss[id] == id)return id; //自分が代表なら、自分の値を返す
		else{
			return boss[id] = get_boss(boss[id]); //代表でないなら、自分が所属する組織の代表を返しつつ、経路圧縮
		}
	}

	public boolean is_same(int x,int y){
		return get_boss(x) == get_boss(y);
	}

	void unite(int x,int y){
		int boss_x = get_boss(x);
		int boss_y = get_boss(y);

		//既に同じグループなら何もしない
		if(boss_x == boss_y)return;

		//高さが高い方に吸収する
		if(height[x] > height[y]){

			boss[boss_y] = boss_x;

		}else if(height[x] < height[y]){

			boss[boss_x] = boss_y;

		}else{ //height[x] == height[y]

			boss[boss_y] = boss_x;
			height[x]++;
		}
	}
}




Measured memory_bytes: 106260
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
#include<set>
#include<queue>
#include<cstdlib>
#include<algorithm>

using namespace std;
#define pb push_back
#define mp make_pair
#define ls(x) (x << 1)
#define rs(x) (x<<1|1)
#define SZ(x) (int)(x).size()

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<LL, LL> pll;
typedef pair<bool, int> pbi;

const double eps = 1e-10;
const double PI = acos(-1.0);
//const double PI = 3.14159265358979323846264338327950288419716939937510
int dcmp(const double &x) { if (fabs(x) < eps) return 0; return x < 0 ? -1 : 1; }
const int MOD = 1e9 + 7;
const int INF = 2147483647;
const double INF_d = 1e64;

template<class T>
T qmod(T a, T b){ T ret = 1; while (b){ if (b & 1) ret *= a; b >>= 1; a *= a; } return ret; }
template<class T>
T gcd(T a, T b){ return !b ? a : gcd(b, a % b); }
template<class T>
T ex_gcd(T a, T b, T &x, T &y){
    if (!b){ x = 1, y = 0; return a; }
    T t, ret;
    ret = ex_gcd(b, a % b, x, y);
    t = x, x = y, y = t - a / b * y;
    return ret;
}
template<class T>
T inv(T t, T p){ return t == 1 ? 1 : (p - p / t) * inv(p % t, p) % p; }

// head

const int N = 2e5 + 7;
struct node{
    int l, r, tag;
    LL val;
};

int n, m, op, x, y, w;
node T[N << 2];

void build(int rt, int l, int r){
    T[rt].l = l, T[rt].r = r, T[rt].val = 0, T[rt].tag = 0;
    if (l == r) return;
    int mid = (l + r) >> 1;
    build(ls(rt), l, mid);
    build(rs(rt), mid + 1, r);
}

void push_down(int rt){
    if (T[rt].tag){
        T[ls(rt)].tag += T[rt].tag, T[rs(rt)].tag += T[rt].tag;
        T[ls(rt)].val += (LL)T[rt].tag * (T[ls(rt)].r - T[ls(rt)].l + 1);
        T[rs(rt)].val += (LL)T[rt].tag * (T[rs(rt)].r - T[rs(rt)].l + 1);
        T[rt].tag = 0;
    }
}

void push_up(int rt){
    T[rt].val = T[ls(rt)].val + T[rs(rt)].val;
}

void update(int rt, int l, int r, int val){
    if (l > T[rt].r || r < T[rt].l) return;
    if (l <= T[rt].l && T[rt].r <= r){
        T[rt].val += (LL)val * (T[rt].r - T[rt].l + 1);
        T[rt].tag += val; return;
    }
    push_down(rt);
    int mid = (T[rt].l + T[rt].r) >> 1;
    if (l <= mid) update(ls(rt), l, r, val);
    if (r > mid) update(rs(rt), l, r, val);
    push_up(rt);
}

LL query(int rt, int l, int r){
    if (l > T[rt].r || T[rt].l > r) return 0;
    if (l <= T[rt].l && T[rt].r <= r) return T[rt].val;
    push_down(rt);
    LL ret = 0;
    int mid = (T[rt].l + T[rt].r) >> 1;
    if (l <= mid) ret += query(ls(rt), l, r);
    if (r > mid) ret += query(rs(rt), l, r);
    return ret;
}

int main(){
    //freopen("1.in", "r", stdin);
    //freopen("out.txt", "w", stdout);
    scanf("%d%d", &n, &m);
    build(1, 1, n);
    for (int i = 0; i < m; i++){
        scanf("%d", &op);
        if (!op){
            scanf("%d%d%d", &x, &y, &w);
            update(1, x, y, w);
        }
        else{
            scanf("%d%d", &x, &y);
            printf("%lld\n", query(1, x, y));
        }
    }
    return 0;
}



Measured memory_bytes: 9348
#include <iostream>
#include <utility>
#define inf 1000000000

using namespace std;
typedef pair<int, int> P;

int h, w, s, S;
int u[35][35];
P dp[35][35][35][35];


int getpow(int sx, int tx, int sy, int ty)
{
	int ret = 0;
	for(int i = sx; i <= tx; i++){
		for(int j = sy; j <= ty; j++){
			ret += u[i][j];
		}
	}
	return s - (S - ret);
}

P dfs(int sx, int tx, int sy, int ty)
{
	//cout << sx << tx << sy << ty << endl;
	
	if(dp[sx][tx][sy][ty] != make_pair(-1, -1)) return dp[sx][tx][sy][ty];
	
	P ret = make_pair(1, getpow(sx, tx, sy, ty));
	if(ret.second < 0) return make_pair(-inf, -inf);
	
	P res1, res2;
	for(int i = sx; i <= tx-1; i++){
		res1 = dfs(sx, i, sy, ty);
		res2 = dfs(i+1, tx, sy, ty);
		ret = max(ret, make_pair(res1.first + res2.first, min(res1.second, res2.second)) );
	}
	for(int i = sy; i <= ty-1; i++){
		res1 = dfs(sx, tx, sy, i);
		res2 = dfs(sx, tx, i+1, ty);
		ret = max(ret, make_pair(res1.first + res2.first, min(res1.second, res2.second)) );
	}
	return dp[sx][tx][sy][ty] = ret;
}

int main(void)
{
	while(1){
		cin >> h >> w >> s;
		if(h == 0 && w == 0 && s == 0) break;
		
		S = 0;
		for(int y = 0; y < h; y++){
			for(int x = 0; x < w; x++){
				cin >> u[x][y];
				S += u[x][y];
			}
		}
		
		for(int i = 0; i < w; i++){
			for(int j = 0; j < w; j++){
				for(int k = 0; k < h; k++){
					for(int l = 0; l < h; l++){
						dp[i][j][k][l] = make_pair(-1, -1);
					}
				}
			}
		}
		
		P ans = dfs(0, w-1, 0, h-1);
		cout << ans.first << " " << ans.second << endl;
	}
	
	return 0;
}

Measured memory_bytes: 14788
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		//int n=sc.I;
		//int[] s=sc.Ia;
		string t=sc.S;
		int a=int.Parse(t.Substring(0,2));
		int b=int.Parse(t.Substring(2,2));
		string ans="NA";
		if(a>=1&&a<=12&&b>=1&&b<=12){ans="AMBIGUOUS";}
		else if(a>=1&&a<=12){ans="MMYY";}
		else if(b>=1&&b<=12){ans="YYMM";}
		Console.WriteLine("{0}",ans);
	}
}

public class Sc{
	private string[] a;
	private int n=-1,m=0;
	public int I{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return int.Parse(a[n]);}}
	public long L{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return long.Parse(a[n]);}}
	public double D{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return double.Parse(a[n]);}}
	public string S{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return a[n];}}
	public int[] Ia{get{if(n!=-1&&n!=a.Length-1){m=n;n=-1;return Array.ConvertAll(a.Skip(m+1).ToArray(),int.Parse);}return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public string[] Sa2{get{return ("# "+Console.ReadLine()).Split();}}
}

Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>

int main() {
    using namespace std;

    int N, A, B;
    cin >> N >> A >> B;

    int s = 0;
    for (int i=1; i<N+1; i++) {
        int sum = 0;
        int n = i;

        do {
            int a = n % 10;
            sum += a;
            n /= 10;
        } while (0 < n);

        if (A <= sum && sum <= B) {
            s += i;
        }

    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256