akhauriyash/Code-Regression huggingface dataset:
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Security;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] array1 = { '2', '4', '5', '7', '9' };
            char[] array2 = { '0', '1', '6', '8' };
            char[] array3 = { '3' };

            string a = "hon";
            string b = "pon";
            string c = "bon";
            
            string str = Console.ReadLine();

                    if (array1.Contains(str[str.Length - 1]))
                        Console.WriteLine(a);
                    if (array2.Contains(str[str.Length - 1]))
                        Console. WriteLine(b);
                    if (array3.Contains(str[str.Length - 1]))
                        Console.WriteLine(c);

        }
    }
}

Measured memory_bytes: 26248
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
//string b="12345";
//a = int(b[4]-48);
using namespace std;
int main()
{
	int N,ANS=0;
	string S;
	cin >> N >> S;

	for (int i = 0; i < N-2; i++) {
		if (S.substr(i, 3) == "ABC") {
			ANS++;
		}
	}
	cout << ANS << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

#include <map>

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin, n;
    vector<ll> A(n);
    map<int, ll> m;
    REP(i, 0, n) {
        cin, A[i];
        m[A[i]]++;
    }
    ll ans = 0;
    for (auto &it : m) {
        ll a = it.second;
        ans += a * (a - 1) / 2;
    }
    REP(i, 0, n) {
        ll a = m[A[i]];
        ll b = a - 1;
        cout << ans - a * (a - 1) / 2 + b * (b - 1) / 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 11136
#include<stdio.h>

long long min(long long x,long long y){

    if(x<y){
        return x;
    }else{
        return y;
    }
}

/*long long max(long long x,long long y){

    if(x>y){
        return x;
    }else{
        return y;
    }
}*/

long long to_1(long long A,long long B){
    return A + (B-A-1)/2;
}

long long to_N(long long N,long long A,long long B){
    return N-B+1 + (B-A-1)/2;
}

int main(){

    long long N, A, B;
    scanf("%ld%ld%ld", &N, &A, &B);

    long long ans;

    if((B-A)%2 == 0){
        ans = (B - A) / 2;
    }else{
        ans = min(to_1(A, B), to_N(N, A, B));
    }

    printf("%ld\n", ans);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'

int main() {
	int x, a;
	cin >> x >> a;
	
	if(x < a) cout <<"0";
	else cout << "10";
	
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();

		int b = 0;

		for(int i = 1; i <= a;i++) {
				b += i;
		}

		System.out.println(b);
	}
}

Measured memory_bytes: 22736
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string ans = "AGC";
    if (n < 1200) ans = "ABC";
    else if (n < 2800) ans = "ARC";
    cout << ans << endl;
}


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

typedef long long ll;

ll n, a, b, c, d;

int main() {
	cin >> n >> a >> b >> c >> d;
	for(int i = 0; i < n; i++){
		ll j = n - i - 1;
		if (c * i - d * j <= b - a && b - a <= d * i - c * j) {
			cout << "YES\n";
			return 0;
		}
	}
	cout << "NO\n";

	return 0;
}

Measured memory_bytes: 256
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	int n;
	cin>>n;
	float x = 1.0*n;
	float ans = (x/3)*(x/3)*(x-x/3-x/3);
	cout<<setprecision(12)<<ans;
	return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# 整数の入力

n = int(input())
a = list(map(int, input().split()))

cash = 1000
stock = 0

for i in range(n - 1):
    if stock == 0:
        if all(j < a[i] for j in a[i:]):
            break
        else:
            if a[i] < a[i + 1]:
                stock = int(cash / a[i])
                cash = cash % a[i]

    else:
        if a[i] > a[i + 1]:
            cash += stock * a[i]
            stock = 0

if stock != 0:
    cash += stock * a[n - 1]
    stock = 0
print("{}".format(cash))


Measured memory_bytes: 9200
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;
int main(){
	LL x,y,cnt;
	while(cin>>x>>y){
		cnt = 1;
		while(x<=y){
			x*=2;
			if(x<=y)
				cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;	
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

long long int gcd(long long int x, long long int y)
{
	if (y == 0) { return x; }
	return gcd(y, x % y);
}

int main(void)
{
	int x,ans = 0;
	cin >> x;
	if (x == 1) { cout << 1 << "\n"; return 0; }
	for (int i = 2; i <= x;i++)
	{
		for (int j = 2;; j++)
		{
			if (pow(i, j) > x) { break; }
			else { if (ans < pow(i, j)) { ans = pow(i, j); } }
		}
	}
	cout << ans << "\n";
	return 0;
}


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

#define int long long int
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back

signed main() {
    int n;
    cin >> n;
    map<vi, int> mp;
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        int val = i;
        vi v;
        while(val) {
            v.pb(val % 10);
            val /= 10;
        }
        if(v[0] == v.back())    ans++;
        mp[{ v[0], v.back() }]++;
        // cout << mp[{ v[0], v.back() }] << endl;
    }
    for(auto& i : mp) {
        int x = i.first[0], y = i.first[1], val = i.second;
        int other = mp[{ y, x }];
        if(x == y) {
            ans += (val * (val - 1));
        }
        else {
            ans += (val * other);
        }
    }
    cout << ans;
}


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

#define INF 987654321
#define ll long long

ll N;
string s;

int main()
{
	scanf("%lld", &N);
	ll res = 0;
	res += N/500*1000;
	N %= 500;
	res += N/5*5;
	printf("%lld", res);
	return 0;
}

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

int main()
{
    int n,k;
    cin >> n >> k;
    int sum = 0;
    rep(i,n) {
        int x;
        cin >> x;
        sum += min(2*x, 2*(k-x));
    }
    cout << sum << endl;
    return 0;
}

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

const double pi = 3.141592653589;
int main()
{
  double r, men, syu;
  cin >> r;

  men = r * r * pi;
  syu = r * 2 * pi;

  printf("%lf %lf\n", men, syu);
  return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define _ ios_base::sync_with_stdio(false);cin.tie(0);
#define f first
#define s second

using namespace std;

const int maxn = (int)(1e5)+2;
const int inf = (int)(1e9)+7;

int n, s, a[111];


int main() {
	_
	
	cin >> n;
	for (int i = 1; i <= n; i++)	cin >> a[i], s+=a[i];

	sort(a+1, a+1+n);
	if (s%10==0){
	for (int i = 1; i <= n; i++)
		if (a[i]%10!=0) {
			s -= a[i];
			break;
		}
	}
	if (s%10==0) s = 0;
	cout << s;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    int sum = h[0];
    for(int i = 1; i < n; i++){
        if(h[i] - h[i - 1] >= 0)
        sum += (h[i] - h[i - 1]);
    }
    cout << sum << endl;
}


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

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

int main() {
	int H, W, N;
	cin >> H >> W >> N;
	int sr, sc;
	cin >> sr >> sc;
	string s, t;
	cin >> s >> t;

	bool esc = false;
	// 右から出る
	int nowX = sc;
	for (int i = 0; i < N; ++i) {
		if (s[i] == 'R') { ++nowX; }
		if (nowX > W) { esc = true; }
		if ((t[i] == 'L') && (nowX > 1)) { --nowX; }
	}
	// 左から出る
	nowX = sc;
	for (int i = 0; i < N; ++i) {
		if (s[i] == 'L') { --nowX; }
		if (nowX < 1) { esc = true; }
		if ((t[i] == 'R') && (nowX < W)) { ++nowX; }
	}
	// 上から出る
	int nowY = sr;
	for (int i = 0; i < N; ++i) {
		if (s[i] == 'U') { --nowY; }
		if (nowY < 1) { esc = true; }
		if ((t[i] == 'D') && (nowY < H)) { ++nowY; }
	}
	// 下から出る
	nowY = sr;
	for (int i = 0; i < N; ++i) {
		if (s[i] == 'D') { ++nowY; }
		if (nowY > H) { esc = true; }
		if ((t[i] == 'U') && (nowY > 1)) { --nowY; }
	}

	if (!esc) { cout << "YES" << endl; }
	else { cout << "NO" << endl; }

	return 0;
}


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

int main()
{
    int l, r, d, ans =0;
    cin >> l >> r >> d;

    for(int i = l; i <= r; i++)
    {
        if(i%d == 0) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3588
n,m = map( int,input().split() )
k = [ list(map( int,input().split() )) for _ in range(n) ]

c = [0] * (m+1)

for i in k:
  for j,data in enumerate(i):
    if j == 0:
      continue
    else:
      c[data] += 1

ans = 0
for i in c:
  if i == n:
    ans += 1

print(ans)


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

vector<vector<ll>> d;
//ll ans = LINF;
//
//void rec(ll start, map<ll, ll> done, ll sum) {
//    for (auto town : done) {
//        if (town.second == 1) continue;
//
//        done[town.first] = 1;
//        rec(town.first, done, sum += d[start][town.first]);
//        done[town.first] = 0;
//    }
//
//    ans = min(ans, sum);
//};

int main() {

    ll n, m, r; cin >> n >> m >> r;
    vector<ll> t(r);
    for (ll i = 0; i < r; ++i) {
        cin >> t[i];
        t[i]--;
    }

    d.resize(n, vector<ll>(n, LINF));
    for (int i = 0; i < n; ++i) {
        d[i][i] = 0;
    }
    for (ll i = 0; i < m; ++i) {
        ll a, b, c; cin >> a >> b >> c;
        --a; --b;

        d[a][b] = c;
        d[b][a] = c;
    }

    // ワーシャルフロイド
    for (ll k = 0; k < n; ++k) {
        for (ll i = 0; i < n; ++i) {
            for (ll j = 0; j < n; ++j) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

//    map<ll, ll> done;
//    for (ll i = 0; i < r; ++i) {
//        done[t[i]] = 0;
//    }
//
//    for (ll i = 0; i < r; ++i) {
//        done[t[i]] = 1;
//        rec(t[i], done, 0);
//        done[t[i]] = 0;
//    }

    ll ans = LINF;
    sort(t.begin(), t.end());
    do {
        ll tmp = 0;
        for (int i = 1; i < t.size(); ++i) tmp += d[t[i]][t[i-1]];
        ans = min(ans, tmp);
    } while (next_permutation(t.begin(), t.end()));

    cout << ans << endl;
}

Measured memory_bytes: 3948
#include<stdio.h>
#include<algorithm>
using namespace std;
struct seg{
	int l,r;
	seg(int a=0,int b=0){
		if(a>b)swap(a,b);
		l=a;
		r=b;
	}
}p[100010];
bool operator<(seg a,seg b){return a.l<b.l;}
int r,c;
bool border(int x,int y){
	return x==0||x==r||y==0||y==c;
}
int ord(int x,int y){
	if(y==0)return x;
	if(x==r)return y+r;
	if(y==c)return r-x+r+c;
	return c-y+2*r+c;
}
int v[200010],s[200010],M;
int lowbit(int x){return x&-x;}
void modify(int x){
	while(x<=M){
		s[x]++;
		x+=lowbit(x);
	}
}
int query(int x){
	int res=0;
	while(x){
		res+=s[x];
		x-=lowbit(x);
	}
	return res;
}
int main(){
	int n,N,i,x1,y1,x2,y2;
	scanf("%d%d%d",&r,&c,&n);
	N=0;
	for(i=1;i<=n;i++){
		scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
		if(border(x1,y1)&&border(x2,y2)){
			p[++N]=seg(ord(x1,y1),ord(x2,y2));
			v[++M]=p[N].l;
			v[++M]=p[N].r;
		}
	}
	sort(v+1,v+M+1);
	for(i=1;i<=N;i++)p[i]=seg(lower_bound(v+1,v+M+1,p[i].l)-v,lower_bound(v+1,v+M+1,p[i].r)-v);
	sort(p+1,p+N+1);
	for(i=1;i<=N;i++){
		if(query(p[i].r)-query(p[i].l-1)){
			puts("NO");
			return 0;
		}
		modify(p[i].r);
	}
	puts("YES");
}

Measured memory_bytes: 2560
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 50;
int N;
ll A[Nmax];

int main(){
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> A[i];
	}

	ll ans = 0;
	while(true){
		ll x = 0;
		for(int i=0; i<N; i++){
			x += A[i]/N;
		}
		ans += x;
		for(int i=0; i<N; i++){
			A[i] += x - (A[i]/N)*(N+1);
		}

		bool f = true;
		for(int i=0; i<N; i++){
			f = f && A[i] < N;
		}

		if(f) break;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define int long long
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;

signed main(){
	
	int n;
	cin>>n;
	int k=2,ke=1;
	while(n>=k*k){
		if(n%k==0)ke=k;
		k++;
	}
	int a=ke,b=n/a;
	string s=to_string(a),t=to_string(b);
	cout<<max(s.size(),t.size())<<endl;
	
	
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
using namespace std;

int main()
{
    int N;
    cin >> N;
    set<string> w;
    vector<string> W(N);
    for (int i = 0; i < N; i++)
    {
        string tmp;
        cin >> tmp;
        w.insert(tmp);
        W[i] = tmp;
    }
    bool flag = true;
    if (w.size() == N)
    {
        for (int i = 0; i < N - 1; i++)
        {
            if (*(W[i].end() - 1) != *W[i + 1].begin())
            {
                flag = false;
                break;
            }
        }
    }
    else
    {
        flag = false;
    }
    if (flag)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int i, j, Min, p, q, r, n, w[101][101], key[101], d[101];
    scanf("%d", &n);
    for ( i = 0; i < n; i++ ) {
        key[i] = 0;
        d[i] = 200001;
        for ( j = 0; j < n; j++ ) {
            w[i][j] = -1;
        }
    }
    for ( i = 0; i < n; i++ ) {
        scanf("%d %d", &p, &q);
        for ( j = 0; j < q; j++ ) {
            scanf("%d", &r);
            scanf("%d", &w[p][r]);
        }
    }
    d[0] = 0;
    while ( 1 ) {
        Min = 200001;
        for ( i = 0; i < n; i++ ) {
            if ( key[i] != 1 && d[i] < Min ) {
                Min = d[i];
                p = i;
            }
        }
        if ( Min == 200001 ) break;
        for ( i = 0; i < n; i++ ) {
            if ( w[p][i] != -1 && key[i] != 1 && d[p] + w[p][i] < d[i] )
            d[i] = d[p] + w[p][i];
        }
        key[p] = 1;
    }
    for ( i = 0; i < n; i++ ) {
        printf("%d %d\n", i, d[i]);
    }
    return 0;
}

Measured memory_bytes: 1796
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (m); i < (int)(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define INF 2000000000

#ifdef LOCAL
  #define eprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define eprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

const double PI = 3.1415926535897932384626433832795;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> vv(h+2, string());
  vv[0] = string(w + 2, '.');
  REP(i, h) {
    string t;
    cin >> t;
    t = "." + t + ".";
    //cout << "  " << t << endl;
    vv[i+1] = t;
  }
  vv[vv.size()-1] = string(w + 2, '.');
  /*
  FOR(y, 0, vv.size()) {
      cout << vv[y] << endl;
  }
  */


  vector<int> dx {0, 1, 1, 1, 0, -1, -1, -1};
  vector<int> dy {-1, -1, 0, 1, 1, 1, 0, -1};

  FOR(y, 1, vv.size()-1) {
    FOR(x, 1, vv[0].size()-1) {
      if(vv[y][x] == '#') {
        continue;
      }
      int count = 0;
      REP(i, 8) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(vv[ny][nx] == '#') {
          count++;
        }
      }
      vv[y][x] = count + '0';
    }
  }

  FOR(y, 1, vv.size()-1) {
    FOR(x, 1, vv[0].size()-1) {
      cout << vv[y][x];
    }
    cout << endl;
  }

  return 0;
}


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

int main() {
    int h,n,a;
    cin >> h >> n;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> a;
        sum += a;
    }
    cout << (sum >= h? "Yes":"No") << endl;
    return 0;
}

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

int main() {
	ll n;
	cin >> n;
	vector<ll>a(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	bool l1 = false;
	ll m1 = 0;
	bool l2 = false;
	ll m2 = 0;
	for (int i = 0; i < n; i++) {
		if (l1 == false) {
			if (m1 == a.at(i)) l1 = true;
			else m1 = a.at(i);
		}
		else {
			if (m2 == a.at(i))break;
			else m2 = a.at(i);
		}
	}
	ll ans = m1 * m2;
	cout << ans << endl;

}

Measured memory_bytes: 1024
use std::io;


fn main() {
    let (n, m) = {
        let i = read::<usize>();
        (i[0], i[1])
    };

    let mut ab = Vec::new();
    for _ in 0..m {
        let (a, b) = {
            let i = read::<usize>();
            (i[0], i[1])
        };
        ab.push((a, b));
    }

    let mut uf = UnionFind::new(n + 1);
    let mut cost = n * (n - 1) / 2;
    let mut ans = Vec::new();

    for (a, b) in ab.into_iter().rev() {
        ans.push(cost);
        if uf.same(a, b) { continue; }
        let pa = uf.find(a);
        let pb = uf.find(b);
        let c = uf.siz[pa] * uf.siz[pb];
        uf.unite(a, b);
        cost -= c;
    }

    for a in ans.iter().rev() {
        println!("{}", a);
    }
}


struct UnionFind {
    par: Vec<usize>,
    siz: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> Self {
        UnionFind {
            par: (0..n).collect(),
            siz: vec![1; n],
        }
    }

    fn unite(&mut self, a: usize, b: usize) {
        let pa = self.find(a);
        let pb = self.find(b);
        if pa == pb { return; }
        self.siz[pa] += self.siz[pb];
        self.par[pa] = pb;
        self.siz[pb] = self.siz[pa];
    }

    fn same(&mut self, a: usize, b: usize) -> bool {
        self.find(a) == self.find(b)
    }

    fn find(&mut self, a: usize) -> usize {
        if self.par[a] == a { a }
        else {
            let p = self.par[a];
            self.par[a] = self.find(p);
            self.par[a]
        }
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 11152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int N; cin >> N;
  string S; cin >> S;
  
  string T;
  int k = 0, t = 0;
  rep(i, N) {
    if(S[i] == '(') k++;
    else k--;
    if(k < 0) {
      t++;
      k++;
    } 
  }
  
  rep(i, t) cout << '(';
  cout << S;
  rep(i, k) cout << ')';
  cout << endl;


}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

const ll mod = 998244353;
            // 998,244,353

struct RSQ_RAQ{
    int n;
    vector<ll> node,lazy;

    RSQ_RAQ(int sz){
        n=1;
        while(n < sz) n*=2;
        node.resize(2*n-1);
        lazy.resize(2*n-1,0);
    }

    void eval(int k,int l, int r){
        if(lazy[k] != 0){
            node[k] += lazy[k];//合計を求める上で要素に足しておく
            if(r-l>0){
                lazy[2*k+1] += lazy[k]/2;
                lazy[2*k+2] += lazy[k]/2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a,int b, ll x,int k = 0, int l = 0,int r = -1){
        
        if(r < 0) r = n-1;
        eval(k,l,r);
        if(b < l || r < a) return ;
        if(a <= l && r <= b){
            lazy[k] += (r - l + 1) * x;
            eval(k,l,r);
        }else{
            add(a,b,x,2*k+1,l,(l+r)/2);
            add(a,b,x,2*k+2,(l+r)/2+1,r);
            node[k] = (node[2*k+1] + node[2*k+2]) % mod;
        }
    }

    ll getsum(int a,int b,int k = 0,int l = 0, int r = -1){
        
        if(r < 0)r = n-1;
        
        eval(k,l,r);
        if(b < l || r < a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1,         l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2+1,       r);
        return (vl + vr) % mod;
    }
};

int main(){
    int n,k;
    cin >> n >> k;
    RSQ_RAQ seg(n+10);


    vl l(n),r(n);
    rep(i,k){
        cin >> l[i] >> r[i];
    }

    seg.add(0,0,1);
    reps(i,1,n+9){
        rep(j,k){
            seg.add((i-1) + l[j], (i-1)+r[j], seg.getsum(i-1,i-1) % mod);
        }
    }
    // rep(i,n+9){
    //     cout <<  i << ";" << seg.getsum(i,i)%mod << endl;
    // }

    cout << seg.getsum(n-1,n-1)%mod << endl;

    return 0;
}

Measured memory_bytes: 14532
#include<stdio.h>
#include<string.h>
int main(void){
  char str[222];
  scanf("%s",str);
  int n=strlen(str);
  for(int loop=n-2;loop;loop-=2){
    if(strncmp(str,str+loop/2,loop/2)==0){
      printf("%d\n",loop);
      return 0;
    }
  }
  return 0;
}

Measured memory_bytes: 128
local function gcd(a,b)
    if b>0 then
        return gcd(b,a%b)
    else
        return a
    end
end

local n,m=io.read("*n","*n","*l")
local s=io.read()
local t=io.read()

local l=n*m//gcd(n,m)
local ln=m//gcd(n,m)
local lm=n//gcd(n,m)

local x={}
for i=1,n do
    x[(i-1)*ln+1]=s:sub(i,i)
end

for i=1,m do
    if not x[(i-1)*lm+1] then
        x[(i-1)*lm+1]=t:sub(i,i)
    elseif x[(i-1)*lm+1]~=t:sub(i,i) then
        print(-1)
        return
    end
end
print(l)

Measured memory_bytes: 12892
N = int(input())
a = list(map(int, input().split()))
alice_p = 0
bob_p = 0
a.sort(reverse=True)

for i in range(N):
    if i % 2 == 0:
        alice_p += a[i]
    else:
        bob_p += a[i]

print(alice_p - bob_p)


Measured memory_bytes: 2940
from collections import defaultdict
import sys
input = sys.stdin.readline
n,k,l = map(int,input().split())
road = [list(map(int,input().split())) for i in range(k)]
train = [list(map(int,input().split())) for i in range(l)]
rg = [[] for i in range(n+1)]
rv = [0 for i in range(n+1)]
tg = [[] for i in range(n+1)]
tv = [0 for i in range(n+1)]
def connect(road,rg,rv):
  for a,b in road:
    rg[a].append(b)
    rg[b].append(a)
  cnt = 0
  for i in range(1,n+1):
    if rv[i] == 0:
      cnt += 1
      stack = [i]
      while stack:
        x = stack.pop()
        rv[x] = cnt
        for y in rg[x]:
          if rv[y] == 0:
            stack.append(y)
            rv[y] = cnt
connect(road,rg,rv)
connect(train,tg,tv)
condc = defaultdict(list)
for i in range(1,n+1):
  cr = rv[i]
  ct = tv[i]
  condc[(cr,ct)].append(i)
ans = []
for i in range(1,n+1):
  cr = rv[i]
  ct = tv[i]
  ans.append(len(condc[(cr,ct)]))
print(*ans)

Measured memory_bytes: 139348
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef long double ld;
const ld pi = 4*atan((ld)1);
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll nax = 2e5 + 5;

ll n;
pair<ll,ll> a[nax];

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll maxi = -inf;
	ll mini = inf;
	ll idx = 0, idn = 0;
	cin >> n;
	for(ll i = 1; i <= n; i++){
		cin >> a[i].ff >> a[i].ss;
		ll x = a[i].ff, y = a[i].ss;
		if(maxi < x - y){
			maxi = x - y;
			idx = i;
		}
		if(mini > x - y){
			mini = x - y;
			idn = i;
		}
	}
	ll ans = abs(a[idx].ff - a[idn].ff) + abs(a[idx].ss - a[idn].ss);
	maxi = -inf, mini = inf, idx = 0, idn = 0;
	for(ll i = 1; i <= n; i++){
		ll x = a[i].ff, y = a[i].ss;
		if(maxi < x + y){
			maxi = x + y;
			idx = i;
		}
		if(mini > x + y){
			mini = x + y;
			idn = i;
		}
	}
	ans = max(ans, abs(a[idx].ff - a[idn].ff) + abs(a[idx].ss - a[idn].ss));
	cout << ans << '\n';
}



Measured memory_bytes: 6760
#include <stdio.h>

int main ()
{
   int n, x, i, j, k, f, y, count;

   f = 0;
   while(1)
   {
      count = 0;
      scanf("%d %d", &n, &x);

      if (n == 0 && x == 0) {
         break;
      }

         for (i = 1; i <= n; i++) {
            for (j = i+1; j <= n; j++){
               for (k = j+1; k <= n; k++){

                  y = i + j + k;

                  if (y == x) {
                     count++;
                  }
               }
            }
         }

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

      
   }

   return 0;

}

      

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

#define REP(i, n) for(int i=0; i<n; i++)
#define REPR(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=m; i<n; i++)

#define INF 2e9
#define ll long long

int main(){
    int h, w, i, j;
    cin>>h>>w;
    char s[h][w];
    for(i=0; i<h; i++){
        cin>>s[i];
    }

    int l[h][w];
    int r[h][w];
    int d[h][w];
    int u[h][w];
    int tmp = 0;

    for(i=0; i<h; i++){
        tmp = 0;
        for(j=0; j<w; j++){
            l[i][j] = 0;
            r[i][j] = 0;
            d[i][j] = 0;
            u[i][j] = 0;
            if(s[i][j]=='.'){
                tmp++;
            }
            else{
                tmp = 0;
                //cout<<"i="<<i<<"j="<<j<<endl;;
            }
            l[i][j] = tmp;
        }
    }

    for(i=0; i<h; i++){
        tmp = 0;
        for(j=w-1; j>=0; j--){
            if(s[i][j]=='.'){
                tmp++;
            }
            else{
                tmp = 0;
            }
            r[i][j] = tmp;
        }
    }

    for(i=0; i<w; i++){
        tmp = 0;
        for(j=h-1; j>=0; j--){
            if(s[j][i]=='.'){
                tmp++;
            }
            else{
                tmp = 0;
            }
            d[j][i] = tmp;
        }
    }  

    for(i=0; i<w; i++){
        tmp = 0;
        for(j=0; j<h; j++){
            if(s[j][i]=='.'){
                tmp++;
            }
            else{
                tmp = 0;
            }
            u[j][i] = tmp;
        }
    }    

    int ans = 0;


    for(i=0; i<h; i++){
        for(j=0; j<w; j++){
            //cout<<l[i][j]<<" "<<r[i][j]<<" "<<d[i][j]<<" "<<u[i][j]<<endl;
            if(l[i][j]+r[i][j]+d[i][j]+u[i][j]-3>=ans){
                ans = l[i][j]+r[i][j]+d[i][j]+u[i][j]-3;
                //cout<<l[i][j]<<" "<<r[i][j]<<" "<<d[i][j]<<" "<<u[i][j]<<endl;
            }
        }
        //cout<<endl;
    }        

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 66688
###################################################
#                                                 #
#   author: raghav_0901 (Raghav Dalmia)           #
#   updated on: Sunday, 14-06-2020, 17:31:38 pm   #
#                                                 #
###################################################

from math import *


def _in():
    return [int(x) for x in input().split(' ')]


def main():
    arr = _in()
    for i in range(1, 6):
        if not(i in arr):
            print(i)
            return


if __name__ == "__main__":
    tt = 1
    # tt = int(input())
    for _ in range(tt):
        main()


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    int n;cin >>n;
    cout <<n/3<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace abc066A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int[] stl = new int[3];
            stl[0] = int.Parse(str[0]);
            stl[1] = int.Parse(str[1]);
            stl[2] = int.Parse(str[2]);
            Array.Sort(stl);
            Console.WriteLine(stl[0] + stl[1]);
        }
    }
}


Measured memory_bytes: 11476
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int N, M, Q;
vector<int> a, b, c, d;

int dfs(vector<int> v, int last) {
  v.push_back(last);
  if (v.size() == N) {
    int score = 0;
    for (int i = 0; i < Q; ++i) {
      if (v[b[i]] - v[a[i]] == c[i]) score += d[i];
    }
    return score;
  }

  int score = 0;
  for (int i = last; i <= M; ++i) {
    score = max(score, dfs(v, i));
  }
  return score;
}

int main() {
  cin >> N >> M >> Q;
  a.resize(Q);
  b.resize(Q);
  c.resize(Q);
  d.resize(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    --a[i], --b[i];
  }

  int score = 0;
  for (int i = 1; i <= M; ++i) {
    score = max(score, dfs({}, i));
  }
  cout << score << endl;
}


Measured memory_bytes: 3564
#include <stdio.h>

int main(void) {
  int a[100];
  int n, i;

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  for (i = n - 1; i > 0; i--) {
    printf("%d ", a[i]);
  }
  printf("%d\n", a[0]);
  return 0;
}

Measured memory_bytes: 596
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

p=[0]*3
p[0]=list(ns())
p[1]=list(ns())
p[2]=list(ns())
turn='a'
d={'a':0,'b':1,'c':2}

hand=p[d[turn]]
ch=len(hand)
while(ch!=0):
  turn=p[d[turn]].pop(0)
  hand=p[d[turn]]
  ch=len(hand)


print(turn.upper())


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

using namespace std;
#define LL long long
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int qq = 2e5 + 10;
int num[105];

int main(){
	int n;	scanf("%d", &n);
	int ans = 0;
	REP(i, 1, n){
		scanf("%d", num + i);
	}
	sort(num + 1, num + 1 + n);
	REP(i, 2, n){
		ans += num[i] - num[i - 1];
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    ll sum = 0;
    rep(i,N) sum ^= A[i];
    rep(i,N) {
        cout << (sum ^ A[i]);
        if (i < N - 1) cout << " ";
        else cout << endl;
    }
    
    return 0;
}

Measured memory_bytes: 4804
#include <stdio.h>

int main(void) {
    int a, b;
    scanf("%d %d", &a, &b);
    if (a >= 13){
        printf("%d\n", b);
    }else if(a >= 6 && a <= 12){
        printf("%d\n", b / 2);
    }else if(a <= 5){
        printf("0\n");
    }
}


Measured memory_bytes: 128
#include <stdio.h>

int main()
{
	int n,m,q,i,j,k,a,b,c,d,kari=0;
	int board[501][501]={0};
	int nboard[501][501]={0};
	static int ans[100010];
	scanf("%d %d %d",&n,&m,&q);
	for(i=0;i<m;i++)
	{
		scanf("%d %d",&a,&b);
		board[a][b]++;
	}/*
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=n;j++)
		{
			printf("%d ",board[i][j]);
		}
		printf("\n");
	}*/
	for(i=1;i<=n;i++)
	{
		nboard[i][i]=board[i][i];
		for(j=i+1;j<=n;j++)
		{
			kari=0;
			for(k=i;k<=j;k++)
			{
				kari+=board[k][j];
			}
			nboard[i][j]=nboard[i][j-1]+kari;
		}
	}
	for(i=0;i<q;i++)
	{
		scanf("%d %d",&c,&d);
		ans[i]=nboard[c][d];
	}
	for(i=0;i<q;i++)
	{
		printf("%d\n",ans[i]);
	}
}


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

int main()
{
    int N, D;
    int ans = 0;
    cin >> N >> D;
    vector<vector<double>> X(N, vector<double>(D));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < D; j++)
        {
            cin >> X[i][j];
        }
    }
    for (int i = 0; i < N - 1; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            double sum = 0;
            double tmp = 0;
            for (int ix = 0; ix < D; ix++)
            {
                sum += pow(X[i][ix] - X[j][ix], 2);
            }
            tmp = sqrt(sum);
            if (tmp == floor(tmp))
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int n,a[100000];
int main(){
    cin>>n;
    bool zero=true;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]!=0)zero=false;
    }
    if(zero){
        cout<<"Yes";
        return 0;
    }
    if(n%3){
        cout<<"No";
        return 0;
    }
    sort(a,a+n);
    int x=0;
    for(int i=0;i<n;i+=(n/3)){
        x=x^a[i];
        for(int j=i;j<i+n/3;j++){
            if(a[i]!=a[j]){
                cout<<"No";
                return 0;
            }
        }
    }
    if(x)cout<<"No";
    else cout<<"Yes";
    return 0;
}

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

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int main() {

  int n;
  long long a[100005], dp[100005];
  cin>>n;
  long long  sum = 0;
  REP(i,0,n){
    cin>>a[i];
    sum += a[i];
    dp[i] = sum;
  }

  long long diff = 0, ans = 0;
/*
  if(dp[0] == 0){
    if(dp[1] < 0) diff++, ans++;
    else diff--, ans++;
  }
  */
  if(dp[0] == 0){
    ans++;
    diff++;
  }
  REP(i,1,n){
    if(dp[i] + diff == 0){
      if(dp[i-1] + diff < 0) diff++, ans++;
      if(dp[i-1] + diff > 0) diff--, ans++;
      continue;
    }
    if((dp[i-1] + diff)/llabs(dp[i-1] + diff) == (dp[i] + diff)/llabs(dp[i] + diff)){
      if(dp[i] + diff < 0){
        ans += llabs(dp[i] + diff) + 1;
        diff += llabs(dp[i] + diff) + 1;
      }else{
        ans += llabs(dp[i] + diff) + 1;
        diff -= llabs(dp[i] + diff) + 1;
      }
    }
  }

  long long tans = ans;
  diff = 0; ans = 0;
  if(dp[0] == 0){
    ans++;
    diff--;
  }else{
    ans += llabs(dp[0]) + 1;
    if(dp[0] > 0) diff -= llabs(dp[0]) + 1;
    else diff += llabs(dp[0]) + 1;
  }
  REP(i,1,n){
    if(dp[i] + diff == 0){
      if(dp[i-1] + diff < 0) diff++, ans++;
      if(dp[i-1] + diff > 0) diff--, ans++;
      continue;
    }
    if((dp[i-1] + diff)/llabs(dp[i-1] + diff) == (dp[i] + diff)/llabs(dp[i] + diff)){
      if(dp[i] + diff < 0){
        ans += llabs(dp[i] + diff) + 1;
        diff += llabs(dp[i] + diff) + 1;
      }else{
        ans += llabs(dp[i] + diff) + 1;
        diff -= llabs(dp[i] + diff) + 1;
      }
    }
  }

  cout<<min(ans, tans)<<endl;

  return 0;
}


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

int main() {
  int n, counter;
  int f[10001];
  int x, y, z;
  cin >> n;

  for (int i = 0; i < 10001; i++) {
    f[i] = 0;
  }
  for (x = 1; x <= 100; x++) {
    for (y = 1; y <= 100; y++) {
      for (z = 1; z <= 100; z++) {
        int m = x * x + y * y + z * z + x * y + y * z + z * x;
        if (m <= n) {
          f[m]++;
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << f[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3560
s = input()
included = set()
for i in s:
    included.add(i)
for i in range(ord('a'), ord('z') + 1):
    if not chr(i) in included:
        print(s + chr(i))
        exit()
ans = ''
for i in range(len(s) - 1, -1, -1):
    for j in range(ord(s[i]), ord('z') + 1):
        now = s[:i] + chr(j)
        if not chr(j) in s[:i] and s[:i + 1] != now:
            print(now)
            exit()
print(-1)

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using llu = long long unsigned int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int X;
    Scd(X);

    printf ("%d\n", X/500*1000 + (X%500)/5*5);

    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define dbl double
#define pi acos(-1)
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define pb push_back

ll ara[1000005][10];

map<ll,ll>vis;
map<ll,ll>vis1;
map<ll,ll>pos;
map<ll,ll>high;
map<ll,ll>low;
map<string,ll>mp;
vector<ll>vec;
vector<ll>v;
stack<ll>q;
string str1[100];
string str2[100];
priority_queue<ll>pq;
ll dp[1000005][10],t,k;
ll mn=1000000;
ll call(ll id,ll no)
{
    if(dp[id][no]!=-1)
        return dp[id][no];
    if(id==t+1)
        return 0;
    ll p=0,q=0,r=0;
    if(no!=1)
        p=call(id+1,1)+ara[id][1];
    if(no!=2)
        q=call(id+1,2)+ara[id][2];
    if(no!=3)
        r=call(id+1,3)+ara[id][3];
    // cout<<max(max(p,q),r)<<endl;
    return dp[id][no]=max(max(p,q),r);

}
int main()
{

    // ll t;
    memset(dp,-1,sizeof(dp));
    sc1(t);
    ll k=0;
    for(ll i=1; i<=t; i++)
    {
        sc3(ara[i][1],ara[i][2],ara[i][3]);
    }
    cout<<call(1,0)<<endl;
    return 0;
}


Measured memory_bytes: 92544
n = int(input())
lst = []
temp = n
s = 0
for i in range(2, int(-(-n**0.5//1))+1):
  if temp%i==0:
    cnt=0
    while temp%i==0:
      cnt+=1
      temp //= i
    lst.append(cnt)
    for x in range(1,9):
      if x*(x+1)/2 <= cnt and (x+2)*(x+1)/2 > cnt:
        break
    s = s+x    

if temp!=1:
  s = s + 1
if n == 1:
  s = 0
elif lst==[]:
  s = 1

print(s)
  
  
    






Measured memory_bytes: 9460
#include<stdio.h>
#define N 500000
#define NN 250000
#define INFTY 1000000001

int cnt=0;

void merge(int A[],int left,int mid,int right){
  int n1,n2;
  int i,j,k;
  n1=mid-left;
  n2=right-mid;
  int L[n1],R[n2];
  for(i=0;i<n1;i++)L[i]=A[left+i];
  for(i=0;i<n2;i++)R[i]=A[mid+i];
  L[n1]=INFTY;
  R[n2]=INFTY;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      cnt++;
      A[k]=L[i];
      i=i+1;
    }
    else {
      cnt++;
      A[k]=R[j];
      j=j+1;
    }
  }
}

void mergeSort(int A[],int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}
      

int main(){
  int n,i;
  int A[N];
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  mergeSort(A,0,n);
  for(i=0;i<n;i++){
    if(i!=n-1)printf("%d ",A[i]);
    else printf("%d",A[i]);
  }
  printf("\n%d\n",cnt);
  return 0;
}
  



Measured memory_bytes: 5636
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/24
@author: shinjisu
"""


# ABC 122
# import math
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)
def getIntLines(n): return [int(input()) for i in range(n)]
def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    #mat = zeros((n, m))
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)
def zeros2(n, m): return [zeros(m) for i in range(n)] # obsoleted zeros((n, m))で代替

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    B = input()
    d.dmp((B), 'B')
    dic = {'A':'T', 'C':'G', 'G':'C', 'T':'A', }
    return dic[B]

ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  # 1,ans
    for elm in ans[1]:
        print(elm)
else:
    print(ans)
    





Measured memory_bytes: 3064
//
// Created by kuroneko on 2019-07-06.
//

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>

typedef long long ll;
using namespace std;
ll dp[101][4][4][4];
const ll MOD = 1000000007LL;

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


    for (int i = 0; i <= N; i++) {
        for (int c1 = 0; c1 < 4; c1++) {
            for (int c2 = 0; c2 < 4; c2++) {
                for (int c3 = 0; c3 < 4; c3++) {
                        dp[i][c1][c2][c3] = 0;
                }
            }
        }
    }
    dp[0][3][3][3] = 1;
    for (int i = 1; i <= N; i++) {
        for (int c1 = 0; c1 < 4; c1++) {
            for (int c2 = 0; c2 < 4; c2++) {
                for (int c3 = 0; c3 < 4; c3++) {
                    for (int c4 = 0; c4 < 4; c4++) {
                        if (c2 == 0 && c3 == 1 && c4 == 2) continue;
                        else if (c2 == 0 && c3 == 2 && c4 == 1) continue;
                        else if (c2 == 1 && c3 == 0 && c4 == 2) continue;
                        else if (c1 == 0 && c3 == 1 && c4 == 2) continue;
                        else if (c1 == 0 && c2 == 1 && c4 == 2) continue;
                        else {
                            dp[i][c2][c3][c4] = (dp[i][c2][c3][c4] + dp[i-1][c1][c2][c3]) % MOD;
                        }
                    }
                }
            }
        }
    }
    ll ans = 0;
    for (int c1 = 0; c1 < 4; c1++) {
        for (int c2 = 0; c2 < 4; c2++) {
            for (int c3 = 0; c3 < 4; c3++) {
                ans = (ans + dp[N][c1][c2][c3]) % MOD;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-04-26 16:41:19
*/

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

#define all(x) (x).begin(),(x).end()
#define rev(x) greater<x>()
#define MOD 1000000007
#define INF 1000000000

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod)
{
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod)
{
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod)
{
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

int gcd(int k, int l)
{
    if (l > 0) return gcd(l, k%l);
    else return k;
}

struct UnionFind
{
    vector<int> par;

    UnionFind(int n) : par(n) {
        for (int i = 0; i < n; i++) par[i] = i;
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];

    sort(all(a));

    int ans = a[n-1] - a[0];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))

x = 0
for i in range(n):
    if i%2 == 0:
        x += A[i]
    else:
        x -= A[i]

ans = [0]*n
ans[0] = x
for i in range(1, n):
    ans[i] = 2*A[i-1]-ans[i-1]
print(*ans)

Measured memory_bytes: 64484